Esempio n. 1
0
 def _from_record(self, record):
     toplevel = record.getparent().get('id')
     subtype = record.find('iana:name', self.xmlns).text.lower()
     if subtype.startswith('vnd.') or subtype.startswith('prs.'):
         return None
     if len(subtype.split()) > 1:
         if ('deprecated' in subtype) or ('obsoleted' in subtype):
             entry = {'deprecated': True}
             subtype = subtype.split()[0]
         else:
             return None
     else:
         entry = {}
     entry['key'] = MediaType(u'%s/%s' % (toplevel, subtype))
     entry['citation'] = self.extract_citation(record)
     return entry
Esempio n. 2
0
#     Whether this media type is a patch, usable with the PATCH method
#     (see RFC 5789 errata).
#
#   ``is_json``
#     Set this to ``True`` if the media type uses JSON syntax
#     but **does not end** with ``+json``.
#
#   ``is_xml``
#     Set this to ``True`` if the media type uses XML syntax
#     but **does not end** with ``+xml``.
#
#   ``deprecated``
#     Filled by ``tools/iana.py``. You should not need to change it.

known = KnownDict(MediaType, [
 {'_': MediaType(u'application/1d-interleaved-parityfec'),
  '_citations': [RFC(6015)]},
 {'_': MediaType(u'application/alto-costmap+json'), '_citations': [RFC(7285)]},
 {'_': MediaType(u'application/alto-costmapfilter+json'),
  '_citations': [RFC(7285)]},
 {'_': MediaType(u'application/alto-directory+json'),
  '_citations': [RFC(7285)]},
 {'_': MediaType(u'application/alto-endpointprop+json'),
  '_citations': [RFC(7285)]},
 {'_': MediaType(u'application/alto-endpointpropparams+json'),
  '_citations': [RFC(7285)]},
 {'_': MediaType(u'application/alto-endpointcost+json'),
  '_citations': [RFC(7285)]},
 {'_': MediaType(u'application/alto-endpointcostparams+json'),
  '_citations': [RFC(7285)]},
 {'_': MediaType(u'application/alto-error+json'), '_citations': [RFC(7285)]},
Esempio n. 3
0
from httpolice.syntax.rfc3986 import URI_reference, absolute_URI
from httpolice.syntax.rfc4647 import language_range
from httpolice.syntax.rfc5646 import Language_Tag as language_tag
from httpolice.syntax.rfc7230 import (OWS, RWS, comma_list, comma_list1,
                                      comment, field_name, method, partial_URI,
                                      quoted_string, token, token__excluding)

# The standard library's `calendar.day_name` is locale-dependent,
# which brings in Unicode problems.
_DAY_NAMES = [
    u'Monday', u'Tuesday', u'Wednesday', u'Thursday', u'Friday', u'Saturady',
    u'Sunday'
]

_BAD_MEDIA_TYPES = {
    MediaType(u'plain/text'): MediaType(u'text/plain'),
    MediaType(u'text/json'): MediaType(u'application/json'),
}


@can_complain
def _check_media_type(complain, mtype):
    if mtype in _BAD_MEDIA_TYPES:
        complain(1282, bad=mtype, good=_BAD_MEDIA_TYPES[mtype])
    return mtype


def parameter(exclude=None):
    return ((CaseInsensitive << token__excluding(exclude or [])) * skip('=') *
            (token | quoted_string)) > named(
                u'parameter', RFC(7231), is_pivot=True)
Esempio n. 4
0
from httpolice.citation import RFC
from httpolice.known import media
from httpolice.parse import auto, can_complain, fill_names, octet, octet_range
from httpolice.structure import MediaType

ALPHA = octet_range(0x41, 0x5A) | octet_range(0x61, 0x7A) > auto
CHAR = octet_range(0x01, 0x7F) > auto
CTL = octet_range(0x00, 0x1F) | octet(0x7F) > auto
DIGIT = octet_range(0x30, 0x39) > auto
DQUOTE = octet(0x22) > auto
HEXDIG = DIGIT | 'A' | 'B' | 'C' | 'D' | 'E' | 'F' > auto
HTAB = octet(0x09) > auto
SP = octet(0x20) > auto
VCHAR = octet_range(0x21, 0x7E) > auto

_BAD_MEDIA_TYPES = {
    MediaType(u'plain/text'): media.text_plain,
    MediaType(u'text/json'): media.application_json,
}


@can_complain
def check_media_type(complain, mtype):
    if mtype in _BAD_MEDIA_TYPES:
        complain(1282, bad=mtype, good=_BAD_MEDIA_TYPES[mtype])
    return mtype


fill_names(globals(), RFC(5234))