Parses an HTTP sig line and returns a HTTP_Signature object
(cls, sig_line)
| 276 | |
| 277 | @classmethod |
| 278 | def from_raw_sig(cls, sig_line): |
| 279 | """ |
| 280 | Parses an HTTP sig line and returns a HTTP_Signature object |
| 281 | """ |
| 282 | ver, horder, habsent, expsw = lparse(sig_line, 4) |
| 283 | http_ver = -1 if ver == "*" else int(ver) |
| 284 | |
| 285 | # horder parsing - split by commas that aren't in [] |
| 286 | new_horder = [] |
| 287 | for header in re.split(r",(?![^\[]*\])", horder): |
| 288 | name, _, value = header.partition("=") |
| 289 | if name[0] == "?": # Optional header |
| 290 | new_horder.append((name[1:], value[1:-1], True)) |
| 291 | else: |
| 292 | new_horder.append((name, value[1:-1], False)) |
| 293 | hdr = tuple(new_horder) |
| 294 | hdr_set = frozenset(header[0] for header in hdr if not header[2]) |
| 295 | habsent = frozenset(habsent.split(",")) |
| 296 | return cls(http_ver, hdr, hdr_set, habsent, expsw) |
| 297 | |
| 298 | def __str__(self): |
| 299 | # values that depend on the context are not included in the string |