def process(self, raw): processed = {} for (field, value) in raw.items(): if not value: continue elif field == 'key': processed[field] = self.cls(value) elif value.isdigit(): processed[field] = int(value) elif value.lower() in [u'true', u'false']: processed[field] = (value.lower() == u'true') elif isinstance(getattr(self, field, None), type): # Enum processed[field] = getattr(self, field)[value] else: processed[field] = value if 'rfc' in processed: processed['citation'] = RFC(processed.pop('rfc'), processed.pop('rfc_section', None), processed.pop('rfc_appendix', None)) if 'cite_url' in processed: processed['citation'] = Citation(processed.pop('cite_title', None), processed.pop('cite_url')) return processed
def extract_citations(self, record): for xref in record.findall('iana:xref', self.xmlns): if xref.get('type') == 'rfc': match = re.search( r'RFC(\d+), (Section|Appendix) ([A-Z0-9]+(\.[0-9]+)*)', xref.text or '') if match: num = int(match.group(1)) kw = match.group(2).lower() sect = RFC.parse_sect(match.group(3)) yield RFC(num, **{kw: sect}) else: num = int(xref.get('data')[3:]) yield RFC(num) elif xref.get('type') == 'uri': title = normalize_whitespace(xref.text) if xref.text else None url = xref.get('data') yield Citation(title, url)
{'_': MediaType(u'application/edi-consent'), '_citations': [RFC(1767)]}, {'_': MediaType(u'application/edifact'), '_citations': [RFC(1767)]}, {'_': MediaType(u'application/edi-x12'), '_citations': [RFC(1767)]}, {'_': MediaType(u'application/emergencycalldata.comment+xml'), '_citations': [RFC(7852)]}, {'_': MediaType(u'application/emergencycalldata.providerinfo+xml'), '_citations': [RFC(7852)]}, {'_': MediaType(u'application/emergencycalldata.serviceinfo+xml'), '_citations': [RFC(7852)]}, {'_': MediaType(u'application/emergencycalldata.deviceinfo+xml'), '_citations': [RFC(7852)]}, {'_': MediaType(u'application/emergencycalldata.subscriberinfo+xml'), '_citations': [RFC(7852)]}, {'_': MediaType(u'application/emma+xml'), '_citations': [Citation(None, u'http://www.w3.org/TR/2007/CR-emma-20071211/' u'#media-type-registration')]}, {'_': MediaType(u'application/encaprtp'), '_citations': [RFC(6849)]}, {'_': MediaType(u'application/epp+xml'), '_citations': [RFC(5730)]}, {'_': MediaType(u'application/example'), '_citations': [RFC(4735)]}, {'_': MediaType(u'application/exi'), '_citations': [Citation(None, u'http://www.w3.org/TR/2009/' u'CR-exi-20091208/#mediaTypeRegistration')]}, {'_': MediaType(u'application/fdt+xml'), '_citations': [RFC(6726)]}, {'_': MediaType(u'application/fits'), '_citations': [RFC(4047)]}, {'_': MediaType(u'application/font-tdpfr'), '_citations': [RFC(3073)]}, {'_': MediaType(u'application/framework-attributes+xml'), '_citations': [RFC(6230)]}, {'_': MediaType(u'application/geo+json'), '_citations': [RFC(7946)]}, {'_': MediaType(u'application/gzip'), '_citations': [RFC(6713)]},
'rule': MULTI }, { '_': FieldName(u'Accept-Ranges'), '_citations': [RFC(7233, section=(2, 3))], 'for_request': False, 'for_response': True, 'iana_status': u'standard', 'parser': rfc7233.Accept_Ranges, 'rule': SINGLE }, { '_': FieldName(u'Access-Control'), '_citations': [ Citation(u'W3C Web Application Formats Working Group', u'http://www.w3.org/2006/appformats/') ], 'iana_status': u'deprecated' }, { '_': FieldName(u'Access-Control-Allow-Credentials'), '_no_sync': ['_citations'], '_citations': [ Citation( u'W3C Cross-Origin Resource Sharing', u'https://www.w3.org/TR/cors/' u'#access-control-allow-credentials-' u'response-header') ]
# -*- coding: utf-8; -*- from httpolice.citation import RFC, Citation from httpolice.known.base import KnownDict from httpolice.structure import ContentCoding known = KnownDict(ContentCoding, [ {'_': ContentCoding(u'br'), '_citations': [RFC(7932)]}, {'_': ContentCoding(u'compress'), '_citations': [RFC(7230, section=(4, 2, 1))]}, {'_': ContentCoding(u'deflate'), '_citations': [RFC(7230, section=(4, 2, 2))]}, {'_': ContentCoding(u'exi'), '_citations': [Citation(u'W3C Recommendation: ' u'Efficient XML Interchange (EXI) Format', u'http://www.w3.org/TR/exi/')]}, {'_': ContentCoding(u'gzip'), '_citations': [RFC(7230, section=(4, 2, 3))]}, {'_': ContentCoding(u'identity'), '_citations': [RFC(7231, section=(5, 3, 4))]}, {'_': ContentCoding(u'pack200-gzip'), '_citations': [Citation(u'JSR 200: Network Transfer Format for Java', u'http://www.jcp.org/en/jsr/detail?id=200')]}, {'_': ContentCoding(u'x-compress'), '_citations': [RFC(7230, section=(4, 2, 1))]}, {'_': ContentCoding(u'x-gzip'), '_citations': [RFC(7230, section=(4, 2, 3))]} ])
# -*- coding: utf-8; -*- from httpolice.citation import Citation from httpolice.parse import fill_names, pivot from httpolice.syntax.rfc7230 import comma_list from httpolice.syntax.rfc7231 import media_range Accept_Post = comma_list(media_range()) > pivot fill_names( globals(), Citation(u'W3C Linked Data Platform 1.0', u'https://www.w3.org/TR/ldp/'))
from httpolice.parse import (auto, case_sens, fill_names, literal, maybe_str, pivot) from httpolice.syntax.rfc3986 import host, port, scheme from httpolice.syntax.rfc7230 import (comma_list, comma_list1, field_name, method) from httpolice.syntax.rfc7234 import delta_seconds # WHATWG actually uses their own definitions for scheme, host, and port, # but that's a bit too far for HTTPolice, we can live with RFC 3986. origin = scheme + '://' + host + maybe_str(':' + port) > pivot origin_or_null = origin | case_sens('null') > pivot Origin = origin_or_null > pivot Access_Control_Request_Method = method > pivot Access_Control_Request_Headers = comma_list1(field_name) > pivot wildcard = literal('*') > auto Access_Control_Allow_Origin = origin_or_null | wildcard > pivot Access_Control_Allow_Credentials = case_sens('true') > pivot Access_Control_Expose_Headers = comma_list(field_name) > pivot Access_Control_Max_Age = delta_seconds > pivot Access_Control_Allow_Methods = comma_list(method) > pivot Access_Control_Allow_Headers = comma_list(field_name) > pivot X_Content_Type_Options = literal('nosniff') > pivot Cross_Origin_Resource_Policy = (case_sens('same-origin') | case_sens('same-site')) > pivot fill_names(globals(), Citation(u'WHATWG Fetch', u'https://fetch.spec.whatwg.org/'))
# -*- coding: utf-8; -*- from httpolice.citation import Citation from httpolice.parse import fill_names, pivot from httpolice.syntax.rfc7230 import comma_list from httpolice.syntax.rfc7231 import media_range Accept_Post = comma_list(media_range()) > pivot fill_names( globals(), Citation(u'W3C Linked Data Platform 1.0', u'https://www.w3.org/TR/2015/REC-ldp-20150226/'))
# -*- coding: utf-8; -*- from httpolice.citation import RFC, Citation from httpolice.known.base import KnownDict from httpolice.structure import RelationType known = KnownDict(RelationType, [ {'_': RelationType(u'about'), '_citations': [RFC(6903, section=(2,))]}, {'_': RelationType(u'alternate'), '_citations': [Citation(None, u'http://www.w3.org/TR/html5/links.html' u'#link-type-alternate')]}, {'_': RelationType(u'appendix'), '_citations': [Citation(None, u'http://www.w3.org/TR/1999/REC-html401-19991224')]}, {'_': RelationType(u'archives'), '_citations': [Citation(None, u'http://www.w3.org/TR/2011/' u'WD-html5-20110113/links.html#rel-archives')]}, {'_': RelationType(u'author'), '_citations': [Citation(None, u'http://www.w3.org/TR/html5/links.html' u'#link-type-author')]}, {'_': RelationType(u'blocked-by'), '_citations': [RFC(7725, section=(4,))]}, {'_': RelationType(u'bookmark'), '_citations': [Citation(None, u'http://www.w3.org/TR/html5/links.html' u'#link-type-bookmark')]}, {'_': RelationType(u'canonical'), '_citations': [RFC(6596)]}, {'_': RelationType(u'chapter'),