Skip to content

Commit

Permalink
more clearly define specificity constants
Browse files Browse the repository at this point in the history
  • Loading branch information
mmerickel committed Sep 27, 2018
1 parent 9d361a4 commit 206b6c5
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/webob/acceptparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,25 @@ def _list_1_or_more__compiled_re(element_re):
class AcceptOffer(namedtuple('AcceptOffer', ['type', 'subtype', 'params'])):
__slots__ = ()

SPECIFICITY_ANY = 1 # */*
SPECIFICITY_TYPE = 2 # text/*
SPECIFICITY_SUBTYPE = 3 # text/html
SPECIFICITY_PARAMS = 4 # text/html;charset=utf8

@property
def is_range(self):
return self.type == '*' or self.subtype == '*'

@property
def specificity(self):
if self.params:
return 4
return self.SPECIFICITY_PARAMS
elif self.subtype != '*':
return 3
return self.SPECIFICITY_SUBTYPE
elif self.type != '*':
return 2
return self.SPECIFICITY_TYPE
else:
return 1
return self.SPECIFICITY_ANY


class Accept(object):
Expand Down

0 comments on commit 206b6c5

Please sign in to comment.