File: //usr/lib/python3/dist-packages/mercurial/utils/__pycache__/urlutil.cpython-310.pyc
o
�]LbAw � @ s� d dl Z d dlZd dlZddlmZ ddlmZmZ ddl m
Z
mZmZmZ ddl m
Z
ejr5d dlmZ ejZd d
� ZG dd� de�Zd
d� Zdd� Zdd� Zdd� Zdd� Zdd� ZdBdd�Zdd� Zdd� Zdd � ZdBd!d"�ZdCd$d%�Z dDd&d'�Z!dBd(d)�Z"G d*d+� d+e#�Z$i Z%d,d-� Z&e&d.d/�d0d1� �Z'e&d2d2�d3d4� �Z(h d5�Z)e&d6d7�d8d9� �Z*e&d:d;�d<d=� �Z+d>d?� Z,G d@dA� dAe�Z-dS )E� N� )�_)�getattr�setattr)�encoding�error�pycompat�urllibcompat� )�
stringutil)�Unionc C sT zt | �W S ty Y nw z t�t�| ��W S tjy) t�td�| ��w )z�Return 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�
ValueError�socket�
getservbynamer �sysstrr �Abortr )�port� r �9/usr/lib/python3/dist-packages/mercurial/utils/urlutil.py�getport$ s
�
��r c @ sv e Zd ZdZdZdZe�d�jZ ddd�Z
dd � Zej
d
d� �Zdd
� Ze�
e�Zdd� Zdd� Zdd� Zdd� ZdS )�urla� Reliable URL parser.
This parses URLs and provides attributes for the following
components:
<scheme>://<user>:<passwd>@<host>:<port>/<path>?<query>#<fragment>
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 scheme: 'http', host: 'www.ietf.org', path: 'rfc/rfc2396.txt'>
>>> url(b'ssh://[::1]:2200//home/joe/repo')
<url scheme: 'ssh', host: '[::1]', port: '2200', path: '/home/joe/repo'>
>>> url(b'file:///home/joe/repo')
<url scheme: 'file', path: '/home/joe/repo'>
>>> url(b'file:///c:/temp/foo/')
<url scheme: 'file', path: 'c:/temp/foo/'>
>>> url(b'bundle:foo')
<url scheme: 'bundle', path: 'foo'>
>>> url(b'bundle://../foo')
<url scheme: 'bundle', path: '../foo'>
>>> url(br'c:\foo\bar')
<url path: 'c:\\foo\\bar'>
>>> url(br'\\blah\blah\blah')
<url path: '\\\\blah\\blah\\blah'>
>>> url(br'\\blah\blah\blah#baz')
<url path: '\\\\blah\\blah\\blah', fragment: 'baz'>
>>> url(br'file:///C:\users\me')
<url scheme: 'file', path: 'C:\\users\\me'>
Authentication credentials:
>>> url(b'ssh://joe:xyz@x/repo')
<url scheme: 'ssh', user: 'joe', passwd: 'xyz', host: 'x', path: 'repo'>
>>> url(b'ssh://joe@x/repo')
<url scheme: 'ssh', user: 'joe', host: 'x', path: 'repo'>
Query strings and fragments:
>>> url(b'http://host/a?b#c')
<url scheme: 'http', host: 'host', path: 'a', query: 'b', fragment: 'c'>
>>> url(b'http://host/a?b#c', parsequery=False, parsefragment=False)
<url scheme: 'http', host: 'host', path: 'a?b#c'>
Empty path:
>>> url(b'')
<url path: ''>
>>> url(b'#a')
<url path: '', fragment: 'a'>
>>> url(b'http://host/')
<url scheme: 'http', host: 'host', path: ''>
>>> url(b'http://host/#a')
<url scheme: 'http', host: 'host', path: '', fragment: 'a'>
Only scheme:
>>> url(b'http:')
<url scheme: 'http'>
s !~*'()+s
/!~*'()+:\s ^[a-zA-Z0-9+.\-]+:Tc C s� d | _ | _ | _| _d | _ | _ | _| _d| _d| _ || _
|r0d|v r0|�dd�\}| _t|�s9|�
d�r>|| _d S |�
d�r\d| _ |dd � }|�
d �rW|d
d � }|| _d S | �|�rs|�dd�}|d rs|\| _ }d
| _|s�d }| jrd| _d S n�| jr�|| _d S |r�d|v r�|�dd�\}| _|s�d }| js�d | _|r�|�
d �r�|d
d � �dd�}t|�dkr�|\| _}n|d | _d }| js�d | _|r�t|�s�d| }| jr�d| jv r�| j�dd�\| _| _d| jv r�| j�dd�\| _| _| js�d | _| j�r,d| jv �r,| j�
d��r| j�d��s,| j| _ | j�dd�\| _| _| j�s,d | _| j�rC| j dk�rC| jdv�rCt�td���|| _dD ]}t| |�}|d u�r]t| |t�|�� �qHd S )NT� � #r
� \\� bundle:� bundle� � //r � :r F� ?� /� @� [� ]� file)s localhosts 127.0.0.1s [::1]s( file:// URLs can only refer to localhost)� user� passwd� host� port� path� fragment)�scheme�user�passwd�hostr �path�query�fragment�
_localpath� _hostport� _origpath�split�hasdriveletter�
startswith�_matchscheme�len�rsplit�endswithr r r r r �urlreq�unquote)�selfr0 �
parsequery�
parsefragment�parts�a�vr r r �__init__� s�
�
�
�
���
��zurl.__init__c C sd t d�}| j|_| j|_| j|_| j|_| j|_| j|_| j|_| j|_| j|_| j |_ | j
|_
|S )Ns temporary useless value)r r0 r, r- r. r/ r1 r2 r3 r4 r5 )r? �ur r r �copy� s zurl.copyc C sF g }dD ]}t | |�}|d ur|�d|t�|�f � qdd�|� S )N)s schemer&