Changeset 1664
- Timestamp:
- 06/16/07 15:36:00
- Files:
-
- trunk/cherrypy/lib/http.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/cherrypy/lib/http.py
r1638 r1664 131 131 132 132 class AcceptElement(HeaderElement): 133 """An element (with parameters) from an Accept-* header's element list.""" 133 """An element (with parameters) from an Accept* header's element list. 134 135 AcceptElement objects are comparable; the more-preferred object will be 136 "less than" the less-preferred object. They are also therefore sortable; 137 if you sort a list of AcceptElement objects, they will be listed in 138 priority order; the most preferred value will be first. Yes, it should 139 have been the other way around, but it's too late to fix now. 140 """ 134 141 135 142 def from_str(cls, elementstr): 136 143 qvalue = None 137 144 # The first "q" parameter (if any) separates the initial 138 # parameter(s) (if any) from the accept-params.145 # media-range parameter(s) (if any) from the accept-params. 139 146 atoms = q_separator.split(elementstr, 1) 140 initial_value = atoms.pop(0).strip()147 media_range = atoms.pop(0).strip() 141 148 if atoms: 142 149 # The qvalue for an Accept header can have extensions. The other … … 144 151 qvalue = HeaderElement.from_str(atoms[0].strip()) 145 152 146 ival, params = cls.parse(initial_value)153 media_type, params = cls.parse(media_range) 147 154 if qvalue is not None: 148 155 params["q"] = qvalue 149 return cls( ival, params)156 return cls(media_type, params) 150 157 from_str = classmethod(from_str) 151 158 … … 158 165 159 166 def __cmp__(self, other): 160 # If you sort a list of AcceptElement objects, they will be listed161 # in priority order; the most preferred value will be first.162 167 diff = cmp(other.qvalue, self.qvalue) 163 168 if diff == 0:

