def write_dict(filename, contents): if '__corrupted__' in contents: return try: fp = LockedFile(filename, 'w') except (IOError, OSError): if not settings.global_settings.web2py_runtime_gae: logging.warning('Unable to write to file %s' % filename) return fp.write('# coding: utf8\n{\n') for key in sorted(contents, lambda x, y: cmp(unicode(x, 'utf-8').lower(), unicode(y, 'utf-8').lower())): fp.write('%s: %s,\n' % (repr(Utf8(key)), repr(Utf8(contents[key])))) fp.write('}\n') fp.close()
def write_dict(filename, contents): if "__corrupted__" in contents: return try: fp = LockedFile(filename, "w") except (IOError, OSError): if not settings.global_settings.web2py_runtime_gae: logging.warning("Unable to write to file %s" % filename) return fp.write("# coding: utf8\n{\n") for key in sorted(contents, lambda x, y: cmp(unicode(x, "utf-8").lower(), unicode(y, "utf-8").lower())): fp.write("%s: %s,\n" % (repr(Utf8(key)), repr(Utf8(contents[key])))) fp.write("}\n") fp.close()
def write_plural_dict(filename, contents): if '__corrupted__' in contents: return try: fp = LockedFile(filename, 'w') fp.write('#!/usr/bin/env python\n# -*- coding: utf-8 -*-\n{\n# "singular form (0)": ["first plural form (1)", "second plural form (2)", ...],\n') for key in sorted(contents, lambda x, y: cmp(unicode(x, 'utf-8').lower(), unicode(y, 'utf-8').lower())): forms = '[' + ','.join([repr(Utf8(form)) for form in contents[key]]) + ']' fp.write('%s: %s,\n' % (repr(Utf8(key)), forms)) fp.write('}\n') except (IOError, OSError): if not is_gae: logging.warning('Unable to write to file %s' % filename) return finally: fp.close()
def write_plural_dict(filename, contents): if '__corrupted__' in contents: return try: fp = LockedFile(filename, 'w') fp.write('#!/usr/bin/env python\n{\n# "singular form (0)": ["first plural form (1)", "second plural form (2)", ...],\n') # coding: utf8\n{\n') for key in sorted(contents, lambda x, y: cmp(unicode(x, 'utf-8').lower(), unicode(y, 'utf-8').lower())): forms = '[' + ','.join([repr(Utf8(form)) for form in contents[key]]) + ']' fp.write('%s: %s,\n' % (repr(Utf8(key)), forms)) fp.write('}\n') except (IOError, OSError): if not is_gae: logging.warning('Unable to write to file %s' % filename) return finally: fp.close()
def write_dict(filename, contents): if '__corrupted__' in contents: return fp = None try: fp = LockedFile(filename, 'w') fp.write('# -*- coding: utf-8 -*-\n{\n') for key in sorted(contents, sort_function): fp.write('%s: %s,\n' % (repr(Utf8(key)), repr(Utf8(contents[key])))) fp.write('}\n') except (IOError, OSError): if is_writable(): logging.warning('Unable to write to file %s' % filename) return finally: if fp: fp.close()
def write_plural_dict(filename, contents): if '__corrupted__' in contents: return fp = None try: fp = LockedFile(filename, 'w') fp.write('#!/usr/bin/env python\n# -*- coding: utf-8 -*-\n{\n# "singular form (0)": ["first plural form (1)", "second plural form (2)", ...],\n') for key in sorted(contents, sort_function): forms = '[' + ','.join([repr(Utf8(form)) for form in contents[key]]) + ']' fp.write('%s: %s,\n' % (repr(Utf8(key)), forms)) fp.write('}\n') except (IOError, OSError): if is_writable(): logging.warning('Unable to write to file %s' % filename) return finally: if fp: fp.close()
def write_plural_dict(filename, contents): if "__corrupted__" in contents: return try: fp = LockedFile(filename, "w") fp.write( '#!/usr/bin/env python\n{\n# "singular form (0)": ["first plural form (1)", "second plural form (2)", ...],\n' ) # coding: utf8\n{\n') for key in sorted(contents, lambda x, y: cmp(unicode(x, "utf-8").lower(), unicode(y, "utf-8").lower())): forms = "[" + ",".join([repr(Utf8(form)) for form in contents[key]]) + "]" fp.write("%s: %s,\n" % (repr(Utf8(key)), forms)) fp.write("}\n") except (IOError, OSError): if not is_gae: logging.warning("Unable to write to file %s" % filename) return finally: fp.close()