Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 727ba7c

Browse files
Issue #28637: No longer use re in site.py.
This makes Python startup from a virtual environment a little faster.
1 parent 4778e13 commit 727ba7c

1 file changed

Lines changed: 4 additions & 9 deletions

File tree

Lib/site.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -422,8 +422,6 @@ def register_readline():
422422

423423
sys.__interactivehook__ = register_readline
424424

425-
CONFIG_LINE = r'^(?P<key>(\w|[-_])+)\s*=\s*(?P<value>.*)\s*$'
426-
427425
def venv(known_paths):
428426
global PREFIXES, ENABLE_USER_SITE
429427

@@ -445,19 +443,16 @@ def venv(known_paths):
445443
]
446444

447445
if candidate_confs:
448-
import re
449-
config_line = re.compile(CONFIG_LINE)
450446
virtual_conf = candidate_confs[0]
451447
system_site = "true"
452448
# Issue 25185: Use UTF-8, as that's what the venv module uses when
453449
# writing the file.
454450
with open(virtual_conf, encoding='utf-8') as f:
455451
for line in f:
456-
line = line.strip()
457-
m = config_line.match(line)
458-
if m:
459-
d = m.groupdict()
460-
key, value = d['key'].lower(), d['value']
452+
if '=' in line:
453+
key, _, value = line.partition('=')
454+
key = key.strip().lower()
455+
value = value.strip()
461456
if key == 'include-system-site-packages':
462457
system_site = value.lower()
463458
elif key == 'home':

0 commit comments

Comments
 (0)