U  W[|#@srdZddlmZmZddlmZmZmZm Z m Z ddl m Z dddedd DZd d ZGd d d eZdS)z( L{URLPath}, a representation of a URL. )divisionabsolute_import) nativeStringunicode urllib_parse urlunquoteurlquote)URLcCsg|]}t|dqS)ascii)chrencode).0xr8/usr/lib/python3/dist-packages/twisted/python/urlpath.py srcs&td|tfddfddS)a Attriute declaration to preserve mutability on L{URLPath}. @param name: a public attribute name @type name: native L{str} @return: a descriptor which retrieves the private version of the attribute on get and calls rerealize on set. _cs t|SN)getattrselfZ privateNamerrr z"_rereconstituter..cs(t|t|tr|n|dp&|S)Ncharmap)setattr isinstancebytesr _reconstitute)rvaluerrrr s)rproperty)namerrr_rereconstituters   r$c@seZdZdZd*ddZddZedZed Zed Z ed Z ed Z e d dZ d+ddZe ddZe ddZe ddZddZd,ddZd-ddZd.dd Zd/d!d"Zd#d$Zd%d&Zd'd(Zd)S)0URLPatha A representation of a URL. @ivar scheme: The scheme of the URL (e.g. 'http'). @type scheme: L{bytes} @ivar netloc: The network location ("host"). @type netloc: L{bytes} @ivar path: The path on the network location. @type path: L{bytes} @ivar query: The query argument (the portion after ? in the URL). @type query: L{bytes} @ivar fragment: The page fragment (the portion after # in the URL). @type fragment: L{bytes} r localhostcCs2|pd|_||_|pd|_||_||_|dS)Nshttp/)_scheme_netloc_path_query _fragmentr )rschemenetlocpathqueryfragmentrrr__init__;s   zURLPath.__init__cCsBtt|j|j|j|j|jftd}t | d d|_ dS)zM Reconstitute this L{URLPath} from all its given attributes. Zsafer N)rurlparseZ urlunsplitr(r)r*r+r, _allascii_URLfromTextr decode_url)rZurltextrrrr Es zURLPath._reconstituter-r.r/r0r1cCs||}|j|jpdgd|_|jjd|_|jd|_t |jjdd d|_ t |jj d ddd|_|jjd|_|S) a Reconstruct all the public instance variables of this L{URLPath} from its underlying L{_URL}. @param urlInstance: the object to base this L{URLPath} on. @type urlInstance: L{_URL} @return: a new L{URLPath} )r/r T)r/Zrooted)r0rN)__new__replacer/r9r-r r(Z authorityr)r6asURIasTextr*r0r+r1r,)clsZ urlInstancerrrr_fromURLWs  zURLPath._fromURLFTcs8|jj}dd|r fdddgfdd|DS)a Split this URL's path into its components. @param unquote: whether to remove %-encoding from the returned strings. @param copy: (ignored, do not use) @return: The components of C{self.path} @rtype: L{list} of L{bytes} cSs |dS)Nr )r )rrrrr{r z"URLPath.pathList..cSs |t|Sr)r)rmrrrr}r r csg|] }|qSrr)rZsegmentZmapperrrr~sz$URLPath.pathList..)r9r/)rZunquotecopyZsegmentsrrBrpathListos  zURLPath.pathListcCs:t|ttfstdt|tr*||S|t|S)z Make a L{URLPath} from a L{str} or L{unicode}. @param url: A L{str} representation of a URL. @type url: L{str} or L{unicode}. @return: a new L{URLPath} derived from the given string. @rtype: L{URLPath} z'url' must be a str or unicode) rstrr ValueErrorr fromBytesr@r6r7)klassurlrrr fromStrings   zURLPath.fromStringcCs<t|tstdt|td}t|tr2|d}||S)z Make a L{URLPath} from a L{bytes}. @param url: A L{bytes} representation of a URL. @type url: L{bytes} @return: a new L{URLPath} derived from the given L{bytes}. @rtype: L{URLPath} @since: 15.4 z'url' must be bytesr3r )rrrFrr5r8rJ)rHrIZquotedrrrrGs    zURLPath.fromBytescCs||S)a Make a L{URLPath} from a L{twisted.web.http.Request}. @param request: A L{twisted.web.http.Request} to make the L{URLPath} from. @return: a new L{URLPath} derived from the given request. @rtype: L{URLPath} )rGZ prePathURL)rHZrequestrrr fromRequests zURLPath.fromRequestcCs ||jd|r|jjnddS)a Return a modified copy of C{self} using C{newURL}, keeping the query string if C{keepQuery} is C{True}. @param newURL: a L{URL} to derive a new L{URLPath} from @type newURL: L{URL} @param keepQuery: if C{True}, preserve the query parameters from C{self} on the new L{URLPath}; if C{False}, give the new L{URLPath} no query parameters. @type keepQuery: L{bool} @return: a new L{URLPath} r:r)r1r0)r@r<r9r0)rZnewURL keepQueryrrr_modsz URLPath._modcCs||j|d|S)a Get the sibling of the current L{URLPath}. A sibling is a file which is in the same directory as the current file. @param path: The path of the sibling. @type path: L{bytes} @param keepQuery: Whether to keep the query parameters on the returned L{URLPath}. @type: keepQuery: L{bool} @return: a new L{URLPath} r )rMr9siblingr8rr/rLrrrrNszURLPath.siblingcCs||j|d|S)a* Get the child of this L{URLPath}. @param path: The path of the child. @type path: L{bytes} @param keepQuery: Whether to keep the query parameters on the returned L{URLPath}. @type: keepQuery: L{bool} @return: a new L{URLPath} r )rMr9childr8rOrrrrPs z URLPath.childcCs||jd|S)z Get the parent directory of this L{URLPath}. @param keepQuery: Whether to keep the query parameters on the returned L{URLPath}. @type: keepQuery: L{bool} @return: a new L{URLPath} z..rMr9clickrrLrrrparents zURLPath.parentcCs||jd|S)z Get the current directory of this L{URLPath}. @param keepQuery: Whether to keep the query parameters on the returned L{URLPath}. @type: keepQuery: L{bool} @return: a new L{URLPath} .rQrSrrrheres z URLPath.herecCs||j|dS)a7 Return a path which is the URL where a browser would presumably take you if you clicked on a link with an HREF as given. @param st: A relative URL, to be interpreted relative to C{self} as the base URL. @type st: L{bytes} @return: a new L{URLPath} r )r@r9rRr8)rstrrrrR s z URLPath.clickcCst|jS)z= The L{str} of a L{URLPath} is its URL text. )rr9r=r>rrrr__str__szURLPath.__str__cCsd|j|j|j|j|jfS)z{ The L{repr} of a L{URLPath} is an eval-able expression which will construct a similar L{URLPath}. z=URLPath(scheme=%r, netloc=%r, path=%r, query=%r, fragment=%r))r-r.r/r0r1rrrr__repr__s zURLPath.__repr__N)r r&r r r )FT)F)F)F)F)__name__ __module__ __qualname____doc__r2r r$r-r.r/r0r1 classmethodr@rDrJrGrKrMrNrPrTrVrRrXrYrrrrr%(s8          r%N)r]Z __future__rrZtwisted.python.compatrrrr4rrZ hyperlinkr r6joinranger5r$objectr%rrrrs