diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2016-08-03 10:38:42 -0400 |
---|---|---|
committer | Jason R. Coombs <jaraco@jaraco.com> | 2016-08-03 10:38:42 -0400 |
commit | d694cc7cdd23e5a8fd5155db067909dc4fcda616 (patch) | |
tree | b40861dec6413d984345b51f063d77920e80aad7 /cherrypy/lib/httputil.py | |
parent | e6719a4ad879b87f1861947f75373aaa256fb0a9 (diff) | |
download | cherrypy-git-d694cc7cdd23e5a8fd5155db067909dc4fcda616.tar.gz |
Use decorators where appropriate.
Diffstat (limited to 'cherrypy/lib/httputil.py')
-rw-r--r-- | cherrypy/lib/httputil.py | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/cherrypy/lib/httputil.py b/cherrypy/lib/httputil.py index 78cc4039..b23933da 100644 --- a/cherrypy/lib/httputil.py +++ b/cherrypy/lib/httputil.py @@ -149,17 +149,17 @@ class HeaderElement(object): def __unicode__(self): return ntou(self.__str__()) + @staticmethod def parse(elementstr): """Transform 'token;key=val' to ('token', {'key': 'val'}).""" initial_value, params = parse_header(elementstr) return initial_value, params - parse = staticmethod(parse) + @classmethod def from_str(cls, elementstr): """Construct an instance from a string of the form 'token;key=val'.""" ival, params = cls.parse(elementstr) return cls(ival, params) - from_str = classmethod(from_str) q_separator = re.compile(r'; *q *=') @@ -176,6 +176,7 @@ class AcceptElement(HeaderElement): have been the other way around, but it's too late to fix now. """ + @classmethod def from_str(cls, elementstr): qvalue = None # The first "q" parameter (if any) separates the initial @@ -191,14 +192,14 @@ class AcceptElement(HeaderElement): if qvalue is not None: params["q"] = qvalue return cls(media_type, params) - from_str = classmethod(from_str) + @property def qvalue(self): + "The qvalue, or priority, of this value." val = self.params.get("q", "1") if isinstance(val, HeaderElement): val = val.value return float(val) - qvalue = property(qvalue, doc="The qvalue, or priority, of this value.") def __cmp__(self, other): diff = cmp(self.qvalue, other.qvalue) @@ -389,12 +390,12 @@ class CaseInsensitiveDict(dict): for k in E.keys(): self[str(k).title()] = E[k] + @classmethod def fromkeys(cls, seq, value=None): newdict = cls() for k in seq: newdict[str(k).title()] = value return newdict - fromkeys = classmethod(fromkeys) def setdefault(self, key, x=None): key = str(key).title() @@ -456,6 +457,7 @@ class HeaderMap(CaseInsensitiveDict): """Transform self into a list of (name, value) tuples.""" return list(self.encode_header_items(self.items())) + @classmethod def encode_header_items(cls, header_items): """ Prepare the sequence of name, value tuples into a form suitable for @@ -479,8 +481,8 @@ class HeaderMap(CaseInsensitiveDict): header_translate_deletechars) yield (k, v) - encode_header_items = classmethod(encode_header_items) + @classmethod def encode(cls, v): """Return the given header name or value, encoded for HTTP output.""" for enc in cls.encodings: @@ -501,7 +503,6 @@ class HeaderMap(CaseInsensitiveDict): raise ValueError("Could not encode header part %r using " "any of the encodings %r." % (v, cls.encodings)) - encode = classmethod(encode) class Host(object): |