| 485 | return bytestring(self.string) |
| 486 | |
| 487 | def __unicode__(self): |
| 488 | # The string representation includes the query attributes with HTTP GET. |
| 489 | P = self.parts |
| 490 | u = [] |
| 491 | if P[PROTOCOL]: |
| 492 | u.append("%s://" % P[PROTOCOL]) |
| 493 | if P[USERNAME]: |
| 494 | u.append("%s:%s@" % (P[USERNAME], P[PASSWORD])) |
| 495 | if P[DOMAIN]: |
| 496 | u.append(P[DOMAIN]) |
| 497 | if P[PORT]: |
| 498 | u.append(":%s" % P[PORT]) |
| 499 | if P[PORT] or P[DOMAIN] and not P[PATH] and not P[PAGE]: |
| 500 | u.append("/") |
| 501 | if P[PATH]: |
| 502 | u.append("/%s/" % "/".join(P[PATH])) |
| 503 | if P[PAGE] and len(u) > 0: |
| 504 | u[-1] = u[-1].rstrip("/") |
| 505 | if P[PAGE]: |
| 506 | u.append("/%s" % P[PAGE]) |
| 507 | if P[QUERY] and self.method == GET: |
| 508 | u.append("?%s" % self.querystring) |
| 509 | if P[ANCHOR]: |
| 510 | u.append("#%s" % P[ANCHOR]) |
| 511 | u = u"".join(u) |
| 512 | u = u.lstrip("/") |
| 513 | return u |
| 514 | |
| 515 | def __repr__(self): |
| 516 | return "URL('%s', method='%s')" % (str(self), str(self.method)) |