o b @sddZddlmZddlmZmZmZddl m Z d dde dd DZd d ZGd d d ZdS)z( L{URLPath}, a representation of a URL. )cast)quoteunquote urlunsplit)URLcCsg|] }t|dqS)ascii)chrencode).0xr 8/usr/lib/python3/dist-packages/twisted/python/urlpath.py srcs"d|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)getattrself privateNamer r z"_rereconstituter..cs(t|t|tr |n|dp|S)Ncharmap)setattr isinstancebytesr _reconstitute)rvaluerr rrs )property)namer rr_rereconstituters    r#c@seZdZdZ d+ddZddZedZed Zed Z ed Z ed Z e d dZ d,ddZe ddZe ddZe ddZddZd-ddZd-ddZd-dd Zd-d!d"Zd#d$Zd%efd&d'Zd%efd(d)Zd*S).URLPatha 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|_||_|p d|_||_||_|dS)Nshttp/)_scheme_netloc_path_query _fragmentr)rschemenetlocpathqueryfragmentr r r__init__=s   zURLPath.__init__cCs@tt|j|j|j|j|jftd}t | d d|_ dS)zM Reconstitute this L{URLPath} from all its given attributes. saferN) urlquoterr'r(r)r*r+ _allascii_URLfromTextr decode_url)rurltextr r rrGszURLPath._reconstituter,r-r.r/r0cCs||}|j|jp dgd|_|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.rT)r.rooted)r/rN)__new__replacer.r9r,r r' authorityr(r6asURIasTextr)r/r*r0r+)cls urlInstancerr r r_fromURLYs &zURLPath._fromURLFTcs8|jj}dd|rfdddgfdd|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 )r r r rr{rz"URLPath.pathList..cSs |t|Sr) urlunquote)r mr r rr}s rcsg|]}|qSr r )r segmentmapperr rr~sz$URLPath.pathList..)r9r.)rrcopysegmentsr rHrpathListos   zURLPath.pathListcCs"t|ts td|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)rstr ValueErrorrDr6r7)klassurlr r r fromStrings zURLPath.fromStringcCs(t|ts tdt|td}||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 bytesr2)rrrNr4r5rQ)rOrPquotedr r r fromBytess   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} )rS prePathURL)rOrequestr r r fromRequests zURLPath.fromRequestcCs&||jd|r|jjdSddS)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 )r0r/)rDr>r9r/)rnewURL keepQueryr r r_mods z URLPath._modcC||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)rYr9siblingr8rr.rXr r rr[szURLPath.siblingcCrZ)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)rYr9childr8r\r r rr]s z URLPath.childcC||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..rYr9clickrrXr r rparent zURLPath.parentcCr^)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} .r_rar r rherercz 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)rDr9r`r8)rstr r rr`s z URLPath.clickreturncCstt|jS)z= The L{str} of a L{URLPath} is its URL text. )rrMr9r@rArr r r__str__szURLPath.__str__cCsd|j|j|j|j|jS)z{ The L{repr} of a L{URLPath} is an eval-able expression which will construct a similar L{URLPath}. zGURLPath(scheme={!r}, netloc={!r}, path={!r}, query={!r}, fragment={!r}))formatr,r-r.r/r0rr r r__repr__ szURLPath.__repr__N)rr%rrr)FT)F)__name__ __module__ __qualname____doc__r1rr#r,r-r.r/r0 classmethodrDrLrQrSrVrYr[r]rbrer`rMrhrjr r r rr$)s6              r$N)rntypingr urllib.parserr4rrEr hyperlinkrr6joinranger5r#r$r r r rs