a _b)/@s4ddlZddlZddlZddlmZddlmZddlZddlm Z ddl m Z m Z zddl mZWney~ddZYn0d d lmZd d lmZmZd d lmZmZmZd dddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d"d.d*d/d0d1d2d3d4ddd5d6.Zdd7d8Zd9d:Zefd;d<Zd=d>Zd?d@ZdAdBZdCdDZ dEdFZ!dGdHZ"dIZ#dJZ$e!e%dKe&dLe#fdMdNdOZ'e!e%dKe&dPe#fdMdQdRZ(e!e%dKe&dSe#fdMdTdUZ)e!e%dVdMdWdXZ*e!e%dYe&e$dMdZd[Z+d\d]Z,d^d_Z-d`daZ.dbdcZ/dddeZ0dfdgZ1dhdiZ2djdkZ3dldmZ4Gdndodoe5Z6e7ej8Gdpdqdqe5Z9e7ej8Gdrdsdse9Z:e7ej8Gdtdudue9Z;Gdvdwdwe5Ze7ej8Gd|d}d}e5Z?Gd~dde:e=e?eZ@dS)N)deepcopy)normpath)urllib)quoteunquote)iccGs |sdSt|dkr|dS|S)Nr)len)ar 0/tmp/pip-target-4jja1joz/lib/python/furl/furl.pyr r)omdict1D) string_types UnicodeMixin) callable_attris_iterable_but_not_stringabsentii$iD 5i$FiQ Piiwi)ii|ii' iowi3niiiii*iBiiiiijEii if).ZacapZafpdictZdnsftpgitgopherhdlhttphttpsimapZippZippsircZircsZldapZldapsmmsZmsrpZmtqpnfsnntpZnntpspopprosperoZredisrsyncrtspZrtspsrtspusftpsipsipssmbsnewsZsnmpsshsvntelnetZtftpZventriloZvncwaiswswssZxmppcCs&z ||WSty |YS0dSN) IndexError)lstindexdefaultr r r lget\s  rDcCs&z t|WSty |YS0dSr?)str Exceptionor r r attemptstrcs  rIcCs4z |dWSty.|tur&|n|YS0dS)Nutf8)encoderF_absent)rHrCr r r rJjs  rJcCst|dot|t S)N__iter__)r isinstancerrGr r r non_string_iterableqsrOcCs"t|drt|ddS|S)NrKidnarJ)rrErKdecoderGr r r idna_encodews rRcCs tt|drt|dS|S)NrQrP)rrJrQrGr r r idna_decode}srScCs2t|}|r*dt|kr(dks.ndSdS)NriFT)rEisdigitint)portr r r is_valid_ports"rWc sfdd}|S)Ncs$tD]\}}t|||q |Sr?)six iteritemssetattr)funckeyvaluekwargsr r decoratorszstatic_vars..decoratorr )r_r`r r^r static_varss racsfdd}|S)NcsT|dur}n|durd}n|}dt|t@}t||}rP|dd}|S)NTFz%20+)joinsetrreplace)s dont_quotesafequoted quote_plus safe_charsetr r quote_fns  z!create_quote_fn..quote_fnr )rmrlrnr rkr create_quote_fnsroz\%[a-fA-F\d][a-fA-F\d]z!@#$%^&'"*()+=:;/z^([\w%s]|(%s))*$z-.~:@!$&'()*+,;=)regexcCstj|duSr?)is_valid_encoded_path_segmentrpmatch)segmentr r r rqsrqz-.~:@!$&'()*+,;/?cCstj|duSr?)is_valid_encoded_query_keyrprr)r\r r r rtsrtz-.~:@!$&'()*+,;/?=cCstj|duSr?)is_valid_encoded_query_valuerprr)r]r r r rusruz[a-zA-Z][a-zA-Z\-\.\+]*cCstj|duSr?)is_valid_schemerprr)schemer r r rvsrvz[%s]cCsF|d}|ddkr||D]}tj|dur"dSq"d|vS)N.rbF)splitr/ is_valid_hostrpsearch)hostnametokstokr r r r{s  r{cCsr|drdS|ddd}|ddd}|ddd}|dtd|dpXd}|durnt|sndS|S)N:rb#rr?/) startswithrzmaxfindrv)urlZ no_fragmentZno_queryZno_path_or_netlocrwr r r get_schemes rcCs6t|p d}|t|d}|dr2|dd}|S)Nrbrr)rr rrrwr r r strip_schemes    rcCs$t|}|dur|Sd||fSdS)Nz%s:%s)r)rrw after_schemer r r set_schemesrcCs"t|}||durdn|dS)N//://)rrrr r r has_netlocsrcCsht|}|durt|d}tj|\}}}}}t|}|drL|pHd}nd}|}tj|||||S)ad Parameters: url: URL string to split. Returns: urlparse.SplitResult tuple subclass, just like urlparse.urlsplit() returns, with fields (scheme, netloc, path, query, fragment, username, password, hostname, port). See http://docs.python.org/library/urlparse.html#urlparse.urlsplit for more details on urlsplit(). Nr(rrb)rrrparseurlsplitrr SplitResult)rZoriginal_schemerwnetlocpathqueryfragmentrr r r rs    rcCs|t|rt|nd}t|r$t|nd}|dur. url: Relative or absolute URL to join with . Returns: The resultant URL from joining and . Nr()rrrrrurljoin)baserZ base_scheme url_schemerootZjoined new_schemer r r rGs  rcGsg}|D]}|r|dgkrqq|s.||q|ddkr^|ddksRt|dkr^|dn0|ddkr|ddkrt|dkr|dd}||q|S)a Join multiple lists of path segments together, intelligently handling path segments borders to preserve intended slashes of the final constructed path. This function is not encoding aware. It doesn't test for, or change, the encoding of path segments it is passed. Examples: join_path_segments(['a'], ['b']) == ['a','b'] join_path_segments(['a',''], ['b']) == ['a','b'] join_path_segments(['a'], ['','b']) == ['a','b'] join_path_segments(['a',''], ['','b']) == ['a','','b'] join_path_segments(['a','b'], ['c','d']) == ['a','b','c','d'] Returns: A list containing the joined path segments. rbryrrN)extendr r/)argsZfinalssegmentsr r r join_path_segmentsks $ $  rcCs|dgkr|d|dgkr(|dd}||kr:g}nt|t|krP|}n~t|}t|dkrz|ddkrz|d|r||dt|dkr|dt|t|}|ddkr|r|dn|}|S)a1 Removes the path segments of from the end of the path segments . Examples: # ('/a/b/c', 'b/c') -> '/a/' remove_path_segments(['','a','b','c'], ['b','c']) == ['','a',''] # ('/a/b/c', '/b/c') -> '/a' remove_path_segments(['','a','b','c'], ['','b','c']) == ['','a'] Returns: The list of all remaining path segments after the segments in have been removed from the end of . If no segments from were removed from , is returned unmodified. rbNrrry)appendr listr/)rremoveretZtoremover r r remove_path_segmentss$      rcCst|dot|jS)Nr)hasattrrr)objr r r quacks_like_a_path_with_segmentss rc@seZdZdZdZddddfddZd d Zd d Zd dZddZ ddZ ddZ e ddZ e jddZ e ddZe ddZddZddZd d!Zd"d#ZeZd$d%Zd&d'Zd(d)Zd*d+Zd,S)-Patha Represents a path comprised of zero or more path segments. http://tools.ietf.org/html/rfc3986#section-3.3 Path parameters aren't supported. Attributes: _force_absolute: Function whos boolean return value specifies whether self.isabsolute should be forced to True or not. If _force_absolute(self) returns True, isabsolute is read only and raises an AttributeError if assigned to. If _force_absolute(self) returns False, isabsolute is mutable and can be set to True or False. URL paths use _force_absolute and return True if the netloc is non-empty (not equal to ''). Fragment paths are never read-only and their _force_absolute(self) always returns False. segments: List of zero or more path segments comprising this path. If the path string has a trailing '/', the last segment will be '' and self.isdir will be True and self.isfile will be False. An empty segment list represents an empty path, not '/' (though they have the same meaning). isabsolute: Boolean whether or not this is an absolute path or not. An absolute path starts with a '/'. self.isabsolute is False if the path is empty (self.segments == [] and str(path) == ''). strict: Boolean whether or not UserWarnings should be raised if improperly encoded path strings are provided to methods that take such strings, like load(), add(), set(), remove(), etc. z:@-._~!$&'()*+,;=rbcCsdSNFr )_r r r r rz Path.FcCs&g|_||_d|_||_||dSr)rstrict _isabsolute_force_absoluteload)selfrforce_absoluterr r r __init__s z Path.__init__cCs|s g}n(t|r|j}nt|r(|}n ||}||rL|rDdnd|_n|oZ|ddk|_|jrt|dkr|ddkr|d||_|S)z Load , replacing any existing path. can either be a Path instance, a list of segments, a path string to adopt. Returns: . TFrrbr) rrr_segments_from_pathrr isabsoluter r/)rrrr r r rs   z Path.loadcCst|r|j}nt|r|}n ||}|jdgkrP|rP|ddkrP|dd|j}|jr||jr||jddkr||dd|t|||S)z Add to the existing path. can either be a Path instance, a list of segments, or a path string to append to the existing path. Returns: . rbr)rrrrinsertrrr)rrZ newsegmentsrr r r adds   zPath.addcCs|||Sr?rrrr r r re+s zPath.setcCsV|dur|dn>t|r"|}n ||}|jr8dgng|j}|t|||SNTrb)rrrrrr)rrrrr r r r/s  z Path.removecCsDt|r@tt|d|j}|dr6d|d}|||S)zc Normalize the path. Turn '//a/./b/../c//' into '/a/c/'. Returns: . rr)rErisdirrlstripr)r normalizedr r r normalize<s   zPath.normalizecCst||j|j|j|jdS)N)encodedrisfilerr)rErrrrrr r r asdictJs z Path.asdictcCs||rdS|jS)NT)rrrr r r rSs zPath.isabsolutecCs ||rd}t|||_dS)zO Raises: AttributeError if _force_absolute(self) returns True. zPath.isabsolute is True and read-only for URLs with a netloc (a username, password, host, and/or port). A URL path must start with a '/' to separate itself from a netloc.N)rAttributeErrorr)rrrgr r r rYs cCs|jgkp|jo|jddkS)z Returns: True if the path ends on a directory, False otherwise. If True, the last segment is '', representing the trailing '/' of the path. ryrb)rrr r r res z Path.isdircCs|j S)z Returns: True if the path ends on a file, False otherwise. If True, the last segment is not '', representing some file as the last segment of the path. )rrr r r rosz Path.isfilecCst|}||Sr?)rr)rrcopyr r r __truediv__xszPath.__truediv__cCst|t|kSr?rErotherr r r __eq__|sz Path.__eq__cCs ||k Sr?r rr r r __ne__sz Path.__ne__cCst|jdkSNr)r rrr r r __bool__sz Path.__bool__cCs4t|j}|jr*|sddg}n |dd||S)Nrbr)rrrr_path_from_segmentsrrr r r __str__s    z Path.__str__cCsd|jjt|fSNz%s('%s') __class____name__rErr r r __repr__sz Path.__repr__cCsxg}|dD]J}t|sJtt|}|jrJd|||f}t|t| t|q~dd|D}dd|DS)aV Returns: The list of path segments from the path string . Raises: UserWarning if is an improperly encoded path string and self.strict is True. TODO(grun): Accept both list values and string values and refactor the list vs string interface testing to this common method. rzQImproperly encoded path string received: '%s'. Proceeding, but did you mean '%s'?cSs.g|]&}t|tr&t|ts&|dn|qS)rJ)rNbytesrErQ.0rsr r r s  z,Path._segments_from_path..cSsg|] }t|qSr )rrr r r rr) rzrqrrJrrwarningswarn UserWarningr)rrrrsrgr r r rs    zPath._segments_from_pathcsfdd|D}d|S)z Combine the provided path segments into a path string. Path segments in will be quoted. Returns: A path string with quoted path segments. cs g|]}ttt|jqSr )rrJrISAFE_SEGMENT_CHARSrrr r rsz,Path._path_from_segments..r)rdrr rr rs zPath._path_from_segmentsN)r __module__ __qualname____doc__rrrrrerrrpropertyrsetterrrrrrr __nonzero__rrrrr r r r rs4%        !rc@sHeZdZdZdddZeddZeddZej d d Z d d Z d S)PathCompositionInterfacezK Abstract class interface for a parent class that contains a Path. FcCst|j|d|_dS)z Params: force_absolute: See Path._force_absolute. Assignments to in __init__() must be added to __setattr__() below. )rrN)rr_pathrrr r r rsz!PathCompositionInterface.__init__cCs|jSr?)rrr r r rszPathCompositionInterface.pathcCsd}t|tt|jS)z6This method is deprecated. Use str(furl.path) instead.zfurl.pathstr is deprecated. Use str(furl.path) instead. There should be one, and preferably only one, obvious way to serialize a Path object to a string.)rrDeprecationWarningrErrrgr r r pathstrs z PathCompositionInterface.pathstrcCsdS)z Subclass me. Nr rr r r rsz(PathCompositionInterface._force_absolutecCs2|dkr||j|<dS|dkr.|j|dSdS)c Returns: True if this attribute is handled and set here, False otherwise. rTrF)__dict__rrrattrr]r r r __setattr__s  z$PathCompositionInterface.__setattr__N)F) rrrrrrrrabcabstractmethodrrr r r r rs    rc@s"eZdZdZdddZddZdS) URLPathCompositionInterfacea Abstract class interface for a parent class that contains a URL Path. A URL path's isabsolute attribute is absolute and read-only if a netloc is defined. A path cannot start without '/' if there's a netloc. For example, the URL 'http://google.coma/path' makes no sense. It should be 'http://google.com/a/path'. A URL path's isabsolute attribute is mutable if there's no netloc. The scheme doesn't matter. For example, the isabsolute attribute of the URL path in 'mailto:user@host.com', with scheme 'mailto' and path 'user@host.com', is mutable because there is no netloc. See http://en.wikipedia.org/wiki/URI_scheme#Examples FcCstj||ddSNrrrrr r r rsz$URLPathCompositionInterface.__init__cCst|o |jSr?)boolrrr r r r sz+URLPathCompositionInterface._force_absoluteN)Frrrrrrr r r r rs rc@s"eZdZdZdddZddZdS) FragmentPathCompositionInterfacez Abstract class interface for a parent class that contains a Fragment Path. Fragment Paths they be set to absolute (self.isabsolute = True) or not absolute (self.isabsolute = False). FcCstj||ddSrrrr r r rsz)FragmentPathCompositionInterface.__init__cCsdSrr rr r r rsz0FragmentPathCompositionInterface._force_absoluteN)Frr r r r rs rc@seZdZdZdZedZd(ddZdd Zd d Zd d Z ddZ e ddZ e j ddZ dddefddZddZddZddZddZeZdd Zd!d"Zd#d$Zd%d&Zd'S))QueryaU Represents a URL query comprised of zero or more unique parameters and their respective values. http://tools.ietf.org/html/rfc3986#section-3.4 All interaction with Query.params is done with unquoted strings. So f.query.params['a'] = 'a%5E' means the intended value for 'a' is 'a%5E', not 'a^'. Query.params is implemented as an omdict1D object - a one dimensional ordered multivalue dictionary. This provides support for repeated URL parameters, like 'a=1&a=2'. omdict1D is a subclass of omdict, an ordered multivalue dictionary. Documentation for omdict can be found here https://github.com/gruns/orderedmultidict The one dimensional aspect of omdict1D means that a list of values is interpreted as multiple values, not a single value which is itself a list of values. This is a reasonable distinction to make because URL query parameters are one dimensional: query parameter values cannot themselves be composed of sub-values. So what does this mean? This means we can safely interpret f = furl('http://www.google.com') f.query.params['arg'] = ['one', 'two', 'three'] as three different values for 'arg': 'one', 'two', and 'three', instead of a single value which is itself some serialization of the python list ['one', 'two', 'three']. Thus, the result of the above will be f.query.allitems() == [ ('arg','one'), ('arg','two'), ('arg','three')] and not f.query.allitems() == [('arg', ['one', 'two', 'three'])] The latter doesn't make sense because query parameter values cannot be composed of sub-values. So finally str(f.query) == 'arg=one&arg=two&arg=three' Additionally, while the set of allowed characters in URL queries is defined in RFC 3986 section 3.4, the format for encoding key=value pairs within the query is not. In turn, the parsing of encoded key=value query pairs differs between implementations. As a compromise to support equal signs in both key=value pair encoded queries, like https://www.google.com?a=1&b=2 and non-key=value pair encoded queries, like https://www.google.com?===3=== equal signs are percent encoded in key=value pairs where the key is non-empty, e.g. https://www.google.com?equal-sign=%3D but not encoded in key=value pairs where the key is empty, e.g. https://www.google.com?===equal=sign=== This presents a reasonable compromise to accurately reproduce non-key=value queries with equal signs while also still percent encoding equal signs in key=value pair encoded queries, as expected. See https://github.com/gruns/furl/issues/99 for more details. Attributes: params: Ordered multivalue dictionary of query parameter key:value pairs. Parameters in self.params are maintained URL decoded, e.g. 'a b' not 'a+b'. strict: Boolean whether or not UserWarnings should be raised if improperly encoded query strings are provided to methods that take such strings, like load(), add(), set(), remove(), etc. z/?:@-._~!$'()*+,;=rbFcCs||_t|_||dSr?)rr_paramsr)rrrr r r rszQuery.__init__cCs||}|j||Sr?)_itemsparamsr)rritemsr r r rs  z Query.loadcCs&||D]\}}|j||q |Sr?)rrr)rrparamr]r r r rsz Query.addcCs|j||S)a Adopt all mappings in , replacing any existing mappings with the same key. If a key has multiple values in , they are all adopted. Examples: Query({1:1}).set([(1,None),(2,2)]).params.allitems() == [(1,None),(2,2)] Query({1:None,2:None}).set([(1,1),(2,2),(1,11)]).params.allitems() == [(1,1),(2,2),(1,11)] Query({1:None}).set([(1,[1,11,111])]).params.allitems() == [(1,1),(1,11),(1,111)] Returns: . )rZ updateall)rmappingr r r res z Query.setcCs|dur|d|S|g}t|dr2||}n t|r>|}|D]D}t|rtt|dkrt|\}}|j||dqB|}|j|dqB|S)NTrbr)rrrrOr rZpopvaluer/)rrritemr\r]r r r rs   z Query.removecCs|jSr?)rrr r r rsz Query.paramscCs4||}|j|D]\}}|j||qdSr?)rrclearr)rrrr\r]r r r rs   &TcCs|tur |}t|j|}t|j|}g}|jD]t\}} t|tt|} || |} | durd| } n8t| tt| } || |}| s|dd}d| |f} | | q2| |}|S)a Examples: Query('a=a&b=#').encode() == 'a=a&b=%23' Query('a=a&b=#').encode(';') == 'a=a;b=%23' Query('a+b=c@d').encode(dont_quote='@') == 'a+b=c@d' Query('a+b=c@d').encode(quote_plus=False) == 'a%20b=c%40d' Until furl v0.4.6, the 'delimiter' argument was incorrectly spelled 'delimeter'. For backwards compatibility, accept both the correct 'delimiter' and the old, misspelled 'delimeter'. Keys and values are encoded application/x-www-form-urlencoded if is True, percent-encoded otherwise. exempts valid query characters from being percent-encoded, either in their entirety with dont_quote=True, or selectively with dont_quote=, like dont_quote='/?@_'. Invalid query characters -- those not in self.SAFE_KEY_CHARS, like '#' and '^' -- are always encoded, even if included in . For example: Query('#=^').encode(dont_quote='#^') == '%23=%5E'. Returns: A URL encoded query string using as the delimiter separating key:value pairs. The most common and default delimiter is '&', but ';' can also be specified. ';' is W3C recommended. Nz%3Drz%s=%s) rLroSAFE_KEY_CHARSSAFE_VALUE_CHARSr iterallitemsrJrIrfrrd)r delimiterrlrhZ delimeterZ quote_keyZ quote_valuepairsr\r]Zutf8keyZ quoted_keypairZ utf8valueZ quoted_valuerr r r rKs$        z Query.encodecCst||jdS)N)rr)rErallitemsrr r r r sz Query.asdictcCst|t|kSr?rrr r r rsz Query.__eq__cCs ||k Sr?r rr r r rsz Query.__ne__cCst|jdkSr)r rrr r r rszQuery.__bool__cCs|Sr?)rKrr r r rsz Query.__str__cCsd|jjt|fSrrrr r r rszQuery.__repr__cCs|s g}nt|dr"t|}nht|dr:t|}nPt|drRt|}n8t|drjt|}n t|tjr| |}nt|}|S)a& Extract and return the key:value items from various containers. Some containers that could hold key:value items are - List of (key,value) tuples. - Dictionaries of key:value items. - Multivalue dictionary of key:value items, with potentially repeated keys. - Query string with encoded params and values. Keys and values are passed through unmodified unless they were passed in within an encoded query string, like 'a=a%20a&b=b'. Keys and values passed in within an encoded query string are unquoted by urlparse.parse_qsl(), which uses urllib.unquote_plus() internally. Returns: List of items as (key, value) tuples. Keys and values are passed through unmodified unless they were passed in as part of an encoded query string, in which case the final keys and values that are returned will be unquoted. Raises: UserWarning if is an improperly encoded path string and self.strict is True. rrrrY) rrrrrrYrNrXr_extract_items_from_querystr)rrr r r r!s      z Query._itemsc Csg}|d}dd|D}dd|D}tj||D]\}\}}t|}t|} |jr|rb| sd|tj |f} t | t t |dd} ||krd} nt |dd} || | fq8|S)NrcSsg|]}|ddqS)rr)rz)rrr r r rUrz6Query._extract_items_from_querystr..cSs g|]}|dt|ddfqS)rrrb)rDrpr r r rVrz[Incorrectly percent encoded query string received: '%s'. Proceeding, but did you mean '%s'?rc )rzrXmovesziprtrurrr urlencoderrrrrfr) rquerystrrZpairstrsrZpairstrr\r]Z valid_keyZ valid_valuemsgZ key_decodedZ value_decodedr r r rQs&  z"Query._extract_items_from_querystrN)rbF)rrrrrrrrrrerrrrrLrKrrrrrrrrrr r r r r!s0b    ;0rc@sFeZdZdZdddZeddZeddZed d Zd d Z d S)QueryCompositionInterfacezL Abstract class interface for a parent class that contains a Query. FcCst|d|_dSr)r_queryrr r r rusz"QueryCompositionInterface.__init__cCs|jSr?)rrr r r rxszQueryCompositionInterface.querycCsd}t|tt|jS)z7This method is deprecated. Use str(furl.query) instead.zfurl.querystr is deprecated. Use str(furl.query) instead. There should be one, and preferably only one, obvious way to serialize a Query object to a string.)rrrrErrr r r r|s z"QueryCompositionInterface.querystrcCs|jjS)zU Shortcut method to access the query parameters, self._query.params. )rrrr r r rszQueryCompositionInterface.argscCs$|dks|dkr |j|dSdS)rrrTF)rrrr r r rs z%QueryCompositionInterface.__setattr__N)F) rrrrrrrrrrr r r r rns    rc@seZdZdZdddZddZeefdd Zeeefd d Zeeefd d Z ddZ ddZ ddZ ddZ ddZeZddZddZdS)Fragmenta Represents a URL fragment, comprised internally of a Path and Query optionally separated by a '?' character. http://tools.ietf.org/html/rfc3986#section-3.5 Attributes: path: Path object from FragmentPathCompositionInterface. query: Query object from QueryCompositionInterface. separator: Boolean whether or not a '?' separator should be included in the string representation of this fragment. When False, a '?' character will not separate the fragment path from the fragment query in the fragment string. This is useful to build fragments like '#!arg1=val1&arg2=val2', where no separating '?' is desired. rbFcCs6tj||dtj||d||_d|_||dS)NrT)rrrr separatorr)rrrr r r rs zFragment.__init__cCs|jd|jd|dur$d}|dd}t|dkrV|jd|jdnjt|dkrd|vrx|j|q|j|n:d|dvr|j|d|j|dn |j|dS)Nrbrrrr)rrrrzr rr)rrr~r r r rs        z Fragment.loadcCs,|tur|j||tur(|j||Sr?)rLrrr)rrrr r r rs   z Fragment.addcCsB|tur|j||tur(|j||dus8|dur>||_|S)NTF)rLrrrr)rrrrr r r res  z Fragment.setcCs>|dur|d|tur&|j||tur:|j||Sr)rrLrrr)rrrrr r r rs   zFragment.removecCs t||j|j|jdS)N)rrrr)rErrrrrr r r rs zFragment.asdictcCst|t|kSr?rrr r r rszFragment.__eq__cCs ||k Sr?r rr r r rszFragment.__ne__cCs.t|||s*t|||s*t|||dSr?)rrrobjectrr r r rs zFragment.__setattr__cCst|jpt|jSr?)rrrrr r r rszFragment.__bool__cCsRt|jt|j}}|r0|r$|js0|dd}|rB|rB|jrBdnd}|||S)Nz%3Frrb)rErrrrf)rrrrr r r rs  zFragment.__str__cCsd|jjt|fSrrrr r r rszFragment.__repr__N)rbF)rrrrrrrLrrerrrrrrrrrr r r r rs   rc@s:eZdZdZd ddZeddZeddZd d Zd S) FragmentCompositionInterfacezS Abstract class interface for a parent class that contains a Fragment. FcCst|d|_dSr)r _fragmentrr r r rsz%FragmentCompositionInterface.__init__cCs|jSr?)rrr r r r!sz%FragmentCompositionInterface.fragmentcCsd}t|tt|jS)z:This method is deprecated. Use str(furl.fragment) instead.zfurl.fragmentstr is deprecated. Use str(furl.fragment) instead. There should be one, and preferably only one, obvious way to serialize a Fragment object to a string.)rrrrErrr r r fragmentstr%s z(FragmentCompositionInterface.fragmentstrcCs|dkr|j|dSdS)rrTF)rrrr r r r.s z(FragmentCompositionInterface.__setattr__N)F) rrrrrrrrrr r r r rs   rc@seZdZdZdeeeeeeeeeeeeeeedfddZddZedd Zej d d Zed d Z e j d d Z eddZ e j ddZ eddZ e j ddZ eddZ e j ddZ eddZej ddZeeeeefddZeeeeeeeeeeeeeeefddZeeeedddddddeeefddZd7d"d#Zd$d%Zd&d'Zd(d)Zd*d+Zd,d-Zd.d/Zd0d1Zd2d3Zd4d5Zd6S)8furla Object for simple parsing and manipulation of a URL and its components. scheme://username:password@host:port/path?query#fragment Attributes: strict: Boolean whether or not UserWarnings should be raised if improperly encoded path, query, or fragment strings are provided to methods that take such strings, like load(), add(), set(), remove(), etc. username: Username string for authentication. Initially None. password: Password string for authentication with . Initially None. scheme: URL scheme. A string ('http', 'https', '', etc) or None. All lowercase. Initially None. host: URL host (hostname, IPv4 address, or IPv6 address), not including port. All lowercase. Initially None. port: Port. Valid port values are 1-65535, or None meaning no port specified. netloc: Network location. Combined host and port string. Initially None. path: Path object from URLPathCompositionInterface. query: Query object from QueryCompositionInterface. fragment: Fragment object from FragmentCompositionInterface. rbFcCsftj||dtj||dtj||d||_|||j|||||||| | | | | |||ddS)zY Raises: ValueError on invalid URL or invalid URL component(s) provided. r)rrrrwrorigin fragment_path fragment_argsfragment_separatorhostrVr query_paramsusernamepasswordN)rrrrrrre)rrrrrrwrrrrrrrVrrr r!rr r r rWs  z furl.__init__cCsd|_|_d|_|_|_|dur*d}t|tjs>t|}t |}|j |_ |j |_ |j sjt |j |_|j|j|j|j|j|j|S)z Parse and load a URL. Raises: ValueError on invalid URL, like a malformed IPv6 address or invalid port. Nrb)r r!_host_port_schemerNrXrrErrrwrV DEFAULT_PORTSgetrrrr)rrtokensr r r rms  z furl.loadcCs|jSr?)r$rr r r rwsz furl.schemecCst|dr|}||_dS)Nlower)rr(r$)rrwr r r rws cCs|jSr?)r"rr r r rsz furl.hostcCstjd||duo:t|ddko:d|vo:t|ddk}|durd|sdt|sdd}t||tft|d rv|}t|d r| d rt |}||_ dS) zO Raises: ValueError on invalid host or malformed IPv6 address. http://%s/Nr[rry]zInvalid host '%s'. Host strings must have at least one non-period character, can't contain any of '%s', and can't have adjacent periods.r(rzxn--) rrrrDr{ ValueErrorINVALID_HOST_CHARSrr(rrSr")rrZresembles_ipv6_literalerrmsgr r r rs   cCs|jpt|jSr?)r#r%r&rwrr r r rVsz furl.portcCs@|durt|j|_n$t|r0tt||_n td|dS)a The port value can be 1-65535 or None, meaning no port specified. If is None and self.scheme is a known scheme in DEFAULT_PORTS, the default port value from DEFAULT_PORTS will be used. Raises: ValueError on invalid port. NzInvalid port '%s'.)r%r&rwr#rWrUrEr,)rrVr r r rVs cCstt|jpddd}|jdur:|dtt|jdd7}|sH|jdurP|d7}t|j}|jr|jt|j kr|pxddt |j}|s|r|pd|pd}|S)Nrb)rir@) rrJr r!rRrrVr%r&rwrE)ruserpassrr r r rs  z furl.netlocc Cs,tjd|d}}}}|rZd|vrZ|dd\}}d|vrV|dd\}}n|}|rd|vrd|vr|d|d}}||kr||dkrtd|q||kr||dkr|dd\}}q|}q|dd\}}|}n|}||_||_|durdnt ||_ |durdnt ||_ dS)z Params: netloc: Network location string, like 'google.com' or 'user:pass@google.com:99'. Raises: ValueError on invalid port or malformed IPv6 address. r)Nr/rrr+zInvalid netloc '%s'.) rrrrzrfindr,rsplitrVrrr r!) rrr r!rrVr0ZcolonposZ bracketposr r r rs,   cCsPd}|jp d}t|jpd}|jr>|jt|jkr>d|j}d|||f}|S)Nrbz:%sz %s://%s%s)rwrRrrVr%r&)rrVrwrrr r r rs  z furl.origincCsf|durd|_|_nL|dd}t|dkr4|}n |\|_}d|vr\|dd\|_|_n||_dS)Nrrr)rwrrzr rrV)rrr~ host_portr r r rs   cCs|Sr?tostrrr r r rszfurl.urlcCs ||Sr?r)rrr r r r"scCs|tur |tur d}t|t|tur4|j||turH|j||tur\|j||tusl|tur||jj||d|S)a* Add components to a URL and return this furl instance, . If both and are provided, a UserWarning is raised because is provided as a shortcut for , not to be used simultaneously with . Nonetheless, providing both and behaves as expected, with query keys and values from both and added to the query - first, then . Parameters: args: Shortcut for . path: A list of path segments to add to the existing path segments, or a path string to join with the existing path string. query_params: A dictionary of query keys and values or list of key:value items to add to the query. fragment_path: A list of path segments to add to the existing fragment path segments, or a path string to join with the existing fragment path string. fragment_args: A dictionary of query keys and values or list of key:value items to add to the fragment's query. Returns: . Raises: UserWarning if redundant and possibly conflicting and were provided. zBoth and provided to furl.add(). is a shortcut for , not to be used with . See furl.add() documentation for more details.)rr)rLrrrrrrr)rrrrrrrgr r r r&s    zfurl.addcsdd|r(| r(d}t|t| | |pB| g}t|dkrbd}t|ttfdd||| fDdkrd}t|t| ||g}|rtfd d|Drd }t|t|j}z|tur||_|tur||_| tur| |_ | tur| |_ |tur||_ |tur.||_ | tur>| |_ |turT|j||turj|j||tur|j|| tur|j| |tur|j|| tur|jj| |tur|jj||tur||j_Wn ty||Yn0|S) af Set components of a url and return this furl instance, . If any overlapping, and hence possibly conflicting, parameters are provided, appropriate UserWarning's will be raised. The groups of parameters that could potentially overlap are and , , and/or ( or ) and ( and/or ) any two or all of , , and/or In all of the above groups, the latter parameter(s) take precedence over the earlier parameter(s). So, for example furl('http://google.com/').set( netloc='yahoo.com:99', host='bing.com', port=40) will result in a UserWarning being raised and the url becoming 'http://bing.com:40/' not 'http://yahoo.com:99/ Parameters: args: Shortcut for . path: A list of path segments or a path string to adopt. fragment: Fragment string to adopt. scheme: Scheme string to adopt. netloc: Network location string to adopt. origin: Scheme and netloc. query: Query string to adopt. query_params: A dictionary of query keys and values or list of key:value items to adopt. fragment_path: A list of path segments to adopt for the fragment's path or a path string to adopt as the fragment's path. fragment_args: A dictionary of query keys and values or list of key:value items for the fragment's query to adopt. fragment_separator: Boolean whether or not there should be a '?' separator between the fragment path and fragment query. host: Host string to adopt. port: Port number to adopt. username: Username string to adopt. password: Password string to adopt. Raises: ValueError on invalid port. UserWarning if and are provided. UserWarning if , and/or ( and/or ) are provided. UserWarning if , , and/or are provided. UserWarning if and (, , and/or ) are provided. Returns: . cSs|tuSr?)rL)vr r r presentszfurl.set..presentzaPossible parameter overlap: and . See furl.set() documentation for more details.rzPossible parameter overlap: , and/or ( and/or ) provided. See furl.set() documentation for more details.c3s|]}|VqdSr?r r r7r r rzfurl.set..z{Possible parameter overlap: , , and/or provided. See furl.set() documentation for more details.c3s|]}|VqdSr?r r r8r r r9rzPossible parameter overlap: and (and/or ) or and provided. See furl.set() documentation for more details.)rrrsumanyrrLr r!rrrwrrVrrrrrrF)rrrrrrwr r!rrVrrrrrrrgprovided original_urlr r8r reWsh>                          zfurl.setcCs|durd|_|durd|_|dur*d|_|dur8d|_| durFd|_| durTd|_| durbd|_|turv|j ||tur|j ||tur|j || tur|j | |tur|j || tur|j j | |tur|j j ||S)a8 Remove components of this furl's URL and return this furl instance, . Parameters: args: Shortcut for query_params. path: A list of path segments to remove from the end of the existing path segments list, or a path string to remove from the end of the existing path string, or True to remove the path portion of the URL entirely. query: A list of query keys to remove from the query, if they exist, or True to remove the query portion of the URL entirely. query_params: A list of query keys to remove from the query, if they exist. port: If True, remove the port from the network location string, if it exists. fragment: If True, remove the fragment portion of the URL entirely. fragment_path: A list of path segments to remove from the end of the fragment's path segments or a path string to remove from the end of the fragment's path string. fragment_args: A list of query keys to remove from the fragment's query, if they exist. username: If True, remove the username, if it exists. password: If True, remove the password, if it exists. Returns: . TN) rwr r!rrVrrrLrrrr)rrrrrrwr r!rrVrrrrrr r r rs:!     z furl.removerTcCs|j|||}tj|jpd|jt|j|t|j f}|jdkrLd|}|jdkr~|jdurjd|}nt |dkr~|d}t|S)Nrbrr) rrKrr urlunsplitrwrrErrr)rZquery_delimiterZquery_quote_plusZquery_dont_quoteZ encoded_queryrr r r r5s$     z furl.tostrcGs8|D].}t|tjst|}t|j|}||q|Sr?)rNrXrrErrr)rurlsrnewurlr r r rd6s    z furl.joincCs ||Sr?)rrr r r r>sz furl.copyc CsF|j|j|j|j|jt|j|j|j|j|j |j |j d S)N) rrwr r!rZ host_encodedrVrrrrr) rrwr r!rrRrVrrrrrrrr r r rAsz furl.asdictcCs|j|dS)N)r)rrrr r r rQszfurl.__truediv__cCs(z|j|jkWSty"YdS0dSr?)rrrr r r rTs z furl.__eq__cCs ||k Sr?r rr r r rZsz furl.__ne__cCs<t|||s8t|||s8t|||s8t|||dSr?)rrrrrrr r r r]s   zfurl.__setattr__cCs|Sr?r4rr r r __unicode__cszfurl.__unicode__cCsd|jjt|fSrrrr r r rfsz furl.__repr__N)rTrb)rrrrrLrrrrwrrrVrrrrrerr5rdrrrrrrrArr r r r r9sz         +     1  C r)N)Arerrrr posixpathrrXZ six.movesrZsix.moves.urllib.parserricecreamr ImportErrorrcompatrrcommonrrrrLr%rDrIrJrOrRrSrWraroZ PERCENT_REGEXr-compileescaperqrtrurvr{rrrrrrrrrrr add_metaclassABCMetarrrrrrrrr r r r  s     2  :      +$&+ 2  O ( "