mirror of
https://github.com/python/cpython.git
synced 2025-07-28 05:34:31 +00:00
Merged revisions 59921-59932 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r59923 | raymond.hettinger | 2008-01-11 19:04:55 +0100 (Fri, 11 Jan 2008) | 1 line Speed-up and simplify code urlparse's result objects. ........ r59924 | andrew.kuchling | 2008-01-11 20:33:24 +0100 (Fri, 11 Jan 2008) | 1 line Bug #1790: update link; remove outdated paragraph ........ r59925 | thomas.heller | 2008-01-11 20:34:06 +0100 (Fri, 11 Jan 2008) | 5 lines Raise an error instead of crashing with a segfault when a NULL function pointer is called. Will backport to release25-maint. ........ r59927 | thomas.heller | 2008-01-11 21:29:19 +0100 (Fri, 11 Jan 2008) | 4 lines Fix a potential 'SystemError: NULL result without error'. NULL may be a valid return value from PyLong_AsVoidPtr. Will backport to release25-maint. ........ r59928 | raymond.hettinger | 2008-01-12 00:25:18 +0100 (Sat, 12 Jan 2008) | 1 line Update the opcode docs for STORE_MAP and BUILD_MAP ........ r59929 | mark.dickinson | 2008-01-12 02:56:00 +0100 (Sat, 12 Jan 2008) | 4 lines Issue 1780: Allow leading and trailing whitespace in Decimal constructor, when constructing from a string. Disallow trailing newlines in Context.create_decimal. ........ r59930 | georg.brandl | 2008-01-12 11:53:29 +0100 (Sat, 12 Jan 2008) | 3 lines Move OSError docs to exceptions doc, remove obsolete descriptions from os docs, rework posix docs. ........ r59931 | georg.brandl | 2008-01-12 14:47:57 +0100 (Sat, 12 Jan 2008) | 3 lines Patch #1700288: Method cache optimization, by Armin Rigo, ported to 2.6 by Kevin Jacobs. ........ r59932 | georg.brandl | 2008-01-12 17:11:09 +0100 (Sat, 12 Jan 2008) | 2 lines Fix editing glitch. ........
This commit is contained in:
parent
25bb783c03
commit
a62da1daaf
14 changed files with 317 additions and 141 deletions
|
@ -37,46 +37,11 @@ _parse_cache = {}
|
|||
|
||||
def clear_cache():
|
||||
"""Clear the parse cache."""
|
||||
global _parse_cache
|
||||
_parse_cache = {}
|
||||
_parse_cache.clear()
|
||||
|
||||
|
||||
class BaseResult(tuple):
|
||||
"""Base class for the parsed result objects.
|
||||
|
||||
This provides the attributes shared by the two derived result
|
||||
objects as read-only properties. The derived classes are
|
||||
responsible for checking the right number of arguments were
|
||||
supplied to the constructor.
|
||||
|
||||
"""
|
||||
|
||||
__slots__ = ()
|
||||
|
||||
# Attributes that access the basic components of the URL:
|
||||
|
||||
@property
|
||||
def scheme(self):
|
||||
return self[0]
|
||||
|
||||
@property
|
||||
def netloc(self):
|
||||
return self[1]
|
||||
|
||||
@property
|
||||
def path(self):
|
||||
return self[2]
|
||||
|
||||
@property
|
||||
def query(self):
|
||||
return self[-2]
|
||||
|
||||
@property
|
||||
def fragment(self):
|
||||
return self[-1]
|
||||
|
||||
# Additional attributes that provide access to parsed-out portions
|
||||
# of the netloc:
|
||||
class ResultMixin(object):
|
||||
"""Shared methods for the parsed result objects."""
|
||||
|
||||
@property
|
||||
def username(self):
|
||||
|
@ -116,31 +81,20 @@ class BaseResult(tuple):
|
|||
return int(port, 10)
|
||||
return None
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
class SplitResult(BaseResult):
|
||||
class SplitResult(namedtuple('SplitResult', 'scheme netloc path query fragment'), ResultMixin):
|
||||
|
||||
__slots__ = ()
|
||||
|
||||
def __new__(cls, scheme, netloc, path, query, fragment):
|
||||
return BaseResult.__new__(
|
||||
cls, (scheme, netloc, path, query, fragment))
|
||||
|
||||
def geturl(self):
|
||||
return urlunsplit(self)
|
||||
|
||||
|
||||
class ParseResult(BaseResult):
|
||||
class ParseResult(namedtuple('ParseResult', 'scheme netloc path params query fragment'), ResultMixin):
|
||||
|
||||
__slots__ = ()
|
||||
|
||||
def __new__(cls, scheme, netloc, path, params, query, fragment):
|
||||
return BaseResult.__new__(
|
||||
cls, (scheme, netloc, path, params, query, fragment))
|
||||
|
||||
@property
|
||||
def params(self):
|
||||
return self[3]
|
||||
|
||||
def geturl(self):
|
||||
return urlunparse(self)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue