def _set_mime_headers(self, headers): for name, value in headers: name = name.lower() if name == 'project-id-version': parts = value.split(' ') self.project = u' '.join(parts[:-1]) self.version = parts[-1] elif name == 'report-msgid-bugs-to': self.msgid_bugs_address = value elif name == 'last-translator': self.last_translator = value elif name == 'language': if value in MISSING_LOCALES: self.locale = Locale.parse( MISSING_LOCALES[value]['plural_rule']) else: self.locale = Locale.parse(value) elif name == 'language-team': self.language_team = value elif name == 'content-type': mimetype, params = parse_header(value) if 'charset' in params: self.charset = params['charset'].lower() elif name == 'plural-forms': _, params = parse_header(' ;' + value) self._num_plurals = int(params.get('nplurals', 2)) self._plural_expr = params.get('plural', '(n != 1)') elif name == 'pot-creation-date': self.creation_date = _parse_datetime_header(value) elif name == 'po-revision-date': # Keep the value if it's not the default one if 'YEAR' not in value: self.revision_date = _parse_datetime_header(value)
def test_datetime_parsing(): val1 = catalog._parse_datetime_header('2006-06-28 23:24+0200') assert val1.year == 2006 assert val1.month == 6 assert val1.day == 28 assert val1.tzinfo.zone == 'Etc/GMT+120' val2 = catalog._parse_datetime_header('2006-06-28 23:24') assert val2.year == 2006 assert val2.month == 6 assert val2.day == 28 assert val2.tzinfo is None