@@ -797,25 +797,29 @@ class URL(object):
797797 constructor arguments is below.
798798
799799 Args:
800- scheme: The text name of the scheme.
801- host: The host portion of the network location
802- port: The port part of the network location. If ``None`` or no port is
803- passed, the port will default to the default port of the scheme, if
804- it is known. See the ``SCHEME_PORT_MAP`` and
805- :func:`register_default_port` for more info.
806- path: A tuple of strings representing the slash-separated parts of the
807- path.
808- query: The query parameters, as a dictionary or as an iterable of
809- key-value pairs.
810- fragment: The fragment part of the URL.
811- rooted: Whether or not the path begins with a slash.
812- userinfo: The username or colon-separated username:password pair.
813- uses_netloc: Indicates whether two slashes appear between the scheme
814- and the host (``http://eg.com`` vs. ``mailto:e@g.com``).
815- Set automatically based on scheme.
816-
817- All of these parts are also exposed as read-only attributes of URL
818- instances, along with several useful methods.
800+ scheme: The text name of the scheme.
801+ host: The host portion of the network location
802+ port: The port part of the network location. If
803+ ``None`` or no port is passed, the port will default to
804+ the default port of the scheme, if it is known. See the
805+ ``SCHEME_PORT_MAP`` and :func:`register_default_port`
806+ for more info.
807+ path: A tuple of strings representing the
808+ slash-separated parts of the path.
809+ query: The query parameters, as a dictionary or
810+ as an iterable of key-value pairs.
811+ fragment: The fragment part of the URL.
812+ rooted: A rooted URL is one which indicates an absolute path.
813+ This is True on any URL that includes a host, or any relative URL
814+ that starts with a slash.
815+ userinfo: The username or colon-separated
816+ username:password pair.
817+ uses_netloc: Indicates whether two slashes appear
818+ between the scheme and the host (``http://eg.com`` vs
819+ ``mailto:e@g.com``). Set automatically based on scheme.
820+
821+ All of these parts are also exposed as read-only attributes of
822+ URL instances, along with several useful methods.
819823
820824 .. _RFC 3986: https://tools.ietf.org/html/rfc3986
821825 .. _RFC 3987: https://tools.ietf.org/html/rfc3987
@@ -880,8 +884,12 @@ def __init__(
880884 uses_netloc = scheme_uses_netloc (self ._scheme , uses_netloc )
881885 self ._uses_netloc = _typecheck ("uses_netloc" ,
882886 uses_netloc , bool , NoneType )
883-
884- return
887+ # fixup for rooted consistency
888+ if self ._host :
889+ self ._rooted = True
890+ if (not self ._rooted ) and self ._path and self ._path [0 ] == '' :
891+ self ._rooted = True
892+ self ._path = self ._path [1 :]
885893
886894 def get_decoded_url (self , lazy = False ):
887895 # type: (bool) -> DecodedURL
@@ -1051,7 +1059,7 @@ def __eq__(self, other):
10511059 if not isinstance (other , self .__class__ ):
10521060 return NotImplemented
10531061 for attr in ['scheme' , 'userinfo' , 'host' , 'query' ,
1054- 'fragment' , 'port' , 'uses_netloc' ]:
1062+ 'fragment' , 'port' , 'uses_netloc' , 'rooted' ]:
10551063 if getattr (self , attr ) != getattr (other , attr ):
10561064 return False
10571065 if (
0 commit comments