o ]LbAw@sddlZddlZddlZddlmZddlmZmZddl m Z m Z mZm Z ddl m Z ejr5ddlmZe jZd d ZGd d d eZd dZddZddZddZddZddZdBddZddZddZdd ZdBd!d"ZdCd$d%Z dDd&d'Z!dBd(d)Z"Gd*d+d+e#Z$iZ%d,d-Z&e&d.d/d0d1Z'e&d2d2d3d4Z(hd5Z)e&d6d7d8d9Z*e&d:d;dd?Z,Gd@dAdAeZ-dS)EN)_)getattrsetattr)encodingerrorpycompat urllibcompat) stringutil)UnioncCsTzt|WStyYnwz tt|WStjy)ttd|w)zReturn the port for a given network service. If port is an integer, it's returned as is. If it's a string, it's looked up using socket.getservbyname(). If there's no matching service, error.Abort is raised. s+no port number associated with service '%s') int ValueErrorsocket getservbynamersysstrrAbortr)portr9/usr/lib/python3/dist-packages/mercurial/utils/urlutil.pygetport$s   rc@sveZdZdZdZdZedjZ dddZ dd Z e j d d Zd d Ze eZddZddZddZddZdS)urla Reliable URL parser. This parses URLs and provides attributes for the following components: ://:@:/?# Missing components are set to None. The only exception is fragment, which is set to '' if present but empty. If parsefragment is False, fragment is included in query. If parsequery is False, query is included in path. If both are False, both fragment and query are included in path. See http://www.ietf.org/rfc/rfc2396.txt for more information. Note that for backward compatibility reasons, bundle URLs do not take host names. That means 'bundle://../' has a path of '../'. Examples: >>> url(b'http://www.ietf.org/rfc/rfc2396.txt') >>> url(b'ssh://[::1]:2200//home/joe/repo') >>> url(b'file:///home/joe/repo') >>> url(b'file:///c:/temp/foo/') >>> url(b'bundle:foo') >>> url(b'bundle://../foo') >>> url(br'c:\foo\bar') >>> url(br'\\blah\blah\blah') >>> url(br'\\blah\blah\blah#baz') >>> url(br'file:///C:\users\me') Authentication credentials: >>> url(b'ssh://joe:xyz@x/repo') >>> url(b'ssh://joe@x/repo') Query strings and fragments: >>> url(b'http://host/a?b#c') >>> url(b'http://host/a?b#c', parsequery=False, parsefragment=False) Empty path: >>> url(b'') >>> url(b'#a') >>> url(b'http://host/') >>> url(b'http://host/#a') Only scheme: >>> url(b'http:') s!~*'()+s /!~*'()+:\s^[a-zA-Z0-9+.\-]+:TcCsd|_|_|_|_d|_|_|_|_d|_d|_ ||_ |r0d|vr0| dd\}|_t |s9| dr>||_dS| dr\d|_|dd}| d rW|d d}||_dS||rs| d d}|d rs|\|_}d |_|sd}|jrd|_dSn|jr||_dS|rd|vr| dd\}|_|sd}|jsd|_|r| d r|d d dd}t|dkr|\|_}n|d |_d}|jsd|_|rt |sd|}|jrd|jvr|jdd\|_|_d |jvr|j d d\|_|_|jsd|_|jr,d |jvr,|j dr|jds,|j|_ |jd d\|_|_|js,d|_|jrC|jdkrC|jdvrCttd||_dD]}t||}|dur]t||t|qHdS)NT#r \\bundle:bundle//r:rF?/@[]file)s localhosts 127.0.0.1s[::1]s(file:// URLs can only refer to localhost)userpasswdhostportpathfragment)schemeuserpasswdhostrpathqueryfragment _localpath _hostport _origpathsplithasdriveletter startswith _matchschemelenrsplitendswithrrrrrurlrequnquote)selfr0 parsequery parsefragmentpartsavrrr__init__s                     z url.__init__cCsdtd}|j|_|j|_|j|_|j|_|j|_|j|_|j|_|j|_|j|_|j |_ |j |_ |S)Nstemporary useless value) rr0r,r-r.r/r1r2r3r4r5)r?urrrcopyszurl.copycCsFg}dD]}t||}|dur|d|t|fqdd|S)N)sschemer&r'r(r)r*squeryr+s%s: %rss, )rappendrbytestrjoin)r?attrsrCrDrrr__repr__s z url.__repr__cCs|jr|j}|jdkrd|}|jr|d|j7}|S|jd}|js)|js)|jr.|d7}n|jrL|jr?|jds?t|jrL|d7}t|jrL|d7}|jrZ|t j |j|j d7}|jrj|dt j |j|j d7}|jsp|jrt|d7}|jr|jd r|j d s|t |j7}n||j7}|j r|dt |j 7}|jr|d7}|jr|t j |j|jd7}|jr|d |j7}|jd ur|dt j |j|jd7}|S) aJoin the URL's components back into a URL string. Examples: >>> bytes(url(b'http://user:pw@host:80/c:/bob?fo:oo#ba:ar')) 'http://user:pw@host:80/c:/bob?fo:oo#ba:ar' >>> bytes(url(b'http://user:pw@host:80/?foo=bar&baz=42')) 'http://user:pw@host:80/?foo=bar&baz=42' >>> bytes(url(b'http://user:pw@host:80/?foo=bar%3dbaz')) 'http://user:pw@host:80/?foo=bar%3dbaz' >>> bytes(url(b'ssh://user:pw@[::1]:2200//home/joe#')) 'ssh://user:pw@[::1]:2200//home/joe#' >>> bytes(url(b'http://localhost:80//')) 'http://localhost:80//' >>> bytes(url(b'http://localhost:80/')) 'http://localhost:80/' >>> bytes(url(b'http://localhost:80')) 'http://localhost:80/' >>> bytes(url(b'bundle:foo')) 'bundle:foo' >>> bytes(url(b'bundle://../foo')) 'bundle:../foo' >>> bytes(url(b'path')) 'path' >>> bytes(url(b'file:///tmp/foo/bar')) 'file:///tmp/foo/bar' >>> bytes(url(b'file:///c:/tmp/foo/bar')) 'file:///c:/tmp/foo/bar' >>> print(url(br'bundle:foo\bar')) bundle:foo\bar >>> print(url(br'file:///D:\data\hg')) file:///D:\data\hg rrrrrr!)safer"r#r$r N)r3r0r,r2r-r.r/r8r7r=quote _safecharsr<r _safepcharsr1)r?srrr __bytes__sR"        z url.__bytes__c Csr|j|j}}zd\|_|_t|}W|||_|_n|||_|_w|js*|dfS|d||jf|j|jp6dffS)N)NNr)r-r.bytesr/)r?r-r.rQrrrauthinfo`s   z url.authinfocCsF|jr |jdkr dSt|jrdS|jdrdS|jdr!dSdS)Nr%Trr!F)r,r7r0r8r?rrrisabsos   z url.isabscCsf|jdks |jdkr0|jpd}t|jr|jd|j}|S|jdur.|jr.t|s.d|}|S|jS)Nr%rr!)r,r0r7r4r/r5r?r0rrr localpathzs  z url.localpathcCs|j p |jdkp |jdkS)z?whether localpath will return something that posixfile can openr%r)r,rUrrrislocals z url.islocalN)TT)__name__ __module__ __qualname____doc__rOrPremodcompilematchr9rErGr strmethodrLrR__str__rTrVrXrYrrrrr9sI  f  P rcCstt|jSN)boolrr,r0rrr hasschemesrfcCs(t|o|dddko|ddS)Nr rrr)rdisalpharerrrr7s(r7cCst|dddS)NF)r@rA)rrXrerrr urllocalpathsrhcCs<t|}|ds|drttdt|fdS)a\check if a path / url is a potentially unsafe ssh exploit (SEC) This is a sanity check for ssh urls. ssh will parse the first item as an option; e.g. ssh://-oProxyCommand=curl${IFS}bad.server|sh/path. Let's prevent these potentially exploited urls entirely and warn the user. Raises an error.Abort when the url is unsafe. sssh://-s svn+ssh://-spotentially unsafe url: %rN)r=r>r8rrrrrIrerrr checksafesshs ricCst|}|jr d|_t|S)z$hide user credential in a url strings***)rr.rSrFrrr hidepasswordsrkcCst|}d|_|_t|S)z7remove all authentication information from a url stringN)rr-r.rSrjrrr removeauths rlcCshg}|dur!tt|jD]\}}|D] }|||fqq|S|j|gD] }|||fq(|S)z+list all the (name, paths) in the passed uiN)sortedr iteritemspathsrHget)ui target_pathresultnameropr0rrr list_pathssrvcCs&zt|d|dWStyYdSw)zLtry to build a path from a url Return None if no Path could built. Nrawloc)r0r)rqrrrrtry_paths  ryccs|s2d|jvr|jdD]}|Vq dSd|jvr'|jdD]}|VqdStjtdtdd|D],}||jvrG|j|D]}|Vq@q4t||}|dur]td}||;}t||Vq4dS)z=yields all the `path` selected as push destination by `dests`s default-pushdefaults"default repository not configured!ssee 'hg help config.paths')hintNrepository %s does not exist)ror ConfigErrorrry RepoError)reporqdestsrudestr0msgrrrget_push_pathss4     rccsR|sdg}|D]}||jvr|j|D]}|Vqqt|d|dd}|VqdS)zDyields all the `(path, branch)` selected as pull source by `sources`rzNF) validate_path)ror0)rrqsourcessourcerurrrget_pull_pathss rcCs~|durg}n|g}tt|||}t|dkr;|dur)td}|t||f;}n td}|t|||f;}t||dS)a5return a unique `path` or abort if multiple are found This is useful for command and action that does not support multiple destination (yet). Note that for now, we cannot get multiple destination so this function is "trivial". The `action` parameter will be used for the error message. Nr 9default path points to %d urls while %s only supports one5path points to %d urls while %s only supports one: %sr)listrr:rrr)actionrrqrrrrrrget_unique_push_paths   rrcCsg}|durd|jvr|dd|jdDn.|dn(||jvr2|dd|j|Dnt||}|durB||jn||t|dkrp|dur^td}|t||f;}n td}|t|||f;}t|t |d |S) a?return a unique `(path, branch)` or abort if multiple are found This is useful for command and action that does not support multiple destination (yet). Note that for now, we cannot get multiple destination so this function is "trivial". The `action` parameter will be used for the error message. Nrzcs|]}|jVqdSrcrw.0rurrr 0z'get_unique_pull_path..csrrcrwrrrrr7rr rrr roextendrHryrxr:rrrparseurl)rrrqrdefault_branchesurlsr0rrrrget_unique_pull_path#s*        rc Csg}|durd|jvr|dd|jdDn.|dn(||jvr2|dd|j|Dnt||}|durB||jn||t|dkrm|dur\td}|t|;}n td}|t||f;}t||d }t ||\}}|||fS) z@return the `(origsource, path, branch)` selected as clone sourceNrzcsrrcrwrrrrrQrz!get_clone_path..csrrcrwrrrrrXrr s:default path points to %d urls while only one is supporteds6path points to %d urls while only one is supported: %srr) rqrrrr0rr clone_pathbranchrrrget_clone_pathLs.        rcCs2t|}d}|jr|j}d|_t|||pgffS)z5parse url#branch, returning (url, (branch, branches))N)rr2rS)r0branchesrFrrrrros rc@s"eZdZdZddZdddZdS)rozRepresents a collection of paths and their configs. Data is initially derived from ui instances and the config files they have loaded. cCsJt|tjd}|jdddD]q\}}|sq|d|\}}|d|}|||f}|j ||} | d} | durGt | rGt |} n|g} g} | D]0} tj | } tj| } t| sqtj| sqtjtj| | } t||| |d}| |qN| ||<qt|D]\}}g}|D] }|t|||q|||<qdS)N~pathsT) ignoresub multi-urls)rx suboptions)dictrEosr0 expanduser configitemsconfigsuboptions configsource _path_to_rootrpr parsebool parselist expandvarsrfrVnormpathrJrHrmitemsr _chain_path)r?rq home_pathrtvalue_valuesub_optsrQroot_keyroot multi_url base_locsrolocru old_paths new_pathsrrrrEs8           zpaths.__init__Nc Csd}||d|dur4|sd}n t|ttfs|f}|D]}z ||dWSty1YqwdS|s8dS||vrB||dSt||}|durTttd||j S)a Return a ``path`` from a string, falling back to default. ``name`` can be a named path or locations. Locations are filesystem paths or URIs. Returns None if ``name`` is not a registered path, a URI, or a local path to a repo. s9getpath is deprecated, use `get_*` functions from urlutils6.0Nrrr|) deprecwarn isinstancetuplerKeyErrorryrr~rrx)r?rqrtdefaultrkr0rrrgetpaths,    z paths.getpathrc)rZr[r\r]rErrrrrroys$rocsfdd}|S)aDecorator used to declare a path sub-option. Arguments are the sub-option name and the attribute it should set on ``path`` instances. The decorated function will receive as arguments a ``ui`` instance, ``path`` instance, and the string value of this option from the config. The function should return the value that will be set on the ``path`` instance. This decorator can be used to perform additional verification of sub-options and to change the type of sub-options. cs|ft<|Src)_pathsuboptions)funcattroptionrrregisters zpathsuboption..registerr)rrrrrr pathsuboptionsrspushurlspushloccCsZt|}|jstd}||j|f;}||dS|jr)|td|jd|_t|S)Ns-(paths.%s:pushurl not a URL; ignoring: "%s") s:("#fragment" in paths.%s:pushurl not supported; ignoring) )rr,rrtwarnr2rS)rqr0rrFrrrrpushurlpathoptions  rspushrevcCs|Srcr)rqr0rrrrpushrevpathoptionsr>ignoremirrorrzsbookmarks.modesbookmarks_modecCsH|tvr|j}|dur d}td}|||f;}|||dkr"d}|S)N*s2(paths.%s:bookmarks.mode has unknown value: "%s") rz)SUPPORTED_BOOKMARKS_MODESrtrr)rqr0r path_namerrrrbookmarks_mode_options  rrs multi_urlscCs.t|}|dur|td|jd}|S)Ns.(paths.%s:multi-urls not a boolean; ignoring) F)r rrrrt)rqr0rresrrrmultiurls_pathoptions  rc Cs(g}|jjdkr|||S|jjdusJ||jj}|dur4td}||j|jjf;}t ||D][}| }|j jdkrTtd}||j|jjf;}t ||j|_|j|_|j |_ |j durj|j |_ n|jddd}d||j f|_|j } | |j||| ||q6|S) zsT   [    ) # Q     !