self.set_header(
"Last-Modified", datetime.datetime.utcfromtimestamp(info.st_mtime)
)
- object_file = open(path, "rb")
- try:
+ with open(path, "rb") as object_file:
self.finish(object_file.read())
- finally:
- object_file.close()
def put(self, bucket, object_name):
object_name = urllib.unquote(object_name)
directory = os.path.dirname(path)
if not os.path.exists(directory):
os.makedirs(directory)
- object_file = open(path, "w")
- object_file.write(self.request.body)
- object_file.close()
+ with open(path, "w") as object_file:
+ object_file.write(self.request.body)
self.finish()
def delete(self, bucket, object_name):
encoding = "utf-8-sig"
# python 3: csv.reader requires a file open in text mode.
# Specify an encoding to avoid dependence on $LANG environment variable.
- f = open(full_path, "r", encoding=encoding)
- _translations[locale] = {}
- for i, row in enumerate(csv.reader(f)):
- if not row or len(row) < 2:
- continue
- row = [escape.to_unicode(c).strip() for c in row]
- english, translation = row[:2]
- if len(row) > 2:
- plural = row[2] or "unknown"
- else:
- plural = "unknown"
- if plural not in ("plural", "singular", "unknown"):
- gen_log.error(
- "Unrecognized plural indicator %r in %s line %d",
- plural,
- path,
- i + 1,
- )
- continue
- _translations[locale].setdefault(plural, {})[english] = translation
- f.close()
+ with open(full_path, encoding=encoding) as f:
+ _translations[locale] = {}
+ for i, row in enumerate(csv.reader(f)):
+ if not row or len(row) < 2:
+ continue
+ row = [escape.to_unicode(c).strip() for c in row]
+ english, translation = row[:2]
+ if len(row) > 2:
+ plural = row[2] or "unknown"
+ else:
+ plural = "unknown"
+ if plural not in ("plural", "singular", "unknown"):
+ gen_log.error(
+ "Unrecognized plural indicator %r in %s line %d",
+ plural,
+ path,
+ i + 1,
+ )
+ continue
+ _translations[locale].setdefault(plural, {})[english] = translation
_supported_locales = frozenset(list(_translations.keys()) + [_default_locale])
gen_log.debug("Supported locales: %s", sorted(_supported_locales))