Plan 9 from Bell Labs’s /usr/web/sources/contrib/bichued/root/sys/lib/python/urllib.pyc

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


�
��c#@svdZddkZddkZddkZddkZddkZddklZdddddd	d
ddd
ddddddddddddddddddd gZ	d!Z
d"Zeid#jodd$k
lZlZngeid%jodd$klZlZn=eid&jodd$klZlZnd'�Zd(�Zeaeed)�Zeeed*�Zd+�Zd,efd-��YZhZdfd.��YZdefd/��YZead0�Zead1�Zea d2�Z!ea"d3�Z#d4fd5��YZ$d6fd7��YZ%d8e%fd9��YZ&d:e%fd;��YZ'd<e%fd=��YZ(ye)Wne*j
od>�Z+nXd?�Z+d@�Z,dA�Z-ea.dB�Z/ea0dC�Z1ea2dD�Z3ea4dE�Z5ea6dF�Z7ea8ddG�Z9ea:dH�Z;ea<dI�Z=dJ�Z>ea?dK�Z@dL�ZAeBdM�eCdN�D��ZDeDiEdO�eCdN�D��dP�ZFdQ�ZGdRZHhZIdSdT�ZJdUdV�ZKdWdX�ZLdY�ZMeiNdZjod[�ZOd\�ZPd]�ZQn?eid%jod^�ZRd_�ZQd`�ZPneMZQda�ZPdb�ZSdc�ZTgdd�ZUde�ZVeWdfjoeV�ndS(gs�Open an arbitrary URL.

See the following document for more info on URLs:
"Names and Addresses, URIs, URLs, URNs, URCs", at
http://www.w3.org/pub/WWW/Addressing/Overview.html

See also the HTTP spec (from which the error codes are derived):
"HTTP - Hypertext Transfer Protocol", at
http://www.w3.org/pub/WWW/Protocols/

Related standards and specs:
- RFC1808: the "relative URL" spec. (authoritative status)
- RFC1738 - the "URL standard". (authoritative status)
- RFC1630 - the "URI spec". (informational status)

The object returned by URLopener().open(file) will differ per
protocol.  All you know is that is has methods read(), readline(),
readlines(), fileno(), close() and info().  The read*(), fileno()
and close() methods work like those of open files.
The info() method returns a mimetools.Message object which can be
used to query various info about the object, if available.
(mimetools.Message objects are queried with the getheader() method.)
i�N(turljointurlopent	URLopenertFancyURLopenerturlretrievet
urlcleanuptquotet
quote_plustunquotetunquote_plust	urlencodeturl2pathnametpathname2urltsplittagt	localhosttthishostt	ftperrorstbasejointunwrapt	splittypet	splithostt	splitusertsplitpasswdt	splitportt
splitnportt
splitqueryt	splitattrt
splitvaluetsplitgophertypet
getproxiess1.17i
tmac(RRtnttriscoscCs
t|�S(sOS-specific conversion from a relative URL of the 'file' scheme
        to a file system path; not recommended for general use.(R(tpathname((s/sys/lib/python/urllib.pyR4scCs
t|�S(sOS-specific conversion from a file system path to a relative URL
        of the 'file' scheme; not recommended for general use.(R(R!((s/sys/lib/python/urllib.pyR9scCsr|dj	otd|�}n!tpt�}|ant}|djo|i|�Sn|i||�SdS(s.urlopen(url [, data]) -> open file-like objecttproxiesN(tNoneRt
_urlopenertopen(turltdataR"topener((s/sys/lib/python/urllib.pyRGs
	

cCs*tp
t�anti||||�S(N(R$Rtretrieve(R&tfilenamet
reporthookR'((s/sys/lib/python/urllib.pyRUs
cCstoti�ndS(N(R$tcleanup(((s/sys/lib/python/urllib.pyRZstContentTooShortErrorcBseZd�ZRS(cCsti||�||_dS(N(tIOErrort__init__tcontent(tselftmessageR0((s/sys/lib/python/urllib.pyR/`s(t__name__t
__module__R/(((s/sys/lib/python/urllib.pyR-_scBs�eZdZdZdeZdd�Zd�Zd�Z	d�Z
d�Zdd�Zdd�Z
dd	�Zdddd
�Zdd�Zdd�Zd
�Zeed�odd�Znd�Zd�Zd�Zd�Zdd�ZRS(s,Class to open URLs.
    This is a class rather than just a subroutine because we may need
    more than one set of global protocol-specific options.
    Note -- this is a base class for those who don't want the
    automatic handling of errors type 302 (relocated) and 401
    (authorization needed).sPython-urllib/%scKs�|djo
t�}nt|d�p
td�||_|id�|_|id�|_d|ifg|_	g|_
ti|_
d|_t|_dS(Nthas_keysproxies must be a mappingtkey_filet	cert_files
User-Agent(R#RthasattrtAssertionErrorR"tgetR6R7tversiont
addheaderst_URLopener__tempfilestostunlinkt_URLopener__unlinkt	tempcachetftpcache(R1R"tx509((s/sys/lib/python/urllib.pyR/rs

			cCs|i�dS(N(tclose(R1((s/sys/lib/python/urllib.pyt__del__�scCs|i�dS(N(R,(R1((s/sys/lib/python/urllib.pyRD�scCso|ioFx8|iD]-}y|i|�Wqtj
oqXqW|i2n|io|ii�ndS(N(R=R@tOSErrorRAtclear(R1tfile((s/sys/lib/python/urllib.pyR,�s

	
cGs|ii|�dS(sdAdd a header to be used by the HTTP interface only
        e.g. u.addheader('Accept', 'sound/basic')N(R<tappend(R1targs((s/sys/lib/python/urllib.pyt	addheader�scCs�tt|��}|ioF||ijo6|i|\}}t|d�}t|||�Snt|�\}}|p
d}n||ijoA|i|}t|�\}}	t|	�\}
}|
|f}nd}d|}||_	|i
dd�}t||�p2|o|i|||�SqC|i
||�Sny>|djot||�|�Snt||�||�SWn4tij
o%}
td|
fti�d�nXdS(	s6Use URLopener().open(file) instead of open(file, 'r').trbRHtopen_t-t_ssocket erroriN(RttoBytesRAR%t
addinfourlRR"RR#ttypetreplaceR8topen_unknown_proxytopen_unknowntgetattrtsocketterrorR.tsystexc_info(R1tfullurlR'R*theaderstfpturltypeR&tproxyt	proxyhostthosttselectortnametmsg((s/sys/lib/python/urllib.pyR%�s6


	
cCs(t|�\}}tdd|f�dS(s/Overridable interface to open unknown URL type.s	url errorsunknown url typeN(RR.(R1R[R'RRR&((s/sys/lib/python/urllib.pyRU�scCs,t|�\}}tdd||f�dS(s/Overridable interface to open unknown URL type.s	url errorsinvalid proxy for %sN(RR.(R1R_R[R'RRR&((s/sys/lib/python/urllib.pyRT�scCs�tt|��}|io||ijo|i|Snt|�\}}|djom|p
|djoXy<|i|�}|i�}~tt|�d�|fSWq�t	j
o	}	q�Xn|i
||�}|i�}
|ot
|d�}n�ddk}t|�\}
}t|pd�\}
}t|pd�\}}
t
|pd�\}}
tii|�d}|i|�\}}|ii|�ti|d�}||
f}|idj	o||i|<nd
}d}d	}d	}|o5d
|
jot|
d�}n||||�nxf|i|�}|djoPn|t|�7}|i|�|d7}|o||||�q9q9|i�|i�~~|d	jo*||jotd||f|��n|S(stretrieve(url) returns (filename, headers) for a local object
        or (tempfilename, headers) for a remote object.RHitwbi�Ntiiiscontent-lengthsContent-Lengths1retrieval incomplete: got only %i out of %i bytesi (RRPRARR#topen_local_filetinfoRRR.R%ttempfileRRR>tpathtsplitexttmkstempR=RItfdopentinttreadtlentwriteRDR-(R1R&R*R+R'RRturl1R]thdrsRdR\ttfpRitgarbageRjtsuffixtfdtresulttbstsizeRotblocknumtblock((s/sys/lib/python/urllib.pyR)�sj"	





cCsXddk}d}d}t|t�oEt|�\}}|o"t|�\}}t|�}n|}n�|\}}t|�\}}t|�\}	}
|
}d}|	i�djo
d}net|
�\}}
|ot|�\}}n|od|	||
f}nt	|�o
|}n|p
t
d�n|o%ddk}|i|�i
�}nd}|o%ddk}|i|�i
�}
nd}
|i|�}|dj	o>|id|�|idd	�|id
dt|��n|id|�|o|id
d|�n|
o|idd|
�n|o|id|�nx|iD]}|i|�qoW|i�|dj	o|i|�n|i�\}}}|djo
t
d�n|i�}|djot||d|�SnG|djo|i|||||�Sn|i||||||�SdS(sUse HTTP protocol.i�Nthttps	%s://%s%ss
http errors
no host giventPOSTsContent-Types!application/x-www-form-urlencodedsContent-Lengths%dtGETsProxy-AuthorizationsBasic %st
AuthorizationtHostshttp protocol errorisgot a bad status linei�shttp:(s
http errors
no host given(shttp protocol errorisgot a bad status lineN(thttplibR#t
isinstancetstrRRRRtlowertproxy_bypassR.tbase64t	b64encodetstriptHTTPt
putrequestt	putheaderRpR<t
endheaderstsendtgetreplytgetfileRQt
http_error(R1R&R'R�tuser_passwdtproxy_passwdRaRbtrealhostR^trestR�t
proxy_authtauththRJterrcodeterrmsgR\R]((s/sys/lib/python/urllib.pyt	open_httpsp











c
Cs�d|}t||�oft||�}|djo||||||�}	n|||||||�}	|	o|	Sq�n|i|||||�S(s�Handle http errors.
        Derived class can override this, or provide specific handlers
        named http_error_DDD where DDD is the 3-digit error code.s
http_error_%dN(R8RVR#thttp_error_default(
R1R&R]R�R�R\R'RctmethodRx((s/sys/lib/python/urllib.pyR�Vs

cCs/|i�}|i�td|||f�dS(s>Default error handler: close the connection and raise IOError.s
http errorN(RoRDR.(R1R&R]R�R�R\tvoid((s/sys/lib/python/urllib.pyR�es
tsslcCsVddk}d}d}t|t�oEt|�\}}|o"t|�\}}t|�}n|}n�|\}}t|�\}}t|�\}	}
|
}d}|	i�djo
d}nNt|
�\}}
|ot|�\}}n|od|	||
f}n|p
t	d�n|o%ddk
}|i|�i�}nd}|o%ddk
}|i|�i�}
nd}
|i
|dd|id	|i�}|dj	o>|id
|�|idd�|id
dt|��n|id|�|o|idd|�n|
o|idd|
�n|o|id|�nx|iD]}|i|�qmW|i�|dj	o|i|�n|i�\}}}|djo
t	d�n|i�}|djot||d|�SnG|djo|i|||||�Sn|i||||||�SdS(sUse HTTPS protocol.i�Nthttpss	%s://%s%sshttps errors
no host giveniR6R7R~sContent-Types!application/x-www-form-urlencodedsContent-Lengths%dRsProxy-AuthorizationsBasic %sR�R�shttp protocol errorsgot a bad status linei�shttps:(shttps errors
no host given(shttp protocol errorisgot a bad status lineN(R�R#R�R�RRRRR�R.R�R�R�tHTTPSR6R7R�R�RpR<R�R�R�R�RQR�(R1R&R'R�R�R�RaRbR�R^R�R�R�R�R�RJR�R�R\R]((s/sys/lib/python/urllib.pyt
open_httpslst

	
	






cCs�t|t�p
td�nddk}t|�\}}|p
td�nt|�}t|�\}}t|�\}}t|�}|o%t|�}|i|||�}n|i	||�}t
|t�d|�S(	sUse Gopher protocol.sgopher errors;proxy support for gopher protocol currently not implementedi�Ns
no host givensgopher:(sgopher errors;proxy support for gopher protocol currently not implemented(sgopher errors
no host given(R�R�R.t	gopherlibRRRRt
send_queryt
send_selectorRQt	noheaders(R1R&R�RaRbRRtqueryR]((s/sys/lib/python/urllib.pytopen_gopher�s
cCs~t|t�p
td
�n|d djo?|dd!djo+|dd!i�djo|i|�Sn|i|�Sd	S(s/Use local file or FTP depending on form of URL.s
file errors9proxy support for file protocol currently not implementedis//it/is
localhost/N(s
file errors9proxy support for file protocol currently not implemented(R�R�R.R�topen_ftpRg(R1R&((s/sys/lib/python/urllib.pyt	open_file�s

?cCs�ddk}ddk}ddk}yddkl}Wn#tj
oddkl}nXt|�\}}t|�}yti	|�}	Wn0t
j
o$}
t|
i|
i
|
i��nX|	i}|ii|	idt�}|i|�d}
|i|d|
pd||f��}|pB|}|d d	jod
|}ntt|d�||�Snt|�\}}|odti|�t�t�fjoB|}|d d	jod
|}ntt|d�||�Sntd�dS(sUse local file.i�N(tStringIOtusegmtis6Content-Type: %s
Content-Length: %d
Last-modified: %s
s
text/plainiR�sfile://RLslocal file errorsnot on local host(slocal file errorsnot on local host(t	mimetypest	mimetoolstemail.Utilst	cStringIOR�tImportErrorRRR>tstatRFR.terrnotstrerrorR*tst_sizetUtilst
formatdatetst_mtimetTruet
guess_typetMessageRQR%RRWt
gethostbynameRR(R1R&R�R�temailR�RaRHt	localnametstatsteRztmodifiedtmtypeR\turlfiletport((s/sys/lib/python/urllib.pyRg�s@$ 		"cCs�t|t�p
td�nddk}ddk}yddkl}Wn#tj
oddkl}nXt|�\}}|p
td�nt	|�\}}t
|�\}}|ot|�\}}	nd}	t
|�}t
|pd�}t
|	pd�}	ti|�}|pddk}
|
i}n
t|�}t|�\}}t
|�}|id�}|d |d}}
|o|d	o|d
}n|o|d	od|d	<n|||di|�f}t|i�tjoPxM|ii�D]8}||jo%|i|}|i|=|i�qqWnyK||ijo#t||	|||�|i|<n|
p
d}nd}xP|D]H}t|�\}}|i�d
jo|djo|i�}q�q�W|i|i|
|�\}}|i d|�d	}d}|o|d|7}n|dj	o|d	jo|d|7}n|i!||��}t"||d|�SWn4t#�j
o%}td|ft$i%�d�nXdS(sUse FTP protocol.s	ftp errors8proxy support for ftp protocol currently not implementedi�N(R�s
no host givenRfR�iitDtIRRtatAtitdsftp:sContent-Type: %s
sContent-Length: %d
i(s	ftp errors8proxy support for ftp protocol currently not implemented(s	ftp errors
no host given(R�R�R�R�R�R�(&R�R�R.R�R�R�R�R�RRRRR#RRWR�tftplibtFTP_PORTRnRtsplittjoinRpRBtMAXFTPCACHEtkeysRDt
ftpwrapperRR�tuppertretrfileR�R�RQRRYRZ(R1R&R�R�R�RaRjR�tusertpasswdR�tattrstdirsRHtkeytktvRRtattrtvalueR]tretrlenR�R\Rd((s/sys/lib/python/urllib.pyR��sr

!!


#
cCs�t|t�p
td�nddk}yddkl}Wn#tj
oddkl}nXy|idd�\}}Wntj
otd�nX|p
d	}n|i	d
�}|djo-d||jo||d}|| }nd
}g}|i
dtidti
ti����|i
d|�|djoddk}	|	i|�}n
t|�}|i
dt|��|i
d
�|i
|�di|�}||�}
|i|
d�}t|
||�S(sUse "data" URL.s
data errors9proxy support for data protocol currently not implementedi�N(R�t,isbad data URLstext/plain;charset=US-ASCIIt;it=RfsDate: %ss%a, %d %b %Y %T GMTsContent-type: %sR�sContent-Length: %ds
(s
data errors9proxy support for data protocol currently not implemented(s
data errorsbad data URL(R�R�R.R�R�R�R�R�t
ValueErrortrfindRIttimetstrftimetgmtimeR�tdecodestringRRpR�R�RQ(R1R&R'R�R�RRtsemitencodingRdR�tfR\((s/sys/lib/python/urllib.pyt	open_data.sB




N(R3R4t__doc__R#R=t__version__R;R/RERDR,RKR%RURTR)R�R�R�R8RWR�R�R�RgR�R�(((s/sys/lib/python/urllib.pyRes,
				!?H	F				#	>cBs�eZdZd�Zd�Zdd�Zd�Zdd�Zdd�Z	dd�Z
dd�Zdd	�Zdd
�Z
dd�Zdd�Zdd
�Zdd�Zd�ZRS(s?Derived class with handlers for errors we can handle (perhaps).cOs2ti|||�h|_d|_d|_dS(Nii
(RR/t
auth_cachettriestmaxtries(R1RJtkwargs((s/sys/lib/python/urllib.pyR/`s		cCst||d|�S(s3Default error handling -- don't raise an exception.shttp:(RQ(R1R&R]R�R�R\((s/sys/lib/python/urllib.pyR�fsc	Cs�|id7_|io\|i|ijoIt|d�o
|i}n
|i}d|_|||dd|�Sn|i||||||�}d|_|S(s%Error 302 -- relocated (temporarily).ithttp_error_500ii�s)Internal Server Error: Redirect Recursion(R�R�R8R�R�tredirect_internal(	R1R&R]R�R�R\R'tmethRx((s/sys/lib/python/urllib.pythttp_error_302js
				c	Cswd|jo|d}n d|jo|d}ndS|i�}|i�t|id||�}|i|�S(Ntlocationturit:(RoRDRRRR%(	R1R&R]R�R�R\R'tnewurlR�((s/sys/lib/python/urllib.pyR�zs


cCs|i||||||�S(s*Error 301 -- also relocated (permanently).(R�(R1R&R]R�R�R\R'((s/sys/lib/python/urllib.pythttp_error_301�scCs|i||||||�S(s;Error 303 -- also relocated (essentially identical to 302).(R�(R1R&R]R�R�R\R'((s/sys/lib/python/urllib.pythttp_error_303�scCsJ|djo |i||||||�Sn|i|||||�SdS(s1Error 307 -- relocated, but turn POST into error.N(R#R�R�(R1R&R]R�R�R\R'((s/sys/lib/python/urllib.pythttp_error_307�s
 c
Csd|jo ti||||||�n|d}ddk}|id|�}	|	p ti||||||�n|	i�\}
}|
i�djo ti||||||�nd|id}|djot||�||�Snt||�|||�SdS(s_Error 401 -- authentication required.
        This function supports Basic authentication only.swww-authenticatei�Ns![ 	]*([^ 	]+)[ 	]+realm="([^"]*)"tbasictretry_t_basic_auth(	RR�tretmatchtgroupsR�RRR#RV(
R1R&R]R�R�R\R'tstuffRRtschemetrealmRc((s/sys/lib/python/urllib.pythttp_error_401�s"


c
Csd|jo ti||||||�n|d}ddk}|id|�}	|	p ti||||||�n|	i�\}
}|
i�djo ti||||||�nd|id}|djot||�||�Snt||�|||�SdS(seError 407 -- proxy authentication required.
        This function supports Basic authentication only.sproxy-authenticatei�Ns![ 	]*([^ 	]+)[ 	]+realm="([^"]*)"R�tretry_proxy_R�(	RR�RRRR�RRR#RV(
R1R&R]R�R�R\R'RRRRRRc((s/sys/lib/python/urllib.pythttp_error_407�s"


cCst|�\}}d||}|id}t|�\}}	t|	�\}	}
|	id�d}|	|}	|i|	||�\}}
|p|
pdSnt|dd�dt|
dd�d|	}	d|	|
|id<|djo|i|�Sn|i||�SdS(Nshttp://R}t@itsafeRfR�(RR"Rtfindtget_user_passwdR#RR%(R1R&RR'RaRbR�R_R^R`t
proxyselectorR�R�R�((s/sys/lib/python/urllib.pytretry_proxy_http_basic_auth�s

.
cCst|�\}}d||}|id}t|�\}}	t|	�\}	}
|	id�d}|	|}	|i|	||�\}}
|p|
pdSnt|dd�dt|
dd�d|	}	d|	|
|id<|djo|i|�Sn|i||�SdS(Nshttps://R�R	iR
RfR�(RR"RRRR#RR%(R1R&RR'RaRbR�R_R^R`R
R�R�R�((s/sys/lib/python/urllib.pytretry_proxy_https_basic_auth�s

.
c
Cs�t|�\}}|id�d}||}|i|||�\}}|p|pdSnt|dd�dt|dd�d|}d||}	|djo|i|	�Sn|i|	|�SdS(NR	iR
RfR�shttp://(RRRR#RR%(
R1R&RR'RaRbR�R�R�R�((s/sys/lib/python/urllib.pytretry_http_basic_auth�s
.
c
Cs�t|�\}}|id�d}||}|i|||�\}}|p|pdSnt|dd�dt|dd�d|}d||}	|djo|i|	�Sn|i|	|�SdS(NR	iR
RfR�shttps://(RRRR#RR%(
R1R&RR'RaRbR�R�R�R�((s/sys/lib/python/urllib.pytretry_https_basic_auth�s
.
icCs�|d|i�}||ijo$|o|i|=qH|i|Sn|i||�\}}|p|o||f|i|<n||fS(NR	(R�R�tprompt_user_passwd(R1RaRtclear_cacheR�R�R�((s/sys/lib/python/urllib.pyR�s%c	Cskddk}y@td||f�}|id|||f�}||fSWntj
oHdSnXdS(s#Override this in a GUI environment!i�NsEnter username for %s at %s: s#Enter password for %s in %s at %s: (NN(tgetpasst	raw_inputtKeyboardInterruptR#(R1RaRRR�R�((s/sys/lib/python/urllib.pyR	s	
	N(R3R4R�R/R�R#R�R�R�R�R�RRRRRRRR(((s/sys/lib/python/urllib.pyR]s 			


cCs$tdjotid�antS(s8Return the IP address of the magic hostname 'localhost'.RN(t
_localhostR#RWR�(((s/sys/lib/python/urllib.pyRs
cCs*tdjotiti��antS(s*Return the IP address of the current host.N(t	_thishostR#RWR�tgethostname(((s/sys/lib/python/urllib.pyR"s
cCs*tdjoddk}|iantS(s1Return the set of errors raised by the FTP class.i�N(t
_ftperrorsR#R�t
all_errors(R�((s/sys/lib/python/urllib.pyR*s

cCs}tdjolddk}yddkl}Wn#tj
oddkl}nX|i|�d�atii�ntS(s)Return an empty mimetools.Message object.i�N(R�i(	t
_noheadersR#R�R�R�R�R�R]RD(R�R�((s/sys/lib/python/urllib.pyR�3s
R�cBs;eZdZd�Zd�Zd�Zd�Zd�ZRS(s;Class used by open_ftp() for cache of open FTP connections.cCs;||_||_||_||_||_|i�dS(N(R�R�RaR�R�tinit(R1R�R�RaR�R�((s/sys/lib/python/urllib.pyR/Fs					cCs~ddk}d|_|i�|_|ii|i|i�|ii|i|i	�x!|i
D]}|ii|�q`WdS(Ni�i(R�tbusytFTPtftptconnectRaR�tloginR�R�R�tcwd(R1R�tdir((s/sys/lib/python/urllib.pyRNs	
c
Cs�ddk}|i�|djod}d}nd|}d}y|ii|�Wn0|ij
o!|i�|ii|�nXd}|o~|ovy d|}|ii|�}Wq|ij
o@}t	|�d	 d
jo t
d|fti�d�qqXn|pA|iid�|od
|}nd}|ii|�}nd|_
t|did�|i�|dfS(Ni�R�R�sTYPE AisTYPE isRETR it550s	ftp errorisLIST tLISTRL(R�R�(R�tendtransferR tvoidcmdRRR#tntransfercmdt
error_permR�R.RYRZRtaddclosehooktmakefile(R1RHRRR�tcmdtisdirtconntreason((s/sys/lib/python/urllib.pyR�Ws2


)	cCsI|ipdSnd|_y|ii�Wnt�j
onXdS(Ni(RR tvoidrespR(R1((s/sys/lib/python/urllib.pyR'us
	cCs8|i�y|ii�Wnt�j
onXdS(N(R'R RDR(R1((s/sys/lib/python/urllib.pyRD~s

(R3R4R�R/RR�R'RD(((s/sys/lib/python/urllib.pyR�Cs						taddbasecBs)eZdZd�Zd�Zd�ZRS(s(Base class for addinfo and addclosehook.cCs�||_|ii|_|ii|_t|id�o|ii|_nt|id�o|ii|_n
d�|_t|id�o9|ii|_t|id�o|ii|_q�ndS(Nt	readlinestfilenocSsdS(N(R#(((s/sys/lib/python/urllib.pyt<lambda>�st__iter__tnext(R]RotreadlineR8R3R4R6R7(R1R]((s/sys/lib/python/urllib.pyR/�s	&cCs d|iit|�|ifS(Ns<%s at %r whose fp = %r>(t	__class__R3tidR](R1((s/sys/lib/python/urllib.pyt__repr__�scCsLd|_d|_d|_d|_|io|ii�nd|_dS(N(R#RoR8R3R4R]RD(R1((s/sys/lib/python/urllib.pyRD�s				(R3R4R�R/R;RD(((s/sys/lib/python/urllib.pyR2�s		R+cBs eZdZd�Zd�ZRS(s*Class to add a close hook to an open file.cGs&ti||�||_||_dS(N(R2R/t	closehookthookargs(R1R]R<R=((s/sys/lib/python/urllib.pyR/�s	cCsAti|�|io&|i|i�d|_d|_ndS(N(R2RDR<R=R#(R1((s/sys/lib/python/urllib.pyRD�s


	(R3R4R�R/RD(((s/sys/lib/python/urllib.pyR+�s	taddinfocBs eZdZd�Zd�ZRS(s.class to add an info() method to an open file.cCsti||�||_dS(N(R2R/R\(R1R]R\((s/sys/lib/python/urllib.pyR/�scCs|iS(N(R\(R1((s/sys/lib/python/urllib.pyRh�s(R3R4R�R/Rh(((s/sys/lib/python/urllib.pyR>�s	RQcBs)eZdZd�Zd�Zd�ZRS(s9class to add info() and geturl() methods to an open file.cCs&ti||�||_||_dS(N(R2R/R\R&(R1R]R\R&((s/sys/lib/python/urllib.pyR/�s	cCs|iS(N(R\(R1((s/sys/lib/python/urllib.pyRh�scCs|iS(N(R&(R1((s/sys/lib/python/urllib.pytgeturl�s(R3R4R�R/RhR?(((s/sys/lib/python/urllib.pyRQ�s		cCsdS(Ni((tx((s/sys/lib/python/urllib.pyt_is_unicode�scCs
t|t�S(N(R�tunicode(R@((s/sys/lib/python/urllib.pyRA�scCsXt|�oGy|id�}WqTtj
o!tdt|�d��qTXn|S(stoBytes(u"URL") --> 'URL'.tASCIIsURL s contains non-ASCII characters(RAtencodetUnicodeErrortrepr(R&((s/sys/lib/python/urllib.pyRP�s
cCsn|i�}|d djo(|ddjo|dd!i�}n|d djo|di�}n|S(s8unwrap('<URL:type://host/path>') --> 'type://host/path'.it<i�t>isURL:(R�(R&((s/sys/lib/python/urllib.pyR�s
"%cCs}tdjoddk}|id�anti|�}|o1|id�}|i�|t|�dfSnd|fS(s:splittype('type:opaquestring') --> 'type', 'opaquestring'.i�Ns
^([^/:]+):i(t	_typeprogR#RtcompileRtgroupR�Rp(R&RRR((s/sys/lib/python/urllib.pyR�s
"cCs`tdjoddk}|id�anti|�}|o|idd�Snd|fS(s;splithost('//host[:port]/path') --> 'host[:port]', '/path'.i�Ns^//([^/?]*)(.*)$ii(t	_hostprogR#RRJRRK(R&RR((s/sys/lib/python/urllib.pyRs
cCsitdjoddk}|id�anti|�}|ott|idd��Snd|fS(sJsplituser('user[:passwd]@host[:port]') --> 'user[:passwd]', 'host[:port]'.i�Ns^(.*)@(.*)$ii(t	_userprogR#RRJRtmapRRK(RaRR((s/sys/lib/python/urllib.pyRs
$cCs`tdjoddk}|id�anti|�}|o|idd�Sn|dfS(s/splitpasswd('user:passwd') -> 'user', 'passwd'.i�Ns^([^:]*):(.*)$ii(t_passwdprogR#RRJRRK(R�RR((s/sys/lib/python/urllib.pyRs
cCs`tdjoddk}|id�anti|�}|o|idd�Sn|dfS(s*splitport('host:port') --> 'host', 'port'.i�Ns^(.*):([0-9]+)$ii(t	_portprogR#RRJRRK(RaRR((s/sys/lib/python/urllib.pyR+s
cCs�tdjoddk}|id�anti|�}|of|idd�\}}y$|p
td�nt|�}Wntj
o
d}nX||fSn||fS(s�Split host and port, returning numeric port.
    Return given default port if no ':' found; defaults to -1.
    Return numerical port if a valid number are found after ':'.
    Return None if ':' but not a valid number.i�Ns^(.*):(.*)$iis	no digits(t
_nportprogR#RRJRRKR�Rn(RatdefportRRR�tnport((s/sys/lib/python/urllib.pyR7s
cCs`tdjoddk}|id�anti|�}|o|idd�Sn|dfS(s/splitquery('/path?query') --> '/path', 'query'.i�Ns^(.*)\?([^?]*)$ii(t
_queryprogR#RRJRRK(R&RR((s/sys/lib/python/urllib.pyRMs
cCs`tdjoddk}|id�anti|�}|o|idd�Sn|dfS(s)splittag('/path#tag') --> '/path', 'tag'.i�Ns^(.*)#([^#]*)$ii(t_tagprogR#RRJRRK(R&RR((s/sys/lib/python/urllib.pyR
Ys
cCs!|id�}|d|dfS(sksplitattr('/path;attr1=value1;attr2=value2;...') ->
        '/path', ['attr1=value1', 'attr2=value2', ...].R�ii(R�(R&twords((s/sys/lib/python/urllib.pyRdscCs`tdjoddk}|id�anti|�}|o|idd�Sn|dfS(s-splitvalue('attr=value') --> 'attr', 'value'.i�Ns^([^=]*)=(.*)$ii(t
_valueprogR#RRJRRK(R�RR((s/sys/lib/python/urllib.pyRks
cCs?|d djo$|dd!o|d|dfSnd|fS(s2splitgophertype('/Xselector') --> 'X', 'selector'.iR�iN(R#(Rb((s/sys/lib/python/urllib.pyRvsccs)x"|]}d|t|�fVqWdS(s%02xN(tchr(t.0R�((s/sys/lib/python/urllib.pys	<genexpr>|siccs)x"|]}d|t|�fVqWdS(s%02XN(RX(RYR�((s/sys/lib/python/urllib.pys	<genexpr>}sc	Cs�|id�}x�tdt|��D]�}||}yt|d |d||<Wq%tj
od|||<q%tj
o,tt|d d��|d||<q%Xq%Wdi|�S(s"unquote('abc%20def') -> 'abc def'.t%iiiRf(	R�txrangeRpt	_hextochrtKeyErrortUnicodeDecodeErrortunichrRnR�(tstresR�titem((s/sys/lib/python/urllib.pyRs
.cCs|idd�}t|�S(s%unquote('%7e/abc+def') -> '~/abc def't+t (RSR(R`((s/sys/lib/python/urllib.pyR	�ssAABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_.-R�cCs�|tf}yt|}Wnrtj
of|t7}h}xBtd�D]4}t|�}||jo|pd|||<qHW|t|<nXt|i|�}di|�S(squote('abc def') -> 'abc%20def'

    Each part of a URL, e.g. the path info, the query, etc., has a
    different set of reserved characters that must be quoted.

    RFC 2396 Uniform Resource Identifiers (URI): Generic Syntax lists
    the following reserved characters.

    reserved    = ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" |
                  "$" | ","

    Each of these characters is reserved in some component of a URL,
    but not necessarily in all of them.

    By default, the quote function is intended for quoting the path
    section of a URL.  Thus, it will not encode '/'.  This character
    is reserved, but in typical usage the quote function is being
    called on a path where the existing slash characters are used as
    reserved characters.
    is%%%02XRf(talways_safet	_safemapsR]trangeRXRNt__getitem__R�(R`R
tcachekeytsafe_mapR�tcRa((s/sys/lib/python/urllib.pyR�s

&RfcCsAd|jo't||d�}|idd�Snt||�S(s9Quote the query fragment of a URL; replacing ' ' with '+'RdRc(RRS(R`R
((s/sys/lib/python/urllib.pyR�s
ic

Cst|d�o|i�}nhy0t|�ot|dt�o
t�nWn4tj
o(ti�\}}}td|�nXg}|pTxl|D]E\}}tt	|��}tt	|��}|i
|d|�q�Wnx|D]\}}tt	|��}t|t	�o%t|�}|i
|d|�q�t|�o1t|idd��}|i
|d|�q�yt|�}Wn:tj
o.tt	|��}|i
|d|�q�Xx/|D]'}	|i
|dtt	|	���q�Wq�di
|�S(svEncode a sequence of two-element tuples or dictionary into a URL query string.

    If any values in the query arg are sequences and doseq is true, each
    sequence element is converted to a separate parameter.

    If the query arg is a sequence of two-element tuples, the order of the
    parameters in the output will match the order of parameters in the
    input.
    titemsis1not a valid non-string sequence or mapping objectR�RCRSt&(R8RlRpR�ttuplet	TypeErrorRYRZRR�RIRARDR�(
R�tdoseqttytvattbtlR�R�R@telt((s/sys/lib/python/urllib.pyR
�sB"
)cCs`h}xStii�D]B\}}|i�}|o#|ddjo|||d <qqW|S(sReturn a dictionary of scheme -> proxy server URL mappings.

    Scan the environment for variables named <scheme>_proxy;
    this seems to be the standard convention.  If you need a
    different way, you can pass a proxies dictionary to the
    [Fancy]URLopener constructor.

    i�t_proxy(R>tenvironRlR�(R"RcR�((s/sys/lib/python/urllib.pytgetproxies_environment�s	tdarwinc
Cs�yddk}Wntj
ohSnXy|i�}Wn|ij
ohSnXh}d|joD|do9y|d}Wn|ij
oq�Xd||d<n|S(s�Return a dictionary of scheme -> proxy server URL mappings.

        By convention the mac uses Internet Config to store
        proxies.  An HTTP proxy, for instance, is stored under
        the HttpProxy key.

        i�NtUseHTTPProxyt
HTTPProxyHosts	http://%sR}(ticR�tICRX(R|tconfigR"R�((s/sys/lib/python/urllib.pytgetproxies_internetconfigs 		cCsdS(Ni((R@((s/sys/lib/python/urllib.pyR�.scCst�pt�S(N(RxR(((s/sys/lib/python/urllib.pyR1sc	Csnh}yddk}Wntj
o|SnXy|i|id�}|i|d�d}|o�t|i|d�d�}d|josx�|id�D][}|idd	�\}}ddk}|id
|�pd||f}n|||<q�Wq@|d d
jo||d<q@d||d<d||d<n|i	�Wnt
ttfj
onX|S(sxReturn a dictionary of scheme -> proxy server URL mappings.

        Win32 uses the registry to store proxies.

        i�Ns;Software\Microsoft\Windows\CurrentVersion\Internet SettingstProxyEnableitProxyServerR�R�is^([^/:]+)://s%s://%sishttp:R}s	http://%ssftp://%sR (
t_winregR�tOpenKeytHKEY_CURRENT_USERtQueryValueExR�R�RRtClosetWindowsErrorR�Ro(	R"R�tinternetSettingstproxyEnabletproxyServertptprotocoltaddressR((s/sys/lib/python/urllib.pytgetproxies_registry5s:			

cCst�pt�S(s�Return a dictionary of scheme -> proxy server URL mappings.

        Returns settings gathered from the environment, if specified,
        or the registry.

        (RxR�(((s/sys/lib/python/urllib.pyRbsc
Cs`yddk}ddk}Wntj
odSnXyK|i|id�}|i|d�d}t|i|d�d�}Wntj
odSnX|p|odSnt|�\}}|g}y1t	i
|�}||jo|i|�nWnt	ij
onXy1t	i
|�}	|	|jo|i|	�nWnt	ij
onX|id�}d}
xi|
t|�joU||
djo6dd	t	i�t	i
t	i��g||
|
d
+n|
d
7}
qzWxv|D]n}|idd�}|id
d�}|idd�}x/|D]'}|i|||i�od
Sq-q-Wq�dS(Ni�is;Software\Microsoft\Windows\CurrentVersion\Internet SettingsR�t
ProxyOverrideR�s<local>Rs	127.0.0.1it.s\.t*s.*t?(R�RR�R�R�R�R�R�RRWR�RIRXtgetfqdnR�RpRRSRR�(
RaR�RR�R�t
proxyOverridetrawHostR�taddrtfqdnR�ttesttval((s/sys/lib/python/urllib.pyR�ksd			
		

	!cCsdS(Ni((Ra((s/sys/lib/python/urllib.pyR��scCs�d}x$td�D]}|t|�}qW|d}ti�}t|�}t|�}ti�}||jo	dGHnt|�GHt|�GHt|�GHt||d�GdGHdS(NRfiisWrong!itsec(RgRXR�RRRFtround(R`R�tt0tqstuqstt1((s/sys/lib/python/urllib.pyttest1�s


	cCsd|||fGHdS(Ns0Block number: %d, Block size: %d, Total size: %d((R{t	blocksizet	totalsize((s/sys/lib/python/urllib.pyR+�sc	Cs9|p:dddddg}ttd�o|id�qAnz��|D]�}dG|GdGHt|dt�\}}|GH|o6d
GHx%|i�D]}|dG||GHq�Wd
GHnt|d�}|i�}~d
|jo(t	i
dd�}|i|d
�}n|GHd\}}qKWddGHWdt�XdS(Ns/etc/passwdsfile:/etc/passwdsfile://localhost/etc/passwdsftp://ftp.gnu.org/pub/READMEs http://www.python.org/index.htmlR�s!https://synergy.as.cmu.edu/~geek/RNi
s======R�RLs
Rfi(s
----------s
----------(NN(
R8RRIRR#R+R�R%Rotstringt	maketranst	translateR(RJR&tfnR�R�R]R'ttable((s/sys/lib/python/urllib.pyR��s:	

	

c	Cs!ddk}ddk}y#|i|idd�\}}Wn&|ij
o}|GHdGHdSnXd}xR|D]J\}}|djo|d}n|djodGHd	Gd
GHdSqqqqW|o&|djot�nt|�n2|p	dGHnx|D]}t|�i�GqWdS(Ni�itthsUse -h for helpis-ts-hs&Usage: python urllib.py [-t] [url ...]s-t runs self-test;s'otherwise, contents of urls are printed(tgetoptRYtargvRXR�R�RRo(	R�RYtoptsRJRdtttoR�R&((s/sys/lib/python/urllib.pytmain�s4#	


	t__main__(XR�R�RWR>R�RYturlparseRRt__all__R�R�Rctmacurl2pathRRt
nturl2patht
rourl2pathR#R$RRRR.R-RBRRRRRRRRRR�R�R2R+R>RQRBt	NameErrorRARPRRIRRLRRMRRORRPRRQRRTRRUR
RRWRRtdictRgR\tupdateRR	ReRfRRR
RxtplatformRR�RR�R�R+R�R�R3(((s/sys/lib/python/urllib.pys<module>s�		
	��				B
				
										
	"@			
	-		
=			!	


Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].