diff options
| author | Ira Lun <sammyrosajoe@gmail.com> | 2017-08-29 22:40:54 +0100 |
|---|---|---|
| committer | Ira Lun <sammyrosajoe@gmail.com> | 2017-08-29 22:40:54 +0100 |
| commit | cd7b5987160eb7337d16db0fbe6e5b2c37465832 (patch) | |
| tree | d345979de0d2893cc512f0e822d30df403535c6e /src | |
| parent | 5bdeb858539749887ae69f05cb484ea35a1b2bf8 (diff) | |
| download | webob-cd7b5987160eb7337d16db0fbe6e5b2c37465832.tar.gz | |
Remove MIMEAccept, MIMENilAccept and NilAccept.
Diffstat (limited to 'src')
| -rw-r--r-- | src/webob/acceptparse.py | 157 |
1 files changed, 0 insertions, 157 deletions
diff --git a/src/webob/acceptparse.py b/src/webob/acceptparse.py index 09ddbc9..60cb0df 100644 --- a/src/webob/acceptparse.py +++ b/src/webob/acceptparse.py @@ -1569,60 +1569,6 @@ def accept_property(): return property(fget, fset, fdel, textwrap.dedent(doc)) -class NilAccept(object): - """ - Represents a generic ``Accept-*`` style header when it is not present in - the request or is empty. - """ - MasterClass = Accept - - def __repr__(self): - return '<%s: %s>' % (self.__class__.__name__, self.MasterClass) - - def __str__(self): - return '' - - def __nonzero__(self): - return False - __bool__ = __nonzero__ # python 3 - - def __iter__(self): - return iter(()) - - def __add__(self, item): - if isinstance(item, self.MasterClass): - return item - else: - return self.MasterClass('') + item - - def __radd__(self, item): - if isinstance(item, self.MasterClass): - return item - else: - return item + self.MasterClass('') - - def __contains__(self, item): - _check_offer(item) - return True - - def quality(self, offer): - return 0 - - def best_match(self, offers, default_match=None): - best_quality = -1 - best_offer = default_match - for offer in offers: - _check_offer(offer) - if isinstance(offer, (list, tuple)): - offer, quality = offer - else: - quality = 1 - if quality > best_quality: - best_offer = offer - best_quality = quality - return best_offer - - class AcceptCharset(object): """ Represent an ``Accept-Charset`` header. @@ -5165,109 +5111,6 @@ def accept_language_property(): pass return property(fget, fset, fdel, textwrap.dedent(doc)) - - -class MIMEAccept(Accept): - """ - Represents an ``Accept`` header, which is a list of mimetypes. - - This class knows about mime wildcards, like ``image/*`` - """ - @staticmethod - def parse(value): - """ - Parse ``Accept`` header. - - Return iterator of ``(media range, qvalue)`` pairs. - """ - for mask, q in Accept.parse(value): - try: - mask_major, mask_minor = [x.lower() for x in mask.split('/')] - except ValueError: - continue - if mask_major == '*' and mask_minor != '*': - continue - if mask_major != "*" and "*" in mask_major: - continue - if mask_minor != "*" and "*" in mask_minor: - continue - yield ("%s/%s" % (mask_major, mask_minor), q) - - def accept_html(self): - """ - Returns true if any HTML-like type is accepted - """ - return ('text/html' in self - or 'application/xhtml+xml' in self - or 'application/xml' in self - or 'text/xml' in self) - - accepts_html = property(accept_html) # note the plural - - def _match(self, mask, offer): - """ - Check if the offer is covered by the mask - - ``offer`` may contain wildcards to facilitate checking if a - ``mask`` would match a 'permissive' offer. - - Wildcard matching forces the match to take place against the - type or subtype of the mask and offer (depending on where - the wildcard matches) - """ - # Match if comparisons are the same or either is a complete wildcard - if (mask.lower() == offer.lower() or - '*/*' in (mask, offer) or - '*' == offer): - return True - - # Set mask type with wildcard subtype for malformed masks - try: - mask_type, mask_subtype = [x.lower() for x in mask.split('/')] - except ValueError: - mask_type = mask - mask_subtype = '*' - - # Set offer type with wildcard subtype for malformed offers - try: - offer_type, offer_subtype = [x.lower() for x in offer.split('/')] - except ValueError: - offer_type = offer - offer_subtype = '*' - - if mask_subtype == '*': - # match on type only - if offer_type == '*': - return True - else: - return mask_type.lower() == offer_type.lower() - - if mask_type == '*': - # match on subtype only - if offer_subtype == '*': - return True - else: - return mask_subtype.lower() == offer_subtype.lower() - - if offer_subtype == '*': - # match on type only - return mask_type.lower() == offer_type.lower() - - if offer_type == '*': - # match on subtype only - return mask_subtype.lower() == offer_subtype.lower() - - return offer.lower() == mask.lower() - - - -class MIMENilAccept(NilAccept): - """ - Represents an ``Accept`` header when it is not present in the request or is - empty. - """ - MasterClass = MIMEAccept - def _check_offer(offer): if '*' in offer: raise ValueError("The application should offer specific types, got %r" % offer) |
