]> git.ipfire.org Git - thirdparty/babel.git/commitdiff
Avoid reading files entirely into memory
authorVille Skyttä <ville.skytta@iki.fi>
Tue, 26 Jul 2016 20:28:10 +0000 (23:28 +0300)
committerVille Skyttä <ville.skytta@iki.fi>
Tue, 26 Jul 2016 23:23:13 +0000 (02:23 +0300)
babel/localtime/_unix.py
babel/messages/pofile.py

index 378a90b43c70977046e2cbd740ffc92cea34a850..91f03bc993ada70caf9a85f408a8dbe1ad947336 100644 (file)
@@ -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'):
index f3ba2fa3025b7e4fad8034553d119146236539e2..e431fcd7f875979ca6e873924f2ecf096d104721 100644 (file)
@@ -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)