From: Ville Skyttä Date: Tue, 26 Jul 2016 20:28:10 +0000 (+0300) Subject: Avoid reading files entirely into memory X-Git-Tag: v2.4.0~13^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0127312630b31a00e3989c54d7e8188e1caa1c34;p=thirdparty%2Fbabel.git Avoid reading files entirely into memory --- diff --git a/babel/localtime/_unix.py b/babel/localtime/_unix.py index 378a90b4..91f03bc9 100644 --- a/babel/localtime/_unix.py +++ b/babel/localtime/_unix.py @@ -109,21 +109,19 @@ def _get_localzone(_root='/'): if not os.path.exists(tzpath): continue with open(tzpath, 'rt') as tzfile: - data = tzfile.readlines() - - for line in data: - # Look for the ZONE= setting. - match = zone_re.match(line) - if match is None: - # No ZONE= setting. Look for the TIMEZONE= setting. - match = timezone_re.match(line) - if match is not None: - # Some setting existed - line = line[match.end():] - etctz = line[:end_re.search(line).start()] - - # We found a timezone - return pytz.timezone(etctz.replace(' ', '_')) + for line in tzfile: + # Look for the ZONE= setting. + match = zone_re.match(line) + if match is None: + # No ZONE= setting. Look for the TIMEZONE= setting. + match = timezone_re.match(line) + if match is not None: + # Some setting existed + line = line[match.end():] + etctz = line[:end_re.search(line).start()] + + # We found a timezone + return pytz.timezone(etctz.replace(' ', '_')) # No explicit setting existed. Use localtime for filename in ('etc/localtime', 'usr/local/etc/localtime'): diff --git a/babel/messages/pofile.py b/babel/messages/pofile.py index f3ba2fa3..e431fcd7 100644 --- a/babel/messages/pofile.py +++ b/babel/messages/pofile.py @@ -207,7 +207,7 @@ class PoFileParser(object): units found in it to the `Catalog` supplied to the constructor. """ - for lineno, line in enumerate(fileobj.readlines()): + for lineno, line in enumerate(fileobj): line = line.strip() if not isinstance(line, text_type): line = line.decode(self.catalog.charset)