Viewing File: /opt/alt/python35/lib64/python3.5/site-packages/aiohttp/__pycache__/helpers.cpython-35.opt-1.pyc



ZnY@sdZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlmZddlmZddlmZddlmZddlmZddlmZddlZddlZdd	lmZdd
lmZddl m!Z!dd
l"m#Z#ddl$m%Z%dkZ&ej'dlkZ(ej'dmkZ)e)sddl*Z*e*j+e,Z-e.e	j/j0dZ1e2dde3ddDZ4e2dde3ddDe5dhBZ6ddddddd d!d"d#d$d%d&d'd(d)d*d+e5d,hZ7e4e6Ae7AZ8ej9Z9e9j:Z;d-e9_:ej<d.d/Z=e;e9_:Gd0ddedd1d2d3gZ>d4d5Z?d6d7Z@ejAd8d9d:d9Gd;d<d<ZBd=d>ZCdd?d@ZDdAdBZEejAd8d9d:d9GdCdDdDZFdEdFZGddGdHZHd9dIdJZIGdKdLdLe#ZJGdMdNdNZKdOZLdPZMe
jNeLZOe
jNeMdQe
jPZQe
jNeLjRdRZSe
jNeMjRdRdQe
jPZTdSdTZUdaVdaWdUdVZXdWdXZYd9dYdZZZd[d\Z[Gd]d^d^Z\Gd_d`d`Z]GdadbdbZ^Gdcddddej_Z`GdedfdfZadgdhZbdidjZcdS)nzVarious helper functionsN)
namedtuple)suppress)ceil)Path)quote)
getproxies)	MultiDict)URL)hdrs)AbstractAccessLogger)
client_logger	BasicAuthZAIOHTTP_NO_EXTENSIONSccs|]}t|VqdS)N)chr).0ir/helpers.py	<genexpr>.srccs|]}t|VqdS)N)r)rrrrrr/s ()<>@,;:\"/[]?={} 	FcOsdS)Nr)argskwargsrrrnoop:sr0csgeZdZdZddfddZedddZeddd	d
ZddZS)
rz!Http basic authentication helper.latin1csa|dkrtd|dkr0tdd|krHtdtj||||S)Nz"None is not allowed as login valuez%None is not allowed as password valuer"z5A ":" is not allowed in login (RFC 1945#section-11.1))
ValueErrorsuper__new__)clsloginpasswordencoding)	__class__rrr5Es	zBasicAuth.__new__c
Cs|jjd}t|dkrd|djjdkrWtd|d|d}ntdy7tj|jdj|j	d	\}}}Wn!t
jk
rtd
YnX|||d|S)z<Create a BasicAuth object from an Authorization HTTP header.r,rZbasiczUnknown authorization method %sr
z%Could not parse authorization header.asciir"zInvalid base64 encoding.r9)stripsplitlenlowerr3base64Z	b64decodeencodedecode	partitionbinasciiError)r6Zauth_headerr9r>Z	to_decodeZusername_r8rrrrCRs
zBasicAuth.decoder9cCsMt|tstd|jdkr.dS||j|jpCdd|S)zCreate BasicAuth from url.zurl should be yarl.URL instanceNr1r9)
isinstancer		TypeErroruserr8)r6urlr9rrrfrom_urlfs
zBasicAuth.from_urlcCs?d|j|jfj|j}dtj|j|jS)zEncode credentials.z%s:%szBasic %s)r7r8rBr9rAZ	b64encoderC)selfZcredsrrrrBos"zBasicAuth.encode)	__name__
__module____qualname____doc__r5classmethodrCrLrBrr)r:rrBs
r7r8r9cCs<tj|}|dkr%|dfS|jd|fSdS)N)rrLZ	with_user)rKauthrrrstrip_auth_from_urlus
rTcCs4d}tjjd}y|dk	r6t|}n<tj}tjdkrc|jd}n|jd}|r|jrytjt	|}Wn>tj
tfk
r}ztj
d|WYdd}~XnX|dkrtj
dWn5tk
r/}ztj
d|WYdd}~XnX|S)NZNETRCntZ_netrcz.netrcz.netrc file parses fail: %szcould't find .netrc filezcould't find .netrc file: %s)osenvirongetrhomenameZjoinpathis_filenetrcstrZNetrcParseErrorOSErrorr
warningRuntimeError)	netrc_objZ
netrc_pathZhome_direrrrnetrc_from_env}s&##rcfrozenTslotsc@s4eZdZejdeZejdeZdS)	ProxyInfotypeN)	rNrOrPattribr]proxyrZ
proxy_authrrrrrfsrfcCs	ddtjD}t}dd|jD}i}x|jD]\}}|\}}|jdkrtjd|qQ|r|dkr|j|j}|dk	r|^}	}
t|	dr|	dn|	d|
}t	||||<qQW|S)	NcSs1i|]'\}}|dkrt||qS)httphttps)rkrl)r	)rkvrrr
<dictcomp>s		z$proxies_from_env.<locals>.<dictcomp>cSs%i|]\}}t||qSr)rT)rrmrnrrrros	rlz,HTTPS proxies %s are not supported, ignoringrr
)
ritemsrcschemer
r_Zauthenticatorshostrrf)Z
proxy_urlsraZstrippedZretprotovalrjrSZauth_from_netrcZloginsr8rrrproxies_from_envs$	
	rvcCss|dkrtj}tr3tjd|}ntjjd|}|dkrot|dro|j}|S)Nloopcurrent_task)asyncioZget_event_loopPY_37rxZTaskhasattr)rwtaskrrrrxsrxcCs ttdrtj|SdS)NisasyncgenfunctionF)r{inspectr})objrrrr}s
r}c@sXeZdZejdeZejdeZejdeZejde	Z
dS)MimeTypergN)rNrOrPrhrir]rgsubtypesuffixr
parametersrrrrrsrc
	Csi|s%tdddddddiS|jd}g}xy|ddD]g}|sZqKd	|krx|jd	dn	|df\}}|j|jj|jd
fqKWt|}|djj}|dkrd
}d|kr|jddn	|df\}}d|kr8|jddn	|df\}}	td|d|d|	d|S)aParses a MIME type into its components.

    mimetype is a MIME type string.

    Returns a MimeType object.

    Example:

    >>> parse_mimetype('text/html; charset=utf-8')
    MimeType(type='text', subtype='html', suffix='',
             parameters={'charset': 'utf-8'})

    rgr1rrrr!r
Nr)z "r*z*/*r%+)rr>appendr@r=r)
ZmimetypepartsparamsitemkeyvalueZfulltypeZmtypestyperrrrparse_mimetypes"0,00rcCsXt|dd}|rTt|trT|ddkrT|ddkrTt|jS|S)NrZrrr
rrp)getattrrHr]rrZ)rdefaultrZrrrguess_filenames5
rc	Ks|stt|kr/tdj||}|rg}x|jD]\}}|sttt|krtdj|||rt|dn|}|j|d|f|dkrN|jdd|fqNWdjd	d
|D}dj||f}|S)zSets ``Content-Disposition`` header.

    disptype is a disposition type: inline, attachment, form-data.
    Should be valid extension token (see RFC 2183)

    params is a dict with disposition params.
    z!bad content disposition type {!r}z+bad content disposition parameter {!r}={!r}r1z"%s"filenamez	filename*zutf-8''z; css|]}dj|VqdS)r)N)join)rZpairrrrrsz-content_disposition_header.<locals>.<genexpr>)TOKENsetr3formatrqrrr)	ZdisptypeZquote_fieldsrrZlparamsrruZqvalZsparamsrrrcontent_disposition_headers"		rcseZdZdZdddddddd	d
ddd
ddddddddddiZdZejdZejdZ	iZ
eddZefddZ
dd Zed!d"Zed#d$Zed%d&Zed'd(Zed)d*Zed+d,Zed-d.Zed/d0Zed1d2Zed3d4Zed5d6Zd7d8Zd9d:ZS);AccessLoggeraHelper object to log access.

    Usage:
        log = logging.getLogger("spam")
        log_format = "%a %{User-Agent}i"
        access_logger = AccessLogger(log, log_format)
        access_logger.log(request, response, time)

    Format:
        %%  The percent sign
        %a  Remote IP-address (IP-address of proxy if using reverse proxy)
        %t  Time when the request was started to process
        %P  The process ID of the child that serviced the request
        %r  First line of request
        %s  Response status code
        %b  Size of response in bytes, including HTTP headers
        %T  Time taken to serve the request, in seconds
        %Tf Time taken to serve the request, in seconds with floating fraction
            in .06f format
        %D  Time taken to serve the request, in microseconds
        %{FOO}i  request.headers['FOO']
        %{FOO}o  response.headers['FOO']
        %{FOO}e  os.environ['FOO']

    aZremote_addresstZrequest_start_timePZ
process_idrZfirst_request_linesZresponse_statusbZ
response_sizeTZrequest_timeZTfZrequest_time_fracDZrequest_time_microrZrequest_headeroZresponse_headerz/%a %t "%r" %s %b "%{Referer}i" "%{User-Agent}i"z.%(\{([A-Za-z0-9\-_]+)\}([ioe])|[atPrsbOD]|Tf?)z(%[^s])	KeyMethodz
key methodcs`tj|d|tjj|}|sJ|j|}|tj|<|\|_|_dS)zInitialise the logger.

        logger is a logger object to be used for logging.
        log_format is an string with apache compatible log format description.

        
log_formatN)r4__init__r
_FORMAT_CACHErXcompile_format_log_format_methods)rMloggerrZ_compiled_format)r:rrrMs
zAccessLogger.__init__cCst}x|jj|D]}|ddkr]|j|d}ttd|d}nH|j|d|df}ttd|d}tj||d}|j|j	||qW|jj
d|}|jj
d|}||fS)aTranslate log_format into form usable by modulo formatting

        All known atoms will be replaced with %s
        Also methods for formatting of those atoms will be added to
        _methods in apropriate order

        For example we have log_format = "%a %t"
        This format will be translated to "%s %s"
        Also contents of _methods will be
        [self._format_a, self._format_t]
        These method will be called and results will be passed
        to translated string format.

        Each _format_* method receive 'args' which is list of arguments
        given to self.log

        Exceptions are _format_e, _format_i and _format_o methods which
        also receive key name (by functools.partial)

        r
r1rz
_format_%sr;z%sz%\1)list	FORMAT_REfindallLOG_FORMAT_MAPrr	functoolspartialrrsub
CLEANUP_RE)rMrmethodsZatomZ
format_keymrrrr]s	zAccessLogger.compile_formatcCs#|dkrdS|jj|dS)Nz(no headers)-)headersrX)rrequestresponsetimerrr	_format_iszAccessLogger._format_icCs|jj|dS)Nr)rrX)rrrrrrr	_format_oszAccessLogger._format_ocCs-|dkrdS|j}|dk	r)|SdS)Nr)Zremote)rrrZiprrr	_format_as	zAccessLogger._format_acCs2tjj}|tjd|}|jdS)NZsecondsz[%d/%b/%Y:%H:%M:%S +0000])datetimeZutcnowZ	timedeltastrftime)rrrnowZ
start_timerrr	_format_tszAccessLogger._format_tcCsdtjS)Nz<%s>)rVgetpid)rrrrrr	_format_PszAccessLogger._format_PcCs1|dkrdSdt|j|jf|jS)Nrz%s %s HTTP/%s.%s)tuplemethodZpath_qsversion)rrrrrr	_format_rszAccessLogger._format_rcCs|jS)N)status)rrrrrr	_format_sszAccessLogger._format_scCs|jS)N)Zbody_length)rrrrrr	_format_bszAccessLogger._format_bcCs
t|S)N)round)rrrrrr	_format_TszAccessLogger._format_TcCsd|S)Nz%06fr)rrrrrr
_format_TfszAccessLogger._format_TfcCst|dS)Ni@B)r)rrrrrr	_format_DszAccessLogger._format_Dcs fdd|jDS)Nc3s-|]#\}}||fVqdS)Nr)rrr)rrrrrrsz,AccessLogger._format_line.<locals>.<genexpr>)r)rMrrrr)rrrr_format_lineszAccessLogger._format_linecCsy|j|||}t}t}xo|D]g\}}|j||jtkrf|||<q1|\}	}
|j|	i}|||
<|||	<q1W|jj|j	t
|d|Wn"tk
r|jjdYnXdS)NextrazError in logging)
rrdictrr:r]rXrinforr	Exception	exception)rMrrrZfmt_infovaluesrrrZk1Zk2dctrrrlogs		


'
zAccessLogger.log)rNrOrPrQrZ
LOG_FORMATrecompilerrrrrrrstaticmethodrrrrrrrrrrrrrrr)r:rrs@(rc@s=eZdZdZddZeddZddZdS)	reifyaRUse as a class method decorator.  It operates almost exactly like
    the Python `@property` decorator, but it puts the result of the
    method it decorates into the instance dict after the first call,
    effectively replacing the function it decorates with an instance
    variable.  It is, in Python parlance, a data descriptor.

    cCsG||_y|j|_Wntk
r6d|_YnX|j|_dS)Nr1)wrappedrQrrNrZ)rMrrrrrs	
zreify.__init__cCszyNy|j|jSWn5tk
rL|j|}||j|j<|SYnXWn%tk
ru|dkrn|SYnXdS)N)_cacherZKeyErrorrAttributeError)rMinstowner	_sentinelrurrr__get__s


z
reify.__get__cCstddS)Nzreified property is read-only)r)rMrrrrr__set__sz
reify.__set__N)rNrOrPrQrsentinelrrrrrrrs
rz[^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$a^(?:(?:(?:[A-F0-9]{1,4}:){6}|(?=(?:[A-F0-9]{0,4}:){0,6}(?:[0-9]{1,3}\.){3}[0-9]{1,3}$)(([0-9A-F]{1,4}:){0,5}|:)((:[0-9A-F]{1,4}){1,5}:|:)|::(?:[A-F0-9]{1,4}:){5})(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])|(?:[A-F0-9]{1,4}:){7}[A-F0-9]{1,4}|(?=(?:[A-F0-9]{0,4}:){0,7}[A-F0-9]{0,4}$)(([0-9A-F]{1,4}:){1,7}|:)((:[0-9A-F]{1,4}){1,7}|:)|(?:[A-F0-9]{1,4}:){7}:|:(:[A-F0-9]{1,4}){7})$flagsr<cCs|dkrdSt|trHtj|s=tj|rAdSdSn_t|tttfrtj|s~t	j|rdSdSnt
dj|t|dS)NFTz{} [{}] is not a str or bytes)
rHr]_ipv4_regexmatch_ipv6_regexbytes	bytearray
memoryview_ipv4_regexb_ipv6_regexbrIrrg)rsrrr
is_ip_addresss	rc
Csttj}|tkrd}d}tj|\	}}}}}}}	}
}d||	|||||||fa|atS)NMonTueWedThuFriSatSunr1JanFebMarAprMayJunJulAugSepOctNovDecz#%s, %02d %3s %4d %02d:%02d:%02d GMT)rrrrrrr)
r1rrrrrrrrrrrr)intr_cached_current_datetimegmtime_cached_formatted_datetime)rZ_weekdaynameZ
_monthnameZyearZmonthZdayZhhZmmZssZwdyzrrrrfc822_formatted_time!s*$rc
CsI|\}}|}|dk	rEttt||WdQRXdS)N)rrr)rrefrZobrrr_weakref_handle7s
	
r	cCs`|dk	r\|dkr\|j|}|r:t|}|j|ttj||fSdS)Nr)rrcall_atr	weakrefr)rrZtimeoutrwZceil_timeoutwhenrrrweakref_handle?s
rcCsB|dk	r>|dkr>t|j|}|j||SdS)Nr)rrr
)cbrrwr
rrr
call_laterHsrc@s^eZdZdZddZddZddZdd	Zd
dZdd
Z	dS)
TimeoutHandlez Timeout handle cCs||_||_g|_dS)N)_timeout_loop
_callbacks)rMrwrrrrrQs		zTimeoutHandle.__init__cOs|jj|||fdS)N)rr)rMcallbackr.r/rrrregisterVszTimeoutHandle.registercCs|jjdS)N)rclear)rMrrrcloseYszTimeoutHandle.closecCsT|jdk	rP|jdkrPt|jj|j}|jj||jSdS)Nr)rrrrr
__call__)rMZatrrrstart\szTimeoutHandle.startcCsM|jdk	r@|jdkr@t|j}|j|jn	t}|S)Nr)rTimerContextrrr	TimerNoop)rMtimerrrrras
	zTimeoutHandle.timercCsOx;|jD]0\}}}tt|||WdQRXq
W|jjdS)N)rrrr)rMrr.r/rrrris
zTimeoutHandle.__call__N)
rNrOrPrQrrrrrrrrrrrNsrc@s(eZdZddZddZdS)rcCs|S)Nr)rMrrr	__enter__sszTimerNoop.__enter__cCsdS)NFr)rMexc_typeexc_valexc_tbrrr__exit__vszTimerNoop.__exit__N)rNrOrPrr"rrrrrqsrc@sFeZdZdZddZddZddZdd	Zd
S)rz( Low resolution timeout context manager cCs||_g|_d|_dS)NF)r_tasks
_cancelled)rMrwrrrr}s		zTimerContext.__init__cCs]td|j}|dkr*td|jrI|jtjd|jj||S)Nrwz4Timeout context manager should be used inside a task)	rxrr`r$cancelryTimeoutErrorr#r)rMr|rrrrs	
zTimerContext.__enter__cCs>|jr|jj|tjkr:|jr:tjddS)N)r#popryCancelledErrorr$r&)rMrr r!rrrr"s	
zTimerContext.__exit__cCs:|js6x!t|jD]}|jqWd|_dS)NT)r$rr#r%)rMr|rrrrs	zTimerContext.timeoutN)rNrOrPrQrrr"rrrrrrzs
rc@seZdZddZdS)CeilTimeoutcCst|jdk	rptd|j|_|jdkr?td|jjt|jj|j|j|_	|S)Nrwz4Timeout context manager should be used inside a task)
rrxrZ_taskr`r
rrZ_cancel_taskZ_cancel_handler)rMrrrrs		(zCeilTimeout.__enter__N)rNrOrPrrrrrr)sr)c@seZdZedddgZdZdZeZddZ	e
dejdd	Z
e
dejd
dZe
dejd
dZdS)HeadersMixin
_content_type
_content_dict_stored_content_typeNcCsI||_|dkr*d|_i|_ntj|\|_|_dS)Nzapplication/octet-stream)r-r+r,cgiZparse_header)rMrawrrr_parse_content_types
		z HeadersMixin._parse_content_type
_CONTENT_TYPEcCs5|jj|}|j|kr.|j||jS)z7The value of content part for Content-Type HTTP header.)_headersrXr-r0r+)rMr1r/rrrcontent_types
zHeadersMixin.content_typecCs>|jj|}|j|kr.|j||jjdS)z7The value of charset part for Content-Type HTTP header.charset)r2rXr-r0r,)rMr1r/rrrr4s
zHeadersMixin.charset_CONTENT_LENGTHcCs&|jj|}|r"t|SdS)z(The value of Content-Length HTTP header.N)r2rXr)rMr5content_lengthrrrr6szHeadersMixin.content_length)rNrOrP	frozensetZATTRSr+r,rr-r0propertyrZCONTENT_TYPEr3r4ZCONTENT_LENGTHr6rrrrr*s	r*cCs|js|j|dS)N)done
set_result)futresultrrrr:sr:cCs|js|j|dS)N)r9
set_exception)r;excrrrr=sr=)r)rr)rr)drQryrArEr.rrr~r\rVrsysrrcollectionsr
contextlibrmathrZpathlibrZurllib.parserZurllib.requestrZ
async_timeoutrhZ	multidictrZyarlr	r1rabcrrr
__all__version_infoZPY_36rzZidna_sslZpatch_match_hostnameobjectrboolrWrXZ
NO_EXTENSIONSrrangeZCHARrZCTLZ
SEPARATORSrZ
coroutinesZ_DEBUGZ	old_debug	coroutiner0rrTrcrrfrvrxr}rrrrrrZ
_ipv4_patternZ
_ipv6_patternrr
IGNORECASErrBrrrrrrr	rrrrrrr)r*r:r=rrrr<module>s
	"/'				(3++&"!	#	%
+
Back to Directory File Manager