context.cpython-36.opt-1.pyc000064400000031452147204630710011626 0ustar003 \*@sddlZddlZddlZddlmZddlmZgZGdddeZGdddeZ Gd d d eZ Gd d d eZ Gd dde Z GdddejZGddde ZeddeeDe_ejdkrPGdddejZGdddejZGdddejZGddde ZGddde ZGd d!d!e Zeeed"Zeed#Zn8Gd$ddejZGd%dde Zd&eiZeed&Zd'd(ZejZd)d*Zd+d,Z d-d.Z!dS)/N)process) reductionc@s eZdZdS) ProcessErrorN)__name__ __module__ __qualname__r r //usr/lib64/python3.6/multiprocessing/context.pyrsrc@s eZdZdS)BufferTooShortN)rrrr r r r r sr c@s eZdZdS) TimeoutErrorN)rrrr r r r r sr c@s eZdZdS)AuthenticationErrorN)rrrr r r r r sr c@sVeZdZeZeZeZeZeej Z eej Z ddZ ddZ dBddZ dd Zd d ZdCd dZdDddZdEddZddZdFddZdGddZdHddZddZd d fd fdd Zd!d"Zd#d$Zdd%d&d'Zdd%d(d)Zd*d+Zd,d-ZdId.d/Zd0d1Z d2d3Z!d4d5Z"dJd6d7Z#dKd9d:Z$dLd;d<Z%e&d=d>Z'e'j(d?d>Z'd@dAZ)d S)M BaseContextcCs"tj}|dkrtdn|SdS)z(Returns the number of CPUs in the systemNzcannot determine number of cpus)os cpu_countNotImplementedError)selfZnumr r r r(s zBaseContext.cpu_countcCs&ddlm}||jd}|j|S)zReturns a manager associated with a running server process The managers methods such as `Lock()`, `Condition()` and `Queue()` can be used to create shared objects. r) SyncManager)ctx)Zmanagersr get_contextstart)rrmr r r Manager0s zBaseContext.ManagerTcCsddlm}||S)z1Returns two connection object connected by a piper)Pipe) connectionr)rZduplexrr r r r;s zBaseContext.PipecCsddlm}||jdS)z#Returns a non-recursive lock objectr)Lock)r) synchronizerr)rrr r r r@s zBaseContext.LockcCsddlm}||jdS)zReturns a recursive lock objectr)RLock)r)rrr)rrr r r rEs zBaseContext.RLockNcCsddlm}|||jdS)zReturns a condition objectr) Condition)r)rrr)rlockrr r r rJs zBaseContext.ConditionrcCsddlm}|||jdS)zReturns a semaphore objectr) Semaphore)r)rr r)rvaluer r r r r Os zBaseContext.SemaphorecCsddlm}|||jdS)z"Returns a bounded semaphore objectr)BoundedSemaphore)r)rr"r)rr!r"r r r r"Ts zBaseContext.BoundedSemaphorecCsddlm}||jdS)zReturns an event objectr)Event)r)rr#r)rr#r r r r#Ys zBaseContext.EventcCs ddlm}|||||jdS)zReturns a barrier objectr)Barrier)r)rr$r)rZpartiesactionZtimeoutr$r r r r$^s zBaseContext.BarrierrcCsddlm}|||jdS)zReturns a queue objectr)Queue)r)queuesr&r)rmaxsizer&r r r r&cs zBaseContext.QueuecCsddlm}|||jdS)zReturns a queue objectr) JoinableQueue)r)r'r)r)rr(r)r r r r)hs zBaseContext.JoinableQueuecCsddlm}||jdS)zReturns a queue objectr) SimpleQueue)r)r'r*r)rr*r r r r*ms zBaseContext.SimpleQueuecCs"ddlm}||||||jdS)zReturns a process pool objectr)Pool)context)Zpoolr+r)rZ processesZ initializerZinitargsZmaxtasksperchildr+r r r r+rs  zBaseContext.PoolcGsddlm}||f|S)zReturns a shared objectr)RawValue) sharedctypesr-)rtypecode_or_typeargsr-r r r r-ys zBaseContext.RawValuecCsddlm}|||S)zReturns a shared arrayr)RawArray)r.r1)rr/size_or_initializerr1r r r r1~s zBaseContext.RawArray)rcGs&ddlm}||f|||jdS)z$Returns a synchronized shared objectr)Value)rr)r.r3r)rr/rr0r3r r r r3s  zBaseContext.ValuecCs ddlm}|||||jdS)z#Returns a synchronized shared arrayr)Array)rr)r.r4r)rr/r2rr4r r r r4s zBaseContext.ArraycCs,tjdkr(ttddr(ddlm}|dS)zCheck whether this is a fake forked process in a frozen executable. If so then run code specified by commandline and exit. win32frozenFr)freeze_supportN)sysplatformgetattrspawnr7)rr7r r r r7s zBaseContext.freeze_supportcCsddlm}|S)zZReturn package logger -- if it does not already exist then it is created. r) get_logger)utilr<)rr<r r r r<s zBaseContext.get_loggercCsddlm}||S)z8Turn on logging and add a handler which prints to stderrr) log_to_stderr)r=r>)rlevelr>r r r r>s zBaseContext.log_to_stderrcCsddlm}dS)zVInstall support for sending connections and sockets between processes r)rN)r)rrr r r allow_connection_picklingsz%BaseContext.allow_connection_picklingcCsddlm}||dS)zSets the path to a python.exe or pythonw.exe binary used to run child processes instead of sys.executable when using the 'spawn' start method. Useful for people embedding Python. r)set_executableN)r;rB)r executablerBr r r rBs zBaseContext.set_executablecCsddlm}||dS)zkSet list of module names to try to load in forkserver process. This is really just a hint. r)set_forkserver_preloadN) forkserverrD)rZ module_namesrDr r r rDs z"BaseContext.set_forkserver_preloadc CsF|dkr |Sy t|}Wn tk r8td|YnX|j|S)Nzcannot find context for %r)_concrete_contextsKeyError ValueError_check_available)rmethodrr r r rs zBaseContext.get_contextFcCs|jS)N)_name)r allow_noner r r get_start_methodszBaseContext.get_start_methodcCs tddS)Nz+cannot set start method of concrete context)rH)rrJforcer r r set_start_methodszBaseContext.set_start_methodcCs tjdS)z_Controls how objects will be reduced to a form that can be shared with other processes.r)globalsget)rr r r reducerszBaseContext.reducercCs|td<dS)Nr)rP)rrr r r rRscCsdS)Nr )rr r r rIszBaseContext._check_available)T)N)r)r)NN)r)r)N)N)F)F)*rrrrr r r staticmethodrZcurrent_processZactive_childrenrrrrrrr r"r#r$r&r)r*r+r-r1r3r4r7r<r>rArBrDrrMrOpropertyrRsetterrIr r r r rsJ              rc@seZdZdZeddZdS)ProcessNcCstjjj|S)N)_default_contextrrV_Popen) process_objr r r rXszProcess._Popen)rrr _start_methodrSrXr r r r rVsrVcsFeZdZeZddZd fdd ZdddZdd d Zd d ZZ S)DefaultContextcCs||_d|_dS)N)rW_actual_context)rr,r r r __init__szDefaultContext.__init__Ncs0|dkr |jdkr|j|_|jStj|SdS)N)r\rWsuperr)rrJ) __class__r r rs  zDefaultContext.get_contextFcCs>|jdk r| rtd|dkr.|r.d|_dS|j||_dS)Nzcontext has already been set)r\ RuntimeErrorr)rrJrNr r r rOs  zDefaultContext.set_start_methodcCs"|jdkr|rdS|j|_|jjS)N)r\rWrK)rrLr r r rMs  zDefaultContext.get_start_methodcCs,tjdkrdgStjr dddgSddgSdS)Nr5r;forkrE)r8r9rHAVE_SEND_HANDLE)rr r r get_all_start_methodss   z$DefaultContext.get_all_start_methods)N)F)F) rrrrVr]rrOrMrc __classcell__r r )r_r r[s   r[ccs|]}|ddkr|VqdS)r_Nr ).0xr r r srhr5c@seZdZdZeddZdS) ForkProcessracCsddlm}||S)Nr)Popen)Z popen_forkrj)rYrjr r r rXs zForkProcess._PopenN)rrrrZrSrXr r r r risric@seZdZdZeddZdS) SpawnProcessr;cCsddlm}||S)Nr)rj)Zpopen_spawn_posixrj)rYrjr r r rXs zSpawnProcess._PopenN)rrrrZrSrXr r r r rksrkc@seZdZdZeddZdS)ForkServerProcessrEcCsddlm}||S)Nr)rj)Zpopen_forkserverrj)rYrjr r r rX s zForkServerProcess._PopenN)rrrrZrSrXr r r r rlsrlc@seZdZdZeZdS) ForkContextraN)rrrrKrirVr r r r rm%srmc@seZdZdZeZdS) SpawnContextr;N)rrrrKrkrVr r r r rn)srnc@seZdZdZeZddZdS)ForkServerContextrEcCstjstddS)Nz%forkserver start method not available)rrbrH)rr r r rI0sz"ForkServerContext._check_availableN)rrrrKrlrVrIr r r r ro-sro)rar;rErac@seZdZdZeddZdS)rkr;cCsddlm}||S)Nr)rj)Zpopen_spawn_win32rj)rYrjr r r rX?s zSpawnProcess._PopenN)rrrrZrSrXr r r r rk=sc@seZdZdZeZdS)rnr;N)rrrrKrkrVr r r r rnDsr;cCst|t_dS)N)rFrWr\)rJr r r _force_start_methodQsrpcCs ttddS)Nspawning_popen)r:_tlsr r r r get_spawning_popenZsrscCs |t_dS)N)rrrq)popenr r r set_spawning_popen]srucCs tdkrtdt|jdS)NzF%s objects should only be shared between processes through inheritance)rsr`typer)objr r r assert_spawning`s rx)"rr8Z threadingr@rr__all__ Exceptionrr r r objectrZ BaseProcessrVr[listdirr9rirkrlrmrnrorFrWrpZlocalrrrsrurxr r r r sD  >'    context.cpython-36.pyc000064400000031452147204630710010667 0ustar003 \*@sddlZddlZddlZddlmZddlmZgZGdddeZGdddeZ Gd d d eZ Gd d d eZ Gd dde Z GdddejZGddde ZeddeeDe_ejdkrPGdddejZGdddejZGdddejZGddde ZGddde ZGd d!d!e Zeeed"Zeed#Zn8Gd$ddejZGd%dde Zd&eiZeed&Zd'd(ZejZd)d*Zd+d,Z d-d.Z!dS)/N)process) reductionc@s eZdZdS) ProcessErrorN)__name__ __module__ __qualname__r r //usr/lib64/python3.6/multiprocessing/context.pyrsrc@s eZdZdS)BufferTooShortN)rrrr r r r r sr c@s eZdZdS) TimeoutErrorN)rrrr r r r r sr c@s eZdZdS)AuthenticationErrorN)rrrr r r r r sr c@sVeZdZeZeZeZeZeej Z eej Z ddZ ddZ dBddZ dd Zd d ZdCd dZdDddZdEddZddZdFddZdGddZdHddZddZd d fd fdd Zd!d"Zd#d$Zdd%d&d'Zdd%d(d)Zd*d+Zd,d-ZdId.d/Zd0d1Z d2d3Z!d4d5Z"dJd6d7Z#dKd9d:Z$dLd;d<Z%e&d=d>Z'e'j(d?d>Z'd@dAZ)d S)M BaseContextcCs"tj}|dkrtdn|SdS)z(Returns the number of CPUs in the systemNzcannot determine number of cpus)os cpu_countNotImplementedError)selfZnumr r r r(s zBaseContext.cpu_countcCs&ddlm}||jd}|j|S)zReturns a manager associated with a running server process The managers methods such as `Lock()`, `Condition()` and `Queue()` can be used to create shared objects. r) SyncManager)ctx)Zmanagersr get_contextstart)rrmr r r Manager0s zBaseContext.ManagerTcCsddlm}||S)z1Returns two connection object connected by a piper)Pipe) connectionr)rZduplexrr r r r;s zBaseContext.PipecCsddlm}||jdS)z#Returns a non-recursive lock objectr)Lock)r) synchronizerr)rrr r r r@s zBaseContext.LockcCsddlm}||jdS)zReturns a recursive lock objectr)RLock)r)rrr)rrr r r rEs zBaseContext.RLockNcCsddlm}|||jdS)zReturns a condition objectr) Condition)r)rrr)rlockrr r r rJs zBaseContext.ConditionrcCsddlm}|||jdS)zReturns a semaphore objectr) Semaphore)r)rr r)rvaluer r r r r Os zBaseContext.SemaphorecCsddlm}|||jdS)z"Returns a bounded semaphore objectr)BoundedSemaphore)r)rr"r)rr!r"r r r r"Ts zBaseContext.BoundedSemaphorecCsddlm}||jdS)zReturns an event objectr)Event)r)rr#r)rr#r r r r#Ys zBaseContext.EventcCs ddlm}|||||jdS)zReturns a barrier objectr)Barrier)r)rr$r)rZpartiesactionZtimeoutr$r r r r$^s zBaseContext.BarrierrcCsddlm}|||jdS)zReturns a queue objectr)Queue)r)queuesr&r)rmaxsizer&r r r r&cs zBaseContext.QueuecCsddlm}|||jdS)zReturns a queue objectr) JoinableQueue)r)r'r)r)rr(r)r r r r)hs zBaseContext.JoinableQueuecCsddlm}||jdS)zReturns a queue objectr) SimpleQueue)r)r'r*r)rr*r r r r*ms zBaseContext.SimpleQueuecCs"ddlm}||||||jdS)zReturns a process pool objectr)Pool)context)Zpoolr+r)rZ processesZ initializerZinitargsZmaxtasksperchildr+r r r r+rs  zBaseContext.PoolcGsddlm}||f|S)zReturns a shared objectr)RawValue) sharedctypesr-)rtypecode_or_typeargsr-r r r r-ys zBaseContext.RawValuecCsddlm}|||S)zReturns a shared arrayr)RawArray)r.r1)rr/size_or_initializerr1r r r r1~s zBaseContext.RawArray)rcGs&ddlm}||f|||jdS)z$Returns a synchronized shared objectr)Value)rr)r.r3r)rr/rr0r3r r r r3s  zBaseContext.ValuecCs ddlm}|||||jdS)z#Returns a synchronized shared arrayr)Array)rr)r.r4r)rr/r2rr4r r r r4s zBaseContext.ArraycCs,tjdkr(ttddr(ddlm}|dS)zCheck whether this is a fake forked process in a frozen executable. If so then run code specified by commandline and exit. win32frozenFr)freeze_supportN)sysplatformgetattrspawnr7)rr7r r r r7s zBaseContext.freeze_supportcCsddlm}|S)zZReturn package logger -- if it does not already exist then it is created. r) get_logger)utilr<)rr<r r r r<s zBaseContext.get_loggercCsddlm}||S)z8Turn on logging and add a handler which prints to stderrr) log_to_stderr)r=r>)rlevelr>r r r r>s zBaseContext.log_to_stderrcCsddlm}dS)zVInstall support for sending connections and sockets between processes r)rN)r)rrr r r allow_connection_picklingsz%BaseContext.allow_connection_picklingcCsddlm}||dS)zSets the path to a python.exe or pythonw.exe binary used to run child processes instead of sys.executable when using the 'spawn' start method. Useful for people embedding Python. r)set_executableN)r;rB)r executablerBr r r rBs zBaseContext.set_executablecCsddlm}||dS)zkSet list of module names to try to load in forkserver process. This is really just a hint. r)set_forkserver_preloadN) forkserverrD)rZ module_namesrDr r r rDs z"BaseContext.set_forkserver_preloadc CsF|dkr |Sy t|}Wn tk r8td|YnX|j|S)Nzcannot find context for %r)_concrete_contextsKeyError ValueError_check_available)rmethodrr r r rs zBaseContext.get_contextFcCs|jS)N)_name)r allow_noner r r get_start_methodszBaseContext.get_start_methodcCs tddS)Nz+cannot set start method of concrete context)rH)rrJforcer r r set_start_methodszBaseContext.set_start_methodcCs tjdS)z_Controls how objects will be reduced to a form that can be shared with other processes.r)globalsget)rr r r reducerszBaseContext.reducercCs|td<dS)Nr)rP)rrr r r rRscCsdS)Nr )rr r r rIszBaseContext._check_available)T)N)r)r)NN)r)r)N)N)F)F)*rrrrr r r staticmethodrZcurrent_processZactive_childrenrrrrrrr r"r#r$r&r)r*r+r-r1r3r4r7r<r>rArBrDrrMrOpropertyrRsetterrIr r r r rsJ              rc@seZdZdZeddZdS)ProcessNcCstjjj|S)N)_default_contextrrV_Popen) process_objr r r rXszProcess._Popen)rrr _start_methodrSrXr r r r rVsrVcsFeZdZeZddZd fdd ZdddZdd d Zd d ZZ S)DefaultContextcCs||_d|_dS)N)rW_actual_context)rr,r r r __init__szDefaultContext.__init__Ncs0|dkr |jdkr|j|_|jStj|SdS)N)r\rWsuperr)rrJ) __class__r r rs  zDefaultContext.get_contextFcCs>|jdk r| rtd|dkr.|r.d|_dS|j||_dS)Nzcontext has already been set)r\ RuntimeErrorr)rrJrNr r r rOs  zDefaultContext.set_start_methodcCs"|jdkr|rdS|j|_|jjS)N)r\rWrK)rrLr r r rMs  zDefaultContext.get_start_methodcCs,tjdkrdgStjr dddgSddgSdS)Nr5r;forkrE)r8r9rHAVE_SEND_HANDLE)rr r r get_all_start_methodss   z$DefaultContext.get_all_start_methods)N)F)F) rrrrVr]rrOrMrc __classcell__r r )r_r r[s   r[ccs|]}|ddkr|VqdS)r_Nr ).0xr r r srhr5c@seZdZdZeddZdS) ForkProcessracCsddlm}||S)Nr)Popen)Z popen_forkrj)rYrjr r r rXs zForkProcess._PopenN)rrrrZrSrXr r r r risric@seZdZdZeddZdS) SpawnProcessr;cCsddlm}||S)Nr)rj)Zpopen_spawn_posixrj)rYrjr r r rXs zSpawnProcess._PopenN)rrrrZrSrXr r r r rksrkc@seZdZdZeddZdS)ForkServerProcessrEcCsddlm}||S)Nr)rj)Zpopen_forkserverrj)rYrjr r r rX s zForkServerProcess._PopenN)rrrrZrSrXr r r r rlsrlc@seZdZdZeZdS) ForkContextraN)rrrrKrirVr r r r rm%srmc@seZdZdZeZdS) SpawnContextr;N)rrrrKrkrVr r r r rn)srnc@seZdZdZeZddZdS)ForkServerContextrEcCstjstddS)Nz%forkserver start method not available)rrbrH)rr r r rI0sz"ForkServerContext._check_availableN)rrrrKrlrVrIr r r r ro-sro)rar;rErac@seZdZdZeddZdS)rkr;cCsddlm}||S)Nr)rj)Zpopen_spawn_win32rj)rYrjr r r rX?s zSpawnProcess._PopenN)rrrrZrSrXr r r r rk=sc@seZdZdZeZdS)rnr;N)rrrrKrkrVr r r r rnDsr;cCst|t_dS)N)rFrWr\)rJr r r _force_start_methodQsrpcCs ttddS)Nspawning_popen)r:_tlsr r r r get_spawning_popenZsrscCs |t_dS)N)rrrq)popenr r r set_spawning_popen]srucCs tdkrtdt|jdS)NzF%s objects should only be shared between processes through inheritance)rsr`typer)objr r r assert_spawning`s rx)"rr8Z threadingr@rr__all__ Exceptionrr r r objectrZ BaseProcessrVr[listdirr9rirkrlrmrnrorFrWrpZlocalrrrsrurxr r r r sD  >'    forkserver.cpython-36.opt-1.pyc000064400000015126147204630710012332 0ustar003 \!@sddlZddlZddlZddlZddlZddlZddlZddlZddlm Z ddlm Z ddl m Z ddlm Z ddlmZddlmZd d d d gZd ZejdZGdddeZdddZddZddZddZeZejZejZejZejZdS)N) connection)process) reduction)semaphore_tracker)spawn)utilensure_runningget_inherited_fdsconnect_to_new_processset_forkserver_preloadQc@s4eZdZddZddZddZddZd d Zd S) ForkServercCs.d|_d|_d|_d|_tj|_dg|_dS)N__main__)_forkserver_address_forkserver_alive_fd_forkserver_pid_inherited_fds threadingZLock_lock_preload_modules)selfr2/usr/lib64/python3.6/multiprocessing/forkserver.py__init__!s  zForkServer.__init__cCs&tdd|jDstd||_dS)z>Set list of module names to try to load in forkserver process.css|]}t|tkVqdS)N)typestr).0modrrr +sz4ForkServer.set_forkserver_preload..z&module_names must be a list of stringsN)allr TypeError)rZ modules_namesrrrr )sz!ForkServer.set_forkserver_preloadcCs|jS)zReturn list of fds inherited from parent process. This returns None if the current process was not started by fork server. )r)rrrrr /szForkServer.get_inherited_fdscCs|jt|dtkr tdtjtj}|j|jtj \}}tj \}}|||j t j g}||7}z.r(iz-czCfrom multiprocessing.forkserver import main; main(%d, %d, %r, **%r))rrr rr)waitpidWNOHANGr+rrrrZget_preparation_datadictitemsr'r(rZarbitrary_addressZbindchmodZlistenr*filenoZget_executablerZ_args_from_interpreter_flagsZspawnv_passfds) rpidZstatuscmddatalistenerZaddressalive_rZalive_wZ fds_to_passZexeargsr)r4rr TsL             zForkServer.ensure_runningN)__name__ __module__ __qualname__rr r r r rrrrrs rc4Cs|rhd|kr8|dk r8dtj_ztj|Wdtj`Xx.|D]&}y t|Wq>tk rbYq>Xq>Wtjt j t j t j t j i}dd|j D}tjtj|d,}tj} |jt_| j|tj| j|tjxyxdd| jD} | rPqW|| kr t|jd l} d } tjd krzFyt| |||Wn.tk rntjtj tj!j"YnXWdtj#| XWdQRXWqt$k r} z| j%t%j&krWYdd} ~ XqXqWWdQRXWdQRXdS) zRun forkserver.rNTcSsi|]\}}tj|||qSr)signal)rsigvalrrr szmain..)r:cSsg|]\}}|jqSr)Zfileobj)rkeyZeventsrrr szmain..rr)'rZcurrent_processZ _inheritingrZimport_main_path __import__ ImportErrorrZ _close_stdinrDSIGCHLDSIG_IGNSIGINTr8r'r( selectorsZDefaultSelectorZ getsockname _forkserverrregisterZ EVENT_READZselect SystemExitZacceptr)fork _serve_one Exceptionsys excepthookexc_infostderrflush_exitOSErrorerrnoZ ECONNABORTED)Z listener_fdr?Zpreloadr/r0modnamehandlersZ old_handlersr>ZselectorZrfdsscodeerrrmainsR          rcc Cs|jtj|x |jD]\}}tj||qWtj|td}|j|^}}t_} t_ | t j _ t |tjdtjkrddl} | jtj|} t || dS)Nrrandomr)r+r)r8rDrZrecvfdsr%rPrrrZ_semaphore_trackerZ_fdwrite_unsignedgetpidrVmodulesrdZseedr_main) r`r>r?r_rErFr,r.r-ZstfdrdrarrrrTs   rTcCsRd}tj}x8t||krBtj||t|}|s8td||7}q Wtj|dS)Nzunexpected EOFr)UNSIGNED_STRUCTsizer$r)readEOFErrorZunpack)fdr=Zlengthr`rrr read_unsigneds rocCs@tj|}x0|r:tj||}|dkr,td||d}q WdS)Nrzshould not get here)rjZpackr)write RuntimeError)rnnmsgnbytesrrrres   re)NN)r]r)rOrDr'ZstructrVrrrcontextrrrr__all__r%ZStructrjobjectrrcrTrorerPr r r r rrrrs6       s =!  forkserver.cpython-36.opt-2.pyc000064400000013501147204630710012326 0ustar003 \!@sddlZddlZddlZddlZddlZddlZddlZddlZddlm Z ddlm Z ddl m Z ddlm Z ddlmZddlmZd d d d gZd ZejdZGdddeZdddZddZddZddZeZejZejZejZejZdS)N) connection)process) reduction)semaphore_tracker)spawn)utilensure_runningget_inherited_fdsconnect_to_new_processset_forkserver_preloadQc@s4eZdZddZddZddZddZd d Zd S) ForkServercCs.d|_d|_d|_d|_tj|_dg|_dS)N__main__)_forkserver_address_forkserver_alive_fd_forkserver_pid_inherited_fds threadingZLock_lock_preload_modules)selfr2/usr/lib64/python3.6/multiprocessing/forkserver.py__init__!s  zForkServer.__init__cCs&tdd|jDstd||_dS)Ncss|]}t|tkVqdS)N)typestr).0modrrr +sz4ForkServer.set_forkserver_preload..z&module_names must be a list of strings)allr TypeError)rZ modules_namesrrrr )sz!ForkServer.set_forkserver_preloadcCs|jS)N)r)rrrrr /szForkServer.get_inherited_fdscCs|jt|dtkr tdtjtj}|j|jtj \}}tj \}}|||j t j g}||7}z.r(iz-czCfrom multiprocessing.forkserver import main; main(%d, %d, %r, **%r))rrr rr)waitpidWNOHANGr+rrrrZget_preparation_datadictitemsr'r(rZarbitrary_addressZbindchmodZlistenr*filenoZget_executablerZ_args_from_interpreter_flagsZspawnv_passfds) rpidZstatuscmddatalistenerZaddressalive_rZalive_wZ fds_to_passZexeargsr)r4rr TsL             zForkServer.ensure_runningN)__name__ __module__ __qualname__rr r r r rrrrrs rc4Cs|rhd|kr8|dk r8dtj_ztj|Wdtj`Xx.|D]&}y t|Wq>tk rbYq>Xq>Wtjt j t j t j t j i}dd|j D}tjtj|d,}tj} |jt_| j|tj| j|tjxyxdd| jD} | rPqW|| kr t|jdl} d } tjdkrzFyt| |||Wn.tk rntjtj tj!j"YnXWdtj#| XWdQRXWqt$k r} z| j%t%j&krWYdd} ~ XqXqWWdQRXWdQRXdS) NrTcSsi|]\}}tj|||qSr)signal)rsigvalrrr szmain..)r:cSsg|]\}}|jqSr)Zfileobj)rkeyZeventsrrr szmain..rr)'rZcurrent_processZ _inheritingrZimport_main_path __import__ ImportErrorrZ _close_stdinrDSIGCHLDSIG_IGNSIGINTr8r'r( selectorsZDefaultSelectorZ getsockname _forkserverrregisterZ EVENT_READZselect SystemExitZacceptr)fork _serve_one Exceptionsys excepthookexc_infostderrflush_exitOSErrorerrnoZ ECONNABORTED)Z listener_fdr?Zpreloadr/r0modnamehandlersZ old_handlersr>ZselectorZrfdsscodeerrrmainsR          rcc Cs|jtj|x |jD]\}}tj||qWtj|td}|j|^}}t_} t_ | t j _ t |tjdtjkrddl} | jtj|} t || dS)Nrrandomr)r+r)r8rDrZrecvfdsr%rPrrrZ_semaphore_trackerZ_fdwrite_unsignedgetpidrVmodulesrdZseedr_main) r`r>r?r_rErFr,r.r-ZstfdrdrarrrrTs   rTcCsRd}tj}x8t||krBtj||t|}|s8td||7}q Wtj|dS)Nzunexpected EOFr)UNSIGNED_STRUCTsizer$r)readEOFErrorZunpack)fdr=Zlengthr`rrr read_unsigneds rocCs@tj|}x0|r:tj||}|dkr,td||d}q WdS)Nrzshould not get here)rjZpackr)write RuntimeError)rnnmsgnbytesrrrres   re)NN)r]r)rOrDr'ZstructrVrrrcontextrrrr__all__r%ZStructrjobjectrrcrTrorerPr r r r rrrrs6       s =!  forkserver.cpython-36.pyc000064400000015266147204630710011400 0ustar003 \!@sddlZddlZddlZddlZddlZddlZddlZddlZddlm Z ddlm Z ddl m Z ddlm Z ddlmZddlmZd d d d gZd ZejdZGdddeZdddZddZddZddZeZejZejZejZejZdS)N) connection)process) reduction)semaphore_tracker)spawn)utilensure_runningget_inherited_fdsconnect_to_new_processset_forkserver_preloadQc@s4eZdZddZddZddZddZd d Zd S) ForkServercCs.d|_d|_d|_d|_tj|_dg|_dS)N__main__)_forkserver_address_forkserver_alive_fd_forkserver_pid_inherited_fds threadingZLock_lock_preload_modules)selfr2/usr/lib64/python3.6/multiprocessing/forkserver.py__init__!s  zForkServer.__init__cCs&tdd|jDstd||_dS)z>Set list of module names to try to load in forkserver process.css|]}t|tkVqdS)N)typestr).0modrrr +sz4ForkServer.set_forkserver_preload..z&module_names must be a list of stringsN)allr TypeError)rZ modules_namesrrrr )sz!ForkServer.set_forkserver_preloadcCs|jS)zReturn list of fds inherited from parent process. This returns None if the current process was not started by fork server. )r)rrrrr /szForkServer.get_inherited_fdscCs|jt|dtkr tdtjtj}|j|jtj \}}tj \}}|||j t j g}||7}z.r(iz-czCfrom multiprocessing.forkserver import main; main(%d, %d, %r, **%r))rrr rr)waitpidWNOHANGr+rrrrZget_preparation_datadictitemsr'r(rZarbitrary_addressZbindchmodZlistenr*filenoZget_executablerZ_args_from_interpreter_flagsZspawnv_passfds) rpidZstatuscmddatalistenerZaddressalive_rZalive_wZ fds_to_passZexeargsr)r4rr TsL             zForkServer.ensure_runningN)__name__ __module__ __qualname__rr r r r rrrrrs rc4Cs|rhd|kr8|dk r8dtj_ztj|Wdtj`Xx.|D]&}y t|Wq>tk rbYq>Xq>Wtjt j t j t j t j i}dd|j D}tjtj|dR}tj<} |jt_| j|tj| j|tjx yxdd| jD} | rPqW|| kr$tj|d d ks tt|| ks2t|jd l} d } tjd krzFyt| |||Wn.tk rt j!t j"t j#j$YnXWdtj%| XWdQRXWqt&k r} z| j't'j(krւWYdd} ~ XqXqWWdQRXWdQRXdS) zRun forkserver.rNTcSsi|]\}}tj|||qSr)signal)rsigvalrrr szmain..)r:cSsg|]\}}|jqSr)Zfileobj)rkeyZeventsrrr szmain..rr))rZcurrent_processZ _inheritingrZimport_main_path __import__ ImportErrorrZ _close_stdinrDSIGCHLDSIG_IGNSIGINTr8r'r( selectorsZDefaultSelectorZ getsockname _forkserverrregisterZ EVENT_READZselectr)readAssertionError SystemExitZacceptfork _serve_one Exceptionsys excepthookexc_infostderrflush_exitOSErrorerrnoZ ECONNABORTED)Z listener_fdr?Zpreloadr/r0modnamehandlersZ old_handlersr>ZselectorZrfdsscodeerrrmainsV          rfc Cs|jtj|x |jD]\}}tj||qWtj|td}|jt|tks\t|^}}t _ } t _ | t j _t|tjdtjkrddl} | jtj|} t|| dS)Nrrandomr)r+r)r8rDrZrecvfdsr%r$rTrQrrrZ_semaphore_trackerZ_fdwrite_unsignedgetpidrYmodulesrgZseedr_main) rcr>r?rbrErFr,r.r-ZstfdrgrdrrrrWs   rWcCsRd}tj}x8t||krBtj||t|}|s8td||7}q Wtj|dS)NrJzunexpected EOFr)UNSIGNED_STRUCTsizer$r)rSEOFErrorZunpack)fdr=Zlengthrcrrr read_unsigneds rpcCs@tj|}x0|r:tj||}|dkr,td||d}q WdS)Nrzshould not get here)rlZpackr)write RuntimeError)ronmsgnbytesrrrrhs   rh)NN)r`r)rPrDr'ZstructrYrrrcontextrrrr__all__r%ZStructrlobjectrrfrWrprhrQr r r r rrrrs6       s =!  heap.cpython-36.opt-1.pyc000064400000013405147204630710011055 0ustar003 \ @sddlZddlZddlZddlZddlZddlZddlmZmZddl m Z dgZ ej dkrvddl Z GdddeZn,Gd ddeZd d Zd d ZejeeGdddeZGdddeZdS)N) reductionassert_spawning)util BufferWrapperZwin32c@s,eZdZejZddZddZddZdS)ArenacCsz||_xTtdD]@}dtjt|jf}tjd||d}tjdkrHP|j qWt d||_ ||_ |j|j f|_ dS)Ndz pym-%d-%sr)tagnamerzCannot find name for new mmap)sizerangeosgetpidnext_randmmap_winapiZ GetLastErrorcloseFileExistsErrornamebuffer_state)selfr irZbufr,/usr/lib64/python3.6/multiprocessing/heap.py__init__"s  zArena.__init__cCst||jS)N)rr)rrrr __getstate__1szArena.__getstate__cCs,|\|_|_|_tjd|j|jd|_dS)Nr)r r )r rrrr)rstaterrr __setstate__5szArena.__setstate__N) __name__ __module__ __qualname__tempfileZ_RandomNameSequencerrrrrrrrrsrc@seZdZdddZdS)rrc Cs||_||_|d krtjdtjtjd\|_}tj|tj |tj |jft |jdddN}d }||krd|}xt ||D]}|j |qW~|j d||WdQRXtj|j|j|_dS) Nrzpym-%d-)prefixdirwbF)closefdir i)r fdr#Zmkstempr rrZ get_temp_dirunlinkFinalizeropenr writerr)rr r)rfZbsZzeros_rrrr@s"  zArena.__init__Nr )r )r r!r"rrrrrr>scCs(|jdkrtdt|jtj|jffS)NrzDArena is unpicklable because forking was enabled when it was createdr )r) ValueError rebuild_arenar rZDupFd)arrr reduce_arenaSs r3cCst||jS)N)rdetach)r Zdupfdrrrr1Ysr1c@sZeZdZdZejfddZeddZddZ dd Z d d Z d d Z ddZ ddZdS)HeapcCsJtj|_tj|_||_g|_i|_i|_ i|_ t |_ g|_ g|_dS)N)r r_lastpid threadingZLock_lock_size_lengths _len_to_seq_start_to_block_stop_to_blockset_allocated_blocks_arenas_pending_free_blocks)rr rrrrfs  z Heap.__init__cCs|d}|||@S)Nrr)nZ alignmentmaskrrr_roundupssz Heap._roundupc Cstj|j|}|t|jkrj|jt|j|tj}|jd9_t j d|t |}|j j ||d|fS|j|}|j|}|j}|s|j|=|j|=|\}}}|j||f=|j||f=|S)Nz"allocating a new mmap of length %dr)bisectZ bisect_leftr;lenrEmaxr:rPAGESIZErinforrAappendr<popr=r>) rr rlengtharenaseqblockstartstoprrr_mallocys"        z Heap._mallocc Cs|\}}}y|j||f}Wntk r0YnX|j|\}}y|j||f}Wntk rfYnX|j|\}}|||f}||}y|j|j|Wn.tk r|g|j|<tj|j|YnX||j||f<||j||f<dS)N) r>KeyError_absorbr=r<rLrGZinsortr;) rrQrOrRrSZ prev_blockr/Z next_blockrNrrr_frees(   z Heap._freecCs^|\}}}|j||f=|j||f=||}|j|}|j||sV|j|=|jj|||fS)N)r=r>r<remover;)rrQrOrRrSrNrPrrrrVs      z Heap._absorbc CsFx@y|jj}Wntk r&PYnX|jj||j|qWdS)N)rBrM IndexErrorr@rXrW)rrQrrr_free_pending_blockss zHeap._free_pending_blocksc CsN|jjds|jj|n0z"|j|jj||j|Wd|jjXdS)NF) r9acquirerBrLrZr@rXrWrelease)rrQrrrfrees  z Heap.freec Cstj|jkr|j|jh|j|jt|d|j}|j |\}}}||}||krj|j |||f|||f}|j j ||SQRXdS)Nr) r rr7rr9rZrErI _alignmentrTrWr@add)rr rOrRrSZnew_stoprQrrrmallocs  z Heap.mallocN)r r!r"r^rrJr staticmethodrErTrWrVrZr]r`rrrrr5bs  r5c@s"eZdZeZddZddZdS)rcCs0tjj|}||f|_tj|tjj|fddS)N)args)r_heapr`rrr+r])rr rQrrrrs  zBufferWrapper.__init__cCs&|j\\}}}}t|j|||S)N)r memoryviewr)rrOrRrSr rrrcreate_memoryviewszBufferWrapper.create_memoryviewN)r r!r"r5rcrrerrrrrs)rGrr sysr#r8contextrrr__all__platformrobjectrr3r1registerr5rrrrr s$    managers.cpython-36.opt-2.pyc000064400000073242147204630710011743 0ustar003 \@sddddgZddlZddlZddlZddlZddlZddlmZddlm Z dd l m Z m Z dd lm Z dd lmZdd lmZdd lmZddZe jejedddDZedek rddZxeD]Ze jeeqWGdddeZfifddZddZGdddeZddZd d!ZGd"d#d#eZGd$d%d%eZ e j!e j"fe j#e j$fd&Z%Gd'ddeZ&Gd(d)d)e'Z(Gd*ddeZ)d+d,Z*ifd-d.Z+dd0d1Z,Gd2d3d3eZ-Gd4d5d5eZ.dd6d7Z/Gd8d9d9e)Z0Gd:d;d;e)Z1Gdd?d?e)Z3Gd@dAdAe)Z4GdBdCdCe)Z5GdDdEdEe)Z6e+dFdZ7GdZd[d[e7Z8e+d\dZ9d]deie9_:e+dfdZ;e+dgdZe>jdwej?e>jdxej?e>jdyej@e3e>jdzejAe1e>jd{ejBe1e>jd|ejCe1e>jd}ejDe1e>jd~ejEe2e>jdejFe4e>jde jGe=e>jdee8e>jdeHe9e>jd5e.e6e>jd7e/e;e>jd3e-e5e>jdee0dde>jdsdddS) BaseManager SyncManager BaseProxyTokenN) format_exc) connection) reductionget_spawning_popen)pool)process)util) get_contextcCstj|j|jffS)N)arraytypecodetobytes)ar0/usr/lib64/python3.6/multiprocessing/managers.py reduce_array$srcCsg|]}tti|qSr)typegetattr).0namerrr (sritemskeysvaluescCstt|ffS)N)list)objrrrrebuild_as_list*sr c@s0eZdZd ZddZddZdd Zd d Zd S)rtypeidaddressidcCs||||_|_|_dS)N)r!r"r#)selfr!r"r#rrr__init__9szToken.__init__cCs|j|j|jfS)N)r!r"r#)r$rrr __getstate__<szToken.__getstate__cCs|\|_|_|_dS)N)r!r"r#)r$staterrr __setstate__?szToken.__setstate__cCsd|jj|j|j|jfS)Nz %s(typeid=%r, address=%r, id=%r)) __class____name__r!r"r#)r$rrr__repr__BszToken.__repr__N)r!r"r#)r* __module__ __qualname__ __slots__r%r&r(r+rrrrr3s cCs8|j||||f|j\}}|dkr*|St||dS)Nz#RETURN)sendrecvconvert_to_error)cr# methodnameargskwdskindresultrrrdispatchJs  r8cCs<|dkr |S|dkrt|S|dkr0td|StdSdS)Nz#ERRORz #TRACEBACKz#UNSERIALIZABLEzUnserializable message: %s zUnrecognized message type) RemoteError ValueError)r6r7rrrr1Ts r1c@seZdZddZdS)r9cCs&ddddt|jdddS)N -Kr)strr4)r$rrr__str__aszRemoteError.__str__N)r*r,r-r?rrrrr9`sr9cCs6g}x,t|D] }t||}t|r|j|qW|S)N)dirrcallableappend)rtemprfuncrrr all_methodshs  rEcCsddt|DS)NcSsg|]}|ddkr|qS)r_r)rrrrrrwsz"public_methods..)rE)rrrrpublic_methodsssrGc @seZdZddddddddd g Zd d Zd d ZddZddZddZddZ ddZ ddZ e e e dZ ddZ ddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+d,Zd-S).Servershutdowncreateaccept_connection get_methods debug_infonumber_of_objectsdummyincrefdecrefcCs^||_tj||_t|\}}||dd|_|jj|_ddffi|_i|_i|_ t j |_ dS)N)r"Zbacklog0) registryr AuthenticationStringauthkeylistener_clientlistenerr" id_to_objid_to_refcountid_to_local_proxy_obj threadingLockmutex)r$rTr"rV serializerListenerClientrrrr%s   zServer.__init__cCstj|_|tj_zZtj|jd}d|_|j y x|jj sN|jj dq6WWnt t fk rjYnXWdtjtjkrtjdtjt_tjt_tjdXdS)N)targetTrzresetting stdout, stderrr)r\Event stop_eventr current_process_manager_serverThreadaccepterdaemonstartis_setwaitKeyboardInterrupt SystemExitsysstdout __stdout__r debug __stderr__stderrexit)r$rhrrr serve_forevers       zServer.serve_foreverc CsPxJy|jj}Wntk r&wYnXtj|j|fd}d|_|jqWdS)N)rbr4T)rXZacceptOSErrorr\rghandle_requestrirj)r$r2trrrrhszServer.accepterc 'Cs4d}}}y>tj||jtj||j|j}|\}}}}t||}Wntk rhdtf} Yn>Xy||f||}Wntk rdtf} Yn Xd|f} y|j| Wnrtk r&} zTy|jdtfWntk rYnXt j d| t j d|t j d| WYdd} ~ XnX|j dS)Nz #TRACEBACKz#RETURNzFailure to send message: %rz ... request was %rz ... exception was %r) rZdeliver_challengerVZanswer_challenger0r Exceptionrr/r infoclose) r$r2funcnamer7requestignorer4r5rDmsgerrrrxs2    zServer.handle_requestcDCstjdtjj|j}|j}|j}x|jj syBd}}|}|\}}} } y||\}} } Wn^t k r} zBy|j |\}} } Wn&t k r}z | WYdd}~XnXWYdd} ~ XnX|| krt d|t || ft||}y|| | }Wn,tk r&}zd|f}WYdd}~XnPX| o8| j|d}|rn|j|||\}}t||j|}d||ff}nd|f}Wnt k r|dkrdtf}nNy,|j|}|||||f| | }d|f}Wn tk rdtf}YnXYnPtk r"tjdtjjtjdYn tk r@dtf}YnXyDy ||Wn2tk r}z|d tfWYdd}~XnXWq(tk r}zBtjd tjjtjd |tjd ||jtjd WYdd}~Xq(Xq(WdS)Nz$starting server thread to service %rz+method %r of %r object is not in exposed=%rz#ERRORz#PROXYz#RETURNz #TRACEBACKz$got EOF -- exiting thread serving %rrz#UNSERIALIZABLEzexception in thread serving %rz ... message was %rz ... exception was %rr)r rrr\current_threadrr0r/rYrdrkKeyErrorr[AttributeErrorrrrzgetrJrr"rfallback_mappingEOFErrorrorur{r|)r$connr0r/rYr3rr~identr4r5exposed gettypeidkeZ second_keZfunctionresrrr!ZridentZrexposedtokenZ fallback_funcr7rrr serve_clientsx  (        $   zServer.serve_clientcCs|S)Nr)r$rrrrrrfallback_getvalue&szServer.fallback_getvaluecCst|S)N)r>)r$rrrrrr fallback_str)szServer.fallback_strcCst|S)N)repr)r$rrrrrr fallback_repr,szServer.fallback_repr)r?r+z #GETVALUEcCsdS)Nr)r$r2rrrrO5sz Server.dummycCs||jlg}t|jj}|jxD|D]<}|dkr(|jd||j|t|j|dddfq(Wdj|SQRXdS)NrSz %s: refcount=%s %srr=r;) r^rrZrsortrBr>rYjoin)r$r2r7rrrrrrM8s  $zServer.debug_infocCs t|jS)N)lenrZ)r$r2rrrrNGszServer.number_of_objectscCsLz:ytjd|jdWnddl}|jYnXWd|jjXdS)Nz!manager received shutdown message#RETURNr)rN)r rrr/ traceback print_excrdset)r$r2rrrrrINs zServer.shutdownc Os|j|j|\}}}}|dkr,|d} n |||} |dkrFt| }|dk r^t|t|}dt| } tjd|| | t||f|j| <| |j krd|j | <WdQRX|j || | t |fS)Nrz%xz&%r callable returned object with id %r) r^rTrGrr#r rrrrYrZrPtuple) r$r2r!r4r5rArmethod_to_typeid proxytyperrrrrrJ[s      z Server.createcCst|j|jdS)Nr)rrYr#)r$r2rrrrrLzszServer.get_methodscCs"|tj_|jd|j|dS)N#RETURN)rN)r\rrr/r)r$r2rrrrrKs  zServer.accept_connectioncCs|jy|j|d7<Wnhtk r}zL||jkrrd|j|<|j||j|<|j|\}}}tjd|n|WYdd}~XnXWdQRXdS)Nrz&Server re-enabled tracking & INCREF %r)r^rZrr[rYr rr)r$r2rrrrrrrrrPs  z Server.increfcCs||jkr$||jkr$tjd|dS|j.|j|d8<|j|dkrT|j|=WdQRX||jkrdfdf|j|<tjd||j|j|=WdQRXdS)NzServer DECREF skipping %rrrzdisposing of obj with id %r)rZr[r rrr^rY)r$r2rrrrrQs     z Server.decrefN)r*r,r-Zpublicr%rvrhrxrrrrrrOrMrNrIrJrLrKrPrQrrrrrH}s, "Q rHc@seZdZdgZdZdZdZdS)StatevaluerrN)r*r,r-r.INITIALSTARTEDSHUTDOWNrrrrrsr)pickleZ xmlrpclibc@seZdZiZeZd ddZddZddZdffd d Z e dffd d Z d dZ d!ddZ ddZddZddZddZeddZeddZe d"ddZdS)#rNrcCs\|dkrtjj}||_tj||_t|_tj|j_ ||_ t |\|_ |_ |pTt|_dS)N)r rerV_addressrU_authkeyr_staterr _serializerrWZ _Listener_Clientr_ctx)r$r"rVr_Zctxrrrr%s   zBaseManager.__init__cCst|j|j|j|jS)N)rH _registryrrr)r$rrr get_servers zBaseManager.get_servercCs8t|j\}}||j|jd}t|ddtj|j_dS)N)rVrO) rWrrrr8rrrr)r$r`rarrrrconnects zBaseManager.connectc Cs|dk rt| rtdtjdd\}}|jjt|j|j|j |j |j |||fd|_ dj dd|j jD}t|jd||j _|j j|j|j|_ |jtj|j_tj|t|j|j |j |j |j|jfd d |_dS) Nzinitializer must be a callableF)Zduplex)rbr4:css|]}t|VqdS)N)r>)rirrr sz$BaseManager.start..r<r)r4 exitpriority)rA TypeErrorrZPiperZProcessr _run_serverrrrr_processrZ _identityr*rrjr|r0rrrrr Finalize_finalize_managerrrI)r$ initializerinitargsreaderwriterrrrrrjs&       zBaseManager.startc CsN|dk r|||j||||}|j|j|jtjd|j|jdS)Nzmanager serving at %r)_Serverr/r"r|r r{rv) clsrTr"rVr_rrrserverrrrrs zBaseManager._run_serverc OsN|j|j|jd}zt|dd|f||\}}Wd|jXt||j||fS)N)rVrJ)rrrr8r|r)r$r!r4r5rr#rrrr_create%s  zBaseManager._createcCs*|jdk r&|jj||jjs&d|_dS)N)rris_alive)r$timeoutrrrr1s   zBaseManager.joinc Cs.|j|j|jd}z t|ddS|jXdS)N)rVrM)rrrr8r|)r$rrrr _debug_info:s zBaseManager._debug_infoc Cs.|j|j|jd}z t|ddS|jXdS)N)rVrN)rrrr8r|)r$rrrr_number_of_objectsDs zBaseManager._number_of_objectscCs|jjtjkr|j|S)N)rrrrrj)r$rrr __enter__NszBaseManager.__enter__cCs |jdS)N)rI)r$exc_typeexc_valexc_tbrrr__exit__TszBaseManager.__exit__cCs|jrtjdy,|||d}zt|ddWd|jXWntk rRYnX|jdd|jrtjdt|drtjd|j|jd d|jrtjd t j |_ y t j |=Wntk rYnXdS) Nz#sending shutdown message to manager)rVrIg?)rzmanager still alive terminatez'trying to `terminate()` manager processg?z#manager still alive after terminate)rr r{r8r|rzrhasattrrrrrr_address_to_localr)r r"rVr'rrrrrrWs.         zBaseManager._finalize_managercCs|jS)N)r)r$rrrwszBaseManager.Tc sd|jkr|jj|_dkr"t|p0tdd}|p@tdd}|r`xt|jD]\}}qTW|||f|j<|rfdd} | _t|| dS)Nr _exposed__method_to_typeid_cs`tjd|jf||\}}||j||j|d}|j|j|jd}t|dd|jf|S)Nz)requesting creation of a shared %r object)managerrVr)rVrQ) r rrrrrrr"r8r#)r$r4r5rZexpproxyr)rr!rrrCs  z"BaseManager.register..temp) __dict__rcopy AutoProxyrrrr*setattr) rr!rArrr create_methodkeyrrCr)rr!rregisterys    zBaseManager.register)NNrN)N)NNNNT)r*r,r-rrHrr%rrrj classmethodrrrrrrr staticmethodrpropertyr"rrrrrrs(  $    c@seZdZddZddZdS)ProcessLocalSetcCstj|dddS)NcSs|jS)N)clear)rrrrrsz*ProcessLocalSet.__init__..)r register_after_fork)r$rrrr%szProcessLocalSet.__init__cCs t|ffS)N)r)r$rrr __reduce__szProcessLocalSet.__reduce__N)r*r,r-r%rrrrrrsrc@s|eZdZiZejZdddZddZfifdd Z d d Z d d Z e ddZ ddZddZddZddZddZdS)rNTFc Cstj8tjj|jd}|dkr:tjtf}|tj|j<WdQRX|d|_|d|_ ||_ |j j |_ ||_ ||_t|d|_||_|dk rtj||_n"|j dk r|j j|_n tjj|_|r|jtj|tjdS)Nrr)r_mutexrrr"r ZForkAwareLocalr_tls_idset_tokenr#_id_managerrrWr_owned_by_managerr rUrrerV_increfr _after_fork) r$rr_rrVrrP manager_ownedZ tls_idsetrrrr%s*      zBaseProxy.__init__cCsdtjdtjj}tjjdkr4|dtjj7}|j|jj |j d}t |dd|f||j _ dS)Nzmaking connection to managerZ MainThread|)rVrK)r rrr rerr\rrrr"rr8rr)r$rrrrr_connects  zBaseProxy._connectc Csy |jj}Wn6tk rBtjdtjj|j|jj}YnX|j |j |||f|j \}}|dkrp|S|dkr|\}}|j j |jd} |jj|_| ||j|j |j|d} |j|j|jd}t|dd|jf| St||dS) Nz#thread %r does not own a connectionz#RETURNz#PROXYr)rrVr)rVrQ)rrrr rrr\rrrr/rr0rrr!rr"rrrr8r#r1) r$r3r4r5rr6r7rrrrrrr _callmethods,      zBaseProxy._callmethodcCs |jdS)Nz #GETVALUE)r)r$rrr _getvalueszBaseProxy._getvaluec Cs|jrtjd|jjdS|j|jj|jd}t|dd|j ftjd|jj|j j |j |j oj|j j }tj|tj|j|j||j|j |jfdd|_dS)Nz%owned_by_manager skipped INCREF of %r)rVrPz INCREF %r )r4r)rr rrrr#rr"rr8rraddrrrr_decrefrZ_close)r$rr'rrrr s zBaseProxy._increfcCs|j|j|dks |jtjkry2tjd|j||j|d}t|dd|jfWqt k r}ztjd|WYdd}~XqXntjd|j| rt |drtjdt j j |jj|`dS)Nz DECREF %r)rVrQz... decref failed %sz%DECREF %r -- manager already shutdownrz-thread %r has no more proxies so closing conn)discardr#rrrr rrr"r8rzrr\rrrr|)rrVr'ZtlsZidsetrrrrrrr s    zBaseProxy._decrefcCsHd|_y |jWn0tk rB}ztjd|WYdd}~XnXdS)Nzincref failed: %s)rrrzr r{)r$rrrrr9s  zBaseProxy._after_forkcCs^i}tdk r|j|d<t|ddrB|j|d<tt|j|j|ffStt||j|j|ffSdS)NrV_isautoFr) r rrr RebuildProxyrrrr)r$r5rrrrAs    zBaseProxy.__reduce__cCs|jS)N)r)r$memorrr __deepcopy__NszBaseProxy.__deepcopy__cCsdt|j|jjt|fS)Nz<%s object, typeid %r at %#x>)rr*rr!r#)r$rrrr+QszBaseProxy.__repr__c Cs4y |jdStk r.t|dddSXdS)Nr+rz; '__str__()' failed>r)rrzr)r$rrrr?Us zBaseProxy.__str__)NNNTF)r*r,r-rr ZForkAwareThreadLockrr%rrrrrrrrrr+r?rrrrrs (   cCsttjdd}|rT|j|jkrTtjd|d|d<|j|jkrT|j|j|j|j<|j ddopttjdd }|||fd|i|S)Nrfz*Rebuild a proxy owned by manager, token=%rTrrPZ _inheritingF) rr rer"r rrr#r[rYpop)rDrr_r5rrPrrrrbs   rc Csrt|}y |||fStk r(YnXi}x|D]}td||f|q4Wt|tf|}||_||||f<|S)NzLdef %s(self, *args, **kwds): return self._callmethod(%r, args, kwds))rrexecrrr)rr_cacheZdicmeth ProxyTyperrr MakeProxyTypews   rTc Cst|d}|dkrB||j|d}zt|dd|f}Wd|jX|dkrX|dk rX|j}|dkrjtjj}td|j |}||||||d} d| _ | S)Nr)rVrLz AutoProxy[%s])rrVrPT) rWr"r8r|rr rerVrr!r) rr_rrVrrPrrrrrrrrs    rc@seZdZddZddZdS) NamespacecKs|jj|dS)N)rupdate)r$r5rrrr%szNamespace.__init__cCs^t|jj}g}x,|D]$\}}|jds|jd||fqW|jd|jjdj|fS)NrFz%s=%rz%s(%s)z, ) rrr startswithrBrr)r*r)r$rrCrrrrrr+s zNamespace.__repr__N)r*r,r-r%r+rrrrrsrc@s8eZdZd ddZddZddZdd ZeeeZd S) ValueTcCs||_||_dS)N) _typecode_value)r$rrlockrrrr%szValue.__init__cCs|jS)N)r)r$rrrrsz Value.getcCs ||_dS)N)r)r$rrrrrsz Value.setcCsdt|j|j|jfS)Nz %s(%r, %r))rr*rr)r$rrrr+szValue.__repr__N)T) r*r,r-r%rrr+rrrrrrrs  rcCs tj||S)N)r)rZsequencerrrrArraysrc@s8eZdZdZddZddZd d Zd d Zd dZdS) IteratorProxy__next__r/throwr|cCs|S)Nr)r$rrr__iter__szIteratorProxy.__iter__cGs |jd|S)Nr)r)r$r4rrrrszIteratorProxy.__next__cGs |jd|S)Nr/)r)r$r4rrrr/szIteratorProxy.sendcGs |jd|S)Nr)r)r$r4rrrrszIteratorProxy.throwcGs |jd|S)Nr|)r)r$r4rrrr|szIteratorProxy.closeN)rr/rr|) r*r,r-rrrr/rr|rrrrrs rc@s2eZdZd ZdddZddZd d Zd d ZdS) AcquirerProxyacquirereleaseTNcCs"|dkr|fn||f}|jd|S)Nr )r)r$Zblockingrr4rrrr szAcquirerProxy.acquirecCs |jdS)Nr )r)r$rrrr szAcquirerProxy.releasecCs |jdS)Nr )r)r$rrrrszAcquirerProxy.__enter__cCs |jdS)Nr )r)r$rrrrrrrszAcquirerProxy.__exit__)r r )TN)r*r,r-rr r rrrrrrrs  rc@s4eZdZdZdddZd d Zd d Zdd dZdS)ConditionProxyr r rlnotify notify_allNcCs|jd|fS)Nrl)r)r$rrrrrlszConditionProxy.waitcCs |jdS)Nr )r)r$rrrr szConditionProxy.notifycCs |jdS)Nr )r)r$rrrr szConditionProxy.notify_allcCsh|}|r|S|dk r$tj|}nd}d}x6|sb|dk rP|tj}|dkrPP|j||}q.W|S)Nr)timeZ monotonicrl)r$Z predicaterr7ZendtimeZwaittimerrrwait_fors   zConditionProxy.wait_for)r r rlr r )N)N)r*r,r-rrlr r rrrrrr s  r c@s2eZdZdZddZddZd d Zdd d Zd S) EventProxyrkrrrlcCs |jdS)Nrk)r)r$rrrrkszEventProxy.is_setcCs |jdS)Nr)r)r$rrrrszEventProxy.setcCs |jdS)Nr)r)r$rrrrszEventProxy.clearNcCs|jd|fS)Nrl)r)r$rrrrrlszEventProxy.wait)rkrrrl)N)r*r,r-rrkrrrlrrrrrs rc@sNeZdZdZdddZdd Zd d Zed d ZeddZ eddZ dS) BarrierProxy__getattribute__rlabortresetNcCs|jd|fS)Nrl)r)r$rrrrrl szBarrierProxy.waitcCs |jdS)Nr)r)r$rrrrszBarrierProxy.abortcCs |jdS)Nr)r)r$rrrrszBarrierProxy.resetcCs |jddS)Nrparties)r)r)r$rrrrszBarrierProxy.partiescCs |jddS)Nr n_waiting)r)r)r$rrrrszBarrierProxy.n_waitingcCs |jddS)Nrbroken)r)r)r$rrrrszBarrierProxy.broken)rrlrr)N) r*r,r-rrlrrrrrrrrrrr s   rc@s(eZdZd ZddZddZdd Zd S) NamespaceProxyr __setattr__ __delattr__cCs0|ddkrtj||Stj|d}|d|fS)NrrFrr)objectr)r$r callmethodrrr __getattr__ s   zNamespaceProxy.__getattr__cCs4|ddkrtj|||Stj|d}|d||fS)NrrFrr)rrr)r$rrrrrrr%s  zNamespaceProxy.__setattr__cCs0|ddkrtj||Stj|d}|d|fS)NrrFrr)rrr)r$rrrrrr*s   zNamespaceProxy.__delattr__N)rrr)r*r,r-rrrrrrrrrsrc@s*eZdZdZddZddZeeeZdS) ValueProxyrrcCs |jdS)Nr)r)r$rrrr3szValueProxy.getcCs|jd|fS)Nr)r)r$rrrrr5szValueProxy.setN)rr)r*r,r-rrrrrrrrrr1sr BaseListProxy__add__ __contains__ __delitem__ __getitem____len____mul__ __reversed____rmul__ __setitem__rBcountextendindexinsertrremovereverser__imul__c@seZdZddZddZdS) ListProxycCs|jd|f|S)Nr*)r)r$rrrr__iadd__AszListProxy.__iadd__cCs|jd|f|S)Nr/)r)r$rrrrr/DszListProxy.__imul__N)r*r,r-r1r/rrrrr0@sr0 DictProxyrrrrhas_keypopitem setdefaultrIterator ArrayProxy PoolProxyapply apply_asyncr|imapimap_unorderedrmap map_asyncstarmap starmap_asyncrZ AsyncResult)r:r>r@r;r<c@seZdZddZddZdS)r8cCs|S)Nr)r$rrrrdszPoolProxy.__enter__cCs |jdS)N)r)r$rrrrrrrfszPoolProxy.__exit__N)r*r,r-rrrrrrr8csc@s eZdZdS)rN)r*r,r-rrrrrms QueueZ JoinableQueuercr]RLock SemaphoreBoundedSemaphore ConditionBarrierPoolrdictF)rr)r)rrr)NNNT)T)r r!r"r#r$r%r&r'r(rBr)r*r+r,rr-r.rr/)r!r"r#rr$r(rrrr3rrrr4r5rr)r$r#r() r9r:r|r;r<rr=r>r?r@r)I__all__ror\rZqueuerrrrcontextr r r r r rrrZ view_typesrr Z view_typerrr8r1rzr9rErGrHrr`raZ XmlListenerZ XmlClientrWrrrrrrrrrrrrr rrrrrr0r2rr7Z BasePoolProxyr8rrArcr]rBrCrDrErFrGrHrrrr s             ; ] 4             managers.cpython-36.pyc000064400000101052147204630710010772 0ustar003 \@sddddgZddlZddlZddlZddlZddlZddlmZddlm Z dd l m Z m Z dd lm Z dd lmZdd lmZdd lmZddZe jejedddDZedek rddZxeD]Ze jeeqWGdddeZfifddZddZGdddeZddZd d!ZGd"d#d#eZGd$d%d%eZ e j!e j"fe j#e j$fd&Z%Gd'ddeZ&Gd(d)d)e'Z(Gd*ddeZ)d+d,Z*ifd-d.Z+dd0d1Z,Gd2d3d3eZ-Gd4d5d5eZ.dd6d7Z/Gd8d9d9e)Z0Gd:d;d;e)Z1Gdd?d?e)Z3Gd@dAdAe)Z4GdBdCdCe)Z5GdDdEdEe)Z6e+dFdZ7GdZd[d[e7Z8e+d\dZ9d]deie9_:e+dfdZ;e+dgdZe>jdwej?e>jdxej?e>jdyej@e3e>jdzejAe1e>jd{ejBe1e>jd|ejCe1e>jd}ejDe1e>jd~ejEe2e>jdejFe4e>jde jGe=e>jdee8e>jdeHe9e>jd5e.e6e>jd7e/e;e>jd3e-e5e>jdee0dde>jdsdddS) BaseManager SyncManager BaseProxyTokenN) format_exc) connection) reductionget_spawning_popen)pool)process)util) get_contextcCstj|j|jffS)N)arraytypecodetobytes)ar0/usr/lib64/python3.6/multiprocessing/managers.py reduce_array$srcCsg|]}tti|qSr)typegetattr).0namerrr (sritemskeysvaluescCstt|ffS)N)list)objrrrrebuild_as_list*sr c@s4eZdZdZdZddZddZd d Zd d Zd S)rz4 Type to uniquely indentify a shared object typeidaddressidcCs||||_|_|_dS)N)r!r"r#)selfr!r"r#rrr__init__9szToken.__init__cCs|j|j|jfS)N)r!r"r#)r$rrr __getstate__<szToken.__getstate__cCs|\|_|_|_dS)N)r!r"r#)r$staterrr __setstate__?szToken.__setstate__cCsd|jj|j|j|jfS)Nz %s(typeid=%r, address=%r, id=%r)) __class____name__r!r"r#)r$rrr__repr__BszToken.__repr__N)r!r"r#) r* __module__ __qualname____doc__ __slots__r%r&r(r+rrrrr3s cCs8|j||||f|j\}}|dkr*|St||dS)zL Send a message to manager using connection `c` and return response z#RETURNN)sendrecvconvert_to_error)cr# methodnameargskwdskindresultrrrdispatchJs  r9cCs\|dkr |S|dkr,t|tks$tt|S|dkrPt|tksDttd|StdSdS)Nz#ERRORz #TRACEBACKz#UNSERIALIZABLEzUnserializable message: %s zUnrecognized message type)rstrAssertionError RemoteError ValueError)r7r8rrrr2Ts r2c@seZdZddZdS)r<cCs&ddddt|jdddS)N -Kr)r:r5)r$rrr__str__aszRemoteError.__str__N)r*r,r-rArrrrr<`sr<cCs6g}x,t|D] }t||}t|r|j|qW|S)z4 Return a list of names of methods of `obj` )dirrcallableappend)rtemprfuncrrr all_methodshs  rGcCsddt|DS)zP Return a list of names of methods of `obj` which do not start with '_' cSsg|]}|ddkr|qS)r_r)rrrrrrwsz"public_methods..)rG)rrrrpublic_methodsssrIc @seZdZdZdddddddd d g Zd d Zd dZddZddZddZ ddZ ddZ ddZ e e e dZ ddZddZd d!Zd"d#Zd$d%Zd&d'Zd(d)Zd*d+Zd,d-Zd.S)/ServerzM Server class which runs in a process controlled by a manager object shutdowncreateaccept_connection get_methods debug_infonumber_of_objectsdummyincrefdecrefcCslt|tst||_tj||_t|\}}||dd|_|jj |_ ddffi|_ i|_ i|_ t j|_dS)N)r"Zbacklog0) isinstancebytesr;registryr AuthenticationStringauthkeylistener_clientlistenerr" id_to_objid_to_refcountid_to_local_proxy_obj threadingLockmutex)r$rXr"rZ serializerListenerClientrrrr%s   zServer.__init__cCstj|_|tj_zZtj|jd}d|_|j y x|jj sN|jj dq6WWnt t fk rjYnXWdtjtjkrtjdtjt_tjt_tjdXdS)z( Run the server forever )targetTrNzresetting stdout, stderrr)r`Event stop_eventr current_process_manager_serverThreadaccepterdaemonstartis_setwaitKeyboardInterrupt SystemExitsysstdout __stdout__r debug __stderr__stderrexit)r$rlrrr serve_forevers       zServer.serve_foreverc CsPxJy|jj}Wntk r&wYnXtj|j|fd}d|_|jqWdS)N)rfr5T)r\ZacceptOSErrorr`rkhandle_requestrmrn)r$r3trrrrlszServer.accepterc 'CsLd}}}yTtj||jtj||j|j}|\}}}}||jksTtd|t||}Wntk r~dt f} Yn>Xy||f||}Wntk rdt f} Yn Xd|f} y|j | Wnttk r>} zVy|j dt fWntk rYnXt j d| t j d|t j d| WYdd} ~ XnX|j dS)z) Handle a new connection Nz%r unrecognizedz #TRACEBACKz#RETURNzFailure to send message: %rz ... request was %rz ... exception was %r)rZdeliver_challengerZZanswer_challenger1publicr;r Exceptionrr0r infoclose) r$r3funcnamer8requestignorer5r6rFmsgerrrr|s4    zServer.handle_requestcDCstjdtjj|j}|j}|j}x|jj syBd}}|}|\}}} } y||\}} } Wn^t k r} zBy|j |\}} } Wn&t k r}z | WYdd}~XnXWYdd} ~ XnX|| krt d|t || ft||}y|| | }Wn,tk r&}zd|f}WYdd}~XnPX| o8| j|d}|rn|j|||\}}t||j|}d||ff}nd|f}Wnt k r|dkrdtf}nNy,|j|}|||||f| | }d|f}Wn tk rdtf}YnXYnPtk r"tjdtjjtjd Yn tk r@dtf}YnXyDy ||Wn2tk r}z|d tfWYdd}~XnXWq(tk r}zBtjd tjjtjd |tjd ||jtjdWYdd}~Xq(Xq(WdS)zQ Handle requests from the proxies in a particular process/thread z$starting server thread to service %rNz+method %r of %r object is not in exposed=%rz#ERRORz#PROXYz#RETURNz #TRACEBACKz$got EOF -- exiting thread serving %rrz#UNSERIALIZABLEzexception in thread serving %rz ... message was %rz ... exception was %rr)r rvr`current_threadrr1r0r]rhroKeyErrorr_AttributeErrorrrrgetrLrr"rfallback_mappingEOFErrorrsryrr)r$connr1r0r]r4rridentr5r6exposed gettypeidkeZ second_keZfunctionresrrr!ZridentZrexposedtokenZ fallback_funcr8rrr serve_clientsx  (        $   zServer.serve_clientcCs|S)Nr)r$rrrrrrfallback_getvalue&szServer.fallback_getvaluecCst|S)N)r:)r$rrrrrr fallback_str)szServer.fallback_strcCst|S)N)repr)r$rrrrrr fallback_repr,szServer.fallback_repr)rAr+z #GETVALUEcCsdS)Nr)r$r3rrrrQ5sz Server.dummycCs||jlg}t|jj}|jxD|D]<}|dkr(|jd||j|t|j|dddfq(Wdj|SQRXdS)zO Return some info --- useful to spot problems with refcounting rUz %s: refcount=%s %srNr@r>) rbrr^rsortrDr:r]join)r$r3r8rrrrrrO8s  $zServer.debug_infocCs t|jS)z* Number of shared objects )lenr^)r$r3rrrrPGszServer.number_of_objectscCsLz:ytjd|jdWnddl}|jYnXWd|jjXdS)z' Shutdown this process z!manager received shutdown message#RETURNNr)rN)r rvr0 traceback print_excrhset)r$r3rrrrrKNs zServer.shutdownc Os|j|j|\}}}}|dkrBt|dkr4| s8t|d} n |||} |dkr\t| }|dk rt|tksttt|t|}dt| } t j d|| | t ||f|j | <| |j krd|j | <WdQRX|j|| | t|fS)z> Create a new shared object and return its id Nrrz%xz&%r callable returned object with id %r)rbrXrr;rIrdictrr#r rvrr]r^rRtuple) r$r3r!r5r6rCrmethod_to_typeid proxytyperrrrrrL[s$     z Server.createcCst|j|jdS)zL Return the methods of the shared object indicated by token r)rr]r#)r$r3rrrrrNzszServer.get_methodscCs"|tj_|jd|j|dS)z= Spawn a new thread to serve this connection #RETURNN)rN)r`rrr0r)r$r3rrrrrMs  zServer.accept_connectioncCs|jy|j|d7<Wnhtk r}zL||jkrrd|j|<|j||j|<|j|\}}}tjd|n|WYdd}~XnXWdQRXdS)Nrz&Server re-enabled tracking & INCREF %r)rbr^rr_r]r rv)r$r3rrrrrrrrrRs  z Server.increfcCs||jkr$||jkr$tjd|dS|j@|j|dks>t|j|d8<|j|dkrf|j|=WdQRX||jkrdfdf|j|<tjd||j|j|=WdQRXdS)NzServer DECREF skipping %rrrzdisposing of obj with id %r)r^r_r rvrbr;r])r$r3rrrrrSs     z Server.decrefN)r*r,r-r.r~r%rzrlr|rrrrrrQrOrPrKrLrNrMrRrSrrrrrJ}s. "Q rJc@seZdZdgZdZdZdZdS)StatevaluerrN)r*r,r-r/INITIALSTARTEDSHUTDOWNrrrrrsr)pickleZ xmlrpclibc@seZdZdZiZeZd!ddZddZdd Z dffd d Z e dffd d Z ddZ d"ddZddZddZddZddZeddZeddZe d#dd ZdS)$rz! Base class for managers NrcCs\|dkrtjj}||_tj||_t|_tj|j_ ||_ t |\|_ |_ |pTt|_dS)N)r rirZ_addressrY_authkeyr_staterr _serializerr[Z _Listener_Clientr_ctx)r$r"rZrcZctxrrrr%s   zBaseManager.__init__cCs(|jjtjkstt|j|j|j|j S)zX Return server object with serve_forever() method and address attribute ) rrrrr;rJ _registryrrr)r$rrr get_servers zBaseManager.get_servercCs8t|j\}}||j|jd}t|ddtj|j_dS)z> Connect manager object to the server process )rZNrQ) r[rrrr9rrrr)r$rdrerrrrconnects zBaseManager.connectc Cs|jjtjkst|dk r,t| r,tdtjdd\}}|j j t |j |j |j|j|j|||fd|_djdd|jjD}t |jd ||j_|jj|j|j|_|jtj|j_tj|t |j|j|j|j|j|jfd d |_dS) z@ Spawn a server process for this manager object Nzinitializer must be a callableF)Zduplex)rfr5:css|]}t|VqdS)N)r:)rirrr sz$BaseManager.start..r?r)r5 exitpriority)rrrrr;rC TypeErrorrZPiperZProcessr _run_serverrrrr_processrZ _identityr*rrnrr1rr Finalize_finalize_managerrrK)r$ initializerinitargsreaderwriterrrrrrns(       zBaseManager.startc CsN|dk r|||j||||}|j|j|jtjd|j|jdS)z@ Create a server, report its address and run it Nzmanager serving at %r)_Serverr0r"rr rrz) clsrXr"rZrcrrrserverrrrrs zBaseManager._run_serverc Osd|jjtjkstd|j|j|jd}zt|dd|f||\}}Wd|j Xt ||j||fS)zP Create a new shared object; return the token and exposed tuple zserver not yet started)rZNrL) rrrrr;rrrr9rr)r$r!r5r6rr#rrrr_create%s  zBaseManager._createcCs*|jdk r&|jj||jjs&d|_dS)zC Join the manager process (if it has been spawned) N)rris_alive)r$timeoutrrrr1s   zBaseManager.joinc Cs.|j|j|jd}z t|ddS|jXdS)zS Return some info about the servers shared objects and connections )rZNrO)rrrr9r)r$rrrr _debug_info:s zBaseManager._debug_infoc Cs.|j|j|jd}z t|ddS|jXdS)z5 Return the number of shared objects )rZNrP)rrrr9r)r$rrrr_number_of_objectsDs zBaseManager._number_of_objectscCs,|jjtjkr|j|jjtjks(t|S)N)rrrrrnrr;)r$rrr __enter__NszBaseManager.__enter__cCs |jdS)N)rK)r$exc_typeexc_valexc_tbrrr__exit__TszBaseManager.__exit__cCs|jrtjdy,|||d}zt|ddWd|jXWntk rRYnX|jdd|jrtjdt|drtjd |j|jd d|jrtjd t j |_ y t j |=Wntk rYnXdS) zQ Shutdown the manager process; will be registered as a finalizer z#sending shutdown message to manager)rZNrKg?)rzmanager still alive terminatez'trying to `terminate()` manager processg?z#manager still alive after terminate)rr rr9rrrhasattrrrrrr_address_to_localr)r r"rZr'rrrrrrWs.         zBaseManager._finalize_managercCs|jS)N)r)r$rrrwszBaseManager.Tc sd|jkr|jj|_dkr"t|p0tdd}|p@tdd}|rxHt|jD]8\}}t|tkstt d|t|tksTt d|qTW|||f|j<|rƇfdd} | _ t || dS)z9 Register a typeid with the manager type rN _exposed__method_to_typeid_z%r is not a stringcs`tjd|jf||\}}||j||j|d}|j|j|jd}t|dd|jf|S)Nz)requesting creation of a shared %r object)managerrZr)rZrS) r rvrrrrr"r9r#)r$r5r6rZexpproxyr)rr!rrrEs  z"BaseManager.register..temp) __dict__rcopy AutoProxyrrrrr:r;r*setattr) rr!rCrrr create_methodkeyrrEr)rr!rregisterys     zBaseManager.register)NNrN)N)NNNNT)r*r,r-r.rrJrr%rrrn classmethodrrrrrrr staticmethodrpropertyr"rrrrrrs*  $    c@seZdZddZddZdS)ProcessLocalSetcCstj|dddS)NcSs|jS)N)clear)rrrrrsz*ProcessLocalSet.__init__..)r register_after_fork)r$rrrr%szProcessLocalSet.__init__cCs t|ffS)N)r)r$rrr __reduce__szProcessLocalSet.__reduce__N)r*r,r-r%rrrrrrsrc@seZdZdZiZejZdddZddZ fifd d Z d d Z d dZ e ddZddZddZddZddZddZdS)rz. A base for proxies of shared objects NTFc Cstj8tjj|jd}|dkr:tjtf}|tj|j<WdQRX|d|_|d|_ ||_ |j j |_ ||_ ||_t|d|_||_|dk rtj||_n"|j dk r|j j|_n tjj|_|r|jtj|tjdS)Nrr)r_mutexrrr"r ZForkAwareLocalr_tls_idset_tokenr#_id_managerrr[r_owned_by_managerr rYrrirZ_increfr _after_fork) r$rrcrrZrrR manager_ownedZ tls_idsetrrrr%s*      zBaseProxy.__init__cCsdtjdtjj}tjjdkr4|dtjj7}|j|jj |j d}t |dd|f||j _ dS)Nzmaking connection to managerZ MainThread|)rZrM)r rvr rirr`rrrr"rr9rr)r$rrrrr_connects  zBaseProxy._connectc Csy |jj}Wn6tk rBtjdtjj|j|jj}YnX|j |j |||f|j \}}|dkrp|S|dkr|\}}|j j |jd } |jj|_| ||j|j |j|d} |j|j|jd}t|dd|jf| St||dS) zW Try to call a method of the referrent and return a copy of the result z#thread %r does not own a connectionz#RETURNz#PROXYr)rrZr)rZNrS)rrrr rvr`rrrr0rr1rrr!rr"rrrr9r#r2) r$r4r5r6rr7r8rrrrrrr _callmethods,      zBaseProxy._callmethodcCs |jdS)z9 Get a copy of the value of the referent z #GETVALUE)r)r$rrr _getvalueszBaseProxy._getvaluec Cs|jrtjd|jjdS|j|jj|jd}t|dd|j ftjd|jj|j j |j |j oj|j j }tj|tj|j|j||j|j |jfdd|_dS)Nz%owned_by_manager skipped INCREF of %r)rZrRz INCREF %r )r5r)rr rvrr#rr"rr9rraddrrrr_decrefrZ_close)r$rr'rrrr s zBaseProxy._increfcCs|j|j|dks |jtjkry2tjd|j||j|d}t|dd|jfWqt k r}ztjd|WYdd}~XqXntjd|j| rt |drtjdt j j |jj|`dS)Nz DECREF %r)rZrSz... decref failed %sz%DECREF %r -- manager already shutdownrz-thread %r has no more proxies so closing conn)discardr#rrrr rvr"r9rrr`rrrr)rrZr'ZtlsZidsetrrrrrrr s    zBaseProxy._decrefcCsHd|_y |jWn0tk rB}ztjd|WYdd}~XnXdS)Nzincref failed: %s)rrrr r)r$rrrrr9s  zBaseProxy._after_forkcCs^i}tdk r|j|d<t|ddrB|j|d<tt|j|j|ffStt||j|j|ffSdS)NrZ_isautoFr) r rrr RebuildProxyrrrr)r$r6rrrrAs    zBaseProxy.__reduce__cCs|jS)N)r)r$memorrr __deepcopy__NszBaseProxy.__deepcopy__cCsdt|j|jjt|fS)Nz<%s object, typeid %r at %#x>)rr*rr!r#)r$rrrr+QszBaseProxy.__repr__c Cs4y |jdStk r.t|dddSXdS)zV Return representation of the referent (or a fall-back if that fails) r+Nrz; '__str__()' failed>r)rrr)r$rrrrAUs zBaseProxy.__str__)NNNTF)r*r,r-r.rr ZForkAwareThreadLockrr%rrrrrrrrrr+rArrrrrs (   cCsttjdd}|rT|j|jkrTtjd|d|d<|j|jkrT|j|j|j|j<|j ddopttjdd }|||fd|i|S) z5 Function used for unpickling proxy objects. rjNz*Rebuild a proxy owned by manager, token=%rTrrRZ _inheritingF) rr rir"r rvr#r_r]pop)rFrrcr6rrRrrrrbs   rc Csrt|}y |||fStk r(YnXi}x|D]}td||f|q4Wt|tf|}||_||||f<|S)zB Return a proxy type whose methods are given by `exposed` zLdef %s(self, *args, **kwds): return self._callmethod(%r, args, kwds))rrexecrrr)rr_cacheZdicmeth ProxyTyperrr MakeProxyTypews   rTc Cst|d}|dkrB||j|d}zt|dd|f}Wd|jX|dkrX|dk rX|j}|dkrjtjj}td|j |}||||||d} d| _ | S)z* Return an auto-proxy for `token` rN)rZrNz AutoProxy[%s])rrZrRT) r[r"r9rrr rirZrr!r) rrcrrZrrRrrrrrrrrs    rc@seZdZddZddZdS) NamespacecKs|jj|dS)N)rupdate)r$r6rrrr%szNamespace.__init__cCs^t|jj}g}x,|D]$\}}|jds|jd||fqW|jd|jjdj|fS)NrHz%s=%rz%s(%s)z, ) rrr startswithrDrr)r*r)r$rrErrrrrr+s zNamespace.__repr__N)r*r,r-r%r+rrrrrsrc@s8eZdZd ddZddZddZdd ZeeeZd S) ValueTcCs||_||_dS)N) _typecode_value)r$rrlockrrrr%szValue.__init__cCs|jS)N)r)r$rrrrsz Value.getcCs ||_dS)N)r)r$rrrrrsz Value.setcCsdt|j|j|jfS)Nz %s(%r, %r))rr*rr)r$rrrr+szValue.__repr__N)T) r*r,r-r%rrr+rrrrrrrs  rcCs tj||S)N)r)rZsequencerrrrArraysr c@s8eZdZdZddZddZd d Zd d Zd dZdS) IteratorProxy__next__r0throwrcCs|S)Nr)r$rrr__iter__szIteratorProxy.__iter__cGs |jd|S)Nr )r)r$r5rrrr szIteratorProxy.__next__cGs |jd|S)Nr0)r)r$r5rrrr0szIteratorProxy.sendcGs |jd|S)Nr )r)r$r5rrrr szIteratorProxy.throwcGs |jd|S)Nr)r)r$r5rrrrszIteratorProxy.closeN)r r0r r) r*r,r-rr r r0r rrrrrr s r c@s2eZdZd ZdddZddZd d Zd d ZdS) AcquirerProxyacquirereleaseTNcCs"|dkr|fn||f}|jd|S)Nr)r)r$Zblockingrr5rrrrszAcquirerProxy.acquirecCs |jdS)Nr)r)r$rrrrszAcquirerProxy.releasecCs |jdS)Nr)r)r$rrrrszAcquirerProxy.__enter__cCs |jdS)Nr)r)r$rrrrrrrszAcquirerProxy.__exit__)rr)TN)r*r,r-rrrrrrrrrrs  rc@s4eZdZdZdddZd d Zd d Zdd dZdS)ConditionProxyrrrpnotify notify_allNcCs|jd|fS)Nrp)r)r$rrrrrpszConditionProxy.waitcCs |jdS)Nr)r)r$rrrrszConditionProxy.notifycCs |jdS)Nr)r)r$rrrrszConditionProxy.notify_allcCsh|}|r|S|dk r$tj|}nd}d}x6|sb|dk rP|tj}|dkrPP|j||}q.W|S)Nr)timeZ monotonicrp)r$Z predicaterr8ZendtimeZwaittimerrrwait_fors   zConditionProxy.wait_for)rrrprr)N)N)r*r,r-rrprrrrrrrrs  rc@s2eZdZdZddZddZd d Zdd d Zd S) EventProxyrorrrpcCs |jdS)Nro)r)r$rrrroszEventProxy.is_setcCs |jdS)Nr)r)r$rrrrszEventProxy.setcCs |jdS)Nr)r)r$rrrrszEventProxy.clearNcCs|jd|fS)Nrp)r)r$rrrrrpszEventProxy.wait)rorrrp)N)r*r,r-rrorrrprrrrrs rc@sNeZdZdZdddZdd Zd d Zed d ZeddZ eddZ dS) BarrierProxy__getattribute__rpabortresetNcCs|jd|fS)Nrp)r)r$rrrrrp szBarrierProxy.waitcCs |jdS)Nr)r)r$rrrrszBarrierProxy.abortcCs |jdS)Nr)r)r$rrrrszBarrierProxy.resetcCs |jddS)Nrparties)r)r)r$rrrrszBarrierProxy.partiescCs |jddS)Nr n_waiting)r)r)r$rrrrszBarrierProxy.n_waitingcCs |jddS)Nrbroken)r)r)r$rrrrszBarrierProxy.broken)rrprr)N) r*r,r-rrprrrrrrrrrrr s   rc@s(eZdZd ZddZddZdd Zd S) NamespaceProxyr __setattr__ __delattr__cCs0|ddkrtj||Stj|d}|d|fS)NrrHrr)objectr)r$r callmethodrrr __getattr__ s   zNamespaceProxy.__getattr__cCs4|ddkrtj|||Stj|d}|d||fS)NrrHrr)r!rr)r$rrr"rrrr%s  zNamespaceProxy.__setattr__cCs0|ddkrtj||Stj|d}|d|fS)NrrHrr )r!r r)r$rr"rrrr *s   zNamespaceProxy.__delattr__N)rrr )r*r,r-rr#rr rrrrrsrc@s*eZdZdZddZddZeeeZdS) ValueProxyrrcCs |jdS)Nr)r)r$rrrr3szValueProxy.getcCs|jd|fS)Nr)r)r$rrrrr5szValueProxy.setN)rr)r*r,r-rrrrrrrrrr$1sr$ BaseListProxy__add__ __contains__ __delitem__ __getitem____len____mul__ __reversed____rmul__ __setitem__rDcountextendindexinsertrremovereverser__imul__c@seZdZddZddZdS) ListProxycCs|jd|f|S)Nr0)r)r$rrrr__iadd__AszListProxy.__iadd__cCs|jd|f|S)Nr5)r)r$rrrrr5DszListProxy.__imul__N)r*r,r-r7r5rrrrr6@sr6 DictProxyr rrrhas_keypopitem setdefaultrIterator ArrayProxy PoolProxyapply apply_asyncrimapimap_unorderedrmap map_asyncstarmap starmap_asyncrZ AsyncResult)r@rDrFrArBc@seZdZddZddZdS)r>cCs|S)Nr)r$rrrrdszPoolProxy.__enter__cCs |jdS)N)r)r$rrrrrrrfszPoolProxy.__exit__N)r*r,r-rrrrrrr>csc@seZdZdZdS)ra( Subclass of `BaseManager` which supports a number of shared object types. The types registered are those intended for the synchronization of threads, plus `dict`, `list` and `Namespace`. The `multiprocessing.Manager()` function creates started instances of this class. N)r*r,r-r.rrrrrms QueueZ JoinableQueuergraRLock SemaphoreBoundedSemaphore ConditionBarrierPoolrrF)rr)r)rrr)NNNT)T)r&r'r(r)r*r+r,r-r.rDr/r0r1r2rr3r4rr5)r'r(r)r r*r.rrrr9rrrr:r;rr)r*r)r.) r?r@rrArBrrCrDrErFr)I__all__rsr`rZqueuerrrrcontextr r r r r rrrZ view_typesrr Z view_typer!rr9r2rr<rGrIrJrrdreZ XmlListenerZ XmlClientr[rrrrrrrrrr r rrrrrr$r%r6r8rr=Z BasePoolProxyr>rrGrgrarHrIrJrKrLrMrrrrr s             ; ] 4             pool.cpython-36.opt-1.pyc000064400000050126147204630710011112 0ustar003 \e@s8ddgZddlZddlZddlZddlZddlZddlZddlZddlm Z ddlm Z m Z dZ dZ dZejZdd Zd d ZGd d d eZGdddZddZGdddeZdfddfddZddZGdddeZGdddeZeZGdddeZGdddeZGd d!d!eZ Gd"ddeZ!dS)#Pool ThreadPoolN)util) get_context TimeoutErrorcCs tt|S)N)listmap)argsr ,/usr/lib64/python3.6/multiprocessing/pool.pymapstar+srcCsttj|d|dS)Nrr)r itertoolsstarmap)r r r r starmapstar.src@seZdZddZddZdS)RemoteTracebackcCs ||_dS)N)tb)selfrr r r __init__6szRemoteTraceback.__init__cCs|jS)N)r)rr r r __str__8szRemoteTraceback.__str__N)__name__ __module__ __qualname__rrr r r r r5src@seZdZddZddZdS)ExceptionWithTracebackcCs0tjt|||}dj|}||_d||_dS)Nz """ %s""") tracebackformat_exceptiontypejoinexcr)rr rr r r r<s zExceptionWithTraceback.__init__cCst|j|jffS)N) rebuild_excr r)rr r r __reduce__Asz!ExceptionWithTraceback.__reduce__N)rrrrr"r r r r r;srcCst||_|S)N)r __cause__)r rr r r r!Ds r!cs0eZdZdZfddZddZddZZS)MaybeEncodingErrorzVWraps possible unpickleable errors, so they can be safely sent through the socket.cs.t||_t||_tt|j|j|jdS)N)reprr valuesuperr$r)rr r&) __class__r r rPs  zMaybeEncodingError.__init__cCsd|j|jfS)Nz(Error sending result: '%s'. Reason: '%s')r&r )rr r r rUszMaybeEncodingError.__str__cCsd|jj|fS)Nz<%s: %s>)r(r)rr r r __repr__YszMaybeEncodingError.__repr__)rrr__doc__rrr) __classcell__r r )r(r r$Ls r$Fc'Cs|j}|j}t|dr*|jj|jj|dk r:||d}xH|dksX|oT||kry |} Wn$ttfk rtj dPYnX| dkrtj dP| \} } } } }yd| | |f}WnBt k r}z&|r| t k rt ||j }d|f}WYdd}~XnXy|| | |fWnRt k rd}z4t||d}tj d||| | d|ffWYdd}~XnXd} } }} } }|d7}qBWtj d |dS) N_writerrz)worker got EOFError or OSError -- exitingzworker got sentinel -- exitingTFrz0Possible encoding error while sending result: %szworker exiting after %d tasks)putgethasattrr,close_readerEOFErrorOSErrorrdebug Exception_helper_reraises_exceptionr __traceback__r$)inqueueoutqueue initializerinitargsZmaxtasksZwrap_exceptionr-r.Z completedtaskjobifuncr kwdsresultewrappedr r r worker]sD        $ rDcCs|dS)z@Pickle-able helper function for use by _guarded_task_generation.Nr )Zexr r r r6sr6c@s6eZdZdZdZddZddfddfddZdd Zd d Zd d Z ddZ fifddZ d=ddZ d>ddZ d?ddZddZd@ddZdAddZfiddfdd ZdBd!d"ZdCd#d$Zed%d&Zed'd(Zed)d*Zed+d,Zd-d.Zd/d0Zd1d2Zd3d4Zed5d6Zed7d8Z d9d:Z!d;d<Z"dS)DrzS Class which supports an async version of applying functions to arguments. TcOs|jj||S)N)_ctxProcess)rr r@r r r rFsz Pool.ProcessNc Csn|pt|_|jtj|_i|_t|_||_ ||_ ||_ |dkrPt j pNd}|dkr`td|dk rzt| rztd||_g|_|jtjtj|fd|_d|j_t|j_|jjtjtj|j|j|j|j|jfd|_d|j_t|j_|jjtjtj|j|j |jfd|_!d|j!_t|j!_|j!jt"j#||j$|j|j%|j|j|j|j|j!|jfdd|_&dS)Nrz&Number of processes must be at least 1zinitializer must be a callable)targetr T)r Z exitpriority)'rrE _setup_queuesqueueQueue _taskqueue_cacheRUN_state_maxtasksperchild _initializer _initargsos cpu_count ValueErrorcallable TypeError _processes_pool_repopulate_pool threadingZThreadr_handle_workers_worker_handlerdaemonstart _handle_tasks _quick_put _outqueue _task_handler_handle_results _quick_get_result_handlerrZFinalize_terminate_pool_inqueue _terminate)r processesr:r;Zmaxtasksperchildcontextr r r rsT         z Pool.__init__cCsZd}xPttt|jD]:}|j|}|jdk rtjd||jd}|j|=qW|S)zCleanup after any worker processes which have exited due to reaching their specified lifetime. Returns True if any workers were cleaned up. FNzcleaning up worker %dT)reversedrangelenrYexitcoderr4r)rZcleanedr>rDr r r _join_exited_workerss   zPool._join_exited_workersc Cs|xvt|jt|jD]^}|jt|j|j|j|j |j |j fd}|jj ||j jdd|_ d|_|jtjdqWdS)zBring the number of pool processes up to the specified number, for use after reaping workers which have exited. )rGr rFZ PoolWorkerTz added workerN)rmrXrnrYrFrDrhrbrQrRrP_wrap_exceptionappendnamereplacer^r_rr4)rr>wr r r rZs  zPool._repopulate_poolcCs|jr|jdS)zEClean up any exited workers and start replacements for them. N)rprZ)rr r r _maintain_poolszPool._maintain_poolcCs4|jj|_|jj|_|jjj|_|jjj|_ dS)N) rEZ SimpleQueuerhrbr,sendrar1recvre)rr r r rIs   zPool._setup_queuescCs|j|||jS)z6 Equivalent of `func(*args, **kwds)`. ) apply_asyncr.)rr?r r@r r r applysz Pool.applycCs|j||t|jS)zx Apply `func` to each element in `iterable`, collecting the results in a list that is returned. ) _map_asyncrr.)rr?iterable chunksizer r r r szPool.mapcCs|j||t|jS)z Like `map()` method but the elements of the `iterable` are expected to be iterables as well and will be unpacked as arguments. Hence `func` and (a, b) becomes func(a, b). )r{rr.)rr?r|r}r r r r sz Pool.starmapcCs|j||t|||S)z= Asynchronous version of `starmap()` method. )r{r)rr?r|r}callbackerror_callbackr r r starmap_asyncs zPool.starmap_asyncccsny0d}x&t|D]\}}||||fifVqWWn8tk rh}z||dt|fifVWYdd}~XnXdS)zProvides a generator of tasks for imap and imap_unordered with appropriate handling for iterables which throw exceptions during iteration.rN) enumerater5r6)rZ result_jobr?r|r>xrBr r r _guarded_task_generations zPool._guarded_task_generationrcCs|jtkrtd|dkrFt|j}|jj|j|j|||j f|St j |||}t|j}|jj|j|jt ||j fdd|DSdS)zP Equivalent of `map()` -- can be MUCH slower than `Pool.map()`. zPool not runningrcss|]}|D] }|Vq qdS)Nr ).0chunkitemr r r @szPool.imap..N) rOrNrU IMapIteratorrMrLr-r_job _set_lengthr _get_tasksr)rr?r|r}rA task_batchesr r r imap's      z Pool.imapcCs|jtkrtd|dkrFt|j}|jj|j|j|||j f|St j |||}t|j}|jj|j|jt ||j fdd|DSdS)zL Like `imap()` method but ordering of results is arbitrary. zPool not runningrcss|]}|D] }|Vq qdS)Nr )rrrr r r r[sz&Pool.imap_unordered..N) rOrNrUIMapUnorderedIteratorrMrLr-rrrrrr)rr?r|r}rArr r r imap_unorderedBs      zPool.imap_unorderedcCsB|jtkrtdt|j||}|jj|jd|||fgdf|S)z; Asynchronous version of `apply()` method. zPool not runningrN)rOrNrU ApplyResultrMrLr-r)rr?r r@r~rrAr r r ry]s  zPool.apply_asynccCs|j||t|||S)z9 Asynchronous version of `map()` method. )r{r)rr?r|r}r~rr r r map_asynchszPool.map_asyncc Cs|jtkrtdt|ds$t|}|dkrTtt|t|jd\}}|rT|d7}t|dkrdd}tj |||}t |j |t|||d} |j j |j| j||df| S)zY Helper function to implement map, starmap and their async counterparts. zPool not running__len__Nrr)r)rOrNrUr/r divmodrnrYrr MapResultrMrLr-rr) rr?r|Zmapperr}r~rZextrarrAr r r r{ps&   zPool._map_asynccCsTtj}x0|jtks$|jr8|jtkr8|jtjdq W|j j dt j ddS)Ng?zworker handler exiting) r[current_threadrOrNrM TERMINATErvtimesleeprLr-rr4)poolthreadr r r r\s  zPool._handle_workersc Csjtj}xt|jdD]\}}d}zx|D]}|jr@tjdPy ||Wq*tk r} zD|dd\} } y|| j| d| fWnt k rYnXWYdd} ~ Xq*Xq*W|rtjd|r|dnd } || dwPWdd}}} XqWtjdy:tjd|j dtjdx|D]} |dq&WWn t k rZtjd YnXtjd dS) Nz'task handler found thread._state != RUNrFzdoing set_length()rztask handler got sentinelz/task handler sending sentinel to result handlerz(task handler sending sentinel to workersz/task handler got OSError when sending sentinelsztask handler exitingr) r[riterr.rOrr4r5_setKeyErrorr-r3) taskqueuer-r9rcacherZtaskseqZ set_lengthr<rBr=idxpr r r r`sB          zPool._handle_taskscCstj}xy |}Wn"ttfk r6tjddSX|jrJtjdP|dkr^tjdP|\}}}y||j||Wntk rYnXd}}}q Wx|o|jt kr:y |}Wn"ttfk rtjddSX|dkrtjdq|\}}}y||j||Wntk r*YnXd}}}qWt |drtjdy,x&t dD]}|j j spP|q^WWnttfk rYnXtjdt||jdS) Nz.result handler got EOFError/OSError -- exitingz,result handler found thread._state=TERMINATEzresult handler got sentinelz&result handler ignoring extra sentinelr1z"ensuring that outqueue is not full z7result handler exiting: len(cache)=%s, thread._state=%s)r[rr3r2rr4rOrrrr/rmr1pollrn)r9r.rrr<r=r>objr r r rdsZ            zPool._handle_resultsccs4t|}x&ttj||}|s"dS||fVq WdS)N)rtuplerislice)r?itsizerr r r rs zPool._get_taskscCs tddS)Nz:pool objects cannot be passed between processes or pickled)NotImplementedError)rr r r r"szPool.__reduce__cCs&tjd|jtkr"t|_t|j_dS)Nz closing pool)rr4rOrNCLOSEr])rr r r r0s  z Pool.closecCs$tjdt|_t|j_|jdS)Nzterminating pool)rr4rrOr]ri)rr r r terminates zPool.terminatecCsDtjd|jj|jj|jjx|jD] }|jq0WdS)Nz joining pool)rr4r]rrcrfrY)rrr r r rs      z Pool.joincCsDtjd|jjx*|jr>|jjr>|jjtj dqWdS)Nz7removing tasks from inqueue until task handler finishedr) rr4Z_rlockacquireis_aliver1rrxrr)r8 task_handlerrr r r _help_stuff_finish(s    zPool._help_stuff_finishc Cs(tjdt|_t|_tjd|j||t|t|_|jdtjdtj|k r`|j |rt |ddrtjdx|D]} | j dkr| j qWtjdtj|k r|j tjdtj|k r|j |ot |ddr$tjd x,|D]$} | j rtjd | j| j qWdS) Nzfinalizing poolz&helping task handler/workers to finishzjoining worker handlerrrzterminating workerszjoining task handlerzjoining result handlerzjoining pool workerszcleaning up worker %d)rr4rrOrrnr-r[rrr/rorrpid) clsrr8r9rZworker_handlerrZresult_handlerrrr r r rg1s6               zPool._terminate_poolcCs|S)Nr )rr r r __enter___szPool.__enter__cCs |jdS)N)r)rexc_typeZexc_valZexc_tbr r r __exit__bsz Pool.__exit__)N)N)NNN)r)r)NNN)NNN)#rrrr*rqrFrrprZrvrIrzr rrrrrryrr{ staticmethodr\r`rdrr"r0rrr classmethodrgrrr r r r rsF8         . <  .c@s@eZdZddZddZddZddd Zdd d Zd d ZdS)rcCs4tj|_tt|_||_||_||_|||j<dS)N) r[ZEvent_eventnext job_counterrrM _callback_error_callback)rrr~rr r r rks   zApplyResult.__init__cCs |jjS)N)rZis_set)rr r r readysszApplyResult.readycCs|jS)N)_success)rr r r successfulvszApplyResult.successfulNcCs|jj|dS)N)rwait)rtimeoutr r r rzszApplyResult.waitcCs,|j||jst|jr"|jS|jdS)N)rrrr_value)rrr r r r.}s  zApplyResult.getcCsV|\|_|_|jr$|jr$|j|j|jr>|j r>|j|j|jj|j|j=dS)N)rrrrrsetrMr)rr>rr r r rs     zApplyResult._set)N)N) rrrrrrrr.rr r r r ris   rc@seZdZddZddZdS)rcCsftj||||dd|_dg||_||_|dkrLd|_|jj||j=n||t |||_dS)N)rTr) rrrr _chunksize _number_leftrrrbool)rrr}lengthr~rr r r rs    zMapResult.__init__cCs|jd8_|\}}|rp|jrp||j||j|d|j<|jdkr|jrZ|j|j|j|j=|jjnH| r|jrd|_||_|jdkr|j r|j |j|j|j=|jjdS)NrrF) rrrrrrMrrrr)rr>Zsuccess_resultsuccessrAr r r rs"         zMapResult._setN)rrrrrr r r r rs rc@s:eZdZddZddZd ddZeZdd Zd d ZdS) rcCsJtjtj|_tt|_||_tj |_ d|_ d|_ i|_ |||j<dS)Nr)r[Z ConditionZLock_condrrrrM collectionsdeque_items_index_length _unsorted)rrr r r rs  zIMapIterator.__init__cCs|S)Nr )rr r r __iter__szIMapIterator.__iter__NcCs|j~y|jj}Wnhtk r~|j|jkr6t|jj|y|jj}Wn(tk rx|j|jkrpttYnXYnXWdQRX|\}}|r|S|dS)N) rrpopleft IndexErrorrr StopIterationrr)rrrrr&r r r rs"   zIMapIterator.nextc Cs|j|j|krr|jj||jd7_x8|j|jkrd|jj|j}|jj||jd7_q.W|jjn ||j|<|j|jkr|j|j =WdQRXdS)Nr) rrrrrrpopnotifyrrMr)rr>rr r r rs      zIMapIterator._setc Cs<|j,||_|j|jkr.|jj|j|j=WdQRXdS)N)rrrrrMr)rrr r r rs   zIMapIterator._set_length)N) rrrrrr__next__rrr r r r rs   rc@seZdZddZdS)rc CsP|j@|jj||jd7_|jj|j|jkrB|j|j=WdQRXdS)Nr)rrrrrrrrMr)rr>rr r r rs    zIMapUnorderedIterator._setN)rrrrr r r r rsrc@s@eZdZdZeddZddffddZddZed d ZdS) rFcOsddlm}|||S)Nr)rF)ZdummyrF)r r@rFr r r rFs zThreadPool.ProcessNcCstj||||dS)N)rr)rrjr:r;r r r rszThreadPool.__init__cCs,tj|_tj|_|jj|_|jj|_dS)N)rJrKrhrbr-rar.re)rr r r rIs   zThreadPool._setup_queuesc Cs<|j,|jj|jjdg||jjWdQRXdS)N)Z not_emptyrJclearextendZ notify_all)r8rrr r r rs zThreadPool._help_stuff_finish) rrrrqrrFrrIrr r r r r s  )"__all__r[rJrrrSrrrrrrrNrrcountrrrr5rrr!r$rDr6objectrrZ AsyncResultrrrrr r r r  s@   *\&)@pool.cpython-36.opt-2.pyc000064400000045034147204630710011115 0ustar003 \e@s8ddgZddlZddlZddlZddlZddlZddlZddlZddlm Z ddlm Z m Z dZ dZ dZejZdd Zd d ZGd d d eZGdddZddZGdddeZdfddfddZddZGdddeZGdddeZeZGdddeZGdddeZGd d!d!eZ Gd"ddeZ!dS)#Pool ThreadPoolN)util) get_context TimeoutErrorcCs tt|S)N)listmap)argsr ,/usr/lib64/python3.6/multiprocessing/pool.pymapstar+srcCsttj|d|dS)Nrr)r itertoolsstarmap)r r r r starmapstar.src@seZdZddZddZdS)RemoteTracebackcCs ||_dS)N)tb)selfrr r r __init__6szRemoteTraceback.__init__cCs|jS)N)r)rr r r __str__8szRemoteTraceback.__str__N)__name__ __module__ __qualname__rrr r r r r5src@seZdZddZddZdS)ExceptionWithTracebackcCs0tjt|||}dj|}||_d||_dS)Nz """ %s""") tracebackformat_exceptiontypejoinexcr)rr rr r r r<s zExceptionWithTraceback.__init__cCst|j|jffS)N) rebuild_excr r)rr r r __reduce__Asz!ExceptionWithTraceback.__reduce__N)rrrrr"r r r r r;srcCst||_|S)N)r __cause__)r rr r r r!Ds r!cs,eZdZfddZddZddZZS)MaybeEncodingErrorcs.t||_t||_tt|j|j|jdS)N)reprr valuesuperr$r)rr r&) __class__r r rPs  zMaybeEncodingError.__init__cCsd|j|jfS)Nz(Error sending result: '%s'. Reason: '%s')r&r )rr r r rUszMaybeEncodingError.__str__cCsd|jj|fS)Nz<%s: %s>)r(r)rr r r __repr__YszMaybeEncodingError.__repr__)rrrrrr) __classcell__r r )r(r r$Ls r$Fc'Cs|j}|j}t|dr*|jj|jj|dk r:||d}xH|dksX|oT||kry |} Wn$ttfk rtj dPYnX| dkrtj dP| \} } } } }yd| | |f}WnBt k r}z&|r| t k rt ||j }d|f}WYdd}~XnXy|| | |fWnRt k rd}z4t||d}tj d||| | d|ffWYdd}~XnXd} } }} } }|d7}qBWtj d |dS) N_writerrz)worker got EOFError or OSError -- exitingzworker got sentinel -- exitingTFrz0Possible encoding error while sending result: %szworker exiting after %d tasks)putgethasattrr+close_readerEOFErrorOSErrorrdebug Exception_helper_reraises_exceptionr __traceback__r$)inqueueoutqueue initializerinitargsZmaxtasksZwrap_exceptionr,r-Z completedtaskjobifuncr kwdsresultewrappedr r r worker]sD        $ rCcCs|dS)Nr )Zexr r r r5sr5c@s2eZdZdZddZddfddfddZddZd d Zd d Zd dZ fifddZ dddZ ddZd?ddZd@ddZfiddfddZdAd d!ZdBd"d#Zed$d%Zed&d'Zed(d)Zed*d+Zd,d-Zd.d/Zd0d1Zd2d3Zed4d5Zed6d7Zd8d9Z d:d;Z!dS)CrTcOs|jj||S)N)_ctxProcess)rr r?r r r rEsz Pool.ProcessNc Csn|pt|_|jtj|_i|_t|_||_ ||_ ||_ |dkrPt j pNd}|dkr`td|dk rzt| rztd||_g|_|jtjtj|fd|_d|j_t|j_|jjtjtj|j|j|j|j|jfd|_d|j_t|j_|jjtjtj|j|j |jfd|_!d|j!_t|j!_|j!jt"j#||j$|j|j%|j|j|j|j|j!|jfdd|_&dS)Nrz&Number of processes must be at least 1zinitializer must be a callable)targetr T)r Z exitpriority)'rrD _setup_queuesqueueQueue _taskqueue_cacheRUN_state_maxtasksperchild _initializer _initargsos cpu_count ValueErrorcallable TypeError _processes_pool_repopulate_pool threadingZThreadr_handle_workers_worker_handlerdaemonstart _handle_tasks _quick_put _outqueue _task_handler_handle_results _quick_get_result_handlerrZFinalize_terminate_pool_inqueue _terminate)r processesr9r:Zmaxtasksperchildcontextr r r rsT         z Pool.__init__cCsZd}xPttt|jD]:}|j|}|jdk rtjd||jd}|j|=qW|S)NFzcleaning up worker %dT)reversedrangelenrXexitcoderr3r)rZcleanedr=rCr r r _join_exited_workerss   zPool._join_exited_workersc Cs|xvt|jt|jD]^}|jt|j|j|j|j |j |j fd}|jj ||j jdd|_ d|_|jtjdqWdS)N)rFr rEZ PoolWorkerTz added worker)rlrWrmrXrErCrgrarPrQrO_wrap_exceptionappendnamereplacer]r^rr3)rr=wr r r rYs  zPool._repopulate_poolcCs|jr|jdS)N)rorY)rr r r _maintain_poolszPool._maintain_poolcCs4|jj|_|jj|_|jjj|_|jjj|_ dS)N) rDZ SimpleQueuergrar+sendr`r0recvrd)rr r r rHs   zPool._setup_queuescCs|j|||jS)N) apply_asyncr-)rr>r r?r r r applysz Pool.applycCs|j||t|jS)N) _map_asyncrr-)rr>iterable chunksizer r r r szPool.mapcCs|j||t|jS)N)rzrr-)rr>r{r|r r r r sz Pool.starmapcCs|j||t|||S)N)rzr)rr>r{r|callbackerror_callbackr r r starmap_asyncs zPool.starmap_asyncccsny0d}x&t|D]\}}||||fifVqWWn8tk rh}z||dt|fifVWYdd}~XnXdS)Nr) enumerater4r5)rZ result_jobr>r{r=xrAr r r _guarded_task_generations zPool._guarded_task_generationrcCs|jtkrtd|dkrFt|j}|jj|j|j|||j f|St j |||}t|j}|jj|j|jt ||j fdd|DSdS)NzPool not runningrcss|]}|D] }|Vq qdS)Nr ).0chunkitemr r r @szPool.imap..) rNrMrT IMapIteratorrLrKr,r_job _set_lengthr _get_tasksr)rr>r{r|r@ task_batchesr r r imap's      z Pool.imapcCs|jtkrtd|dkrFt|j}|jj|j|j|||j f|St j |||}t|j}|jj|j|jt ||j fdd|DSdS)NzPool not runningrcss|]}|D] }|Vq qdS)Nr )rrrr r r r[sz&Pool.imap_unordered..) rNrMrTIMapUnorderedIteratorrLrKr,rrrrrr)rr>r{r|r@rr r r imap_unorderedBs      zPool.imap_unorderedcCsB|jtkrtdt|j||}|jj|jd|||fgdf|S)NzPool not runningr)rNrMrT ApplyResultrLrKr,r)rr>r r?r}r~r@r r r rx]s  zPool.apply_asynccCs|j||t|||S)N)rzr)rr>r{r|r}r~r r r map_asynchszPool.map_asyncc Cs|jtkrtdt|ds$t|}|dkrTtt|t|jd\}}|rT|d7}t|dkrdd}tj |||}t |j |t|||d} |j j |j| j||df| S)NzPool not running__len__rr)r~)rNrMrTr.r divmodrmrXrr MapResultrLrKr,rr) rr>r{Zmapperr|r}r~Zextrarr@r r r rzps&   zPool._map_asynccCsTtj}x0|jtks$|jr8|jtkr8|jtjdq W|j j dt j ddS)Ng?zworker handler exiting) rZcurrent_threadrNrMrL TERMINATErutimesleeprKr,rr3)poolthreadr r r r[s  zPool._handle_workersc Csjtj}xt|jdD]\}}d}zx|D]}|jr@tjdPy ||Wq*tk r} zD|dd\} } y|| j| d| fWnt k rYnXWYdd} ~ Xq*Xq*W|rtjd|r|dnd } || dwPWdd}}} XqWtjdy:tjd|j dtjdx|D]} |dq&WWn t k rZtjd YnXtjd dS) Nz'task handler found thread._state != RUNrFzdoing set_length()rztask handler got sentinelz/task handler sending sentinel to result handlerz(task handler sending sentinel to workersz/task handler got OSError when sending sentinelsztask handler exitingr) rZriterr-rNrr3r4_setKeyErrorr,r2) taskqueuer,r8rcacherZtaskseqZ set_lengthr;rAr<idxpr r r r_sB          zPool._handle_taskscCstj}xy |}Wn"ttfk r6tjddSX|jrJtjdP|dkr^tjdP|\}}}y||j||Wntk rYnXd}}}q Wx|o|jt kr:y |}Wn"ttfk rtjddSX|dkrtjdq|\}}}y||j||Wntk r*YnXd}}}qWt |drtjdy,x&t dD]}|j j spP|q^WWnttfk rYnXtjdt||jdS) Nz.result handler got EOFError/OSError -- exitingz,result handler found thread._state=TERMINATEzresult handler got sentinelz&result handler ignoring extra sentinelr0z"ensuring that outqueue is not full z7result handler exiting: len(cache)=%s, thread._state=%s)rZrr2r1rr3rNrrrr.rlr0pollrm)r8r-rrr;r<r=objr r r rcsZ            zPool._handle_resultsccs4t|}x&ttj||}|s"dS||fVq WdS)N)rtuplerislice)r>itsizerr r r rs zPool._get_taskscCs tddS)Nz:pool objects cannot be passed between processes or pickled)NotImplementedError)rr r r r"szPool.__reduce__cCs&tjd|jtkr"t|_t|j_dS)Nz closing pool)rr3rNrMCLOSEr\)rr r r r/s  z Pool.closecCs$tjdt|_t|j_|jdS)Nzterminating pool)rr3rrNr\rh)rr r r terminates zPool.terminatecCsDtjd|jj|jj|jjx|jD] }|jq0WdS)Nz joining pool)rr3r\rrbrerX)rrr r r rs      z Pool.joincCsDtjd|jjx*|jr>|jjr>|jjtj dqWdS)Nz7removing tasks from inqueue until task handler finishedr) rr3Z_rlockacquireis_aliver0rrwrr)r7 task_handlerrr r r _help_stuff_finish(s    zPool._help_stuff_finishc Cs(tjdt|_t|_tjd|j||t|t|_|jdtjdtj|k r`|j |rt |ddrtjdx|D]} | j dkr| j qWtjdtj|k r|j tjdtj|k r|j |ot |ddr$tjd x,|D]$} | j rtjd | j| j qWdS) Nzfinalizing poolz&helping task handler/workers to finishzjoining worker handlerrrzterminating workerszjoining task handlerzjoining result handlerzjoining pool workerszcleaning up worker %d)rr3rrNrrmr,rZrrr.rnrrpid) clsrr7r8rZworker_handlerrZresult_handlerrrr r r rf1s6               zPool._terminate_poolcCs|S)Nr )rr r r __enter___szPool.__enter__cCs |jdS)N)r)rexc_typeZexc_valZexc_tbr r r __exit__bsz Pool.__exit__)N)N)NNN)r)r)NNN)NNN)"rrrrprErrorYrurHryr rrrrrrxrrz staticmethodr[r_rcrr"r/rrr classmethodrfrrr r r r rsD8         . <  .c@s@eZdZddZddZddZddd Zdd d Zd d ZdS)rcCs4tj|_tt|_||_||_||_|||j<dS)N) rZZEvent_eventnext job_counterrrL _callback_error_callback)rrr}r~r r r rks   zApplyResult.__init__cCs |jjS)N)rZis_set)rr r r readysszApplyResult.readycCs|jS)N)_success)rr r r successfulvszApplyResult.successfulNcCs|jj|dS)N)rwait)rtimeoutr r r rzszApplyResult.waitcCs,|j||jst|jr"|jS|jdS)N)rrrr_value)rrr r r r-}s  zApplyResult.getcCsV|\|_|_|jr$|jr$|j|j|jr>|j r>|j|j|jj|j|j=dS)N)rrrrrsetrLr)rr=rr r r rs     zApplyResult._set)N)N) rrrrrrrr-rr r r r ris   rc@seZdZddZddZdS)rcCsftj||||dd|_dg||_||_|dkrLd|_|jj||j=n||t |||_dS)N)r~Tr) rrrr _chunksize _number_leftrrrbool)rrr|lengthr}r~r r r rs    zMapResult.__init__cCs|jd8_|\}}|rp|jrp||j||j|d|j<|jdkr|jrZ|j|j|j|j=|jjnH| r|jrd|_||_|jdkr|j r|j |j|j|j=|jjdS)NrrF) rrrrrrLrrrr)rr=Zsuccess_resultsuccessr@r r r rs"         zMapResult._setN)rrrrrr r r r rs rc@s:eZdZddZddZd ddZeZdd Zd d ZdS) rcCsJtjtj|_tt|_||_tj |_ d|_ d|_ i|_ |||j<dS)Nr)rZZ ConditionZLock_condrrrrL collectionsdeque_items_index_length _unsorted)rrr r r rs  zIMapIterator.__init__cCs|S)Nr )rr r r __iter__szIMapIterator.__iter__NcCs|j~y|jj}Wnhtk r~|j|jkr6t|jj|y|jj}Wn(tk rx|j|jkrpttYnXYnXWdQRX|\}}|r|S|dS)N) rrpopleft IndexErrorrr StopIterationrr)rrrrr&r r r rs"   zIMapIterator.nextc Cs|j|j|krr|jj||jd7_x8|j|jkrd|jj|j}|jj||jd7_q.W|jjn ||j|<|j|jkr|j|j =WdQRXdS)Nr) rrrrqrpopnotifyrrLr)rr=rr r r rs      zIMapIterator._setc Cs<|j,||_|j|jkr.|jj|j|j=WdQRXdS)N)rrrrrLr)rrr r r rs   zIMapIterator._set_length)N) rrrrrr__next__rrr r r r rs   rc@seZdZddZdS)rc CsP|j@|jj||jd7_|jj|j|jkrB|j|j=WdQRXdS)Nr)rrrqrrrrLr)rr=rr r r rs    zIMapUnorderedIterator._setN)rrrrr r r r rsrc@s@eZdZdZeddZddffddZddZed d ZdS) rFcOsddlm}|||S)Nr)rE)ZdummyrE)r r?rEr r r rEs zThreadPool.ProcessNcCstj||||dS)N)rr)rrir9r:r r r rszThreadPool.__init__cCs,tj|_tj|_|jj|_|jj|_dS)N)rIrJrgrar,r`r-rd)rr r r rHs   zThreadPool._setup_queuesc Cs<|j,|jj|jjdg||jjWdQRXdS)N)Z not_emptyrIclearextendZ notify_all)r7rrr r r rs zThreadPool._help_stuff_finish) rrrrprrErrHrr r r r r s  )"__all__rZrIrrrRrrrrrrrMrrcountrrrr4rrr!r$rCr5objectrrZ AsyncResultrrrrr r r r  s@   *\&)@pool.cpython-36.pyc000064400000050527147204630710010160 0ustar003 \e@s8ddgZddlZddlZddlZddlZddlZddlZddlZddlm Z ddlm Z m Z dZ dZ dZejZdd Zd d ZGd d d eZGdddZddZGdddeZdfddfddZddZGdddeZGdddeZeZGdddeZGdddeZGd d!d!eZ Gd"ddeZ!dS)#Pool ThreadPoolN)util) get_context TimeoutErrorcCs tt|S)N)listmap)argsr ,/usr/lib64/python3.6/multiprocessing/pool.pymapstar+srcCsttj|d|dS)Nrr)r itertoolsstarmap)r r r r starmapstar.src@seZdZddZddZdS)RemoteTracebackcCs ||_dS)N)tb)selfrr r r __init__6szRemoteTraceback.__init__cCs|jS)N)r)rr r r __str__8szRemoteTraceback.__str__N)__name__ __module__ __qualname__rrr r r r r5src@seZdZddZddZdS)ExceptionWithTracebackcCs0tjt|||}dj|}||_d||_dS)Nz """ %s""") tracebackformat_exceptiontypejoinexcr)rr rr r r r<s zExceptionWithTraceback.__init__cCst|j|jffS)N) rebuild_excr r)rr r r __reduce__Asz!ExceptionWithTraceback.__reduce__N)rrrrr"r r r r r;srcCst||_|S)N)r __cause__)r rr r r r!Ds r!cs0eZdZdZfddZddZddZZS)MaybeEncodingErrorzVWraps possible unpickleable errors, so they can be safely sent through the socket.cs.t||_t||_tt|j|j|jdS)N)reprr valuesuperr$r)rr r&) __class__r r rPs  zMaybeEncodingError.__init__cCsd|j|jfS)Nz(Error sending result: '%s'. Reason: '%s')r&r )rr r r rUszMaybeEncodingError.__str__cCsd|jj|fS)Nz<%s: %s>)r(r)rr r r __repr__YszMaybeEncodingError.__repr__)rrr__doc__rrr) __classcell__r r )r(r r$Ls r$Fc'Cs|dks t|tkr|dks t|j}|j}t|drJ|jj|jj|dk rZ||d}xL|dksx|ot||kry |} Wn$t t fk rt j dPYnX| dkrt j dP| \} } } } }yd| | |f}WnFt k r"}z(|o| tk r t||j}d|f}WYdd}~XnXy|| | |fWnRt k r}z4t||d}t j d||| | d|ffWYdd}~XnXd} } }} } }|d7}qbWt j d |dS) Nr_writerz)worker got EOFError or OSError -- exitingzworker got sentinel -- exitingTFrz0Possible encoding error while sending result: %szworker exiting after %d tasks)rintAssertionErrorputgethasattrr,close_readerEOFErrorOSErrorrdebug Exception_helper_reraises_exceptionr __traceback__r$)inqueueoutqueue initializerinitargsZmaxtasksZwrap_exceptionr/r0Z completedtaskjobifuncr kwdsresultewrappedr r r worker]sF        $ rFcCs|dS)z@Pickle-able helper function for use by _guarded_task_generation.Nr )Zexr r r r8sr8c@s6eZdZdZdZddZddfddfddZdd Zd d Zd d Z ddZ fifddZ d=ddZ d>ddZ d?ddZddZd@ddZdAddZfiddfdd ZdBd!d"ZdCd#d$Zed%d&Zed'd(Zed)d*Zed+d,Zd-d.Zd/d0Zd1d2Zd3d4Zed5d6Zed7d8Z d9d:Z!d;d<Z"dS)DrzS Class which supports an async version of applying functions to arguments. TcOs|jj||S)N)_ctxProcess)rr rBr r r rHsz Pool.ProcessNc Csn|pt|_|jtj|_i|_t|_||_ ||_ ||_ |dkrPt j pNd}|dkr`td|dk rzt| rztd||_g|_|jtjtj|fd|_d|j_t|j_|jjtjtj|j|j|j|j|jfd|_d|j_t|j_|jjtjtj|j|j |jfd|_!d|j!_t|j!_|j!jt"j#||j$|j|j%|j|j|j|j|j!|jfdd|_&dS)Nrz&Number of processes must be at least 1zinitializer must be a callable)targetr T)r Z exitpriority)'rrG _setup_queuesqueueQueue _taskqueue_cacheRUN_state_maxtasksperchild _initializer _initargsos cpu_count ValueErrorcallable TypeError _processes_pool_repopulate_pool threadingZThreadr_handle_workers_worker_handlerdaemonstart _handle_tasks _quick_put _outqueue _task_handler_handle_results _quick_get_result_handlerrZFinalize_terminate_pool_inqueue _terminate)r processesr<r=Zmaxtasksperchildcontextr r r rsT         z Pool.__init__cCsZd}xPttt|jD]:}|j|}|jdk rtjd||jd}|j|=qW|S)zCleanup after any worker processes which have exited due to reaching their specified lifetime. Returns True if any workers were cleaned up. FNzcleaning up worker %dT)reversedrangelenr[exitcoderr6r)rZcleanedr@rFr r r _join_exited_workerss   zPool._join_exited_workersc Cs|xvt|jt|jD]^}|jt|j|j|j|j |j |j fd}|jj ||j jdd|_ d|_|jtjdqWdS)zBring the number of pool processes up to the specified number, for use after reaping workers which have exited. )rIr rHZ PoolWorkerTz added workerN)rorZrpr[rHrFrjrdrSrTrR_wrap_exceptionappendnamereplacer`rarr6)rr@wr r r r\s  zPool._repopulate_poolcCs|jr|jdS)zEClean up any exited workers and start replacements for them. N)rrr\)rr r r _maintain_poolszPool._maintain_poolcCs4|jj|_|jj|_|jjj|_|jjj|_ dS)N) rGZ SimpleQueuerjrdr,sendrcr3recvrg)rr r r rKs   zPool._setup_queuescCs |jtkst|j|||jS)z6 Equivalent of `func(*args, **kwds)`. )rQrPr. apply_asyncr0)rrAr rBr r r applysz Pool.applycCs|j||t|jS)zx Apply `func` to each element in `iterable`, collecting the results in a list that is returned. ) _map_asyncrr0)rrAiterable chunksizer r r r szPool.mapcCs|j||t|jS)z Like `map()` method but the elements of the `iterable` are expected to be iterables as well and will be unpacked as arguments. Hence `func` and (a, b) becomes func(a, b). )r}rr0)rrAr~rr r r r sz Pool.starmapcCs|j||t|||S)z= Asynchronous version of `starmap()` method. )r}r)rrAr~rcallbackerror_callbackr r r starmap_asyncs zPool.starmap_asyncccsny0d}x&t|D]\}}||||fifVqWWn8tk rh}z||dt|fifVWYdd}~XnXdS)zProvides a generator of tasks for imap and imap_unordered with appropriate handling for iterables which throw exceptions during iteration.rN) enumerater7r8)rZ result_jobrAr~r@xrDr r r _guarded_task_generations zPool._guarded_task_generationrcCs|jtkrtd|dkrFt|j}|jj|j|j|||j f|S|dksRt t j |||}t|j}|jj|j|jt ||j fdd|DSdS)zP Equivalent of `map()` -- can be MUCH slower than `Pool.map()`. zPool not runningrcss|]}|D] }|Vq qdS)Nr ).0chunkitemr r r @szPool.imap..N)rQrPrW IMapIteratorrOrNr/r_job _set_lengthr.r _get_tasksr)rrAr~rrC task_batchesr r r imap's"      z Pool.imapcCs|jtkrtd|dkrFt|j}|jj|j|j|||j f|S|dksRt t j |||}t|j}|jj|j|jt ||j fdd|DSdS)zL Like `imap()` method but ordering of results is arbitrary. zPool not runningrcss|]}|D] }|Vq qdS)Nr )rrrr r r r[sz&Pool.imap_unordered..N)rQrPrWIMapUnorderedIteratorrOrNr/rrrr.rrr)rrAr~rrCrr r r imap_unorderedBs"      zPool.imap_unorderedcCsB|jtkrtdt|j||}|jj|jd|||fgdf|S)z; Asynchronous version of `apply()` method. zPool not runningrN)rQrPrW ApplyResultrOrNr/r)rrAr rBrrrCr r r r{]s  zPool.apply_asynccCs|j||t|||S)z9 Asynchronous version of `map()` method. )r}r)rrAr~rrrr r r map_asynchszPool.map_asyncc Cs|jtkrtdt|ds$t|}|dkrTtt|t|jd\}}|rT|d7}t|dkrdd}tj |||}t |j |t|||d} |j j |j| j||df| S)zY Helper function to implement map, starmap and their async counterparts. zPool not running__len__Nrr)r)rQrPrWr1r divmodrpr[rr MapResultrOrNr/rr) rrAr~ZmapperrrrZextrarrCr r r r}ps&   zPool._map_asynccCsTtj}x0|jtks$|jr8|jtkr8|jtjdq W|j j dt j ddS)Ng?zworker handler exiting) r]current_threadrQrPrO TERMINATErxtimesleeprNr/rr6)poolthreadr r r r^s  zPool._handle_workersc Csjtj}xt|jdD]\}}d}zx|D]}|jr@tjdPy ||Wq*tk r} zD|dd\} } y|| j| d| fWnt k rYnXWYdd} ~ Xq*Xq*W|rtjd|r|dnd } || dwPWdd}}} XqWtjdy:tjd|j dtjdx|D]} |dq&WWn t k rZtjd YnXtjd dS) Nz'task handler found thread._state != RUNrFzdoing set_length()rztask handler got sentinelz/task handler sending sentinel to result handlerz(task handler sending sentinel to workersz/task handler got OSError when sending sentinelsztask handler exitingr) r]riterr0rQrr6r7_setKeyErrorr/r5) taskqueuer/r;rcacherZtaskseqZ set_lengthr>rDr?idxpr r r rbsB          zPool._handle_taskscCstj}xy |}Wn"ttfk r6tjddSX|jrX|jtksLttjdP|dkrltjdP|\}}}y||j ||Wnt k rYnXd}}}q Wx|o|jtkrJy |}Wn"ttfk rtjddSX|dkrtjdq|\}}}y||j ||Wnt k r:YnXd}}}qWt |drtjdy,x&t dD]}|j jsP|qnWWnttfk rYnXtjdt||jdS) Nz.result handler got EOFError/OSError -- exitingz,result handler found thread._state=TERMINATEzresult handler got sentinelz&result handler ignoring extra sentinelr3z"ensuring that outqueue is not full z7result handler exiting: len(cache)=%s, thread._state=%s)r]rr5r4rr6rQrr.rrr1ror3pollrp)r;r0rrr>r?r@objr r r rfs\             zPool._handle_resultsccs4t|}x&ttj||}|s"dS||fVq WdS)N)rtuplerislice)rAitsizerr r r rs zPool._get_taskscCs tddS)Nz:pool objects cannot be passed between processes or pickled)NotImplementedError)rr r r r"szPool.__reduce__cCs&tjd|jtkr"t|_t|j_dS)Nz closing pool)rr6rQrPCLOSEr_)rr r r r2s  z Pool.closecCs$tjdt|_t|j_|jdS)Nzterminating pool)rr6rrQr_rk)rr r r terminates zPool.terminatecCsVtjd|jttfkst|jj|jj|j jx|j D] }|jqBWdS)Nz joining pool) rr6rQrrr.r_rrerhr[)rrr r r rs     z Pool.joincCsDtjd|jjx*|jr>|jjr>|jjtj dqWdS)Nz7removing tasks from inqueue until task handler finishedr) rr6Z_rlockacquireis_aliver3rrzrr)r: task_handlerrr r r _help_stuff_finish(s    zPool._help_stuff_finishc CsFtjdt|_t|_tjd|j||t||jsJt|dksJtt|_|jdtjdt j |k rx|j |rt |ddrtjdx|D]} | j dkr| jqWtjdt j |k r|j tjdt j |k r|j |rBt |ddrBtjd x0|D](} | jrtjd | j| j qWdS) Nzfinalizing poolz&helping task handler/workers to finishrzjoining worker handlerrzterminating workerszjoining task handlerzjoining result handlerzjoining pool workerszcleaning up worker %d)rr6rrQrrprr.r/r]rrr1rqrpid) clsrr:r;rZworker_handlerrZresult_handlerrrr r r ri1s8                zPool._terminate_poolcCs|S)Nr )rr r r __enter___szPool.__enter__cCs |jdS)N)r)rexc_typeZexc_valZexc_tbr r r __exit__bsz Pool.__exit__)N)N)NNN)r)r)NNN)NNN)#rrrr*rsrHrrrr\rxrKr|r rrrrrr{rr} staticmethodr^rbrfrr"r2rrr classmethodrirrr r r r rsF8         . <  .c@s@eZdZddZddZddZddd Zdd d Zd d ZdS)rcCs4tj|_tt|_||_||_||_|||j<dS)N) r]ZEvent_eventnext job_counterrrO _callback_error_callback)rrrrr r r rks   zApplyResult.__init__cCs |jjS)N)rZis_set)rr r r readysszApplyResult.readycCs|js t|jS)N)rr._success)rr r r successfulvs zApplyResult.successfulNcCs|jj|dS)N)rwait)rtimeoutr r r rzszApplyResult.waitcCs,|j||jst|jr"|jS|jdS)N)rrrr_value)rrr r r r0}s  zApplyResult.getcCsV|\|_|_|jr$|jr$|j|j|jr>|j r>|j|j|jj|j|j=dS)N)rrrrrsetrOr)rr@rr r r rs     zApplyResult._set)N)N) rrrrrrrr0rr r r r ris   rc@seZdZddZddZdS)rcCsftj||||dd|_dg||_||_|dkrLd|_|jj||j=n||t |||_dS)N)rTr) rrrr _chunksize _number_leftrrrbool)rrrlengthrrr r r rs    zMapResult.__init__cCs|jd8_|\}}|rp|jrp||j||j|d|j<|jdkr|jrZ|j|j|j|j=|jjnH| r|jrd|_||_|jdkr|j r|j |j|j|j=|jjdS)NrrF) rrrrrrOrrrr)rr@Zsuccess_resultsuccessrCr r r rs"         zMapResult._setN)rrrrrr r r r rs rc@s:eZdZddZddZd ddZeZdd Zd d ZdS) rcCsJtjtj|_tt|_||_tj |_ d|_ d|_ i|_ |||j<dS)Nr)r]Z ConditionZLock_condrrrrO collectionsdeque_items_index_length _unsorted)rrr r r rs  zIMapIterator.__init__cCs|S)Nr )rr r r __iter__szIMapIterator.__iter__NcCs|j~y|jj}Wnhtk r~|j|jkr6t|jj|y|jj}Wn(tk rx|j|jkrpttYnXYnXWdQRX|\}}|r|S|dS)N) rrpopleft IndexErrorrr StopIterationrr)rrrrr&r r r rs"   zIMapIterator.nextc Cs|j|j|krr|jj||jd7_x8|j|jkrd|jj|j}|jj||jd7_q.W|jjn ||j|<|j|jkr|j|j =WdQRXdS)Nr) rrrrtrpopnotifyrrOr)rr@rr r r rs      zIMapIterator._setc Cs<|j,||_|j|jkr.|jj|j|j=WdQRXdS)N)rrrrrOr)rrr r r rs   zIMapIterator._set_length)N) rrrrrr__next__rrr r r r rs   rc@seZdZddZdS)rc CsP|j@|jj||jd7_|jj|j|jkrB|j|j=WdQRXdS)Nr)rrrtrrrrOr)rr@rr r r rs    zIMapUnorderedIterator._setN)rrrrr r r r rsrc@s@eZdZdZeddZddffddZddZed d ZdS) rFcOsddlm}|||S)Nr)rH)ZdummyrH)r rBrHr r r rHs zThreadPool.ProcessNcCstj||||dS)N)rr)rrlr<r=r r r rszThreadPool.__init__cCs,tj|_tj|_|jj|_|jj|_dS)N)rLrMrjrdr/rcr0rg)rr r r rKs   zThreadPool._setup_queuesc Cs<|j,|jj|jjdg||jjWdQRXdS)N)Z not_emptyrLclearextendZ notify_all)r:rrr r r rs zThreadPool._help_stuff_finish) rrrrsrrHrrKrr r r r r s  )"__all__r]rLrrrUrrrrrrrPrrcountrrrr7rrr!r$rFr8objectrrZ AsyncResultrrrrr r r r  s@   *\&)@popen_fork.cpython-36.opt-1.pyc000064400000004051147204630710012277 0ustar003 \ @s>ddlZddlZddlZddlmZdgZGdddeZdS)N)utilPopenc@sHeZdZdZddZddZejfddZdd d Z d d Z d dZ dS)rforkcCstjd|_|j|dS)N)rZ_flush_std_streams returncode_launch)self process_objr 2/usr/lib64/python3.6/multiprocessing/popen_fork.py__init__szPopen.__init__cCs|S)Nr )rfdr r r duplicate_for_childszPopen.duplicate_for_childcCs|jdkrzx>ytj|j|\}}Wn tk rB}zdSd}~Xq XPq W||jkrztj|rntj| |_n tj||_|jS)N)roswaitpidpidOSError WIFSIGNALEDWTERMSIG WEXITSTATUS)rflagrstser r r polls    z Popen.pollNcCsN|jdkrH|dk r0ddlm}||jg|s0dS|j|dkrBtjndS|jS)Nr)waitg)rZmultiprocessing.connectionrsentinelrrWNOHANG)rtimeoutrr r r r+s  z Popen.waitc Cs\|jdkrXytj|jtjWn8tk r2Yn&tk rV|jdddkrRYnXdS)Ng?)r) rrkillrsignalSIGTERMProcessLookupErrorrr)rr r r terminate5s zPopen.terminatec Csd}tj\}}tj|_|jdkrdz0tj|dtjkrJddl}|j|j }Wdtj |Xn"tj|t j |tj|f||_ dS)Nrrrandom)rpiperrclosesysmodulesr#Zseed _bootstrap_exitrZFinalizer)rr codeZparent_rZchild_wr#r r r r?s       z Popen._launch)N) __name__ __module__ __qualname__methodr rrrrrr"rr r r r r s  )rr&rr__all__objectrr r r r s  popen_fork.cpython-36.opt-2.pyc000064400000004051147204630710012300 0ustar003 \ @s>ddlZddlZddlZddlmZdgZGdddeZdS)N)utilPopenc@sHeZdZdZddZddZejfddZdd d Z d d Z d dZ dS)rforkcCstjd|_|j|dS)N)rZ_flush_std_streams returncode_launch)self process_objr 2/usr/lib64/python3.6/multiprocessing/popen_fork.py__init__szPopen.__init__cCs|S)Nr )rfdr r r duplicate_for_childszPopen.duplicate_for_childcCs|jdkrzx>ytj|j|\}}Wn tk rB}zdSd}~Xq XPq W||jkrztj|rntj| |_n tj||_|jS)N)roswaitpidpidOSError WIFSIGNALEDWTERMSIG WEXITSTATUS)rflagrstser r r polls    z Popen.pollNcCsN|jdkrH|dk r0ddlm}||jg|s0dS|j|dkrBtjndS|jS)Nr)waitg)rZmultiprocessing.connectionrsentinelrrWNOHANG)rtimeoutrr r r r+s  z Popen.waitc Cs\|jdkrXytj|jtjWn8tk r2Yn&tk rV|jdddkrRYnXdS)Ng?)r) rrkillrsignalSIGTERMProcessLookupErrorrr)rr r r terminate5s zPopen.terminatec Csd}tj\}}tj|_|jdkrdz0tj|dtjkrJddl}|j|j }Wdtj |Xn"tj|t j |tj|f||_ dS)Nrrrandom)rpiperrclosesysmodulesr#Zseed _bootstrap_exitrZFinalizer)rr codeZparent_rZchild_wr#r r r r?s       z Popen._launch)N) __name__ __module__ __qualname__methodr rrrrrr"rr r r r r s  )rr&rr__all__objectrr r r r s  popen_forkserver.cpython-36.opt-1.pyc000064400000004430147204630710013527 0ustar003 \@sddlZddlZddlmZmZejs.edddlmZddlm Z ddlm Z ddlm Z d gZ Gd d d e ZGd d d e jZdS) N) reductionset_spawning_popenz,No support for sending fds between processes) forkserver) popen_fork)spawn)utilPopenc@seZdZddZddZdS)_DupFdcCs ||_dS)N)ind)selfr r 8/usr/lib64/python3.6/multiprocessing/popen_forkserver.py__init__sz_DupFd.__init__cCstj|jS)N)rZget_inherited_fdsr )r r r rdetachsz _DupFd.detachN)__name__ __module__ __qualname__rrr r r rr sr csBeZdZdZeZfddZddZddZe j fdd Z Z S) r rcsg|_tj|dS)N)_fdssuperr)r process_obj) __class__r rr!szPopen.__init__cCs|jj|t|jdS)Nr)rappendlen)r fdr r rduplicate_for_child%s zPopen.duplicate_for_childcCstj|j}tj}t|ztj||tj||WdtdXtj |j \|_ }t j |tj|j ft|ddd}|j|jWdQRXtj|j |_dS)NwbT)closefd)rZget_preparation_data_nameioBytesIOrrdumprZconnect_to_new_processrsentinelrZFinalizeoscloseopenwrite getbuffer read_unsignedpid)r rZ prep_dataZbufwfr r r_launch)s   z Popen._launchc Csr|jdkrlddlm}|tjkr$dnd}||jg|s:dSytj|j|_Wntt fk rjd|_YnX|jS)Nr)wait) returncodeZmultiprocessing.connectionr-r#WNOHANGr"rr(OSErrorEOFError)r flagr-Ztimeoutr r rpoll9s   z Popen.poll) rrrmethodr ZDupFdrrr,r#r0r4 __classcell__r r )rrr s  )rr#contextrrZHAVE_SEND_HANDLE ImportErrorrrrr__all__objectr r r r r rs     popen_spawn_win32.cpython-36.pyc000064400000005310147204630710012550 0ustar003 \ @sddlZddlZddlZddlZddlZddlmZmZmZddl m Z ddl m Z dgZ dZ ejdkoreed d Zejjjd ZGd ddeZdS) N) reductionget_spawning_popenset_spawning_popen)spawn)utilPopeniZwin32frozenFzpythonservice.exec@s>eZdZdZdZddZddZddd Zd d Zd d Z dS)rz@ Start a subprocess to run the code of a process object rc Cstj|j}tjdd\}}tj|d}tjtj |d}dj dd|D}t |ddd}y4tj tj |ddd dddd \}} } } tj| Wntj|YnX| |_d|_||_t||_tj|tj|jft|ztj||tj||WdtdXWdQRXdS) Nr)Z parent_pidZ pipe_handle css|]}d|VqdS)z"%s"N).0xr r 9/usr/lib64/python3.6/multiprocessing/popen_spawn_win32.py )sz!Popen.__init__..wbT)closefdF)rZget_preparation_data_name_winapiZ CreatePipemsvcrtZopen_osfhandleZget_command_lineosgetpidjoinopenZ CreateProcessZget_executableZ CloseHandlepid returncode_handleintsentinelrZFinalizerrdump) selfZ process_objZ prep_dataZrhandleZwhandleZwfdcmdZto_childZhpZhtrtidr r r__init__ s2      zPopen.__init__cCs|tksttj||jS)N)rAssertionErrorrZ duplicater)rZhandler r rduplicate_for_childEszPopen.duplicate_for_childNcCst|jdkrn|dkrtj}ntdt|dd}tjt|j|}|tjkrntj|j}|t krht j }||_|jS)Nrig?) rrZINFINITEmaxrZWaitForSingleObjectrZ WAIT_OBJECT_0ZGetExitCodeProcess TERMINATEsignalSIGTERM)rtimeoutZmsecsrescoder r rwaitIs   z Popen.waitcCs |jddS)Nr)r))r,)rr r rpollYsz Popen.pollc CsL|jdkrHytjt|jtWn&tk rF|jdddkrBYnXdS)Ng?)r))rrZTerminateProcessrrr&OSErrorr,)rr r r terminate\s  zPopen.terminate)N) __name__ __module__ __qualname____doc__methodr"r$r,r-r/r r r rrs% )rrr'sysrcontextrrrrr__all__r&platformgetattrZWINEXE executablelowerendswithZ WINSERVICEobjectrr r r rs  process.cpython-36.opt-1.pyc000064400000016507147204630710011624 0ustar003 \# @sdddgZddlZddlZddlZddlZddlmZyejjej Z Wne k rbdZ YnXddZ ddZ dd ZGd ddeZGd d d eZGd ddeZeaejdaea[iZxSsz'BaseProcess.__init__..)next_process_counterr _identity_configcopyosgetpid _parent_pidr _targettuple_argsdict_kwargstype__name__join_namer _danglingadd)rgrouptargetnameargskwargsrcountrrr__init__Gs    zBaseProcess.__init__cCs|jr|j|j|jdS)zQ Method to be run in sub-process; can be overridden in sub-class N)r"r$r&)rrrrrunXszBaseProcess.runcCs6t|j||_|jj|_|`|`|`tj |dS)z% Start child process N) r rr sentinel _sentinelr"r$r&r r,)rrrrstart_s    zBaseProcess.startcCs|jjdS)zT Terminate process; sends SIGTERM signal or uses TerminateProcess() N)r terminate)rrrrr8pszBaseProcess.terminatecCs"|jj|}|dk rtj|dS)z5 Wait until child process terminates N)r waitr r)rZtimeoutresrrrr)vs zBaseProcess.joincCsB|tkr dS|jdkrdS|jj}|dkr0dStj|dSdS)z1 Return whether process is alive TNF)rr r r r)r returncoderrris_alives   zBaseProcess.is_alivecCs|jS)N)r*)rrrrr/szBaseProcess.namecCs ||_dS)N)r*)rr/rrrr/scCs|jjddS)z4 Return whether process is a daemon rF)rget)rrrrrszBaseProcess.daemoncCs||jd<dS)z1 Set whether process is a daemon rN)r)rZdaemonicrrrrscCs |jdS)Nauthkey)r)rrrrr>szBaseProcess.authkeycCst||jd<dS)z2 Set authorization key of process r>N)AuthenticationStringr)rr>rrrr>scCs|jdkr|jS|jjS)zM Return exit code of process or `None` if it has yet to stop N)r r )rrrrexitcodes zBaseProcess.exitcodecCs"|tkrtjS|jo|jjSdS)zU Return identifier (PID) of process or `None` if it has yet to start N)rrr r pid)rrrridentszBaseProcess.identc Cs(y|jStk r"tdYnXdS)z{ Return a file descriptor (Unix) or handle (Windows) suitable for waiting for process termination. zprocess not startedN)r6AttributeError ValueError)rrrrr5szBaseProcess.sentinelcCs|tkrd}n>|jtjkr"d}n*|jdkr2d}n|jjdk rH|j}nd}t|tkrv|dkrfd}ndt j ||}dt|j |j ||j rdpd fS) NZstartedunknowninitialrZstoppedz stopped[%s]z<%s(%s, %s%s)>z daemon)rr!rr r r r@r'int_exitcode_to_namer=r(r*r)rZstatusrrr__repr__s  zBaseProcess.__repr__c CsJddlm}m}zy||jdk r,|j|jtjdata |j t }|a z|j j |jWd~X|jdz|jd}Wd|jXWntk r}zL|jsd}n:t|jdtr|jd}ntjjt|jddd}WYdd}~Xn2d}ddl}tjjd|j|jYnXWd|jd||jX|S)N)utilcontextz child process calling self.run()r z Process %s: z process exiting with exitcode %d)rGrLrMZ _start_methodZ_force_start_method itertoolsr2rsetr Z _close_stdinrZ_finalizer_registryclearZ_run_after_forkersinfor4Z_exit_function SystemExitr0 isinstancerHsysstderrwriter tracebackr/ print_excZ_flush_std_streams)rrLrMZ old_processr@erXrrr _bootstrapsB        zBaseProcess._bootstrap)N)r( __module__ __qualname____doc__rr3r4r7r8r)r<propertyr/setterrr>r@rBrAr5rJr[rrrrr>s*       c@seZdZddZdS)r?cCs,ddlm}|dkrtdtt|ffS)NrK)get_spawning_popenzJPickling an AuthenticationString object is disallowed for security reasons)rMra TypeErrorr?bytes)rrarrr __reduce__s   zAuthenticationString.__reduce__N)r(r\r]rdrrrrr?sr?c@seZdZddZdS) _MainProcesscCs2f|_d|_d|_d|_ttjddd|_dS)NZ MainProcess z/mp)r>Z semprefix)rr*r!r r?rurandomr)rrrrr3-s  z_MainProcess.__init__N)r(r\r]r3rrrrre+srerKZSIG_) __all__rrUsignalrO _weakrefsetrpathabspathgetcwdZ ORIGINAL_DIROSErrorrrr objectrrcr?rerr2rrPr rIr __dict__itemsr/Zsignumr+rrrr s2     ` process.cpython-36.opt-2.pyc000064400000014455147204630710011625 0ustar003 \# @sdddgZddlZddlZddlZddlZddlmZyejjej Z Wne k rbdZ YnXddZ ddZ dd ZGd ddeZGd d d eZGd ddeZeaejdaea[iZxSsz'BaseProcess.__init__..)next_process_counterr _identity_configcopyosgetpid _parent_pidr _targettuple_argsdict_kwargstype__name__join_namer _danglingadd)rgrouptargetnameargskwargsrcountrrr__init__Gs    zBaseProcess.__init__cCs|jr|j|j|jdS)N)r"r$r&)rrrrrunXszBaseProcess.runcCs6t|j||_|jj|_|`|`|`tj |dS)N) r rr sentinel _sentinelr"r$r&r r,)rrrrstart_s    zBaseProcess.startcCs|jjdS)N)r terminate)rrrrr8pszBaseProcess.terminatecCs"|jj|}|dk rtj|dS)N)r waitr r)rZtimeoutresrrrr)vs zBaseProcess.joincCsB|tkr dS|jdkrdS|jj}|dkr0dStj|dSdS)NTF)rr r r r)r returncoderrris_alives   zBaseProcess.is_alivecCs|jS)N)r*)rrrrr/szBaseProcess.namecCs ||_dS)N)r*)rr/rrrr/scCs|jjddS)NrF)rget)rrrrrszBaseProcess.daemoncCs||jd<dS)Nr)r)rZdaemonicrrrrscCs |jdS)Nauthkey)r)rrrrr>szBaseProcess.authkeycCst||jd<dS)Nr>)AuthenticationStringr)rr>rrrr>scCs|jdkr|jS|jjS)N)r r )rrrrexitcodes zBaseProcess.exitcodecCs"|tkrtjS|jo|jjSdS)N)rrr r pid)rrrridentszBaseProcess.identc Cs(y|jStk r"tdYnXdS)Nzprocess not started)r6AttributeError ValueError)rrrrr5szBaseProcess.sentinelcCs|tkrd}n>|jtjkr"d}n*|jdkr2d}n|jjdk rH|j}nd}t|tkrv|dkrfd}ndt j ||}dt|j |j ||j rdpd fS) NZstartedunknowninitialrZstoppedz stopped[%s]z<%s(%s, %s%s)>z daemon)rr!rr r r r@r'int_exitcode_to_namer=r(r*r)rZstatusrrr__repr__s  zBaseProcess.__repr__c CsJddlm}m}zy||jdk r,|j|jtjdata |j t }|a z|j j |jWd~X|jdz|jd}Wd|jXWntk r}zL|jsd}n:t|jdtr|jd}ntjjt|jddd}WYdd}~Xn2d}ddl}tjjd|j|jYnXWd|jd||jX|S)N)utilcontextz child process calling self.run()r z Process %s: z process exiting with exitcode %d)rGrLrMZ _start_methodZ_force_start_method itertoolsr2rsetr Z _close_stdinrZ_finalizer_registryclearZ_run_after_forkersinfor4Z_exit_function SystemExitr0 isinstancerHsysstderrwriter tracebackr/ print_excZ_flush_std_streams)rrLrMZ old_processr@erXrrr _bootstrapsB        zBaseProcess._bootstrap)N)r( __module__ __qualname__rr3r4r7r8r)r<propertyr/setterrr>r@rBrAr5rJr[rrrrr>s(       c@seZdZddZdS)r?cCs,ddlm}|dkrtdtt|ffS)NrK)get_spawning_popenzJPickling an AuthenticationString object is disallowed for security reasons)rMr` TypeErrorr?bytes)rr`rrr __reduce__s   zAuthenticationString.__reduce__N)r(r\r]rcrrrrr?sr?c@seZdZddZdS) _MainProcesscCs2f|_d|_d|_d|_ttjddd|_dS)NZ MainProcess z/mp)r>Z semprefix)rr*r!r r?rurandomr)rrrrr3-s  z_MainProcess.__init__N)r(r\r]r3rrrrrd+srdrKZSIG_) __all__rrUsignalrO _weakrefsetrpathabspathgetcwdZ ORIGINAL_DIROSErrorrrr objectrrbr?rdrr2rrPr rIr __dict__itemsr/Zsignumr+rrrr s2     ` process.cpython-36.pyc000064400000017715147204630710010667 0ustar003 \# @sdddgZddlZddlZddlZddlZddlmZyejjej Z Wne k rbdZ YnXddZ ddZ dd ZGd ddeZGd d d eZGd ddeZeaejdaea[iZxSsz'BaseProcess.__init__..)AssertionErrornext_process_counterr _identity_configcopyosgetpid _parent_pidr _targettuple_argsdict_kwargstype__name__join_namer _danglingadd)rgrouptargetnameargskwargsrcountrrr__init__Gs    zBaseProcess.__init__cCs|jr|j|j|jdS)zQ Method to be run in sub-process; can be overridden in sub-class N)r#r%r')rrrrrunXszBaseProcess.runcCst|jdkstd|jtjks(tdtjjd s>tdt|j ||_|jj |_ |` |` |`tj|dS)z% Start child process Nzcannot start a process twicez:can only start a process object created by current processrz3daemonic processes are not allowed to have children)r rr"r r!rrgetr rsentinel _sentinelr#r%r'r r-)rrrrstart_s   zBaseProcess.startcCs|jjdS)zT Terminate process; sends SIGTERM signal or uses TerminateProcess() N)r terminate)rrrrr:pszBaseProcess.terminatecCsJ|jtjkstd|jdk s(td|jj|}|dk rFtj|dS)z5 Wait until child process terminates zcan only join a child processNzcan only join a started process)r"r r!rr waitr r)rZtimeoutresrrrr*vs  zBaseProcess.joincCsX|tkr dS|jtjks"td|jdkr0dS|jj}|dkrFdStj|dSdS)z1 Return whether process is alive Tzcan only test a child processNF) rr"r r!rr r r r)r returncoderrris_alives   zBaseProcess.is_alivecCs|jS)N)r+)rrrrr0szBaseProcess.namecCst|tstd||_dS)Nzname must be a string) isinstancerrr+)rr0rrrr0scCs|jjddS)z4 Return whether process is a daemon rF)rr6)rrrrrszBaseProcess.daemoncCs |jdkstd||jd<dS)z1 Set whether process is a daemon Nzprocess has already startedr)r rr)rZdaemonicrrrrscCs |jdS)Nauthkey)r)rrrrr@szBaseProcess.authkeycCst||jd<dS)z2 Set authorization key of process r@N)AuthenticationStringr)rr@rrrr@scCs|jdkr|jS|jjS)zM Return exit code of process or `None` if it has yet to stop N)r r )rrrrexitcodes zBaseProcess.exitcodecCs"|tkrtjS|jo|jjSdS)zU Return identifier (PID) of process or `None` if it has yet to start N)rr r!r pid)rrrridentszBaseProcess.identc Cs(y|jStk r"tdYnXdS)z{ Return a file descriptor (Unix) or handle (Windows) suitable for waiting for process termination. zprocess not startedN)r8AttributeError ValueError)rrrrr7szBaseProcess.sentinelcCs|tkrd}n>|jtjkr"d}n*|jdkr2d}n|jjdk rH|j}nd}t|tkrv|dkrfd}ndt j ||}dt|j |j ||j rdpd fS) NZstartedunknowninitialrZstoppedz stopped[%s]z<%s(%s, %s%s)>z daemon)rr"r r!r r rBr(int_exitcode_to_namer6r)r+r)rZstatusrrr__repr__s  zBaseProcess.__repr__c CsJddlm}m}zy||jdk r,|j|jtjdata |j t }|a z|j j |jWd~X|jdz|jd}Wd|jXWntk r}zL|jsd}n:t|jdtr|jd}ntjjt|jddd}WYdd}~Xn2d}ddl}tjjd|j|jYnXWd|jd||jX|S)N)utilcontextz child process calling self.run()r z Process %s: z process exiting with exitcode %d)rIrNrOZ _start_methodZ_force_start_method itertoolsr3rsetr Z _close_stdinrZ_finalizer_registryclearZ_run_after_forkersinfor5Z_exit_function SystemExitr1r?rJsysstderrwriter tracebackr0 print_excZ_flush_std_streams)rrNrOZ old_processrBerYrrr _bootstrapsB        zBaseProcess._bootstrap)N)r) __module__ __qualname____doc__rr4r5r9r:r*r>propertyr0setterrr@rBrDrCr7rLr\rrrrr>s*       c@seZdZddZdS)rAcCs,ddlm}|dkrtdtt|ffS)NrM)get_spawning_popenzJPickling an AuthenticationString object is disallowed for security reasons)rOrb TypeErrorrAbytes)rrbrrr __reduce__s   zAuthenticationString.__reduce__N)r)r]r^rerrrrrAsrAc@seZdZddZdS) _MainProcesscCs2f|_d|_d|_d|_ttjddd|_dS)NZ MainProcess z/mp)r@Z semprefix)rr+r"r rAr urandomr)rrrrr4-s  z_MainProcess.__init__N)r)r]r^r4rrrrrf+srfrMZSIG_) __all__r rVsignalrQ _weakrefsetrpathabspathgetcwdZ ORIGINAL_DIROSErrorrrr objectrrdrArfrr3rrRr rKr __dict__itemsr0Zsignumr,rrrr s2     ` queues.cpython-36.opt-1.pyc000064400000021242147204630710011445 0ustar003 \ *@sdddgZddlZddlZddlZddlZddlZddlZddlZddlm Z m Z ddl Z ddl m Z ddl mZejjZdd lmZmZmZmZmZGd ddeZeZGd ddeZGd ddeZdS) Queue SimpleQueue JoinableQueueN)EmptyFull) connection)context)debuginfoFinalizeregister_after_fork is_exitingc@seZdZd(ddZddZddZdd Zd)d d Zd*ddZddZ ddZ ddZ ddZ ddZ ddZddZddZd d!Zed"d#Zed$d%Zed&d'Zd S)+rrcCs|dkrddlm}||_tjdd\|_|_|j|_t j |_ t j dkrTd|_n |j|_|j||_d|_|jt j dkrt|tjdS)Nrr) SEM_VALUE_MAXF)duplexwin32)Z synchronizer_maxsizerPipe_reader_writerLock_rlockosgetpid_opidsysplatform_wlockZBoundedSemaphore_sem _ignore_epipe _after_forkr r)selfmaxsizectxr$./usr/lib64/python3.6/multiprocessing/queues.py__init__$s       zQueue.__init__cCs.tj||j|j|j|j|j|j|j|j fS)N) r assert_spawningrrrrrrrr)r!r$r$r% __getstate__9s zQueue.__getstate__c Cs0|\|_|_|_|_|_|_|_|_|jdS)N) rrrrrrrrr )r!stater$r$r% __setstate__>s$zQueue.__setstate__cCsbtdtjtj|_tj|_d|_d|_ d|_ d|_ d|_ |j j|_|jj|_|jj|_dS)NzQueue._after_fork()F)r threading Conditionr _notempty collectionsdeque_buffer_thread _jointhread_joincancelled_closed_closer send_bytes _send_bytesr recv_bytes _recv_bytespoll_poll)r!r$r$r%r Cs   zQueue._after_forkTNc CsP|jj||st|j.|jdkr,|j|jj||jjWdQRXdS)N) racquirerr-r1 _start_threadr0appendnotify)r!objblocktimeoutr$r$r%putPs  z Queue.putc Cs|r2|dkr2|j|j}WdQRX|jjnr|rBtj|}|jj||sTtzB|rv|tj}|j|stn |jst|j}|jjWd|jjXt j |S)N) rr9rreleasetimeZ monotonicr<rr;_ForkingPicklerloads)r!rArBresZdeadliner$r$r%get[s&      z Queue.getcCs|j|jjjS)N)rr_semlockZ _get_value)r!r$r$r%qsizessz Queue.qsizecCs |j S)N)r;)r!r$r$r%emptywsz Queue.emptycCs |jjjS)N)rrJ_is_zero)r!r$r$r%fullzsz Queue.fullcCs |jdS)NF)rI)r!r$r$r% get_nowait}szQueue.get_nowaitcCs |j|dS)NF)rC)r!r@r$r$r% put_nowaitszQueue.put_nowaitc Cs2d|_z|jjWd|j}|r,d|_|XdS)NT)r4rcloser5)r!rQr$r$r%rQsz Queue.closecCstd|jr|jdS)NzQueue.join_thread())r r2)r!r$r$r% join_threadszQueue.join_threadc Cs6tdd|_y|jjWntk r0YnXdS)NzQueue.cancel_join_thread()T)r r3r2ZcancelAttributeError)r!r$r$r%cancel_join_threads zQueue.cancel_join_threadcCstd|jjtjtj|j|j|j|j |j j |j fdd|_ d|j _td|j jtd|jst|j tjtj|j gd d|_t|tj|j|jgd d|_dS) NzQueue._start_thread()ZQueueFeederThread)targetargsnameTzdoing self._thread.start()z... done self._thread.start())Z exitpriority )r r0clearr+ZThreadr_feedr-r7rrrQrr1Zdaemonstartr3r _finalize_joinweakrefrefr2_finalize_closer5)r!r$r$r%r=s(       zQueue._start_threadcCs4td|}|dk r(|jtdntddS)Nzjoining queue threadz... queue thread joinedz... queue thread already dead)r join)ZtwrZthreadr$r$r%r^s  zQueue._finalize_joinc Cs.td||jt|jWdQRXdS)Nztelling queue thread to quit)r r> _sentinelr?)buffernotemptyr$r$r%ras zQueue._finalize_closecCsPtd|j}|j}|j}|j} t} tjdkr<|j} |j} nd} xy|z|sX|Wd|Xybx\| } | | krtd|dStj | } | dkr|| qh| z || Wd| XqhWWnt k rYnXWqDt k rF}zJ|rt |ddt jkrdStr&td|dSddl}|jWYdd}~XqDXqDWdS)Nz$starting thread to feed data to piperz%feeder thread got sentinel -- exitingerrnorzerror in queue thread: %s)r r<rDwaitpopleftrcrrrFdumps IndexError ExceptiongetattrrfZEPIPErr traceback print_exc)rdrer6Z writelockrQZ ignore_epipeZnacquireZnreleaseZnwaitZbpopleftsentinelZwacquireZwreleaser@ermr$r$r%r\sR       z Queue._feed)r)TN)TN)__name__ __module__ __qualname__r&r(r*r rCrIrKrLrNrOrPrQrRrTr= staticmethodr^rar\r$r$r$r%r"s$    c@s@eZdZdddZddZddZdd d Zd d ZddZd S)rrcCs*tj|||d|jd|_|j|_dS)N)r#r)rr&Z Semaphore_unfinished_tasksr,_cond)r!r"r#r$r$r%r&s zJoinableQueue.__init__cCstj||j|jfS)N)rr(rvru)r!r$r$r%r(szJoinableQueue.__getstate__cCs,tj||dd|dd\|_|_dS)Nrx)rr*rvru)r!r)r$r$r%r*szJoinableQueue.__setstate__TNcCsl|jj||st|jJ|j8|jdkr4|j|jj||j j |jj WdQRXWdQRXdS)N) rr<rr-rvr1r=r0r>rurDr?)r!r@rArBr$r$r%rCs   zJoinableQueue.putc Cs@|j0|jjdstd|jjjr2|jjWdQRXdS)NFz!task_done() called too many times)rvrur< ValueErrorrJrMZ notify_all)r!r$r$r% task_done's   zJoinableQueue.task_donec Cs,|j|jjjs|jjWdQRXdS)N)rvrurJrMrg)r!r$r$r%rb.s zJoinableQueue.join)r)TN) rqrrrsr&r(r*rCrzrbr$r$r$r%r s   c@s<eZdZddZddZddZddZd d Zd d Zd S)rcCsHtjdd\|_|_|j|_|jj|_tj dkr:d|_ n |j|_ dS)NF)rr) rrrrrrr:r;rrr)r!r#r$r$r%r&9s    zSimpleQueue.__init__cCs |j S)N)r;)r!r$r$r%rLBszSimpleQueue.emptycCstj||j|j|j|jfS)N)r r'rrrr)r!r$r$r%r(Es zSimpleQueue.__getstate__cCs"|\|_|_|_|_|jj|_dS)N)rrrrr:r;)r!r)r$r$r%r*IszSimpleQueue.__setstate__c Cs&|j|jj}WdQRXtj|S)N)rrr8rFrG)r!rHr$r$r%rIMszSimpleQueue.getc CsDtj|}|jdkr"|jj|n|j|jj|WdQRXdS)N)rFrirrr6)r!r@r$r$r%rCSs   zSimpleQueue.putN) rqrrrsr&rLr(r*rIrCr$r$r$r%r7s  )__all__rrr+r.rEr_rfZqueuerrZ_multiprocessingrr Z reductionZForkingPicklerrFutilr r r r robjectrrcrrr$r$r$r% s$   b *queues.cpython-36.opt-2.pyc000064400000021242147204630710011446 0ustar003 \ *@sdddgZddlZddlZddlZddlZddlZddlZddlZddlm Z m Z ddl Z ddl m Z ddl mZejjZdd lmZmZmZmZmZGd ddeZeZGd ddeZGd ddeZdS) Queue SimpleQueue JoinableQueueN)EmptyFull) connection)context)debuginfoFinalizeregister_after_fork is_exitingc@seZdZd(ddZddZddZdd Zd)d d Zd*ddZddZ ddZ ddZ ddZ ddZ ddZddZddZd d!Zed"d#Zed$d%Zed&d'Zd S)+rrcCs|dkrddlm}||_tjdd\|_|_|j|_t j |_ t j dkrTd|_n |j|_|j||_d|_|jt j dkrt|tjdS)Nrr) SEM_VALUE_MAXF)duplexwin32)Z synchronizer_maxsizerPipe_reader_writerLock_rlockosgetpid_opidsysplatform_wlockZBoundedSemaphore_sem _ignore_epipe _after_forkr r)selfmaxsizectxr$./usr/lib64/python3.6/multiprocessing/queues.py__init__$s       zQueue.__init__cCs.tj||j|j|j|j|j|j|j|j fS)N) r assert_spawningrrrrrrrr)r!r$r$r% __getstate__9s zQueue.__getstate__c Cs0|\|_|_|_|_|_|_|_|_|jdS)N) rrrrrrrrr )r!stater$r$r% __setstate__>s$zQueue.__setstate__cCsbtdtjtj|_tj|_d|_d|_ d|_ d|_ d|_ |j j|_|jj|_|jj|_dS)NzQueue._after_fork()F)r threading Conditionr _notempty collectionsdeque_buffer_thread _jointhread_joincancelled_closed_closer send_bytes _send_bytesr recv_bytes _recv_bytespoll_poll)r!r$r$r%r Cs   zQueue._after_forkTNc CsP|jj||st|j.|jdkr,|j|jj||jjWdQRXdS)N) racquirerr-r1 _start_threadr0appendnotify)r!objblocktimeoutr$r$r%putPs  z Queue.putc Cs|r2|dkr2|j|j}WdQRX|jjnr|rBtj|}|jj||sTtzB|rv|tj}|j|stn |jst|j}|jjWd|jjXt j |S)N) rr9rreleasetimeZ monotonicr<rr;_ForkingPicklerloads)r!rArBresZdeadliner$r$r%get[s&      z Queue.getcCs|j|jjjS)N)rr_semlockZ _get_value)r!r$r$r%qsizessz Queue.qsizecCs |j S)N)r;)r!r$r$r%emptywsz Queue.emptycCs |jjjS)N)rrJ_is_zero)r!r$r$r%fullzsz Queue.fullcCs |jdS)NF)rI)r!r$r$r% get_nowait}szQueue.get_nowaitcCs |j|dS)NF)rC)r!r@r$r$r% put_nowaitszQueue.put_nowaitc Cs2d|_z|jjWd|j}|r,d|_|XdS)NT)r4rcloser5)r!rQr$r$r%rQsz Queue.closecCstd|jr|jdS)NzQueue.join_thread())r r2)r!r$r$r% join_threadszQueue.join_threadc Cs6tdd|_y|jjWntk r0YnXdS)NzQueue.cancel_join_thread()T)r r3r2ZcancelAttributeError)r!r$r$r%cancel_join_threads zQueue.cancel_join_threadcCstd|jjtjtj|j|j|j|j |j j |j fdd|_ d|j _td|j jtd|jst|j tjtj|j gd d|_t|tj|j|jgd d|_dS) NzQueue._start_thread()ZQueueFeederThread)targetargsnameTzdoing self._thread.start()z... done self._thread.start())Z exitpriority )r r0clearr+ZThreadr_feedr-r7rrrQrr1Zdaemonstartr3r _finalize_joinweakrefrefr2_finalize_closer5)r!r$r$r%r=s(       zQueue._start_threadcCs4td|}|dk r(|jtdntddS)Nzjoining queue threadz... queue thread joinedz... queue thread already dead)r join)ZtwrZthreadr$r$r%r^s  zQueue._finalize_joinc Cs.td||jt|jWdQRXdS)Nztelling queue thread to quit)r r> _sentinelr?)buffernotemptyr$r$r%ras zQueue._finalize_closecCsPtd|j}|j}|j}|j} t} tjdkr<|j} |j} nd} xy|z|sX|Wd|Xybx\| } | | krtd|dStj | } | dkr|| qh| z || Wd| XqhWWnt k rYnXWqDt k rF}zJ|rt |ddt jkrdStr&td|dSddl}|jWYdd}~XqDXqDWdS)Nz$starting thread to feed data to piperz%feeder thread got sentinel -- exitingerrnorzerror in queue thread: %s)r r<rDwaitpopleftrcrrrFdumps IndexError ExceptiongetattrrfZEPIPErr traceback print_exc)rdrer6Z writelockrQZ ignore_epipeZnacquireZnreleaseZnwaitZbpopleftsentinelZwacquireZwreleaser@ermr$r$r%r\sR       z Queue._feed)r)TN)TN)__name__ __module__ __qualname__r&r(r*r rCrIrKrLrNrOrPrQrRrTr= staticmethodr^rar\r$r$r$r%r"s$    c@s@eZdZdddZddZddZdd d Zd d ZddZd S)rrcCs*tj|||d|jd|_|j|_dS)N)r#r)rr&Z Semaphore_unfinished_tasksr,_cond)r!r"r#r$r$r%r&s zJoinableQueue.__init__cCstj||j|jfS)N)rr(rvru)r!r$r$r%r(szJoinableQueue.__getstate__cCs,tj||dd|dd\|_|_dS)Nrx)rr*rvru)r!r)r$r$r%r*szJoinableQueue.__setstate__TNcCsl|jj||st|jJ|j8|jdkr4|j|jj||j j |jj WdQRXWdQRXdS)N) rr<rr-rvr1r=r0r>rurDr?)r!r@rArBr$r$r%rCs   zJoinableQueue.putc Cs@|j0|jjdstd|jjjr2|jjWdQRXdS)NFz!task_done() called too many times)rvrur< ValueErrorrJrMZ notify_all)r!r$r$r% task_done's   zJoinableQueue.task_donec Cs,|j|jjjs|jjWdQRXdS)N)rvrurJrMrg)r!r$r$r%rb.s zJoinableQueue.join)r)TN) rqrrrsr&r(r*rCrzrbr$r$r$r%r s   c@s<eZdZddZddZddZddZd d Zd d Zd S)rcCsHtjdd\|_|_|j|_|jj|_tj dkr:d|_ n |j|_ dS)NF)rr) rrrrrrr:r;rrr)r!r#r$r$r%r&9s    zSimpleQueue.__init__cCs |j S)N)r;)r!r$r$r%rLBszSimpleQueue.emptycCstj||j|j|j|jfS)N)r r'rrrr)r!r$r$r%r(Es zSimpleQueue.__getstate__cCs"|\|_|_|_|_|jj|_dS)N)rrrrr:r;)r!r)r$r$r%r*IszSimpleQueue.__setstate__c Cs&|j|jj}WdQRXtj|S)N)rrr8rFrG)r!rHr$r$r%rIMszSimpleQueue.getc CsDtj|}|jdkr"|jj|n|j|jj|WdQRXdS)N)rFrirrr6)r!r@r$r$r%rCSs   zSimpleQueue.putN) rqrrrsr&rLr(r*rIrCr$r$r$r%r7s  )__all__rrr+r.rEr_rfZqueuerrZ_multiprocessingrr Z reductionZForkingPicklerrFutilr r r r robjectrrcrrr$r$r$r% s$   b *reduction.cpython-36.opt-1.pyc000064400000017350147204630710012137 0ustar003 \ $@sddlmZmZddlZddlZddlZddlZddlZddlZddl Z ddl m Z ddddd gZ e j d kpeed oeed oeejd ZGdddejZejZd5dd Ze j d kre dddg7Z ddlZd6ddZddZddZddZGdddeZnHe dddg7Z ddlZe j dkZddZddZddZd dZd!dZd"d#Z Gd$d%d%Z!ee"e!j#e d&d'Z$ee"e%j&e$ee"e'j(e$d(d)Z)d*d+Z*eej+e)e j d krd,d-Z,d.d/Z-eeje,nd0d-Z,d1d/Z-eeje,Gd2d3d3ed4Z.dS)7)ABCMetaabstractmethodN)context send_handle recv_handleForkingPicklerregisterdumpwin32ZCMSG_LEN SCM_RIGHTSsendmsgcsJeZdZdZiZejZfddZe ddZ e d ddZ e j Z ZS) rz)Pickler subclass used by multiprocessing.cs*tj||jj|_|jj|jdS)N)super__init___copyreg_dispatch_tablecopydispatch_tableupdate_extra_reducers)selfargs) __class__1/usr/lib64/python3.6/multiprocessing/reduction.pyr&s  zForkingPickler.__init__cCs||j|<dS)z&Register a reduce function for a type.N)r)clstypereducerrrr +szForkingPickler.registerNcCs tj}|||j||jS)N)ioBytesIOr getbuffer)robjprotocolZbufrrrdumps0szForkingPickler.dumps)N)__name__ __module__ __qualname____doc__rcopyregrrr classmethodr r"pickleloads __classcell__rr)rrr!s   cCst||j|dS)z3Replacement for pickle.dump() using ForkingPickler.N)rr )r filer!rrrr :s DupHandle duplicate steal_handleFcCs*|dkrtj}tjtj||d|tjS)zr?r@r0r5r6r2r1rAr7r8)rrErrrr=us  zDupHandle.detach)N)r#r$r%r&rr=rrrrr-ds DupFdsendfdsrecvfdsdarwincCsVtjd|}tt|dg}|j|gtjtj|fgtrR|jddkrRt ddS)z,Send an array of fds over an AF_UNIX socket.irAz%did not receive acknowledgement of fdN) arraybyteslenr socket SOL_SOCKETr ACKNOWLEDGEr< RuntimeError)sockZfdsmsgrrrrGs  c Cstjd}|j|}|jdtj|\}}}}| r>| r>tyxtrN|jdt|dkrjt dt||d\}} } |tj kr| tj krt| |jdkrt |j | t|SWnt tfk rYnXt ddS)z/Receive an array of fds over an AF_UNIX socket.rJrrLzreceived %d items of ancdatarzInvalid data receivedN)rMitemsizeZrecvmsgrPZ CMSG_SPACEEOFErrorrRr9rOrSrQr ValueErrorZ frombyteslist IndexError) rTsizeaZ bytes_sizerUZancdataflagsZaddrZ cmsg_levelZ cmsg_typeZ cmsg_datarrrrHs*          c Cs2tj|jtjtj}t||gWdQRXdS)z&Send a handle over a local connection.N)rPfromfdfilenoAF_UNIX SOCK_STREAMrG)r:r4r;srrrrsc Cs0tj|jtjtj}t|ddSQRXdS)z)Receive a handle over a local connection.rrN)rPr^r_r`rarH)r:rbrrrrscCsFtj}|dk r |j|j|Str:ddlm}|j|StddS)zReturn a wrapper for an fd.Nr)resource_sharerz&SCM_RIGHTS appears not to be available)rZget_spawning_popenrFZduplicate_for_childHAVE_SEND_HANDLErcrX)fdZ popen_objrcrrrrFs  cCs2|jdkrt|j|jjffSt|j|jjffSdS)N)__self__getattrr__func__r#)mrrr_reduce_methods rkc@seZdZddZdS)_CcCsdS)Nr)rrrrfsz_C.fN)r#r$r%rmrrrrrlsrlcCst|j|jffS)N)rh __objclass__r#)rjrrr_reduce_method_descriptorsrocCst|j|j|jpiffS)N)_rebuild_partialfuncrkeywords)prrr_reduce_partialsrtcCstj|f||S)N) functoolspartial)rqrrrrrrrpsrpcCsddlm}t||ffS)Nr) DupSocket)rcrw_rebuild_socket)rbrwrrr_reduce_sockets rycCs|jS)N)r=)ZdsrrrrxsrxcCs"t|j}t||j|j|jffS)N)rFr_rxfamilyrproto)rbdfrrrrys cCs|j}tj||||dS)N)r_)r=rP)r|rzrr{rfrrrrxsc@sdeZdZdZeZeZeZeZeZe j dkr8e Z e Z e Z n eZeZeZeZeZeZeZeZddZdS)AbstractReducerzAbstract base class for use in implementing a Reduction class suitable for use in replacing the standard reduction mechanism used in multiprocessing.r cGsNtttjttttjttttj ttt j t tt j tdS)N)r rrlrmrkrYappendroint__add__rurvrtrPry)rrrrrr s  zAbstractReducer.__init__N)r#r$r%r&rr r rrsysplatformr/r.r-rGrHrFrkrorpryrxrrrrrr}s& r}) metaclass)N)NF)/abcrrr'rurr>r)rPrrer__all__rhasattrrdZPicklerrr r r0r.r/rrobjectr-rMrRrGrHrFrkrlrrmrorYr~rrrtrprvryrxr}rrrr sb         #    reduction.cpython-36.opt-2.pyc000064400000015662147204630710012144 0ustar003 \ $@sddlmZmZddlZddlZddlZddlZddlZddlZddl Z ddl m Z ddddd gZ e j d kpeed oeed oeejd ZGdddejZejZd5dd Ze j d kre dddg7Z ddlZd6ddZddZddZddZGdddeZnHe dddg7Z ddlZe j dkZddZddZddZd dZd!dZd"d#Z Gd$d%d%Z!ee"e!j#e d&d'Z$ee"e%j&e$ee"e'j(e$d(d)Z)d*d+Z*eej+e)e j d krd,d-Z,d.d/Z-eeje,nd0d-Z,d1d/Z-eeje,Gd2d3d3ed4Z.dS)7)ABCMetaabstractmethodN)context send_handle recv_handleForkingPicklerregisterdumpwin32ZCMSG_LEN SCM_RIGHTSsendmsgcsFeZdZiZejZfddZeddZ edddZ e j Z Z S) rcs*tj||jj|_|jj|jdS)N)super__init___copyreg_dispatch_tablecopydispatch_tableupdate_extra_reducers)selfargs) __class__1/usr/lib64/python3.6/multiprocessing/reduction.pyr&s  zForkingPickler.__init__cCs||j|<dS)N)r)clstypereducerrrr +szForkingPickler.registerNcCs tj}|||j||jS)N)ioBytesIOr getbuffer)robjprotocolZbufrrrdumps0szForkingPickler.dumps)N)__name__ __module__ __qualname__rcopyregrrr classmethodr r"pickleloads __classcell__rr)rrr!s   cCst||j|dS)N)rr )r filer!rrrr :s DupHandle duplicate steal_handleFcCs*|dkrtj}tjtj||d|tjS)Nr)_winapiGetCurrentProcessDuplicateHandleDUPLICATE_SAME_ACCESS)handleZtarget_processZ inheritablerrrr-Gs  cCsBtjtjd|}z tj||tjddtjtjBStj|XdS)NFr)r/ OpenProcessPROCESS_DUP_HANDLEr1r0r2DUPLICATE_CLOSE_SOURCE CloseHandle)Z source_pidr3Zsource_process_handlerrrr.Os  cCst|tj|}|j|dS)N)r,r/r2send)connr3destination_pidZdhrrrr[scCs |jjS)N)recvdetach)r9rrrr`sc@seZdZdddZddZdS)r,Nc Cs\|dkrtj}tjtjd|}ztjtj|||dd|_Wdtj|X||_ ||_ dS)NFr) osgetpidr/r4r5r1r0_handler7_access_pid)rr3accesspidprocrrrrfs zDupHandle.__init__c CsV|jtjkr|jStjtjd|j}ztj||jtj|j dtj Stj |XdS)NF) rAr=r>r?r/r4r5r1r0r@r6r7)rrDrrrr<us  zDupHandle.detach)N)r#r$r%rr<rrrrr,ds DupFdsendfdsrecvfdsdarwincCsVtjd|}tt|dg}|j|gtjtj|fgtrR|jddkrRt ddS)NirAz%did not receive acknowledgement of fd) arraybyteslenr socket SOL_SOCKETr ACKNOWLEDGEr; RuntimeError)sockZfdsmsgrrrrFs  c Cstjd}|j|}|jdtj|\}}}}| r>| r>tyxtrN|jdt|dkrjt dt||d\}} } |tj kr| tj krt| |jdkrt |j | t|SWnt tfk rYnXt ddS)NrIrrKzreceived %d items of ancdatarzInvalid data received)rLitemsizeZrecvmsgrOZ CMSG_SPACEEOFErrorrQr8rNrRrPr ValueErrorZ frombyteslist IndexError) rSsizeaZ bytes_sizerTZancdataflagsZaddrZ cmsg_levelZ cmsg_typeZ cmsg_datarrrrGs*          c Cs2tj|jtjtj}t||gWdQRXdS)N)rOfromfdfilenoAF_UNIX SOCK_STREAMrF)r9r3r:srrrrsc Cs0tj|jtjtj}t|ddSQRXdS)Nrr)rOr]r^r_r`rG)r9rarrrrscCsFtj}|dk r |j|j|Str:ddlm}|j|StddS)Nr)resource_sharerz&SCM_RIGHTS appears not to be available)rZget_spawning_popenrEZduplicate_for_childHAVE_SEND_HANDLErbrW)fdZ popen_objrbrrrrEs  cCs2|jdkrt|j|jjffSt|j|jjffSdS)N)__self__getattrr__func__r#)mrrr_reduce_methods rjc@seZdZddZdS)_CcCsdS)Nr)rrrrfsz_C.fN)r#r$r%rlrrrrrksrkcCst|j|jffS)N)rg __objclass__r#)rirrr_reduce_method_descriptorsrncCst|j|j|jpiffS)N)_rebuild_partialfuncrkeywords)prrr_reduce_partialsrscCstj|f||S)N) functoolspartial)rprrqrrrrosrocCsddlm}t||ffS)Nr) DupSocket)rbrv_rebuild_socket)rarvrrr_reduce_sockets rxcCs|jS)N)r<)ZdsrrrrwsrwcCs"t|j}t||j|j|jffS)N)rEr^rwfamilyrproto)radfrrrrxs cCs|j}tj||||dS)N)r^)r<rO)r{ryrrzrerrrrwsc@s`eZdZeZeZeZeZeZej dkr4e Z e Z e Z n e Z eZeZeZeZeZeZeZddZdS)AbstractReducerr cGsNtttjttttjttttj ttt j t tt j tdS)N)r rrkrlrjrXappendrnint__add__rtrursrOrx)rrrrrr s  zAbstractReducer.__init__N)r#r$r%rr r rrsysplatformr.r-r,rFrGrErjrnrorxrwrrrrrr|s$ r|) metaclass)N)NF)/abcrrr&rtrr=r(rOrrdr__all__rhasattrrcZPicklerrr r r/r-r.rrobjectr,rLrQrFrGrErjrkrrlrnrXr}r~rrsrorurxrwr|rrrr sb         #    reduction.cpython-36.pyc000064400000017427147204630710011205 0ustar003 \ $@sddlmZmZddlZddlZddlZddlZddlZddlZddl Z ddl m Z ddddd gZ e j d kpeed oeed oeejd ZGdddejZejZd5dd Ze j d kre dddg7Z ddlZd6ddZddZddZddZGdddeZnHe dddg7Z ddlZe j dkZddZddZddZd dZd!dZd"d#Z Gd$d%d%Z!ee"e!j#e d&d'Z$ee"e%j&e$ee"e'j(e$d(d)Z)d*d+Z*eej+e)e j d krd,d-Z,d.d/Z-eeje,nd0d-Z,d1d/Z-eeje,Gd2d3d3ed4Z.dS)7)ABCMetaabstractmethodN)context send_handle recv_handleForkingPicklerregisterdumpwin32ZCMSG_LEN SCM_RIGHTSsendmsgcsJeZdZdZiZejZfddZe ddZ e d ddZ e j Z ZS) rz)Pickler subclass used by multiprocessing.cs*tj||jj|_|jj|jdS)N)super__init___copyreg_dispatch_tablecopydispatch_tableupdate_extra_reducers)selfargs) __class__1/usr/lib64/python3.6/multiprocessing/reduction.pyr&s  zForkingPickler.__init__cCs||j|<dS)z&Register a reduce function for a type.N)r)clstypereducerrrr +szForkingPickler.registerNcCs tj}|||j||jS)N)ioBytesIOr getbuffer)robjprotocolZbufrrrdumps0szForkingPickler.dumps)N)__name__ __module__ __qualname____doc__rcopyregrrr classmethodr r"pickleloads __classcell__rr)rrr!s   cCst||j|dS)z3Replacement for pickle.dump() using ForkingPickler.N)rr )r filer!rrrr :s DupHandle duplicate steal_handleFcCs*|dkrtj}tjtj||d|tjS)zr?r@r0r5r6r2r1rAr7r8)rrErrrr=us  zDupHandle.detach)N)r#r$r%r&rr=rrrrr-ds DupFdsendfdsrecvfdsdarwincCsVtjd|}tt|dg}|j|gtjtj|fgtrR|jddkrRt ddS)z,Send an array of fds over an AF_UNIX socket.irAz%did not receive acknowledgement of fdN) arraybyteslenr socket SOL_SOCKETr ACKNOWLEDGEr< RuntimeError)sockZfdsmsgrrrrGs  c Cstjd}|j|}|jdtj|\}}}}| r>| r>tytrN|jdt|dkrjt dt||d\}} } |tj kr| tj krt| |jdkrt |j | t|d|dkstt|SWnt tfk rYnXt ddS) z/Receive an array of fds over an AF_UNIX socket.rJrrLzreceived %d items of ancdatarrKzInvalid data receivedN)rMitemsizeZrecvmsgrPZ CMSG_SPACEEOFErrorrRr9rOrSrQr ValueErrorZ frombytesAssertionErrorlist IndexError) rTsizeaZ bytes_sizerUZancdataflagsZaddrZ cmsg_levelZ cmsg_typeZ cmsg_datarrrrHs,          c Cs2tj|jtjtj}t||gWdQRXdS)z&Send a handle over a local connection.N)rPfromfdfilenoAF_UNIX SOCK_STREAMrG)r:r4r;srrrrsc Cs0tj|jtjtj}t|ddSQRXdS)z)Receive a handle over a local connection.rrN)rPr_r`rarbrH)r:rcrrrrscCsFtj}|dk r |j|j|Str:ddlm}|j|StddS)zReturn a wrapper for an fd.Nr)resource_sharerz&SCM_RIGHTS appears not to be available)rZget_spawning_popenrFZduplicate_for_childHAVE_SEND_HANDLErdrX)fdZ popen_objrdrrrrFs  cCs2|jdkrt|j|jjffSt|j|jjffSdS)N)__self__getattrr__func__r#)mrrr_reduce_methods rlc@seZdZddZdS)_CcCsdS)Nr)rrrrfsz_C.fN)r#r$r%rnrrrrrmsrmcCst|j|jffS)N)ri __objclass__r#)rkrrr_reduce_method_descriptorsrpcCst|j|j|jpiffS)N)_rebuild_partialfuncrkeywords)prrr_reduce_partialsrucCstj|f||S)N) functoolspartial)rrrrsrrrrqsrqcCsddlm}t||ffS)Nr) DupSocket)rdrx_rebuild_socket)rcrxrrr_reduce_sockets rzcCs|jS)N)r=)ZdsrrrrysrycCs"t|j}t||j|j|jffS)N)rFr`ryfamilyrproto)rcdfrrrrzs cCs|j}tj||||dS)N)r`)r=rP)r}r{rr|rgrrrrysc@sdeZdZdZeZeZeZeZeZe j dkr8e Z e Z e Z n eZeZeZeZeZeZeZeZddZdS)AbstractReducerzAbstract base class for use in implementing a Reduction class suitable for use in replacing the standard reduction mechanism used in multiprocessing.r cGsNtttjttttjttttj ttt j t tt j tdS)N)r rrmrnrlrZappendrpint__add__rvrwrurPrz)rrrrrr s  zAbstractReducer.__init__N)r#r$r%r&rr r rrsysplatformr/r.r-rGrHrFrlrprqrzryrrrrrr~s& r~) metaclass)N)NF)/abcrrr'rvrr>r)rPrrfr__all__rhasattrreZPicklerrr r r0r.r/rrobjectr-rMrRrGrHrFrlrmrrnrprZrrrrurqrwrzryr~rrrr sb         #    resource_sharer.cpython-36.opt-1.pyc000064400000012004147204630710013325 0ustar003 \@sddlZddlZddlZddlZddlZddlmZddlmZddlm Z dgZ ej dkrxe dg7Z Gd dde Z ne d g7Z Gd d d e ZGd d d e ZeZejZdS)N)process) reduction)utilstopZwin32 DupSocketc@s eZdZdZddZddZdS)rzPicklable wrapper for a socket.cs(|jfdd}tj|j|_dS)Ncsj|}|j|dS)N)shareZ send_bytes)connpidr)new_sock7/usr/lib64/python3.6/multiprocessing/resource_sharer.pysends z DupSocket.__init__..send)dup_resource_sharerregisterclose_id)selfZsockrr )r r __init__s zDupSocket.__init__c Cs*tj|j}|j}tj|SQRXdS)z1Get the socket. This should only be called once.N)rget_connectionrZ recv_bytessocketZ fromshare)rr rr r r detach$szDupSocket.detachN)__name__ __module__ __qualname____doc__rrr r r r rsDupFdc@s eZdZdZddZddZdS)rz-Wrapper for fd which can be used at any time.cs4tj|fdd}fdd}tj|||_dS)Ncstj||dS)N)rZ send_handle)r r )new_fdr r r1szDupFd.__init__..sendcstjdS)N)osrr )rr r r3szDupFd.__init__..close)rrrrr)rfdrrr )rr r/s   zDupFd.__init__c Cs"tj|j }tj|SQRXdS)z-Get the fd. This should only be called once.N)rrrrZ recv_handle)rr r r r r7sz DupFd.detachN)rrrrrrr r r r r-sc@sNeZdZdZddZddZeddZdd d Zd d Z d dZ ddZ dS)_ResourceSharerz-Manager for resouces using background thread.cCs@d|_i|_g|_tj|_d|_d|_d|_t j |t j dS)Nr) _key_cache _old_locks threadingLock_lock _listener_address_threadrZregister_after_forkr! _afterfork)rr r r r?s z_ResourceSharer.__init__c CsN|j>|jdkr|j|jd7_||f|j|j<|j|jfSQRXdS)z+Register resource, returning an identifier.Nr)r'r)_startr"r#)rrrr r r rIs  z_ResourceSharer.registercCs<ddlm}|\}}||tjjd}|j|tjf|S)z s       `resource_sharer.cpython-36.opt-2.pyc000064400000011130147204630710013325 0ustar003 \@sddlZddlZddlZddlZddlZddlmZddlmZddlm Z dgZ ej dkrxe dg7Z Gd dde Z ne d g7Z Gd d d e ZGd d d e ZeZejZdS)N)process) reduction)utilstopZwin32 DupSocketc@seZdZddZddZdS)rcs(|jfdd}tj|j|_dS)Ncsj|}|j|dS)N)shareZ send_bytes)connpidr)new_sock7/usr/lib64/python3.6/multiprocessing/resource_sharer.pysends z DupSocket.__init__..send)dup_resource_sharerregisterclose_id)selfZsockrr )r r __init__s zDupSocket.__init__c Cs*tj|j}|j}tj|SQRXdS)N)rget_connectionrZ recv_bytessocketZ fromshare)rr rr r r detach$szDupSocket.detachN)__name__ __module__ __qualname__rrr r r r rsDupFdc@seZdZddZddZdS)rcs4tj|fdd}fdd}tj|||_dS)Ncstj||dS)N)rZ send_handle)r r )new_fdr r r1szDupFd.__init__..sendcstjdS)N)osrr )rr r r3szDupFd.__init__..close)rrrrr)rfdrrr )rr r/s   zDupFd.__init__c Cs"tj|j }tj|SQRXdS)N)rrrrZ recv_handle)rr r r r r7sz DupFd.detachN)rrrrrr r r r r-sc@sJeZdZddZddZeddZddd Zd d Zd d Z ddZ dS)_ResourceSharercCs@d|_i|_g|_tj|_d|_d|_d|_t j |t j dS)Nr) _key_cache _old_locks threadingLock_lock _listener_address_threadrZregister_after_forkr _afterfork)rr r r r?s z_ResourceSharer.__init__c CsN|j>|jdkr|j|jd7_||f|j|j<|j|jfSQRXdS)Nr)r&r(_startr!r")rrrr r r rIs  z_ResourceSharer.registercCs<ddlm}|\}}||tjjd}|j|tjf|S)Nr)Client)authkey) connectionr,rcurrent_processr-rrgetpid)Zidentr,addresskeycr r r rRs  z_ResourceSharer.get_connectionNc Csddlm}|j|jdk r||jtjjd}|jd|j|j j ||j j rdt j d|jjd|_ d|_d|_x |jjD]\}\}}|qW|jjWdQRXdS)Nr)r,)r-z._ResourceSharer thread did not stop when asked)r.r,r&r(rr/r-rrr)joinZis_aliverZ sub_warningr'r"itemsclear)rZtimeoutr,r3r2rrr r r r[s"        z_ResourceSharer.stopcCsnx |jjD]\}\}}|q W|jj|jj|jtj|_|jdk rX|jj d|_d|_ d|_ dS)N) r"r5r6r#appendr&r$r%r'rr(r))rr2rrr r r r*ps     z_ResourceSharer._afterforkcCsXddlm}tjd|tjjd|_|jj|_ t j |j d}d|_ |j||_dS)Nr)Listenerz0starting listener and thread for sending handles)r-)targetT)r.r8rdebugrr/r-r'r1r(r$ZThread_serveZdaemonstartr))rr8tr r r r+~s   z_ResourceSharer._startcCsttdr tjtjtdtjxy\|jjH}|j}|dkrBP|\}}|j j |\}}z|||Wd|XWdQRXWq"t j st jt jYq"Xq"WdS)Npthread_sigmaskr)hasattrsignalr> SIG_BLOCKrangeNSIGr'ZacceptZrecvr"poprZ is_exitingsys excepthookexc_info)rr msgr2Zdestination_pidrrr r r r;s   z_ResourceSharer._serve)N) rrrrr staticmethodrrr*r+r;r r r r r =s   r )rr@rrEr$rcontextrr__all__platformobjectrrr rrr r r r  s       `resource_sharer.cpython-36.pyc000064400000012044147204630710012372 0ustar003 \@sddlZddlZddlZddlZddlZddlmZddlmZddlm Z dgZ ej dkrxe dg7Z Gd dde Z ne d g7Z Gd d d e ZGd d d e ZeZejZdS)N)process) reduction)utilstopZwin32 DupSocketc@s eZdZdZddZddZdS)rzPicklable wrapper for a socket.cs(|jfdd}tj|j|_dS)Ncsj|}|j|dS)N)shareZ send_bytes)connpidr)new_sock7/usr/lib64/python3.6/multiprocessing/resource_sharer.pysends z DupSocket.__init__..send)dup_resource_sharerregisterclose_id)selfZsockrr )r r __init__s zDupSocket.__init__c Cs*tj|j}|j}tj|SQRXdS)z1Get the socket. This should only be called once.N)rget_connectionrZ recv_bytessocketZ fromshare)rr rr r r detach$szDupSocket.detachN)__name__ __module__ __qualname____doc__rrr r r r rsDupFdc@s eZdZdZddZddZdS)rz-Wrapper for fd which can be used at any time.cs4tj|fdd}fdd}tj|||_dS)Ncstj||dS)N)rZ send_handle)r r )new_fdr r r1szDupFd.__init__..sendcstjdS)N)osrr )rr r r3szDupFd.__init__..close)rrrrr)rfdrrr )rr r/s   zDupFd.__init__c Cs"tj|j }tj|SQRXdS)z-Get the fd. This should only be called once.N)rrrrZ recv_handle)rr r r r r7sz DupFd.detachN)rrrrrrr r r r r-sc@sNeZdZdZddZddZeddZdd d Zd d Z d dZ ddZ dS)_ResourceSharerz-Manager for resouces using background thread.cCs@d|_i|_g|_tj|_d|_d|_d|_t j |t j dS)Nr) _key_cache _old_locks threadingLock_lock _listener_address_threadrZregister_after_forkr! _afterfork)rr r r r?s z_ResourceSharer.__init__c CsN|j>|jdkr|j|jd7_||f|j|j<|j|jfSQRXdS)z+Register resource, returning an identifier.Nr)r'r)_startr"r#)rrrr r r rIs  z_ResourceSharer.registercCs<ddlm}|\}}||tjjd}|j|tjf|S)z s       `semaphore_tracker.cpython-36.opt-1.pyc000064400000007065147204630710013643 0ustar003 \@sddlZddlZddlZddlZddlZddlZddlmZddlmZdddgZ Gdd d e Z e Z e j Z e jZe jZe jZd d ZdS) N)spawn)utilensure_runningregister unregisterc@s<eZdZddZddZddZddZd d Zd d Zd S)SemaphoreTrackercCstj|_d|_d|_dS)N) threadingZLock_lock_fd_pid)selfr9/usr/lib64/python3.6/multiprocessing/semaphore_tracker.py__init__s zSemaphoreTracker.__init__cCs|j|jS)N)rr )r rrrgetfd"szSemaphoreTracker.getfdc Cs|j|jdk rRtj|jtj\}}|s0dStj|jd|_d|_tjdg}y|j t j j Wnt k r~YnXd}tj\}}zlyB|j |tj}|gtj}|d||g7}tj|||}Wntj|YnX||_||_Wdtj|XWdQRXdS)zMake sure that semaphore tracker process is running. This can be run from any process. Usually a child process will use the semaphore created by its parent.NzWsemaphore_tracker: process died unexpectedly, relaunching. Some semaphores might leak.z;from multiprocessing.semaphore_tracker import main;main(%d)z-c)r r oswaitpidWNOHANGcloser warningswarnappendsysstderrfileno ExceptionpiperZget_executablerZ_args_from_interpreter_flagsZspawnv_passfds) r pidZstatusZ fds_to_passcmdrwZexeargsrrrr&s8        zSemaphoreTracker.ensure_runningcCs|jd|dS)z2Register name of semaphore with semaphore tracker.ZREGISTERN)_send)r namerrrrQszSemaphoreTracker.registercCs|jd|dS)z4Unregister name of semaphore with semaphore tracker.Z UNREGISTERN)r#)r r$rrrrUszSemaphoreTracker.unregistercCs@|jdj||jd}t|dkr.tdtj|j|}dS)Nz{0}:{1} asciiiz name too long)rformatencodelen ValueErrorrwriter )r rr$msgnbytesrrrr#Ys  zSemaphoreTracker._sendN) __name__ __module__ __qualname__rrrrrr#rrrrrs +rc-Cstjtjtjtjtjtjx6tjtjfD]&}y |jWq.tk rRYq.Xq.Wt }zt |d}x|D]}yJ|j j d\}}|dkr|j |n |dkr|j|n td|Wqrtk rytjtjWn YnXYqrXqrWWdQRXWd|rs   Isemaphore_tracker.cpython-36.opt-2.pyc000064400000006403147204630710013637 0ustar003 \@sddlZddlZddlZddlZddlZddlZddlmZddlmZdddgZ Gdd d e Z e Z e j Z e jZe jZe jZd d ZdS) N)spawn)utilensure_runningregister unregisterc@s<eZdZddZddZddZddZd d Zd d Zd S)SemaphoreTrackercCstj|_d|_d|_dS)N) threadingZLock_lock_fd_pid)selfr9/usr/lib64/python3.6/multiprocessing/semaphore_tracker.py__init__s zSemaphoreTracker.__init__cCs|j|jS)N)rr )r rrrgetfd"szSemaphoreTracker.getfdc Cs|j|jdk rRtj|jtj\}}|s0dStj|jd|_d|_tjdg}y|j t j j Wnt k r~YnXd}tj\}}zlyB|j |tj}|gtj}|d||g7}tj|||}Wntj|YnX||_||_Wdtj|XWdQRXdS)NzWsemaphore_tracker: process died unexpectedly, relaunching. Some semaphores might leak.z;from multiprocessing.semaphore_tracker import main;main(%d)z-c)r r oswaitpidWNOHANGcloser warningswarnappendsysstderrfileno ExceptionpiperZget_executablerZ_args_from_interpreter_flagsZspawnv_passfds) r pidZstatusZ fds_to_passcmdrwZexeargsrrrr&s8        zSemaphoreTracker.ensure_runningcCs|jd|dS)NZREGISTER)_send)r namerrrrQszSemaphoreTracker.registercCs|jd|dS)NZ UNREGISTER)r#)r r$rrrrUszSemaphoreTracker.unregistercCs@|jdj||jd}t|dkr.tdtj|j|}dS)Nz{0}:{1} asciiiz name too long)rformatencodelen ValueErrorrwriter )r rr$msgnbytesrrrr#Ys  zSemaphoreTracker._sendN) __name__ __module__ __qualname__rrrrrr#rrrrrs +rc-Cstjtjtjtjtjtjx6tjtjfD]&}y |jWq.tk rRYq.Xq.Wt }zt |d}x|D]}yJ|j j d\}}|dkr|j |n |dkr|j|n td|Wqrtk rytjtjWn YnXYqrXqrWWdQRXWd|rs   Isemaphore_tracker.cpython-36.pyc000064400000007125147204630710012701 0ustar003 \@sddlZddlZddlZddlZddlZddlZddlmZddlmZdddgZ Gdd d e Z e Z e j Z e jZe jZe jZd d ZdS) N)spawn)utilensure_runningregister unregisterc@s<eZdZddZddZddZddZd d Zd d Zd S)SemaphoreTrackercCstj|_d|_d|_dS)N) threadingZLock_lock_fd_pid)selfr9/usr/lib64/python3.6/multiprocessing/semaphore_tracker.py__init__s zSemaphoreTracker.__init__cCs|j|jS)N)rr )r rrrgetfd"szSemaphoreTracker.getfdc Cs|j|jdk rRtj|jtj\}}|s0dStj|jd|_d|_tjdg}y|j t j j Wnt k r~YnXd}tj\}}zlyB|j |tj}|gtj}|d||g7}tj|||}Wntj|YnX||_||_Wdtj|XWdQRXdS)zMake sure that semaphore tracker process is running. This can be run from any process. Usually a child process will use the semaphore created by its parent.NzWsemaphore_tracker: process died unexpectedly, relaunching. Some semaphores might leak.z;from multiprocessing.semaphore_tracker import main;main(%d)z-c)r r oswaitpidWNOHANGcloser warningswarnappendsysstderrfileno ExceptionpiperZget_executablerZ_args_from_interpreter_flagsZspawnv_passfds) r pidZstatusZ fds_to_passcmdrwZexeargsrrrr&s8        zSemaphoreTracker.ensure_runningcCs|jd|dS)z2Register name of semaphore with semaphore tracker.ZREGISTERN)_send)r namerrrrQszSemaphoreTracker.registercCs|jd|dS)z4Unregister name of semaphore with semaphore tracker.Z UNREGISTERN)r#)r r$rrrrUszSemaphoreTracker.unregistercCsP|jdj||jd}t|dkr.tdtj|j|}|t|ksLtdS)Nz{0}:{1} asciiiz name too long) rformatencodelen ValueErrorrwriter AssertionError)r rr$msgnbytesrrrr#Ys  zSemaphoreTracker._sendN) __name__ __module__ __qualname__rrrrrr#rrrrrs +rc-Cstjtjtjtjtjtjx6tjtjfD]&}y |jWq.tk rRYq.Xq.Wt }zt |d}x|D]}yJ|j j d\}}|dkr|j |n |dkr|j|n td|Wqrtk rytjtjWn YnXYqrXqrWWdQRXWd|rs   Isharedctypes.cpython-36.opt-1.pyc000064400000015231147204630710012635 0ustar003 \e @s:ddlZddlZddlmZddlmZddlmZmZejZ dddd d d gZ ej ej ej ejejejejejejejejejd Zd dZddZddZdddddZddddd Zdd Zd&dd ZddZddZ ddZ!dZ"iZ#ej$Z%Gddde&Z'Gd d!d!e'Z(Gd"d#d#e'Z)Gd$d%d%e)Z*dS)'N)heap) get_context) reductionassert_spawningRawValueRawArrayValueArraycopy synchronized) cubBhHiIlLfdcCs tj|}tj|}t||dS)N)ctypessizeofrZ BufferWrapper rebuild_ctype)type_sizewrapperr4/usr/lib64/python3.6/multiprocessing/sharedctypes.py _new_value&s  r!cGs<tj||}t|}tjtj|dtj||j||S)z> Returns a ctypes object allocated from shared memory r)typecode_to_typegetr!rmemset addressofr__init__)typecode_or_typeargsrobjrrr r+s   cCsjtj||}t|trD||}t|}tjtj|dtj||S|t |}t|}|j ||SdS)z= Returns a ctypes array allocated from shared memory rN) r"r# isinstanceintr!rr$r%rlenr&)r'size_or_initializerrr)resultrrr r5s    T)lockctxcGsXt|f|}|dkr|S|dkr4|p*t}|j}t|dsJtd|t|||dS)z6 Return a synchronization wrapper for a Value FTNacquirez'%r' has no method 'acquire')r0)TN)rrRLockhasattrAttributeErrorr )r'r/r0r(r)rrr r Es   cCsTt||}|dkr|S|dkr0|p&t}|j}t|dsFtd|t|||dS)z9 Return a synchronization wrapper for a RawArray FTNr1z'%r' has no method 'acquire')r0)TN)rrr2r3r4r )r'r-r/r0r)rrr r Ss    cCstt|}|tj|d<|S)Nr)r!typerZpointer)r)Znew_objrrr r as c Cs|pt}t|tjr"t|||St|tjrR|jtjkrFt|||St |||St |}y t |}WnVt k rdd|j D}tdd|D}d|j}t |tf|}t |<YnX||||SdS)NcSsg|] }|dqS)rr).0Zfieldrrr usz synchronized..css|]}|t|fVqdS)N) make_property)r6namerrr vszsynchronized.. Synchronized)rr*rZ _SimpleCDatar;r _type_c_charSynchronizedStringSynchronizedArrayr5 class_cacheKeyErrorZ_fields_dict__name__SynchronizedBase)r)r/r0clssclsnamesrZ classnamerrr r fs          cCs@t|t|tjr(t|j|j|jffStt||jdffSdS)N) rr*rr rr<_wrapperZ_length_r5)r)rrr reduce_ctypes rIcCs8|dk r||}tj|t|j}|j|}||_|S)N)_ForkingPicklerregisterrIZcreate_memoryviewZ from_bufferrH)rrZlengthZbufr)rrr rs  rc CsJyt|Stk rDi}tt|fd|||t|<||SXdS)N) prop_cacherAexectemplate)r9rrrr r8s r8z def get%s(self): self.acquire() try: return self._obj.%s finally: self.release() def set%s(self, value): self.acquire() try: self._obj.%s = value finally: self.release() %s = property(get%s, set%s) c@sFeZdZdddZddZddZdd Zd d Zd d ZddZ dS)rDNcCsB||_|r||_n|ptdd}|j|_|jj|_|jj|_dS)NT)Zforce)_obj_lockrr2r1release)selfr)r/r0rrr r&s  zSynchronizedBase.__init__cCs |jjS)N)rQ __enter__)rSrrr rTszSynchronizedBase.__enter__cGs |jj|S)N)rQ__exit__)rSr(rrr rUszSynchronizedBase.__exit__cCst|t|j|jffS)N)rr rPrQ)rSrrr __reduce__szSynchronizedBase.__reduce__cCs|jS)N)rP)rSrrr get_objszSynchronizedBase.get_objcCs|jS)N)rQ)rSrrr get_lockszSynchronizedBase.get_lockcCsdt|j|jfS)Nz<%s wrapper for %s>)r5rCrP)rSrrr __repr__szSynchronizedBase.__repr__)NN) rC __module__ __qualname__r&rTrUrVrWrXrYrrrr rDs rDc@seZdZedZdS)r;valueN)rCrZr[r8r\rrrr r;sr;c@s4eZdZddZddZddZddZd d Zd S) r?cCs t|jS)N)r,rP)rSrrr __len__szSynchronizedArray.__len__c Cs| |j|SQRXdS)N)rP)rSrrrr __getitem__szSynchronizedArray.__getitem__c Cs|||j|<WdQRXdS)N)rP)rSrr\rrr __setitem__szSynchronizedArray.__setitem__c Cs||j||SQRXdS)N)rP)rSstartstoprrr __getslice__szSynchronizedArray.__getslice__c Cs"|||j||<WdQRXdS)N)rP)rSr`ravaluesrrr __setslice__szSynchronizedArray.__setslice__N)rCrZr[r]r^r_rbrdrrrr r?s r?c@seZdZedZedZdS)r>r\rawN)rCrZr[r8r\rerrrr r>sr>)NN)+rweakrefrrcontextrrZForkingPicklerrJ__all__r=Zc_wcharZc_byteZc_ubyteZc_shortZc_ushortZc_intZc_uintZc_longZc_ulongZc_floatZc_doubler"r!rrr r r r rIrr8rOrMWeakKeyDictionaryr@objectrDr;r?r>rrrr  s:      sharedctypes.cpython-36.opt-2.pyc000064400000014650147204630710012642 0ustar003 \e @s:ddlZddlZddlmZddlmZddlmZmZejZ dddd d d gZ ej ej ej ejejejejejejejejejd Zd dZddZddZdddddZddddd Zdd Zd&dd ZddZddZ ddZ!dZ"iZ#ej$Z%Gddde&Z'Gd d!d!e'Z(Gd"d#d#e'Z)Gd$d%d%e)Z*dS)'N)heap) get_context) reductionassert_spawningRawValueRawArrayValueArraycopy synchronized) cubBhHiIlLfdcCs tj|}tj|}t||dS)N)ctypessizeofrZ BufferWrapper rebuild_ctype)type_sizewrapperr4/usr/lib64/python3.6/multiprocessing/sharedctypes.py _new_value&s  r!cGs<tj||}t|}tjtj|dtj||j||S)Nr)typecode_to_typegetr!rmemset addressofr__init__)typecode_or_typeargsrobjrrr r+s   cCsjtj||}t|trD||}t|}tjtj|dtj||S|t |}t|}|j ||SdS)Nr) r"r# isinstanceintr!rr$r%rlenr&)r'size_or_initializerrr)resultrrr r5s    T)lockctxcGsXt|f|}|dkr|S|dkr4|p*t}|j}t|dsJtd|t|||dS)NFTacquirez'%r' has no method 'acquire')r0)TN)rrRLockhasattrAttributeErrorr )r'r/r0r(r)rrr r Es   cCsTt||}|dkr|S|dkr0|p&t}|j}t|dsFtd|t|||dS)NFTr1z'%r' has no method 'acquire')r0)TN)rrr2r3r4r )r'r-r/r0r)rrr r Ss    cCstt|}|tj|d<|S)Nr)r!typerZpointer)r)Znew_objrrr r as c Cs|pt}t|tjr"t|||St|tjrR|jtjkrFt|||St |||St |}y t |}WnVt k rdd|j D}tdd|D}d|j}t |tf|}t |<YnX||||SdS)NcSsg|] }|dqS)rr).0Zfieldrrr usz synchronized..css|]}|t|fVqdS)N) make_property)r6namerrr vszsynchronized.. Synchronized)rr*rZ _SimpleCDatar;r _type_c_charSynchronizedStringSynchronizedArrayr5 class_cacheKeyErrorZ_fields_dict__name__SynchronizedBase)r)r/r0clssclsnamesrZ classnamerrr r fs          cCs@t|t|tjr(t|j|j|jffStt||jdffSdS)N) rr*rr rr<_wrapperZ_length_r5)r)rrr reduce_ctypes rIcCs8|dk r||}tj|t|j}|j|}||_|S)N)_ForkingPicklerregisterrIZcreate_memoryviewZ from_bufferrH)rrZlengthZbufr)rrr rs  rc CsJyt|Stk rDi}tt|fd|||t|<||SXdS)N) prop_cacherAexectemplate)r9rrrr r8s r8z def get%s(self): self.acquire() try: return self._obj.%s finally: self.release() def set%s(self, value): self.acquire() try: self._obj.%s = value finally: self.release() %s = property(get%s, set%s) c@sFeZdZdddZddZddZdd Zd d Zd d ZddZ dS)rDNcCsB||_|r||_n|ptdd}|j|_|jj|_|jj|_dS)NT)Zforce)_obj_lockrr2r1release)selfr)r/r0rrr r&s  zSynchronizedBase.__init__cCs |jjS)N)rQ __enter__)rSrrr rTszSynchronizedBase.__enter__cGs |jj|S)N)rQ__exit__)rSr(rrr rUszSynchronizedBase.__exit__cCst|t|j|jffS)N)rr rPrQ)rSrrr __reduce__szSynchronizedBase.__reduce__cCs|jS)N)rP)rSrrr get_objszSynchronizedBase.get_objcCs|jS)N)rQ)rSrrr get_lockszSynchronizedBase.get_lockcCsdt|j|jfS)Nz<%s wrapper for %s>)r5rCrP)rSrrr __repr__szSynchronizedBase.__repr__)NN) rC __module__ __qualname__r&rTrUrVrWrXrYrrrr rDs rDc@seZdZedZdS)r;valueN)rCrZr[r8r\rrrr r;sr;c@s4eZdZddZddZddZddZd d Zd S) r?cCs t|jS)N)r,rP)rSrrr __len__szSynchronizedArray.__len__c Cs| |j|SQRXdS)N)rP)rSrrrr __getitem__szSynchronizedArray.__getitem__c Cs|||j|<WdQRXdS)N)rP)rSrr\rrr __setitem__szSynchronizedArray.__setitem__c Cs||j||SQRXdS)N)rP)rSstartstoprrr __getslice__szSynchronizedArray.__getslice__c Cs"|||j||<WdQRXdS)N)rP)rSr`ravaluesrrr __setslice__szSynchronizedArray.__setslice__N)rCrZr[r]r^r_rbrdrrrr r?s r?c@seZdZedZedZdS)r>r\rawN)rCrZr[r8r\rerrrr r>sr>)NN)+rweakrefrrcontextrrZForkingPicklerrJ__all__r=Zc_wcharZc_byteZc_ubyteZc_shortZc_ushortZc_intZc_uintZc_longZc_ulongZc_floatZc_doubler"r!rrr r r r rIrr8rOrMWeakKeyDictionaryr@objectrDr;r?r>rrrr  s:      sharedctypes.cpython-36.pyc000064400000015334147204630710011702 0ustar003 \e @s:ddlZddlZddlmZddlmZddlmZmZejZ dddd d d gZ ej ej ej ejejejejejejejejejd Zd dZddZddZdddddZddddd Zdd Zd&dd ZddZddZ ddZ!dZ"iZ#ej$Z%Gddde&Z'Gd d!d!e'Z(Gd"d#d#e'Z)Gd$d%d%e)Z*dS)'N)heap) get_context) reductionassert_spawningRawValueRawArrayValueArraycopy synchronized) cubBhHiIlLfdcCs tj|}tj|}t||dS)N)ctypessizeofrZ BufferWrapper rebuild_ctype)type_sizewrapperr4/usr/lib64/python3.6/multiprocessing/sharedctypes.py _new_value&s  r!cGs<tj||}t|}tjtj|dtj||j||S)z> Returns a ctypes object allocated from shared memory r)typecode_to_typegetr!rmemset addressofr__init__)typecode_or_typeargsrobjrrr r+s   cCsjtj||}t|trD||}t|}tjtj|dtj||S|t |}t|}|j ||SdS)z= Returns a ctypes array allocated from shared memory rN) r"r# isinstanceintr!rr$r%rlenr&)r'size_or_initializerrr)resultrrr r5s    T)lockctxcGsXt|f|}|dkr|S|dkr4|p*t}|j}t|dsJtd|t|||dS)z6 Return a synchronization wrapper for a Value FTNacquirez'%r' has no method 'acquire')r0)TN)rrRLockhasattrAttributeErrorr )r'r/r0r(r)rrr r Es   cCsTt||}|dkr|S|dkr0|p&t}|j}t|dsFtd|t|||dS)z9 Return a synchronization wrapper for a RawArray FTNr1z'%r' has no method 'acquire')r0)TN)rrr2r3r4r )r'r-r/r0r)rrr r Ss    cCstt|}|tj|d<|S)Nr)r!typerZpointer)r)Znew_objrrr r as c Cst|t std|pt}t|tjr6t|||St|tjrf|jtj krZt |||St |||St |}y t |}WnVtk rdd|jD}tdd|D}d|j}t |tf|}t |<YnX||||SdS)Nzobject already synchronizedcSsg|] }|dqS)rr).0Zfieldrrr usz synchronized..css|]}|t|fVqdS)N) make_property)r6namerrr vszsynchronized.. Synchronized)r*SynchronizedBaseAssertionErrorrrZ _SimpleCDatar;r _type_c_charSynchronizedStringSynchronizedArrayr5 class_cacheKeyErrorZ_fields_dict__name__)r)r/r0clssclsnamesrZ classnamerrr r fs"         cCs@t|t|tjr(t|j|j|jffStt||jdffSdS)N) rr*rr rr>_wrapperZ_length_r5)r)rrr reduce_ctypes rJcCs8|dk r||}tj|t|j}|j|}||_|S)N)_ForkingPicklerregisterrJZcreate_memoryviewZ from_bufferrI)rrZlengthZbufr)rrr rs  rc CsJyt|Stk rDi}tt|fd|||t|<||SXdS)N) prop_cacherCexectemplate)r9rrrr r8s r8z def get%s(self): self.acquire() try: return self._obj.%s finally: self.release() def set%s(self, value): self.acquire() try: self._obj.%s = value finally: self.release() %s = property(get%s, set%s) c@sFeZdZdddZddZddZdd Zd d Zd d ZddZ dS)r<NcCsB||_|r||_n|ptdd}|j|_|jj|_|jj|_dS)NT)Zforce)_obj_lockrr2r1release)selfr)r/r0rrr r&s  zSynchronizedBase.__init__cCs |jjS)N)rR __enter__)rTrrr rUszSynchronizedBase.__enter__cGs |jj|S)N)rR__exit__)rTr(rrr rVszSynchronizedBase.__exit__cCst|t|j|jffS)N)rr rQrR)rTrrr __reduce__szSynchronizedBase.__reduce__cCs|jS)N)rQ)rTrrr get_objszSynchronizedBase.get_objcCs|jS)N)rR)rTrrr get_lockszSynchronizedBase.get_lockcCsdt|j|jfS)Nz<%s wrapper for %s>)r5rErQ)rTrrr __repr__szSynchronizedBase.__repr__)NN) rE __module__ __qualname__r&rUrVrWrXrYrZrrrr r<s r<c@seZdZedZdS)r;valueN)rEr[r\r8r]rrrr r;sr;c@s4eZdZddZddZddZddZd d Zd S) rAcCs t|jS)N)r,rQ)rTrrr __len__szSynchronizedArray.__len__c Cs| |j|SQRXdS)N)rQ)rTrrrr __getitem__szSynchronizedArray.__getitem__c Cs|||j|<WdQRXdS)N)rQ)rTrr]rrr __setitem__szSynchronizedArray.__setitem__c Cs||j||SQRXdS)N)rQ)rTstartstoprrr __getslice__szSynchronizedArray.__getslice__c Cs"|||j||<WdQRXdS)N)rQ)rTrarbvaluesrrr __setslice__szSynchronizedArray.__setslice__N)rEr[r\r^r_r`rcrerrrr rAs rAc@seZdZedZedZdS)r@r]rawN)rEr[r\r8r]rfrrrr r@sr@)NN)+rweakrefrrcontextrrZForkingPicklerrK__all__r?Zc_wcharZc_byteZc_ubyteZc_shortZc_ushortZc_intZc_uintZc_longZc_ulongZc_floatZc_doubler"r!rrr r r r rJrr8rPrNWeakKeyDictionaryrBobjectr<r;rAr@rrrr  s:      spawn.cpython-36.opt-1.pyc000064400000014401147204630710011265 0ustar003 \"@s.ddlZddlZddlZddlZddlmZmZddlmZddlm Z ddlm Z ddd d d d d gZ ej dkrzdZ dZn&ej dkoeeddZ ejjjdZerejjejdanejadd Zdd ZddZddZdd Zd&ddZddZddZdd ZgZ dd Z!d!d"Z"d#d$Z#d%d Z$dS)'N)get_start_methodset_start_method)process) reduction)util_mainfreeze_supportset_executableget_executableget_preparation_dataget_command_lineimport_main_pathwin32Ffrozenzpythonservice.exez python.execCs|adS)N) _python_exe)Zexer-/usr/lib64/python3.6/multiprocessing/spawn.pyr )scCstS)N)rrrrrr -scCs$t|dkr|ddkrdSdSdS)z= Return whether commandline indicates we are forking rz--multiprocessing-forkTFN)len)argvrrr is_forking4srcCshttjrdi}xBtjddD]0}|jd\}}|dkrBd||<qt|||<qWtf|tjdS)zE Run code for process object if this in not the main process rN=None)rsysrsplitint spawn_mainexit)kwdsargnamevaluerrrr >s   cKshttddr(tjdgdd|jDSd}|djdd |jD;}tj}tg|d |dgSd S) zJ Returns prefix of command line used for spawning a child process rFz--multiprocessing-forkcSsg|] }d|qS)z%s=%rr).0itemrrr Tsz$get_command_line..zWsz#get_command_line..z-cN)getattrr executableitemsjoinrZ_args_from_interpreter_flagsr)rprogZoptsrrrr Ns cCs\tjdkr.ddl}tj||}|j|tj}nddlm }||j _ |}t |}tj |dS)z7 Run code specified by data received over pipe rrNr)semaphore_tracker)rplatformmsvcrtrZ steal_handleZopen_osfhandleosO_RDONLYr,Z_semaphore_trackerZ_fdrr)Z pipe_handleZ parent_pidZ tracker_fdr.Z new_handlefdr,Zexitcoderrrr\s   rcCs^tj|ddd@}dtj_z$tjj|}t|tjj|}Wdtj`XWdQRX|j S)NrbT)closefd) r/fdopenrcurrent_process _inheritingrpickleloadprepare _bootstrap)r2Z from_parentZpreparation_dataselfrrrrms  cCsttjddrtddS)Nr7Fa An attempt has been made to start a new process before the current process has finished its bootstrapping phase. This probably means that you are not using fork to start your child processes and you have forgotten to use the proper idiom in the main module: if __name__ == '__main__': freeze_support() ... The "freeze_support()" line can be omitted if the program is not going to be frozen to produce an executable.)r'rr6 RuntimeErrorrrrr_check_not_importing_mainys r>cCs tttjtjjd}tjdk r2tjj|d<t j j }y|j d}Wnt k r^Yn Xtj||<|j||t jtjtjtdt jd}t|jdd}|dk r||d<nht jd kst ot rt|d d}|dk rtj j| otjdk r tj jtj|}tj j||d <|S) zM Return info about parent needed by child to unpickle process object ) log_to_stderrauthkeyN log_levelr1)r!sys_pathsys_argvorig_dirdir start_method__main__r!init_main_from_namer__file__init_main_from_path)r>dictrZ_log_to_stderrrr6r@Z_loggerZgetEffectiveLevelrpathcopyindex ValueError ORIGINAL_DIRupdaterr/getcwdrmodulesr'__spec__r-WINEXE WINSERVICEisabsr*normpath)r!drBi main_moduleZ main_mod_name main_pathrrrr s>         cCsd|kr|dtj_d|kr,|dtj_d|krD|drDtjd|kr^tjj|dd|krp|dt_ d|kr|dt_ d|krt j |dd|kr|dt_ d |krt|d d d d |krt|d nd |krt|d dS)zE Try to get current process ready to unpickle process object r!r@r?rArBrCrErDrFT)ZforcerHrJN)rr6r!r@rr?Z get_loggerZsetLevelrrLrr/chdirrPr_fixup_main_from_name_fixup_main_from_path)datarrrr:s,   r:cCs~tjd}|dks|jdr dSt|jdd|kr6dStj|tjd}t j |ddd}|j j ||tjd<tjd<dS)NrGz .__main__r! __mp_main__T)run_nameZ alter_sys) rrSendswithr'rTold_main_modulesappendtypes ModuleTyperunpyZ run_module__dict__rQ)Zmod_name current_mainr[ main_contentrrrr^s    r^cCstjd}tjjtjj|d}|dkr.dSt|dd|krBdStj|t j d}t j |dd}|j j||tjd<tjd<dS)NrGrZipythonrIra)rb)rrSr/rLsplitextbasenamer'rdrerfrgrhZrun_pathrirQ)r\rjZ main_namer[rkrrrr_s    r_cCs t|dS)z< Set sys.modules['__main__'] to module at main_path N)r_)r\rrrrs)NN)%r/rrhrfr1rrrcontextrr__all__r-rUrVr'r(lowerrcrLr* exec_prefixrr r rr r rrr>r rdr:r^r_rrrrr s>        2&spawn.cpython-36.opt-2.pyc000064400000013442147204630710011272 0ustar003 \"@s.ddlZddlZddlZddlZddlmZmZddlmZddlm Z ddlm Z ddd d d d d gZ ej dkrzdZ dZn&ej dkoeeddZ ejjjdZerejjejdanejadd Zdd ZddZddZdd Zd&ddZddZddZdd ZgZ dd Z!d!d"Z"d#d$Z#d%d Z$dS)'N)get_start_methodset_start_method)process) reduction)util_mainfreeze_supportset_executableget_executableget_preparation_dataget_command_lineimport_main_pathwin32Ffrozenzpythonservice.exez python.execCs|adS)N) _python_exe)Zexer-/usr/lib64/python3.6/multiprocessing/spawn.pyr )scCstS)N)rrrrrr -scCs$t|dkr|ddkrdSdSdS)Nrz--multiprocessing-forkTF)len)argvrrr is_forking4srcCshttjrdi}xBtjddD]0}|jd\}}|dkrBd||<qt|||<qWtf|tjdS)Nr=None)rsysrsplitint spawn_mainexit)kwdsargnamevaluerrrr >s   cKshttddr(tjdgdd|jDSd}|djdd |jD;}tj}tg|d |dgSdS) NrFz--multiprocessing-forkcSsg|] }d|qS)z%s=%rr).0itemrrr Tsz$get_command_line..zWsz#get_command_line..z-c)getattrr executableitemsjoinrZ_args_from_interpreter_flagsr)rprogZoptsrrrr Ns cCs\tjdkr.ddl}tj||}|j|tj}nddlm }||j _ |}t |}tj |dS)Nrrr)semaphore_tracker)rplatformmsvcrtrZ steal_handleZopen_osfhandleosO_RDONLYr,Z_semaphore_trackerZ_fdrr)Z pipe_handleZ parent_pidZ tracker_fdr.Z new_handlefdr,Zexitcoderrrr\s   rcCs^tj|ddd@}dtj_z$tjj|}t|tjj|}Wdtj`XWdQRX|j S)NrbT)closefd) r/fdopenrcurrent_process _inheritingrpickleloadprepare _bootstrap)r2Z from_parentZpreparation_dataselfrrrrms  cCsttjddrtddS)Nr7Fa An attempt has been made to start a new process before the current process has finished its bootstrapping phase. This probably means that you are not using fork to start your child processes and you have forgotten to use the proper idiom in the main module: if __name__ == '__main__': freeze_support() ... The "freeze_support()" line can be omitted if the program is not going to be frozen to produce an executable.)r'rr6 RuntimeErrorrrrr_check_not_importing_mainys r>cCs tttjtjjd}tjdk r2tjj|d<t j j }y|j d}Wnt k r^Yn Xtj||<|j||t jtjtjtdt jd}t|jdd}|dk r||d<nht jdkst ot rt|d d}|dk rtj j| otjdk r tj jtj|}tj j||d <|S) N) log_to_stderrauthkey log_levelr1)r!sys_pathsys_argvorig_dirdir start_method__main__r!init_main_from_namer__file__init_main_from_path)r>dictrZ_log_to_stderrrr6r@Z_loggerZgetEffectiveLevelrpathcopyindex ValueError ORIGINAL_DIRupdaterr/getcwdrmodulesr'__spec__r-WINEXE WINSERVICEisabsr*normpath)r!drBi main_moduleZ main_mod_name main_pathrrrr s>         cCsd|kr|dtj_d|kr,|dtj_d|krD|drDtjd|kr^tjj|dd|krp|dt_ d|kr|dt_ d|krt j |dd|kr|dt_ d |krt|d d d d |krt|d nd |krt|d dS)Nr!r@r?rArBrCrErDrFT)ZforcerHrJ)rr6r!r@rr?Z get_loggerZsetLevelrrLrr/chdirrPr_fixup_main_from_name_fixup_main_from_path)datarrrr:s,   r:cCs~tjd}|dks|jdr dSt|jdd|kr6dStj|tjd}t j |ddd}|j j ||tjd<tjd<dS)NrGz .__main__r! __mp_main__T)run_nameZ alter_sys) rrSendswithr'rTold_main_modulesappendtypes ModuleTyperunpyZ run_module__dict__rQ)Zmod_name current_mainr[ main_contentrrrr^s    r^cCstjd}tjjtjj|d}|dkr.dSt|dd|krBdStj|t j d}t j |dd}|j j||tjd<tjd<dS)NrGrZipythonrIra)rb)rrSr/rLsplitextbasenamer'rdrerfrgrhZrun_pathrirQ)r\rjZ main_namer[rkrrrr_s    r_cCs t|dS)N)r_)r\rrrrs)NN)%r/rrhrfr1rrrcontextrr__all__r-rUrVr'r(lowerrcrLr* exec_prefixrr r rr r rrr>r rdr:r^r_rrrrr s>        2&spawn.cpython-36.pyc000064400000014453147204630710010335 0ustar003 \"@s.ddlZddlZddlZddlZddlmZmZddlmZddlm Z ddlm Z ddd d d d d gZ ej dkrzdZ dZn&ej dkoeeddZ ejjjdZerejjejdanejadd Zdd ZddZddZdd Zd&ddZddZddZdd ZgZ dd Z!d!d"Z"d#d$Z#d%d Z$dS)'N)get_start_methodset_start_method)process) reduction)util_mainfreeze_supportset_executableget_executableget_preparation_dataget_command_lineimport_main_pathwin32Ffrozenzpythonservice.exez python.execCs|adS)N) _python_exe)Zexer-/usr/lib64/python3.6/multiprocessing/spawn.pyr )scCstS)N)rrrrrr -scCs$t|dkr|ddkrdSdSdS)z= Return whether commandline indicates we are forking rz--multiprocessing-forkTFN)len)argvrrr is_forking4srcCshttjrdi}xBtjddD]0}|jd\}}|dkrBd||<qt|||<qWtf|tjdS)zE Run code for process object if this in not the main process rN=None)rsysrsplitint spawn_mainexit)kwdsargnamevaluerrrr >s   cKshttddr(tjdgdd|jDSd}|djdd |jD;}tj}tg|d |dgSd S) zJ Returns prefix of command line used for spawning a child process rFz--multiprocessing-forkcSsg|] }d|qS)z%s=%rr).0itemrrr Tsz$get_command_line..zWsz#get_command_line..z-cN)getattrr executableitemsjoinrZ_args_from_interpreter_flagsr)rprogZoptsrrrr Ns cCsjttjsttjdkr         cCsd|kr|dtj_d|kr,|dtj_d|krD|drDtjd|kr^tjj|dd|krp|dt_ d|kr|dt_ d|krt j |dd|kr|dt_ d |krt|d d d d |krt|d nd |krt|d dS)zE Try to get current process ready to unpickle process object r!rAr@rBrCrDrFrErGT)ZforcerIrKN)rr7r!rArr@Z get_loggerZsetLevelrrMrr0chdirrQr_fixup_main_from_name_fixup_main_from_path)datarrrr;s,   r;cCs~tjd}|dks|jdr dSt|jdd|kr6dStj|tjd}t j |ddd}|j j ||tjd<tjd<dS)NrHz .__main__r! __mp_main__T)run_nameZ alter_sys) rrTendswithr'rUold_main_modulesappendtypes ModuleTyperunpyZ run_module__dict__rR)Zmod_name current_mainr\ main_contentrrrr_s    r_cCstjd}tjjtjj|d}|dkr.dSt|dd|krBdStj|t j d}t j |dd}|j j||tjd<tjd<dS)NrHrZipythonrJrb)rc)rrTr0rMsplitextbasenamer'rerfrgrhriZrun_pathrjrR)r]rkZ main_namer\rlrrrr`s    r`cCs t|dS)z< Set sys.modules['__main__'] to module at main_path N)r`)r]rrrrs)NN)%r0rrirgr2rrrcontextrr__all__r.rVrWr'r(lowerrdrMr* exec_prefixrr r rr r rrr?r rer;r_r`rrrrr s>        2&synchronize.cpython-36.opt-1.pyc000064400000026043147204630710012515 0ustar003 \/ @s,ddddddgZddlZddlZddlZddlZddlZdd lmZdd lmZdd lm Z ydd lm Z m Z Wne k re dYnXe ed\ZZej jZGdddeZ Gddde ZGdddeZGddde ZGddde ZGdddeZGdddeZGdddejZdS)LockRLock SemaphoreBoundedSemaphore ConditionEventN)context)process)util)SemLock sem_unlinkz*This platform lacks a functioning sem_openz( implementation, therefore, the requiredz+ synchronization primitives needed will notz function, see issue 3770.c@s\eZdZejZddZeddZddZ ddZ d d Z d d Z d dZ eddZdS)r c Cs|dkrtjj}|j}tjdkp*|dk}xPtdD]<}y tj||||j |}|_ Wnt k rnYq6XPq6Wt dt j d|j|jtjdkrdd} t j|| |j jdk rdd lm} | |j jt j|tj|j jfd d dS) Nwin32forkdzcannot find name for semaphorezcreated semlock with handle %scSs|jjdS)N)_semlock _after_fork)objr3/usr/lib64/python3.6/multiprocessing/synchronize.pyrGsz%SemLock.__init__.._after_forkr)registerr)Z exitpriority)r Z_default_contextZ get_contextZget_start_methodsysplatformrange_multiprocessingr _make_namerFileExistsErrorr debughandle _make_methodsZregister_after_forknamesemaphore_trackerrZFinalize_cleanup) selfkindvaluemaxvaluectxr!Z unlink_nowislrrrrr__init__2s.       zSemLock.__init__cCs ddlm}t|||dS)Nr) unregister)r"r,r )r!r,rrrr#Ts zSemLock._cleanupcCs|jj|_|jj|_dS)N)racquirerelease)r$rrrr Zs zSemLock._make_methodscCs |jjS)N)r __enter__)r$rrrr/^szSemLock.__enter__cGs |jj|S)N)r__exit__)r$argsrrrr0aszSemLock.__exit__cCsDtj||j}tjdkr,tjj|j}n|j}||j|j |j fS)Nr) r assert_spawningrrrZget_spawning_popenZduplicate_for_childrr%r'r!)r$r*hrrr __getstate__ds   zSemLock.__getstate__cCs,tjj||_tjd|d|jdS)Nz recreated blocker with handle %rr)rr Z_rebuildrr rr )r$staterrr __setstate__mszSemLock.__setstate__cCsdtjjdttjfS)Nz%s-%sZ semprefix)r current_processZ_confignextr _randrrrrrrszSemLock._make_nameN)__name__ __module__ __qualname__tempfileZ_RandomNameSequencer9r+ staticmethodr#r r/r0r4r6rrrrrr .s"  r c@s&eZdZd ddZddZddZdS) rrcCstj|t|t|ddS)N)r()r r+ SEMAPHORE SEM_VALUE_MAX)r$r&r(rrrr+}szSemaphore.__init__cCs |jjS)N)r _get_value)r$rrr get_valueszSemaphore.get_valuec Cs8y|jj}Wntk r&d}YnXd|jj|fS)Nunknownz<%s(value=%s)>)rrA Exception __class__r:)r$r&rrr__repr__s  zSemaphore.__repr__N)r)r:r;r<r+rBrFrrrrr{s c@seZdZdddZddZdS)rrcCstj|t|||ddS)N)r()r r+r?)r$r&r(rrrr+szBoundedSemaphore.__init__c Cs>y|jj}Wntk r&d}YnXd|jj||jjfS)NrCz<%s(value=%s, maxvalue=%s)>)rrArDrEr:r')r$r&rrrrFs  zBoundedSemaphore.__repr__N)r)r:r;r<r+rFrrrrrs c@seZdZddZddZdS)rcCstj|tdd|ddS)Nr)r()r r+r?)r$r(rrrr+sz Lock.__init__c Csyf|jjr8tjj}tjjdkrd|dtjj7}n,|jjdkrLd}n|jjdkr`d}nd}Wnt k r~d}YnXd |j j |fS) N MainThread|rNonerSomeOtherThreadSomeOtherProcessrCz<%s(owner=%s)>) r_is_miner r7r! threadingcurrent_threadrA_countrDrEr:)r$r!rrrrFs   z Lock.__repr__N)r:r;r<r+rFrrrrrsc@seZdZddZddZdS)rcCstj|tdd|ddS)Nr)r()r r+RECURSIVE_MUTEX)r$r(rrrr+szRLock.__init__c Csy||jjrBtjj}tjjdkr6|dtjj7}|jj}n8|jjdkrZd \}}n |jjdkrrd \}}nd \}}Wnt k rd\}}YnXd |j j ||fS)NrGrHrrIrrJnonzerorKrCz <%s(%s, %s)>)rIr)rJrQ)rKrQ)rCrC) rrLr r7r!rMrNrOrArDrEr:)r$r!countrrrrFs      zRLock.__repr__N)r:r;r<r+rFrrrrrsc@sjeZdZdddZddZddZdd Zd d Zd d ZddZ dddZ ddZ ddZ dddZ dS)rNcCs>|p |j|_|jd|_|jd|_|jd|_|jdS)Nr)r_lockr_sleeping_count _woken_count_wait_semaphorer )r$lockr(rrrr+s    zCondition.__init__cCstj||j|j|j|jfS)N)r r2rSrTrUrV)r$rrrr4s zCondition.__getstate__cCs |\|_|_|_|_|jdS)N)rSrTrUrVr )r$r5rrrr6szCondition.__setstate__cCs |jjS)N)rSr/)r$rrrr/szCondition.__enter__cGs |jj|S)N)rSr0)r$r1rrrr0szCondition.__exit__cCs|jj|_|jj|_dS)N)rSr-r.)r$rrrr s zCondition._make_methodsc CsJy|jjj|jjj}Wntk r4d}YnXd|jj|j|fS)NrCz <%s(%s, %s)>)rTrrArUrDrEr:rS)r$Z num_waitersrrrrFs   zCondition.__repr__c Csn|jj|jjj}xt|D]}|jjq Wz|jjd|S|jjxt|D]}|jjqVWXdS)NT) rTr.rSrrOrrVr-rU)r$timeoutrRr)rrrwaits   zCondition.waitcCsNx|jjdr|jjd}qW|jjdrJ|jj|jj|jjddS)NF)rUr-rTrVr.)r$resrrrnotifys    zCondition.notifycCs|x|jjdr|jjd}qWd}x"|jjdrD|jj|d7}q$W|rxxt|D]}|jjqTWx|jjdrvqhWdS)NFrr)rUr-rTrVr.r)r$rZZsleepersr)rrr notify_alls   zCondition.notify_allcCsh|}|r|S|dk r$tj|}nd}d}x6|sb|dk rP|tj}|dkrPP|j||}q.W|S)Nr)timeZ monotonicrY)r$Z predicaterXresultZendtimeZwaittimerrrwait_for6s   zCondition.wait_for)N)N)N)r:r;r<r+r4r6r/r0r rFrYr[r\r_rrrrrs  c@s6eZdZddZddZddZddZd d d Zd S) rcCs |j|j|_|jd|_dS)Nr)rr_condr_flag)r$r(rrrr+NszEvent.__init__c Cs0|j |jjdr"|jjdSdSQRXdS)NFT)r`rar-r.)r$rrris_setRs   z Event.is_setc Cs6|j&|jjd|jj|jjWdQRXdS)NF)r`rar-r.r\)r$rrrsetYs  z Event.setc Cs"|j|jjdWdQRXdS)NF)r`rar-)r$rrrclear_sz Event.clearNc CsT|jD|jjdr |jjn |jj||jjdrF|jjdSdSQRXdS)NFT)r`rar-r.rY)r$rXrrrrYcs     z Event.wait)N)r:r;r<r+rbrcrdrYrrrrrLs c@sZeZdZdddZddZddZedd Zejd d Zed d Z e jd d Z dS)BarrierNc CsRddl}ddlm}||jdd}|j}|j|||||fd|_d|_dS)Nrr) BufferWrapperr)r)structheaprfZcalcsizerr6_staterO) r$ZpartiesactionrXr(rgrfwrapperZcondrrrr+us zBarrier.__init__cCs.|\|_|_|_|_|_|jjjd|_dS)Nr))_parties_action_timeoutr`_wrapperZcreate_memoryviewcast_array)r$r5rrrr6~szBarrier.__setstate__cCs|j|j|j|j|jfS)N)rlrmrnr`ro)r$rrrr4s zBarrier.__getstate__cCs |jdS)Nr)rq)r$rrrriszBarrier._statecCs||jd<dS)Nr)rq)r$r&rrrriscCs |jdS)Nr)rq)r$rrrrOszBarrier._countcCs||jd<dS)Nr)rq)r$r&rrrrOs)NN) r:r;r<r+r6r4propertyrisetterrOrrrrress   rezRThis platform lacks a functioning sem_open implementation, therefore, the requiredz}This platform lacks a functioning sem_open implementation, therefore, the required synchronization primitives needed will notzThis platform lacks a functioning sem_open implementation, therefore, the required synchronization primitives needed will not function, see issue 3770.)__all__rMrr=rr]r r r r r ImportErrorlistrrPr?r@objectrrrrrrrerrrr s0    Mz'synchronize.cpython-36.opt-2.pyc000064400000026043147204630710012516 0ustar003 \/ @s,ddddddgZddlZddlZddlZddlZddlZdd lmZdd lmZdd lm Z ydd lm Z m Z Wne k re dYnXe ed\ZZej jZGdddeZ Gddde ZGdddeZGddde ZGddde ZGdddeZGdddeZGdddejZdS)LockRLock SemaphoreBoundedSemaphore ConditionEventN)context)process)util)SemLock sem_unlinkz*This platform lacks a functioning sem_openz( implementation, therefore, the requiredz+ synchronization primitives needed will notz function, see issue 3770.c@s\eZdZejZddZeddZddZ ddZ d d Z d d Z d dZ eddZdS)r c Cs|dkrtjj}|j}tjdkp*|dk}xPtdD]<}y tj||||j |}|_ Wnt k rnYq6XPq6Wt dt j d|j|jtjdkrdd} t j|| |j jdk rdd lm} | |j jt j|tj|j jfd d dS) Nwin32forkdzcannot find name for semaphorezcreated semlock with handle %scSs|jjdS)N)_semlock _after_fork)objr3/usr/lib64/python3.6/multiprocessing/synchronize.pyrGsz%SemLock.__init__.._after_forkr)registerr)Z exitpriority)r Z_default_contextZ get_contextZget_start_methodsysplatformrange_multiprocessingr _make_namerFileExistsErrorr debughandle _make_methodsZregister_after_forknamesemaphore_trackerrZFinalize_cleanup) selfkindvaluemaxvaluectxr!Z unlink_nowislrrrrr__init__2s.       zSemLock.__init__cCs ddlm}t|||dS)Nr) unregister)r"r,r )r!r,rrrr#Ts zSemLock._cleanupcCs|jj|_|jj|_dS)N)racquirerelease)r$rrrr Zs zSemLock._make_methodscCs |jjS)N)r __enter__)r$rrrr/^szSemLock.__enter__cGs |jj|S)N)r__exit__)r$argsrrrr0aszSemLock.__exit__cCsDtj||j}tjdkr,tjj|j}n|j}||j|j |j fS)Nr) r assert_spawningrrrZget_spawning_popenZduplicate_for_childrr%r'r!)r$r*hrrr __getstate__ds   zSemLock.__getstate__cCs,tjj||_tjd|d|jdS)Nz recreated blocker with handle %rr)rr Z_rebuildrr rr )r$staterrr __setstate__mszSemLock.__setstate__cCsdtjjdttjfS)Nz%s-%sZ semprefix)r current_processZ_confignextr _randrrrrrrszSemLock._make_nameN)__name__ __module__ __qualname__tempfileZ_RandomNameSequencer9r+ staticmethodr#r r/r0r4r6rrrrrr .s"  r c@s&eZdZd ddZddZddZdS) rrcCstj|t|t|ddS)N)r()r r+ SEMAPHORE SEM_VALUE_MAX)r$r&r(rrrr+}szSemaphore.__init__cCs |jjS)N)r _get_value)r$rrr get_valueszSemaphore.get_valuec Cs8y|jj}Wntk r&d}YnXd|jj|fS)Nunknownz<%s(value=%s)>)rrA Exception __class__r:)r$r&rrr__repr__s  zSemaphore.__repr__N)r)r:r;r<r+rBrFrrrrr{s c@seZdZdddZddZdS)rrcCstj|t|||ddS)N)r()r r+r?)r$r&r(rrrr+szBoundedSemaphore.__init__c Cs>y|jj}Wntk r&d}YnXd|jj||jjfS)NrCz<%s(value=%s, maxvalue=%s)>)rrArDrEr:r')r$r&rrrrFs  zBoundedSemaphore.__repr__N)r)r:r;r<r+rFrrrrrs c@seZdZddZddZdS)rcCstj|tdd|ddS)Nr)r()r r+r?)r$r(rrrr+sz Lock.__init__c Csyf|jjr8tjj}tjjdkrd|dtjj7}n,|jjdkrLd}n|jjdkr`d}nd}Wnt k r~d}YnXd |j j |fS) N MainThread|rNonerSomeOtherThreadSomeOtherProcessrCz<%s(owner=%s)>) r_is_miner r7r! threadingcurrent_threadrA_countrDrEr:)r$r!rrrrFs   z Lock.__repr__N)r:r;r<r+rFrrrrrsc@seZdZddZddZdS)rcCstj|tdd|ddS)Nr)r()r r+RECURSIVE_MUTEX)r$r(rrrr+szRLock.__init__c Csy||jjrBtjj}tjjdkr6|dtjj7}|jj}n8|jjdkrZd \}}n |jjdkrrd \}}nd \}}Wnt k rd\}}YnXd |j j ||fS)NrGrHrrIrrJnonzerorKrCz <%s(%s, %s)>)rIr)rJrQ)rKrQ)rCrC) rrLr r7r!rMrNrOrArDrEr:)r$r!countrrrrFs      zRLock.__repr__N)r:r;r<r+rFrrrrrsc@sjeZdZdddZddZddZdd Zd d Zd d ZddZ dddZ ddZ ddZ dddZ dS)rNcCs>|p |j|_|jd|_|jd|_|jd|_|jdS)Nr)r_lockr_sleeping_count _woken_count_wait_semaphorer )r$lockr(rrrr+s    zCondition.__init__cCstj||j|j|j|jfS)N)r r2rSrTrUrV)r$rrrr4s zCondition.__getstate__cCs |\|_|_|_|_|jdS)N)rSrTrUrVr )r$r5rrrr6szCondition.__setstate__cCs |jjS)N)rSr/)r$rrrr/szCondition.__enter__cGs |jj|S)N)rSr0)r$r1rrrr0szCondition.__exit__cCs|jj|_|jj|_dS)N)rSr-r.)r$rrrr s zCondition._make_methodsc CsJy|jjj|jjj}Wntk r4d}YnXd|jj|j|fS)NrCz <%s(%s, %s)>)rTrrArUrDrEr:rS)r$Z num_waitersrrrrFs   zCondition.__repr__c Csn|jj|jjj}xt|D]}|jjq Wz|jjd|S|jjxt|D]}|jjqVWXdS)NT) rTr.rSrrOrrVr-rU)r$timeoutrRr)rrrwaits   zCondition.waitcCsNx|jjdr|jjd}qW|jjdrJ|jj|jj|jjddS)NF)rUr-rTrVr.)r$resrrrnotifys    zCondition.notifycCs|x|jjdr|jjd}qWd}x"|jjdrD|jj|d7}q$W|rxxt|D]}|jjqTWx|jjdrvqhWdS)NFrr)rUr-rTrVr.r)r$rZZsleepersr)rrr notify_alls   zCondition.notify_allcCsh|}|r|S|dk r$tj|}nd}d}x6|sb|dk rP|tj}|dkrPP|j||}q.W|S)Nr)timeZ monotonicrY)r$Z predicaterXresultZendtimeZwaittimerrrwait_for6s   zCondition.wait_for)N)N)N)r:r;r<r+r4r6r/r0r rFrYr[r\r_rrrrrs  c@s6eZdZddZddZddZddZd d d Zd S) rcCs |j|j|_|jd|_dS)Nr)rr_condr_flag)r$r(rrrr+NszEvent.__init__c Cs0|j |jjdr"|jjdSdSQRXdS)NFT)r`rar-r.)r$rrris_setRs   z Event.is_setc Cs6|j&|jjd|jj|jjWdQRXdS)NF)r`rar-r.r\)r$rrrsetYs  z Event.setc Cs"|j|jjdWdQRXdS)NF)r`rar-)r$rrrclear_sz Event.clearNc CsT|jD|jjdr |jjn |jj||jjdrF|jjdSdSQRXdS)NFT)r`rar-r.rY)r$rXrrrrYcs     z Event.wait)N)r:r;r<r+rbrcrdrYrrrrrLs c@sZeZdZdddZddZddZedd Zejd d Zed d Z e jd d Z dS)BarrierNc CsRddl}ddlm}||jdd}|j}|j|||||fd|_d|_dS)Nrr) BufferWrapperr)r)structheaprfZcalcsizerr6_staterO) r$ZpartiesactionrXr(rgrfwrapperZcondrrrr+us zBarrier.__init__cCs.|\|_|_|_|_|_|jjjd|_dS)Nr))_parties_action_timeoutr`_wrapperZcreate_memoryviewcast_array)r$r5rrrr6~szBarrier.__setstate__cCs|j|j|j|j|jfS)N)rlrmrnr`ro)r$rrrr4s zBarrier.__getstate__cCs |jdS)Nr)rq)r$rrrriszBarrier._statecCs||jd<dS)Nr)rq)r$r&rrrriscCs |jdS)Nr)rq)r$rrrrOszBarrier._countcCs||jd<dS)Nr)rq)r$r&rrrrOs)NN) r:r;r<r+r6r4propertyrisetterrOrrrrress   rezRThis platform lacks a functioning sem_open implementation, therefore, the requiredz}This platform lacks a functioning sem_open implementation, therefore, the required synchronization primitives needed will notzThis platform lacks a functioning sem_open implementation, therefore, the required synchronization primitives needed will not function, see issue 3770.)__all__rMrr=rr]r r r r r ImportErrorlistrrPr?r@objectrrrrrrrerrrr s0    Mz'synchronize.cpython-36.pyc000064400000026460147204630710011561 0ustar003 \/ @s,ddddddgZddlZddlZddlZddlZddlZdd lmZdd lmZdd lm Z ydd lm Z m Z Wne k re dYnXe ed\ZZej jZGdddeZ Gddde ZGdddeZGddde ZGddde ZGdddeZGdddeZGdddejZdS)LockRLock SemaphoreBoundedSemaphore ConditionEventN)context)process)util)SemLock sem_unlinkz*This platform lacks a functioning sem_openz( implementation, therefore, the requiredz+ synchronization primitives needed will notz function, see issue 3770.c@s\eZdZejZddZeddZddZ ddZ d d Z d d Z d dZ eddZdS)r c Cs|dkrtjj}|j}tjdkp*|dk}xPtdD]<}y tj||||j |}|_ Wnt k rnYq6XPq6Wt dt j d|j|jtjdkrdd} t j|| |j jdk rdd lm} | |j jt j|tj|j jfd d dS) Nwin32forkdzcannot find name for semaphorezcreated semlock with handle %scSs|jjdS)N)_semlock _after_fork)objr3/usr/lib64/python3.6/multiprocessing/synchronize.pyrGsz%SemLock.__init__.._after_forkr)registerr)Z exitpriority)r Z_default_contextZ get_contextZget_start_methodsysplatformrange_multiprocessingr _make_namerFileExistsErrorr debughandle _make_methodsZregister_after_forknamesemaphore_trackerrZFinalize_cleanup) selfkindvaluemaxvaluectxr!Z unlink_nowislrrrrr__init__2s.       zSemLock.__init__cCs ddlm}t|||dS)Nr) unregister)r"r,r )r!r,rrrr#Ts zSemLock._cleanupcCs|jj|_|jj|_dS)N)racquirerelease)r$rrrr Zs zSemLock._make_methodscCs |jjS)N)r __enter__)r$rrrr/^szSemLock.__enter__cGs |jj|S)N)r__exit__)r$argsrrrr0aszSemLock.__exit__cCsDtj||j}tjdkr,tjj|j}n|j}||j|j |j fS)Nr) r assert_spawningrrrZget_spawning_popenZduplicate_for_childrr%r'r!)r$r*hrrr __getstate__ds   zSemLock.__getstate__cCs,tjj||_tjd|d|jdS)Nz recreated blocker with handle %rr)rr Z_rebuildrr rr )r$staterrr __setstate__mszSemLock.__setstate__cCsdtjjdttjfS)Nz%s-%sZ semprefix)r current_processZ_confignextr _randrrrrrrszSemLock._make_nameN)__name__ __module__ __qualname__tempfileZ_RandomNameSequencer9r+ staticmethodr#r r/r0r4r6rrrrrr .s"  r c@s&eZdZd ddZddZddZdS) rrcCstj|t|t|ddS)N)r()r r+ SEMAPHORE SEM_VALUE_MAX)r$r&r(rrrr+}szSemaphore.__init__cCs |jjS)N)r _get_value)r$rrr get_valueszSemaphore.get_valuec Cs8y|jj}Wntk r&d}YnXd|jj|fS)Nunknownz<%s(value=%s)>)rrA Exception __class__r:)r$r&rrr__repr__s  zSemaphore.__repr__N)r)r:r;r<r+rBrFrrrrr{s c@seZdZdddZddZdS)rrcCstj|t|||ddS)N)r()r r+r?)r$r&r(rrrr+szBoundedSemaphore.__init__c Cs>y|jj}Wntk r&d}YnXd|jj||jjfS)NrCz<%s(value=%s, maxvalue=%s)>)rrArDrEr:r')r$r&rrrrFs  zBoundedSemaphore.__repr__N)r)r:r;r<r+rFrrrrrs c@seZdZddZddZdS)rcCstj|tdd|ddS)Nr)r()r r+r?)r$r(rrrr+sz Lock.__init__c Csyf|jjr8tjj}tjjdkrd|dtjj7}n,|jjdkrLd}n|jjdkr`d}nd}Wnt k r~d}YnXd |j j |fS) N MainThread|rNonerSomeOtherThreadSomeOtherProcessrCz<%s(owner=%s)>) r_is_miner r7r! threadingcurrent_threadrA_countrDrEr:)r$r!rrrrFs   z Lock.__repr__N)r:r;r<r+rFrrrrrsc@seZdZddZddZdS)rcCstj|tdd|ddS)Nr)r()r r+RECURSIVE_MUTEX)r$r(rrrr+szRLock.__init__c Csy||jjrBtjj}tjjdkr6|dtjj7}|jj}n8|jjdkrZd \}}n |jjdkrrd \}}nd \}}Wnt k rd\}}YnXd |j j ||fS)NrGrHrrIrrJnonzerorKrCz <%s(%s, %s)>)rIr)rJrQ)rKrQ)rCrC) rrLr r7r!rMrNrOrArDrEr:)r$r!countrrrrFs      zRLock.__repr__N)r:r;r<r+rFrrrrrsc@sjeZdZdddZddZddZdd Zd d Zd d ZddZ dddZ ddZ ddZ dddZ dS)rNcCs>|p |j|_|jd|_|jd|_|jd|_|jdS)Nr)r_lockr_sleeping_count _woken_count_wait_semaphorer )r$lockr(rrrr+s    zCondition.__init__cCstj||j|j|j|jfS)N)r r2rSrTrUrV)r$rrrr4s zCondition.__getstate__cCs |\|_|_|_|_|jdS)N)rSrTrUrVr )r$r5rrrr6szCondition.__setstate__cCs |jjS)N)rSr/)r$rrrr/szCondition.__enter__cGs |jj|S)N)rSr0)r$r1rrrr0szCondition.__exit__cCs|jj|_|jj|_dS)N)rSr-r.)r$rrrr s zCondition._make_methodsc CsJy|jjj|jjj}Wntk r4d}YnXd|jj|j|fS)NrCz <%s(%s, %s)>)rTrrArUrDrEr:rS)r$Z num_waitersrrrrFs   zCondition.__repr__c Cs|jjjstd|jj|jjj}xt|D]}|jjq4Wz|jj d|S|j jxt|D]}|jj qjWXdS)Nz,must acquire() condition before using wait()T) rSrrLAssertionErrorrTr.rOrrVr-rU)r$timeoutrRr)rrrwaits   zCondition.waitcCs||jjjstd|jjd s&tx$|jjdrJ|jjd}|s(tq(W|jjdrx|jj|jj|jjddS)Nzlock is not ownedF) rSrrLrXrVr-rUrTr.)r$resrrrnotifys     zCondition.notifycCs|jjjstd|jjd s&tx$|jjdrJ|jjd}|s(tq(Wd}x"|jjdrr|jj|d7}qRW|rxt |D]}|jjqWx|jjdrqWdS)Nzlock is not ownedFrr) rSrrLrXrVr-rUrTr.r)r$r[Zsleepersr)rrr notify_alls    zCondition.notify_allcCsh|}|r|S|dk r$tj|}nd}d}x6|sb|dk rP|tj}|dkrPP|j||}q.W|S)Nr)timeZ monotonicrZ)r$Z predicaterYresultZendtimeZwaittimerrrwait_for6s   zCondition.wait_for)N)N)N)r:r;r<r+r4r6r/r0r rFrZr\r]r`rrrrrs  c@s6eZdZddZddZddZddZd d d Zd S) rcCs |j|j|_|jd|_dS)Nr)rr_condr_flag)r$r(rrrr+NszEvent.__init__c Cs0|j |jjdr"|jjdSdSQRXdS)NFT)rarbr-r.)r$rrris_setRs   z Event.is_setc Cs6|j&|jjd|jj|jjWdQRXdS)NF)rarbr-r.r])r$rrrsetYs  z Event.setc Cs"|j|jjdWdQRXdS)NF)rarbr-)r$rrrclear_sz Event.clearNc CsT|jD|jjdr |jjn |jj||jjdrF|jjdSdSQRXdS)NFT)rarbr-r.rZ)r$rYrrrrZcs     z Event.wait)N)r:r;r<r+rcrdrerZrrrrrLs c@sZeZdZdddZddZddZedd Zejd d Zed d Z e jd d Z dS)BarrierNc CsRddl}ddlm}||jdd}|j}|j|||||fd|_d|_dS)Nrr) BufferWrapperr)r)structheaprgZcalcsizerr6_staterO) r$ZpartiesactionrYr(rhrgwrapperZcondrrrr+us zBarrier.__init__cCs.|\|_|_|_|_|_|jjjd|_dS)Nr))_parties_action_timeoutra_wrapperZcreate_memoryviewcast_array)r$r5rrrr6~szBarrier.__setstate__cCs|j|j|j|j|jfS)N)rmrnrorarp)r$rrrr4s zBarrier.__getstate__cCs |jdS)Nr)rr)r$rrrrjszBarrier._statecCs||jd<dS)Nr)rr)r$r&rrrrjscCs |jdS)Nr)rr)r$rrrrOszBarrier._countcCs||jd<dS)Nr)rr)r$r&rrrrOs)NN) r:r;r<r+r6r4propertyrjsetterrOrrrrrfss   rfzRThis platform lacks a functioning sem_open implementation, therefore, the requiredz}This platform lacks a functioning sem_open implementation, therefore, the required synchronization primitives needed will notzThis platform lacks a functioning sem_open implementation, therefore, the required synchronization primitives needed will not function, see issue 3770.)__all__rMrr=rr^r r r r r ImportErrorlistrrPr?r@objectrrrrrrrfrrrr s0    Mz'util.cpython-36.opt-1.pyc000064400000016074147204630710011122 0ustar003 \-@sddlZddlZddlZddlZejdkrBddZddZddZejd krlejd krldd l m Z d dZnejd krddl Z ddl Z d dZejdkrddZnddZejjd%rddZddZn6ejdkrddZd&ddZnddZdd Zd!dZd"d#Zed$kredS)'NntcCsd}tjj|}|d krdS|t|}tj|djdd\}}t|dd d}|dkrf|d7}t|ddd }|dkrd }|dkr||SdS) zReturn the version of MSVC that was used to build Python. For Python 2.3 and up, the version number is included in sys.version. For earlier versions, assume the compiler is MSVC 6. zMSC v.N  g$@r)sysversionfindlensplitint)prefixisrestZ majorVersionZ minorVersionr#/usr/lib64/python3.6/ctypes/util.py_get_build_version s  rcCs^t}|dkrdS|dkr d}n|dkr6d|d}ndSddl}d|jjkrV|d 7}|d S) z%Return the name of the VC runtime dllNrmsvcrtrzmsvcr%d rz_d.pyddz.dll)rimportlib.machinery machineryEXTENSION_SUFFIXES)r Zclibname importlibrrr find_msvcrt"s rcCst|dkrtSx`tjdjtjD]J}tjj||}tjj|rD|S|jj drTq"|d}tjj|r"|Sq"WdS)NcmPATHz.dll)r r!) rosenvironrpathseppathjoinisfilelowerendswith)nameZ directoryZfnamerrr find_library7s  r,posixdarwin) dyld_findc CsLd|d|d||fg}x,|D]$}yt|Stk rBw Yq Xq WdS)Nz lib%s.dylibz%s.dylibz%s.framework/%s) _dyld_find ValueError)r+possiblerrrr,Hs  c !Cstjdtj|}tjd}|s,tjd}|s4dStj}z||dd|jd|g}t tj }d|d<d|d <yt j |t j t j|d }Wntk rdSX||jj}WdQRXWdy |jWntk rYnXXtj||}|sdStj|jd S) Nz[^\(\)\s]*lib%s\.[^\(\)\s]*gccZccz-Wl,-tz-oz-lCLC_ALLLANG)stdoutstderrenvr)r#fsencodereescapeshutilwhichtempfileZNamedTemporaryFiler+dictr$ subprocessPopenPIPEZSTDOUTOSErrorr7readcloseFileNotFoundErrorsearchfsdecodegroup) r+exprZ c_compilerZtempargsr9procZtraceresrrr _findLib_gccWs:      rOZsunos5cCsz|sdSytjdd|ftjtjd}Wntk r:dSX||jj}WdQRXtjd|}|sjdSt j |j dS)Nz/usr/ccs/bin/dumpz-Lpv)r7r8s\[.*\]\sSONAME\s+([^\s]+)r) rArBrCDEVNULLrDr7rEr;rHr#rIrJ)frMdatarNrrr _get_sonames  rScCs|sdStjd}|sdSy"tj|ddd|ftjtjd}Wntk rPdSX||jj}WdQRXt j d|}|sdSt j |j dS)Nobjdumpz-pz-jz.dynamic)r7r8s\sSONAME\s+([^\s]+)r)r=r>rArBrCrPrDr7rEr;rHr#rIrJ)rQrTrMdumprNrrrrSs"  freebsdopenbsd dragonflyc CsR|jd}g}y"x|r,|jdt|jqWWntk rDYnX|pPtjgS)N.r)rinsertrpopr1r maxsize)ZlibnamepartsZnumsrrr _num_versions r^cCstj|}d||f}tj|}ytjdtjtjd}Wntk rPd}YnX||j j }WdQRXtj ||}|st t |S|jtdtj|d S) Nz:-l%s\.\S+ => \S*/(lib%s\.\S+)/sbin/ldconfig-r)r7r8)keyr)r_r`r )r;r<r#r:rArBrCrPrDr7rEfindallrSrOsortr^rI)r+ZenamerKrMrRrNrrrr,s        c CstjjdsdSttj}d|d<|r,d }nd }d}ytj|tjtj|d}Wnt k rbdSX|:x2|j D](}|j }|j drrtj |jd}qrWWdQRX|sdSx4|jdD]&}tjj|d |}tjj|r|SqWdS) N /usr/bin/crler4r5-64)r7r8r9sDefault Library Path (ELF)::zlib%s.so)rerf)re)r#r&existsr@r$rArBrCrPrDr7strip startswithrIrr') r+is64r9rLpathsrMlinedirZlibfilerrr _findLib_crles6       rpFcCstt||pt|S)N)rSrprO)r+rlrrrr,scCsddl}|jddkr&tjjd}ntjjd}dddddd }|j|d }d }tj|tj||f}yZt j d d gt j t j t j dddd,}tj ||jj}|rtj|jdSWdQRXWntk rYnXdS)Nrlrgz-32z-64z libc6,x86-64z libc6,64bitz libc6,IA-64)z x86_64-64zppc64-64z sparc64-64zs390x-64zia64-64Zlibc6z\s+(lib%s\.[^\s]+)\s+\(%sz/sbin/ldconfigz-pr4)r5r6)stdinr8r7r9r)structZcalcsizer#unamemachinegetr:r;r<rArBrPrCrHr7rErIrJrD)r+rsruZmach_mapZabi_typeZregexprNrrr_findSoname_ldconfigs.  rxc Csdtj|}ddg}tjjd}|rHx |jdD]}|jd|gq2W|jdtjd|gd}yFtj |tj tj d d }|j \}}tj |tj |} | r| jd }Wn"tk r} zWYdd} ~ XnX|S) Nz[^\(\)\s]*lib%s\.[^\(\)\s]*Zldz-tZLD_LIBRARY_PATHrhz-Lz-oz-l%sT)r7r8Zuniversal_newlinesr)r;r<r#r$rvrextenddevnullrArBrCZ communicaterHrIrJ Exception) r+rKcmdZlibpathrresultrwout_rNerrr _findLib_lds&   rcCst|ptt|pt|S)N)rxrSrOr)r+rrrr,,scCsddlm}tjdkr:t|jt|jdttdtjdkrttdttdttdtj d krt|j d t|j d t|j d t|j d n(t|j dt|j dttddS)Nr)cdllrrr-r!r bz2r.z libm.dylibzlibcrypto.dylibzlibSystem.dylibzSystem.framework/Systemzlibm.soz libcrypt.soZcrypt) Zctypesrr#r+printrloadr,r platformZ LoadLibrary)rrrrtest4s"         r__main__)rVrWrX)F)r#r=rAr r+rrr,rZctypes.macholib.dyldr/r0r;r?rOrSrkr^rprxrr__name__rrrrs8   +     $  util.cpython-36.opt-2.pyc000064400000015504147204630710011120 0ustar003 \-@sddlZddlZddlZddlZejdkrBddZddZddZejd krlejd krldd l m Z d dZnejd krddl Z ddl Z d dZejdkrddZnddZejjd%rddZddZn6ejdkrddZd&ddZnddZdd Zd!dZd"d#Zed$kredS)'NntcCsd}tjj|}|d krdS|t|}tj|djdd\}}t|dd d}|dkrf|d7}t|ddd}|dkrd }|dkr||SdS) NzMSC v.  g$@r)sysversionfindlensplitint)prefixisrestZ majorVersionZ minorVersionr#/usr/lib64/python3.6/ctypes/util.py_get_build_version s  rcCs^t}|dkrdS|dkr d}n|dkr6d|d}ndSddl}d|jjkrV|d7}|d S) Nrmsvcrtrzmsvcr%d rz_d.pyddz.dll)rimportlib.machinery machineryEXTENSION_SUFFIXES)r Zclibname importlibrrr find_msvcrt"s rcCst|dkrtSx`tjdjtjD]J}tjj||}tjj|rD|S|jj drTq"|d}tjj|r"|Sq"WdS)NcmPATHz.dll)r r!) rosenvironrpathseppathjoinisfilelowerendswith)nameZ directoryZfnamerrr find_library7s  r,posixdarwin) dyld_findc CsLd|d|d||fg}x,|D]$}yt|Stk rBw Yq Xq WdS)Nz lib%s.dylibz%s.dylibz%s.framework/%s) _dyld_find ValueError)r+possiblerrrr,Hs  c !Cstjdtj|}tjd}|s,tjd}|s4dStj}z||dd|jd|g}t tj }d|d<d|d <yt j |t j t j|d }Wntk rdSX||jj}WdQRXWdy |jWntk rYnXXtj||}|sdStj|jd S) Nz[^\(\)\s]*lib%s\.[^\(\)\s]*gccZccz-Wl,-tz-oz-lCLC_ALLLANG)stdoutstderrenvr)r#fsencodereescapeshutilwhichtempfileZNamedTemporaryFiler+dictr$ subprocessPopenPIPEZSTDOUTOSErrorr7readcloseFileNotFoundErrorsearchfsdecodegroup) r+exprZ c_compilerZtempargsr9procZtraceresrrr _findLib_gccWs:      rOZsunos5cCsz|sdSytjdd|ftjtjd}Wntk r:dSX||jj}WdQRXtjd|}|sjdSt j |j dS)Nz/usr/ccs/bin/dumpz-Lpv)r7r8s\[.*\]\sSONAME\s+([^\s]+)r) rArBrCDEVNULLrDr7rEr;rHr#rIrJ)frMdatarNrrr _get_sonames  rScCs|sdStjd}|sdSy"tj|ddd|ftjtjd}Wntk rPdSX||jj}WdQRXt j d|}|sdSt j |j dS)Nobjdumpz-pz-jz.dynamic)r7r8s\sSONAME\s+([^\s]+)r)r=r>rArBrCrPrDr7rEr;rHr#rIrJ)rQrTrMdumprNrrrrSs"  freebsdopenbsd dragonflyc CsR|jd}g}y"x|r,|jdt|jqWWntk rDYnX|pPtjgS)N.r)rinsertrpopr1r maxsize)ZlibnamepartsZnumsrrr _num_versions r^cCstj|}d||f}tj|}ytjdtjtjd}Wntk rPd}YnX||j j }WdQRXtj ||}|st t |S|jtdtj|d S) Nz:-l%s\.\S+ => \S*/(lib%s\.\S+)/sbin/ldconfig-r)r7r8)keyr)r_r`r )r;r<r#r:rArBrCrPrDr7rEfindallrSrOsortr^rI)r+ZenamerKrMrRrNrrrr,s        c CstjjdsdSttj}d|d<|r,d }nd }d}ytj|tjtj|d}Wnt k rbdSX|:x2|j D](}|j }|j drrtj |jd}qrWWdQRX|sdSx4|jdD]&}tjj|d |}tjj|r|SqWdS) N /usr/bin/crler4r5-64)r7r8r9sDefault Library Path (ELF)::zlib%s.so)rerf)re)r#r&existsr@r$rArBrCrPrDr7strip startswithrIrr') r+is64r9rLpathsrMlinedirZlibfilerrr _findLib_crles6       rpFcCstt||pt|S)N)rSrprO)r+rlrrrr,scCsddl}|jddkr&tjjd}ntjjd}dddddd }|j|d }d }tj|tj||f}yZt j d d gt j t j t j dddd,}tj ||jj}|rtj|jdSWdQRXWntk rYnXdS)Nrlrgz-32z-64z libc6,x86-64z libc6,64bitz libc6,IA-64)z x86_64-64zppc64-64z sparc64-64zs390x-64zia64-64Zlibc6z\s+(lib%s\.[^\s]+)\s+\(%sz/sbin/ldconfigz-pr4)r5r6)stdinr8r7r9r)structZcalcsizer#unamemachinegetr:r;r<rArBrPrCrHr7rErIrJrD)r+rsruZmach_mapZabi_typeZregexprNrrr_findSoname_ldconfigs.  rxc Csdtj|}ddg}tjjd}|rHx |jdD]}|jd|gq2W|jdtjd|gd}yFtj |tj tj d d }|j \}}tj |tj |} | r| jd }Wn"tk r} zWYdd} ~ XnX|S) Nz[^\(\)\s]*lib%s\.[^\(\)\s]*Zldz-tZLD_LIBRARY_PATHrhz-Lz-oz-l%sT)r7r8Zuniversal_newlinesr)r;r<r#r$rvrextenddevnullrArBrCZ communicaterHrIrJ Exception) r+rKcmdZlibpathrresultrwout_rNerrr _findLib_lds&   rcCst|ptt|pt|S)N)rxrSrOr)r+rrrr,,scCsddlm}tjdkr:t|jt|jdttdtjdkrttdttdttdtj d krt|j d t|j d t|j d t|j d n(t|j dt|j dttddS)Nr)cdllrrr-r!r bz2r.z libm.dylibzlibcrypto.dylibzlibSystem.dylibzSystem.framework/Systemzlibm.soz libcrypt.soZcrypt) Zctypesrr#r+printrloadr,r platformZ LoadLibrary)rrrrtest4s"         r__main__)rVrWrX)F)r#r=rAr r+rrr,rZctypes.macholib.dyldr/r0r;r?rOrSrkr^rprxrr__name__rrrrs8   +     $  util.cpython-36.pyc000064400000016074147204630710010163 0ustar003 \-@sddlZddlZddlZddlZejdkrBddZddZddZejd krlejd krldd l m Z d dZnejd krddl Z ddl Z d dZejdkrddZnddZejjd%rddZddZn6ejdkrddZd&ddZnddZdd Zd!dZd"d#Zed$kredS)'NntcCsd}tjj|}|d krdS|t|}tj|djdd\}}t|dd d}|dkrf|d7}t|ddd }|dkrd }|dkr||SdS) zReturn the version of MSVC that was used to build Python. For Python 2.3 and up, the version number is included in sys.version. For earlier versions, assume the compiler is MSVC 6. zMSC v.N  g$@r)sysversionfindlensplitint)prefixisrestZ majorVersionZ minorVersionr#/usr/lib64/python3.6/ctypes/util.py_get_build_version s  rcCs^t}|dkrdS|dkr d}n|dkr6d|d}ndSddl}d|jjkrV|d 7}|d S) z%Return the name of the VC runtime dllNrmsvcrtrzmsvcr%d rz_d.pyddz.dll)rimportlib.machinery machineryEXTENSION_SUFFIXES)r Zclibname importlibrrr find_msvcrt"s rcCst|dkrtSx`tjdjtjD]J}tjj||}tjj|rD|S|jj drTq"|d}tjj|r"|Sq"WdS)NcmPATHz.dll)r r!) rosenvironrpathseppathjoinisfilelowerendswith)nameZ directoryZfnamerrr find_library7s  r,posixdarwin) dyld_findc CsLd|d|d||fg}x,|D]$}yt|Stk rBw Yq Xq WdS)Nz lib%s.dylibz%s.dylibz%s.framework/%s) _dyld_find ValueError)r+possiblerrrr,Hs  c !Cstjdtj|}tjd}|s,tjd}|s4dStj}z||dd|jd|g}t tj }d|d<d|d <yt j |t j t j|d }Wntk rdSX||jj}WdQRXWdy |jWntk rYnXXtj||}|sdStj|jd S) Nz[^\(\)\s]*lib%s\.[^\(\)\s]*gccZccz-Wl,-tz-oz-lCLC_ALLLANG)stdoutstderrenvr)r#fsencodereescapeshutilwhichtempfileZNamedTemporaryFiler+dictr$ subprocessPopenPIPEZSTDOUTOSErrorr7readcloseFileNotFoundErrorsearchfsdecodegroup) r+exprZ c_compilerZtempargsr9procZtraceresrrr _findLib_gccWs:      rOZsunos5cCsz|sdSytjdd|ftjtjd}Wntk r:dSX||jj}WdQRXtjd|}|sjdSt j |j dS)Nz/usr/ccs/bin/dumpz-Lpv)r7r8s\[.*\]\sSONAME\s+([^\s]+)r) rArBrCDEVNULLrDr7rEr;rHr#rIrJ)frMdatarNrrr _get_sonames  rScCs|sdStjd}|sdSy"tj|ddd|ftjtjd}Wntk rPdSX||jj}WdQRXt j d|}|sdSt j |j dS)Nobjdumpz-pz-jz.dynamic)r7r8s\sSONAME\s+([^\s]+)r)r=r>rArBrCrPrDr7rEr;rHr#rIrJ)rQrTrMdumprNrrrrSs"  freebsdopenbsd dragonflyc CsR|jd}g}y"x|r,|jdt|jqWWntk rDYnX|pPtjgS)N.r)rinsertrpopr1r maxsize)ZlibnamepartsZnumsrrr _num_versions r^cCstj|}d||f}tj|}ytjdtjtjd}Wntk rPd}YnX||j j }WdQRXtj ||}|st t |S|jtdtj|d S) Nz:-l%s\.\S+ => \S*/(lib%s\.\S+)/sbin/ldconfig-r)r7r8)keyr)r_r`r )r;r<r#r:rArBrCrPrDr7rEfindallrSrOsortr^rI)r+ZenamerKrMrRrNrrrr,s        c CstjjdsdSttj}d|d<|r,d }nd }d}ytj|tjtj|d}Wnt k rbdSX|:x2|j D](}|j }|j drrtj |jd}qrWWdQRX|sdSx4|jdD]&}tjj|d |}tjj|r|SqWdS) N /usr/bin/crler4r5-64)r7r8r9sDefault Library Path (ELF)::zlib%s.so)rerf)re)r#r&existsr@r$rArBrCrPrDr7strip startswithrIrr') r+is64r9rLpathsrMlinedirZlibfilerrr _findLib_crles6       rpFcCstt||pt|S)N)rSrprO)r+rlrrrr,scCsddl}|jddkr&tjjd}ntjjd}dddddd }|j|d }d }tj|tj||f}yZt j d d gt j t j t j dddd,}tj ||jj}|rtj|jdSWdQRXWntk rYnXdS)Nrlrgz-32z-64z libc6,x86-64z libc6,64bitz libc6,IA-64)z x86_64-64zppc64-64z sparc64-64zs390x-64zia64-64Zlibc6z\s+(lib%s\.[^\s]+)\s+\(%sz/sbin/ldconfigz-pr4)r5r6)stdinr8r7r9r)structZcalcsizer#unamemachinegetr:r;r<rArBrPrCrHr7rErIrJrD)r+rsruZmach_mapZabi_typeZregexprNrrr_findSoname_ldconfigs.  rxc Csdtj|}ddg}tjjd}|rHx |jdD]}|jd|gq2W|jdtjd|gd}yFtj |tj tj d d }|j \}}tj |tj |} | r| jd }Wn"tk r} zWYdd} ~ XnX|S) Nz[^\(\)\s]*lib%s\.[^\(\)\s]*Zldz-tZLD_LIBRARY_PATHrhz-Lz-oz-l%sT)r7r8Zuniversal_newlinesr)r;r<r#r$rvrextenddevnullrArBrCZ communicaterHrIrJ Exception) r+rKcmdZlibpathrresultrwout_rNerrr _findLib_lds&   rcCst|ptt|pt|S)N)rxrSrOr)r+rrrr,,scCsddlm}tjdkr:t|jt|jdttdtjdkrttdttdttdtj d krt|j d t|j d t|j d t|j d n(t|j dt|j dttddS)Nr)cdllrrr-r!r bz2r.z libm.dylibzlibcrypto.dylibzlibSystem.dylibzSystem.framework/Systemzlibm.soz libcrypt.soZcrypt) Zctypesrr#r+printrloadr,r platformZ LoadLibrary)rrrrtest4s"         r__main__)rVrWrX)F)r#r=rAr r+rrr,rZctypes.macholib.dyldr/r0r;r?rOrSrkr^rprxrr__name__rrrrs8   +     $  connection.cpython-36.opt-1.pyc000064400000057737147204630710012317 0ustar003 fVy @s ddddgZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl m Z ddl m Z m Z dd lmZejZy$ddlZdd lmZmZmZmZWn$ek rejd kr‚dZYnXd Zd ZdZejZdZdgZe edrdZedg7Zejd krdZedg7ZefddZ!ddZ"ddZ#ddZ$ddZ%GdddZ&ernGddde&Z'Gd d!d!e&Z(Gd"dde)Z*dPd#dZ+ejd krdQd%dZ,n dRd&dZ,Gd'd(d(e)Z-d)d*Z.ejd krGd+d,d,e)Z/d-d.Z0d/Z1d0Z2d1Z3d2Z4d3d4Z5d5d6Z6Gd7d8d8e)Z7d9d:Z8d;d<Z9Gd=d>d>e*Z:d?d@Z;ejd krzdAdBZhZ?dSdCdZ@n,ddlAZAe eAdDreAjBZCneAjDZCdTdEdZ@ejd krdFdGZEdHdIZFejGe(eEdJdKZHdLdMZIejGe'eHndNdGZEdOdIZFejGe(eEdS)UClientListenerPipewaitN)util)AuthenticationErrorBufferTooShort) reduction) WAIT_OBJECT_0WAIT_ABANDONED_0 WAIT_TIMEOUTINFINITEwin32i g4@Zsha256AF_INETAF_UNIXAF_PIPEcCs tj|S)N)time monotonic)timeoutr2/usr/lib64/python3.6/multiprocessing/connection.py _init_timeout?srcCs tj|kS)N)rr)trrr_check_timeoutBsrcCsX|dkr d S|dkr&tjdtjdS|dkrLtjdtjttfd dStd d S) z? Return an arbitrary free address for the given family r localhostrrz listener-)prefixdirrz\\.\pipe\pyc-%d-%d-zunrecognized familyN)rr) tempfileZmktemprZ get_temp_dirosgetpidnext _mmap_counter ValueError)familyrrrarbitrary_addressIsr&cCsJtjdkr|dkrtd|tjdkrF|dkrFtt|sFtd|dS)zD Checks if the family is valid for the current environment. rrzFamily %s is not recognized.rN)sysplatformr$hasattrsocket)r%rrr_validate_familyWs   r+cCsJt|tkrdSt|tkr*|jdr*dSt|tkr:dStd|dS)z] Return the types of the address This can be 'AF_INET', 'AF_UNIX', or 'AF_PIPE' rz\\rrzaddress type of %r unrecognizedN)typetuplestr startswithr$)addressrrr address_typecs  r1c@seZdZdZd+ddZddZddZd d Zd d Zd dZ e ddZ e ddZ e ddZ ddZddZd,ddZddZd-ddZd.d d!Zd"d#Zd/d%d&Zd'd(Zd)d*ZdS)0_ConnectionBaseNTcCsB|j}|dkrtd| r,| r,td||_||_||_dS)Nrzinvalid handlez6at least one of `readable` and `writable` must be True) __index__r$_handle _readable _writable)selfhandlereadablewritablerrr__init__ys z_ConnectionBase.__init__cCs|jdk r|jdS)N)r4_close)r7rrr__del__s z_ConnectionBase.__del__cCs|jdkrtddS)Nzhandle is closed)r4OSError)r7rrr _check_closeds z_ConnectionBase._check_closedcCs|jstddS)Nzconnection is write-only)r5r>)r7rrr_check_readablesz_ConnectionBase._check_readablecCs|jstddS)Nzconnection is read-only)r6r>)r7rrr_check_writablesz_ConnectionBase._check_writablecCs"|jrd|_n|jtddS)NFzbad message length)r6r5closer>)r7rrr_bad_message_lengthsz#_ConnectionBase._bad_message_lengthcCs |jdkS)z True if the connection is closedN)r4)r7rrrclosedsz_ConnectionBase.closedcCs|jS)z"True if the connection is readable)r5)r7rrrr9sz_ConnectionBase.readablecCs|jS)z"True if the connection is writable)r6)r7rrrr:sz_ConnectionBase.writablecCs|j|jS)z+File descriptor or handle of the connection)r?r4)r7rrrfilenosz_ConnectionBase.filenoc Cs$|jdk r z |jWdd|_XdS)zClose the connectionN)r4r<)r7rrrrBs  z_ConnectionBase.closercCs|j|jt|}|jdkr.tt|}t|}|dkrFtd||krVtd|dkrh||}n&|dkrztdn|||krtd|j||||dS)z,Send the bytes data from a bytes-like objectrrzoffset is negativezbuffer length < offsetNzsize is negativezbuffer length < offset + size)r?rA memoryviewitemsizebyteslenr$ _send_bytes)r7bufoffsetsizemnrrr send_bytess"     z_ConnectionBase.send_bytescCs$|j|j|jtj|dS)zSend a (picklable) objectN)r?rArJ_ForkingPicklerdumps)r7objrrrsendsz_ConnectionBase.sendcCsJ|j|j|dk r(|dkr(td|j|}|dkrB|j|jS)z7 Receive bytes data as a bytes object. Nrznegative maxlength)r?r@r$ _recv_bytesrCgetvalue)r7Z maxlengthrKrrr recv_bytess z_ConnectionBase.recv_bytesc Cs|j|jt|}|j}|t|}|dkr>tdn||krNtd|j}|j}|||krvt|j |j d|j |||||||SQRXdS)zq Receive bytes data into a writeable bytes-like object. Return the number of bytes read. rznegative offsetzoffset too largeN) r?r@rFrGrIr$rUtellr rVseekreadinto)r7rKrLrNrGZbytesizeresultrMrrrrecv_bytes_intos"       z_ConnectionBase.recv_bytes_intocCs&|j|j|j}tj|jS)zReceive a (picklable) object)r?r@rUrQloads getbuffer)r7rKrrrrecvsz_ConnectionBase.recvcCs|j|j|j|S)z/Whether there is any input available to be read)r?r@_poll)r7rrrrpollsz_ConnectionBase.pollcCs|S)Nr)r7rrr __enter__sz_ConnectionBase.__enter__cCs |jdS)N)rB)r7exc_type exc_valueexc_tbrrr__exit__ sz_ConnectionBase.__exit__)TT)rN)N)r)r`)__name__ __module__ __qualname__r4r;r=r?r@rArCpropertyrDr9r:rErBrPrTrWr\r_rbrcrgrrrrr2vs(       r2c@sDeZdZdZdZejfddZddZddd Z d d Z d d Z dS)PipeConnectionz Connection class based on a Windows named pipe. Overlapped I/O is used, so the handles must have been created with FILE_FLAG_OVERLAPPED. FcCs||jdS)N)r4)r7Z _CloseHandlerrrr<szPipeConnection._closecCshtj|j|dd\}}zwinerrorERROR_BROKEN_PIPEEOFError RuntimeError) r7maxsizeZbsizertrurvZnreadferrrrU*s6      zPipeConnection._recv_bytescCs.|jstj|jddkrdStt|g|S)NrT)rxrn PeekNamedPiper4boolr)r7rrrrraJszPipeConnection._pollcCs|j}tj}|j|tj|jd}|dk rJt|||krJ|jtj |j|dd\}}|j d\}}|j|j|S)NrT)rm) r^ryrzr}rnrr4rIrCr|rs)r7rtrrKrleftruZrbytesrrrr~Ps zPipeConnection._get_more_data)N) rhrirj__doc__rxrn CloseHandler<rJrUrar~rrrrrls rlc@s|eZdZdZer,ejfddZejZ ej Z ne j fddZe jZ e jZ e fddZe fddZd d Zdd d ZddZd S) Connectionzo Connection class based on an arbitrary file descriptor (Unix only), or a socket handle (Windows). cCs||jdS)N)r4)r7r<rrrr<gszConnection._closecCs||jdS)N)r4)r7r<rrrr<lscCs<t|}x.||j|}||8}|dkr(P||d}q WdS)Nr)rIr4)r7rKr} remainingrOrrr_sendqs zConnection._sendcCsftj}|j}|}xN|dkr`|||}t|}|dkrL||krDtntd|j|||8}qW|S)Nrzgot end of file during message)ryrzr4rIrr>r})r7rMreadrKr8rchunkrOrrr_recvzs    zConnection._recvcCsDt|}tjd|}|dkr2|j||j|n|j||dS)Nz!ii@)rIstructZpackr)r7rKrOheaderrrrrJs    zConnection._send_bytesNcCs:|jd}tjd|j\}|dk r0||kr0dS|j|S)Nz!i)rrZunpackrV)r7rrKrMrrrrUs  zConnection._recv_bytescCst|g|}t|S)N)rr)r7rrrrrras zConnection._poll)N)rhrirjrrn_multiprocessingZ closesocketr<rTZ_writer_Z_readr rBr}rrrrJrUrarrrrr`s  rc@sReZdZdZdddZddZdd Zed d Zed d Z d dZ ddZ dS)rz Returns a listener object. This is a wrapper for a bound socket which is 'listening' for connections, or for a Windows named pipe. NrcCsr|p|rt|pt}|pt|}t||dkr>t|||_nt||||_|dk rht|t rht d||_ dS)Nrzauthkey should be a byte string) r1default_familyr&r+ PipeListener _listenerSocketListener isinstancerH TypeError_authkey)r7r0r%backlogauthkeyrrrr;s zListener.__init__cCs>|jdkrtd|jj}|jr:t||jt||j|S)zz Accept a connection on the bound socket or named pipe of `self`. Returns a `Connection` object. Nzlistener is closed)rr>acceptrdeliver_challengeanswer_challenge)r7crrrrs    zListener.acceptcCs |j}|dk rd|_|jdS)zA Close the bound socket or named pipe of `self`. N)rrB)r7ZlistenerrrrrBszListener.closecCs|jjS)N)r_address)r7rrrszListener.cCs|jjS)N)r_last_accepted)r7rrrrscCs|S)Nr)r7rrrrcszListener.__enter__cCs |jdS)N)rB)r7rdrerfrrrrgszListener.__exit__)NNrN) rhrirjrr;rrBrkr0Z last_acceptedrcrgrrrrrs   cCsj|p t|}t||dkr&t|}nt|}|dk rJt|t rJtd|dk rft||t|||S)z= Returns a connection to the address of a `Listener` rNzauthkey should be a byte string) r1r+ PipeClient SocketClientrrHrrr)r0r%rrrrrrs    TcCsj|r>tj\}}|jd|jdt|j}t|j}n$tj\}}t|dd}t|dd}||fS)zL Returns pair of connection objects at either end of a pipe TF)r:)r9)r*Z socketpair setblockingrdetachr pipe)duplexs1s2c1c2Zfd1Zfd2rrrrs       c Cstd}|r*tj}tjtjB}tt}}ntj}tj}dt}}tj||tjBtj Btj tj Btj Bd||tj tj}tj||dtjtjtjtj}tj|tj ddtj|dd}|jd\} } t||d} t||d} | | fS) zL Returns pair of connection objects at either end of a pipe rrrNT)rm)r:)r9)r&rnPIPE_ACCESS_DUPLEX GENERIC_READ GENERIC_WRITEBUFSIZEZPIPE_ACCESS_INBOUNDCreateNamedPipeFILE_FLAG_OVERLAPPEDFILE_FLAG_FIRST_PIPE_INSTANCEPIPE_TYPE_MESSAGEPIPE_READMODE_MESSAGE PIPE_WAITNMPWAIT_WAIT_FOREVERNULL CreateFile OPEN_EXISTINGSetNamedPipeHandleStateConnectNamedPipersrl) rr0ZopenmodeaccessZobsizeZibsizeZh1Zh2rm_rurrrrrr s2         c@s*eZdZdZd ddZddZddZd S) rzO Representation of a socket which is bound to an address and listening rcCstjtt||_yRtjdkr2|jjtjtjd|jjd|jj ||jj ||jj |_ Wn t k r|jjYnX||_d|_|dkrtj|tj|fdd|_nd|_dS)NposixrTrr)args exitpriority)r*getattr_socketr nameZ setsockoptZ SOL_SOCKETZ SO_REUSEADDRrZbindZlistenZ getsocknamerr>rBZ_familyrrFinalizeunlink_unlink)r7r0r%rrrrr;<s$       zSocketListener.__init__cCs&|jj\}|_|jdt|jS)NT)rrrrrr)r7srrrrTs zSocketListener.acceptc Cs0z|jjWd|j}|dk r*d|_|XdS)N)rrBr)r7rrrrrBYs zSocketListener.closeN)r)rhrirjrr;rrBrrrrr8s rc CsDt|}tjtt|"}|jd|j|t|jSQRXdS)zO Return a connection object connected to the socket given by `address` TN)r1r*rrZconnectrr)r0r%rrrrrcs   rc@s8eZdZdZd ddZd ddZdd Zed d ZdS)rz0 Representation of a named pipe NcCsL||_|jddg|_d|_tjd|jtj|tj|j|jfdd|_ dS)NT)firstz listener created with address=%rr)rr) r _new_handle _handle_queuerr sub_debugrr_finalize_pipe_listenerrB)r7r0rrrrr;wszPipeListener.__init__Fc CsHtjtjB}|r|tjO}tj|j|tjtjBtjBtj t t tj tj S)N) rnrrrrrrrrZPIPE_UNLIMITED_INSTANCESrrr)r7rflagsrrrrs   zPipeListener._new_handlecCs|jj|j|jjd}ytj|dd}Wn0tk r^}z|jtjkrNWYdd}~XnPXzrZ ERROR_NO_DATArprqrrrrrsrl)r7r8rtrresrrurrrrs"    zPipeListener.acceptcCs(tjd|x|D]}tj|qWdS)Nz closing listener with address=%r)rrrnr)Zqueuer0r8rrrrs  z$PipeListener._finalize_pipe_listener)N)F) rhrirjrr;rr staticmethodrrrrrrss  rcCst}x~y6tj|dtj|tjtjBdtjtjtjtj}Wn>t k r|}z"|j tj tj fksjt |rlWYdd}~XqXPqWtj|tjddt|S)zU Return a connection object connected to the pipe given by `address` irN)rrnZ WaitNamedPiperrrrrrr>rZERROR_SEM_TIMEOUTZERROR_PIPE_BUSYrrrrl)r0rhrrrrrs"   rs #CHALLENGE#s #WELCOME#s #FAILURE#cCsfddl}tjt}|jt||j||tj}|j d}||krP|jt n|jt t ddS)Nrzdigest received was wrong) hmacr urandomMESSAGE_LENGTHrP CHALLENGEnewHMAC_DIGEST_NAMEdigestrWWELCOMEFAILUREr) connectionrrmessagerresponserrrrs    rcCs\ddl}|jd}|ttd}|j||tj}|j||jd}|tkrXt ddS)Nrrzdigest sent was rejected) rrWrIrrrrrPrr)rrrrrrrrrrs   rc@s$eZdZddZddZddZdS)ConnectionWrappercCs:||_||_||_x"dD]}t||}t|||qWdS)NrErBrbrWrP)rErBrbrWrP)_conn_dumps_loadsrsetattr)r7connrRr]attrrSrrrr;s   zConnectionWrapper.__init__cCs|j|}|jj|dS)N)rrrP)r7rSrrrrrTs zConnectionWrapper.sendcCs|jj}|j|S)N)rrWr)r7rrrrr_s zConnectionWrapper.recvN)rhrirjr;rTr_rrrrrsrcCstj|fddddjdS)Nrzutf-8) xmlrpclibrRencode)rSrrr _xml_dumpssrcCstj|jd\\}}|S)Nzutf-8)rr]decode)rrSmethodrrr _xml_loadssrc@seZdZddZdS) XmlListenercCs ddljatj|}t|ttS)Nr) xmlrpc.clientclientrrrrrr)r7rSrrrrs  zXmlListener.acceptN)rhrirjrrrrrrsrcOsddljatt||ttS)Nr)rrrrrrr)rkwdsrrr XmlClient s rcCst|}g}x|rtj|d|}|tkr,Pn\t|koFtt|knrV|t8}n2t|koptt|knr|t8}ntd|j||||dd}d}qW|S)NFzShould not get hererr) listrnrpr r rIr rr)ZhandlesrLreadyrrrr_exhaustive_waits    rc .sn|dkrt}n|dkrd}nt|dd}t|}ig}tt}zHx2|D](}yt|d}Wn tk r||j<YqTXytj|dd\}}Wn8t k r}zd|j }}|t krʂWYdd}~XnX|tj kr|j |||j<qT|rptjdddkrpy|jd \} }Wn*t k rT}z |j }WYdd}~XnX| rpt|d rpd|_j|d}qTWtj|}Wdx|D]}|jqWx|D]}y|jd\} }Wn6t k r}z|j }|t krWYdd}~XnX|tjkr|j}j||dkrt|d rd|_qWXjfd d |Dfd d|DS)z Wait till an object in object_list is ready/readable. Returns list of those objects in object_list which are ready/readable. Nrig?rETFrxc3s|]}|VqdS)Nr).0r)waithandle_to_objrr vszwait..csg|]}|kr|qSrr)ro) ready_objectsrr wszwait..)rr)rintrsetrAttributeErrorr3rnr|r>r _ready_errorsrorrqr'Zgetwindowsversionrsr)rxaddrkeysrrZERROR_OPERATION_ABORTEDupdate) object_listrZov_listZ ready_handlesrrErtrurrr)rrrr+sh              PollSelectorc Cstx}x|D]}|j|tjqW|dk r8tj|}x@|j|}|rVdd|DS|dk r:|tj}|dkr:|Sq:WWdQRXdS)z Wait till an object in object_list is ready/readable. Returns list of those objects in object_list which are ready/readable. NcSsg|]\}}|jqSr)Zfileobj)rkeyZeventsrrrrszwait..r) _WaitSelectorregister selectorsZ EVENT_READrrZselect)r rZselectorrSZdeadlinerrrrrs    c CsN|j}tj|tjtj*}ddlm}|j|}t||j |j ffSQRXdS)Nr)resource_sharer) rEr*ZfromfdrZ SOCK_STREAMrrZ DupSocketrebuild_connectionr9r:)rr8rrdsrrrreduce_connections   rcCs|j}t|j||S)N)rr)rr9r:ZsockrrrrsrcCsB|jr tjnd|jrtjndB}tj|j|}t||j|jffS)Nr) r9rnZFILE_GENERIC_READr:ZFILE_GENERIC_WRITEr Z DupHandlerErebuild_pipe_connection)rrdhrrrreduce_pipe_connectionsrcCs|j}t|||S)N)rrl)rr9r:r8rrrrsrcCs tj|j}t||j|jffS)N)r ZDupFdrErr9r:)rdfrrrrscCs|j}t|||S)N)rr)rr9r:fdrrrrs)NN)T)T)N)N)J__all__ryr r'r*rrr itertoolsrrrrr contextr ZForkingPicklerrQrnr r r r ImportErrorr(rZCONNECTION_TIMEOUTrcountr#rZfamiliesr)rrr&r+r1r2rlrobjectrrrrrrrrrrrrrrrrrrrrZERROR_NETNAME_DELETEDrrrr r ZSelectSelectorrrrrrrrrr s           PJ8    ,+ 8    P    connection.cpython-36.pyc000064400000060406147204630710011343 0ustar003 fVy @s ddddgZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl m Z ddl m Z m Z dd lmZejZy$ddlZdd lmZmZmZmZWn$ek rejd kr‚dZYnXd Zd ZdZejZdZdgZe edrdZedg7Zejd krdZedg7ZefddZ!ddZ"ddZ#ddZ$ddZ%GdddZ&ernGddde&Z'Gd d!d!e&Z(Gd"dde)Z*dPd#dZ+ejd krdQd%dZ,n dRd&dZ,Gd'd(d(e)Z-d)d*Z.ejd krGd+d,d,e)Z/d-d.Z0d/Z1d0Z2d1Z3d2Z4d3d4Z5d5d6Z6Gd7d8d8e)Z7d9d:Z8d;d<Z9Gd=d>d>e*Z:d?d@Z;ejd krzdAdBZhZ?dSdCdZ@n,ddlAZAe eAdDreAjBZCneAjDZCdTdEdZ@ejd krdFdGZEdHdIZFejGe(eEdJdKZHdLdMZIejGe'eHndNdGZEdOdIZFejGe(eEdS)UClientListenerPipewaitN)util)AuthenticationErrorBufferTooShort) reduction) WAIT_OBJECT_0WAIT_ABANDONED_0 WAIT_TIMEOUTINFINITEwin32i g4@Zsha256AF_INETAF_UNIXAF_PIPEcCs tj|S)N)time monotonic)timeoutr2/usr/lib64/python3.6/multiprocessing/connection.py _init_timeout?srcCs tj|kS)N)rr)trrr_check_timeoutBsrcCsX|dkr d S|dkr&tjdtjdS|dkrLtjdtjttfd dStd d S) z? Return an arbitrary free address for the given family r localhostrrz listener-)prefixdirrz\\.\pipe\pyc-%d-%d-zunrecognized familyN)rr) tempfileZmktemprZ get_temp_dirosgetpidnext _mmap_counter ValueError)familyrrrarbitrary_addressIsr&cCsJtjdkr|dkrtd|tjdkrF|dkrFtt|sFtd|dS)zD Checks if the family is valid for the current environment. rrzFamily %s is not recognized.rN)sysplatformr$hasattrsocket)r%rrr_validate_familyWs   r+cCsJt|tkrdSt|tkr*|jdr*dSt|tkr:dStd|dS)z] Return the types of the address This can be 'AF_INET', 'AF_UNIX', or 'AF_PIPE' rz\\rrzaddress type of %r unrecognizedN)typetuplestr startswithr$)addressrrr address_typecs  r1c@seZdZdZd+ddZddZddZd d Zd d Zd dZ e ddZ e ddZ e ddZ ddZddZd,ddZddZd-ddZd.d d!Zd"d#Zd/d%d&Zd'd(Zd)d*ZdS)0_ConnectionBaseNTcCsB|j}|dkrtd| r,| r,td||_||_||_dS)Nrzinvalid handlez6at least one of `readable` and `writable` must be True) __index__r$_handle _readable _writable)selfhandlereadablewritablerrr__init__ys z_ConnectionBase.__init__cCs|jdk r|jdS)N)r4_close)r7rrr__del__s z_ConnectionBase.__del__cCs|jdkrtddS)Nzhandle is closed)r4OSError)r7rrr _check_closeds z_ConnectionBase._check_closedcCs|jstddS)Nzconnection is write-only)r5r>)r7rrr_check_readablesz_ConnectionBase._check_readablecCs|jstddS)Nzconnection is read-only)r6r>)r7rrr_check_writablesz_ConnectionBase._check_writablecCs"|jrd|_n|jtddS)NFzbad message length)r6r5closer>)r7rrr_bad_message_lengthsz#_ConnectionBase._bad_message_lengthcCs |jdkS)z True if the connection is closedN)r4)r7rrrclosedsz_ConnectionBase.closedcCs|jS)z"True if the connection is readable)r5)r7rrrr9sz_ConnectionBase.readablecCs|jS)z"True if the connection is writable)r6)r7rrrr:sz_ConnectionBase.writablecCs|j|jS)z+File descriptor or handle of the connection)r?r4)r7rrrfilenosz_ConnectionBase.filenoc Cs$|jdk r z |jWdd|_XdS)zClose the connectionN)r4r<)r7rrrrBs  z_ConnectionBase.closercCs|j|jt|}|jdkr.tt|}t|}|dkrFtd||krVtd|dkrh||}n&|dkrztdn|||krtd|j||||dS)z,Send the bytes data from a bytes-like objectrrzoffset is negativezbuffer length < offsetNzsize is negativezbuffer length < offset + size)r?rA memoryviewitemsizebyteslenr$ _send_bytes)r7bufoffsetsizemnrrr send_bytess"     z_ConnectionBase.send_bytescCs$|j|j|jtj|dS)zSend a (picklable) objectN)r?rArJ_ForkingPicklerdumps)r7objrrrsendsz_ConnectionBase.sendcCsJ|j|j|dk r(|dkr(td|j|}|dkrB|j|jS)z7 Receive bytes data as a bytes object. Nrznegative maxlength)r?r@r$ _recv_bytesrCgetvalue)r7Z maxlengthrKrrr recv_bytess z_ConnectionBase.recv_bytesc Cs|j|jt|}|j}|t|}|dkr>tdn||krNtd|j}|j}|||krvt|j |j d|j |||||||SQRXdS)zq Receive bytes data into a writeable bytes-like object. Return the number of bytes read. rznegative offsetzoffset too largeN) r?r@rFrGrIr$rUtellr rVseekreadinto)r7rKrLrNrGZbytesizeresultrMrrrrecv_bytes_intos"       z_ConnectionBase.recv_bytes_intocCs&|j|j|j}tj|jS)zReceive a (picklable) object)r?r@rUrQloads getbuffer)r7rKrrrrecvsz_ConnectionBase.recvcCs|j|j|j|S)z/Whether there is any input available to be read)r?r@_poll)r7rrrrpollsz_ConnectionBase.pollcCs|S)Nr)r7rrr __enter__sz_ConnectionBase.__enter__cCs |jdS)N)rB)r7exc_type exc_valueexc_tbrrr__exit__ sz_ConnectionBase.__exit__)TT)rN)N)r)r`)__name__ __module__ __qualname__r4r;r=r?r@rArCpropertyrDr9r:rErBrPrTrWr\r_rbrcrgrrrrr2vs(       r2c@sDeZdZdZdZejfddZddZddd Z d d Z d d Z dS)PipeConnectionz Connection class based on a Windows named pipe. Overlapped I/O is used, so the handles must have been created with FILE_FLAG_OVERLAPPED. FcCs||jdS)N)r4)r7Z _CloseHandlerrrr<szPipeConnection._closecCstj|j|dd\}}zHy,|tjkrBtj|jgdt}|tksBtWn|j YnXWd|j d\}}X|dks|t|t |kstdS)NT) overlappedFr) _winapiZ WriteFiler4ERROR_IO_PENDINGWaitForMultipleObjectseventrr AssertionErrorcancelGetOverlappedResultrI)r7rKoverrwaitresZnwrittenrrrrJs   zPipeConnection._send_bytesNc Cs|jrd|_tjS|dkr dnt|d}ytj|j|dd\}}zHy,|tjkrntj|j gdt }|t ksnt Wn|j YnXWd|jd\}}|dkrtj}|j|j|S|tjkr|j||SXWn:tk r}z|jtjkrtnWYdd}~XnXtddS)NFT)rmrz.shouldn't get here; expected KeyboardInterrupt)_got_empty_messageioBytesIOminrnReadFiler4rorprqrr rrrsrtwriter^ZERROR_MORE_DATA_get_more_datar>winerrorERROR_BROKEN_PIPEEOFError RuntimeError) r7maxsizeZbsizerurvrwZnreadferrrrU*s6     zPipeConnection._recv_bytescCs.|jstj|jddkrdStt|g|S)NrT)ryrn PeekNamedPiper4boolr)r7rrrrraJszPipeConnection._pollcCs|j}tj}|j|tj|jd}|dks6t|dk rVt|||krV|j tj |j|dd\}}|j d\}}|dkst||kst|j|j|S)NrrT)rm) r^rzr{r~rnrr4rrrIrCr}rt)r7rurrKrleftrvZrbytesrrrrPs    zPipeConnection._get_more_data)N) rhrirj__doc__ryrn CloseHandler<rJrUrarrrrrrls rlc@s|eZdZdZer,ejfddZejZ ej Z ne j fddZe jZ e jZ e fddZe fddZd d Zdd d ZddZd S) Connectionzo Connection class based on an arbitrary file descriptor (Unix only), or a socket handle (Windows). cCs||jdS)N)r4)r7r<rrrr<gszConnection._closecCs||jdS)N)r4)r7r<rrrr<lscCs<t|}x.||j|}||8}|dkr(P||d}q WdS)Nr)rIr4)r7rKr~ remainingrOrrr_sendqs zConnection._sendcCsftj}|j}|}xN|dkr`|||}t|}|dkrL||krDtntd|j|||8}qW|S)Nrzgot end of file during message)rzr{r4rIrr>r~)r7rMreadrKr8rchunkrOrrr_recvzs    zConnection._recvcCsDt|}tjd|}|dkr2|j||j|n|j||dS)Nz!ii@)rIstructZpackr)r7rKrOheaderrrrrJs    zConnection._send_bytesNcCs:|jd}tjd|j\}|dk r0||kr0dS|j|S)Nz!i)rrZunpackrV)r7rrKrMrrrrUs  zConnection._recv_bytescCst|g|}t|S)N)rr)r7rrrrrras zConnection._poll)N)rhrirjrrn_multiprocessingZ closesocketr<rTZ_writer_Z_readr rBr~rrrrJrUrarrrrr`s  rc@sReZdZdZdddZddZdd Zed d Zed d Z d dZ ddZ dS)rz Returns a listener object. This is a wrapper for a bound socket which is 'listening' for connections, or for a Windows named pipe. NrcCsr|p|rt|pt}|pt|}t||dkr>t|||_nt||||_|dk rht|t rht d||_ dS)Nrzauthkey should be a byte string) r1default_familyr&r+ PipeListener _listenerSocketListener isinstancerH TypeError_authkey)r7r0r%backlogauthkeyrrrr;s zListener.__init__cCs>|jdkrtd|jj}|jr:t||jt||j|S)zz Accept a connection on the bound socket or named pipe of `self`. Returns a `Connection` object. Nzlistener is closed)rr>acceptrdeliver_challengeanswer_challenge)r7crrrrs    zListener.acceptcCs |j}|dk rd|_|jdS)zA Close the bound socket or named pipe of `self`. N)rrB)r7ZlistenerrrrrBszListener.closecCs|jjS)N)r_address)r7rrrszListener.cCs|jjS)N)r_last_accepted)r7rrrrscCs|S)Nr)r7rrrrcszListener.__enter__cCs |jdS)N)rB)r7rdrerfrrrrgszListener.__exit__)NNrN) rhrirjrr;rrBrkr0Z last_acceptedrcrgrrrrrs   cCsj|p t|}t||dkr&t|}nt|}|dk rJt|t rJtd|dk rft||t|||S)z= Returns a connection to the address of a `Listener` rNzauthkey should be a byte string) r1r+ PipeClient SocketClientrrHrrr)r0r%rrrrrrs    TcCsj|r>tj\}}|jd|jdt|j}t|j}n$tj\}}t|dd}t|dd}||fS)zL Returns pair of connection objects at either end of a pipe TF)r:)r9)r*Z socketpair setblockingrdetachr pipe)duplexs1s2c1c2Zfd1Zfd2rrrrs       c Cstd}|r*tj}tjtjB}tt}}ntj}tj}dt}}tj||tjBtj Btj tj Btj Bd||tj tj}tj||dtjtjtjtj}tj|tj ddtj|dd}|jd\} } | dkstt||d} t||d} | | fS) zL Returns pair of connection objects at either end of a pipe rrrNT)rm)r:)r9)r&rnPIPE_ACCESS_DUPLEX GENERIC_READ GENERIC_WRITEBUFSIZEZPIPE_ACCESS_INBOUNDCreateNamedPipeFILE_FLAG_OVERLAPPEDFILE_FLAG_FIRST_PIPE_INSTANCEPIPE_TYPE_MESSAGEPIPE_READMODE_MESSAGE PIPE_WAITNMPWAIT_WAIT_FOREVERNULL CreateFile OPEN_EXISTINGSetNamedPipeHandleStateConnectNamedPipertrrrl) rr0ZopenmodeaccessZobsizeZibsizeZh1Zh2rm_rvrrrrrr s4          c@s*eZdZdZd ddZddZddZd S) rzO Representation of a socket which is bound to an address and listening rcCstjtt||_yRtjdkr2|jjtjtjd|jjd|jj ||jj ||jj |_ Wn t k r|jjYnX||_d|_|dkrtj|tj|fdd|_nd|_dS)NposixrTrr)args exitpriority)r*getattr_socketr nameZ setsockoptZ SOL_SOCKETZ SO_REUSEADDRrZbindZlistenZ getsocknamerr>rBZ_familyrrFinalizeunlink_unlink)r7r0r%rrrrr;<s$       zSocketListener.__init__cCs&|jj\}|_|jdt|jS)NT)rrrrrr)r7srrrrTs zSocketListener.acceptc Cs0z|jjWd|j}|dk r*d|_|XdS)N)rrBr)r7rrrrrBYs zSocketListener.closeN)r)rhrirjrr;rrBrrrrr8s rc CsDt|}tjtt|"}|jd|j|t|jSQRXdS)zO Return a connection object connected to the socket given by `address` TN)r1r*rrZconnectrr)r0r%rrrrrcs   rc@s8eZdZdZd ddZd ddZdd Zed d ZdS)rz0 Representation of a named pipe NcCsL||_|jddg|_d|_tjd|jtj|tj|j|jfdd|_ dS)NT)firstz listener created with address=%rr)rr) r _new_handle _handle_queuerr sub_debugrr_finalize_pipe_listenerrB)r7r0rrrrr;wszPipeListener.__init__Fc CsHtjtjB}|r|tjO}tj|j|tjtjBtjBtj t t tj tj S)N) rnrrrrrrrrZPIPE_UNLIMITED_INSTANCESrrr)r7rflagsrrrrs   zPipeListener._new_handlecCs|jj|j|jjd}ytj|dd}Wn0tk r^}z|jtjkrNWYdd}~Xn\XzrZ ERROR_NO_DATArprqrrsrrtrrrl)r7r8rurresrrvrrrrs"    zPipeListener.acceptcCs(tjd|x|D]}tj|qWdS)Nz closing listener with address=%r)rrrnr)Zqueuer0r8rrrrs  z$PipeListener._finalize_pipe_listener)N)F) rhrirjrr;rr staticmethodrrrrrrss  rcCst}x~y6tj|dtj|tjtjBdtjtjtjtj}Wn>t k r|}z"|j tj tj fksjt |rlWYdd}~XqXPqWtj|tjddt|S)zU Return a connection object connected to the pipe given by `address` irN)rrnZ WaitNamedPiperrrrrrr>rZERROR_SEM_TIMEOUTZERROR_PIPE_BUSYrrrrl)r0rhrrrrrs"   rs #CHALLENGE#s #WELCOME#s #FAILURE#cCstddl}t|tsttjt}|jt||j ||t j }|j d}||kr^|jt n|jttddS)Nrzdigest received was wrong)hmacrrHrrr urandomMESSAGE_LENGTHrP CHALLENGEnewHMAC_DIGEST_NAMEdigestrWWELCOMEFAILUREr) connectionrrmessagerresponserrrrs    rcCsddl}t|tst|jd}|dtttks@td||ttd}|j||tj }|j ||jd}|t krt ddS)Nrrz message = %rzdigest sent was rejected) rrrHrrrWrIrrrrrPrr)rrrrrrrrrrs    rc@s$eZdZddZddZddZdS)ConnectionWrappercCs:||_||_||_x"dD]}t||}t|||qWdS)NrErBrbrWrP)rErBrbrWrP)_conn_dumps_loadsrsetattr)r7connrRr]attrrSrrrr;s   zConnectionWrapper.__init__cCs|j|}|jj|dS)N)rrrP)r7rSrrrrrTs zConnectionWrapper.sendcCs|jj}|j|S)N)rrWr)r7rrrrr_s zConnectionWrapper.recvN)rhrirjr;rTr_rrrrrsrcCstj|fddddjdS)Nrzutf-8) xmlrpclibrRencode)rSrrr _xml_dumpssrcCstj|jd\\}}|S)Nzutf-8)rr]decode)rrSmethodrrr _xml_loadssrc@seZdZddZdS) XmlListenercCs ddljatj|}t|ttS)Nr) xmlrpc.clientclientrrrrrr)r7rSrrrrs  zXmlListener.acceptN)rhrirjrrrrrrsrcOsddljatt||ttS)Nr)rrrrrrr)rkwdsrrr XmlClient s rcCst|}g}x|rtj|d|}|tkr,Pn\t|koFtt|knrV|t8}n2t|koptt|knr|t8}ntd|j||||dd}d}qW|S)NFzShould not get hererr) listrnrpr r rIr rr)ZhandlesrLreadyrrrr_exhaustive_waits    rc .sn|dkrt}n|dkrd}nt|dd}t|}ig}tt}zHx2|D](}yt|d}Wn tk r||j<YqTXytj|dd\}}Wn8t k r}zd|j }}|t krʂWYdd}~XnX|tj kr|j |||j<qT|rptjdddkrpy|jd \} }Wn*t k rT}z |j }WYdd}~XnX| rpt|d rpd|_j|d}qTWtj|}Wdx|D]}|jqWx|D]}y|jd\} }Wn6t k r}z|j }|t krWYdd}~XnX|tjkr|j}j||dkrt|d rd|_qWXjfd d |Dfd d|DS)z Wait till an object in object_list is ready/readable. Returns list of those objects in object_list which are ready/readable. Nrig?rETFryc3s|]}|VqdS)Nr).0r)waithandle_to_objrr vszwait..csg|]}|kr|qSrr)ro) ready_objectsrr wszwait..)rr)rintrsetrAttributeErrorr3rnr}r>r _ready_errorsrorrqr'Zgetwindowsversionrtr)ryaddrkeysrsZERROR_OPERATION_ABORTEDupdate) object_listrZov_listZ ready_handlesrrErurvrrr)rrrr+sh              PollSelectorc Cstx}x|D]}|j|tjqW|dk r8tj|}x@|j|}|rVdd|DS|dk r:|tj}|dkr:|Sq:WWdQRXdS)z Wait till an object in object_list is ready/readable. Returns list of those objects in object_list which are ready/readable. NcSsg|]\}}|jqSr)Zfileobj)rkeyZeventsrrrrszwait..r) _WaitSelectorregister selectorsZ EVENT_READrrZselect)r rZselectorrSZdeadlinerrrrrs    c CsN|j}tj|tjtj*}ddlm}|j|}t||j |j ffSQRXdS)Nr)resource_sharer) rEr*ZfromfdrZ SOCK_STREAMrrZ DupSocketrebuild_connectionr9r:)rr8rrdsrrrreduce_connections   rcCs|j}t|j||S)N)rr)rr9r:ZsockrrrrsrcCsB|jr tjnd|jrtjndB}tj|j|}t||j|jffS)Nr) r9rnZFILE_GENERIC_READr:ZFILE_GENERIC_WRITEr Z DupHandlerErebuild_pipe_connection)rrdhrrrreduce_pipe_connectionsrcCs|j}t|||S)N)rrl)rr9r:r8rrrrsrcCs tj|j}t||j|jffS)N)r ZDupFdrErr9r:)rdfrrrrscCs|j}t|||S)N)rr)rr9r:fdrrrrs)NN)T)T)N)N)J__all__rzr r'r*rrr itertoolsrrrrr contextr ZForkingPicklerrQrnr r r r ImportErrorr(rZCONNECTION_TIMEOUTrcountr#rZfamiliesr)rrr&r+r1r2rlrobjectrrrrrrrrrrrrrrrrrrrrZERROR_NETNAME_DELETEDrrrr rZSelectSelectorrrrrrrrrr s           PJ8    ,+ 8    P    context.cpython-36.opt-2.pyc000064400000026523147204630710011632 0ustar003 \*@sddlZddlZddlZddlmZddlmZgZGdddeZGdddeZ Gd d d eZ Gd d d eZ Gd dde Z GdddejZGddde ZeddeeDe_ejdkrPGdddejZGdddejZGdddejZGddde ZGddde ZGd d!d!e Zeeed"Zeed#Zn8Gd$ddejZGd%dde Zd&eiZeed&Zd'd(ZejZd)d*Zd+d,Z d-d.Z!dS)/N)process) reductionc@s eZdZdS) ProcessErrorN)__name__ __module__ __qualname__r r //usr/lib64/python3.6/multiprocessing/context.pyrsrc@s eZdZdS)BufferTooShortN)rrrr r r r r sr c@s eZdZdS) TimeoutErrorN)rrrr r r r r sr c@s eZdZdS)AuthenticationErrorN)rrrr r r r r sr c@sVeZdZeZeZeZeZeej Z eej Z ddZ ddZ dBddZ dd Zd d ZdCd dZdDddZdEddZddZdFddZdGddZdHddZddZd d fd fdd Zd!d"Zd#d$Zdd%d&d'Zdd%d(d)Zd*d+Zd,d-ZdId.d/Zd0d1Z d2d3Z!d4d5Z"dJd6d7Z#dKd9d:Z$dLd;d<Z%e&d=d>Z'e'j(d?d>Z'd@dAZ)d S)M BaseContextcCs"tj}|dkrtdn|SdS)Nzcannot determine number of cpus)os cpu_countNotImplementedError)selfZnumr r r r(s zBaseContext.cpu_countcCs&ddlm}||jd}|j|S)Nr) SyncManager)ctx)Zmanagersr get_contextstart)rrmr r r Manager0s zBaseContext.ManagerTcCsddlm}||S)Nr)Pipe) connectionr)rZduplexrr r r r;s zBaseContext.PipecCsddlm}||jdS)Nr)Lock)r) synchronizerr)rrr r r r@s zBaseContext.LockcCsddlm}||jdS)Nr)RLock)r)rrr)rrr r r rEs zBaseContext.RLockNcCsddlm}|||jdS)Nr) Condition)r)rrr)rlockrr r r rJs zBaseContext.ConditionrcCsddlm}|||jdS)Nr) Semaphore)r)rr r)rvaluer r r r r Os zBaseContext.SemaphorecCsddlm}|||jdS)Nr)BoundedSemaphore)r)rr"r)rr!r"r r r r"Ts zBaseContext.BoundedSemaphorecCsddlm}||jdS)Nr)Event)r)rr#r)rr#r r r r#Ys zBaseContext.EventcCs ddlm}|||||jdS)Nr)Barrier)r)rr$r)rZpartiesactionZtimeoutr$r r r r$^s zBaseContext.BarrierrcCsddlm}|||jdS)Nr)Queue)r)queuesr&r)rmaxsizer&r r r r&cs zBaseContext.QueuecCsddlm}|||jdS)Nr) JoinableQueue)r)r'r)r)rr(r)r r r r)hs zBaseContext.JoinableQueuecCsddlm}||jdS)Nr) SimpleQueue)r)r'r*r)rr*r r r r*ms zBaseContext.SimpleQueuecCs"ddlm}||||||jdS)Nr)Pool)context)Zpoolr+r)rZ processesZ initializerZinitargsZmaxtasksperchildr+r r r r+rs  zBaseContext.PoolcGsddlm}||f|S)Nr)RawValue) sharedctypesr-)rtypecode_or_typeargsr-r r r r-ys zBaseContext.RawValuecCsddlm}|||S)Nr)RawArray)r.r1)rr/size_or_initializerr1r r r r1~s zBaseContext.RawArray)rcGs&ddlm}||f|||jdS)Nr)Value)rr)r.r3r)rr/rr0r3r r r r3s  zBaseContext.ValuecCs ddlm}|||||jdS)Nr)Array)rr)r.r4r)rr/r2rr4r r r r4s zBaseContext.ArraycCs,tjdkr(ttddr(ddlm}|dS)Nwin32frozenFr)freeze_support)sysplatformgetattrspawnr7)rr7r r r r7s zBaseContext.freeze_supportcCsddlm}|S)Nr) get_logger)utilr<)rr<r r r r<s zBaseContext.get_loggercCsddlm}||S)Nr) log_to_stderr)r=r>)rlevelr>r r r r>s zBaseContext.log_to_stderrcCsddlm}dS)Nr)r)r)rrr r r allow_connection_picklingsz%BaseContext.allow_connection_picklingcCsddlm}||dS)Nr)set_executable)r;rB)r executablerBr r r rBs zBaseContext.set_executablecCsddlm}||dS)Nr)set_forkserver_preload) forkserverrD)rZ module_namesrDr r r rDs z"BaseContext.set_forkserver_preloadc CsF|dkr |Sy t|}Wn tk r8td|YnX|j|S)Nzcannot find context for %r)_concrete_contextsKeyError ValueError_check_available)rmethodrr r r rs zBaseContext.get_contextFcCs|jS)N)_name)r allow_noner r r get_start_methodszBaseContext.get_start_methodcCs tddS)Nz+cannot set start method of concrete context)rH)rrJforcer r r set_start_methodszBaseContext.set_start_methodcCs tjdS)Nr)globalsget)rr r r reducerszBaseContext.reducercCs|td<dS)Nr)rP)rrr r r rRscCsdS)Nr )rr r r rIszBaseContext._check_available)T)N)r)r)NN)r)r)N)N)F)F)*rrrrr r r staticmethodrZcurrent_processZactive_childrenrrrrrrr r"r#r$r&r)r*r+r-r1r3r4r7r<r>rArBrDrrMrOpropertyrRsetterrIr r r r rsJ              rc@seZdZdZeddZdS)ProcessNcCstjjj|S)N)_default_contextrrV_Popen) process_objr r r rXszProcess._Popen)rrr _start_methodrSrXr r r r rVsrVcsFeZdZeZddZd fdd ZdddZdd d Zd d ZZ S)DefaultContextcCs||_d|_dS)N)rW_actual_context)rr,r r r __init__szDefaultContext.__init__Ncs0|dkr |jdkr|j|_|jStj|SdS)N)r\rWsuperr)rrJ) __class__r r rs  zDefaultContext.get_contextFcCs>|jdk r| rtd|dkr.|r.d|_dS|j||_dS)Nzcontext has already been set)r\ RuntimeErrorr)rrJrNr r r rOs  zDefaultContext.set_start_methodcCs"|jdkr|rdS|j|_|jjS)N)r\rWrK)rrLr r r rMs  zDefaultContext.get_start_methodcCs,tjdkrdgStjr dddgSddgSdS)Nr5r;forkrE)r8r9rHAVE_SEND_HANDLE)rr r r get_all_start_methodss   z$DefaultContext.get_all_start_methods)N)F)F) rrrrVr]rrOrMrc __classcell__r r )r_r r[s   r[ccs|]}|ddkr|VqdS)r_Nr ).0xr r r srhr5c@seZdZdZeddZdS) ForkProcessracCsddlm}||S)Nr)Popen)Z popen_forkrj)rYrjr r r rXs zForkProcess._PopenN)rrrrZrSrXr r r r risric@seZdZdZeddZdS) SpawnProcessr;cCsddlm}||S)Nr)rj)Zpopen_spawn_posixrj)rYrjr r r rXs zSpawnProcess._PopenN)rrrrZrSrXr r r r rksrkc@seZdZdZeddZdS)ForkServerProcessrEcCsddlm}||S)Nr)rj)Zpopen_forkserverrj)rYrjr r r rX s zForkServerProcess._PopenN)rrrrZrSrXr r r r rlsrlc@seZdZdZeZdS) ForkContextraN)rrrrKrirVr r r r rm%srmc@seZdZdZeZdS) SpawnContextr;N)rrrrKrkrVr r r r rn)srnc@seZdZdZeZddZdS)ForkServerContextrEcCstjstddS)Nz%forkserver start method not available)rrbrH)rr r r rI0sz"ForkServerContext._check_availableN)rrrrKrlrVrIr r r r ro-sro)rar;rErac@seZdZdZeddZdS)rkr;cCsddlm}||S)Nr)rj)Zpopen_spawn_win32rj)rYrjr r r rX?s zSpawnProcess._PopenN)rrrrZrSrXr r r r rk=sc@seZdZdZeZdS)rnr;N)rrrrKrkrVr r r r rnDsr;cCst|t_dS)N)rFrWr\)rJr r r _force_start_methodQsrpcCs ttddS)Nspawning_popen)r:_tlsr r r r get_spawning_popenZsrscCs |t_dS)N)rrrq)popenr r r set_spawning_popen]srucCs tdkrtdt|jdS)NzF%s objects should only be shared between processes through inheritance)rsr`typer)objr r r assert_spawning`s rx)"rr8Z threadingr@rr__all__ Exceptionrr r r objectrZ BaseProcessrVr[listdirr9rirkrlrmrnrorFrWrpZlocalrrrsrurxr r r r sD  >'    heap.cpython-36.opt-2.pyc000064400000013405147204630710011056 0ustar003 \ @sddlZddlZddlZddlZddlZddlZddlmZmZddl m Z dgZ ej dkrvddl Z GdddeZn,Gd ddeZd d Zd d ZejeeGdddeZGdddeZdS)N) reductionassert_spawning)util BufferWrapperZwin32c@s,eZdZejZddZddZddZdS)ArenacCsz||_xTtdD]@}dtjt|jf}tjd||d}tjdkrHP|j qWt d||_ ||_ |j|j f|_ dS)Ndz pym-%d-%sr)tagnamerzCannot find name for new mmap)sizerangeosgetpidnext_randmmap_winapiZ GetLastErrorcloseFileExistsErrornamebuffer_state)selfr irZbufr,/usr/lib64/python3.6/multiprocessing/heap.py__init__"s  zArena.__init__cCst||jS)N)rr)rrrr __getstate__1szArena.__getstate__cCs,|\|_|_|_tjd|j|jd|_dS)Nr)r r )r rrrr)rstaterrr __setstate__5szArena.__setstate__N) __name__ __module__ __qualname__tempfileZ_RandomNameSequencerrrrrrrrrsrc@seZdZdddZdS)rrc Cs||_||_|d krtjdtjtjd\|_}tj|tj |tj |jft |jdddN}d }||krd|}xt ||D]}|j |qW~|j d||WdQRXtj|j|j|_dS) Nrzpym-%d-)prefixdirwbF)closefdir i)r fdr#Zmkstempr rrZ get_temp_dirunlinkFinalizeropenr writerr)rr r)rfZbsZzeros_rrrr@s"  zArena.__init__Nr )r )r r!r"rrrrrr>scCs(|jdkrtdt|jtj|jffS)NrzDArena is unpicklable because forking was enabled when it was createdr )r) ValueError rebuild_arenar rZDupFd)arrr reduce_arenaSs r3cCst||jS)N)rdetach)r Zdupfdrrrr1Ysr1c@sZeZdZdZejfddZeddZddZ dd Z d d Z d d Z ddZ ddZdS)HeapcCsJtj|_tj|_||_g|_i|_i|_ i|_ t |_ g|_ g|_dS)N)r r_lastpid threadingZLock_lock_size_lengths _len_to_seq_start_to_block_stop_to_blockset_allocated_blocks_arenas_pending_free_blocks)rr rrrrfs  z Heap.__init__cCs|d}|||@S)Nrr)nZ alignmentmaskrrr_roundupssz Heap._roundupc Cstj|j|}|t|jkrj|jt|j|tj}|jd9_t j d|t |}|j j ||d|fS|j|}|j|}|j}|s|j|=|j|=|\}}}|j||f=|j||f=|S)Nz"allocating a new mmap of length %dr)bisectZ bisect_leftr;lenrEmaxr:rPAGESIZErinforrAappendr<popr=r>) rr rlengtharenaseqblockstartstoprrr_mallocys"        z Heap._mallocc Cs|\}}}y|j||f}Wntk r0YnX|j|\}}y|j||f}Wntk rfYnX|j|\}}|||f}||}y|j|j|Wn.tk r|g|j|<tj|j|YnX||j||f<||j||f<dS)N) r>KeyError_absorbr=r<rLrGZinsortr;) rrQrOrRrSZ prev_blockr/Z next_blockrNrrr_frees(   z Heap._freecCs^|\}}}|j||f=|j||f=||}|j|}|j||sV|j|=|jj|||fS)N)r=r>r<remover;)rrQrOrRrSrNrPrrrrVs      z Heap._absorbc CsFx@y|jj}Wntk r&PYnX|jj||j|qWdS)N)rBrM IndexErrorr@rXrW)rrQrrr_free_pending_blockss zHeap._free_pending_blocksc CsN|jjds|jj|n0z"|j|jj||j|Wd|jjXdS)NF) r9acquirerBrLrZr@rXrWrelease)rrQrrrfrees  z Heap.freec Cstj|jkr|j|jh|j|jt|d|j}|j |\}}}||}||krj|j |||f|||f}|j j ||SQRXdS)Nr) r rr7rr9rZrErI _alignmentrTrWr@add)rr rOrRrSZnew_stoprQrrrmallocs  z Heap.mallocN)r r!r"r^rrJr staticmethodrErTrWrVrZr]r`rrrrr5bs  r5c@s"eZdZeZddZddZdS)rcCs0tjj|}||f|_tj|tjj|fddS)N)args)r_heapr`rrr+r])rr rQrrrrs  zBufferWrapper.__init__cCs&|j\\}}}}t|j|||S)N)r memoryviewr)rrOrRrSr rrrcreate_memoryviewszBufferWrapper.create_memoryviewN)r r!r"r5rcrrerrrrrs)rGrr sysr#r8contextrrr__all__platformrobjectrr3r1registerr5rrrrr s$    heap.cpython-36.pyc000064400000013677147204630710010131 0ustar003 \ @sddlZddlZddlZddlZddlZddlZddlmZmZddl m Z dgZ ej dkrvddl Z GdddeZn,Gd ddeZd d Zd d ZejeeGdddeZGdddeZdS)N) reductionassert_spawning)util BufferWrapperZwin32c@s,eZdZejZddZddZddZdS)ArenacCsz||_xTtdD]@}dtjt|jf}tjd||d}tjdkrHP|j qWt d||_ ||_ |j|j f|_ dS)Ndz pym-%d-%sr)tagnamerzCannot find name for new mmap)sizerangeosgetpidnext_randmmap_winapiZ GetLastErrorcloseFileExistsErrornamebuffer_state)selfr irZbufr,/usr/lib64/python3.6/multiprocessing/heap.py__init__"s  zArena.__init__cCst||jS)N)rr)rrrr __getstate__1szArena.__getstate__cCs,|\|_|_|_tjd|j|jd|_dS)Nr)r r )r rrrr)rstaterrr __setstate__5szArena.__setstate__N) __name__ __module__ __qualname__tempfileZ_RandomNameSequencerrrrrrrrrsrc@seZdZdddZdS)rrc Cs||_||_|d krtjdtjtjd\|_}tj|tj |tj |jft |jddd^}d }||krd|}xt ||D]}|j |qW~|j d|||j|kstWdQRXtj|j|j|_dS) Nrzpym-%d-)prefixdirwbF)closefdir i)r fdr#Zmkstempr rrZ get_temp_dirunlinkFinalizeropenr writetellAssertionErrorrr)rr r)rfZbsZzeros_rrrr@s" zArena.__init__Nr )r )r r!r"rrrrrr>scCs(|jdkrtdt|jtj|jffS)NrzDArena is unpicklable because forking was enabled when it was createdr )r) ValueError rebuild_arenar rZDupFd)arrr reduce_arenaSs r5cCst||jS)N)rdetach)r Zdupfdrrrr3Ysr3c@sZeZdZdZejfddZeddZddZ dd Z d d Z d d Z ddZ ddZdS)HeapcCsJtj|_tj|_||_g|_i|_i|_ i|_ t |_ g|_ g|_dS)N)r r_lastpid threadingZLock_lock_size_lengths _len_to_seq_start_to_block_stop_to_blockset_allocated_blocks_arenas_pending_free_blocks)rr rrrrfs  z Heap.__init__cCs|d}|||@S)Nrr)nZ alignmentmaskrrr_roundupssz Heap._roundupc Cstj|j|}|t|jkrj|jt|j|tj}|jd9_t j d|t |}|j j ||d|fS|j|}|j|}|j}|s|j|=|j|=|\}}}|j||f=|j||f=|S)Nz"allocating a new mmap of length %dr)bisectZ bisect_leftr=lenrGmaxr<rPAGESIZErinforrCappendr>popr?r@) rr rlengtharenaseqblockstartstoprrr_mallocys"        z Heap._mallocc Cs|\}}}y|j||f}Wntk r0YnX|j|\}}y|j||f}Wntk rfYnX|j|\}}|||f}||}y|j|j|Wn.tk r|g|j|<tj|j|YnX||j||f<||j||f<dS)N) r@KeyError_absorbr?r>rNrIZinsortr=) rrSrQrTrUZ prev_blockr1Z next_blockrPrrr_frees(   z Heap._freecCs^|\}}}|j||f=|j||f=||}|j|}|j||sV|j|=|jj|||fS)N)r?r@r>remover=)rrSrQrTrUrPrRrrrrXs      z Heap._absorbc CsFx@y|jj}Wntk r&PYnX|jj||j|qWdS)N)rDrO IndexErrorrBrZrY)rrSrrr_free_pending_blockss zHeap._free_pending_blocksc Cs`tj|jkst|jjds,|jj|n0z"|j|j j ||j |Wd|jj XdS)NF) r rr9r/r;acquirerDrNr\rBrZrYrelease)rrSrrrfrees   z Heap.freec Csd|kotjknsttj|jkr4|j|jh|j|j t |d|j }|j |\}}}||}||kr|j |||f|||f}|jj||SQRXdS)Nrr)sysmaxsizer/r rr9rr;r\rGrK _alignmentrVrYrBadd)rr rQrTrUZnew_stoprSrrrmallocs  z Heap.mallocN)r r!r"rbrrLr staticmethodrGrVrYrXr\r_rdrrrrr7bs  r7c@s"eZdZeZddZddZdS)rcCsNd|kotjknsttjj|}||f|_tj|tjj |fddS)Nr)args) r`rar/r_heaprdrrr+r_)rr rSrrrrs  zBufferWrapper.__init__cCs&|j\\}}}}t|j|||S)N)r memoryviewr)rrQrTrUr rrrcreate_memoryviewszBufferWrapper.create_memoryviewN)r r!r"r7rgrrirrrrrs)rIrr r`r#r:contextrrr__all__platformrobjectrr5r3registerr7rrrrr s$    managers.cpython-36.opt-1.pyc000064400000100054147204630710011732 0ustar003 \@sddddgZddlZddlZddlZddlZddlZddlmZddlm Z dd l m Z m Z dd lm Z dd lmZdd lmZdd lmZddZe jejedddDZedek rddZxeD]Ze jeeqWGdddeZfifddZddZGdddeZddZd d!ZGd"d#d#eZGd$d%d%eZ e j!e j"fe j#e j$fd&Z%Gd'ddeZ&Gd(d)d)e'Z(Gd*ddeZ)d+d,Z*ifd-d.Z+dd0d1Z,Gd2d3d3eZ-Gd4d5d5eZ.dd6d7Z/Gd8d9d9e)Z0Gd:d;d;e)Z1Gdd?d?e)Z3Gd@dAdAe)Z4GdBdCdCe)Z5GdDdEdEe)Z6e+dFdZ7GdZd[d[e7Z8e+d\dZ9d]deie9_:e+dfdZ;e+dgdZe>jdwej?e>jdxej?e>jdyej@e3e>jdzejAe1e>jd{ejBe1e>jd|ejCe1e>jd}ejDe1e>jd~ejEe2e>jdejFe4e>jde jGe=e>jdee8e>jdeHe9e>jd5e.e6e>jd7e/e;e>jd3e-e5e>jdee0dde>jdsdddS) BaseManager SyncManager BaseProxyTokenN) format_exc) connection) reductionget_spawning_popen)pool)process)util) get_contextcCstj|j|jffS)N)arraytypecodetobytes)ar0/usr/lib64/python3.6/multiprocessing/managers.py reduce_array$srcCsg|]}tti|qSr)typegetattr).0namerrr (sritemskeysvaluescCstt|ffS)N)list)objrrrrebuild_as_list*sr c@s4eZdZdZdZddZddZd d Zd d Zd S)rz4 Type to uniquely indentify a shared object typeidaddressidcCs||||_|_|_dS)N)r!r"r#)selfr!r"r#rrr__init__9szToken.__init__cCs|j|j|jfS)N)r!r"r#)r$rrr __getstate__<szToken.__getstate__cCs|\|_|_|_dS)N)r!r"r#)r$staterrr __setstate__?szToken.__setstate__cCsd|jj|j|j|jfS)Nz %s(typeid=%r, address=%r, id=%r)) __class____name__r!r"r#)r$rrr__repr__BszToken.__repr__N)r!r"r#) r* __module__ __qualname____doc__ __slots__r%r&r(r+rrrrr3s cCs8|j||||f|j\}}|dkr*|St||dS)zL Send a message to manager using connection `c` and return response z#RETURNN)sendrecvconvert_to_error)cr# methodnameargskwdskindresultrrrdispatchJs  r9cCs<|dkr |S|dkrt|S|dkr0td|StdSdS)Nz#ERRORz #TRACEBACKz#UNSERIALIZABLEzUnserializable message: %s zUnrecognized message type) RemoteError ValueError)r7r8rrrr2Ts r2c@seZdZddZdS)r:cCs&ddddt|jdddS)N -Kr)strr5)r$rrr__str__aszRemoteError.__str__N)r*r,r-r@rrrrr:`sr:cCs6g}x,t|D] }t||}t|r|j|qW|S)z4 Return a list of names of methods of `obj` )dirrcallableappend)rtemprfuncrrr all_methodshs  rFcCsddt|DS)zP Return a list of names of methods of `obj` which do not start with '_' cSsg|]}|ddkr|qS)r_r)rrrrrrwsz"public_methods..)rF)rrrrpublic_methodsssrHc @seZdZdZdddddddd d g Zd d Zd dZddZddZddZ ddZ ddZ ddZ e e e dZ ddZddZd d!Zd"d#Zd$d%Zd&d'Zd(d)Zd*d+Zd,d-Zd.S)/ServerzM Server class which runs in a process controlled by a manager object shutdowncreateaccept_connection get_methods debug_infonumber_of_objectsdummyincrefdecrefcCs^||_tj||_t|\}}||dd|_|jj|_ddffi|_i|_i|_ t j |_ dS)N)r"Zbacklog0) registryr AuthenticationStringauthkeylistener_clientlistenerr" id_to_objid_to_refcountid_to_local_proxy_obj threadingLockmutex)r$rUr"rW serializerListenerClientrrrr%s   zServer.__init__cCstj|_|tj_zZtj|jd}d|_|j y x|jj sN|jj dq6WWnt t fk rjYnXWdtjtjkrtjdtjt_tjt_tjdXdS)z( Run the server forever )targetTrNzresetting stdout, stderrr)r]Event stop_eventr current_process_manager_serverThreadaccepterdaemonstartis_setwaitKeyboardInterrupt SystemExitsysstdout __stdout__r debug __stderr__stderrexit)r$rirrr serve_forevers       zServer.serve_foreverc CsPxJy|jj}Wntk r&wYnXtj|j|fd}d|_|jqWdS)N)rcr5T)rYZacceptOSErrorr]rhhandle_requestrjrk)r$r3trrrriszServer.accepterc 'Cs4d}}}y>tj||jtj||j|j}|\}}}}t||}Wntk rhdtf} Yn>Xy||f||}Wntk rdtf} Yn Xd|f} y|j| Wnrtk r&} zTy|jdtfWntk rYnXt j d| t j d|t j d| WYdd} ~ XnX|j dS)z) Handle a new connection Nz #TRACEBACKz#RETURNzFailure to send message: %rz ... request was %rz ... exception was %r) rZdeliver_challengerWZanswer_challenger1r Exceptionrr0r infoclose) r$r3funcnamer8requestignorer5r6rEmsgerrrrys2    zServer.handle_requestcDCstjdtjj|j}|j}|j}x|jj syBd}}|}|\}}} } y||\}} } Wn^t k r} zBy|j |\}} } Wn&t k r}z | WYdd}~XnXWYdd} ~ XnX|| krt d|t || ft||}y|| | }Wn,tk r&}zd|f}WYdd}~XnPX| o8| j|d}|rn|j|||\}}t||j|}d||ff}nd|f}Wnt k r|dkrdtf}nNy,|j|}|||||f| | }d|f}Wn tk rdtf}YnXYnPtk r"tjdtjjtjd Yn tk r@dtf}YnXyDy ||Wn2tk r}z|d tfWYdd}~XnXWq(tk r}zBtjd tjjtjd |tjd ||jtjdWYdd}~Xq(Xq(WdS)zQ Handle requests from the proxies in a particular process/thread z$starting server thread to service %rNz+method %r of %r object is not in exposed=%rz#ERRORz#PROXYz#RETURNz #TRACEBACKz$got EOF -- exiting thread serving %rrz#UNSERIALIZABLEzexception in thread serving %rz ... message was %rz ... exception was %rr)r rsr]current_threadrr1r0rZrerlKeyErrorr\AttributeErrorrrr{getrKrr"rfallback_mappingEOFErrorrprvr|r})r$connr1r0rZr4rridentr5r6exposed gettypeidkeZ second_keZfunctionresrrr!ZridentZrexposedtokenZ fallback_funcr8rrr serve_clientsx  (        $   zServer.serve_clientcCs|S)Nr)r$rrrrrrfallback_getvalue&szServer.fallback_getvaluecCst|S)N)r?)r$rrrrrr fallback_str)szServer.fallback_strcCst|S)N)repr)r$rrrrrr fallback_repr,szServer.fallback_repr)r@r+z #GETVALUEcCsdS)Nr)r$r3rrrrP5sz Server.dummycCs||jlg}t|jj}|jxD|D]<}|dkr(|jd||j|t|j|dddfq(Wdj|SQRXdS)zO Return some info --- useful to spot problems with refcounting rTz %s: refcount=%s %srNr>r<) r_rr[rsortrCr?rZjoin)r$r3r8rrrrrrN8s  $zServer.debug_infocCs t|jS)z* Number of shared objects )lenr[)r$r3rrrrOGszServer.number_of_objectscCsLz:ytjd|jdWnddl}|jYnXWd|jjXdS)z' Shutdown this process z!manager received shutdown message#RETURNNr)rN)r rsr0 traceback print_excreset)r$r3rrrrrJNs zServer.shutdownc Os|j|j|\}}}}|dkr,|d} n |||} |dkrFt| }|dk r^t|t|}dt| } tjd|| | t||f|j| <| |j krd|j | <WdQRX|j || | t |fS)z> Create a new shared object and return its id Nrz%xz&%r callable returned object with id %r) r_rUrHrr#r rsrrZr[rQtuple) r$r3r!r5r6rBrmethod_to_typeid proxytyperrrrrrK[s      z Server.createcCst|j|jdS)zL Return the methods of the shared object indicated by token r)rrZr#)r$r3rrrrrMzszServer.get_methodscCs"|tj_|jd|j|dS)z= Spawn a new thread to serve this connection #RETURNN)rN)r]rrr0r)r$r3rrrrrLs  zServer.accept_connectioncCs|jy|j|d7<Wnhtk r}zL||jkrrd|j|<|j||j|<|j|\}}}tjd|n|WYdd}~XnXWdQRXdS)Nrz&Server re-enabled tracking & INCREF %r)r_r[rr\rZr rs)r$r3rrrrrrrrrQs  z Server.increfcCs||jkr$||jkr$tjd|dS|j.|j|d8<|j|dkrT|j|=WdQRX||jkrdfdf|j|<tjd||j|j|=WdQRXdS)NzServer DECREF skipping %rrrzdisposing of obj with id %r)r[r\r rsr_rZ)r$r3rrrrrRs     z Server.decrefN)r*r,r-r.Zpublicr%rwriryrrrrrrPrNrOrJrKrMrLrQrRrrrrrI}s. "Q rIc@seZdZdgZdZdZdZdS)StatevaluerrN)r*r,r-r/INITIALSTARTEDSHUTDOWNrrrrrsr)pickleZ xmlrpclibc@seZdZdZiZeZd!ddZddZdd Z dffd d Z e dffd d Z ddZ d"ddZddZddZddZddZeddZeddZe d#dd ZdS)$rz! Base class for managers NrcCs\|dkrtjj}||_tj||_t|_tj|j_ ||_ t |\|_ |_ |pTt|_dS)N)r rfrW_addressrV_authkeyr_staterr _serializerrXZ _Listener_Clientr_ctx)r$r"rWr`Zctxrrrr%s   zBaseManager.__init__cCst|j|j|j|jS)zX Return server object with serve_forever() method and address attribute )rI _registryrrr)r$rrr get_servers zBaseManager.get_servercCs8t|j\}}||j|jd}t|ddtj|j_dS)z> Connect manager object to the server process )rWNrP) rXrrrr9rrrr)r$rarbrrrrconnects zBaseManager.connectc Cs|dk rt| rtdtjdd\}}|jjt|j|j|j |j |j |||fd|_ dj dd|j jD}t|jd ||j _|j j|j|j|_ |jtj|j_tj|t|j|j |j |j |j|jfd d |_dS) z@ Spawn a server process for this manager object Nzinitializer must be a callableF)Zduplex)rcr5:css|]}t|VqdS)N)r?)rirrr sz$BaseManager.start..r=r)r5 exitpriority)rB TypeErrorrZPiperZProcessr _run_serverrrrr_processrZ _identityr*rrkr}r1rrrrr Finalize_finalize_managerrrJ)r$ initializerinitargsreaderwriterrrrrrks&       zBaseManager.startc CsN|dk r|||j||||}|j|j|jtjd|j|jdS)z@ Create a server, report its address and run it Nzmanager serving at %r)_Serverr0r"r}r r|rw) clsrUr"rWr`rrrserverrrrrs zBaseManager._run_serverc OsN|j|j|jd}zt|dd|f||\}}Wd|jXt||j||fS)zP Create a new shared object; return the token and exposed tuple )rWNrK)rrrr9r}r)r$r!r5r6rr#rrrr_create%s  zBaseManager._createcCs*|jdk r&|jj||jjs&d|_dS)zC Join the manager process (if it has been spawned) N)rris_alive)r$timeoutrrrr1s   zBaseManager.joinc Cs.|j|j|jd}z t|ddS|jXdS)zS Return some info about the servers shared objects and connections )rWNrN)rrrr9r})r$rrrr _debug_info:s zBaseManager._debug_infoc Cs.|j|j|jd}z t|ddS|jXdS)z5 Return the number of shared objects )rWNrO)rrrr9r})r$rrrr_number_of_objectsDs zBaseManager._number_of_objectscCs|jjtjkr|j|S)N)rrrrrk)r$rrr __enter__NszBaseManager.__enter__cCs |jdS)N)rJ)r$exc_typeexc_valexc_tbrrr__exit__TszBaseManager.__exit__cCs|jrtjdy,|||d}zt|ddWd|jXWntk rRYnX|jdd|jrtjdt|drtjd |j|jd d|jrtjd t j |_ y t j |=Wntk rYnXdS) zQ Shutdown the manager process; will be registered as a finalizer z#sending shutdown message to manager)rWNrJg?)rzmanager still alive terminatez'trying to `terminate()` manager processg?z#manager still alive after terminate)rr r|r9r}r{rhasattrrrrrr_address_to_localr)r r"rWr'rrrrrrWs.         zBaseManager._finalize_managercCs|jS)N)r)r$rrrwszBaseManager.Tc sd|jkr|jj|_dkr"t|p0tdd}|p@tdd}|r`xt|jD]\}}qTW|||f|j<|rfdd} | _t|| dS)z9 Register a typeid with the manager type rN _exposed__method_to_typeid_cs`tjd|jf||\}}||j||j|d}|j|j|jd}t|dd|jf|S)Nz)requesting creation of a shared %r object)managerrWr)rWrR) r rsrrrrr"r9r#)r$r5r6rZexpproxyr)rr!rrrDs  z"BaseManager.register..temp) __dict__rcopy AutoProxyrrrr*setattr) rr!rBrrr create_methodkeyrrDr)rr!rregisterys    zBaseManager.register)NNrN)N)NNNNT)r*r,r-r.rrIrr%rrrk classmethodrrrrrrr staticmethodrpropertyr"rrrrrrs*  $    c@seZdZddZddZdS)ProcessLocalSetcCstj|dddS)NcSs|jS)N)clear)rrrrrsz*ProcessLocalSet.__init__..)r register_after_fork)r$rrrr%szProcessLocalSet.__init__cCs t|ffS)N)r)r$rrr __reduce__szProcessLocalSet.__reduce__N)r*r,r-r%rrrrrrsrc@seZdZdZiZejZdddZddZ fifd d Z d d Z d dZ e ddZddZddZddZddZddZdS)rz. A base for proxies of shared objects NTFc Cstj8tjj|jd}|dkr:tjtf}|tj|j<WdQRX|d|_|d|_ ||_ |j j |_ ||_ ||_t|d|_||_|dk rtj||_n"|j dk r|j j|_n tjj|_|r|jtj|tjdS)Nrr)r_mutexrrr"r ZForkAwareLocalr_tls_idset_tokenr#_id_managerrrXr_owned_by_managerr rVrrfrW_increfr _after_fork) r$rr`rrWrrQ manager_ownedZ tls_idsetrrrr%s*      zBaseProxy.__init__cCsdtjdtjj}tjjdkr4|dtjj7}|j|jj |j d}t |dd|f||j _ dS)Nzmaking connection to managerZ MainThread|)rWrL)r rsr rfrr]rrrr"rr9rr)r$rrrrr_connects  zBaseProxy._connectc Csy |jj}Wn6tk rBtjdtjj|j|jj}YnX|j |j |||f|j \}}|dkrp|S|dkr|\}}|j j |jd } |jj|_| ||j|j |j|d} |j|j|jd}t|dd|jf| St||dS) zW Try to call a method of the referrent and return a copy of the result z#thread %r does not own a connectionz#RETURNz#PROXYr)rrWr)rWNrR)rrrr rsr]rrrr0rr1rrr!rr"rrrr9r#r2) r$r4r5r6rr7r8rrrrrrr _callmethods,      zBaseProxy._callmethodcCs |jdS)z9 Get a copy of the value of the referent z #GETVALUE)r)r$rrr _getvalueszBaseProxy._getvaluec Cs|jrtjd|jjdS|j|jj|jd}t|dd|j ftjd|jj|j j |j |j oj|j j }tj|tj|j|j||j|j |jfdd|_dS)Nz%owned_by_manager skipped INCREF of %r)rWrQz INCREF %r )r5r)rr rsrr#rr"rr9rraddrrrr_decrefrZ_close)r$rr'rrrr s zBaseProxy._increfcCs|j|j|dks |jtjkry2tjd|j||j|d}t|dd|jfWqt k r}ztjd|WYdd}~XqXntjd|j| rt |drtjdt j j |jj|`dS)Nz DECREF %r)rWrRz... decref failed %sz%DECREF %r -- manager already shutdownrz-thread %r has no more proxies so closing conn)discardr#rrrr rsr"r9r{rr]rrrr})rrWr'ZtlsZidsetrrrrrrr s    zBaseProxy._decrefcCsHd|_y |jWn0tk rB}ztjd|WYdd}~XnXdS)Nzincref failed: %s)rrr{r r|)r$rrrrr9s  zBaseProxy._after_forkcCs^i}tdk r|j|d<t|ddrB|j|d<tt|j|j|ffStt||j|j|ffSdS)NrW_isautoFr) r rrr RebuildProxyrrrr)r$r6rrrrAs    zBaseProxy.__reduce__cCs|jS)N)r)r$memorrr __deepcopy__NszBaseProxy.__deepcopy__cCsdt|j|jjt|fS)Nz<%s object, typeid %r at %#x>)rr*rr!r#)r$rrrr+QszBaseProxy.__repr__c Cs4y |jdStk r.t|dddSXdS)zV Return representation of the referent (or a fall-back if that fails) r+Nrz; '__str__()' failed>r)rr{r)r$rrrr@Us zBaseProxy.__str__)NNNTF)r*r,r-r.rr ZForkAwareThreadLockrr%rrrrrrrrrr+r@rrrrrs (   cCsttjdd}|rT|j|jkrTtjd|d|d<|j|jkrT|j|j|j|j<|j ddopttjdd }|||fd|i|S) z5 Function used for unpickling proxy objects. rgNz*Rebuild a proxy owned by manager, token=%rTrrQZ _inheritingF) rr rfr"r rsr#r\rZpop)rErr`r6rrQrrrrbs   rc Csrt|}y |||fStk r(YnXi}x|D]}td||f|q4Wt|tf|}||_||||f<|S)zB Return a proxy type whose methods are given by `exposed` zLdef %s(self, *args, **kwds): return self._callmethod(%r, args, kwds))rrexecrrr)rr_cacheZdicmeth ProxyTyperrr MakeProxyTypews   rTc Cst|d}|dkrB||j|d}zt|dd|f}Wd|jX|dkrX|dk rX|j}|dkrjtjj}td|j |}||||||d} d| _ | S)z* Return an auto-proxy for `token` rN)rWrMz AutoProxy[%s])rrWrQT) rXr"r9r}rr rfrWrr!r) rr`rrWrrQrrrrrrrrs    rc@seZdZddZddZdS) NamespacecKs|jj|dS)N)rupdate)r$r6rrrr%szNamespace.__init__cCs^t|jj}g}x,|D]$\}}|jds|jd||fqW|jd|jjdj|fS)NrGz%s=%rz%s(%s)z, ) rrr startswithrCrr)r*r)r$rrDrrrrrr+s zNamespace.__repr__N)r*r,r-r%r+rrrrrsrc@s8eZdZd ddZddZddZdd ZeeeZd S) ValueTcCs||_||_dS)N) _typecode_value)r$rrlockrrrr%szValue.__init__cCs|jS)N)r)r$rrrrsz Value.getcCs ||_dS)N)r)r$rrrrrsz Value.setcCsdt|j|j|jfS)Nz %s(%r, %r))rr*rr)r$rrrr+szValue.__repr__N)T) r*r,r-r%rrr+rrrrrrrs  rcCs tj||S)N)r)rZsequencerrrrArraysrc@s8eZdZdZddZddZd d Zd d Zd dZdS) IteratorProxy__next__r0throwr}cCs|S)Nr)r$rrr__iter__szIteratorProxy.__iter__cGs |jd|S)Nr)r)r$r5rrrrszIteratorProxy.__next__cGs |jd|S)Nr0)r)r$r5rrrr0szIteratorProxy.sendcGs |jd|S)Nr)r)r$r5rrrrszIteratorProxy.throwcGs |jd|S)Nr})r)r$r5rrrr}szIteratorProxy.closeN)rr0rr}) r*r,r-rrrr0rr}rrrrrs rc@s2eZdZd ZdddZddZd d Zd d ZdS) AcquirerProxyacquirereleaseTNcCs"|dkr|fn||f}|jd|S)Nr )r)r$Zblockingrr5rrrr szAcquirerProxy.acquirecCs |jdS)Nr )r)r$rrrr szAcquirerProxy.releasecCs |jdS)Nr )r)r$rrrrszAcquirerProxy.__enter__cCs |jdS)Nr )r)r$rrrrrrrszAcquirerProxy.__exit__)r r )TN)r*r,r-rr r rrrrrrr s  r c@s4eZdZdZdddZd d Zd d Zdd dZdS)ConditionProxyr r rmnotify notify_allNcCs|jd|fS)Nrm)r)r$rrrrrmszConditionProxy.waitcCs |jdS)Nr )r)r$rrrr szConditionProxy.notifycCs |jdS)Nr)r)r$rrrrszConditionProxy.notify_allcCsh|}|r|S|dk r$tj|}nd}d}x6|sb|dk rP|tj}|dkrPP|j||}q.W|S)Nr)timeZ monotonicrm)r$Z predicaterr8ZendtimeZwaittimerrrwait_fors   zConditionProxy.wait_for)r r rmr r)N)N)r*r,r-rrmr rrrrrrr s  r c@s2eZdZdZddZddZd d Zdd d Zd S) EventProxyrlrrrmcCs |jdS)Nrl)r)r$rrrrlszEventProxy.is_setcCs |jdS)Nr)r)r$rrrrszEventProxy.setcCs |jdS)Nr)r)r$rrrrszEventProxy.clearNcCs|jd|fS)Nrm)r)r$rrrrrmszEventProxy.wait)rlrrrm)N)r*r,r-rrlrrrmrrrrrs rc@sNeZdZdZdddZdd Zd d Zed d ZeddZ eddZ dS) BarrierProxy__getattribute__rmabortresetNcCs|jd|fS)Nrm)r)r$rrrrrm szBarrierProxy.waitcCs |jdS)Nr)r)r$rrrrszBarrierProxy.abortcCs |jdS)Nr)r)r$rrrrszBarrierProxy.resetcCs |jddS)Nrparties)r)r)r$rrrrszBarrierProxy.partiescCs |jddS)Nr n_waiting)r)r)r$rrrrszBarrierProxy.n_waitingcCs |jddS)Nrbroken)r)r)r$rrrrszBarrierProxy.broken)rrmrr)N) r*r,r-rrmrrrrrrrrrrr s   rc@s(eZdZd ZddZddZdd Zd S) NamespaceProxyr __setattr__ __delattr__cCs0|ddkrtj||Stj|d}|d|fS)NrrGrr)objectr)r$r callmethodrrr __getattr__ s   zNamespaceProxy.__getattr__cCs4|ddkrtj|||Stj|d}|d||fS)NrrGrr)rrr)r$rrrrrrr%s  zNamespaceProxy.__setattr__cCs0|ddkrtj||Stj|d}|d|fS)NrrGrr)rrr)r$rrrrrr*s   zNamespaceProxy.__delattr__N)rrr)r*r,r-rrrrrrrrrsrc@s*eZdZdZddZddZeeeZdS) ValueProxyrrcCs |jdS)Nr)r)r$rrrr3szValueProxy.getcCs|jd|fS)Nr)r)r$rrrrr5szValueProxy.setN)rr)r*r,r-rrrrrrrrrr1sr BaseListProxy__add__ __contains__ __delitem__ __getitem____len____mul__ __reversed____rmul__ __setitem__rCcountextendindexinsertrremovereverser__imul__c@seZdZddZddZdS) ListProxycCs|jd|f|S)Nr+)r)r$rrrr__iadd__AszListProxy.__iadd__cCs|jd|f|S)Nr0)r)r$rrrrr0DszListProxy.__imul__N)r*r,r-r2r0rrrrr1@sr1 DictProxyrrrrhas_keypopitem setdefaultrIterator ArrayProxy PoolProxyapply apply_asyncr}imapimap_unorderedrmap map_asyncstarmap starmap_asyncrZ AsyncResult)r;r?rAr<r=c@seZdZddZddZdS)r9cCs|S)Nr)r$rrrrdszPoolProxy.__enter__cCs |jdS)N)r)r$rrrrrrrfszPoolProxy.__exit__N)r*r,r-rrrrrrr9csc@seZdZdZdS)ra( Subclass of `BaseManager` which supports a number of shared object types. The types registered are those intended for the synchronization of threads, plus `dict`, `list` and `Namespace`. The `multiprocessing.Manager()` function creates started instances of this class. N)r*r,r-r.rrrrrms QueueZ JoinableQueuerdr^RLock SemaphoreBoundedSemaphore ConditionBarrierPoolrdictF)rr)r)rrr)NNNT)T)r!r"r#r$r%r&r'r(r)rCr*r+r,r-rr.r/rr0)r"r#r$rr%r)rrrr4rrrr5r6rr)r%r$r)) r:r;r}r<r=rr>r?r@rAr)I__all__rpr]rZqueuerrrrcontextr r r r r rrrZ view_typesrr Z view_typerrr9r2r{r:rFrHrIrrarbZ XmlListenerZ XmlClientrXrrrrrrrrrrrr r rrrrr r1r3rr8Z BasePoolProxyr9rrBrdr^rCrDrErFrGrHrIrrrr s             ; ] 4             popen_fork.cpython-36.pyc000064400000004124147204630710011341 0ustar003 \ @s>ddlZddlZddlZddlmZdgZGdddeZdS)N)utilPopenc@sHeZdZdZddZddZejfddZdd d Z d d Z d dZ dS)rforkcCstjd|_|j|dS)N)rZ_flush_std_streams returncode_launch)self process_objr 2/usr/lib64/python3.6/multiprocessing/popen_fork.py__init__szPopen.__init__cCs|S)Nr )rfdr r r duplicate_for_childszPopen.duplicate_for_childcCs|jdkrx>ytj|j|\}}Wn tk rB}zdSd}~Xq XPq W||jkrtj|rntj| |_ntj|s|ttj ||_|jS)N) roswaitpidpidOSError WIFSIGNALEDWTERMSIG WIFEXITEDAssertionError WEXITSTATUS)rflagrstser r r polls    z Popen.pollNcCsN|jdkrH|dk r0ddlm}||jg|s0dS|j|dkrBtjndS|jS)Nr)waitg)rZmultiprocessing.connectionrsentinelrrWNOHANG)rtimeoutrr r r r+s  z Popen.waitc Cs\|jdkrXytj|jtjWn8tk r2Yn&tk rV|jdddkrRYnXdS)Ng?)r) rrkillrsignalSIGTERMProcessLookupErrorrr)rr r r terminate5s zPopen.terminatec Csd}tj\}}tj|_|jdkrdz0tj|dtjkrJddl}|j|j }Wdtj |Xn"tj|t j |tj|f||_ dS)Nrrrandom)rpiperrclosesysmodulesr%Zseed _bootstrap_exitrZFinalizer)rr codeZparent_rZchild_wr%r r r r?s       z Popen._launch)N) __name__ __module__ __qualname__methodr rrrrrr$rr r r r r s  )rr(r!r__all__objectrr r r r s  popen_forkserver.cpython-36.opt-2.pyc000064400000004430147204630710013530 0ustar003 \@sddlZddlZddlmZmZejs.edddlmZddlm Z ddlm Z ddlm Z d gZ Gd d d e ZGd d d e jZdS) N) reductionset_spawning_popenz,No support for sending fds between processes) forkserver) popen_fork)spawn)utilPopenc@seZdZddZddZdS)_DupFdcCs ||_dS)N)ind)selfr r 8/usr/lib64/python3.6/multiprocessing/popen_forkserver.py__init__sz_DupFd.__init__cCstj|jS)N)rZget_inherited_fdsr )r r r rdetachsz _DupFd.detachN)__name__ __module__ __qualname__rrr r r rr sr csBeZdZdZeZfddZddZddZe j fdd Z Z S) r rcsg|_tj|dS)N)_fdssuperr)r process_obj) __class__r rr!szPopen.__init__cCs|jj|t|jdS)Nr)rappendlen)r fdr r rduplicate_for_child%s zPopen.duplicate_for_childcCstj|j}tj}t|ztj||tj||WdtdXtj |j \|_ }t j |tj|j ft|ddd}|j|jWdQRXtj|j |_dS)NwbT)closefd)rZget_preparation_data_nameioBytesIOrrdumprZconnect_to_new_processrsentinelrZFinalizeoscloseopenwrite getbuffer read_unsignedpid)r rZ prep_dataZbufwfr r r_launch)s   z Popen._launchc Csr|jdkrlddlm}|tjkr$dnd}||jg|s:dSytj|j|_Wntt fk rjd|_YnX|jS)Nr)wait) returncodeZmultiprocessing.connectionr-r#WNOHANGr"rr(OSErrorEOFError)r flagr-Ztimeoutr r rpoll9s   z Popen.poll) rrrmethodr ZDupFdrrr,r#r0r4 __classcell__r r )rrr s  )rr#contextrrZHAVE_SEND_HANDLE ImportErrorrrrr__all__objectr r r r r rs     popen_forkserver.cpython-36.pyc000064400000004430147204630710012570 0ustar003 \@sddlZddlZddlmZmZejs.edddlmZddlm Z ddlm Z ddlm Z d gZ Gd d d e ZGd d d e jZdS) N) reductionset_spawning_popenz,No support for sending fds between processes) forkserver) popen_fork)spawn)utilPopenc@seZdZddZddZdS)_DupFdcCs ||_dS)N)ind)selfr r 8/usr/lib64/python3.6/multiprocessing/popen_forkserver.py__init__sz_DupFd.__init__cCstj|jS)N)rZget_inherited_fdsr )r r r rdetachsz _DupFd.detachN)__name__ __module__ __qualname__rrr r r rr sr csBeZdZdZeZfddZddZddZe j fdd Z Z S) r rcsg|_tj|dS)N)_fdssuperr)r process_obj) __class__r rr!szPopen.__init__cCs|jj|t|jdS)Nr)rappendlen)r fdr r rduplicate_for_child%s zPopen.duplicate_for_childcCstj|j}tj}t|ztj||tj||WdtdXtj |j \|_ }t j |tj|j ft|ddd}|j|jWdQRXtj|j |_dS)NwbT)closefd)rZget_preparation_data_nameioBytesIOrrdumprZconnect_to_new_processrsentinelrZFinalizeoscloseopenwrite getbuffer read_unsignedpid)r rZ prep_dataZbufwfr r r_launch)s   z Popen._launchc Csr|jdkrlddlm}|tjkr$dnd}||jg|s:dSytj|j|_Wntt fk rjd|_YnX|jS)Nr)wait) returncodeZmultiprocessing.connectionr-r#WNOHANGr"rr(OSErrorEOFError)r flagr-Ztimeoutr r rpoll9s   z Popen.poll) rrrmethodr ZDupFdrrr,r#r0r4 __classcell__r r )rrr s  )rr#contextrrZHAVE_SEND_HANDLE ImportErrorrrrr__all__objectr r r r r rs     popen_spawn_posix.cpython-36.opt-1.pyc000064400000004074147204630710013715 0ustar003 \p@spddlZddlZddlmZmZddlmZddlmZddlmZdgZ Gdd d e Z Gd ddej Z dS) N) reductionset_spawning_popen) popen_fork)spawn)utilPopenc@seZdZddZddZdS)_DupFdcCs ||_dS)N)fd)selfr r 9/usr/lib64/python3.6/multiprocessing/popen_spawn_posix.py__init__sz_DupFd.__init__cCs|jS)N)r )r r r r detachsz _DupFd.detachN)__name__ __module__ __qualname__rrr r r r r sr cs4eZdZdZeZfddZddZddZZ S)rrcsg|_tj|dS)N)_fdssuperr)r process_obj) __class__r r rszPopen.__init__cCs|jj||S)N)rappend)r r r r r duplicate_for_child"s zPopen.duplicate_for_childc Cs@ddlm}|j}|jj|tj|j}tj }t |zt j ||t j ||Wdt dXd}}}} z~t j\}}t j\}} tj||d} |jj||gtjtj| |j|_||_t| ddd} | j|jWdQRXWd|dk rtj|t j|fx(||| fD]} | dk rt j| qWXdS)Nr)semaphore_tracker) tracker_fdZ pipe_handlewbF)closefd)rZgetfdrrrZget_preparation_data_nameioBytesIOrrdumpospipeZget_command_lineextendrZspawnv_passfdsZget_executablepidsentinelopenwrite getbufferZFinalizeclose) r rrrZ prep_datafpZparent_rZchild_wZchild_rZparent_wcmdfr r r r _launch&s6           z Popen._launch) rrrmethodr ZDupFdrrr. __classcell__r r )rr rs  ) rr"contextrrrrrr__all__objectr rr r r r s    popen_spawn_posix.cpython-36.opt-2.pyc000064400000004074147204630710013716 0ustar003 \p@spddlZddlZddlmZmZddlmZddlmZddlmZdgZ Gdd d e Z Gd ddej Z dS) N) reductionset_spawning_popen) popen_fork)spawn)utilPopenc@seZdZddZddZdS)_DupFdcCs ||_dS)N)fd)selfr r 9/usr/lib64/python3.6/multiprocessing/popen_spawn_posix.py__init__sz_DupFd.__init__cCs|jS)N)r )r r r r detachsz _DupFd.detachN)__name__ __module__ __qualname__rrr r r r r sr cs4eZdZdZeZfddZddZddZZ S)rrcsg|_tj|dS)N)_fdssuperr)r process_obj) __class__r r rszPopen.__init__cCs|jj||S)N)rappend)r r r r r duplicate_for_child"s zPopen.duplicate_for_childc Cs@ddlm}|j}|jj|tj|j}tj }t |zt j ||t j ||Wdt dXd}}}} z~t j\}}t j\}} tj||d} |jj||gtjtj| |j|_||_t| ddd} | j|jWdQRXWd|dk rtj|t j|fx(||| fD]} | dk rt j| qWXdS)Nr)semaphore_tracker) tracker_fdZ pipe_handlewbF)closefd)rZgetfdrrrZget_preparation_data_nameioBytesIOrrdumpospipeZget_command_lineextendrZspawnv_passfdsZget_executablepidsentinelopenwrite getbufferZFinalizeclose) r rrrZ prep_datafpZparent_rZchild_wZchild_rZparent_wcmdfr r r r _launch&s6           z Popen._launch) rrrmethodr ZDupFdrrr. __classcell__r r )rr rs  ) rr"contextrrrrrr__all__objectr rr r r r s    popen_spawn_posix.cpython-36.pyc000064400000004074147204630710012756 0ustar003 \p@spddlZddlZddlmZmZddlmZddlmZddlmZdgZ Gdd d e Z Gd ddej Z dS) N) reductionset_spawning_popen) popen_fork)spawn)utilPopenc@seZdZddZddZdS)_DupFdcCs ||_dS)N)fd)selfr r 9/usr/lib64/python3.6/multiprocessing/popen_spawn_posix.py__init__sz_DupFd.__init__cCs|jS)N)r )r r r r detachsz _DupFd.detachN)__name__ __module__ __qualname__rrr r r r r sr cs4eZdZdZeZfddZddZddZZ S)rrcsg|_tj|dS)N)_fdssuperr)r process_obj) __class__r r rszPopen.__init__cCs|jj||S)N)rappend)r r r r r duplicate_for_child"s zPopen.duplicate_for_childc Cs@ddlm}|j}|jj|tj|j}tj }t |zt j ||t j ||Wdt dXd}}}} z~t j\}}t j\}} tj||d} |jj||gtjtj| |j|_||_t| ddd} | j|jWdQRXWd|dk rtj|t j|fx(||| fD]} | dk rt j| qWXdS)Nr)semaphore_tracker) tracker_fdZ pipe_handlewbF)closefd)rZgetfdrrrZget_preparation_data_nameioBytesIOrrdumpospipeZget_command_lineextendrZspawnv_passfdsZget_executablepidsentinelopenwrite getbufferZFinalizeclose) r rrrZ prep_datafpZparent_rZchild_wZchild_rZparent_wcmdfr r r r _launch&s6           z Popen._launch) rrrmethodr ZDupFdrrr. __classcell__r r )rr rs  ) rr"contextrrrrrr__all__objectr rr r r r s    popen_spawn_win32.cpython-36.opt-1.pyc000064400000005243147204630710013514 0ustar003 \ @sddlZddlZddlZddlZddlZddlmZmZmZddl m Z ddl m Z dgZ dZ ejdkoreed d Zejjjd ZGd ddeZdS) N) reductionget_spawning_popenset_spawning_popen)spawn)utilPopeniZwin32frozenFzpythonservice.exec@s>eZdZdZdZddZddZddd Zd d Zd d Z dS)rz@ Start a subprocess to run the code of a process object rc Cstj|j}tjdd\}}tj|d}tjtj |d}dj dd|D}t |ddd}y4tj tj |ddd dddd \}} } } tj| Wntj|YnX| |_d|_||_t||_tj|tj|jft|ztj||tj||WdtdXWdQRXdS) Nr)Z parent_pidZ pipe_handle css|]}d|VqdS)z"%s"N).0xr r 9/usr/lib64/python3.6/multiprocessing/popen_spawn_win32.py )sz!Popen.__init__..wbT)closefdF)rZget_preparation_data_name_winapiZ CreatePipemsvcrtZopen_osfhandleZget_command_lineosgetpidjoinopenZ CreateProcessZget_executableZ CloseHandlepid returncode_handleintsentinelrZFinalizerrdump) selfZ process_objZ prep_dataZrhandleZwhandleZwfdcmdZto_childZhpZhtrtidr r r__init__ s2      zPopen.__init__cCstj||jS)N)rZ duplicater)rZhandler r rduplicate_for_childEszPopen.duplicate_for_childNcCst|jdkrn|dkrtj}ntdt|dd}tjt|j|}|tjkrntj|j}|t krht j }||_|jS)Nrig?) rrZINFINITEmaxrZWaitForSingleObjectrZ WAIT_OBJECT_0ZGetExitCodeProcess TERMINATEsignalSIGTERM)rtimeoutZmsecsrescoder r rwaitIs   z Popen.waitcCs |jddS)Nr)r()r+)rr r rpollYsz Popen.pollc CsL|jdkrHytjt|jtWn&tk rF|jdddkrBYnXdS)Ng?)r()rrZTerminateProcessrrr%OSErrorr+)rr r r terminate\s  zPopen.terminate)N) __name__ __module__ __qualname____doc__methodr"r#r+r,r.r r r rrs% )rrr&sysrcontextrrrrr__all__r%platformgetattrZWINEXE executablelowerendswithZ WINSERVICEobjectrr r r rs  popen_spawn_win32.cpython-36.opt-2.pyc000064400000005122147204630710013511 0ustar003 \ @sddlZddlZddlZddlZddlZddlmZmZmZddl m Z ddl m Z dgZ dZ ejdkoreed d Zejjjd ZGd ddeZdS) N) reductionget_spawning_popenset_spawning_popen)spawn)utilPopeniZwin32frozenFzpythonservice.exec@s:eZdZdZddZddZd ddZd d Zd d ZdS)rrc Cstj|j}tjdd\}}tj|d}tjtj |d}dj dd|D}t |ddd}y4tj tj |ddd dddd \}} } } tj| Wntj|YnX| |_d|_||_t||_tj|tj|jft|ztj||tj||WdtdXWdQRXdS) Nr)Z parent_pidZ pipe_handle css|]}d|VqdS)z"%s"N).0xr r 9/usr/lib64/python3.6/multiprocessing/popen_spawn_win32.py )sz!Popen.__init__..wbT)closefdF)rZget_preparation_data_name_winapiZ CreatePipemsvcrtZopen_osfhandleZget_command_lineosgetpidjoinopenZ CreateProcessZget_executableZ CloseHandlepid returncode_handleintsentinelrZFinalizerrdump) selfZ process_objZ prep_dataZrhandleZwhandleZwfdcmdZto_childZhpZhtrtidr r r__init__ s2      zPopen.__init__cCstj||jS)N)rZ duplicater)rZhandler r rduplicate_for_childEszPopen.duplicate_for_childNcCst|jdkrn|dkrtj}ntdt|dd}tjt|j|}|tjkrntj|j}|t krht j }||_|jS)Nrig?) rrZINFINITEmaxrZWaitForSingleObjectrZ WAIT_OBJECT_0ZGetExitCodeProcess TERMINATEsignalSIGTERM)rtimeoutZmsecsrescoder r rwaitIs   z Popen.waitcCs |jddS)Nr)r()r+)rr r rpollYsz Popen.pollc CsL|jdkrHytjt|jtWn&tk rF|jdddkrBYnXdS)Ng?)r()rrZTerminateProcessrrr%OSErrorr+)rr r r terminate\s  zPopen.terminate)N) __name__ __module__ __qualname__methodr"r#r+r,r.r r r rrs % )rrr&sysrcontextrrrrr__all__r%platformgetattrZWINEXE executablelowerendswithZ WINSERVICEobjectrr r r rs  queues.cpython-36.pyc000064400000021363147204630710010512 0ustar003 \ *@sdddgZddlZddlZddlZddlZddlZddlZddlZddlm Z m Z ddl Z ddl m Z ddl mZejjZdd lmZmZmZmZmZGd ddeZeZGd ddeZGd ddeZdS) Queue SimpleQueue JoinableQueueN)EmptyFull) connection)context)debuginfoFinalizeregister_after_fork is_exitingc@seZdZd(ddZddZddZdd Zd)d d Zd*ddZddZ ddZ ddZ ddZ ddZ ddZddZddZd d!Zed"d#Zed$d%Zed&d'Zd S)+rrcCs|dkrddlm}||_tjdd\|_|_|j|_t j |_ t j dkrTd|_n |j|_|j||_d|_|jt j dkrt|tjdS)Nrr) SEM_VALUE_MAXF)duplexwin32)Z synchronizer_maxsizerPipe_reader_writerLock_rlockosgetpid_opidsysplatform_wlockZBoundedSemaphore_sem _ignore_epipe _after_forkr r)selfmaxsizectxr$./usr/lib64/python3.6/multiprocessing/queues.py__init__$s       zQueue.__init__cCs.tj||j|j|j|j|j|j|j|j fS)N) r assert_spawningrrrrrrrr)r!r$r$r% __getstate__9s zQueue.__getstate__c Cs0|\|_|_|_|_|_|_|_|_|jdS)N) rrrrrrrrr )r!stater$r$r% __setstate__>s$zQueue.__setstate__cCsbtdtjtj|_tj|_d|_d|_ d|_ d|_ d|_ |j j|_|jj|_|jj|_dS)NzQueue._after_fork()F)r threading Conditionr _notempty collectionsdeque_buffer_thread _jointhread_joincancelled_closed_closer send_bytes _send_bytesr recv_bytes _recv_bytespoll_poll)r!r$r$r%r Cs   zQueue._after_forkTNc Cs\|j s t|jj||st|j.|jdkr8|j|jj ||jj WdQRXdS)N) r4AssertionErrorracquirerr-r1 _start_threadr0appendnotify)r!objblocktimeoutr$r$r%putPs   z Queue.putc Cs|r2|dkr2|j|j}WdQRX|jjnr|rBtj|}|jj||sTtzB|rv|tj}|j|stn |jst|j}|jjWd|jjXt j |S)N) rr9rreleasetimeZ monotonicr=rr;_ForkingPicklerloads)r!rBrCresZdeadliner$r$r%get[s&      z Queue.getcCs|j|jjjS)N)rr_semlockZ _get_value)r!r$r$r%qsizessz Queue.qsizecCs |j S)N)r;)r!r$r$r%emptywsz Queue.emptycCs |jjjS)N)rrK_is_zero)r!r$r$r%fullzsz Queue.fullcCs |jdS)NF)rJ)r!r$r$r% get_nowait}szQueue.get_nowaitcCs |j|dS)NF)rD)r!rAr$r$r% put_nowaitszQueue.put_nowaitc Cs2d|_z|jjWd|j}|r,d|_|XdS)NT)r4rcloser5)r!rRr$r$r%rRsz Queue.closecCs$td|jst|jr |jdS)NzQueue.join_thread())r r4r<r2)r!r$r$r% join_threads zQueue.join_threadc Cs6tdd|_y|jjWntk r0YnXdS)NzQueue.cancel_join_thread()T)r r3r2ZcancelAttributeError)r!r$r$r%cancel_join_threads zQueue.cancel_join_threadcCstd|jjtjtj|j|j|j|j |j j |j fdd|_ d|j _td|j jtd|jst|j tjtj|j gd d|_t|tj|j|jgd d|_dS) NzQueue._start_thread()ZQueueFeederThread)targetargsnameTzdoing self._thread.start()z... done self._thread.start())Z exitpriority )r r0clearr+ZThreadr_feedr-r7rrrRrr1Zdaemonstartr3r _finalize_joinweakrefrefr2_finalize_closer5)r!r$r$r%r>s(       zQueue._start_threadcCs4td|}|dk r(|jtdntddS)Nzjoining queue threadz... queue thread joinedz... queue thread already dead)r join)ZtwrZthreadr$r$r%r_s  zQueue._finalize_joinc Cs.td||jt|jWdQRXdS)Nztelling queue thread to quit)r r? _sentinelr@)buffernotemptyr$r$r%rbs zQueue._finalize_closecCsPtd|j}|j}|j}|j} t} tjdkr<|j} |j} nd} xy|z|sX|Wd|Xybx\| } | | krtd|dStj | } | dkr|| qh| z || Wd| XqhWWnt k rYnXWqDt k rF}zJ|rt |ddt jkrdStr&td|dSddl}|jWYdd}~XqDXqDWdS)Nz$starting thread to feed data to piperz%feeder thread got sentinel -- exitingerrnorzerror in queue thread: %s)r r=rEwaitpopleftrdrrrGdumps IndexError ExceptiongetattrrgZEPIPErr traceback print_exc)rerfr6Z writelockrRZ ignore_epipeZnacquireZnreleaseZnwaitZbpopleftsentinelZwacquireZwreleaserAernr$r$r%r]sR       z Queue._feed)r)TN)TN)__name__ __module__ __qualname__r&r(r*r rDrJrLrMrOrPrQrRrSrUr> staticmethodr_rbr]r$r$r$r%r"s$    c@s@eZdZdddZddZddZdd d Zd d ZddZd S)rrcCs*tj|||d|jd|_|j|_dS)N)r#r)rr&Z Semaphore_unfinished_tasksr,_cond)r!r"r#r$r$r%r&s zJoinableQueue.__init__cCstj||j|jfS)N)rr(rwrv)r!r$r$r%r(szJoinableQueue.__getstate__cCs,tj||dd|dd\|_|_dS)Nry)rr*rwrv)r!r)r$r$r%r*szJoinableQueue.__setstate__TNcCsx|j s t|jj||st|jJ|j8|jdkr@|j|j j ||j j |jj WdQRXWdQRXdS)N)r4r<rr=rr-rwr1r>r0r?rvrEr@)r!rArBrCr$r$r%rDs    zJoinableQueue.putc Cs@|j0|jjdstd|jjjr2|jjWdQRXdS)NFz!task_done() called too many times)rwrvr= ValueErrorrKrNZ notify_all)r!r$r$r% task_done's   zJoinableQueue.task_donec Cs,|j|jjjs|jjWdQRXdS)N)rwrvrKrNrh)r!r$r$r%rc.s zJoinableQueue.join)r)TN) rrrsrtr&r(r*rDr{rcr$r$r$r%r s   c@s<eZdZddZddZddZddZd d Zd d Zd S)rcCsHtjdd\|_|_|j|_|jj|_tj dkr:d|_ n |j|_ dS)NF)rr) rrrrrrr:r;rrr)r!r#r$r$r%r&9s    zSimpleQueue.__init__cCs |j S)N)r;)r!r$r$r%rMBszSimpleQueue.emptycCstj||j|j|j|jfS)N)r r'rrrr)r!r$r$r%r(Es zSimpleQueue.__getstate__cCs"|\|_|_|_|_|jj|_dS)N)rrrrr:r;)r!r)r$r$r%r*IszSimpleQueue.__setstate__c Cs&|j|jj}WdQRXtj|S)N)rrr8rGrH)r!rIr$r$r%rJMszSimpleQueue.getc CsDtj|}|jdkr"|jj|n|j|jj|WdQRXdS)N)rGrjrrr6)r!rAr$r$r%rDSs   zSimpleQueue.putN) rrrsrtr&rMr(r*rJrDr$r$r$r%r7s  )__all__rrr+r.rFr`rgZqueuerrZ_multiprocessingrr Z reductionZForkingPicklerrGutilr r r r robjectrrdrrr$r$r$r% s$   b *__init__.cpython-36.opt-1.pyc000064400000131372147204630710011703 0ustar003 \$@sdZddddddddd g Zd d lTd d lZeej7Zd d lmZmZd dlm Z d d l Z d d l Zd dlmZd dlmZmZmZd dlmZyd dlmZWnek rYn Xej eyd dlm!Z!Wnek rYnXGddde"Z#Gddde$Z%Gddde&Z'Gddde(Z)Gddde*Z+yd dlm+Z+Wnek rXYnXdZ,dZ-d Z.d!d!d d"d#dZ/d$d%Z0yd d&lm0Z0Wnek rYnXGd'dde*Z1Gd(d d e2Z3Gd)dde2Z4Gd*ddeZ5Gd+dde6Z7d S),a?This module implements specialized container datatypes providing alternatives to Python's general purpose built-in containers, dict, list, set, and tuple. * namedtuple factory function for creating tuple subclasses with named fields * deque list-like container with fast appends and pops on either end * ChainMap dict-like class for creating a single view of multiple mappings * Counter dict subclass for counting hashable objects * OrderedDict dict subclass that remembers the order entries were added * defaultdict dict subclass that calls a factory function to supply missing values * UserDict wrapper around dictionary objects for easier dict subclassing * UserList wrapper around list objects for easier list subclassing * UserString wrapper around string objects for easier string subclassing deque defaultdict namedtupleUserDictUserList UserStringCounter OrderedDictChainMap)*N) itemgettereq) iskeyword)proxy)repeatchainstarmap)recursive_repr)r)rc@seZdZddZdS)_OrderedDictKeysViewccst|jEdHdS)N)reversed_mapping)selfr,/usr/lib64/python3.6/collections/__init__.py __reversed__5sz!_OrderedDictKeysView.__reversed__N)__name__ __module__ __qualname__rrrrrr3src@seZdZddZdS)_OrderedDictItemsViewccs(x"t|jD]}||j|fVq WdS)N)rr)rkeyrrrr:sz"_OrderedDictItemsView.__reversed__N)rrrrrrrrr8src@seZdZddZdS)_OrderedDictValuesViewccs$xt|jD]}|j|Vq WdS)N)rr)rrrrrr@sz#_OrderedDictValuesView.__reversed__N)rrrrrrrrr >sr c@seZdZdZdS)_Linkprevnextr __weakref__N)r"r#rr$)rrr __slots__rrrrr!Dsr!c@seZdZdZddZejeefddZej fddZ dd Z d d Z d d Z d*ddZ d+ddZddZejZZddZddZddZejZeZefddZd,ddZed d!Zd"d#Zd$d%Zed-d&d'Z d(d)Z!dS).rz)Dictionary that remembers insertion orderc Os|s td|^}}t|dkr0tdt|y |jWn>tk rxt|_t|j|_}||_|_i|_ YnX|j ||dS)zInitialize an ordered dictionary. The signature is the same as regular dictionaries. Keyword argument order is preserved. z?descriptor '__init__' of 'OrderedDict' object needs an argumentz$expected at most 1 arguments, got %dN) TypeErrorlen_OrderedDict__rootAttributeErrorr!_OrderedDict__hardroot_proxyr"r#_OrderedDict__map_OrderedDict__update)argskwdsrrootrrr__init__Vs    zOrderedDict.__init__c CsZ||krJ||j|<}|j}|j}||||_|_|_||_|||_||||dS)z!od.__setitem__(i, y) <==> od[i]=yN)r-r)r"r#r) rrvalueZ dict_setitemrZLinklinkr1lastrrr __setitem__is zOrderedDict.__setitem__cCs>||||jj|}|j}|j}||_||_d|_d|_dS)z od.__delitem__(y) <==> del od[y]N)r-popr"r#)rrZ dict_delitemr4 link_prev link_nextrrr __delitem__ws  zOrderedDict.__delitem__ccs,|j}|j}x||k r&|jV|j}qWdS)zod.__iter__() <==> iter(od)N)r)r#r)rr1currrrr__iter__s  zOrderedDict.__iter__ccs,|j}|j}x||k r&|jV|j}qWdS)z#od.__reversed__() <==> reversed(od)N)r)r"r)rr1r;rrrrs  zOrderedDict.__reversed__cCs*|j}||_|_|jjtj|dS)z.od.clear() -> None. Remove all items from od.N)r)r"r#r-cleardict)rr1rrrr=s  zOrderedDict.clearTcCsj|s td|j}|r0|j}|j}||_||_n|j}|j}||_||_|j}|j|=tj||}||fS)zRemove and return a (key, value) pair from the dictionary. Pairs are returned in LIFO order if last is true or FIFO order if false. zdictionary is empty)KeyErrorr)r"r#rr-r>r7)rr5r1r4r8r9rr3rrrpopitems  zOrderedDict.popitemc Cst|j|}|j}|j}|j}||_||_|j}|rR|j}||_||_||_||_n|j}||_||_||_||_dS)zMove an existing element to the end (or beginning if last==False). Raises KeyError if the element does not exist. When last=True, acts like a fast version of self[key]=self.pop(key). N)r-r"r#r)) rrr5r4r8r9Z soft_linkr1firstrrr move_to_ends$ zOrderedDict.move_to_endcCsVtj}t|d}||j}|||jd7}|||j|7}|||j|7}|S)Nr&)_sys getsizeofr(__dict__r-r+r))rZsizeofnsizerrr __sizeof__s  zOrderedDict.__sizeof__cCst|S)z:D.keys() -> a set-like object providing a view on D's keys)r)rrrrkeysszOrderedDict.keyscCst|S)z a set-like object providing a view on D's items)r)rrrritemsszOrderedDict.itemscCst|S)z6D.values() -> an object providing a view on D's values)r )rrrrvaluesszOrderedDict.valuescCs0||kr||}||=|S||jkr,t||S)zod.pop(k[,d]) -> v, remove specified key and return the corresponding value. If key is not found, d is returned if given, otherwise KeyError is raised. )_OrderedDict__markerr?)rrdefaultresultrrrr7s zOrderedDict.popNcCs||kr||S|||<|S)zDod.setdefault(k[,d]) -> od.get(k,d), also set od[k]=d if k not in odr)rrrNrrr setdefaultszOrderedDict.setdefaultcCs*|sd|jjfSd|jjt|jfS)zod.__repr__() <==> repr(od)z%s()z%s(%r)) __class__rlistrK)rrrr__repr__szOrderedDict.__repr__cCsHt|j}xttD]}|j|dqW|jf|p8ddt|jfS)z%Return state information for picklingN)varscopyrr7rQiterrK)rZ inst_dictkrrr __reduce__s zOrderedDict.__reduce__cCs |j|S)z!od.copy() -> a shallow copy of od)rQ)rrrrrU szOrderedDict.copycCs |}x|D] }|||<q W|S)zOD.fromkeys(S[, v]) -> New ordered dictionary with keys from S. If not specified, the value defaults to None. r)clsiterabler3rrrrrfromkeyss  zOrderedDict.fromkeyscCs2t|tr&tj||o$ttt||Stj||S)zod.__eq__(y) <==> od==y. Comparison to another OD is order-sensitive while comparison to a regular mapping is order-insensitive. ) isinstancerr>__eq__allmap_eq)rotherrrrr]s zOrderedDict.__eq__)T)T)N)N)"rrr__doc__r2r>r6r,r!r:r<rr=r@rBrIMutableMappingupdater.rJrKrL__ne__objectrMr7rP_recursive_reprrSrXrU classmethodr[r]rrrrrGs0          )rafrom builtins import property as _property, tuple as _tuple from operator import itemgetter as _itemgetter from collections import OrderedDict class {typename}(tuple): '{typename}({arg_list})' __slots__ = () _fields = {field_names!r} def __new__(_cls, {arg_list}): 'Create new instance of {typename}({arg_list})' return _tuple.__new__(_cls, ({arg_list})) @classmethod def _make(cls, iterable, new=tuple.__new__, len=len): 'Make a new {typename} object from a sequence or iterable' result = new(cls, iterable) if len(result) != {num_fields:d}: raise TypeError('Expected {num_fields:d} arguments, got %d' % len(result)) return result def _replace(_self, **kwds): 'Return a new {typename} object replacing specified fields with new values' result = _self._make(map(kwds.pop, {field_names!r}, _self)) if kwds: raise ValueError('Got unexpected field names: %r' % list(kwds)) return result def __repr__(self): 'Return a nicely formatted representation string' return self.__class__.__name__ + '({repr_fmt})' % self def _asdict(self): 'Return a new OrderedDict which maps field names to their values.' return OrderedDict(zip(self._fields, self)) def __getnewargs__(self): 'Return self as a plain tuple. Used by copy and pickle.' return tuple(self) {field_defs} z {name}=%rzW {name} = _property(_itemgetter({index:d}), doc='Alias for field number {index:d}') F)verboserenamemodulec Cst|tr|jddj}ttt|}t|}|rt}xNt|D]B\}}|j spt |sp|j dsp||kr|d|||<|j |qDWxN|g|D]@}t |tk rt d|jstd|t |rtd|qWt}xJ|D]B}|j do| rtd|||krtd ||j |qWtj|t|t|tt|jd d d dd jdd|Ddjddt|Dd}td|d} t|| | |} || _|rt| j|dkrytjd jjdd}Wnttfk rYnX|dk r || _| S)aCReturns a new subclass of tuple with named fields. >>> Point = namedtuple('Point', ['x', 'y']) >>> Point.__doc__ # docstring for the new class 'Point(x, y)' >>> p = Point(11, y=22) # instantiate with positional args or keywords >>> p[0] + p[1] # indexable like a plain tuple 33 >>> x, y = p # unpack like a regular tuple >>> x, y (11, 22) >>> p.x + p.y # fields also accessible by name 33 >>> d = p._asdict() # convert to a dictionary >>> d['x'] 11 >>> Point(**d) # convert from a dictionary Point(x=11, y=22) >>> p._replace(x=100) # _replace() is like str.replace() but targets named fields Point(x=100, y=22) , _z_%dz*Type names and field names must be stringsz8Type names and field names must be valid identifiers: %rz2Type names and field names cannot be a keyword: %rz/Field names cannot start with an underscore: %rz$Encountered duplicate field name: %r'r&z, css|]}tj|dVqdS))nameN)_repr_templateformat).0rqrrr sznamedtuple.. css |]\}}tj||dVqdS))indexrqN)_field_templaters)rtrwrqrrrrus)typename field_names num_fieldsarg_listrepr_fmt field_defsz namedtuple_%s)rNr__main__)r\strreplacesplitrRr_set enumerate isidentifier _iskeyword startswithaddtyper' ValueError_class_templaterstupler(reprjoinr>exec_sourceprintrD _getframe f_globalsgetr*r) ryrzrirjrkseenrwrqclass_definition namespacerOrrrresj               cCs*|j}x|D]}||dd||<q WdS)z!Tally elements from the iterable.r r&N)r)mappingrZZ mapping_getelemrrr_count_elementss r)rcseZdZdZfddZddZd/ddZd d Zed0d d Z fd dZ ddZ ddZ ddZ fddZddZddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+d,Zd-d.ZZS)1raDict subclass for counting hashable items. Sometimes called a bag or multiset. Elements are stored as dictionary keys and their counts are stored as dictionary values. >>> c = Counter('abcdeabcdabcaba') # count elements from a string >>> c.most_common(3) # three most common elements [('a', 5), ('b', 4), ('c', 3)] >>> sorted(c) # list all unique elements ['a', 'b', 'c', 'd', 'e'] >>> ''.join(sorted(c.elements())) # list elements with repetitions 'aaaaabbbbcccdde' >>> sum(c.values()) # total of all counts 15 >>> c['a'] # count of letter 'a' 5 >>> for elem in 'shazam': # update counts from an iterable ... c[elem] += 1 # by adding 1 to each element's count >>> c['a'] # now there are seven 'a' 7 >>> del c['b'] # remove all 'b' >>> c['b'] # now there are zero 'b' 0 >>> d = Counter('simsalabim') # make another counter >>> c.update(d) # add in the second counter >>> c['a'] # now there are nine 'a' 9 >>> c.clear() # empty the counter >>> c Counter() Note: If a count is set to zero or reduced to zero, it will remain in the counter until the entry is deleted or the counter is cleared: >>> c = Counter('aaabbc') >>> c['b'] -= 2 # reduce the count of 'b' by two >>> c.most_common() # 'b' is still in, but its count is zero [('a', 3), ('c', 1), ('b', 0)] csN|s td|^}}t|dkr0tdt|tt|j|j||dS)a Create a new, empty Counter object. And if given, count elements from an input iterable. Or, initialize the count from another mapping of elements to their counts. >>> c = Counter() # a new, empty counter >>> c = Counter('gallahad') # a new counter from an iterable >>> c = Counter({'a': 4, 'b': 2}) # a new counter from a mapping >>> c = Counter(a=4, b=2) # a new counter from keyword args z;descriptor '__init__' of 'Counter' object needs an argumentr&z$expected at most 1 arguments, got %dN)r'r(superrr2rd)r/r0r)rQrrr2s  zCounter.__init__cCsdS)z1The count of elements not in the Counter is zero.r r)rrrrr __missing__szCounter.__missing__NcCs6|dkrt|jtdddStj||jtddS)zList the n most common elements and their counts from the most common to the least. If n is None, then list all element counts. >>> Counter('abcdeabcdabcaba').most_common(3) [('a', 5), ('b', 4), ('c', 3)] Nr&T)rreverse)r)sortedrK _itemgetter_heapqnlargest)rrGrrr most_commons zCounter.most_commoncCstjtt|jS)aIterator over elements repeating each as many times as its count. >>> c = Counter('ABCABC') >>> sorted(c.elements()) ['A', 'A', 'B', 'B', 'C', 'C'] # Knuth's example for prime factors of 1836: 2**2 * 3**3 * 17**1 >>> prime_factors = Counter({2: 2, 3: 3, 17: 1}) >>> product = 1 >>> for factor in prime_factors.elements(): # loop over factors ... product *= factor # and multiply them >>> product 1836 Note, if an element's count has been set to zero or is a negative number, elements() will ignore it. )_chain from_iterable_starmap_repeatrK)rrrrelements+szCounter.elementscCs tddS)Nz@Counter.fromkeys() is undefined. Use Counter(iterable) instead.)NotImplementedError)rYrZvrrrr[CszCounter.fromkeyscs|s td|^}}t|dkr0tdt||r<|dnd}|dk rt|tr|r|j}x8|jD]\}}|||d||<qfWqtt|j|n t |||r|j|dS)aLike dict.update() but add counts instead of replacing them. Source can be an iterable, a dictionary, or another Counter instance. >>> c = Counter('which') >>> c.update('witch') # add elements from another iterable >>> d = Counter('watch') >>> c.update(d) # add elements from another counter >>> c['h'] # four 'h' in which, witch, and watch 4 z9descriptor 'update' of 'Counter' object needs an argumentr&z$expected at most 1 arguments, got %dr N) r'r(r\MappingrrKrrrdr)r/r0rrZself_getrcount)rQrrrdJs    zCounter.updatecOs|s td|^}}t|dkr0tdt||r<|dnd}|dk r|j}t|trxH|jD]\}}||d|||<qbWn x|D]}||dd||<qW|r|j|dS)aLike dict.update() but subtracts counts instead of replacing them. Counts can be reduced below zero. Both the inputs and outputs are allowed to contain zero and negative counts. Source can be an iterable, a dictionary, or another Counter instance. >>> c = Counter('which') >>> c.subtract('witch') # subtract elements from another iterable >>> c.subtract(Counter('watch')) # subtract elements from another counter >>> c['h'] # 2 in which, minus 1 in witch, minus 1 in watch 0 >>> c['w'] # 1 in which, minus 1 in witch, minus 1 in watch -1 z;descriptor 'subtract' of 'Counter' object needs an argumentr&z$expected at most 1 arguments, got %dr N)r'r(rr\rrKsubtract)r/r0rrZrrrrrrrrs   zCounter.subtractcCs |j|S)zReturn a shallow copy.)rQ)rrrrrUsz Counter.copycCs|jt|ffS)N)rQr>)rrrrrXszCounter.__reduce__cs||krtj|dS)zGLike dict.__delitem__() but does not raise KeyError for missing values.N)rr:)rr)rQrrr:szCounter.__delitem__c Cs`|sd|jjSy&djtdj|j}d|jj|fStk rZdj|jjt|SXdS)Nz%s()z, z%r: %rz%s({%s})z {0}({1!r})) rQrrr___mod__rr'rsr>)rrKrrrrSs zCounter.__repr__cCsxt|tstSt}x0|jD]$\}}|||}|dkr|||<qWx,|jD] \}}||krP|dkrP|||<qPW|S)zAdd counts from two counters. >>> Counter('abbb') + Counter('bcc') Counter({'b': 4, 'c': 2, 'a': 1}) r )r\rNotImplementedrK)rrarOrrnewcountrrr__add__s    zCounter.__add__cCs|t|tstSt}x0|jD]$\}}|||}|dkr|||<qWx0|jD]$\}}||krP|dkrPd|||<qPW|S)z Subtract count, but keep only results with positive counts. >>> Counter('abbbc') - Counter('bccd') Counter({'b': 2, 'a': 1}) r )r\rrrK)rrarOrrrrrr__sub__s   zCounter.__sub__cCst|tstSt}x<|jD]0\}}||}||kr:|n|}|dkr|||<qWx,|jD] \}}||kr\|dkr\|||<q\W|S)zUnion is the maximum of value in either of the input counters. >>> Counter('abbb') | Counter('bcc') Counter({'b': 3, 'c': 2, 'a': 1}) r )r\rrrK)rrarOrr other_countrrrr__or__s   zCounter.__or__cCsVt|tstSt}x<|jD]0\}}||}||kr:|n|}|dkr|||<qW|S)z Intersection is the minimum of corresponding counts. >>> Counter('abbb') & Counter('bcc') Counter({'b': 1}) r )r\rrrK)rrarOrrrrrrr__and__s  zCounter.__and__cCs0t}x$|jD]\}}|dkr|||<qW|S)zEAdds an empty counter, effectively stripping negative and zero countsr )rrK)rrOrrrrr__pos__s  zCounter.__pos__cCs4t}x(|jD]\}}|dkrd|||<qW|S)z{Subtracts from an empty counter. Strips positive and zero counts, and flips the sign on negative counts. r )rrK)rrOrrrrr__neg__s zCounter.__neg__cCs*dd|jD}x|D] }||=qW|S)z?Internal method to strip elements with a negative or zero countcSsg|]\}}|dks|qS)r r)rtrrrrr sz*Counter._keep_positive..)rK)r nonpositiverrrr_keep_positives  zCounter._keep_positivecCs.x$|jD]\}}|||7<q W|jS)zInplace add from another counter, keeping only positive counts. >>> c = Counter('abbb') >>> c += Counter('bcc') >>> c Counter({'b': 4, 'c': 2, 'a': 1}) )rKr)rrarrrrr__iadd__s zCounter.__iadd__cCs.x$|jD]\}}|||8<q W|jS)zInplace subtract counter, but keep only results with positive counts. >>> c = Counter('abbbc') >>> c -= Counter('bccd') >>> c Counter({'b': 2, 'a': 1}) )rKr)rrarrrrr__isub__%s zCounter.__isub__cCs6x,|jD] \}}||}||kr |||<q W|jS)zInplace union is the maximum of value from either counter. >>> c = Counter('abbb') >>> c |= Counter('bcc') >>> c Counter({'b': 3, 'c': 2, 'a': 1}) )rKr)rrarrrrrr__ior__2s  zCounter.__ior__cCs6x,|jD] \}}||}||kr |||<q W|jS)zInplace intersection is the minimum of corresponding counts. >>> c = Counter('abbb') >>> c &= Counter('bcc') >>> c Counter({'b': 1}) )rKr)rrarrrrrr__iand__As  zCounter.__iand__)N)N)rrrrbr2rrrrhr[rdrrUrXr:rSrrrrrrrrrrr __classcell__rr)rQrrs0+    ("    c@seZdZdZddZddZddZd'd d Zd d Zd dZ ddZ ddZ e ddZ eddZddZeZd(ddZeddZddZdd Zd!d"Zd#d$Zd%d&ZdS))r a A ChainMap groups multiple dicts (or other mappings) together to create a single, updateable view. The underlying mappings are stored in a list. That list is public and can be accessed or updated using the *maps* attribute. There is no other state. Lookups search the underlying mappings successively until a key is found. In contrast, writes, updates, and deletions only operate on the first mapping. cGst|p ig|_dS)zInitialize a ChainMap by setting *maps* to the given mappings. If no mappings are provided, a single empty dictionary is used. N)rRmaps)rrrrrr2cszChainMap.__init__cCs t|dS)N)r?)rrrrrrjszChainMap.__missing__c Cs8x,|jD]"}y||Stk r(YqXqW|j|S)N)rr?r)rrrrrr __getitem__ms   zChainMap.__getitem__NcCs||kr||S|S)Nr)rrrNrrrrusz ChainMap.getcCsttj|jS)N)r(runionr)rrrr__len__xszChainMap.__len__cCsttj|jS)N)rVrrr)rrrrr<{szChainMap.__iter__cstfdd|jDS)Nc3s|]}|kVqdS)Nr)rtm)rrrrusz(ChainMap.__contains__..)anyr)rrr)rr __contains__~szChainMap.__contains__cCs t|jS)N)rr)rrrr__bool__szChainMap.__bool__cCsdj|djtt|jS)Nz{0.__class__.__name__}({1})z, )rsrr_rr)rrrrrSszChainMap.__repr__cGs|tj|f|S)z?Create a ChainMap with a single dict created from the iterable.)r>r[)rYrZr/rrrr[szChainMap.fromkeyscCs$|j|jdjf|jddS)zHNew ChainMap or subclass with a new copy of maps[0] and refs to maps[1:]r r&N)rQrrU)rrrrrUsz ChainMap.copycCs|dkr i}|j|f|jS)zyNew ChainMap with a new map followed by all previous maps. If no map is provided, an empty dict is used. N)rQr)rrrrr new_childszChainMap.new_childcCs|j|jddS)zNew ChainMap from maps[1:].r&N)rQr)rrrrparentsszChainMap.parentscCs||jd|<dS)Nr )r)rrr3rrrr6szChainMap.__setitem__c Cs8y|jd|=Wn"tk r2tdj|YnXdS)Nr z(Key not found in the first mapping: {!r})rr?rs)rrrrrr:szChainMap.__delitem__c Cs0y|jdjStk r*tdYnXdS)zPRemove and return an item pair from maps[0]. Raise KeyError is maps[0] is empty.r z#No keys found in the first mapping.N)rr@r?)rrrrr@szChainMap.popitemc Gs>y|jdj|f|Stk r8tdj|YnXdS)zWRemove *key* from maps[0] and return its value. Raise KeyError if *key* not in maps[0].r z(Key not found in the first mapping: {!r}N)rr7r?rs)rrr/rrrr7sz ChainMap.popcCs|jdjdS)z'Clear maps[0], leaving maps[1:] intact.r N)rr=)rrrrr=szChainMap.clear)N)N)rrrrbr2rrrrr<rrrgrSrhr[rU__copy__rpropertyrr6r:r@r7r=rrrrr Us(     c@sbeZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ e dddZ dS)rcOs|s td|^}}t|dkr0tdt||r>|d}n0d|krj|jd}ddl}|jdtddnd}i|_|dk r|j|t|r|j|dS) Nzz0Passing 'dict' as keyword argument is deprecatedrC) stacklevel)r'r(r7warningswarnDeprecationWarningdatard)r/kwargsrr>rrrrr2s$     zUserDict.__init__cCs t|jS)N)r(r)rrrrrszUserDict.__len__cCs:||jkr|j|St|jdr.|jj||St|dS)Nr)rhasattrrQrr?)rrrrrrs    zUserDict.__getitem__cCs||j|<dS)N)r)rritemrrrr6szUserDict.__setitem__cCs |j|=dS)N)r)rrrrrr:szUserDict.__delitem__cCs t|jS)N)rVr)rrrrr<szUserDict.__iter__cCs ||jkS)N)r)rrrrrrszUserDict.__contains__cCs t|jS)N)rr)rrrrrSszUserDict.__repr__c CsR|jtkrt|jjSddl}|j}zi|_|j|}Wd||_X|j||S)Nr )rQrrrUrd)rrUrcrrrrUs  z UserDict.copyNcCs |}x|D] }|||<q W|S)Nr)rYrZr3drrrrr[s  zUserDict.fromkeys)N)rrrr2rrr6r:r<rrSrUrhr[rrrrrs c@seZdZdZd>ddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZddZddZdd Zd!d"Zd#d$ZeZd%d&Zd'd(Zd)d*Zd@d,d-Zd.d/Zd0d1Zd2d3Zd4d5Zd6d7Zd8d9Zd:d;Z dszUserList.indexcCs|jjdS)N)rr)rrrrr?szUserList.reversecOs|jj||dS)N)rsort)rr/r0rrrr@sz UserList.sortcCs*t|tr|jj|jn |jj|dS)N)r\rrextend)rrarrrrAs zUserList.extend)Nr)r)"rrrrbr2rSrrr]rrrrrrr6r:rrrr__rmul__rrrr7rr=rUrrwrrrrrrrrs>  c@s`eZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZddZddZdd Zd!d"Zd#d$Zd%d&ZeZd'd(Zd)d*Zd+d,Zd-d.Zd/d0Zd1ejfd2d3Zdd5d6Zd1ejfd7d8Z dd:d;Z!d1ejfdd?Z#d@dAZ$d1ejfdBdCZ%dDdEZ&dFdGZ'dHdIZ(dJdKZ)dLdMZ*dNdOZ+dPdQZ,dRdSZ-dTdUZ.dVdWZ/dXdYZ0dZd[Z1d\d]Z2d^d_Z3dd`daZ4e5j6Z6dbdcZ7ddedfZ8d1ejfdgdhZ9d1ejfdidjZ:dkdlZ;dmdnZddsdtZ?ddvdwZ@d1ejfdxdyZAddzd{ZBd|d}ZCd~dZDddZEddZFddZGd4S)rcCs<t|tr||_n&t|tr.|jdd|_n t||_dS)N)r\rrr)rseqrrrr2Ns   zUserString.__init__cCs t|jS)N)rr)rrrr__str__UszUserString.__str__cCs t|jS)N)rr)rrrrrSVszUserString.__repr__cCs t|jS)N)intr)rrrr__int__WszUserString.__int__cCs t|jS)N)floatr)rrrr __float__XszUserString.__float__cCs t|jS)N)complexr)rrrr __complex__YszUserString.__complex__cCs t|jS)N)hashr)rrrr__hash__ZszUserString.__hash__cCs|jddfS)N)r)rrrr__getnewargs__[szUserString.__getnewargs__cCs t|tr|j|jkS|j|kS)N)r\rr)rstringrrrr]^s  zUserString.__eq__cCs t|tr|j|jkS|j|kS)N)r\rr)rrrrrrbs  zUserString.__lt__cCs t|tr|j|jkS|j|kS)N)r\rr)rrrrrrfs  zUserString.__le__cCs t|tr|j|jkS|j|kS)N)r\rr)rrrrrrjs  zUserString.__gt__cCs t|tr|j|jkS|j|kS)N)r\rr)rrrrrrns  zUserString.__ge__cCst|tr|j}||jkS)N)r\rr)rcharrrrrss zUserString.__contains__cCs t|jS)N)r(r)rrrrrxszUserString.__len__cCs|j|j|S)N)rQr)rrwrrrryszUserString.__getitem__cCsJt|tr|j|j|jSt|tr6|j|j|S|j|jt|S)N)r\rrQrr)rrarrrrzs   zUserString.__add__cCs.t|tr|j||jS|jt||jS)N)r\rrQr)rrarrrrs zUserString.__radd__cCs|j|j|S)N)rQr)rrGrrrrszUserString.__mul__cCs|j|j|S)N)rQr)rr/rrrrszUserString.__mod__cCs|j|tS)N)rQr/)rrsrrr__rmod__szUserString.__rmod__cCs|j|jjS)N)rQr capitalize)rrrrrszUserString.capitalizecCs|j|jjS)N)rQrcasefold)rrrrrszUserString.casefoldcGs|j|jj|f|S)N)rQrcenter)rwidthr/rrrrszUserString.centerr cCs t|tr|j}|jj|||S)N)r\rrr)rsubstartendrrrrs zUserString.countNcCs>|r.|r|j|jj||S|j|jj|S|j|jjS)N)rQrencode)rencodingerrorsrrrrs zUserString.encodecCs|jj|||S)N)rendswith)rsuffixrrrrrrszUserString.endswithcCs|j|jj|S)N)rQr expandtabs)rtabsizerrrrszUserString.expandtabscCs t|tr|j}|jj|||S)N)r\rrfind)rrrrrrrrs zUserString.findcOs|jj||S)N)rrs)rr/r0rrrrsszUserString.formatcCs |jj|S)N)r format_map)rrrrrrszUserString.format_mapcCs|jj|||S)N)rrw)rrrrrrrrwszUserString.indexcCs |jjS)N)risalpha)rrrrrszUserString.isalphacCs |jjS)N)risalnum)rrrrrszUserString.isalnumcCs |jjS)N)r isdecimal)rrrrr szUserString.isdecimalcCs |jjS)N)risdigit)rrrrr szUserString.isdigitcCs |jjS)N)rr)rrrrrszUserString.isidentifiercCs |jjS)N)rislower)rrrrr szUserString.islowercCs |jjS)N)r isnumeric)rrrrr szUserString.isnumericcCs |jjS)N)r isprintable)rrrrr szUserString.isprintablecCs |jjS)N)risspace)rrrrrszUserString.isspacecCs |jjS)N)ristitle)rrrrrszUserString.istitlecCs |jjS)N)risupper)rrrrrszUserString.isuppercCs |jj|S)N)rr)rrrrrrszUserString.joincGs|j|jj|f|S)N)rQrljust)rrr/rrrrszUserString.ljustcCs|j|jjS)N)rQrlower)rrrrrszUserString.lowercCs|j|jj|S)N)rQrlstrip)rcharsrrrrszUserString.lstripcCs |jj|S)N)r partition)rseprrrrszUserString.partitionr&cCs6t|tr|j}t|tr |j}|j|jj|||S)N)r\rrrQr)roldnewmaxsplitrrrrs   zUserString.replacecCs t|tr|j}|jj|||S)N)r\rrrfind)rrrrrrrrs zUserString.rfindcCs|jj|||S)N)rrindex)rrrrrrrrszUserString.rindexcGs|j|jj|f|S)N)rQrrjust)rrr/rrrrszUserString.rjustcCs |jj|S)N)r rpartition)rrrrrrszUserString.rpartitioncCs|j|jj|S)N)rQrrstrip)rrrrrrszUserString.rstripcCs|jj||S)N)rr)rrrrrrrszUserString.splitcCs|jj||S)N)rrsplit)rrrrrrrszUserString.rsplitFcCs |jj|S)N)r splitlines)rkeependsrrrr szUserString.splitlinescCs|jj|||S)N)rr)rprefixrrrrrrszUserString.startswithcCs|j|jj|S)N)rQrstrip)rrrrrr#szUserString.stripcCs|j|jjS)N)rQrswapcase)rrrrr$szUserString.swapcasecCs|j|jjS)N)rQrtitle)rrrrr%szUserString.titlecGs|j|jj|S)N)rQr translate)rr/rrrr&szUserString.translatecCs|j|jjS)N)rQrupper)rrrrr'szUserString.uppercCs|j|jj|S)N)rQrzfill)rrrrrr(szUserString.zfill)NN)r)Nr)r)Nr)Nrr)Nr)F)N)Hrrrr2rrSrrrrrr]rrrrrrrrrrrrrrrrrDmaxsizerrrrrrsrrwrrr r rr r r rrrrrrrr maketransrrrrrrrrrr rr#r$r%r&r'r(rrrrrMs         )8rb__all___collections_abcoperatorr rr r`keywordrrsysrDheapqr_weakrefrr, itertoolsrrrrrrreprlibrrg _collectionsr ImportErrorMutableSequenceregisterrKeysViewr ItemsViewr ValuesViewr rfr!r>rrrrrxrrrrcr rrSequencerrrrrs`       `3blCI__init__.cpython-36.opt-2.pyc000064400000105022147204630710011675 0ustar003 \$@sdddddddddg Zd d lTd d lZeej7Zd d lmZmZd d lmZ d d l Z d d l Z d dlmZd dlmZmZmZd dlmZyd dlmZWnek rYn Xejeyd dlm Z Wnek rYnXGddde!Z"Gddde#Z$Gddde%Z&Gddde'Z(Gddde)Z*yd dlm*Z*Wnek rTYnXdZ+dZ,dZ-d d d d!d"dZ.d#d$Z/yd d%lm/Z/Wnek rYnXGd&dde)Z0Gd'dde1Z2Gd(dde1Z3Gd)ddeZ4Gd*dde5Z6d S)+deque defaultdict namedtupleUserDictUserList UserStringCounter OrderedDictChainMap)*N) itemgettereq) iskeyword)proxy)repeatchainstarmap)recursive_repr)r)rc@seZdZddZdS)_OrderedDictKeysViewccst|jEdHdS)N)reversed_mapping)selfr,/usr/lib64/python3.6/collections/__init__.py __reversed__5sz!_OrderedDictKeysView.__reversed__N)__name__ __module__ __qualname__rrrrrr3src@seZdZddZdS)_OrderedDictItemsViewccs(x"t|jD]}||j|fVq WdS)N)rr)rkeyrrrr:sz"_OrderedDictItemsView.__reversed__N)rrrrrrrrr8src@seZdZddZdS)_OrderedDictValuesViewccs$xt|jD]}|j|Vq WdS)N)rr)rrrrrr@sz#_OrderedDictValuesView.__reversed__N)rrrrrrrrr >sr c@seZdZdZdS)_Linkprevnextr __weakref__N)r"r#rr$)rrr __slots__rrrrr!Dsr!c@seZdZddZejeefddZejfddZddZ d d Z d d Z d)ddZ d*ddZ ddZejZZddZddZddZejZeZefddZd+ddZedd Zd!d"Zd#d$Zed,d%d&Zd'd(Z dS)-rc Os|s td|^}}t|dkr0tdt|y |jWn>tk rxt|_t|j|_}||_|_i|_ YnX|j ||dS)Nz?descriptor '__init__' of 'OrderedDict' object needs an argumentz$expected at most 1 arguments, got %d) TypeErrorlen_OrderedDict__rootAttributeErrorr!_OrderedDict__hardroot_proxyr"r#_OrderedDict__map_OrderedDict__update)argskwdsrrootrrr__init__Vs    zOrderedDict.__init__c CsZ||krJ||j|<}|j}|j}||||_|_|_||_|||_||||dS)N)r-r)r"r#r) rrvalueZ dict_setitemrZLinklinkr1lastrrr __setitem__is zOrderedDict.__setitem__cCs>||||jj|}|j}|j}||_||_d|_d|_dS)N)r-popr"r#)rrZ dict_delitemr4 link_prev link_nextrrr __delitem__ws  zOrderedDict.__delitem__ccs,|j}|j}x||k r&|jV|j}qWdS)N)r)r#r)rr1currrrr__iter__s  zOrderedDict.__iter__ccs,|j}|j}x||k r&|jV|j}qWdS)N)r)r"r)rr1r;rrrrs  zOrderedDict.__reversed__cCs*|j}||_|_|jjtj|dS)N)r)r"r#r-cleardict)rr1rrrr=s  zOrderedDict.clearTcCsj|s td|j}|r0|j}|j}||_||_n|j}|j}||_||_|j}|j|=tj||}||fS)Nzdictionary is empty)KeyErrorr)r"r#rr-r>r7)rr5r1r4r8r9rr3rrrpopitems  zOrderedDict.popitemc Cst|j|}|j}|j}|j}||_||_|j}|rR|j}||_||_||_||_n|j}||_||_||_||_dS)N)r-r"r#r)) rrr5r4r8r9Z soft_linkr1firstrrr move_to_ends$ zOrderedDict.move_to_endcCsVtj}t|d}||j}|||jd7}|||j|7}|||j|7}|S)Nr&)_sys getsizeofr(__dict__r-r+r))rZsizeofnsizerrr __sizeof__s  zOrderedDict.__sizeof__cCst|S)N)r)rrrrkeysszOrderedDict.keyscCst|S)N)r)rrrritemsszOrderedDict.itemscCst|S)N)r )rrrrvaluesszOrderedDict.valuescCs0||kr||}||=|S||jkr,t||S)N)_OrderedDict__markerr?)rrdefaultresultrrrr7s zOrderedDict.popNcCs||kr||S|||<|S)Nr)rrrNrrr setdefaultszOrderedDict.setdefaultcCs*|sd|jjfSd|jjt|jfS)Nz%s()z%s(%r)) __class__rlistrK)rrrr__repr__szOrderedDict.__repr__cCsHt|j}xttD]}|j|dqW|jf|p8ddt|jfS)N)varscopyrr7rQiterrK)rZ inst_dictkrrr __reduce__s zOrderedDict.__reduce__cCs |j|S)N)rQ)rrrrrU szOrderedDict.copycCs |}x|D] }|||<q W|S)Nr)clsiterabler3rrrrrfromkeyss  zOrderedDict.fromkeyscCs2t|tr&tj||o$ttt||Stj||S)N) isinstancerr>__eq__allmap_eq)rotherrrrr]s zOrderedDict.__eq__)T)T)N)N)!rrrr2r>r6r,r!r:r<rr=r@rBrIMutableMappingupdater.rJrKrL__ne__objectrMr7rP_recursive_reprrSrXrU classmethodr[r]rrrrrGs.          )rafrom builtins import property as _property, tuple as _tuple from operator import itemgetter as _itemgetter from collections import OrderedDict class {typename}(tuple): '{typename}({arg_list})' __slots__ = () _fields = {field_names!r} def __new__(_cls, {arg_list}): 'Create new instance of {typename}({arg_list})' return _tuple.__new__(_cls, ({arg_list})) @classmethod def _make(cls, iterable, new=tuple.__new__, len=len): 'Make a new {typename} object from a sequence or iterable' result = new(cls, iterable) if len(result) != {num_fields:d}: raise TypeError('Expected {num_fields:d} arguments, got %d' % len(result)) return result def _replace(_self, **kwds): 'Return a new {typename} object replacing specified fields with new values' result = _self._make(map(kwds.pop, {field_names!r}, _self)) if kwds: raise ValueError('Got unexpected field names: %r' % list(kwds)) return result def __repr__(self): 'Return a nicely formatted representation string' return self.__class__.__name__ + '({repr_fmt})' % self def _asdict(self): 'Return a new OrderedDict which maps field names to their values.' return OrderedDict(zip(self._fields, self)) def __getnewargs__(self): 'Return self as a plain tuple. Used by copy and pickle.' return tuple(self) {field_defs} z {name}=%rzW {name} = _property(_itemgetter({index:d}), doc='Alias for field number {index:d}') F)verboserenamemodulec Cst|tr|jddj}ttt|}t|}|rt}xNt|D]B\}}|j spt |sp|j dsp||kr|d|||<|j |qDWxN|g|D]@}t |tk rt d|jstd|t |rtd|qWt}xJ|D]B}|j do| rtd|||krtd ||j |qWtj|t|t|tt|jd d d dd jdd|Ddjddt|Dd}td|d} t|| | |} || _|rt| j|dkrytjd jjdd}Wnttfk rYnX|dk r || _| S)N, _z_%dz*Type names and field names must be stringsz8Type names and field names must be valid identifiers: %rz2Type names and field names cannot be a keyword: %rz/Field names cannot start with an underscore: %rz$Encountered duplicate field name: %r'r&z, css|]}tj|dVqdS))nameN)_repr_templateformat).0rprrr sznamedtuple.. css |]\}}tj||dVqdS))indexrpN)_field_templaterr)rsrvrprrrrts)typename field_names num_fieldsarg_listrepr_fmt field_defsz namedtuple_%s)rr__main__)r\strreplacesplitrRr_set enumerate isidentifier _iskeyword startswithaddtyper' ValueError_class_templaterrtupler(reprjoinr>exec_sourceprintrD _getframe f_globalsgetr*r) rxryrhrirjseenrvrpclass_definition namespacerOrrrresj               cCs*|j}x|D]}||dd||<q WdS)Nr r&)r)mappingrZZ mapping_getelemrrr_count_elementss r)rcseZdZfddZddZd.ddZdd Zed/d d Zfd d Z ddZ ddZ ddZ fddZ ddZddZddZddZddZd d!Zd"d#Zd$d%Zd&d'Zd(d)Zd*d+Zd,d-ZZS)0rcsN|s td|^}}t|dkr0tdt|tt|j|j||dS)Nz;descriptor '__init__' of 'Counter' object needs an argumentr&z$expected at most 1 arguments, got %d)r'r(superrr2rc)r/r0r)rQrrr2s  zCounter.__init__cCsdS)Nr r)rrrrr __missing__szCounter.__missing__NcCs6|dkrt|jtdddStj||jtddS)Nr&T)rreverse)r)sortedrK _itemgetter_heapqnlargest)rrGrrr most_commons zCounter.most_commoncCstjtt|jS)N)_chain from_iterable_starmap_repeatrK)rrrrelements+szCounter.elementscCs tddS)Nz@Counter.fromkeys() is undefined. Use Counter(iterable) instead.)NotImplementedError)rYrZvrrrr[CszCounter.fromkeyscs|s td|^}}t|dkr0tdt||r<|dnd}|dk rt|tr|r|j}x8|jD]\}}|||d||<qfWqtt|j|n t |||r|j|dS)Nz9descriptor 'update' of 'Counter' object needs an argumentr&z$expected at most 1 arguments, got %dr ) r'r(r\MappingrrKrrrcr)r/r0rrZself_getrcount)rQrrrcJs    zCounter.updatecOs|s td|^}}t|dkr0tdt||r<|dnd}|dk r|j}t|trxH|jD]\}}||d|||<qbWn x|D]}||dd||<qW|r|j|dS)Nz;descriptor 'subtract' of 'Counter' object needs an argumentr&z$expected at most 1 arguments, got %dr )r'r(rr\rrKsubtract)r/r0rrZrrrrrrrrs   zCounter.subtractcCs |j|S)N)rQ)rrrrrUsz Counter.copycCs|jt|ffS)N)rQr>)rrrrrXszCounter.__reduce__cs||krtj|dS)N)rr:)rr)rQrrr:szCounter.__delitem__c Cs`|sd|jjSy&djtdj|j}d|jj|fStk rZdj|jjt|SXdS)Nz%s()z, z%r: %rz%s({%s})z {0}({1!r})) rQrrr___mod__rr'rrr>)rrKrrrrSs zCounter.__repr__cCsxt|tstSt}x0|jD]$\}}|||}|dkr|||<qWx,|jD] \}}||krP|dkrP|||<qPW|S)Nr )r\rNotImplementedrK)rrarOrrnewcountrrr__add__s    zCounter.__add__cCs|t|tstSt}x0|jD]$\}}|||}|dkr|||<qWx0|jD]$\}}||krP|dkrPd|||<qPW|S)Nr )r\rrrK)rrarOrrrrrr__sub__s   zCounter.__sub__cCst|tstSt}x<|jD]0\}}||}||kr:|n|}|dkr|||<qWx,|jD] \}}||kr\|dkr\|||<q\W|S)Nr )r\rrrK)rrarOrr other_countrrrr__or__s   zCounter.__or__cCsVt|tstSt}x<|jD]0\}}||}||kr:|n|}|dkr|||<qW|S)Nr )r\rrrK)rrarOrrrrrrr__and__s  zCounter.__and__cCs0t}x$|jD]\}}|dkr|||<qW|S)Nr )rrK)rrOrrrrr__pos__s  zCounter.__pos__cCs4t}x(|jD]\}}|dkrd|||<qW|S)Nr )rrK)rrOrrrrr__neg__s zCounter.__neg__cCs*dd|jD}x|D] }||=qW|S)NcSsg|]\}}|dks|qS)r r)rsrrrrr sz*Counter._keep_positive..)rK)r nonpositiverrrr_keep_positives  zCounter._keep_positivecCs.x$|jD]\}}|||7<q W|jS)N)rKr)rrarrrrr__iadd__s zCounter.__iadd__cCs.x$|jD]\}}|||8<q W|jS)N)rKr)rrarrrrr__isub__%s zCounter.__isub__cCs6x,|jD] \}}||}||kr |||<q W|jS)N)rKr)rrarrrrrr__ior__2s  zCounter.__ior__cCs6x,|jD] \}}||}||kr |||<q W|jS)N)rKr)rrarrrrrr__iand__As  zCounter.__iand__)N)N)rrrr2rrrrgr[rcrrUrXr:rSrrrrrrrrrrr __classcell__rr)rQrrs.3    ("    c@seZdZddZddZddZd&dd Zd d Zd d ZddZ ddZ e ddZ e ddZddZeZd'ddZeddZddZddZd d!Zd"d#Zd$d%ZdS)(r cGst|p ig|_dS)N)rRmaps)rrrrrr2cszChainMap.__init__cCs t|dS)N)r?)rrrrrrjszChainMap.__missing__c Cs8x,|jD]"}y||Stk r(YqXqW|j|S)N)rr?r)rrrrrr __getitem__ms   zChainMap.__getitem__NcCs||kr||S|S)Nr)rrrNrrrrusz ChainMap.getcCsttj|jS)N)r(runionr)rrrr__len__xszChainMap.__len__cCsttj|jS)N)rVrrr)rrrrr<{szChainMap.__iter__cstfdd|jDS)Nc3s|]}|kVqdS)Nr)rsm)rrrrtsz(ChainMap.__contains__..)anyr)rrr)rr __contains__~szChainMap.__contains__cCs t|jS)N)rr)rrrr__bool__szChainMap.__bool__cCsdj|djtt|jS)Nz{0.__class__.__name__}({1})z, )rrrr_rr)rrrrrSszChainMap.__repr__cGs|tj|f|S)N)r>r[)rYrZr/rrrr[szChainMap.fromkeyscCs$|j|jdjf|jddS)Nr r&)rQrrU)rrrrrUsz ChainMap.copycCs|dkr i}|j|f|jS)N)rQr)rrrrr new_childszChainMap.new_childcCs|j|jddS)Nr&)rQr)rrrrparentsszChainMap.parentscCs||jd|<dS)Nr )r)rrr3rrrr6szChainMap.__setitem__c Cs8y|jd|=Wn"tk r2tdj|YnXdS)Nr z(Key not found in the first mapping: {!r})rr?rr)rrrrrr:szChainMap.__delitem__c Cs0y|jdjStk r*tdYnXdS)Nr z#No keys found in the first mapping.)rr@r?)rrrrr@szChainMap.popitemc Gs>y|jdj|f|Stk r8tdj|YnXdS)Nr z(Key not found in the first mapping: {!r})rr7r?rr)rrr/rrrr7sz ChainMap.popcCs|jdjdS)Nr )rr=)rrrrr=szChainMap.clear)N)N)rrrr2rrrrr<rrrfrSrgr[rU__copy__rpropertyrr6r:r@r7r=rrrrr Us&    c@sbeZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ e dddZ dS)rcOs|s td|^}}t|dkr0tdt||r>|d}n0d|krj|jd}ddl}|jdtddnd}i|_|dk r|j|t|r|j|dS) Nzz0Passing 'dict' as keyword argument is deprecatedrC) stacklevel)r'r(r7warningswarnDeprecationWarningdatarc)r/kwargsrr>rrrrr2s$     zUserDict.__init__cCs t|jS)N)r(r)rrrrrszUserDict.__len__cCs:||jkr|j|St|jdr.|jj||St|dS)Nr)rhasattrrQrr?)rrrrrrs    zUserDict.__getitem__cCs||j|<dS)N)r)rritemrrrr6szUserDict.__setitem__cCs |j|=dS)N)r)rrrrrr:szUserDict.__delitem__cCs t|jS)N)rVr)rrrrr<szUserDict.__iter__cCs ||jkS)N)r)rrrrrrszUserDict.__contains__cCs t|jS)N)rr)rrrrrSszUserDict.__repr__c CsR|jtkrt|jjSddl}|j}zi|_|j|}Wd||_X|j||S)Nr )rQrrrUrc)rrUrcrrrrUs  z UserDict.copyNcCs |}x|D] }|||<q W|S)Nr)rYrZr3drrrrr[s  zUserDict.fromkeys)N)rrrr2rrr6r:r<rrSrUrgr[rrrrrs c@seZdZd=ddZddZddZdd Zd d Zd d ZddZ ddZ ddZ ddZ ddZ ddZddZddZddZd d!Zd"d#ZeZd$d%Zd&d'Zd(d)Zd?d+d,Zd-d.Zd/d0Zd1d2Zd3d4Zd5d6Zd7d8Zd9d:Zd;d<Z dS)@rNcCsbg|_|dk r^t|t|jkr0||jdd<n.t|trT|jdd|jdd<n t||_dS)N)rrr\rrR)rinitlistrrrr2s zUserList.__init__cCs t|jS)N)rr)rrrrrSszUserList.__repr__cCs|j|j|kS)N)r_UserList__cast)rrarrr__lt__szUserList.__lt__cCs|j|j|kS)N)rr)rrarrr__le__szUserList.__le__cCs|j|j|kS)N)rr)rrarrrr]szUserList.__eq__cCs|j|j|kS)N)rr)rrarrr__gt__szUserList.__gt__cCs|j|j|kS)N)rr)rrarrr__ge__szUserList.__ge__cCst|tr|jS|S)N)r\rr)rrarrr__castszUserList.__castcCs ||jkS)N)r)rrrrrrszUserList.__contains__cCs t|jS)N)r(r)rrrrrszUserList.__len__cCs |j|S)N)r)rirrrrszUserList.__getitem__cCs||j|<dS)N)r)rrrrrrr6szUserList.__setitem__cCs |j|=dS)N)r)rrrrrr:szUserList.__delitem__cCsPt|tr|j|j|jSt|t|jr<|j|j|S|j|jt|S)N)r\rrQrrrR)rrarrrrs  zUserList.__add__cCsPt|tr|j|j|jSt|t|jr<|j||jS|jt||jS)N)r\rrQrrrR)rrarrr__radd__#s  zUserList.__radd__cCsRt|tr|j|j7_n2t|t|jr<|j|7_n|jt|7_|S)N)r\rrrrR)rrarrrr)s  zUserList.__iadd__cCs|j|j|S)N)rQr)rrGrrr__mul__1szUserList.__mul__cCs|j|9_|S)N)r)rrGrrr__imul__4szUserList.__imul__cCs|jj|dS)N)rappend)rrrrrr7szUserList.appendcCs|jj||dS)N)rinsert)rrrrrrr8szUserList.insertr&cCs |jj|S)N)rr7)rrrrrr79sz UserList.popcCs|jj|dS)N)rremove)rrrrrr:szUserList.removecCs|jjdS)N)rr=)rrrrr=;szUserList.clearcCs |j|S)N)rQ)rrrrrU<sz UserList.copycCs |jj|S)N)rr)rrrrrr=szUserList.countcGs|jj|f|S)N)rrv)rrr/rrrrv>szUserList.indexcCs|jjdS)N)rr)rrrrr?szUserList.reversecOs|jj||dS)N)rsort)rr/r0rrrr@sz UserList.sortcCs*t|tr|jj|jn |jj|dS)N)r\rrextend)rrarrrrAs zUserList.extend)Nr)r)!rrrr2rSrrr]rrrrrrr6r:rrrr__rmul__rrrr7rr=rUrrvrrrrrrrrs<  c@s`eZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZddZddZdd Zd!d"Zd#d$Zd%d&ZeZd'd(Zd)d*Zd+d,Zd-d.Zd/d0Zd1ejfd2d3Zdd5d6Zd1ejfd7d8Z dd:d;Z!d1ejfdd?Z#d@dAZ$d1ejfdBdCZ%dDdEZ&dFdGZ'dHdIZ(dJdKZ)dLdMZ*dNdOZ+dPdQZ,dRdSZ-dTdUZ.dVdWZ/dXdYZ0dZd[Z1d\d]Z2d^d_Z3dd`daZ4e5j6Z6dbdcZ7ddedfZ8d1ejfdgdhZ9d1ejfdidjZ:dkdlZ;dmdnZddsdtZ?ddvdwZ@d1ejfdxdyZAddzd{ZBd|d}ZCd~dZDddZEddZFddZGd4S)rcCs<t|tr||_n&t|tr.|jdd|_n t||_dS)N)r\rrr)rseqrrrr2Ns   zUserString.__init__cCs t|jS)N)rr)rrrr__str__UszUserString.__str__cCs t|jS)N)rr)rrrrrSVszUserString.__repr__cCs t|jS)N)intr)rrrr__int__WszUserString.__int__cCs t|jS)N)floatr)rrrr __float__XszUserString.__float__cCs t|jS)N)complexr)rrrr __complex__YszUserString.__complex__cCs t|jS)N)hashr)rrrr__hash__ZszUserString.__hash__cCs|jddfS)N)r)rrrr__getnewargs__[szUserString.__getnewargs__cCs t|tr|j|jkS|j|kS)N)r\rr)rstringrrrr]^s  zUserString.__eq__cCs t|tr|j|jkS|j|kS)N)r\rr)rrrrrrbs  zUserString.__lt__cCs t|tr|j|jkS|j|kS)N)r\rr)rrrrrrfs  zUserString.__le__cCs t|tr|j|jkS|j|kS)N)r\rr)rrrrrrjs  zUserString.__gt__cCs t|tr|j|jkS|j|kS)N)r\rr)rrrrrrns  zUserString.__ge__cCst|tr|j}||jkS)N)r\rr)rcharrrrrss zUserString.__contains__cCs t|jS)N)r(r)rrrrrxszUserString.__len__cCs|j|j|S)N)rQr)rrvrrrryszUserString.__getitem__cCsJt|tr|j|j|jSt|tr6|j|j|S|j|jt|S)N)r\rrQrr)rrarrrrzs   zUserString.__add__cCs.t|tr|j||jS|jt||jS)N)r\rrQr)rrarrrrs zUserString.__radd__cCs|j|j|S)N)rQr)rrGrrrrszUserString.__mul__cCs|j|j|S)N)rQr)rr/rrrrszUserString.__mod__cCs|j|tS)N)rQr/)rrrrrr__rmod__szUserString.__rmod__cCs|j|jjS)N)rQr capitalize)rrrrrszUserString.capitalizecCs|j|jjS)N)rQrcasefold)rrrrrszUserString.casefoldcGs|j|jj|f|S)N)rQrcenter)rwidthr/rrrrszUserString.centerr cCs t|tr|j}|jj|||S)N)r\rrr)rsubstartendrrrrs zUserString.countNcCs>|r.|r|j|jj||S|j|jj|S|j|jjS)N)rQrencode)rencodingerrorsrrrrs zUserString.encodecCs|jj|||S)N)rendswith)rsuffixrrrrrrszUserString.endswithcCs|j|jj|S)N)rQr expandtabs)rtabsizerrrrszUserString.expandtabscCs t|tr|j}|jj|||S)N)r\rrfind)rrrrrrrrs zUserString.findcOs|jj||S)N)rrr)rr/r0rrrrrszUserString.formatcCs |jj|S)N)r format_map)rrrrrrszUserString.format_mapcCs|jj|||S)N)rrv)rrrrrrrrvszUserString.indexcCs |jjS)N)risalpha)rrrrrszUserString.isalphacCs |jjS)N)risalnum)rrrrrszUserString.isalnumcCs |jjS)N)r isdecimal)rrrrrszUserString.isdecimalcCs |jjS)N)risdigit)rrrrr szUserString.isdigitcCs |jjS)N)rr)rrrrrszUserString.isidentifiercCs |jjS)N)rislower)rrrrr szUserString.islowercCs |jjS)N)r isnumeric)rrrrr szUserString.isnumericcCs |jjS)N)r isprintable)rrrrr szUserString.isprintablecCs |jjS)N)risspace)rrrrr szUserString.isspacecCs |jjS)N)ristitle)rrrrrszUserString.istitlecCs |jjS)N)risupper)rrrrrszUserString.isuppercCs |jj|S)N)rr)rrrrrrszUserString.joincGs|j|jj|f|S)N)rQrljust)rrr/rrrrszUserString.ljustcCs|j|jjS)N)rQrlower)rrrrrszUserString.lowercCs|j|jj|S)N)rQrlstrip)rcharsrrrrszUserString.lstripcCs |jj|S)N)r partition)rseprrrrszUserString.partitionr&cCs6t|tr|j}t|tr |j}|j|jj|||S)N)r\rrrQr)roldnewmaxsplitrrrrs   zUserString.replacecCs t|tr|j}|jj|||S)N)r\rrrfind)rrrrrrrrs zUserString.rfindcCs|jj|||S)N)rrindex)rrrrrrrrszUserString.rindexcGs|j|jj|f|S)N)rQrrjust)rrr/rrrrszUserString.rjustcCs |jj|S)N)r rpartition)rrrrrrszUserString.rpartitioncCs|j|jj|S)N)rQrrstrip)rrrrrrszUserString.rstripcCs|jj||S)N)rr)rrrrrrrszUserString.splitcCs|jj||S)N)rrsplit)rrrrrrrszUserString.rsplitFcCs |jj|S)N)r splitlines)rkeependsrrrrszUserString.splitlinescCs|jj|||S)N)rr)rprefixrrrrrrszUserString.startswithcCs|j|jj|S)N)rQrstrip)rrrrrr"szUserString.stripcCs|j|jjS)N)rQrswapcase)rrrrr#szUserString.swapcasecCs|j|jjS)N)rQrtitle)rrrrr$szUserString.titlecGs|j|jj|S)N)rQr translate)rr/rrrr%szUserString.translatecCs|j|jjS)N)rQrupper)rrrrr&szUserString.uppercCs|j|jj|S)N)rQrzfill)rrrrrr'szUserString.zfill)NN)r)Nr)r)Nr)Nrr)Nr)F)N)Hrrrr2rrSrrrrrr]rrrrrrrrrrrrrrrrrDmaxsizerrrrrrrrrvrrrr rr r r r rrrrrrr maketransrrrrrrrrrrrr"r#r$r%r&r'rrrrrMs         )7__all___collections_abcoperatorr rr r`keywordrrsysrDheapqr_weakrefrr, itertoolsrrrrrrreprlibrrf _collectionsr ImportErrorMutableSequenceregisterrKeysViewr ItemsViewr ValuesViewr rer!r>rrrqrwrrrrbr rrSequencerrrrrs^       `3blCI__init__.cpython-36.pyc000064400000131372147204630710010744 0ustar003 \$@sdZddddddddd g Zd d lTd d lZeej7Zd d lmZmZd dlm Z d d l Z d d l Zd dlmZd dlmZmZmZd dlmZyd dlmZWnek rYn Xej eyd dlm!Z!Wnek rYnXGddde"Z#Gddde$Z%Gddde&Z'Gddde(Z)Gddde*Z+yd dlm+Z+Wnek rXYnXdZ,dZ-d Z.d!d!d d"d#dZ/d$d%Z0yd d&lm0Z0Wnek rYnXGd'dde*Z1Gd(d d e2Z3Gd)dde2Z4Gd*ddeZ5Gd+dde6Z7d S),a?This module implements specialized container datatypes providing alternatives to Python's general purpose built-in containers, dict, list, set, and tuple. * namedtuple factory function for creating tuple subclasses with named fields * deque list-like container with fast appends and pops on either end * ChainMap dict-like class for creating a single view of multiple mappings * Counter dict subclass for counting hashable objects * OrderedDict dict subclass that remembers the order entries were added * defaultdict dict subclass that calls a factory function to supply missing values * UserDict wrapper around dictionary objects for easier dict subclassing * UserList wrapper around list objects for easier list subclassing * UserString wrapper around string objects for easier string subclassing deque defaultdict namedtupleUserDictUserList UserStringCounter OrderedDictChainMap)*N) itemgettereq) iskeyword)proxy)repeatchainstarmap)recursive_repr)r)rc@seZdZddZdS)_OrderedDictKeysViewccst|jEdHdS)N)reversed_mapping)selfr,/usr/lib64/python3.6/collections/__init__.py __reversed__5sz!_OrderedDictKeysView.__reversed__N)__name__ __module__ __qualname__rrrrrr3src@seZdZddZdS)_OrderedDictItemsViewccs(x"t|jD]}||j|fVq WdS)N)rr)rkeyrrrr:sz"_OrderedDictItemsView.__reversed__N)rrrrrrrrr8src@seZdZddZdS)_OrderedDictValuesViewccs$xt|jD]}|j|Vq WdS)N)rr)rrrrrr@sz#_OrderedDictValuesView.__reversed__N)rrrrrrrrr >sr c@seZdZdZdS)_Linkprevnextr __weakref__N)r"r#rr$)rrr __slots__rrrrr!Dsr!c@seZdZdZddZejeefddZej fddZ dd Z d d Z d d Z d*ddZ d+ddZddZejZZddZddZddZejZeZefddZd,ddZed d!Zd"d#Zd$d%Zed-d&d'Z d(d)Z!dS).rz)Dictionary that remembers insertion orderc Os|s td|^}}t|dkr0tdt|y |jWn>tk rxt|_t|j|_}||_|_i|_ YnX|j ||dS)zInitialize an ordered dictionary. The signature is the same as regular dictionaries. Keyword argument order is preserved. z?descriptor '__init__' of 'OrderedDict' object needs an argumentz$expected at most 1 arguments, got %dN) TypeErrorlen_OrderedDict__rootAttributeErrorr!_OrderedDict__hardroot_proxyr"r#_OrderedDict__map_OrderedDict__update)argskwdsrrootrrr__init__Vs    zOrderedDict.__init__c CsZ||krJ||j|<}|j}|j}||||_|_|_||_|||_||||dS)z!od.__setitem__(i, y) <==> od[i]=yN)r-r)r"r#r) rrvalueZ dict_setitemrZLinklinkr1lastrrr __setitem__is zOrderedDict.__setitem__cCs>||||jj|}|j}|j}||_||_d|_d|_dS)z od.__delitem__(y) <==> del od[y]N)r-popr"r#)rrZ dict_delitemr4 link_prev link_nextrrr __delitem__ws  zOrderedDict.__delitem__ccs,|j}|j}x||k r&|jV|j}qWdS)zod.__iter__() <==> iter(od)N)r)r#r)rr1currrrr__iter__s  zOrderedDict.__iter__ccs,|j}|j}x||k r&|jV|j}qWdS)z#od.__reversed__() <==> reversed(od)N)r)r"r)rr1r;rrrrs  zOrderedDict.__reversed__cCs*|j}||_|_|jjtj|dS)z.od.clear() -> None. Remove all items from od.N)r)r"r#r-cleardict)rr1rrrr=s  zOrderedDict.clearTcCsj|s td|j}|r0|j}|j}||_||_n|j}|j}||_||_|j}|j|=tj||}||fS)zRemove and return a (key, value) pair from the dictionary. Pairs are returned in LIFO order if last is true or FIFO order if false. zdictionary is empty)KeyErrorr)r"r#rr-r>r7)rr5r1r4r8r9rr3rrrpopitems  zOrderedDict.popitemc Cst|j|}|j}|j}|j}||_||_|j}|rR|j}||_||_||_||_n|j}||_||_||_||_dS)zMove an existing element to the end (or beginning if last==False). Raises KeyError if the element does not exist. When last=True, acts like a fast version of self[key]=self.pop(key). N)r-r"r#r)) rrr5r4r8r9Z soft_linkr1firstrrr move_to_ends$ zOrderedDict.move_to_endcCsVtj}t|d}||j}|||jd7}|||j|7}|||j|7}|S)Nr&)_sys getsizeofr(__dict__r-r+r))rZsizeofnsizerrr __sizeof__s  zOrderedDict.__sizeof__cCst|S)z:D.keys() -> a set-like object providing a view on D's keys)r)rrrrkeysszOrderedDict.keyscCst|S)z a set-like object providing a view on D's items)r)rrrritemsszOrderedDict.itemscCst|S)z6D.values() -> an object providing a view on D's values)r )rrrrvaluesszOrderedDict.valuescCs0||kr||}||=|S||jkr,t||S)zod.pop(k[,d]) -> v, remove specified key and return the corresponding value. If key is not found, d is returned if given, otherwise KeyError is raised. )_OrderedDict__markerr?)rrdefaultresultrrrr7s zOrderedDict.popNcCs||kr||S|||<|S)zDod.setdefault(k[,d]) -> od.get(k,d), also set od[k]=d if k not in odr)rrrNrrr setdefaultszOrderedDict.setdefaultcCs*|sd|jjfSd|jjt|jfS)zod.__repr__() <==> repr(od)z%s()z%s(%r)) __class__rlistrK)rrrr__repr__szOrderedDict.__repr__cCsHt|j}xttD]}|j|dqW|jf|p8ddt|jfS)z%Return state information for picklingN)varscopyrr7rQiterrK)rZ inst_dictkrrr __reduce__s zOrderedDict.__reduce__cCs |j|S)z!od.copy() -> a shallow copy of od)rQ)rrrrrU szOrderedDict.copycCs |}x|D] }|||<q W|S)zOD.fromkeys(S[, v]) -> New ordered dictionary with keys from S. If not specified, the value defaults to None. r)clsiterabler3rrrrrfromkeyss  zOrderedDict.fromkeyscCs2t|tr&tj||o$ttt||Stj||S)zod.__eq__(y) <==> od==y. Comparison to another OD is order-sensitive while comparison to a regular mapping is order-insensitive. ) isinstancerr>__eq__allmap_eq)rotherrrrr]s zOrderedDict.__eq__)T)T)N)N)"rrr__doc__r2r>r6r,r!r:r<rr=r@rBrIMutableMappingupdater.rJrKrL__ne__objectrMr7rP_recursive_reprrSrXrU classmethodr[r]rrrrrGs0          )rafrom builtins import property as _property, tuple as _tuple from operator import itemgetter as _itemgetter from collections import OrderedDict class {typename}(tuple): '{typename}({arg_list})' __slots__ = () _fields = {field_names!r} def __new__(_cls, {arg_list}): 'Create new instance of {typename}({arg_list})' return _tuple.__new__(_cls, ({arg_list})) @classmethod def _make(cls, iterable, new=tuple.__new__, len=len): 'Make a new {typename} object from a sequence or iterable' result = new(cls, iterable) if len(result) != {num_fields:d}: raise TypeError('Expected {num_fields:d} arguments, got %d' % len(result)) return result def _replace(_self, **kwds): 'Return a new {typename} object replacing specified fields with new values' result = _self._make(map(kwds.pop, {field_names!r}, _self)) if kwds: raise ValueError('Got unexpected field names: %r' % list(kwds)) return result def __repr__(self): 'Return a nicely formatted representation string' return self.__class__.__name__ + '({repr_fmt})' % self def _asdict(self): 'Return a new OrderedDict which maps field names to their values.' return OrderedDict(zip(self._fields, self)) def __getnewargs__(self): 'Return self as a plain tuple. Used by copy and pickle.' return tuple(self) {field_defs} z {name}=%rzW {name} = _property(_itemgetter({index:d}), doc='Alias for field number {index:d}') F)verboserenamemodulec Cst|tr|jddj}ttt|}t|}|rt}xNt|D]B\}}|j spt |sp|j dsp||kr|d|||<|j |qDWxN|g|D]@}t |tk rt d|jstd|t |rtd|qWt}xJ|D]B}|j do| rtd|||krtd ||j |qWtj|t|t|tt|jd d d dd jdd|Ddjddt|Dd}td|d} t|| | |} || _|rt| j|dkrytjd jjdd}Wnttfk rYnX|dk r || _| S)aCReturns a new subclass of tuple with named fields. >>> Point = namedtuple('Point', ['x', 'y']) >>> Point.__doc__ # docstring for the new class 'Point(x, y)' >>> p = Point(11, y=22) # instantiate with positional args or keywords >>> p[0] + p[1] # indexable like a plain tuple 33 >>> x, y = p # unpack like a regular tuple >>> x, y (11, 22) >>> p.x + p.y # fields also accessible by name 33 >>> d = p._asdict() # convert to a dictionary >>> d['x'] 11 >>> Point(**d) # convert from a dictionary Point(x=11, y=22) >>> p._replace(x=100) # _replace() is like str.replace() but targets named fields Point(x=100, y=22) , _z_%dz*Type names and field names must be stringsz8Type names and field names must be valid identifiers: %rz2Type names and field names cannot be a keyword: %rz/Field names cannot start with an underscore: %rz$Encountered duplicate field name: %r'r&z, css|]}tj|dVqdS))nameN)_repr_templateformat).0rqrrr sznamedtuple.. css |]\}}tj||dVqdS))indexrqN)_field_templaters)rtrwrqrrrrus)typename field_names num_fieldsarg_listrepr_fmt field_defsz namedtuple_%s)rNr__main__)r\strreplacesplitrRr_set enumerate isidentifier _iskeyword startswithaddtyper' ValueError_class_templaterstupler(reprjoinr>exec_sourceprintrD _getframe f_globalsgetr*r) ryrzrirjrkseenrwrqclass_definition namespacerOrrrresj               cCs*|j}x|D]}||dd||<q WdS)z!Tally elements from the iterable.r r&N)r)mappingrZZ mapping_getelemrrr_count_elementss r)rcseZdZdZfddZddZd/ddZd d Zed0d d Z fd dZ ddZ ddZ ddZ fddZddZddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+d,Zd-d.ZZS)1raDict subclass for counting hashable items. Sometimes called a bag or multiset. Elements are stored as dictionary keys and their counts are stored as dictionary values. >>> c = Counter('abcdeabcdabcaba') # count elements from a string >>> c.most_common(3) # three most common elements [('a', 5), ('b', 4), ('c', 3)] >>> sorted(c) # list all unique elements ['a', 'b', 'c', 'd', 'e'] >>> ''.join(sorted(c.elements())) # list elements with repetitions 'aaaaabbbbcccdde' >>> sum(c.values()) # total of all counts 15 >>> c['a'] # count of letter 'a' 5 >>> for elem in 'shazam': # update counts from an iterable ... c[elem] += 1 # by adding 1 to each element's count >>> c['a'] # now there are seven 'a' 7 >>> del c['b'] # remove all 'b' >>> c['b'] # now there are zero 'b' 0 >>> d = Counter('simsalabim') # make another counter >>> c.update(d) # add in the second counter >>> c['a'] # now there are nine 'a' 9 >>> c.clear() # empty the counter >>> c Counter() Note: If a count is set to zero or reduced to zero, it will remain in the counter until the entry is deleted or the counter is cleared: >>> c = Counter('aaabbc') >>> c['b'] -= 2 # reduce the count of 'b' by two >>> c.most_common() # 'b' is still in, but its count is zero [('a', 3), ('c', 1), ('b', 0)] csN|s td|^}}t|dkr0tdt|tt|j|j||dS)a Create a new, empty Counter object. And if given, count elements from an input iterable. Or, initialize the count from another mapping of elements to their counts. >>> c = Counter() # a new, empty counter >>> c = Counter('gallahad') # a new counter from an iterable >>> c = Counter({'a': 4, 'b': 2}) # a new counter from a mapping >>> c = Counter(a=4, b=2) # a new counter from keyword args z;descriptor '__init__' of 'Counter' object needs an argumentr&z$expected at most 1 arguments, got %dN)r'r(superrr2rd)r/r0r)rQrrr2s  zCounter.__init__cCsdS)z1The count of elements not in the Counter is zero.r r)rrrrr __missing__szCounter.__missing__NcCs6|dkrt|jtdddStj||jtddS)zList the n most common elements and their counts from the most common to the least. If n is None, then list all element counts. >>> Counter('abcdeabcdabcaba').most_common(3) [('a', 5), ('b', 4), ('c', 3)] Nr&T)rreverse)r)sortedrK _itemgetter_heapqnlargest)rrGrrr most_commons zCounter.most_commoncCstjtt|jS)aIterator over elements repeating each as many times as its count. >>> c = Counter('ABCABC') >>> sorted(c.elements()) ['A', 'A', 'B', 'B', 'C', 'C'] # Knuth's example for prime factors of 1836: 2**2 * 3**3 * 17**1 >>> prime_factors = Counter({2: 2, 3: 3, 17: 1}) >>> product = 1 >>> for factor in prime_factors.elements(): # loop over factors ... product *= factor # and multiply them >>> product 1836 Note, if an element's count has been set to zero or is a negative number, elements() will ignore it. )_chain from_iterable_starmap_repeatrK)rrrrelements+szCounter.elementscCs tddS)Nz@Counter.fromkeys() is undefined. Use Counter(iterable) instead.)NotImplementedError)rYrZvrrrr[CszCounter.fromkeyscs|s td|^}}t|dkr0tdt||r<|dnd}|dk rt|tr|r|j}x8|jD]\}}|||d||<qfWqtt|j|n t |||r|j|dS)aLike dict.update() but add counts instead of replacing them. Source can be an iterable, a dictionary, or another Counter instance. >>> c = Counter('which') >>> c.update('witch') # add elements from another iterable >>> d = Counter('watch') >>> c.update(d) # add elements from another counter >>> c['h'] # four 'h' in which, witch, and watch 4 z9descriptor 'update' of 'Counter' object needs an argumentr&z$expected at most 1 arguments, got %dr N) r'r(r\MappingrrKrrrdr)r/r0rrZself_getrcount)rQrrrdJs    zCounter.updatecOs|s td|^}}t|dkr0tdt||r<|dnd}|dk r|j}t|trxH|jD]\}}||d|||<qbWn x|D]}||dd||<qW|r|j|dS)aLike dict.update() but subtracts counts instead of replacing them. Counts can be reduced below zero. Both the inputs and outputs are allowed to contain zero and negative counts. Source can be an iterable, a dictionary, or another Counter instance. >>> c = Counter('which') >>> c.subtract('witch') # subtract elements from another iterable >>> c.subtract(Counter('watch')) # subtract elements from another counter >>> c['h'] # 2 in which, minus 1 in witch, minus 1 in watch 0 >>> c['w'] # 1 in which, minus 1 in witch, minus 1 in watch -1 z;descriptor 'subtract' of 'Counter' object needs an argumentr&z$expected at most 1 arguments, got %dr N)r'r(rr\rrKsubtract)r/r0rrZrrrrrrrrs   zCounter.subtractcCs |j|S)zReturn a shallow copy.)rQ)rrrrrUsz Counter.copycCs|jt|ffS)N)rQr>)rrrrrXszCounter.__reduce__cs||krtj|dS)zGLike dict.__delitem__() but does not raise KeyError for missing values.N)rr:)rr)rQrrr:szCounter.__delitem__c Cs`|sd|jjSy&djtdj|j}d|jj|fStk rZdj|jjt|SXdS)Nz%s()z, z%r: %rz%s({%s})z {0}({1!r})) rQrrr___mod__rr'rsr>)rrKrrrrSs zCounter.__repr__cCsxt|tstSt}x0|jD]$\}}|||}|dkr|||<qWx,|jD] \}}||krP|dkrP|||<qPW|S)zAdd counts from two counters. >>> Counter('abbb') + Counter('bcc') Counter({'b': 4, 'c': 2, 'a': 1}) r )r\rNotImplementedrK)rrarOrrnewcountrrr__add__s    zCounter.__add__cCs|t|tstSt}x0|jD]$\}}|||}|dkr|||<qWx0|jD]$\}}||krP|dkrPd|||<qPW|S)z Subtract count, but keep only results with positive counts. >>> Counter('abbbc') - Counter('bccd') Counter({'b': 2, 'a': 1}) r )r\rrrK)rrarOrrrrrr__sub__s   zCounter.__sub__cCst|tstSt}x<|jD]0\}}||}||kr:|n|}|dkr|||<qWx,|jD] \}}||kr\|dkr\|||<q\W|S)zUnion is the maximum of value in either of the input counters. >>> Counter('abbb') | Counter('bcc') Counter({'b': 3, 'c': 2, 'a': 1}) r )r\rrrK)rrarOrr other_countrrrr__or__s   zCounter.__or__cCsVt|tstSt}x<|jD]0\}}||}||kr:|n|}|dkr|||<qW|S)z Intersection is the minimum of corresponding counts. >>> Counter('abbb') & Counter('bcc') Counter({'b': 1}) r )r\rrrK)rrarOrrrrrrr__and__s  zCounter.__and__cCs0t}x$|jD]\}}|dkr|||<qW|S)zEAdds an empty counter, effectively stripping negative and zero countsr )rrK)rrOrrrrr__pos__s  zCounter.__pos__cCs4t}x(|jD]\}}|dkrd|||<qW|S)z{Subtracts from an empty counter. Strips positive and zero counts, and flips the sign on negative counts. r )rrK)rrOrrrrr__neg__s zCounter.__neg__cCs*dd|jD}x|D] }||=qW|S)z?Internal method to strip elements with a negative or zero countcSsg|]\}}|dks|qS)r r)rtrrrrr sz*Counter._keep_positive..)rK)r nonpositiverrrr_keep_positives  zCounter._keep_positivecCs.x$|jD]\}}|||7<q W|jS)zInplace add from another counter, keeping only positive counts. >>> c = Counter('abbb') >>> c += Counter('bcc') >>> c Counter({'b': 4, 'c': 2, 'a': 1}) )rKr)rrarrrrr__iadd__s zCounter.__iadd__cCs.x$|jD]\}}|||8<q W|jS)zInplace subtract counter, but keep only results with positive counts. >>> c = Counter('abbbc') >>> c -= Counter('bccd') >>> c Counter({'b': 2, 'a': 1}) )rKr)rrarrrrr__isub__%s zCounter.__isub__cCs6x,|jD] \}}||}||kr |||<q W|jS)zInplace union is the maximum of value from either counter. >>> c = Counter('abbb') >>> c |= Counter('bcc') >>> c Counter({'b': 3, 'c': 2, 'a': 1}) )rKr)rrarrrrrr__ior__2s  zCounter.__ior__cCs6x,|jD] \}}||}||kr |||<q W|jS)zInplace intersection is the minimum of corresponding counts. >>> c = Counter('abbb') >>> c &= Counter('bcc') >>> c Counter({'b': 1}) )rKr)rrarrrrrr__iand__As  zCounter.__iand__)N)N)rrrrbr2rrrrhr[rdrrUrXr:rSrrrrrrrrrrr __classcell__rr)rQrrs0+    ("    c@seZdZdZddZddZddZd'd d Zd d Zd dZ ddZ ddZ e ddZ eddZddZeZd(ddZeddZddZdd Zd!d"Zd#d$Zd%d&ZdS))r a A ChainMap groups multiple dicts (or other mappings) together to create a single, updateable view. The underlying mappings are stored in a list. That list is public and can be accessed or updated using the *maps* attribute. There is no other state. Lookups search the underlying mappings successively until a key is found. In contrast, writes, updates, and deletions only operate on the first mapping. cGst|p ig|_dS)zInitialize a ChainMap by setting *maps* to the given mappings. If no mappings are provided, a single empty dictionary is used. N)rRmaps)rrrrrr2cszChainMap.__init__cCs t|dS)N)r?)rrrrrrjszChainMap.__missing__c Cs8x,|jD]"}y||Stk r(YqXqW|j|S)N)rr?r)rrrrrr __getitem__ms   zChainMap.__getitem__NcCs||kr||S|S)Nr)rrrNrrrrusz ChainMap.getcCsttj|jS)N)r(runionr)rrrr__len__xszChainMap.__len__cCsttj|jS)N)rVrrr)rrrrr<{szChainMap.__iter__cstfdd|jDS)Nc3s|]}|kVqdS)Nr)rtm)rrrrusz(ChainMap.__contains__..)anyr)rrr)rr __contains__~szChainMap.__contains__cCs t|jS)N)rr)rrrr__bool__szChainMap.__bool__cCsdj|djtt|jS)Nz{0.__class__.__name__}({1})z, )rsrr_rr)rrrrrSszChainMap.__repr__cGs|tj|f|S)z?Create a ChainMap with a single dict created from the iterable.)r>r[)rYrZr/rrrr[szChainMap.fromkeyscCs$|j|jdjf|jddS)zHNew ChainMap or subclass with a new copy of maps[0] and refs to maps[1:]r r&N)rQrrU)rrrrrUsz ChainMap.copycCs|dkr i}|j|f|jS)zyNew ChainMap with a new map followed by all previous maps. If no map is provided, an empty dict is used. N)rQr)rrrrr new_childszChainMap.new_childcCs|j|jddS)zNew ChainMap from maps[1:].r&N)rQr)rrrrparentsszChainMap.parentscCs||jd|<dS)Nr )r)rrr3rrrr6szChainMap.__setitem__c Cs8y|jd|=Wn"tk r2tdj|YnXdS)Nr z(Key not found in the first mapping: {!r})rr?rs)rrrrrr:szChainMap.__delitem__c Cs0y|jdjStk r*tdYnXdS)zPRemove and return an item pair from maps[0]. Raise KeyError is maps[0] is empty.r z#No keys found in the first mapping.N)rr@r?)rrrrr@szChainMap.popitemc Gs>y|jdj|f|Stk r8tdj|YnXdS)zWRemove *key* from maps[0] and return its value. Raise KeyError if *key* not in maps[0].r z(Key not found in the first mapping: {!r}N)rr7r?rs)rrr/rrrr7sz ChainMap.popcCs|jdjdS)z'Clear maps[0], leaving maps[1:] intact.r N)rr=)rrrrr=szChainMap.clear)N)N)rrrrbr2rrrrr<rrrgrSrhr[rU__copy__rpropertyrr6r:r@r7r=rrrrr Us(     c@sbeZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ e dddZ dS)rcOs|s td|^}}t|dkr0tdt||r>|d}n0d|krj|jd}ddl}|jdtddnd}i|_|dk r|j|t|r|j|dS) Nzz0Passing 'dict' as keyword argument is deprecatedrC) stacklevel)r'r(r7warningswarnDeprecationWarningdatard)r/kwargsrr>rrrrr2s$     zUserDict.__init__cCs t|jS)N)r(r)rrrrrszUserDict.__len__cCs:||jkr|j|St|jdr.|jj||St|dS)Nr)rhasattrrQrr?)rrrrrrs    zUserDict.__getitem__cCs||j|<dS)N)r)rritemrrrr6szUserDict.__setitem__cCs |j|=dS)N)r)rrrrrr:szUserDict.__delitem__cCs t|jS)N)rVr)rrrrr<szUserDict.__iter__cCs ||jkS)N)r)rrrrrrszUserDict.__contains__cCs t|jS)N)rr)rrrrrSszUserDict.__repr__c CsR|jtkrt|jjSddl}|j}zi|_|j|}Wd||_X|j||S)Nr )rQrrrUrd)rrUrcrrrrUs  z UserDict.copyNcCs |}x|D] }|||<q W|S)Nr)rYrZr3drrrrr[s  zUserDict.fromkeys)N)rrrr2rrr6r:r<rrSrUrhr[rrrrrs c@seZdZdZd>ddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZddZddZdd Zd!d"Zd#d$ZeZd%d&Zd'd(Zd)d*Zd@d,d-Zd.d/Zd0d1Zd2d3Zd4d5Zd6d7Zd8d9Zd:d;Z dszUserList.indexcCs|jjdS)N)rr)rrrrr?szUserList.reversecOs|jj||dS)N)rsort)rr/r0rrrr@sz UserList.sortcCs*t|tr|jj|jn |jj|dS)N)r\rrextend)rrarrrrAs zUserList.extend)Nr)r)"rrrrbr2rSrrr]rrrrrrr6r:rrrr__rmul__rrrr7rr=rUrrwrrrrrrrrs>  c@s`eZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZddZddZdd Zd!d"Zd#d$Zd%d&ZeZd'd(Zd)d*Zd+d,Zd-d.Zd/d0Zd1ejfd2d3Zdd5d6Zd1ejfd7d8Z dd:d;Z!d1ejfdd?Z#d@dAZ$d1ejfdBdCZ%dDdEZ&dFdGZ'dHdIZ(dJdKZ)dLdMZ*dNdOZ+dPdQZ,dRdSZ-dTdUZ.dVdWZ/dXdYZ0dZd[Z1d\d]Z2d^d_Z3dd`daZ4e5j6Z6dbdcZ7ddedfZ8d1ejfdgdhZ9d1ejfdidjZ:dkdlZ;dmdnZddsdtZ?ddvdwZ@d1ejfdxdyZAddzd{ZBd|d}ZCd~dZDddZEddZFddZGd4S)rcCs<t|tr||_n&t|tr.|jdd|_n t||_dS)N)r\rrr)rseqrrrr2Ns   zUserString.__init__cCs t|jS)N)rr)rrrr__str__UszUserString.__str__cCs t|jS)N)rr)rrrrrSVszUserString.__repr__cCs t|jS)N)intr)rrrr__int__WszUserString.__int__cCs t|jS)N)floatr)rrrr __float__XszUserString.__float__cCs t|jS)N)complexr)rrrr __complex__YszUserString.__complex__cCs t|jS)N)hashr)rrrr__hash__ZszUserString.__hash__cCs|jddfS)N)r)rrrr__getnewargs__[szUserString.__getnewargs__cCs t|tr|j|jkS|j|kS)N)r\rr)rstringrrrr]^s  zUserString.__eq__cCs t|tr|j|jkS|j|kS)N)r\rr)rrrrrrbs  zUserString.__lt__cCs t|tr|j|jkS|j|kS)N)r\rr)rrrrrrfs  zUserString.__le__cCs t|tr|j|jkS|j|kS)N)r\rr)rrrrrrjs  zUserString.__gt__cCs t|tr|j|jkS|j|kS)N)r\rr)rrrrrrns  zUserString.__ge__cCst|tr|j}||jkS)N)r\rr)rcharrrrrss zUserString.__contains__cCs t|jS)N)r(r)rrrrrxszUserString.__len__cCs|j|j|S)N)rQr)rrwrrrryszUserString.__getitem__cCsJt|tr|j|j|jSt|tr6|j|j|S|j|jt|S)N)r\rrQrr)rrarrrrzs   zUserString.__add__cCs.t|tr|j||jS|jt||jS)N)r\rrQr)rrarrrrs zUserString.__radd__cCs|j|j|S)N)rQr)rrGrrrrszUserString.__mul__cCs|j|j|S)N)rQr)rr/rrrrszUserString.__mod__cCs|j|tS)N)rQr/)rrsrrr__rmod__szUserString.__rmod__cCs|j|jjS)N)rQr capitalize)rrrrrszUserString.capitalizecCs|j|jjS)N)rQrcasefold)rrrrrszUserString.casefoldcGs|j|jj|f|S)N)rQrcenter)rwidthr/rrrrszUserString.centerr cCs t|tr|j}|jj|||S)N)r\rrr)rsubstartendrrrrs zUserString.countNcCs>|r.|r|j|jj||S|j|jj|S|j|jjS)N)rQrencode)rencodingerrorsrrrrs zUserString.encodecCs|jj|||S)N)rendswith)rsuffixrrrrrrszUserString.endswithcCs|j|jj|S)N)rQr expandtabs)rtabsizerrrrszUserString.expandtabscCs t|tr|j}|jj|||S)N)r\rrfind)rrrrrrrrs zUserString.findcOs|jj||S)N)rrs)rr/r0rrrrsszUserString.formatcCs |jj|S)N)r format_map)rrrrrrszUserString.format_mapcCs|jj|||S)N)rrw)rrrrrrrrwszUserString.indexcCs |jjS)N)risalpha)rrrrrszUserString.isalphacCs |jjS)N)risalnum)rrrrrszUserString.isalnumcCs |jjS)N)r isdecimal)rrrrr szUserString.isdecimalcCs |jjS)N)risdigit)rrrrr szUserString.isdigitcCs |jjS)N)rr)rrrrrszUserString.isidentifiercCs |jjS)N)rislower)rrrrr szUserString.islowercCs |jjS)N)r isnumeric)rrrrr szUserString.isnumericcCs |jjS)N)r isprintable)rrrrr szUserString.isprintablecCs |jjS)N)risspace)rrrrrszUserString.isspacecCs |jjS)N)ristitle)rrrrrszUserString.istitlecCs |jjS)N)risupper)rrrrrszUserString.isuppercCs |jj|S)N)rr)rrrrrrszUserString.joincGs|j|jj|f|S)N)rQrljust)rrr/rrrrszUserString.ljustcCs|j|jjS)N)rQrlower)rrrrrszUserString.lowercCs|j|jj|S)N)rQrlstrip)rcharsrrrrszUserString.lstripcCs |jj|S)N)r partition)rseprrrrszUserString.partitionr&cCs6t|tr|j}t|tr |j}|j|jj|||S)N)r\rrrQr)roldnewmaxsplitrrrrs   zUserString.replacecCs t|tr|j}|jj|||S)N)r\rrrfind)rrrrrrrrs zUserString.rfindcCs|jj|||S)N)rrindex)rrrrrrrrszUserString.rindexcGs|j|jj|f|S)N)rQrrjust)rrr/rrrrszUserString.rjustcCs |jj|S)N)r rpartition)rrrrrrszUserString.rpartitioncCs|j|jj|S)N)rQrrstrip)rrrrrrszUserString.rstripcCs|jj||S)N)rr)rrrrrrrszUserString.splitcCs|jj||S)N)rrsplit)rrrrrrrszUserString.rsplitFcCs |jj|S)N)r splitlines)rkeependsrrrr szUserString.splitlinescCs|jj|||S)N)rr)rprefixrrrrrrszUserString.startswithcCs|j|jj|S)N)rQrstrip)rrrrrr#szUserString.stripcCs|j|jjS)N)rQrswapcase)rrrrr$szUserString.swapcasecCs|j|jjS)N)rQrtitle)rrrrr%szUserString.titlecGs|j|jj|S)N)rQr translate)rr/rrrr&szUserString.translatecCs|j|jjS)N)rQrupper)rrrrr'szUserString.uppercCs|j|jj|S)N)rQrzfill)rrrrrr(szUserString.zfill)NN)r)Nr)r)Nr)Nrr)Nr)F)N)Hrrrr2rrSrrrrrr]rrrrrrrrrrrrrrrrrDmaxsizerrrrrrsrrwrrr r rr r r rrrrrrrr maketransrrrrrrrrrr rr#r$r%r&r'r(rrrrrMs         )8rb__all___collections_abcoperatorr rr r`keywordrrsysrDheapqr_weakrefrr, itertoolsrrrrrrreprlibrrg _collectionsr ImportErrorMutableSequenceregisterrKeysViewr ItemsViewr ValuesViewr rfr!r>rrrrrxrrrrcr rrSequencerrrrrs`       `3blCIconnection.cpython-36.opt-2.pyc000064400000053450147204630710012304 0ustar003 fVy @s ddddgZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl m Z ddl m Z m Z dd lmZejZy$ddlZdd lmZmZmZmZWn$ek rejd kr‚dZYnXd Zd ZdZejZdZdgZe edrdZedg7Zejd krdZedg7ZefddZ!ddZ"ddZ#ddZ$ddZ%GdddZ&ernGddde&Z'Gd d!d!e&Z(Gd"dde)Z*dPd#dZ+ejd krdQd%dZ,n dRd&dZ,Gd'd(d(e)Z-d)d*Z.ejd krGd+d,d,e)Z/d-d.Z0d/Z1d0Z2d1Z3d2Z4d3d4Z5d5d6Z6Gd7d8d8e)Z7d9d:Z8d;d<Z9Gd=d>d>e*Z:d?d@Z;ejd krzdAdBZhZ?dSdCdZ@n,ddlAZAe eAdDreAjBZCneAjDZCdTdEdZ@ejd krdFdGZEdHdIZFejGe(eEdJdKZHdLdMZIejGe'eHndNdGZEdOdIZFejGe(eEdS)UClientListenerPipewaitN)util)AuthenticationErrorBufferTooShort) reduction) WAIT_OBJECT_0WAIT_ABANDONED_0 WAIT_TIMEOUTINFINITEwin32i g4@Zsha256AF_INETAF_UNIXAF_PIPEcCs tj|S)N)time monotonic)timeoutr2/usr/lib64/python3.6/multiprocessing/connection.py _init_timeout?srcCs tj|kS)N)rr)trrr_check_timeoutBsrcCsX|dkr d S|dkr&tjdtjdS|dkrLtjdtjttfd dStd dS) Nr localhostrrz listener-)prefixdirrz\\.\pipe\pyc-%d-%d-zunrecognized family)rr) tempfileZmktemprZ get_temp_dirosgetpidnext _mmap_counter ValueError)familyrrrarbitrary_addressIsr&cCsJtjdkr|dkrtd|tjdkrF|dkrFtt|sFtd|dS)NrrzFamily %s is not recognized.r)sysplatformr$hasattrsocket)r%rrr_validate_familyWs   r+cCsJt|tkrdSt|tkr*|jdr*dSt|tkr:dStd|dS)Nrz\\rrzaddress type of %r unrecognized)typetuplestr startswithr$)addressrrr address_typecs  r1c@seZdZdZd+ddZddZddZd d Zd d Zd dZ e ddZ e ddZ e ddZ ddZddZd,ddZddZd-ddZd.d d!Zd"d#Zd/d%d&Zd'd(Zd)d*ZdS)0_ConnectionBaseNTcCsB|j}|dkrtd| r,| r,td||_||_||_dS)Nrzinvalid handlez6at least one of `readable` and `writable` must be True) __index__r$_handle _readable _writable)selfhandlereadablewritablerrr__init__ys z_ConnectionBase.__init__cCs|jdk r|jdS)N)r4_close)r7rrr__del__s z_ConnectionBase.__del__cCs|jdkrtddS)Nzhandle is closed)r4OSError)r7rrr _check_closeds z_ConnectionBase._check_closedcCs|jstddS)Nzconnection is write-only)r5r>)r7rrr_check_readablesz_ConnectionBase._check_readablecCs|jstddS)Nzconnection is read-only)r6r>)r7rrr_check_writablesz_ConnectionBase._check_writablecCs"|jrd|_n|jtddS)NFzbad message length)r6r5closer>)r7rrr_bad_message_lengthsz#_ConnectionBase._bad_message_lengthcCs |jdkS)N)r4)r7rrrclosedsz_ConnectionBase.closedcCs|jS)N)r5)r7rrrr9sz_ConnectionBase.readablecCs|jS)N)r6)r7rrrr:sz_ConnectionBase.writablecCs|j|jS)N)r?r4)r7rrrfilenosz_ConnectionBase.filenoc Cs$|jdk r z |jWdd|_XdS)N)r4r<)r7rrrrBs  z_ConnectionBase.closercCs|j|jt|}|jdkr.tt|}t|}|dkrFtd||krVtd|dkrh||}n&|dkrztdn|||krtd|j||||dS)Nrrzoffset is negativezbuffer length < offsetzsize is negativezbuffer length < offset + size)r?rA memoryviewitemsizebyteslenr$ _send_bytes)r7bufoffsetsizemnrrr send_bytess"     z_ConnectionBase.send_bytescCs$|j|j|jtj|dS)N)r?rArJ_ForkingPicklerdumps)r7objrrrsendsz_ConnectionBase.sendcCsJ|j|j|dk r(|dkr(td|j|}|dkrB|j|jS)Nrznegative maxlength)r?r@r$ _recv_bytesrCgetvalue)r7Z maxlengthrKrrr recv_bytess z_ConnectionBase.recv_bytesc Cs|j|jt|}|j}|t|}|dkr>tdn||krNtd|j}|j}|||krvt|j |j d|j |||||||SQRXdS)Nrznegative offsetzoffset too large) r?r@rFrGrIr$rUtellr rVseekreadinto)r7rKrLrNrGZbytesizeresultrMrrrrecv_bytes_intos"       z_ConnectionBase.recv_bytes_intocCs&|j|j|j}tj|jS)N)r?r@rUrQloads getbuffer)r7rKrrrrecvsz_ConnectionBase.recvcCs|j|j|j|S)N)r?r@_poll)r7rrrrpollsz_ConnectionBase.pollcCs|S)Nr)r7rrr __enter__sz_ConnectionBase.__enter__cCs |jdS)N)rB)r7exc_type exc_valueexc_tbrrr__exit__ sz_ConnectionBase.__exit__)TT)rN)N)r)r`)__name__ __module__ __qualname__r4r;r=r?r@rArCpropertyrDr9r:rErBrPrTrWr\r_rbrcrgrrrrr2vs(       r2c@s@eZdZdZejfddZddZd ddZd d Z d d Z dS)PipeConnectionFcCs||jdS)N)r4)r7Z _CloseHandlerrrr<szPipeConnection._closecCshtj|j|dd\}}zwinerrorERROR_BROKEN_PIPEEOFError RuntimeError) r7maxsizeZbsizertrurvZnreadferrrrU*s6      zPipeConnection._recv_bytescCs.|jstj|jddkrdStt|g|S)NrT)rxrn PeekNamedPiper4boolr)r7rrrrraJszPipeConnection._pollcCs|j}tj}|j|tj|jd}|dk rJt|||krJ|jtj |j|dd\}}|j d\}}|j|j|S)NrT)rm) r^ryrzr}rnrr4rIrCr|rs)r7rtrrKrleftruZrbytesrrrr~Ps zPipeConnection._get_more_data)N) rhrirjrxrn CloseHandler<rJrUrar~rrrrrls  rlc@sxeZdZer(ejfddZejZej Z ne j fddZe j Ze jZ efddZe fddZdd Zdd d Zd dZd S) ConnectioncCs||jdS)N)r4)r7r<rrrr<gszConnection._closecCs||jdS)N)r4)r7r<rrrr<lscCs<t|}x.||j|}||8}|dkr(P||d}q WdS)Nr)rIr4)r7rKr} remainingrOrrr_sendqs zConnection._sendcCsftj}|j}|}xN|dkr`|||}t|}|dkrL||krDtntd|j|||8}qW|S)Nrzgot end of file during message)ryrzr4rIrr>r})r7rMreadrKr8rchunkrOrrr_recvzs    zConnection._recvcCsDt|}tjd|}|dkr2|j||j|n|j||dS)Nz!ii@)rIstructZpackr)r7rKrOheaderrrrrJs    zConnection._send_bytesNcCs:|jd}tjd|j\}|dk r0||kr0dS|j|S)Nz!i)rrZunpackrV)r7rrKrMrrrrUs  zConnection._recv_bytescCst|g|}t|S)N)rr)r7rrrrrras zConnection._poll)N)rhrirjrn_multiprocessingZ closesocketr<rTZ_writer_Z_readr rBr}rrrrJrUrarrrrr`s  rc@sNeZdZdddZddZddZed d Zed d Zd d Z ddZ dS)rNrcCsr|p|rt|pt}|pt|}t||dkr>t|||_nt||||_|dk rht|t rht d||_ dS)Nrzauthkey should be a byte string) r1default_familyr&r+ PipeListener _listenerSocketListener isinstancerH TypeError_authkey)r7r0r%backlogauthkeyrrrr;s zListener.__init__cCs>|jdkrtd|jj}|jr:t||jt||j|S)Nzlistener is closed)rr>acceptrdeliver_challengeanswer_challenge)r7crrrrs    zListener.acceptcCs |j}|dk rd|_|jdS)N)rrB)r7ZlistenerrrrrBszListener.closecCs|jjS)N)r_address)r7rrrszListener.cCs|jjS)N)r_last_accepted)r7rrrrscCs|S)Nr)r7rrrrcszListener.__enter__cCs |jdS)N)rB)r7rdrerfrrrrgszListener.__exit__)NNrN) rhrirjr;rrBrkr0Z last_acceptedrcrgrrrrrs   cCsj|p t|}t||dkr&t|}nt|}|dk rJt|t rJtd|dk rft||t|||S)Nrzauthkey should be a byte string) r1r+ PipeClient SocketClientrrHrrr)r0r%rrrrrrs    TcCsj|r>tj\}}|jd|jdt|j}t|j}n$tj\}}t|dd}t|dd}||fS)NTF)r:)r9)r*Z socketpair setblockingrdetachr pipe)duplexs1s2c1c2Zfd1Zfd2rrrrs       c Cstd}|r*tj}tjtjB}tt}}ntj}tj}dt}}tj||tjBtj Btj tj Btj Bd||tj tj}tj||dtjtjtjtj}tj|tj ddtj|dd}|jd\} } t||d} t||d} | | fS)NrrrT)rm)r:)r9)r&rnPIPE_ACCESS_DUPLEX GENERIC_READ GENERIC_WRITEBUFSIZEZPIPE_ACCESS_INBOUNDCreateNamedPipeFILE_FLAG_OVERLAPPEDFILE_FLAG_FIRST_PIPE_INSTANCEPIPE_TYPE_MESSAGEPIPE_READMODE_MESSAGE PIPE_WAITNMPWAIT_WAIT_FOREVERNULL CreateFile OPEN_EXISTINGSetNamedPipeHandleStateConnectNamedPipersrl) rr0ZopenmodeaccessZobsizeZibsizeZh1Zh2rm_rurrrrrr s2         c@s&eZdZd ddZddZddZdS) rrcCstjtt||_yRtjdkr2|jjtjtjd|jjd|jj ||jj ||jj |_ Wn t k r|jjYnX||_d|_|dkrtj|tj|fdd|_nd|_dS)NposixrTrr)args exitpriority)r*getattr_socketr nameZ setsockoptZ SOL_SOCKETZ SO_REUSEADDRrZbindZlistenZ getsocknamerr>rBZ_familyrrFinalizeunlink_unlink)r7r0r%rrrrr;<s$       zSocketListener.__init__cCs&|jj\}|_|jdt|jS)NT)rrrrrr)r7srrrrTs zSocketListener.acceptc Cs0z|jjWd|j}|dk r*d|_|XdS)N)rrBr)r7rrrrrBYs zSocketListener.closeN)r)rhrirjr;rrBrrrrr8s rc CsDt|}tjtt|"}|jd|j|t|jSQRXdS)NT)r1r*rrZconnectrr)r0r%rrrrrcs   rc@s4eZdZd ddZd ddZddZed d ZdS) rNcCsL||_|jddg|_d|_tjd|jtj|tj|j|jfdd|_ dS)NT)firstz listener created with address=%rr)rr) r _new_handle _handle_queuerr sub_debugrr_finalize_pipe_listenerrB)r7r0rrrrr;wszPipeListener.__init__Fc CsHtjtjB}|r|tjO}tj|j|tjtjBtjBtj t t tj tj S)N) rnrrrrrrrrZPIPE_UNLIMITED_INSTANCESrrr)r7rflagsrrrrs   zPipeListener._new_handlecCs|jj|j|jjd}ytj|dd}Wn0tk r^}z|jtjkrNWYdd}~XnPXzrZ ERROR_NO_DATArprqrrrrrsrl)r7r8rtrresrrurrrrs"    zPipeListener.acceptcCs(tjd|x|D]}tj|qWdS)Nz closing listener with address=%r)rrrnr)Zqueuer0r8rrrrs  z$PipeListener._finalize_pipe_listener)N)F)rhrirjr;rr staticmethodrrrrrrss rcCst}x~y6tj|dtj|tjtjBdtjtjtjtj}Wn>t k r|}z"|j tj tj fksjt |rlWYdd}~XqXPqWtj|tjddt|S)Nir)rrnZ WaitNamedPiperrrrrrr>rZERROR_SEM_TIMEOUTZERROR_PIPE_BUSYrrrrl)r0rhrrrrrs"   rs #CHALLENGE#s #WELCOME#s #FAILURE#cCsfddl}tjt}|jt||j||tj}|j d}||krP|jt n|jt t ddS)Nrzdigest received was wrong) hmacr urandomMESSAGE_LENGTHrP CHALLENGEnewHMAC_DIGEST_NAMEdigestrWWELCOMEFAILUREr) connectionrrmessagerresponserrrrs    rcCs\ddl}|jd}|ttd}|j||tj}|j||jd}|tkrXt ddS)Nrrzdigest sent was rejected) rrWrIrrrrrPrr)rrrrrrrrrrs   rc@s$eZdZddZddZddZdS)ConnectionWrappercCs:||_||_||_x"dD]}t||}t|||qWdS)NrErBrbrWrP)rErBrbrWrP)_conn_dumps_loadsrsetattr)r7connrRr]attrrSrrrr;s   zConnectionWrapper.__init__cCs|j|}|jj|dS)N)rrrP)r7rSrrrrrTs zConnectionWrapper.sendcCs|jj}|j|S)N)rrWr)r7rrrrr_s zConnectionWrapper.recvN)rhrirjr;rTr_rrrrrsrcCstj|fddddjdS)Nrzutf-8) xmlrpclibrRencode)rSrrr _xml_dumpssrcCstj|jd\\}}|S)Nzutf-8)rr]decode)rrSmethodrrr _xml_loadssrc@seZdZddZdS) XmlListenercCs ddljatj|}t|ttS)Nr) xmlrpc.clientclientrrrrrr)r7rSrrrrs  zXmlListener.acceptN)rhrirjrrrrrrsrcOsddljatt||ttS)Nr)rrrrrrr)rkwdsrrr XmlClient s rcCst|}g}x|rtj|d|}|tkr,Pn\t|koFtt|knrV|t8}n2t|koptt|knr|t8}ntd|j||||dd}d}qW|S)NFzShould not get hererr) listrnrpr r rIr rr)ZhandlesrLreadyrrrr_exhaustive_waits    rc .sn|dkrt}n|dkrd}nt|dd}t|}ig}tt}zHx2|D](}yt|d}Wn tk r||j<YqTXytj|dd\}}Wn8t k r}zd|j }}|t krʂWYdd}~XnX|tj kr|j |||j<qT|rptjdddkrpy|jd\} }Wn*t k rT}z |j }WYdd}~XnX| rpt|d rpd|_j|d}qTWtj|}Wdx|D]}|jqWx|D]}y|jd\} }Wn6t k r}z|j }|t krWYdd}~XnX|tjkr|j}j||dkrt|d rd|_qWXjfd d |Dfd d |DS)Nrig?rETFrxc3s|]}|VqdS)Nr).0r)waithandle_to_objrr vszwait..csg|]}|kr|qSrr)ro) ready_objectsrr wszwait..)rr)rintrsetrAttributeErrorr3rnr|r>r _ready_errorsrorrqr'Zgetwindowsversionrsr)rxaddrkeysrrZERROR_OPERATION_ABORTEDupdate) object_listrZov_listZ ready_handlesrrErtrurrr)rrrr+sh              PollSelectorc Cstx}x|D]}|j|tjqW|dk r8tj|}x@|j|}|rVdd|DS|dk r:|tj}|dkr:|Sq:WWdQRXdS)NcSsg|]\}}|jqSr)Zfileobj)rkeyZeventsrrrrszwait..r) _WaitSelectorregister selectorsZ EVENT_READrrZselect)r rZselectorrSZdeadlinerrrrrs    c CsN|j}tj|tjtj*}ddlm}|j|}t||j |j ffSQRXdS)Nr)resource_sharer) rEr*ZfromfdrZ SOCK_STREAMrrZ DupSocketrebuild_connectionr9r:)rr8rrdsrrrreduce_connections   rcCs|j}t|j||S)N)rr)rr9r:ZsockrrrrsrcCsB|jr tjnd|jrtjndB}tj|j|}t||j|jffS)Nr) r9rnZFILE_GENERIC_READr:ZFILE_GENERIC_WRITEr Z DupHandlerErebuild_pipe_connection)rrdhrrrreduce_pipe_connectionsrcCs|j}t|||S)N)rrl)rr9r:r8rrrrsrcCs tj|j}t||j|jffS)N)r ZDupFdrErr9r:)rdfrrrrscCs|j}t|||S)N)rr)rr9r:fdrrrrs)NN)T)T)N)N)J__all__ryr r'r*rrr itertoolsrrrrr contextr ZForkingPicklerrQrnr r r r ImportErrorr(rZCONNECTION_TIMEOUTrcountr#rZfamiliesr)rrr&r+r1r2rlrobjectrrrrrrrrrrrrrrrrrrrrZERROR_NETNAME_DELETEDrrrr r ZSelectSelectorrrr rrrrrr s           PJ8    ,+ 8    P    _header_value_parser.cpython-36.opt-2.pyc000064400000164354147204636050014315 0ustar003 f@svddlZddlZddlmZddlmZddlmZddlm Z ddlm Z ddlm Z e dZee d BZe d ZeeBZee d Zee d Zee d Be d ZeeBZee dBZeeBZee dZddhZeeBZddZGdddeZGdddeZGdddeZGdddeZ GdddeZ!GdddeZ"Gd d!d!eZ#Gd"d#d#eZ$Gd$d%d%eZ%Gd&d'd'eZ&Gd(d)d)e&Z'Gd*d+d+eZ(Gd,d-d-eZ)Gd.d/d/eZ*Gd0d1d1eZ+Gd2d3d3eZ,Gd4d5d5eZ-Gd6d7d7eZ.Gd8d9d9eZ/Gd:d;d;eZ0Gdd?d?eZ2Gd@dAdAeZ3GdBdCdCeZ4GdDdEdEeZ5GdFdGdGeZ6GdHdIdIeZ7GdJdKdKe Z8GdLdMdMeZ9GdNdOdOeZ:GdPdQdQeZ;GdRdSdSeZGdXdYdYeZ?GdZd[d[eZ@Gd\d]d]eZAGd^d_d_eZBGd`dadaeBZCGdbdcdceBZDGdddedeeZEGdfdgdgeZFGdhdidieZGGdjdkdkeHZIGdldmdmeIZJGdndodoeIZKGdpdqdqeJZLeKd drZMeKdsdtZNeKdudvZOejPdwjQdxjRejSZTejPdyjQdxjRejUdzd{jUd|d}jVZWejPd~jXZYejPdyjQdxjRejUdzd{jUd|d}jVZZejPdyjQdxjRejUdzd{jUd|d}jVZ[ejPdyjQdxjRejUdzd{jUd|d}jVZ\ddZ]ddZ^ddZ_ddZ`ddZaddZbddZcddZdddZeddZfddZgddZhddZiddZjddZkddZlddZmddZnddZoddZpddZqddZrddZsddZtddZuddZvddZwddZxddZyddZzddZ{ddZ|ddZ}dd„Z~ddĄZddƄZddȄZddʄZdd̄Zdd΄ZddЄZdd҄ZddԄZddքZdd؄ZddڄZdd܄ZddބZddZddZddZddZddZddZddZdS)N) hexdigits) OrderedDict) itemgetter)_encoded_words)errors)utilsz (z ()<>@,:;.\"[].z."(z/?=z*'%%  cCs dt|jddjdddS)N"\z\\z\")strreplace)valuer2/usr/lib64/python3.6/email/_header_value_parser.py quote_stringbsrcseZdZdZdZdZfddZddZfddZe d d Z e d d Z d dZ e ddZ e ddZddZdddZdddZdddZZS) TokenListNTcstj||g|_dS)N)super__init__defects)selfargskw) __class__rrroszTokenList.__init__cCsdjdd|DS)Ncss|]}t|VqdS)N)r).0xrrr tsz$TokenList.__str__..)join)rrrr__str__sszTokenList.__str__csdj|jjtjS)Nz{}({}))formatr__name__r__repr__)r)rrrr%vs zTokenList.__repr__cCsdjdd|DS)Nrcss|]}|jr|jVqdS)N)r)rrrrrr |sz"TokenList.value..)r!)rrrrrzszTokenList.valuecCstdd|D|jS)Ncss|] }|jVqdS)N) all_defects)rrrrrr sz(TokenList.all_defects..)sumr)rrrrr&~szTokenList.all_defectscCs |djS)Nr)startswith_fws)rrrrr(szTokenList.startswith_fwscCstdd|DS)Ncss|] }|jVqdS)N) as_ew_allowed)rpartrrrr sz*TokenList.as_ew_allowed..)all)rrrrr)szTokenList.as_ew_allowedcCs"g}x|D]}|j|jq W|S)N)extendcomments)rr-tokenrrrr-s zTokenList.commentscCs t||dS)N)policy)_refold_parse_tree)rr/rrrfoldszTokenList.foldrcCst|j|ddS)N)indent)printppstr)rr2rrrpprintszTokenList.pprintcCsdj|j|dS)Nr )r2)r!_pp)rr2rrrr4szTokenList.ppstrccs~dj||jj|jVx<|D]4}t|ds<|dj|Vq|j|dEdHqW|jrhdj|j}nd}dj||VdS)Nz{}{}/{}(r6z* !! invalid element in token list: {!r}z z Defects: {}rz{}){})r#rr$ token_typehasattrr6r)rr2r.Zextrarrrr6s    z TokenList._pp)r)r)r)r$ __module__ __qualname__r7syntactic_breakew_combine_allowedrr"r%propertyrr&r(r)r-r1r5r4r6 __classcell__rr)rrris        rc@s$eZdZeddZeddZdS)WhiteSpaceTokenListcCsdS)N r)rrrrrszWhiteSpaceTokenList.valuecCsdd|DS)NcSsg|]}|jdkr|jqS)comment)r7content)rrrrr sz0WhiteSpaceTokenList.comments..r)rrrrr-szWhiteSpaceTokenList.commentsN)r$r9r:r=rr-rrrrr?s r?c@seZdZdZdS)UnstructuredTokenList unstructuredN)r$r9r:r7rrrrrDsrDc@seZdZdZdS)PhrasephraseN)r$r9r:r7rrrrrFsrFc@seZdZdZdS)WordZwordN)r$r9r:r7rrrrrHsrHc@seZdZdZdS)CFWSListcfwsN)r$r9r:r7rrrrrIsrIc@seZdZdZdS)AtomatomN)r$r9r:r7rrrrrKsrKc@seZdZdZdZdS)Tokenr.FN)r$r9r:r7Z encode_as_ewrrrrrMsrMc@seZdZdZdZdZdZdS) EncodedWordz encoded-wordN)r$r9r:r7ctecharsetlangrrrrrNsrNc@s4eZdZdZeddZeddZeddZdS) QuotedStringz quoted-stringcCs"x|D]}|jdkr|jSqWdS)Nzbare-quoted-string)r7r)rrrrrrBs  zQuotedString.contentcCsBg}x2|D]*}|jdkr(|jt|q |j|jq Wdj|S)Nzbare-quoted-stringr)r7appendrrr!)rresrrrr quoted_values   zQuotedString.quoted_valuecCs"x|D]}|jdkr|jSqWdS)Nzbare-quoted-string)r7r)rr.rrrstripped_values  zQuotedString.stripped_valueN)r$r9r:r7r=rBrUrVrrrrrRs  rRc@s$eZdZdZddZeddZdS)BareQuotedStringzbare-quoted-stringcCstdjdd|DS)Nrcss|]}t|VqdS)N)r)rrrrrr sz+BareQuotedString.__str__..)rr!)rrrrr"szBareQuotedString.__str__cCsdjdd|DS)Nrcss|]}t|VqdS)N)r)rrrrrr sz)BareQuotedString.value..)r!)rrrrrszBareQuotedString.valueN)r$r9r:r7r"r=rrrrrrWsrWc@s8eZdZdZddZddZeddZedd Zd S) CommentrAcs(djtdgfddDdgggS)Nrrcsg|]}j|qSr)quote)rr)rrrrC sz#Comment.__str__..))r!r')rr)rrr"s zComment.__str__cCs2|jdkrt|St|jddjddjddS)NrArz\\rz\(rZz\))r7rr)rrrrrrYs  z Comment.quotecCsdjdd|DS)Nrcss|]}t|VqdS)N)r)rrrrrr sz"Comment.content..)r!)rrrrrBszComment.contentcCs|jgS)N)rB)rrrrr-szComment.commentsN) r$r9r:r7r"rYr=rBr-rrrrrXs  rXc@s4eZdZdZeddZeddZeddZdS) AddressListz address-listcCsdd|DS)NcSsg|]}|jdkr|qS)address)r7)rrrrrrC$sz)AddressList.addresses..r)rrrr addresses"szAddressList.addressescCstdd|DgS)Ncss|]}|jdkr|jVqdS)r\N)r7 mailboxes)rrrrrr (sz(AddressList.mailboxes..)r')rrrrr^&szAddressList.mailboxescCstdd|DgS)Ncss|]}|jdkr|jVqdS)r\N)r7 all_mailboxes)rrrrrr -sz,AddressList.all_mailboxes..)r')rrrrr_+szAddressList.all_mailboxesN)r$r9r:r7r=r]r^r_rrrrr[s  r[c@s4eZdZdZeddZeddZeddZdS) Addressr\cCs|djdkr|djSdS)Nrgroup)r7 display_name)rrrrrb5szAddress.display_namecCs4|djdkr|dgS|djdkr*gS|djS)Nrmailboxzinvalid-mailbox)r7r^)rrrrr^:s  zAddress.mailboxescCs:|djdkr|dgS|djdkr0|dgS|djS)Nrrczinvalid-mailbox)r7r_)rrrrr_Bs   zAddress.all_mailboxesN)r$r9r:r7r=rbr^r_rrrrr`1s  r`c@s(eZdZdZeddZeddZdS) MailboxListz mailbox-listcCsdd|DS)NcSsg|]}|jdkr|qS)rc)r7)rrrrrrCPsz)MailboxList.mailboxes..r)rrrrr^NszMailboxList.mailboxescCsdd|DS)NcSsg|]}|jdkr|qS)rcinvalid-mailbox)rcre)r7)rrrrrrCTsz-MailboxList.all_mailboxes..r)rrrrr_RszMailboxList.all_mailboxesN)r$r9r:r7r=r^r_rrrrrdJs rdc@s(eZdZdZeddZeddZdS) GroupListz group-listcCs"| s|djdkrgS|djS)Nrz mailbox-list)r7r^)rrrrr^\szGroupList.mailboxescCs"| s|djdkrgS|djS)Nrz mailbox-list)r7r_)rrrrr_bszGroupList.all_mailboxesN)r$r9r:r7r=r^r_rrrrrfXs rfc@s4eZdZdZeddZeddZeddZdS) GroupracCs|djdkrgS|djS)Nz group-list)r7r^)rrrrr^mszGroup.mailboxescCs|djdkrgS|djS)Nrhz group-list)r7r_)rrrrr_sszGroup.all_mailboxescCs |djS)Nr)rb)rrrrrbyszGroup.display_nameN)r$r9r:r7r=r^r_rbrrrrrgis  rgc@sLeZdZdZeddZeddZeddZedd Zed d Z d S) NameAddrz name-addrcCst|dkrdS|djS)Nr)lenrb)rrrrrbs zNameAddr.display_namecCs |djS)Nrj) local_part)rrrrrmszNameAddr.local_partcCs |djS)Nrjrl)domain)rrrrrnszNameAddr.domaincCs |djS)Nrjrl)route)rrrrroszNameAddr.routecCs |djS)Nrjrl) addr_spec)rrrrrpszNameAddr.addr_specN) r$r9r:r7r=rbrmrnrorprrrrri~s     ric@s@eZdZdZeddZeddZeddZedd Zd S) AngleAddrz angle-addrcCs"x|D]}|jdkr|jSqWdS)Nz addr-spec)r7rm)rrrrrrms  zAngleAddr.local_partcCs"x|D]}|jdkr|jSqWdS)Nz addr-spec)r7rn)rrrrrrns  zAngleAddr.domaincCs"x|D]}|jdkr|jSqWdS)Nz obs-route)r7domains)rrrrrros  zAngleAddr.routecCs<x6|D]*}|jdkr|jr |jSt|j|jSqWdSdS)Nz addr-specz<>)r7rmrpr)rrrrrrps   zAngleAddr.addr_specN) r$r9r:r7r=rmrnrorprrrrrqs    rqc@seZdZdZeddZdS)ObsRoutez obs-routecCsdd|DS)NcSsg|]}|jdkr|jqS)rn)r7rn)rrrrrrCsz$ObsRoute.domains..r)rrrrrrszObsRoute.domainsN)r$r9r:r7r=rrrrrrrssrsc@sLeZdZdZeddZeddZeddZedd Zed d Z d S) MailboxrccCs|djdkr|djSdS)Nrz name-addr)r7rb)rrrrrbszMailbox.display_namecCs |djS)Nr)rm)rrrrrmszMailbox.local_partcCs |djS)Nr)rn)rrrrrnszMailbox.domaincCs|djdkr|djSdS)Nrz name-addr)r7ro)rrrrrosz Mailbox.routecCs |djS)Nr)rp)rrrrrpszMailbox.addr_specN) r$r9r:r7r=rbrmrnrorprrrrrts     rtc@s,eZdZdZeddZeZZZZ dS)InvalidMailboxzinvalid-mailboxcCsdS)Nr)rrrrrbszInvalidMailbox.display_nameN) r$r9r:r7r=rbrmrnrorprrrrrus rucs(eZdZdZdZefddZZS)DomainrnFcsdjtjjS)Nr)r!rrsplit)r)rrrrnsz Domain.domain)r$r9r:r7r)r=rnr>rr)rrrvsrvc@seZdZdZdS)DotAtomzdot-atomN)r$r9r:r7rrrrrxsrxc@seZdZdZdZdS) DotAtomTextz dot-atom-textTN)r$r9r:r7r)rrrrrysryc@sDeZdZdZdZeddZeddZeddZed d Z d S) AddrSpecz addr-specFcCs |djS)Nr)rm)rrrrrmszAddrSpec.local_partcCst|dkrdS|djS)Nrjrl)rkrn)rrrrrns zAddrSpec.domaincCs<t|dkr|djS|djj|dj|djjS)Nr{rrjrh)rkrrstriplstrip)rrrrrs  zAddrSpec.valuecCsLt|j}t|t|tkr*t|j}n|j}|jdk rH|d|jS|S)N@)setrmrk DOT_ATOM_ENDSrrn)rZnamesetZlprrrrps   zAddrSpec.addr_specN) r$r9r:r7r)r=rmrnrrprrrrrzs    rzc@seZdZdZdZdS) ObsLocalPartzobs-local-partFN)r$r9r:r7r)rrrrr srcs4eZdZdZdZeddZefddZZS) DisplayNamez display-nameFcCst|}|djdkr"|jdn*|ddjdkrLt|ddd|d<|djdkrd|jn*|ddjdkrt|ddd|d <|jS) NrrJrjrlrlrlrlrlrl)rr7popr)rrTrrrrb+s  zDisplayName.display_namecsd}|jrd}nx|D]}|jdkrd}qW|rd}}|djdksX|ddjdkr\d}|d jdks||d d jdkrd}|t|j|StjSdS) NFTz quoted-stringrrrJr@rjrlrlrl)rr7rrbrr)rrYrZpreZpost)rrrr:s    zDisplayName.value) r$r9r:r7r<r=rbrr>rr)rrr&s rc@s,eZdZdZdZeddZeddZdS) LocalPartz local-partFcCs&|djdkr|djS|djSdS)Nrz quoted-string)r7rUr)rrrrrSs zLocalPart.valuecCstg}t}d}x|dtgD]}|jdkr.q|r^|jdkr^|djdkr^t|dd|d<t|t}|r|jdkr|djdkr|jt|ddn |j||d }|}qWt|dd }|jS) NFrrJdotrjrlrlrlrlrl)DOTr7r isinstancerSr)rrTZlastZ last_is_tltokZis_tlrrrrmZs$   zLocalPart.local_partN)r$r9r:r7r)r=rrmrrrrrNs rcs4eZdZdZdZefddZeddZZS) DomainLiteralzdomain-literalFcsdjtjjS)Nr)r!rrrw)r)rrrrnwszDomainLiteral.domaincCs"x|D]}|jdkr|jSqWdS)Nptext)r7r)rrrrrip{s  zDomainLiteral.ip) r$r9r:r7r)r=rnrr>rr)rrrrsrc@seZdZdZdZdZdS) MIMEVersionz mime-versionN)r$r9r:r7majorminorrrrrrsrc@s4eZdZdZdZdZdZeddZeddZ dS) Parameter parameterFzus-asciicCs|jr|djSdS)Nrjr) sectionednumber)rrrrsection_numberszParameter.section_numbercCsbx\|D]T}|jdkr|jS|jdkrx4|D],}|jdkr*x|D]}|jdkr>|jSq>Wq*WqWdS)Nrz quoted-stringzbare-quoted-stringr)r7rV)rr.rrr param_values       zParameter.param_valueN) r$r9r:r7rextendedrPr=rrrrrrrs  rc@seZdZdZdS)InvalidParameterzinvalid-parameterN)r$r9r:r7rrrrrsrc@seZdZdZeddZdS) Attribute attributecCs$x|D]}|jjdr|jSqWdS)Nattrtext)r7endswithr)rr.rrrrVs  zAttribute.stripped_valueN)r$r9r:r7r=rVrrrrrsrc@seZdZdZdZdS)SectionsectionN)r$r9r:r7rrrrrrsrc@seZdZdZeddZdS)ValuercCs2|d}|jdkr|d}|jjdr,|jS|jS)NrrJrj quoted-stringrextended-attribute)rrr)r7rrVr)rr.rrrrVs zValue.stripped_valueN)r$r9r:r7r=rVrrrrrsrc@s(eZdZdZdZeddZddZdS)MimeParameterszmime-parametersFc cst}x\|D]T}|jjdsq |djdkr.q |djj}||krLg||<||j|j|fq Wx|jD]\}}t|t dd}|dd}|j }|j rt |dkr|dddkr|ddj jtjd|dd}g}d}x|D]\} } | |kr6| j s$| j jtjdqn| j jtjd|d7}| j} | j rytjj| } Wn&tk rtjj| d d } YnRXy| j|d } Wn"tk r| jd d } YnXtj| r| j jtj|j| qWd j|} || fVqpWdS)Nrrr)keyrjz.duplicate parameter name; duplicate(s) ignoredz+duplicate parameter name; duplicate ignoredz(inconsistent RFC2231 parameter numberingzlatin-1)encodingsurrogateescapezus-asciir)rr7rrstriprSritemssortedrrPrrkrrInvalidHeaderDefectrurllibparseZunquote_to_bytesUnicodeEncodeErrorZunquotedecode LookupErrorr_has_surrogatesUndecodableBytesDefectr!) rparamsr.namepartsZ first_paramrPZ value_partsirparamrrrrrsZ         zMimeParameters.paramscCsXg}x8|jD].\}}|r0|jdj|t|q |j|q Wdj|}|rTd|SdS)Nz{}={}z; r@r)rrSr#rr!)rrrrrrrr"s zMimeParameters.__str__N)r$r9r:r7r;r=rr"rrrrrs Frc@seZdZdZeddZdS)ParameterizedHeaderValueFcCs&x t|D]}|jdkr |jSq WiS)Nzmime-parameters)reversedr7r)rr.rrrr%s  zParameterizedHeaderValue.paramsN)r$r9r:r;r=rrrrrrsrc@seZdZdZdZdZdZdS) ContentTypez content-typeFtextZplainN)r$r9r:r7r)maintypesubtyperrrrr-src@seZdZdZdZdZdS)ContentDispositionzcontent-dispositionFN)r$r9r:r7r)content_dispositionrrrrr5src@seZdZdZdZdZdS)ContentTransferEncodingzcontent-transfer-encodingFZ7bitN)r$r9r:r7r)rOrrrrr<src@seZdZdZdZdS) HeaderLabelz header-labelFN)r$r9r:r7r)rrrrrCsrc@seZdZdZdS)HeaderheaderN)r$r9r:r7rrrrrIsrcsreZdZdZdZdZfddZfddZddZe dd Z dfd d Z d dZ e ddZ ddZZS)TerminalTcstj||}||_g|_|S)N)r__new__r7r)clsrr7r)rrrrXszTerminal.__new__csdj|jjtjS)Nz{}({}))r#rr$rr%)r)rrrr%^szTerminal.__repr__cCst|jjd|jdS)N/)r3rr$r7)rrrrr5aszTerminal.pprintcCs t|jS)N)listr)rrrrr&dszTerminal.all_defectsrcs2dj||jj|jtj|js"dn dj|jgS)Nz {}{}/{}({}){}rz {})r#rr$r7rr%r)rr2)rrrr6hs z Terminal._ppcCsdS)Nr)rrrrpop_trailing_wsqszTerminal.pop_trailing_wscCsgS)Nr)rrrrr-uszTerminal.commentscCst||jfS)N)rr7)rrrr__getnewargs__yszTerminal.__getnewargs__)r)r$r9r:r)r<r;rr%r5r=r&r6rr-rr>rr)rrrRs     rc@s eZdZeddZddZdS)WhiteSpaceTerminalcCsdS)Nr@r)rrrrrszWhiteSpaceTerminal.valuecCsdS)NTr)rrrrr(sz!WhiteSpaceTerminal.startswith_fwsN)r$r9r:r=rr(rrrrr}s rc@s eZdZeddZddZdS) ValueTerminalcCs|S)Nr)rrrrrszValueTerminal.valuecCsdS)NFr)rrrrr(szValueTerminal.startswith_fwsN)r$r9r:r=rr(rrrrrs rc@s eZdZeddZddZdS)EWWhiteSpaceTerminalcCsdS)Nrr)rrrrrszEWWhiteSpaceTerminal.valuecCsdS)Nrr)rrrrr"szEWWhiteSpaceTerminal.__str__N)r$r9r:r=rr"rrrrrs rr,zlist-separatorr~zroute-component-markerz([{}]+)rz[^{}]+rz\\]z\]z[\x00-\x20\x7F]cCs>t|}|r|jjtj|tj|r:|jjtjddS)Nz*Non-ASCII characters found in header token)_non_printable_finderrrSrZNonPrintableDefectrrr)xtextZnon_printablesrrr_validate_xtexts   rcCst|d^}}g}d}d}xbtt|D]J}||dkrL|rFd}d}nd}q(|rVd}n|||krdP|j||q(W|d}dj|dj||dg||fS)NrjFrTr) _wsp_splitterrangerkrSr!)rendcharsZfragment remainderZvcharsescapehad_qpposrrr_get_ptext_to_endcharss$   rcCs.|j}t|dt|t|d}||fS)Nfws)r}rrk)rZnewvaluerrrrget_fwssrc Cst}|jds tjdj||ddjdd^}}||ddkrXtjdj|dj|}t|dkr|dtkr|dtkr|jdd^}}|d|}t|jdkr|j j tj d||_ dj|}yt jd|d\}}}} Wn(tk rtjd j|j YnX||_||_|j j| xh|r|dtkrdt|\} }|j | q6t|d^} }t| d } t| |j | dj|}q6W||fS) Nz=?z"expected encoded word but found {}rhz?=rjrrzwhitespace inside encoded wordz!encoded word format invalid: '{}'vtext)rN startswithrHeaderParseErrorr#rwr!rkrrrSrrO_ewr ValueErrorrPrQr,WSPrrrr) rewrrZremstrrestrrPrQrr.charsrrrrget_encoded_wordsH    $        rc Cst}x|r |dtkr4t|\}}|j|q |jdryt|\}}Wntjk rdYnrXd}t|dkr|d j dkr|j jtj dd}|rt|dkr|d j d krt |dd|d<|j|q t |d^}}t|d }t||j|d j|}q W|S)Nrz=?Trjrz&missing whitespace before encoded wordFrhz encoded-wordrrrlrlrl)rDrrrSrrrrrkr7rrrrrrr!)rrEr.Zhave_wsrrrrrrget_unstructured!s:          rcCs*t|d\}}}t|d}t|||fS)Nz()r)rrr)rr_rrr get_qp_ctextYs  rcCs*t|d\}}}t|d}t|||fS)Nr r)rrr)rrrrrr get_qcontentjs  rcCsNt|}|stjdj||j}|t|d}t|d}t|||fS)Nzexpected atext but found '{}'atext)_non_atom_end_matcherrrr#rarkrr)rmrrrr get_atextys  rc Cs|ddkrtjdj|t}|dd}|ddkrPt|\}}|j|x|r|ddkr|dtkr|t|\}}nd|dddkry"t|\}}|j jtj dWqtjk rt|\}}YqXn t|\}}|j|qRW|s|j jtj d||fS||ddfS) Nrr zexpected '"' but found '{}'rjrhz=?z!encoded word inside quoted stringz"end of header inside quoted string) rrr#rWrrSrrrrr)rZbare_quoted_stringr.rrrget_bare_quoted_strings2            rcCs|r |ddkr tjdj|t}|dd}x^|r|ddkr|dtkr^t|\}}n&|ddkrxt|\}}n t|\}}|j|q4W|s|j jtj d||fS||ddfS)Nrrzexpected '(' but found '{}'rjrZzend of header inside comment) rrr#rXrr get_commentrrSrr)rrAr.rrrrs"      rcCsTt}xD|rJ|dtkrJ|dtkr2t|\}}n t|\}}|j|qW||fS)Nr)rI CFWS_LEADERrrrrS)rrJr.rrrget_cfwss  rcCspt}|r,|dtkr,t|\}}|j|t|\}}|j||rh|dtkrht|\}}|j|||fS)Nr)rRrrrSr)rZ quoted_stringr.rrrget_quoted_strings      rc Cst}|r,|dtkr,t|\}}|j||rL|dtkrLtjdj||jdryt |\}}Wqtjk rt |\}}YqXn t |\}}|j||r|dtkrt|\}}|j|||fS)Nrzexpected atom but found '{}'z=?) rKrrrS ATOM_ENDSrrr#rrr)rrLr.rrrget_atoms$        rcCst}| s|dtkr(tjdj|xP|rx|dtkrxt|\}}|j||r*|ddkr*|jt|dd}q*W|dtkrtjdjd|||fS)Nrz8expected atom at a start of dot-atom-text but found '{}'r rjz4expected atom at end of dot-atom-text but found '{}'rl)ryrrrr#rrSr)rZ dot_atom_textr.rrrget_dot_atom_texts     rc Cst}|dtkr(t|\}}|j||jdrhyt|\}}Wqttjk rdt|\}}YqtXn t|\}}|j||r|dtkrt|\}}|j|||fS)Nrz=?) rxrrrSrrrrr)rZdot_atomr.rrr get_dot_atoms        rcCs|dtkrt|\}}nd}|ddkr8t|\}}n*|dtkrVtjdj|n t|\}}|dk rx|g|dd<||fS)Nrr z1Expected 'atom' or 'quoted-string' but found '{}')rrrSPECIALSrrr#r)rleaderr.rrrget_word*s     rcCst}yt|\}}|j|Wn(tjk rH|jjtjdYnXx|r|dtkr|ddkr|jt|jjtj d|dd}qLyt|\}}WnDtjk r|dt krt |\}}|jjtj dnYnX|j|qLW||fS)Nzphrase does not start with wordrr zperiod in 'phrase'rjzcomment found without atom) rFrrSrrrr PHRASE_ENDSrObsoleteHeaderDefectrr)rrGr.rrr get_phraseIs.          rcCstt}d}|dtkr"t|\}}|s6tjdj|yt|\}}Wn^tjk ryt|\}}Wn6tjk r|ddkr|dtkrt }YnXYnX|dk r|g|dd<|j ||o|ddks|dtkr2t t ||\}}|j dkr|jj tjdn|jj tjd||d<y|jjdWn(tk rj|jj tjdYnX||fS) Nrz"expected local-part but found '{}'rzinvalid-obs-local-partzsB               r cCst}|dtkr(t|\}}|j|| s:|ddkrJtjdj||jtdd|dd}|ddkr|jtdd|jjtj d|dd}||fSyt |\}}Wnztjk r2y"t |\}}|jjtj d Wn(tjk rtjd j|YnX|j|t |\}}YnX|j||r`|ddkr`|dd}n|jjtj d |jtdd|r|dtkrt|\}}|j|||fS) Nrzangle-addr-endznull addr-spec in angle-addrz*obsolete route specification in angle-addrz.expected addr-spec or obs-route but found '{}'z"missing trailing '>' on angle-addr) rqrrrSrrr#rrrrr r)rZ angle_addrr.rrrget_angle_addrgsJ                r cCs<t}t|\}}|j|dd|jdd|_||fS)N)rrr,r)rrbr.rrrget_display_names  rcCst}d}|dtkr6t|\}}|s6tjdj||ddkr|dtkr^tjdj|t|\}}|s~tjdj||dk r|g|ddd<d}|j|t |\}}|dk r|g|dd<|j|||fS)Nrz!expected name-addr but found '{}'r ) rirrrrr#rrrSr )rZ name_addrrr.rrr get_name_addrs0           rcCst}yt|\}}WnNtjk rdyt|\}}Wn&tjk r^tjdj|YnXYnXtdd|jDrd|_|j |||fS)Nzexpected mailbox but found '{}'css|]}t|tjVqdS)N)rrr)rrrrrr szget_mailbox..zinvalid-mailbox) rtrrrrr#anyr&r7rS)rrcr.rrr get_mailboxs  rcCsht}xX|r^|d|kr^|dtkrF|jt|dd|dd}qt|\}}|j|qW||fS)Nrzmisplaced-specialrj)rurrSrr)rrZinvalid_mailboxr.rrrget_invalid_mailboxs   rc Cst}x|o|ddkryt|\}}|j|Wntjk r@d}|dtkrt|\}}| sz|ddkr|j||jjtjdn@t |d\}}|dk r|g|dd<|j||jjtj dnb|ddkr|jjtjdnBt |d\}}|dk r |g|dd<|j||jjtj dYnX|r|ddkr|d }d|_ t |d\}}|j ||jjtj d|r |ddkr |jt |dd}q W||fS) Nr;z,;zempty element in mailbox-listzinvalid mailbox in mailbox-listrrjzinvalid-mailboxrl)rdrrSrrrrrrrrr7r,r)rZ mailbox_listr.rrcrrrget_mailbox_listsN                   rcCst}|s$|jjtjd||fSd}|r|dtkrt|\}}|sl|jjtjd|j|||fS|ddkr|j|||fSt|\}}t|j dkr|dk r|j||j ||jjtj d||fS|dk r|g|dd<|j|||fS)Nzend of header before group-listrzend of header in group-listrzgroup-list with empty entries) rfrrSrrrrrrkr_r,r)rZ group_listrr.rrrget_group_list"s8           rcCs"t}t|\}}| s$|ddkr4tjdj||j||jtdd|dd}|r|ddkr|jtdd||ddfSt|\}}|j||s|jjtj dn|ddkrtjd j||jtdd|dd}|r|dt krt |\}}|j|||fS) Nrrz8expected ':' at end of group display name but found '{}'zgroup-display-name-terminatorrjrzgroup-terminatorzend of header in groupz)expected ';' at end of group but found {}) rgrrrr#rSrrrrrr)rrar.rrr get_groupGs2            rcCsxt}yt|\}}WnNtjk rdyt|\}}Wn&tjk r^tjdj|YnXYnX|j|||fS)Nzexpected address but found '{}')r`rrrrr#rS)rr\r.rrr get_addresses rcCst}x|ryt|\}}|j|Wn$tjk rP}zd}|dtkrt|\}}| sr|ddkr|j||jjtjdnFt |d\}}|dk r|g|dd<|jt |g|jjtj dnh|ddkr|jjtjdnHt |d\}}|dk r|g|dd<|jt |g|jjtj dWYdd}~XnX|r|ddkr|d d}d|_ t |d\}}|j ||jjtj d|r |jtdd|dd}q W||fS) Nrrz"address-list entry with no contentzinvalid address in address-listzempty element in address-listrjzinvalid-mailboxzlist-separatorrl)r[rrSrrrrrrrr`rr7r,r)rZ address_listr.errrrcrrrget_address_listsN                  rcCst}|s |jjtjd|S|dtkrXt|\}}|j||sX|jjtjdd}x8|r|ddkr|dtkr||d7}|dd}q^W|js|jjtjdj ||jt |dnt ||_ |jt |d |o|dtkr t|\}}|j|| s |ddkrX|j dk r>|jjtjd |rT|jt |d|S|jt dd |dd}|r|dtkrt|\}}|j||s|j dk r|jjtjd |Sd}x2|r|dtkr||d7}|dd}qW|js2|jjtjd j ||jt |dnt ||_ |jt |d |rv|dtkrvt|\}}|j||r|jjtjd |jt |d|S)Nz%Missing MIME version number (eg: 1.0)rz0Expected MIME version number but found only CFWSrr rjz1Expected MIME major version number but found {!r}rdigitsz0Incomplete MIME version; found only major numberzversion-separatorz1Expected MIME minor version number but found {!r}z'Excess non-CFWS text after MIME version)rrrSrHeaderMissingRequiredValuerrisdigitrr#rintrr)rZ mime_versionr.rrrrparse_mime_versionsv                        rcCsht}xX|r^|ddkr^|dtkrF|jt|dd|dd}qt|\}}|j|qW||fS)Nrrzmisplaced-specialrj)rrrSrr)rZinvalid_parameterr.rrrget_invalid_parameters   rcCsNt|}|stjdj||j}|t|d}t|d}t|||fS)Nzexpected ttext but found '{}'ttext)_non_token_end_matcherrrr#rarkrr)rrr rrr get_ttexts   r"cCst}|r,|dtkr,t|\}}|j||rL|dtkrLtjdj|t|\}}|j||r|dtkrt|\}}|j|||fS)Nrzexpected token but found '{}') rMrrrS TOKEN_ENDSrrr#r")rZmtokenr.rrr get_token)s        r$cCsNt|}|stjdj||j}|t|d}t|d}t|||fS)Nz expected attrtext but found {!r}r)_non_attribute_end_matcherrrr#rarkrr)rrrrrr get_attrtext@s   r&cCst}|r,|dtkr,t|\}}|j||rL|dtkrLtjdj|t|\}}|j||r|dtkrt|\}}|j|||fS)Nrzexpected token but found '{}') rrrrSATTRIBUTE_ENDSrrr#r&)rrr.rrr get_attributeSs        r(cCsNt|}|stjdj||j}|t|d}t|d}t|||fS)Nz)expected extended attrtext but found {!r}zextended-attrtext)#_non_extended_attribute_end_matcherrrr#rarkrr)rrrrrrget_extended_attrtextjs  r*cCst}|r,|dtkr,t|\}}|j||rL|dtkrLtjdj|t|\}}|j||r|dtkrt|\}}|j|||fS)Nrzexpected token but found '{}') rrrrSEXTENDED_ATTRIBUTE_ENDSrrr#r*)rrr.rrrget_extended_attribute|s       r,cCst}| s|ddkr(tjdj||jtdd|dd}| sX|dj rhtjdj|d}x,|r|djr||d7}|dd}qnW|ddkr|dkr|jjtjd t ||_ |jt|d ||fS) Nr*zExpected section but found {}zsection-markerrjz$Expected section number but found {}r0z'section number has an invalid leading 0r) rrrr#rSrrrZInvalidHeaderErrorrr)rrrrrr get_sections&     r/cCst}|stjdd}|dtkr0t|\}}|sDtjdj||ddkr^t|\}}n t|\}}|dk r|g|dd<|j|||fS)Nz&Expected value but found end of stringrz Expected value but found only {}r ) rrrrrr#rr,rS)rvrr.rrr get_values       r1c Csvt}t|\}}|j|| s.|ddkrN|jjtjdj|||fS|ddkry t|\}}d|_|j|Wntj k rYnX|stj d|ddkr|jt dd|dd}d|_ |dd krtj d |jt d d |dd}d}|r.|dt kr.t |\}}|j|d}|}|j rH|rH|dd krHt|\}}|j}d }|jdkr|r|ddkrd}n$t|\}} | r| ddkrd}n(yt|\}} Wn Yn X| sd}|r2|jjtjd|j|x,|D]$} | jdkrg| dd<| }PqW|}nd}|jjtjd|rb|ddkrbd}n t|\}}|j s|jdkr| s|ddkr|j||dk r|}||fS|jjtjd|s|jjtjd|j||dkr||fSn|dk rFx|D]} | jdkrPqW| jdk|j| | j|_|ddkrdtj dj||jt dd|dd}|r|ddkrt|\}}|j||j|_| s|ddkrtj dj||jt dd|dd}|dk rJt} x>|rB|dtkr(t|\}}n t|\}}| j|qW| }n t|\}}|j||dk rn|}||fS)Nrrz)Parameter contains name ({}) but no valuer-TzIncomplete parameterzextended-parameter-markerrj=zParameter not followed by '='zparameter-separatorr F'z5Quoted string value for extended parameter is invalidzbare-quoted-stringzZParameter marked as extended but appears to have a quoted string value that is non-encodedzcApparent initial-extended-value but attribute was not marked as extended or was not initial sectionz(Missing required charset/lang delimiterszextended-attrtextrz=Expected RFC2231 char/lang encoding delimiter, but found {!r}zRFC2231-delimiterz;Expected RFC2231 char/lang encoding delimiter, but found {})rr(rSrrrr#r/rrrrrrrrVrr&r*r7r1rrPrQrrrr) rrr.rrZappendtoZqstringZ inner_valueZ semi_validrtr0rrr get_parameters                                             r5cCsht}xZ|rbyt|\}}|j|Wntjk r}zd}|dtkrZt|\}}|sl|j||S|ddkr|dk r|j||jjtjdn@t |\}}|r|g|dd<|j||jjtjdj |WYdd}~XnX|r@|ddkr@|d }d|_ t |\}}|j ||jjtjdj ||r |jt dd|dd}q W|S) Nrrzparameter entry with no contentzinvalid parameter {!r}rjzinvalid-parameterz)parameter with invalid trailing text {!r}zparameter-separatorrl)rr5rSrrrrrrrr#r7r,r)rZmime_parametersr.rrrrrrparse_mime_parametersQ sD                 r6cCsxX|rX|ddkrX|dtkr@|jt|dd|dd}qt|\}}|j|qW|sbdS|jtdd|jt|dddS)Nrrzmisplaced-specialrjzparameter-separator)rrSrrr6)Z tokenlistrr.rrr_find_mime_parameters s  r7cCst}d}|s$|jjtjd|Syt|\}}Wn8tjk rl|jjtjdj|t |||SX|j|| s|ddkr|jjtjd|rt |||S|j j j |_ |jtdd|dd}yt|\}}Wn:tjk r$|jjtjd j|t |||SX|j||j j j |_|sJ|S|dd kr|jjtjd j||` |`t |||S|jtd d |jt|dd|S) NFz"Missing content type specificationz(Expected content maintype but found {!r}rrzInvalid content typezcontent-type-separatorrjz'Expected content subtype but found {!r}rz.z unknown-8bitTzmime-parameters)r/rrlrlrlrlrlrl)Zmax_line_lengthfloatutf8rrrrr7 SPECIALSNL isdisjointNLSETrrrr&_fold_mime_parametersr)r;r1lineseprkr=rSr8 _fold_as_ewr<r(insertr!)Z parse_treer/maxlenrr<last_ewr>Z want_encodingZend_ew_not_allowedrr*tstrrPZ encoded_partnewlineZnewpartsrrrr0" s                 r0cCs|dk r<|rFs           C  "   !($ V +            *8" &'/'&).9%>D 49/j7_header_value_parser.cpython-36.pyc000064400000224613147204636050013350 0ustar003 f@szdZddlZddlZddlmZddlmZddlmZddl m Z ddl m Z ddl m Z ed Zeed BZed ZeeBZeed Zeed ZeedBed ZeeBZeedBZeeBZeedZddhZeeBZddZGdddeZGdddeZGdddeZ GdddeZ!GdddeZ"Gdd d eZ#Gd!d"d"eZ$Gd#d$d$eZ%Gd%d&d&eZ&Gd'd(d(eZ'Gd)d*d*e'Z(Gd+d,d,eZ)Gd-d.d.eZ*Gd/d0d0eZ+Gd1d2d2eZ,Gd3d4d4eZ-Gd5d6d6eZ.Gd7d8d8eZ/Gd9d:d:eZ0Gd;d<dd>eZ2Gd?d@d@eZ3GdAdBdBeZ4GdCdDdDeZ5GdEdFdFeZ6GdGdHdHeZ7GdIdJdJeZ8GdKdLdLe!Z9GdMdNdNeZ:GdOdPdPeZ;GdQdRdReZGdWdXdXeZ?GdYdZdZeZ@Gd[d\d\eZAGd]d^d^eZBGd_d`d`eZCGdadbdbeCZDGdcddddeCZEGdedfdfeZFGdgdhdheZGGdidjdjeZHGdkdldleIZJGdmdndneJZKGdodpdpeJZLGdqdrdreKZMeLd dsZNeLdtduZOeLdvdwZPejQdxjRdyjSejTZUejQdzjRdyjSejVd{d|jVd}d~jWZXejQdjYZZejQdzjRdyjSejVd{d|jVd}d~jWZ[ejQdzjRdyjSejVd{d|jVd}d~jWZ\ejQdzjRdyjSejVd{d|jVd}d~jWZ]ddZ^ddZ_ddZ`ddZaddZbddZcddZdddZeddZfddZgddZhddZiddZjddZkddZlddZmddZnddZoddZpddZqddZrddZsddZtddZuddZvddZwddZxddZyddZzddZ{ddZ|ddZ}ddZ~ddÄZddńZddDŽZddɄZdd˄Zdd̈́ZddτZddфZddӄZddՄZddׄZddلZddۄZdd݄Zdd߄ZddZddZddZddZddZddZddZdS)alHeader value parser implementing various email-related RFC parsing rules. The parsing methods defined in this module implement various email related parsing rules. Principal among them is RFC 5322, which is the followon to RFC 2822 and primarily a clarification of the former. It also implements RFC 2047 encoded word decoding. RFC 5322 goes to considerable trouble to maintain backward compatibility with RFC 822 in the parse phase, while cleaning up the structure on the generation phase. This parser supports correct RFC 5322 generation by tagging white space as folding white space only when folding is allowed in the non-obsolete rule sets. Actually, the parser is even more generous when accepting input than RFC 5322 mandates, following the spirit of Postel's Law, which RFC 5322 encourages. Where possible deviations from the standard are annotated on the 'defects' attribute of tokens that deviate. The general structure of the parser follows RFC 5322, and uses its terminology where there is a direct correspondence. Where the implementation requires a somewhat different structure than that used by the formal grammar, new terms that mimic the closest existing terms are used. Thus, it really helps to have a copy of RFC 5322 handy when studying this code. Input to the parser is a string that has already been unfolded according to RFC 5322 rules. According to the RFC this unfolding is the very first step, and this parser leaves the unfolding step to a higher level message parser, which will have already detected the line breaks that need unfolding while determining the beginning and end of each header. The output of the parser is a TokenList object, which is a list subclass. A TokenList is a recursive data structure. The terminal nodes of the structure are Terminal objects, which are subclasses of str. These do not correspond directly to terminal objects in the formal grammar, but are instead more practical higher level combinations of true terminals. All TokenList and Terminal objects have a 'value' attribute, which produces the semantically meaningful value of that part of the parse subtree. The value of all whitespace tokens (no matter how many sub-tokens they may contain) is a single space, as per the RFC rules. This includes 'CFWS', which is herein included in the general class of whitespace tokens. There is one exception to the rule that whitespace tokens are collapsed into single spaces in values: in the value of a 'bare-quoted-string' (a quoted-string with no leading or trailing whitespace), any whitespace that appeared between the quotation marks is preserved in the returned value. Note that in all Terminal strings quoted pairs are turned into their unquoted values. All TokenList and Terminal objects also have a string value, which attempts to be a "canonical" representation of the RFC-compliant form of the substring that produced the parsed subtree, including minimal use of quoted pair quoting. Whitespace runs are not collapsed. Comment tokens also have a 'content' attribute providing the string found between the parens (including any nested comments) with whitespace preserved. All TokenList and Terminal objects have a 'defects' attribute which is a possibly empty list all of the defects found while creating the token. Defects may appear on any token in the tree, and a composite list of all defects in the subtree is available through the 'all_defects' attribute of any node. (For Terminal notes x.defects == x.all_defects.) Each object in a parse tree is called a 'token', and each has a 'token_type' attribute that gives the name from the RFC 5322 grammar that it represents. Not all RFC 5322 nodes are produced, and there is one non-RFC 5322 node that may be produced: 'ptext'. A 'ptext' is a string of printable ascii characters. It is returned in place of lists of (ctext/quoted-pair) and (qtext/quoted-pair). XXX: provide complete list of token types. N) hexdigits) OrderedDict) itemgetter)_encoded_words)errors)utilsz (z ()<>@,:;.\"[].z."(z/?=z*'%%  cCs dt|jddjdddS)N"\z\\z\")strreplace)valuer2/usr/lib64/python3.6/email/_header_value_parser.py quote_stringbsrcseZdZdZdZdZfddZddZfddZe d d Z e d d Z d dZ e ddZ e ddZddZdddZdddZdddZZS) TokenListNTcstj||g|_dS)N)super__init__defects)selfargskw) __class__rrroszTokenList.__init__cCsdjdd|DS)Ncss|]}t|VqdS)N)r).0xrrr tsz$TokenList.__str__..)join)rrrr__str__sszTokenList.__str__csdj|jjtjS)Nz{}({}))formatr__name__r__repr__)r)rrrr%vs zTokenList.__repr__cCsdjdd|DS)Nrcss|]}|jr|jVqdS)N)r)rrrrrr |sz"TokenList.value..)r!)rrrrrzszTokenList.valuecCstdd|D|jS)Ncss|] }|jVqdS)N) all_defects)rrrrrr sz(TokenList.all_defects..)sumr)rrrrr&~szTokenList.all_defectscCs |djS)Nr)startswith_fws)rrrrr(szTokenList.startswith_fwscCstdd|DS)zATrue if all top level tokens of this part may be RFC2047 encoded.css|] }|jVqdS)N) as_ew_allowed)rpartrrrr sz*TokenList.as_ew_allowed..)all)rrrrr)szTokenList.as_ew_allowedcCs"g}x|D]}|j|jq W|S)N)extendcomments)rr-tokenrrrr-s zTokenList.commentscCs t||dS)N)policy)_refold_parse_tree)rr/rrrfoldszTokenList.foldrcCst|j|ddS)N)indent)printppstr)rr2rrrpprintszTokenList.pprintcCsdj|j|dS)Nr )r2)r!_pp)rr2rrrr4szTokenList.ppstrccs~dj||jj|jVx<|D]4}t|ds<|dj|Vq|j|dEdHqW|jrhdj|j}nd}dj||VdS)Nz{}{}/{}(r6z* !! invalid element in token list: {!r}z z Defects: {}rz{}){})r#rr$ token_typehasattrr6r)rr2r.Zextrarrrr6s    z TokenList._pp)r)r)r)r$ __module__ __qualname__r7syntactic_breakew_combine_allowedrr"r%propertyrr&r(r)r-r1r5r4r6 __classcell__rr)rrris        rc@s$eZdZeddZeddZdS)WhiteSpaceTokenListcCsdS)N r)rrrrrszWhiteSpaceTokenList.valuecCsdd|DS)NcSsg|]}|jdkr|jqS)comment)r7content)rrrrr sz0WhiteSpaceTokenList.comments..r)rrrrr-szWhiteSpaceTokenList.commentsN)r$r9r:r=rr-rrrrr?s r?c@seZdZdZdS)UnstructuredTokenList unstructuredN)r$r9r:r7rrrrrDsrDc@seZdZdZdS)PhrasephraseN)r$r9r:r7rrrrrFsrFc@seZdZdZdS)WordZwordN)r$r9r:r7rrrrrHsrHc@seZdZdZdS)CFWSListcfwsN)r$r9r:r7rrrrrIsrIc@seZdZdZdS)AtomatomN)r$r9r:r7rrrrrKsrKc@seZdZdZdZdS)Tokenr.FN)r$r9r:r7Z encode_as_ewrrrrrMsrMc@seZdZdZdZdZdZdS) EncodedWordz encoded-wordN)r$r9r:r7ctecharsetlangrrrrrNsrNc@s4eZdZdZeddZeddZeddZdS) QuotedStringz quoted-stringcCs"x|D]}|jdkr|jSqWdS)Nzbare-quoted-string)r7r)rrrrrrBs  zQuotedString.contentcCsBg}x2|D]*}|jdkr(|jt|q |j|jq Wdj|S)Nzbare-quoted-stringr)r7appendrrr!)rresrrrr quoted_values   zQuotedString.quoted_valuecCs"x|D]}|jdkr|jSqWdS)Nzbare-quoted-string)r7r)rr.rrrstripped_values  zQuotedString.stripped_valueN)r$r9r:r7r=rBrUrVrrrrrRs  rRc@s$eZdZdZddZeddZdS)BareQuotedStringzbare-quoted-stringcCstdjdd|DS)Nrcss|]}t|VqdS)N)r)rrrrrr sz+BareQuotedString.__str__..)rr!)rrrrr"szBareQuotedString.__str__cCsdjdd|DS)Nrcss|]}t|VqdS)N)r)rrrrrr sz)BareQuotedString.value..)r!)rrrrrszBareQuotedString.valueN)r$r9r:r7r"r=rrrrrrWsrWc@s8eZdZdZddZddZeddZedd Zd S) CommentrAcs(djtdgfddDdgggS)Nrrcsg|]}j|qSr)quote)rr)rrrrC sz#Comment.__str__..))r!r')rr)rrr"s zComment.__str__cCs2|jdkrt|St|jddjddjddS)NrArz\\rz\(rZz\))r7rr)rrrrrrYs  z Comment.quotecCsdjdd|DS)Nrcss|]}t|VqdS)N)r)rrrrrr sz"Comment.content..)r!)rrrrrBszComment.contentcCs|jgS)N)rB)rrrrr-szComment.commentsN) r$r9r:r7r"rYr=rBr-rrrrrXs  rXc@s4eZdZdZeddZeddZeddZdS) AddressListz address-listcCsdd|DS)NcSsg|]}|jdkr|qS)address)r7)rrrrrrC$sz)AddressList.addresses..r)rrrr addresses"szAddressList.addressescCstdd|DgS)Ncss|]}|jdkr|jVqdS)r\N)r7 mailboxes)rrrrrr (sz(AddressList.mailboxes..)r')rrrrr^&szAddressList.mailboxescCstdd|DgS)Ncss|]}|jdkr|jVqdS)r\N)r7 all_mailboxes)rrrrrr -sz,AddressList.all_mailboxes..)r')rrrrr_+szAddressList.all_mailboxesN)r$r9r:r7r=r]r^r_rrrrr[s  r[c@s4eZdZdZeddZeddZeddZdS) Addressr\cCs|djdkr|djSdS)Nrgroup)r7 display_name)rrrrrb5szAddress.display_namecCs4|djdkr|dgS|djdkr*gS|djS)Nrmailboxzinvalid-mailbox)r7r^)rrrrr^:s  zAddress.mailboxescCs:|djdkr|dgS|djdkr0|dgS|djS)Nrrczinvalid-mailbox)r7r_)rrrrr_Bs   zAddress.all_mailboxesN)r$r9r:r7r=rbr^r_rrrrr`1s  r`c@s(eZdZdZeddZeddZdS) MailboxListz mailbox-listcCsdd|DS)NcSsg|]}|jdkr|qS)rc)r7)rrrrrrCPsz)MailboxList.mailboxes..r)rrrrr^NszMailboxList.mailboxescCsdd|DS)NcSsg|]}|jdkr|qS)rcinvalid-mailbox)rcre)r7)rrrrrrCTsz-MailboxList.all_mailboxes..r)rrrrr_RszMailboxList.all_mailboxesN)r$r9r:r7r=r^r_rrrrrdJs rdc@s(eZdZdZeddZeddZdS) GroupListz group-listcCs"| s|djdkrgS|djS)Nrz mailbox-list)r7r^)rrrrr^\szGroupList.mailboxescCs"| s|djdkrgS|djS)Nrz mailbox-list)r7r_)rrrrr_bszGroupList.all_mailboxesN)r$r9r:r7r=r^r_rrrrrfXs rfc@s4eZdZdZeddZeddZeddZdS) GroupracCs|djdkrgS|djS)Nz group-list)r7r^)rrrrr^mszGroup.mailboxescCs|djdkrgS|djS)Nrhz group-list)r7r_)rrrrr_sszGroup.all_mailboxescCs |djS)Nr)rb)rrrrrbyszGroup.display_nameN)r$r9r:r7r=r^r_rbrrrrrgis  rgc@sLeZdZdZeddZeddZeddZedd Zed d Z d S) NameAddrz name-addrcCst|dkrdS|djS)Nr)lenrb)rrrrrbs zNameAddr.display_namecCs |djS)Nrj) local_part)rrrrrmszNameAddr.local_partcCs |djS)Nrjrl)domain)rrrrrnszNameAddr.domaincCs |djS)Nrjrl)route)rrrrroszNameAddr.routecCs |djS)Nrjrl) addr_spec)rrrrrpszNameAddr.addr_specN) r$r9r:r7r=rbrmrnrorprrrrri~s     ric@s@eZdZdZeddZeddZeddZedd Zd S) AngleAddrz angle-addrcCs"x|D]}|jdkr|jSqWdS)Nz addr-spec)r7rm)rrrrrrms  zAngleAddr.local_partcCs"x|D]}|jdkr|jSqWdS)Nz addr-spec)r7rn)rrrrrrns  zAngleAddr.domaincCs"x|D]}|jdkr|jSqWdS)Nz obs-route)r7domains)rrrrrros  zAngleAddr.routecCs<x6|D]*}|jdkr|jr |jSt|j|jSqWdSdS)Nz addr-specz<>)r7rmrpr)rrrrrrps   zAngleAddr.addr_specN) r$r9r:r7r=rmrnrorprrrrrqs    rqc@seZdZdZeddZdS)ObsRoutez obs-routecCsdd|DS)NcSsg|]}|jdkr|jqS)rn)r7rn)rrrrrrCsz$ObsRoute.domains..r)rrrrrrszObsRoute.domainsN)r$r9r:r7r=rrrrrrrssrsc@sLeZdZdZeddZeddZeddZedd Zed d Z d S) MailboxrccCs|djdkr|djSdS)Nrz name-addr)r7rb)rrrrrbszMailbox.display_namecCs |djS)Nr)rm)rrrrrmszMailbox.local_partcCs |djS)Nr)rn)rrrrrnszMailbox.domaincCs|djdkr|djSdS)Nrz name-addr)r7ro)rrrrrosz Mailbox.routecCs |djS)Nr)rp)rrrrrpszMailbox.addr_specN) r$r9r:r7r=rbrmrnrorprrrrrts     rtc@s,eZdZdZeddZeZZZZ dS)InvalidMailboxzinvalid-mailboxcCsdS)Nr)rrrrrbszInvalidMailbox.display_nameN) r$r9r:r7r=rbrmrnrorprrrrrus rucs(eZdZdZdZefddZZS)DomainrnFcsdjtjjS)Nr)r!rrsplit)r)rrrrnsz Domain.domain)r$r9r:r7r)r=rnr>rr)rrrvsrvc@seZdZdZdS)DotAtomzdot-atomN)r$r9r:r7rrrrrxsrxc@seZdZdZdZdS) DotAtomTextz dot-atom-textTN)r$r9r:r7r)rrrrrysryc@sDeZdZdZdZeddZeddZeddZed d Z d S) AddrSpecz addr-specFcCs |djS)Nr)rm)rrrrrmszAddrSpec.local_partcCst|dkrdS|djS)Nrjrl)rkrn)rrrrrns zAddrSpec.domaincCs<t|dkr|djS|djj|dj|djjS)Nr{rrjrh)rkrrstriplstrip)rrrrrs  zAddrSpec.valuecCsLt|j}t|t|tkr*t|j}n|j}|jdk rH|d|jS|S)N@)setrmrk DOT_ATOM_ENDSrrn)rZnamesetZlprrrrps   zAddrSpec.addr_specN) r$r9r:r7r)r=rmrnrrprrrrrzs    rzc@seZdZdZdZdS) ObsLocalPartzobs-local-partFN)r$r9r:r7r)rrrrr srcs4eZdZdZdZeddZefddZZS) DisplayNamez display-nameFcCst|}|djdkr"|jdn*|ddjdkrLt|ddd|d<|djdkrd|jn*|ddjdkrt|ddd|d <|jS) NrrJrjrlrlrlrlrlrl)rr7popr)rrTrrrrb+s  zDisplayName.display_namecsd}|jrd}nx|D]}|jdkrd}qW|rd}}|djdksX|ddjdkr\d}|d jdks||d d jdkrd}|t|j|StjSdS) NFTz quoted-stringrrrJr@rjrlrlrl)rr7rrbrr)rrYrZpreZpost)rrrr:s    zDisplayName.value) r$r9r:r7r<r=rbrr>rr)rrr&s rc@s,eZdZdZdZeddZeddZdS) LocalPartz local-partFcCs&|djdkr|djS|djSdS)Nrz quoted-string)r7rUr)rrrrrSs zLocalPart.valuecCstg}t}d}x|dtgD]}|jdkr.q|r^|jdkr^|djdkr^t|dd|d<t|t}|r|jdkr|djdkr|jt|ddn |j||d }|}qWt|dd }|jS) NFrrJdotrjrlrlrlrlrl)DOTr7r isinstancerSr)rrTZlastZ last_is_tltokZis_tlrrrrmZs$   zLocalPart.local_partN)r$r9r:r7r)r=rrmrrrrrNs rcs4eZdZdZdZefddZeddZZS) DomainLiteralzdomain-literalFcsdjtjjS)Nr)r!rrrw)r)rrrrnwszDomainLiteral.domaincCs"x|D]}|jdkr|jSqWdS)Nptext)r7r)rrrrrip{s  zDomainLiteral.ip) r$r9r:r7r)r=rnrr>rr)rrrrsrc@seZdZdZdZdZdS) MIMEVersionz mime-versionN)r$r9r:r7majorminorrrrrrsrc@s4eZdZdZdZdZdZeddZeddZ dS) Parameter parameterFzus-asciicCs|jr|djSdS)Nrjr) sectionednumber)rrrrsection_numberszParameter.section_numbercCsbx\|D]T}|jdkr|jS|jdkrx4|D],}|jdkr*x|D]}|jdkr>|jSq>Wq*WqWdS)Nrz quoted-stringzbare-quoted-stringr)r7rV)rr.rrr param_values       zParameter.param_valueN) r$r9r:r7rextendedrPr=rrrrrrrs  rc@seZdZdZdS)InvalidParameterzinvalid-parameterN)r$r9r:r7rrrrrsrc@seZdZdZeddZdS) Attribute attributecCs$x|D]}|jjdr|jSqWdS)Nattrtext)r7endswithr)rr.rrrrVs  zAttribute.stripped_valueN)r$r9r:r7r=rVrrrrrsrc@seZdZdZdZdS)SectionsectionN)r$r9r:r7rrrrrrsrc@seZdZdZeddZdS)ValuercCs2|d}|jdkr|d}|jjdr,|jS|jS)NrrJrj quoted-stringrextended-attribute)rrr)r7rrVr)rr.rrrrVs zValue.stripped_valueN)r$r9r:r7r=rVrrrrrsrc@s(eZdZdZdZeddZddZdS)MimeParameterszmime-parametersFc cst}x\|D]T}|jjdsq |djdkr.q |djj}||krLg||<||j|j|fq Wx|jD]\}}t|t dd}|dd}|j }|j rt |dkr|dddkr|ddj jtjd|dd}g}d}x|D]\} } | |kr6| j s$| j jtjdqn| j jtjd|d7}| j} | j rytjj| } Wn&tk rtjj| d d } YnRXy| j|d } Wn"tk r| jd d } YnXtj| r| j jtj|j| qWd j|} || fVqpWdS)Nrrr)keyrjz.duplicate parameter name; duplicate(s) ignoredz+duplicate parameter name; duplicate ignoredz(inconsistent RFC2231 parameter numberingzlatin-1)encodingsurrogateescapezus-asciir)rr7rrstriprSritemssortedrrPrrkrrInvalidHeaderDefectrurllibparseZunquote_to_bytesUnicodeEncodeErrorZunquotedecode LookupErrorr_has_surrogatesUndecodableBytesDefectr!) rparamsr.namepartsZ first_paramrPZ value_partsirparamrrrrrsZ         zMimeParameters.paramscCsXg}x8|jD].\}}|r0|jdj|t|q |j|q Wdj|}|rTd|SdS)Nz{}={}z; r@r)rrSr#rr!)rrrrrrrr"s zMimeParameters.__str__N)r$r9r:r7r;r=rr"rrrrrs Frc@seZdZdZeddZdS)ParameterizedHeaderValueFcCs&x t|D]}|jdkr |jSq WiS)Nzmime-parameters)reversedr7r)rr.rrrr%s  zParameterizedHeaderValue.paramsN)r$r9r:r;r=rrrrrrsrc@seZdZdZdZdZdZdS) ContentTypez content-typeFtextZplainN)r$r9r:r7r)maintypesubtyperrrrr-src@seZdZdZdZdZdS)ContentDispositionzcontent-dispositionFN)r$r9r:r7r)content_dispositionrrrrr5src@seZdZdZdZdZdS)ContentTransferEncodingzcontent-transfer-encodingFZ7bitN)r$r9r:r7r)rOrrrrr<src@seZdZdZdZdS) HeaderLabelz header-labelFN)r$r9r:r7r)rrrrrCsrc@seZdZdZdS)HeaderheaderN)r$r9r:r7rrrrrIsrcsreZdZdZdZdZfddZfddZddZe dd Z dfd d Z d dZ e ddZ ddZZS)TerminalTcstj||}||_g|_|S)N)r__new__r7r)clsrr7r)rrrrXszTerminal.__new__csdj|jjtjS)Nz{}({}))r#rr$rr%)r)rrrr%^szTerminal.__repr__cCst|jjd|jdS)N/)r3rr$r7)rrrrr5aszTerminal.pprintcCs t|jS)N)listr)rrrrr&dszTerminal.all_defectsrcs2dj||jj|jtj|js"dn dj|jgS)Nz {}{}/{}({}){}rz {})r#rr$r7rr%r)rr2)rrrr6hs z Terminal._ppcCsdS)Nr)rrrrpop_trailing_wsqszTerminal.pop_trailing_wscCsgS)Nr)rrrrr-uszTerminal.commentscCst||jfS)N)rr7)rrrr__getnewargs__yszTerminal.__getnewargs__)r)r$r9r:r)r<r;rr%r5r=r&r6rr-rr>rr)rrrRs     rc@s eZdZeddZddZdS)WhiteSpaceTerminalcCsdS)Nr@r)rrrrrszWhiteSpaceTerminal.valuecCsdS)NTr)rrrrr(sz!WhiteSpaceTerminal.startswith_fwsN)r$r9r:r=rr(rrrrr}s rc@s eZdZeddZddZdS) ValueTerminalcCs|S)Nr)rrrrrszValueTerminal.valuecCsdS)NFr)rrrrr(szValueTerminal.startswith_fwsN)r$r9r:r=rr(rrrrrs rc@s eZdZeddZddZdS)EWWhiteSpaceTerminalcCsdS)Nrr)rrrrrszEWWhiteSpaceTerminal.valuecCsdS)Nrr)rrrrr"szEWWhiteSpaceTerminal.__str__N)r$r9r:r=rr"rrrrrs rr,zlist-separatorr~zroute-component-markerz([{}]+)rz[^{}]+rz\\]z\]z[\x00-\x20\x7F]cCs>t|}|r|jjtj|tj|r:|jjtjddS)z@If input token contains ASCII non-printables, register a defect.z*Non-ASCII characters found in header tokenN)_non_printable_finderrrSrZNonPrintableDefectrrr)xtextZnon_printablesrrr_validate_xtexts   rcCst|d^}}g}d}d}xbtt|D]J}||dkrL|rFd}d}nd}q(|rVd}n|||krdP|j||q(W|d}dj|dj||dg||fS)akScan printables/quoted-pairs until endchars and return unquoted ptext. This function turns a run of qcontent, ccontent-without-comments, or dtext-with-quoted-printables into a single string by unquoting any quoted printables. It returns the string, the remaining value, and a flag that is True iff there were any quoted printables decoded. rjFrTrN) _wsp_splitterrangerkrSr!)rendcharsZfragment remainderZvcharsescapehad_qpposrrr_get_ptext_to_endcharss$   rcCs.|j}t|dt|t|d}||fS)zFWS = 1*WSP This isn't the RFC definition. We're using fws to represent tokens where folding can be done, but when we are parsing the *un*folding has already been done so we don't need to watch out for CRLF. Nfws)r}rrk)rZnewvaluerrrrget_fwssrc Cst}|jds tjdj||ddjdd^}}||ddkrXtjdj|dj|}t|dkr|dtkr|dtkr|jdd^}}|d|}t|jdkr|j j tj d ||_ dj|}yt jd|d\}}}} Wn(tk rtjd j|j YnX||_||_|j j| xh|r|dtkrdt|\} }|j | q6t|d^} }t| d } t| |j | dj|}q6W||fS) zE encoded-word = "=?" charset "?" encoding "?" encoded-text "?=" z=?z"expected encoded word but found {}rhNz?=rjrrzwhitespace inside encoded wordz!encoded word format invalid: '{}'vtext)rN startswithrHeaderParseErrorr#rwr!rkrrrSrrO_ewr ValueErrorrPrQr,WSPrrrr) rewrrZremstrrestrrPrQrr.charsrrrrget_encoded_wordsH    $        rc Cst}x|r |dtkr4t|\}}|j|q |jdryt|\}}Wntjk rdYnrXd}t|dkr|d j dkr|j jtj dd}|rt|dkr|d j d krt |dd|d<|j|q t |d^}}t|d }t||j|d j|}q W|S)aOunstructured = (*([FWS] vchar) *WSP) / obs-unstruct obs-unstruct = *((*LF *CR *(obs-utext) *LF *CR)) / FWS) obs-utext = %d0 / obs-NO-WS-CTL / LF / CR obs-NO-WS-CTL is control characters except WSP/CR/LF. So, basically, we have printable runs, plus control characters or nulls in the obsolete syntax, separated by whitespace. Since RFC 2047 uses the obsolete syntax in its specification, but requires whitespace on either side of the encoded words, I can see no reason to need to separate the non-printable-non-whitespace from the printable runs if they occur, so we parse this into xtext tokens separated by WSP tokens. Because an 'unstructured' value must by definition constitute the entire value, this 'get' routine does not return a remaining value, only the parsed TokenList. rz=?Trjrz&missing whitespace before encoded wordFrhz encoded-wordrrrlrlrl)rDrrrSrrrrrkr7rrrrrrr!)rrEr.Zhave_wsrrrrrrget_unstructured!s:          rcCs*t|d\}}}t|d}t|||fS)actext = This is not the RFC ctext, since we are handling nested comments in comment and unquoting quoted-pairs here. We allow anything except the '()' characters, but if we find any ASCII other than the RFC defined printable ASCII, a NonPrintableDefect is added to the token's defects list. Since quoted pairs are converted to their unquoted values, what is returned is a 'ptext' token. In this case it is a WhiteSpaceTerminal, so it's value is ' '. z()r)rrr)rr_rrr get_qp_ctextYs  rcCs*t|d\}}}t|d}t|||fS)aoqcontent = qtext / quoted-pair We allow anything except the DQUOTE character, but if we find any ASCII other than the RFC defined printable ASCII, a NonPrintableDefect is added to the token's defects list. Any quoted pairs are converted to their unquoted values, so what is returned is a 'ptext' token. In this case it is a ValueTerminal. r r)rrr)rrrrrr get_qcontentjs  rcCsNt|}|stjdj||j}|t|d}t|d}t|||fS)zatext = We allow any non-ATOM_ENDS in atext, but add an InvalidATextDefect to the token's defects list if we find non-atext characters. zexpected atext but found '{}'Natext)_non_atom_end_matcherrrr#rarkrr)rmrrrr get_atextys  rc Cs|ddkrtjdj|t}|dd}|ddkrPt|\}}|j|x|r|ddkr|dtkr|t|\}}nd|dddkry"t|\}}|j jtj dWqtjk rt|\}}YqXn t|\}}|j|qRW|s|j jtj d ||fS||ddfS) zbare-quoted-string = DQUOTE *([FWS] qcontent) [FWS] DQUOTE A quoted-string without the leading or trailing white space. Its value is the text between the quote marks, with whitespace preserved and quoted pairs decoded. rr zexpected '"' but found '{}'rjNrhz=?z!encoded word inside quoted stringz"end of header inside quoted string) rrr#rWrrSrrrrr)rZbare_quoted_stringr.rrrget_bare_quoted_strings2            rcCs|r |ddkr tjdj|t}|dd}x^|r|ddkr|dtkr^t|\}}n&|ddkrxt|\}}n t|\}}|j|q4W|s|j jtj d||fS||ddfS)zcomment = "(" *([FWS] ccontent) [FWS] ")" ccontent = ctext / quoted-pair / comment We handle nested comments here, and quoted-pair in our qp-ctext routine. rrzexpected '(' but found '{}'rjNrZzend of header inside comment) rrr#rXrr get_commentrrSrr)rrAr.rrrrs"      rcCsTt}xD|rJ|dtkrJ|dtkr2t|\}}n t|\}}|j|qW||fS)z,CFWS = (1*([FWS] comment) [FWS]) / FWS r)rI CFWS_LEADERrrrrS)rrJr.rrrget_cfwss  rcCspt}|r,|dtkr,t|\}}|j|t|\}}|j||rh|dtkrht|\}}|j|||fS)zquoted-string = [CFWS] [CFWS] 'bare-quoted-string' is an intermediate class defined by this parser and not by the RFC grammar. It is the quoted string without any attached CFWS. r)rRrrrSr)rZ quoted_stringr.rrrget_quoted_strings      rc Cst}|r,|dtkr,t|\}}|j||rL|dtkrLtjdj||jdryt |\}}Wqtjk rt |\}}YqXn t |\}}|j||r|dtkrt|\}}|j|||fS)zPatom = [CFWS] 1*atext [CFWS] An atom could be an rfc2047 encoded word. rzexpected atom but found '{}'z=?) rKrrrS ATOM_ENDSrrr#rrr)rrLr.rrrget_atoms$        rcCst}| s|dtkr(tjdj|xP|rx|dtkrxt|\}}|j||r*|ddkr*|jt|dd}q*W|dtkrtjdjd|||fS)z( dot-text = 1*atext *("." 1*atext) rz8expected atom at a start of dot-atom-text but found '{}'r rjNz4expected atom at end of dot-atom-text but found '{}'rl)ryrrrr#rrSr)rZ dot_atom_textr.rrrget_dot_atom_texts     rc Cst}|dtkr(t|\}}|j||jdrhyt|\}}Wqttjk rdt|\}}YqtXn t|\}}|j||r|dtkrt|\}}|j|||fS)z dot-atom = [CFWS] dot-atom-text [CFWS] Any place we can have a dot atom, we could instead have an rfc2047 encoded word. rz=?) rxrrrSrrrrr)rZdot_atomr.rrr get_dot_atoms        rcCs|dtkrt|\}}nd}|ddkr8t|\}}n*|dtkrVtjdj|n t|\}}|dk rx|g|dd<||fS)aword = atom / quoted-string Either atom or quoted-string may start with CFWS. We have to peel off this CFWS first to determine which type of word to parse. Afterward we splice the leading CFWS, if any, into the parsed sub-token. If neither an atom or a quoted-string is found before the next special, a HeaderParseError is raised. The token returned is either an Atom or a QuotedString, as appropriate. This means the 'word' level of the formal grammar is not represented in the parse tree; this is because having that extra layer when manipulating the parse tree is more confusing than it is helpful. rNr z1Expected 'atom' or 'quoted-string' but found '{}')rrrSPECIALSrrr#r)rleaderr.rrrget_word*s     rcCst}yt|\}}|j|Wn(tjk rH|jjtjdYnXx|r|dtkr|ddkr|jt|jjtj d|dd}qLyt|\}}WnDtjk r|dt krt |\}}|jjtj dnYnX|j|qLW||fS)a phrase = 1*word / obs-phrase obs-phrase = word *(word / "." / CFWS) This means a phrase can be a sequence of words, periods, and CFWS in any order as long as it starts with at least one word. If anything other than words is detected, an ObsoleteHeaderDefect is added to the token's defect list. We also accept a phrase that starts with CFWS followed by a dot; this is registered as an InvalidHeaderDefect, since it is not supported by even the obsolete grammar. zphrase does not start with wordrr zperiod in 'phrase'rjNzcomment found without atom) rFrrSrrrr PHRASE_ENDSrObsoleteHeaderDefectrr)rrGr.rrr get_phraseIs.          rcCstt}d}|dtkr"t|\}}|s6tjdj|yt|\}}Wn^tjk ryt|\}}Wn6tjk r|ddkr|dtkrt }YnXYnX|dk r|g|dd<|j ||o|ddks|dtkr2t t ||\}}|j dkr|jj tjdn|jj tjd||d<y|jjdWn(tk rj|jj tjd YnX||fS) z= local-part = dot-atom / quoted-string / obs-local-part Nrz"expected local-part but found '{}'rzinvalid-obs-local-partz / obs-dtext obs-dtext = obs-NO-WS-CTL / quoted-pair We allow anything except the excluded characters, but if we find any ASCII other than the RFC defined printable ASCII, a NonPrintableDefect is added to the token's defects list. Quoted pairs are converted to their unquoted values, so what is returned is a ptext token, in this case a ValueTerminal. If there were quoted-printables, an ObsoleteHeaderDefect is added to the returned token's defect list. z[]rz(quoted printable found in domain-literal)rrrrSrrr)rrrrrr get_dtexts   rcCs,|rdS|jtjd|jtdddS)NFz"end of input inside domain-literalrzdomain-literal-endT)rSrrr)rdomain_literalrrr_check_for_early_dl_ends rcCslt}|dtkr(t|\}}|j||s6tjd|ddkrRtjdj||dd}t||rp||fS|jtdd|dt krt |\}}|j|t |\}}|j|t||r||fS|dt krt |\}}|j|t||r||fS|ddkrtjd j||jtdd |dd}|rd|dtkrdt|\}}|j|||fS) zB domain-literal = [CFWS] "[" *([FWS] dtext) [FWS] "]" [CFWS] rzexpected domain-literal[z6expected '[' at start of domain-literal but found '{}'rjNzdomain-literal-startrz4expected ']' at end of domain-literal but found '{}'zdomain-literal-end) rrrrSrrr#rrrrr)rrr.rrrget_domain_literalsD                    rc Cstt}d}|dtkr"t|\}}|s6tjdj||ddkrvt|\}}|dk rd|g|dd<|j|||fSyt|\}}Wn"tjk rt |\}}YnX|r|ddkrtjd|dk r|g|dd<|j||o|ddkrl|j jtj d|dj d kr(|d|dd<xB|rj|ddkrj|jt t |d d\}}|j|q*W||fS) z] domain = dot-atom / domain-literal / obs-domain obs-domain = atom *("." atom)) Nrzexpected domain but found '{}'rr~zInvalid Domainr z(domain is not a dot-atom (contains CFWS)zdot-atomrj)rvrrrrr#rrSrrrrr7r)rrnrr.rrr get_domains@          rcCs~t}t|\}}|j|| s.|ddkrH|jjtjd||fS|jtddt|dd\}}|j|||fS)z( addr-spec = local-part "@" domain rr~z"add-spec local part with no domainzaddress-at-symbolrjN)rzrrSrrrrr)rrpr.rrr get_addr_spec.s    rcCst}xf|rl|ddks$|dtkrl|dtkrHt|\}}|j|q|ddkr|jt|dd}qW| s|ddkrtjdj||jtt |dd\}}|j|x|o|ddkrB|jt|dd}|sP|dtkr t|\}}|j||ddkr|jtt |dd\}}|j|qW|sTtjd|ddkrrtjd j||jt dd ||ddfS) z obs-route = obs-domain-list ":" obs-domain-list = *(CFWS / ",") "@" domain *("," [CFWS] ["@" domain]) Returns an obs-route token with the appropriate sub-tokens (that is, there is no obs-domain-list in the parse tree). rrrjNr~z(expected obs-route domain but found '{}'z%end of header while parsing obs-route:z4expected ':' marking end of obs-route but found '{}'zend-of-obs-route-marker) rsrrrS ListSeparatorrrr#RouteComponentMarkerrr)rZ obs_router.rrr get_obs_route>sB               r cCst}|dtkr(t|\}}|j|| s:|ddkrJtjdj||jtdd|dd}|ddkr|jtdd|jjtj d |dd}||fSyt |\}}Wnztjk r2y"t |\}}|jjtj d Wn(tjk rtjd j|YnX|j|t |\}}YnX|j||r`|ddkr`|dd}n|jjtj d |jtdd|r|dtkrt|\}}|j|||fS) z angle-addr = [CFWS] "<" addr-spec ">" [CFWS] / obs-angle-addr obs-angle-addr = [CFWS] "<" obs-route addr-spec ">" [CFWS] rzangle-addr-endznull addr-spec in angle-addrz*obsolete route specification in angle-addrz.expected addr-spec or obs-route but found '{}'z"missing trailing '>' on angle-addr) rqrrrSrrr#rrrrr r)rZ angle_addrr.rrrget_angle_addrgsJ                r cCs<t}t|\}}|j|dd|jdd|_||fS)z display-name = phrase Because this is simply a name-rule, we don't return a display-name token containing a phrase, but rather a display-name token with the content of the phrase. N)rrr,r)rrbr.rrrget_display_names  rcCst}d}|dtkr6t|\}}|s6tjdj||ddkr|dtkr^tjdj|t|\}}|s~tjdj||dk r|g|ddd<d}|j|t |\}}|dk r|g|dd<|j|||fS)z, name-addr = [display-name] angle-addr Nrz!expected name-addr but found '{}'r ) rirrrrr#rrrSr )rZ name_addrrr.rrr get_name_addrs0           rcCst}yt|\}}WnNtjk rdyt|\}}Wn&tjk r^tjdj|YnXYnXtdd|jDrd|_|j |||fS)z& mailbox = name-addr / addr-spec zexpected mailbox but found '{}'css|]}t|tjVqdS)N)rrr)rrrrrr szget_mailbox..zinvalid-mailbox) rtrrrrr#anyr&r7rS)rrcr.rrr get_mailboxs  rcCsht}xX|r^|d|kr^|dtkrF|jt|dd|dd}qt|\}}|j|qW||fS)z Read everything up to one of the chars in endchars. This is outside the formal grammar. The InvalidMailbox TokenList that is returned acts like a Mailbox, but the data attributes are None. rzmisplaced-specialrjN)rurrSrr)rrZinvalid_mailboxr.rrrget_invalid_mailboxs   rc Cst}x|o|ddkryt|\}}|j|Wntjk r@d}|dtkrt|\}}| sz|ddkr|j||jjtjdn@t |d\}}|dk r|g|dd<|j||jjtj dnb|ddkr|jjtjdnBt |d\}}|dk r |g|dd<|j||jjtj dYnX|r|ddkr|d }d |_ t |d\}}|j ||jjtj d|r |ddkr |jt |dd}q W||fS) aJ mailbox-list = (mailbox *("," mailbox)) / obs-mbox-list obs-mbox-list = *([CFWS] ",") mailbox *("," [mailbox / CFWS]) For this routine we go outside the formal grammar in order to improve error handling. We recognize the end of the mailbox list only at the end of the value or at a ';' (the group terminator). This is so that we can turn invalid mailboxes into InvalidMailbox tokens and continue parsing any remaining valid mailboxes. We also allow all mailbox entries to be null, and this condition is handled appropriately at a higher level. r;Nz,;zempty element in mailbox-listzinvalid mailbox in mailbox-listrrjzinvalid-mailboxrl)rdrrSrrrrrrrrr7r,r)rZ mailbox_listr.rrcrrrget_mailbox_listsN                   rcCst}|s$|jjtjd||fSd}|r|dtkrt|\}}|sl|jjtjd|j|||fS|ddkr|j|||fSt|\}}t|j dkr|dk r|j||j ||jjtj d||fS|dk r|g|dd<|j|||fS)zg group-list = mailbox-list / CFWS / obs-group-list obs-group-list = 1*([CFWS] ",") [CFWS] zend of header before group-listNrzend of header in group-listrzgroup-list with empty entries) rfrrSrrrrrrkr_r,r)rZ group_listrr.rrrget_group_list"s8           rcCs"t}t|\}}| s$|ddkr4tjdj||j||jtdd|dd}|r|ddkr|jtdd||ddfSt|\}}|j||s|jjtj d n|ddkrtjd j||jtdd|dd}|r|dt krt |\}}|j|||fS) z7 group = display-name ":" [group-list] ";" [CFWS] rrz8expected ':' at end of group display name but found '{}'zgroup-display-name-terminatorrjNrzgroup-terminatorzend of header in groupz)expected ';' at end of group but found {}) rgrrrr#rSrrrrrr)rrar.rrr get_groupGs2            rcCsxt}yt|\}}WnNtjk rdyt|\}}Wn&tjk r^tjdj|YnXYnX|j|||fS)a address = mailbox / group Note that counter-intuitively, an address can be either a single address or a list of addresses (a group). This is why the returned Address object has a 'mailboxes' attribute which treats a single address as a list of length one. When you need to differentiate between to two cases, extract the single element, which is either a mailbox or a group token. zexpected address but found '{}')r`rrrrr#rS)rr\r.rrr get_addresses rcCst}x|ryt|\}}|j|Wn$tjk rP}zd}|dtkrt|\}}| sr|ddkr|j||jjtjdnFt |d\}}|dk r|g|dd<|jt |g|jjtj dnh|ddkr|jjtjdnHt |d\}}|dk r|g|dd<|jt |g|jjtj dWYdd}~XnX|r|ddkr|d d}d|_ t |d\}}|j ||jjtj d|r |jtdd |dd}q W||fS) a address_list = (address *("," address)) / obs-addr-list obs-addr-list = *([CFWS] ",") address *("," [address / CFWS]) We depart from the formal grammar here by continuing to parse until the end of the input, assuming the input to be entirely composed of an address-list. This is always true in email parsing, and allows us to skip invalid addresses to parse additional valid ones. Nrrz"address-list entry with no contentzinvalid address in address-listzempty element in address-listrjzinvalid-mailboxzlist-separatorrl)r[rrSrrrrrrrr`rr7r,r)rZ address_listr.errrrcrrrget_address_listsN                  rcCst}|s |jjtjd|S|dtkrXt|\}}|j||sX|jjtjdd}x8|r|ddkr|dtkr||d7}|dd}q^W|js|jjtjdj ||jt |d nt ||_ |jt |d |o|dtkr t|\}}|j|| s |ddkrX|j dk r>|jjtjd |rT|jt |d |S|jt dd |dd}|r|dtkrt|\}}|j||s|j dk r|jjtjd |Sd}x2|r|dtkr||d7}|dd}qW|js2|jjtjd j ||jt |d nt ||_ |jt |d |rv|dtkrvt|\}}|j||r|jjtjd|jt |d |S)zE mime-version = [CFWS] 1*digit [CFWS] "." [CFWS] 1*digit [CFWS] z%Missing MIME version number (eg: 1.0)rz0Expected MIME version number but found only CFWSrr rjNz1Expected MIME major version number but found {!r}rdigitsz0Incomplete MIME version; found only major numberzversion-separatorz1Expected MIME minor version number but found {!r}z'Excess non-CFWS text after MIME version)rrrSrHeaderMissingRequiredValuerrisdigitrr#rintrr)rZ mime_versionr.rrrrparse_mime_versionsv                        rcCsht}xX|r^|ddkr^|dtkrF|jt|dd|dd}qt|\}}|j|qW||fS)z Read everything up to the next ';'. This is outside the formal grammar. The InvalidParameter TokenList that is returned acts like a Parameter, but the data attributes are None. rrzmisplaced-specialrjN)rrrSrr)rZinvalid_parameterr.rrrget_invalid_parameters   rcCsNt|}|stjdj||j}|t|d}t|d}t|||fS)a8ttext = We allow any non-TOKEN_ENDS in ttext, but add defects to the token's defects list if we find non-ttext characters. We also register defects for *any* non-printables even though the RFC doesn't exclude all of them, because we follow the spirit of RFC 5322. zexpected ttext but found '{}'Nttext)_non_token_end_matcherrrr#rarkrr)rrr rrr get_ttexts   r"cCst}|r,|dtkr,t|\}}|j||rL|dtkrLtjdj|t|\}}|j||r|dtkrt|\}}|j|||fS)ztoken = [CFWS] 1*ttext [CFWS] The RFC equivalent of ttext is any US-ASCII chars except space, ctls, or tspecials. We also exclude tabs even though the RFC doesn't. The RFC implies the CFWS but is not explicit about it in the BNF. rzexpected token but found '{}') rMrrrS TOKEN_ENDSrrr#r")rZmtokenr.rrr get_token)s        r$cCsNt|}|stjdj||j}|t|d}t|d}t|||fS)aQattrtext = 1*(any non-ATTRIBUTE_ENDS character) We allow any non-ATTRIBUTE_ENDS in attrtext, but add defects to the token's defects list if we find non-attrtext characters. We also register defects for *any* non-printables even though the RFC doesn't exclude all of them, because we follow the spirit of RFC 5322. z expected attrtext but found {!r}Nr)_non_attribute_end_matcherrrr#rarkrr)rrrrrr get_attrtext@s   r&cCst}|r,|dtkr,t|\}}|j||rL|dtkrLtjdj|t|\}}|j||r|dtkrt|\}}|j|||fS)aH [CFWS] 1*attrtext [CFWS] This version of the BNF makes the CFWS explicit, and as usual we use a value terminal for the actual run of characters. The RFC equivalent of attrtext is the token characters, with the subtraction of '*', "'", and '%'. We include tab in the excluded set just as we do for token. rzexpected token but found '{}') rrrrSATTRIBUTE_ENDSrrr#r&)rrr.rrr get_attributeSs        r(cCsNt|}|stjdj||j}|t|d}t|d}t|||fS)zattrtext = 1*(any non-ATTRIBUTE_ENDS character plus '%') This is a special parsing routine so that we get a value that includes % escapes as a single string (which we decode as a single string later). z)expected extended attrtext but found {!r}Nzextended-attrtext)#_non_extended_attribute_end_matcherrrr#rarkrr)rrrrrrget_extended_attrtextjs  r*cCst}|r,|dtkr,t|\}}|j||rL|dtkrLtjdj|t|\}}|j||r|dtkrt|\}}|j|||fS)z [CFWS] 1*extended_attrtext [CFWS] This is like the non-extended version except we allow % characters, so that we can pick up an encoded value as a single string. rzexpected token but found '{}') rrrrSEXTENDED_ATTRIBUTE_ENDSrrr#r*)rrr.rrrget_extended_attribute|s       r,cCst}| s|ddkr(tjdj||jtdd|dd}| sX|dj rhtjdj|d}x,|r|djr||d7}|dd}qnW|dd kr|d kr|jjtjd t ||_ |jt|d ||fS) a6 '*' digits The formal BNF is more complicated because leading 0s are not allowed. We check for that and add a defect. We also assume no CFWS is allowed between the '*' and the digits, though the RFC is not crystal clear on that. The caller should already have dealt with leading CFWS. r*zExpected section but found {}zsection-markerrjNz$Expected section number but found {}r0z'section number has an invalid leading 0r) rrrr#rSrrrZInvalidHeaderErrorrr)rrrrrr get_sections&     r/cCst}|stjdd}|dtkr0t|\}}|sDtjdj||ddkr^t|\}}n t|\}}|dk r|g|dd<|j|||fS)z quoted-string / attribute z&Expected value but found end of stringNrz Expected value but found only {}r ) rrrrrr#rr,rS)rvrr.rrr get_values       r1c Cst}t|\}}|j|| s.|ddkrN|jjtjdj|||fS|ddkry t|\}}d|_|j|Wntj k rYnX|stj d|ddkr|jt dd|dd }d|_ |dd krtj d |jt d d |dd }d }|r.|dt kr.t |\}}|j|d }|}|j rH|rH|dd krHt|\}}|j}d}|jdkr|r|ddkrd}n$t|\}} | r| ddkrd}n(yt|\}} Wn Yn X| sd}|r2|jjtjd|j|x,|D]$} | jdkrg| d d <| }PqW|}nd }|jjtjd|rb|ddkrbd }n t|\}}|j s|jdkr| s|ddkr|j||d k r| st||}||fS|jjtjd|s|jjtjd|j||d kr||fSn|d k rVx|D]} | jdkr"Pq"W| jdk|j| | j|_|ddkrttj dj||jt dd|dd }|r|ddkrt|\}}|j||j|_| s|ddkrtj dj||jt dd|dd }|d k rZt} x>|rR|dtkr8t|\}}n t|\}}| j|qW| }n t|\}}|j||d k r| st||}||fS)aY attribute [section] ["*"] [CFWS] "=" value The CFWS is implied by the RFC but not made explicit in the BNF. This simplified form of the BNF from the RFC is made to conform with the RFC BNF through some extra checks. We do it this way because it makes both error recovery and working with the resulting parse tree easier. rrz)Parameter contains name ({}) but no valuer-TzIncomplete parameterzextended-parameter-markerrjN=zParameter not followed by '='zparameter-separatorr F'z5Quoted string value for extended parameter is invalidzbare-quoted-stringzZParameter marked as extended but appears to have a quoted string value that is non-encodedzcApparent initial-extended-value but attribute was not marked as extended or was not initial sectionz(Missing required charset/lang delimiterszextended-attrtextrz=Expected RFC2231 char/lang encoding delimiter, but found {!r}zRFC2231-delimiterz;Expected RFC2231 char/lang encoding delimiter, but found {})rr(rSrrrr#r/rrrrrrrrVrr&r*r7r1AssertionErrorrrPrQrrrr) rrr.rrZappendtoZqstringZ inner_valueZ semi_validrtr0rrr get_parameters                                             r6cCsht}xZ|rbyt|\}}|j|Wntjk r}zd}|dtkrZt|\}}|sl|j||S|ddkr|dk r|j||jjtjdn@t |\}}|r|g|dd<|j||jjtjdj |WYdd}~XnX|r@|ddkr@|d }d|_ t |\}}|j ||jjtjdj ||r |jt dd |dd}q W|S) a! parameter *( ";" parameter ) That BNF is meant to indicate this routine should only be called after finding and handling the leading ';'. There is no corresponding rule in the formal RFC grammar, but it is more convenient for us for the set of parameters to be treated as its own TokenList. This is 'parse' routine because it consumes the reminaing value, but it would never be called to parse a full header. Instead it is called to parse everything after the non-parameter value of a specific MIME header. Nrrzparameter entry with no contentzinvalid parameter {!r}rjzinvalid-parameterz)parameter with invalid trailing text {!r}zparameter-separatorrl)rr6rSrrrrrrrr#r7r,r)rZmime_parametersr.rrrrrrparse_mime_parametersQ sD                 r7cCsxX|rX|ddkrX|dtkr@|jt|dd|dd}qt|\}}|j|qW|sbdS|jtdd|jt|dddS)zBDo our best to find the parameters in an invalid MIME header rrzmisplaced-specialrjNzparameter-separator)rrSrrr7)Z tokenlistrr.rrr_find_mime_parameters s  r8cCst}d}|s$|jjtjd|Syt|\}}Wn8tjk rl|jjtjdj|t |||SX|j|| s|ddkr|jjtjd|rt |||S|j j j |_ |jtdd|dd }yt|\}}Wn:tjk r$|jjtjd j|t |||SX|j||j j j |_|sJ|S|dd kr|jjtjd j||` |`t |||S|jtd d |jt|dd |S)z maintype "/" subtype *( ";" parameter ) The maintype and substype are tokens. Theoretically they could be checked against the official IANA list + x-token, but we don't do that. Fz"Missing content type specificationz(Expected content maintype but found {!r}rrzInvalid content typezcontent-type-separatorrjNz'Expected content subtype but found {!r}rzcCs|jp td}|jrdnd}dg}d}d}d}tdd}t|} xr| r| jd} | |krf|d 8}qDt| } |s| jd krtj |  }n t j |  }y| j ||} Wn6t k rt d d | jDrd } nd} d}YnX| jdkrt| |||qD|r| r| js~d}d}| jr~| j|ddd} |j| kr~t| |t|dkrlt|}|j||d| 7<qDt| dst| | } nt| |||| j| }d}qDt| |t|dkr|d| 7<qD| jr t| d |kr t|}|s| jr |j|| qDt| dsXt| }| jsN|d 7}|j||| } qD| jrz| rz| jd| d}qDt|}|s| jr|j|| qD|d| 7<qDW|jj||jS)zLReturn string of contents of parse_tree folded according to RFC rules. z+infzutf-8zus-asciirNrFwrap_as_ew_blockedrjrcss|]}t|tjVqdS)N)rrr)rrrrrr @ sz%_refold_parse_tree..z unknown-8bitTzmime-parameters)r/rrlrlrlrlrlrl)Zmax_line_lengthfloatutf8rrrrr7 SPECIALSNL isdisjointNLSETrrrr&_fold_mime_parametersr)r;r1lineseprkr>rSr8 _fold_as_ewr<r(insertr!)Z parse_treer/maxlenrr=last_ewr?Z want_encodingZend_ew_not_allowedrr*tstrrPZ encoded_partnewlineZnewpartsrrrr0" s                 r0cCs|dk r<|rrr)Z to_encoder=rIrJr<rPZ leading_wspZ trailing_wspZ new_last_ewZremaining_spaceZ encode_asZ text_spaceZ first_partrZexcessrrrrG sF            rGcCsx|jD]\}}|djjds6|dd7<|}d}y|j|d}Wn0tk rd}tj|rxd}d}nd}YnX|rtjj |d |d } d j ||| } nd j |t |} t |dt | d|kr|dd | |d<q n"t | d|kr|j d | q d} |d} x|rt |t t| dt | } || dkrTd}|| d}}x<|d|}tjj |d |d } t | |krP|d8}qfW|j dj || | | d } | d7} ||d}|r|dd7<qWq WdS)a>Fold TokenList 'part' into the 'lines' list as mime parameters. Using the decoded list of parameters and values, format them according to the RFC rules, including using RFC2231 encoding if the value cannot be expressed in 'encoding' and/or the parameter+value is too long to fit within 'maxlen'. rjrstrictFTz unknown-8bitrzutf-8r)Zsaferz {}*={}''{}z{}={}r@rhrz''r{NNz {}*{}*={}{}rlrlrlrlrlrl)rr|rrrrrrrrYr#rrkrSr)r*r=rIrrrrPZ error_handlerZencoding_requiredZ encoded_valuerKrZ extra_chromeZ chrome_lenZ splitpointZmaxcharspartialrrrrE s\        rE)__doc__rerstringr collectionsroperatorrZemailrrrrrrrrrrrZ TSPECIALSr#Z ASPECIALSr'r+rDrBrrrr?rDrFrHrIrKrMrNrRrWrXr[r`rdrfrgrirqrsrtrurvrxryrzrrrrrrrrrrrrrrrrrrrrrrrrr compiler#r!rwrrmatchrfindallrr!r%r)rrrrrrrrrrrrrrrrrrrrrrrrr r rrrrrrrrrrrr"r$r&r(r*r,r/r1r6r7r8r:r;r<r>r0rGrErrrrDs           C  "   !($ V +            *8" &'/'&).9%>D 49/j7_parseaddr.cpython-36.opt-1.pyc000064400000030323147204636050012245 0ustar003 fD@sdZddddgZddlZddlZdZdZd Zd d d d dddddddddddddddddddd gZd!d"d#d$d%d&d'gZddddd9d:d;dd?d@dAdBd.Z d/dZ d0d1Z d2dZ d3dZ d4dZGd5d6d6ZGd7d8d8eZdS)CzcEmail address parsing code. Lifted directly from rfc822.py. This should eventually be rewritten. mktime_tz parsedate parsedate_tzquoteN z, ZjanZfebZmarZaprZmayZjunZjulZaugsepoctZnovZdecZjanuaryZfebruaryZmarchZaprilZjuneZjulyZaugustZ septemberZoctoberZnovemberZdecemberZmonZtueZwedZthuZfriZsatZsunii,iiXii )ZUTZUTCZGMTZZASTZADTZESTZEDTZCSTZCDTZMSTZMDTZPSTZPDTcCs,t|}|sdS|ddkr$d|d<t|S)zQConvert a date string to a time tuple. Accounts for military timezones. N r) _parsedate_tztuple)dataresr(/usr/lib64/python3.6/email/_parseaddr.pyr-s  cCs|sdS|j}|djds.|djtkr6|d=n.|djd}|dkrd|d|dd|d<t|dkr|djd}t|dkr||dd}t|dkr|d}|jd}|dkr|jd}|dkr|d|||dg|dd<n |jd t|d krdS|dd }|\}}}}}|j}|tkrZ||j}}|tkrZdStj |d}|d krz|d 8}|ddkr|dd}|jd }|dkr||}}|ddkr|dd}|dj s||}}|ddkr|dd}|jd }t|d kr$|\} } d} n~t|dkr>|\} } } ndt|dkrd|dkr|djd}t|d kr|\} } d} nt|dkr|\} } } ndSy,t |}t |}t | } t | } t | } Wnt k rdSX|dkr |dkr|d7}n|d7}d} |j }|tkr,t|} n>y t |} Wnt k rNYnX| dkrj|jdrjd} | r| dkrd} | } nd} | | dd| dd} |||| | | ddd| g S)aConvert date to extended time tuple. The last (additional) element is the time zone offset in seconds, except if the timezone was specified as -0000. In that case the last element is None. This indicates a UTC timestamp that explicitly declaims knowledge of the source timezone, as opposed to a +0000 timestamp that indicates the source timezone really was UTC. Nr,-+r :0.dDilii<r!r!r!r!r!r!r!r!)splitendswithlower _daynamesrfindlenfindappend _monthnamesindexisdigitint ValueErrorupper _timezones startswith)riZstuffsZddZmmZyyZtmZtzZthhZtmmZtssZtzoffsetZtzsignrrrr 9s     "                       r cCs&t|}t|tr|ddS|SdS)z&Convert a time string to a time tuple.Nr )r isinstancer )rtrrrrs  cCs<|ddkr"tj|dddStj|}||dSdS)zETurn a 10-tuple as returned by parsedate_tz() into a POSIX timestamp.r Nrr!)r!)timeZmktimecalendarZtimegm)rr5rrrrs  cCs|jddjddS)zPrepare string to be used in a quoted string. Turns backslash and double quote characters into quoted pairs. These are the only characters that need to be quoted inside a quoted string. Does not add the surrounding double quotes. \z\\"z\")replace)strrrrrsc@s|eZdZdZddZddZddZdd Zd d Zd d Z ddZ dddZ ddZ ddZ ddZdddZddZdS) AddrlistClassaAddress parser class by Ben Escoto. To understand what this class does, it helps to have a copy of RFC 2822 in front of you. Note: this class interface is deprecated and may be removed in the future. Use email.utils.AddressList instead. cCsZd|_d|_d|_d|_|j|j|_|j|j|j|_|jjdd|_||_g|_ dS)zInitialize a new instance. `field' is an unparsed address header field, containing one or more addresses. z ()<>@,:;."[]rz z rrN) specialsposLWSZCRFWSatomendsr; phraseendsfield commentlist)selfrDrrr__init__szAddrlistClass.__init__cCsg}x|jt|jkr|j|j|jdkr^|j|jdkrN|j|j|j|jd7_q|j|jdkr|jj|jqPqWtj|S)z&Skip white space and extract comments.z r() r?r'rDr@r)rE getcomment EMPTYSTRINGjoin)rFZwslistrrrgotonextszAddrlistClass.gotonextcCs>g}x4|jt|jkr8|j}|r,||7}q|jdqW|S)zVParse all addresses. Returns a list containing all of the addresses. r)rr)r?r'rD getaddressr))rFresultZadrrr getaddrlists zAddrlistClass.getaddrlistcCsg|_|j|j}|j}|j}|jg}|jt|jkr\|rXtj|j|dfg}n\|j|jdkr||_||_|j}tj|j|fg}n"|j|jdkrg}t|j}|jd7_x|jt|jkr|j|j|ko|j|jdkr |jd7_P||j }qWn|j|jdkrx|j }|jrftj|ddj|jd |fg}ntj||fg}n@|rtj|j|dfg}n"|j|j|j kr|jd7_|j|jt|jkr|j|jd kr|jd7_|S) zParse the next address.rz.@rr;)rFZoldposZoldclplistZ returnlistZaddrspecZfieldlenZ routeaddrrrrrMsL &$zAddrlistClass.getaddresscCs|j|jdkrdSd}|jd7_|jd}x|jt|jkr|rV|jd}n~|j|jdkrx|jd7_Pn\|j|jdkr|jd7_d}n8|j|jd kr|jd7_n|j}|jd7_P|jq4W|S) zParse a route address (Return-path value). This method just skips all the route stuff and returns the addrspec. rQNFrr>@Tr)rDr?rLr' getdomainrU)rFZ expectrouteZadlistrrrrV?s. zAddrlistClass.getrouteaddrcCs\g}|jx|jt|jkrd}|j|jdkrj|rL|dj rL|j|jd|jd7_d}nf|j|jdkr|jdt|jn>|j|j|j kr|r|d j r|jPn|j|j |j}|r|r|j|qW|jt|jks|j|jdkrt j |S|jd|jd7_|j|j }|sNt St j ||S) zParse an RFC 2822 addr-spec.TrrFr:z"%s"rYr!r!)rLr?r'rDstrippopr)rgetquoterBgetatomrJrKrZ)rFZaslistZ preserve_wsZwsZdomainrrrrU_s: $  zAddrlistClass.getaddrspeccCsg}x|jt|jkr|j|j|jkr8|jd7_q|j|jdkrZ|jj|jq|j|jdkrz|j|jq|j|jdkr|jd7_|jdq|j|jdkrtS|j|j|j krPq|j|j qWtj |S)z-Get the complete domain name from an address.rrH[rrY) r?r'rDr@rEr)rIgetdomainliteralrJrBr^rK)rFZsdlistrrrrZs" zAddrlistClass.getdomainTcCs|j|j|krdSdg}d}|jd7_x|jt|jkr|rZ|j|j|jd}np|j|j|kr||jd7_PnN|r|j|jdkr|j|jq.n(|j|jdkrd}n|j|j|j|jd7_q.Wtj|S)aParse a header fragment delimited by special characters. `beginchar' is the start character for the fragment. If self is not looking at an instance of `beginchar' then getdelimited returns the empty string. `endchars' is a sequence of allowable end-delimiting characters. Parsing stops when one of these is encountered. If `allowcomments' is non-zero, embedded RFC 2822 comments are allowed within the parsed fragment. rFrrHr9T)rDr?r'r)rIrJrK)rFZ begincharZendcharsZ allowcommentsZslistrrrr getdelimiteds( zAddrlistClass.getdelimitedcCs|jdddS)z1Get a quote-delimited fragment from self's field.r:z" F)ra)rFrrrr]szAddrlistClass.getquotecCs|jdddS)z7Get a parenthesis-delimited fragment from self's field.rHz) T)ra)rFrrrrIszAddrlistClass.getcommentcCsd|jdddS)z!Parse an RFC 2822 domain-literal.z[%s]r_z] F)ra)rFrrrr`szAddrlistClass.getdomainliteralNcCshdg}|dkr|j}xH|jt|jkr\|j|j|kr:Pn|j|j|j|jd7_qWtj|S)aParse an RFC 2822 atom. Optional atomends specifies a different set of end token delimiters (the default is to use self.atomends). This is used e.g. in getphraselist() since phrase endings must not include the `.' (which is legal in phrases).rNr)rBr?r'rDr)rJrK)rFrBZatomlistrrrr^szAddrlistClass.getatomcCsg}x|jt|jkr|j|j|jkr8|jd7_q|j|jdkrX|j|jq|j|jdkrz|jj|jq|j|j|jkrPq|j|j |jqW|S)zParse a sequence of RFC 2822 phrases. A phrase is a sequence of words, which are in turn either RFC 2822 atoms or quoted-strings. Phrases are canonicalized by squeezing all runs of continuous whitespace into one space. rr:rH) r?r'rDrAr)r]rErIrCr^)rFrWrrrrSszAddrlistClass.getphraselist)T)N)__name__ __module__ __qualname____doc__rGrLrOrMrVrUrZrar]rIr`r^rSrrrrr=s; & % r=c@sHeZdZdZddZddZddZdd Zd d Zd d Z ddZ dS) AddressListz@An AddressList encapsulates a list of parsed RFC 2822 addresses.cCs&tj|||r|j|_ng|_dS)N)r=rGrO addresslist)rFrDrrrrGs  zAddressList.__init__cCs t|jS)N)r'rg)rFrrr__len__szAddressList.__len__cCsBtd}|jdd|_x$|jD]}||jkr |jj|q W|S)N)rfrgr))rFothernewaddrxrrr__add__s   zAddressList.__add__cCs*x$|jD]}||jkr|jj|qW|S)N)rgr))rFrirkrrr__iadd__ s  zAddressList.__iadd__cCs2td}x$|jD]}||jkr|jj|qW|S)N)rfrgr))rFrirjrkrrr__sub__s   zAddressList.__sub__cCs*x$|jD]}||jkr|jj|qW|S)N)rgremove)rFrirkrrr__isub__s  zAddressList.__isub__cCs |j|S)N)rg)rFr+rrr __getitem__#szAddressList.__getitem__N) rbrcrdrerGrhrlrmrnrprqrrrrrfs rfipii ipii iDiiiD)re__all__r7r8rTrJZ COMMASPACEr*r%r0rr rrrr=rfrrrrs8   u   /_parseaddr.cpython-36.pyc000064400000030323147204636050011306 0ustar003 fD@sdZddddgZddlZddlZdZdZd Zd d d d dddddddddddddddddddd gZd!d"d#d$d%d&d'gZddddd9d:d;dd?d@dAdBd.Z d/dZ d0d1Z d2dZ d3dZ d4dZGd5d6d6ZGd7d8d8eZdS)CzcEmail address parsing code. Lifted directly from rfc822.py. This should eventually be rewritten. mktime_tz parsedate parsedate_tzquoteN z, ZjanZfebZmarZaprZmayZjunZjulZaugsepoctZnovZdecZjanuaryZfebruaryZmarchZaprilZjuneZjulyZaugustZ septemberZoctoberZnovemberZdecemberZmonZtueZwedZthuZfriZsatZsunii,iiXii )ZUTZUTCZGMTZZASTZADTZESTZEDTZCSTZCDTZMSTZMDTZPSTZPDTcCs,t|}|sdS|ddkr$d|d<t|S)zQConvert a date string to a time tuple. Accounts for military timezones. N r) _parsedate_tztuple)dataresr(/usr/lib64/python3.6/email/_parseaddr.pyr-s  cCs|sdS|j}|djds.|djtkr6|d=n.|djd}|dkrd|d|dd|d<t|dkr|djd}t|dkr||dd}t|dkr|d}|jd}|dkr|jd}|dkr|d|||dg|dd<n |jd t|d krdS|dd }|\}}}}}|j}|tkrZ||j}}|tkrZdStj |d}|d krz|d 8}|ddkr|dd}|jd }|dkr||}}|ddkr|dd}|dj s||}}|ddkr|dd}|jd }t|d kr$|\} } d} n~t|dkr>|\} } } ndt|dkrd|dkr|djd}t|d kr|\} } d} nt|dkr|\} } } ndSy,t |}t |}t | } t | } t | } Wnt k rdSX|dkr |dkr|d7}n|d7}d} |j }|tkr,t|} n>y t |} Wnt k rNYnX| dkrj|jdrjd} | r| dkrd} | } nd} | | dd| dd} |||| | | ddd| g S)aConvert date to extended time tuple. The last (additional) element is the time zone offset in seconds, except if the timezone was specified as -0000. In that case the last element is None. This indicates a UTC timestamp that explicitly declaims knowledge of the source timezone, as opposed to a +0000 timestamp that indicates the source timezone really was UTC. Nr,-+r :0.dDilii<r!r!r!r!r!r!r!r!)splitendswithlower _daynamesrfindlenfindappend _monthnamesindexisdigitint ValueErrorupper _timezones startswith)riZstuffsZddZmmZyyZtmZtzZthhZtmmZtssZtzoffsetZtzsignrrrr 9s     "                       r cCs&t|}t|tr|ddS|SdS)z&Convert a time string to a time tuple.Nr )r isinstancer )rtrrrrs  cCs<|ddkr"tj|dddStj|}||dSdS)zETurn a 10-tuple as returned by parsedate_tz() into a POSIX timestamp.r Nrr!)r!)timeZmktimecalendarZtimegm)rr5rrrrs  cCs|jddjddS)zPrepare string to be used in a quoted string. Turns backslash and double quote characters into quoted pairs. These are the only characters that need to be quoted inside a quoted string. Does not add the surrounding double quotes. \z\\"z\")replace)strrrrrsc@s|eZdZdZddZddZddZdd Zd d Zd d Z ddZ dddZ ddZ ddZ ddZdddZddZdS) AddrlistClassaAddress parser class by Ben Escoto. To understand what this class does, it helps to have a copy of RFC 2822 in front of you. Note: this class interface is deprecated and may be removed in the future. Use email.utils.AddressList instead. cCsZd|_d|_d|_d|_|j|j|_|j|j|j|_|jjdd|_||_g|_ dS)zInitialize a new instance. `field' is an unparsed address header field, containing one or more addresses. z ()<>@,:;."[]rz z rrN) specialsposLWSZCRFWSatomendsr; phraseendsfield commentlist)selfrDrrr__init__szAddrlistClass.__init__cCsg}x|jt|jkr|j|j|jdkr^|j|jdkrN|j|j|j|jd7_q|j|jdkr|jj|jqPqWtj|S)z&Skip white space and extract comments.z r() r?r'rDr@r)rE getcomment EMPTYSTRINGjoin)rFZwslistrrrgotonextszAddrlistClass.gotonextcCs>g}x4|jt|jkr8|j}|r,||7}q|jdqW|S)zVParse all addresses. Returns a list containing all of the addresses. r)rr)r?r'rD getaddressr))rFresultZadrrr getaddrlists zAddrlistClass.getaddrlistcCsg|_|j|j}|j}|j}|jg}|jt|jkr\|rXtj|j|dfg}n\|j|jdkr||_||_|j}tj|j|fg}n"|j|jdkrg}t|j}|jd7_x|jt|jkr|j|j|ko|j|jdkr |jd7_P||j }qWn|j|jdkrx|j }|jrftj|ddj|jd |fg}ntj||fg}n@|rtj|j|dfg}n"|j|j|j kr|jd7_|j|jt|jkr|j|jd kr|jd7_|S) zParse the next address.rz.@rr;)rFZoldposZoldclplistZ returnlistZaddrspecZfieldlenZ routeaddrrrrrMsL &$zAddrlistClass.getaddresscCs|j|jdkrdSd}|jd7_|jd}x|jt|jkr|rV|jd}n~|j|jdkrx|jd7_Pn\|j|jdkr|jd7_d}n8|j|jd kr|jd7_n|j}|jd7_P|jq4W|S) zParse a route address (Return-path value). This method just skips all the route stuff and returns the addrspec. rQNFrr>@Tr)rDr?rLr' getdomainrU)rFZ expectrouteZadlistrrrrV?s. zAddrlistClass.getrouteaddrcCs\g}|jx|jt|jkrd}|j|jdkrj|rL|dj rL|j|jd|jd7_d}nf|j|jdkr|jdt|jn>|j|j|j kr|r|d j r|jPn|j|j |j}|r|r|j|qW|jt|jks|j|jdkrt j |S|jd|jd7_|j|j }|sNt St j ||S) zParse an RFC 2822 addr-spec.TrrFr:z"%s"rYr!r!)rLr?r'rDstrippopr)rgetquoterBgetatomrJrKrZ)rFZaslistZ preserve_wsZwsZdomainrrrrU_s: $  zAddrlistClass.getaddrspeccCsg}x|jt|jkr|j|j|jkr8|jd7_q|j|jdkrZ|jj|jq|j|jdkrz|j|jq|j|jdkr|jd7_|jdq|j|jdkrtS|j|j|j krPq|j|j qWtj |S)z-Get the complete domain name from an address.rrH[rrY) r?r'rDr@rEr)rIgetdomainliteralrJrBr^rK)rFZsdlistrrrrZs" zAddrlistClass.getdomainTcCs|j|j|krdSdg}d}|jd7_x|jt|jkr|rZ|j|j|jd}np|j|j|kr||jd7_PnN|r|j|jdkr|j|jq.n(|j|jdkrd}n|j|j|j|jd7_q.Wtj|S)aParse a header fragment delimited by special characters. `beginchar' is the start character for the fragment. If self is not looking at an instance of `beginchar' then getdelimited returns the empty string. `endchars' is a sequence of allowable end-delimiting characters. Parsing stops when one of these is encountered. If `allowcomments' is non-zero, embedded RFC 2822 comments are allowed within the parsed fragment. rFrrHr9T)rDr?r'r)rIrJrK)rFZ begincharZendcharsZ allowcommentsZslistrrrr getdelimiteds( zAddrlistClass.getdelimitedcCs|jdddS)z1Get a quote-delimited fragment from self's field.r:z" F)ra)rFrrrr]szAddrlistClass.getquotecCs|jdddS)z7Get a parenthesis-delimited fragment from self's field.rHz) T)ra)rFrrrrIszAddrlistClass.getcommentcCsd|jdddS)z!Parse an RFC 2822 domain-literal.z[%s]r_z] F)ra)rFrrrr`szAddrlistClass.getdomainliteralNcCshdg}|dkr|j}xH|jt|jkr\|j|j|kr:Pn|j|j|j|jd7_qWtj|S)aParse an RFC 2822 atom. Optional atomends specifies a different set of end token delimiters (the default is to use self.atomends). This is used e.g. in getphraselist() since phrase endings must not include the `.' (which is legal in phrases).rNr)rBr?r'rDr)rJrK)rFrBZatomlistrrrr^szAddrlistClass.getatomcCsg}x|jt|jkr|j|j|jkr8|jd7_q|j|jdkrX|j|jq|j|jdkrz|jj|jq|j|j|jkrPq|j|j |jqW|S)zParse a sequence of RFC 2822 phrases. A phrase is a sequence of words, which are in turn either RFC 2822 atoms or quoted-strings. Phrases are canonicalized by squeezing all runs of continuous whitespace into one space. rr:rH) r?r'rDrAr)r]rErIrCr^)rFrWrrrrSszAddrlistClass.getphraselist)T)N)__name__ __module__ __qualname____doc__rGrLrOrMrVrUrZrar]rIr`r^rSrrrrr=s; & % r=c@sHeZdZdZddZddZddZdd Zd d Zd d Z ddZ dS) AddressListz@An AddressList encapsulates a list of parsed RFC 2822 addresses.cCs&tj|||r|j|_ng|_dS)N)r=rGrO addresslist)rFrDrrrrGs  zAddressList.__init__cCs t|jS)N)r'rg)rFrrr__len__szAddressList.__len__cCsBtd}|jdd|_x$|jD]}||jkr |jj|q W|S)N)rfrgr))rFothernewaddrxrrr__add__s   zAddressList.__add__cCs*x$|jD]}||jkr|jj|qW|S)N)rgr))rFrirkrrr__iadd__ s  zAddressList.__iadd__cCs2td}x$|jD]}||jkr|jj|qW|S)N)rfrgr))rFrirjrkrrr__sub__s   zAddressList.__sub__cCs*x$|jD]}||jkr|jj|qW|S)N)rgremove)rFrirkrrr__isub__s  zAddressList.__isub__cCs |j|S)N)rg)rFr+rrr __getitem__#szAddressList.__getitem__N) rbrcrdrerGrhrlrmrnrprqrrrrrfs rfipii ipii iDiiiD)re__all__r7r8rTrJZ COMMASPACEr*r%r0rr rrrr=rfrrrrs8   u   /_policybase.cpython-36.pyc000064400000035670147204636050011505 0ustar003 f<@sdZddlZddlmZddlmZddlmZdddgZGd d d Z d d Z d dZ Gddde ej dZ e Gddde ZeZdS)zwPolicy framework for the email package. Allows fine grained feature control of how the package parses and emits data. N)header)charset)_has_surrogatesPolicyCompat32compat32cs@eZdZdZfddZddZddZdd Zd d ZZ S) _PolicyBaseaPolicy Object basic framework. This class is useless unless subclassed. A subclass should define class attributes with defaults for any values that are to be managed by the Policy object. The constructor will then allow non-default values to be set for these attributes at instance creation time. The instance will be callable, taking these same attributes keyword arguments, and returning a new instance identical to the called instance except for those values changed by the keyword arguments. Instances may be added, yielding new instances with any non-default values from the right hand operand overriding those in the left hand operand. That is, A + B == A() The repr of an instance can be used to reconstruct the object if and only if the repr of the values can be used to reconstruct those values. c sLxF|jD]:\}}t||r0tt|j||q tdj||jjq WdS)zCreate new Policy, possibly overriding some defaults. See class docstring for a list of overridable attributes. z*{!r} is an invalid keyword argument for {}N) itemshasattrsuperr __setattr__ TypeErrorformat __class____name__)selfkwnamevalue)r)/usr/lib64/python3.6/email/_policybase.py__init__)s  z_PolicyBase.__init__cCs*dd|jjD}dj|jjdj|S)NcSsg|]\}}dj||qS)z{}={!r})r).0rrrrr 8sz(_PolicyBase.__repr__..z{}({})z, )__dict__r rrrjoin)rargsrrr__repr__7sz_PolicyBase.__repr__cKsz|jj|j}x$|jjD]\}}tj|||qWx@|jD]4\}}t||sdtdj||jj tj|||q>W|S)zReturn a new instance with specified attributes changed. The new instance has the same attribute values as the current object, except for the changes passed in as keyword arguments. z*{!r} is an invalid keyword argument for {}) r__new__rr objectr r r rr)rrZ newpolicyattrrrrrclone<s z_PolicyBase.clonecCs,t||rd}nd}t|j|jj|dS)Nz'{!r} object attribute {!r} is read-onlyz!{!r} object has no attribute {!r})r AttributeErrorrrr)rrrmsgrrrr Ns z_PolicyBase.__setattr__cCs|jf|jS)zNon-default values from right operand override those from left. The object returned is a new instance of the subclass. )r!r)rotherrrr__add__Usz_PolicyBase.__add__) r __module__ __qualname____doc__rrr!r r% __classcell__rr)rrrs  rcCs,|jddd}|jddd}|d|S)N r)rsplitsplit)docZ added_docrrr _append_doc^sr/cCs|jr(|jjdr(t|jdj|j|_xf|jjD]X\}}|jr4|jjdr4xhsz%_extend_docstrings..r()r( startswithr/ __bases__rr getattr)clsrr r3r.rrr_extend_docstringscs r9c@seZdZdZdZdZdZdZdZdZ dZ dd Z d d Z d d Z ejddZejddZejddZejddZejddZdS)ra Controls for how messages are interpreted and formatted. Most of the classes and many of the methods in the email package accept Policy objects as parameters. A Policy object contains a set of values and functions that control how input is interpreted and how output is rendered. For example, the parameter 'raise_on_defect' controls whether or not an RFC violation results in an error being raised or not, while 'max_line_length' controls the maximum length of output lines when a Message is serialized. Any valid attribute may be overridden when a Policy is created by passing it as a keyword argument to the constructor. Policy objects are immutable, but a new Policy object can be created with only certain values changed by calling the Policy instance with keyword arguments. Policy objects can also be added, producing a new Policy object in which the non-default attributes set in the right hand operand overwrite those specified in the left operand. Settable attributes: raise_on_defect -- If true, then defects should be raised as errors. Default: False. linesep -- string containing the value to use as separation between output lines. Default '\n'. cte_type -- Type of allowed content transfer encodings 7bit -- ASCII only 8bit -- Content-Transfer-Encoding: 8bit is allowed Default: 8bit. Also controls the disposition of (RFC invalid) binary data in headers; see the documentation of the binary_fold method. max_line_length -- maximum length of lines, excluding 'linesep', during serialization. None or 0 means no line wrapping is done. Default is 78. mangle_from_ -- a flag that, when True escapes From_ lines in the body of the message by putting a `>' in front of them. This is used when the message is being serialized by a generator. Default: True. message_factory -- the class to use to create new message objects. If the value is None, the default is Message. verify_generated_headers -- if true, the generator verifies that each header they are properly folded, so that a parser won't treat it as multiple headers, start-of-body, or part of another header. This is a check against custom Header & fold() implementations. Fr*Z8bitNNTcCs|jr ||j||dS)aZBased on policy, either raise defect or call register_defect. handle_defect(obj, defect) defect should be a Defect subclass, but in any case must be an Exception subclass. obj is the object on which the defect should be registered if it is not raised. If the raise_on_defect is True, the defect is raised as an error, otherwise the object and the defect are passed to register_defect. This method is intended to be called by parsers that discover defects. The email package parsers always call it with Defect instances. N)raise_on_defectregister_defect)robjdefectrrr handle_defectszPolicy.handle_defectcCs|jj|dS)aRecord 'defect' on 'obj'. Called by handle_defect if raise_on_defect is False. This method is part of the Policy API so that Policy subclasses can implement custom defect handling. The default implementation calls the append method of the defects attribute of obj. The objects used by the email package by default that get passed to this method will always have a defects attribute with an append method. N)Zdefectsappend)rr=r>rrrr<s zPolicy.register_defectcCsdS)a[Return the maximum allowed number of headers named 'name'. Called when a header is added to a Message object. If the returned value is not 0 or None, and there are already a number of headers with the name 'name' equal to the value returned, a ValueError is raised. Because the default behavior of Message's __setitem__ is to append the value to the list of headers, it is easy to create duplicate headers without realizing it. This method allows certain headers to be limited in the number of instances of that header that may be added to a Message programmatically. (The limit is not observed by the parser, which will faithfully produce as many headers as exist in the message being parsed.) The default implementation returns None for all header names. Nr)rrrrrheader_max_countszPolicy.header_max_countcCstdS)aZGiven a list of linesep terminated strings constituting the lines of a single header, return the (name, value) tuple that should be stored in the model. The input lines should retain their terminating linesep characters. The lines passed in by the email package may contain surrogateescaped binary data. N)NotImplementedError)r sourcelinesrrrheader_source_parseszPolicy.header_source_parsecCstdS)zGiven the header name and the value provided by the application program, return the (name, value) that should be stored in the model. N)rB)rrrrrrheader_store_parseszPolicy.header_store_parsecCstdS)awGiven the header name and the value from the model, return the value to be returned to the application program that is requesting that header. The value passed in by the email package may contain surrogateescaped binary data if the lines were parsed by a BytesParser. The returned value should not contain any surrogateescaped data. N)rB)rrrrrrheader_fetch_parses zPolicy.header_fetch_parsecCstdS)aGiven the header name and the value from the model, return a string containing linesep characters that implement the folding of the header according to the policy controls. The value passed in by the email package may contain surrogateescaped binary data if the lines were parsed by a BytesParser. The returned value should not contain any surrogateescaped data. N)rB)rrrrrrfolds z Policy.foldcCstdS)a%Given the header name and the value from the model, return binary data containing linesep characters that implement the folding of the header according to the policy controls. The value passed in by the email package may contain surrogateescaped binary data. N)rB)rrrrrr fold_binary szPolicy.fold_binary)rr&r'r(r;linesepcte_typemax_line_length mangle_from_Zmessage_factoryZverify_generated_headersr?r<rAabcabstractmethodrDrErFrGrHrrrrrps 7    ) metaclassc@sLeZdZdZdZddZddZddZd d Zd d Z d dZ ddZ dS)rz+ This particular policy is the backward compatibility Policy. It replicates the behavior of the email package version 5.1. TcCs0t|ts|St|r(tj|tj|dS|SdS)N)r header_name) isinstancestrrrHeader_charset UNKNOWN8BIT)rrrrrr_sanitize_header!s   zCompat32._sanitize_headercCs>|djdd\}}|jddj|dd}||jdfS)a:+ The name is parsed as everything up to the ':' and returned unmodified. The value is determined by stripping leading whitespace off the remainder of the first line, joining all subsequent lines together, and stripping any trailing carriage return or linefeed characters. r:r+z Nz )r-lstriprrstrip)rrCrrrrrrD-szCompat32.header_source_parsecCs||fS)z>+ The name and value are returned unmodified. r)rrrrrrrE9szCompat32.header_store_parsecCs |j||S)z+ If the value contains binary data, it is converted into a Header object using the unknown-8bit charset. Otherwise it is returned unmodified. )rV)rrrrrrrF?szCompat32.header_fetch_parsecCs|j||ddS)a+ Headers are folded using the Header folding algorithm, which preserves existing line breaks in the value, and wraps each resulting line to the max_line_length. Non-ASCII binary data are CTE encoded using the unknown-8bit charset. T)sanitize)_fold)rrrrrrrGFsz Compat32.foldcCs"|j|||jdkd}|jddS)a+ Headers are folded using the Header folding algorithm, which preserves existing line breaks in the value, and wraps each resulting line to the max_line_length. If cte_type is 7bit, non-ascii binary data is CTE encoded using the unknown-8bit charset. Otherwise the original source header is used, with its existing line breaks and/or binary data. Z7bit)r[asciisurrogateescape)r\rJencode)rrrZfoldedrrrrHPs zCompat32.fold_binarycCsg}|jd|t|tr\t|rL|rs   L ( fbase64mime.cpython-36.opt-1.pyc000064400000006224147204636050012100 0ustar003 \ @stdZddddddgZddlmZdd lmZmZd Zd Zd Z d Z ddZ dddZ defddZ ddZeZeZdS)aBase64 content transfer encoding per RFCs 2045-2047. This module handles the content transfer encoding method defined in RFC 2045 to encode arbitrary 8-bit data using the three 8-bit bytes in four 7-bit characters encoding known as Base64. It is used in the MIME standards for email to attach images, audio, and text using some 8-bit character sets to messages. This module provides an interface to encode and decode both headers and bodies with Base64 encoding. RFC 2045 defines a method for including character set information in an `encoded-word' in a header. This method is commonly used for 8-bit real names in To:, From:, Cc:, etc. fields, as well as Subject: lines. This module does not do the line wrapping or end-of-line character conversion necessary for proper internationalized headers; it only does dumb encoding and decoding. To deal with the various line wrapping issues, use the email.header module. body_decode body_encodedecode decodestring header_encode header_length) b64encode) b2a_base64 a2b_base64z  cCs*tt|d\}}|d}|r&|d7}|S)z6Return the length of s when it is encoded with base64.)divmodlen) bytearrayZ groups_of_3Zleftovernr(/usr/lib64/python3.6/email/base64mime.pyr2s  iso-8859-1cCs6|sdSt|tr|j|}t|jd}d||fS)zEncode a single header line with Base64 encoding in a given charset. charset names the character set to use to encode the header. It defaults to iso-8859-1. Base64 encoding is defined in RFC 2045. r asciiz =?%s?b?%s?=) isinstancestrencoderr)Z header_bytescharsetZencodedrrrr=s   LcCs|s|Sg}|dd}x^tdt||D]J}t||||jd}|jtrj|tkrj|dd|}|j|q*Wtj|S)a1Encode a string with base64. Each line will be wrapped at, at most, maxlinelen characters (defaults to 76 characters). Each line of encoded text will end with eol, which defaults to "\n". Set this to "\r\n" if you will be using the result of this function directly in an email. rrrrN) rangerr rendswithNLappend EMPTYSTRINGjoin)sZ maxlinelenZeolZencvecZ max_unencodediencrrrrLs  cCs.|s tSt|tr"t|jdSt|SdS)zDecode a raw base64 string, returning a bytes object. This function does not parse a full MIME header value encoded with base64 (like =?iso-8859-1?b?bmloISBuaWgh?=) -- please use the high level email.header class for that functionality. zraw-unicode-escapeN)bytesrrr r)stringrrrrfs  N)r)__doc____all__base64rZbinasciir r ZCRLFr!r#ZMISC_LENrrrrrrrrrrs$  charset.cpython-36.opt-2.pyc000064400000012025147204636050011572 0ustar003 \B@srddddgZddlmZddlZddlZddlmZddlmZd Z d Z d Z d Z d Z dZdZe e dfe e dfe e dfe e dfe e dfe e dfe e dfe e dfe e dfe e dfe e dfe e dfd*e e dfe e dfe ddfe ddfe ddfe e dfe e dfdZdddddddddddddddddddddddd d Zd!d"dd#Zd+d$dZd%dZd&dZd'd(ZGd)ddZdS),Charset add_alias add_charset add_codec)partialN)errors)encode_7or8bitzus-asciiz unknown-8bitz iso-2022-jpzutf-8)z iso-8859-1z iso-8859-2z iso-8859-3z iso-8859-4z iso-8859-9z iso-8859-10z iso-8859-13z iso-8859-14z iso-8859-15z iso-8859-16z windows-1252Zvisciizus-asciibig5gb2312zeuc-jp shift_jisz iso-2022-jpzkoi8-rzutf-8z iso-8859-1z iso-8859-2z iso-8859-3z iso-8859-4z iso-8859-9z iso-8859-10z iso-8859-13z iso-8859-14z iso-8859-15z iso-8859-16zks_c_5601-1987zeuc-jpzeuc-kr)latin_1zlatin-1Zlatin_2zlatin-2Zlatin_3zlatin-3Zlatin_4zlatin-4Zlatin_5zlatin-5Zlatin_6zlatin-6Zlatin_7zlatin-7Zlatin_8zlatin-8Zlatin_9zlatin-9Zlatin_10zlatin-10cp949euc_jpeuc_krascii eucgb2312_cnbig5_tw)rrzus-asciicCs"|tkrtd|||ft|<dS)Nz!SHORTEST not allowed for body_enc)SHORTEST ValueErrorCHARSETS)charsetZ header_encZbody_encoutput_charsetr%/usr/lib64/python3.6/email/charset.pyrmscCs |t|<dS)N)ALIASES)aliasZ canonicalrrrrscCs |t|<dS)N) CODEC_MAP)rZ codecnamerrrrscCs"|tkr|jddS|j|SdS)Nrsurrogateescape) UNKNOWN8BITencode)stringcodecrrr_encodes r'c@s\eZdZefddZddZeZddZddZd d Z d d Z d dZ ddZ ddZ dS)rc Csy$t|tr|jdn t|d}Wntk rBtj|YnX|j}tj|||_ t j|j t t df\}}}|s~|j }||_ ||_tj|||_tj|j |j |_tj|j|j|_dS)Nr) isinstancestrr$ UnicodeErrorrZ CharsetErrorlowerrget input_charsetrrBASE64header_encoding body_encodingrr!Z input_codec output_codec)selfr-ZhencZbencZconvrrr__init__s&   zCharset.__init__cCs |jjS)N)r-r+)r2rrr__str__szCharset.__str__cCst|t|jkS)N)r)r+)r2otherrrr__eq__szCharset.__eq__cCs$|jtkrdS|jtkrdStSdS)Nzquoted-printablebase64)r0QPr.r)r2rrrget_body_encodings   zCharset.get_body_encodingcCs |jp |jS)N)rr-)r2rrrget_output_charsetszCharset.get_output_charsetcCs6|jpd}t||}|j|}|dkr*|S|j||S)Nzus-ascii)r1r' _get_encoder header_encode)r2r%r& header_bytesencoder_modulerrrr<s   zCharset.header_encodecCs|jpd}t||}|j|}t|j|d}|j}t|t}g} g} t||} x|D]} | j | t j | } |j t| |}|| krZ| j | r| r| j dn.| rdnd}t j | }t||}| j ||| g} t||} qZWt j | }t||}| j ||| S)Nzus-ascii)r r )r1r'r;rr<r:lenRFC2047_CHROME_LENnextappend EMPTYSTRINGjoin header_lengthpop)r2r%Z maxlengthsr&r=r>encoderrZextralinesZ current_linemaxlen characterZ this_lineZlengthZ separatorZ joined_linerrrheader_encode_lines,s6               zCharset.header_encode_linescCs`|jtkrtjS|jtkr tjS|jtkrXtjj|}tjj|}||krPtjStjSndSdS)N)r/r.email base64mimer8 quoprimimerrF)r2r=Zlen64Zlenqprrrr;js     zCharset._get_encodercCs|s|S|jtkr4t|tr(|j|j}tjj|S|jt krjt|trT|j|j}|j d}tj j|St|tr|j|jj d}|SdS)Nlatin1r) r0r.r(r)r$rrMrN body_encoder8decoderO)r2r%rrrrQys           zCharset.body_encodeN)__name__ __module__ __qualname__DEFAULT_CHARSETr3r4__repr__r6r9r:r<rLr;rQrrrrrs, !>)NNN)NNN)__all__ functoolsrZemail.base64mimerMZemail.quoprimimerZemail.encodersrr8r.rrArVr#rDrrr!rrrr'rrrrrs      charset.cpython-36.pyc000064400000026371147204636050010643 0ustar003 \B@srddddgZddlmZddlZddlZddlmZddlmZd Z d Z d Z d Z d Z dZdZe e dfe e dfe e dfe e dfe e dfe e dfe e dfe e dfe e dfe e dfe e dfe e dfd*e e dfe e dfe ddfe ddfe ddfe e dfe e dfdZdddddddddddddddddddddddd d Zd!d"dd#Zd+d$dZd%dZd&dZd'd(ZGd)ddZdS),Charset add_alias add_charset add_codec)partialN)errors)encode_7or8bitzus-asciiz unknown-8bitz iso-2022-jpzutf-8)z iso-8859-1z iso-8859-2z iso-8859-3z iso-8859-4z iso-8859-9z iso-8859-10z iso-8859-13z iso-8859-14z iso-8859-15z iso-8859-16z windows-1252Zvisciizus-asciibig5gb2312zeuc-jp shift_jisz iso-2022-jpzkoi8-rzutf-8z iso-8859-1z iso-8859-2z iso-8859-3z iso-8859-4z iso-8859-9z iso-8859-10z iso-8859-13z iso-8859-14z iso-8859-15z iso-8859-16zks_c_5601-1987zeuc-jpzeuc-kr)latin_1zlatin-1Zlatin_2zlatin-2Zlatin_3zlatin-3Zlatin_4zlatin-4Zlatin_5zlatin-5Zlatin_6zlatin-6Zlatin_7zlatin-7Zlatin_8zlatin-8Zlatin_9zlatin-9Zlatin_10zlatin-10cp949euc_jpeuc_krascii eucgb2312_cnbig5_tw)rrzus-asciicCs"|tkrtd|||ft|<dS)a>Add character set properties to the global registry. charset is the input character set, and must be the canonical name of a character set. Optional header_enc and body_enc is either Charset.QP for quoted-printable, Charset.BASE64 for base64 encoding, Charset.SHORTEST for the shortest of qp or base64 encoding, or None for no encoding. SHORTEST is only valid for header_enc. It describes how message headers and message bodies in the input charset are to be encoded. Default is no encoding. Optional output_charset is the character set that the output should be in. Conversions will proceed from input charset, to Unicode, to the output charset when the method Charset.convert() is called. The default is to output in the same character set as the input. Both input_charset and output_charset must have Unicode codec entries in the module's charset-to-codec mapping; use add_codec(charset, codecname) to add codecs the module does not know about. See the codecs module's documentation for more information. z!SHORTEST not allowed for body_encN)SHORTEST ValueErrorCHARSETS)charsetZ header_encZbody_encoutput_charsetr%/usr/lib64/python3.6/email/charset.pyrmscCs |t|<dS)zAdd a character set alias. alias is the alias name, e.g. latin-1 canonical is the character set's canonical name, e.g. iso-8859-1 N)ALIASES)aliasZ canonicalrrrrscCs |t|<dS)a$Add a codec that map characters in the given charset to/from Unicode. charset is the canonical name of a character set. codecname is the name of a Python codec, as appropriate for the second argument to the unicode() built-in, or to the encode() method of a Unicode string. N) CODEC_MAP)rZ codecnamerrrrscCs"|tkr|jddS|j|SdS)Nrsurrogateescape) UNKNOWN8BITencode)stringcodecrrr_encodes r'c@s`eZdZdZefddZddZeZddZdd Z d d Z d d Z ddZ ddZ ddZdS)ra@ Map character sets to their email properties. This class provides information about the requirements imposed on email for a specific character set. It also provides convenience routines for converting between character sets, given the availability of the applicable codecs. Given a character set, it will do its best to provide information on how to use that character set in an email in an RFC-compliant way. Certain character sets must be encoded with quoted-printable or base64 when used in email headers or bodies. Certain character sets must be converted outright, and are not allowed in email. Instances of this module expose the following information about a character set: input_charset: The initial character set specified. Common aliases are converted to their `official' email names (e.g. latin_1 is converted to iso-8859-1). Defaults to 7-bit us-ascii. header_encoding: If the character set must be encoded before it can be used in an email header, this attribute will be set to Charset.QP (for quoted-printable), Charset.BASE64 (for base64 encoding), or Charset.SHORTEST for the shortest of QP or BASE64 encoding. Otherwise, it will be None. body_encoding: Same as header_encoding, but describes the encoding for the mail message's body, which indeed may be different than the header encoding. Charset.SHORTEST is not allowed for body_encoding. output_charset: Some character sets must be converted before they can be used in email headers or bodies. If the input_charset is one of them, this attribute will contain the name of the charset output will be converted to. Otherwise, it will be None. input_codec: The name of the Python codec used to convert the input_charset to Unicode. If no conversion codec is necessary, this attribute will be None. output_codec: The name of the Python codec used to convert Unicode to the output_charset. If no conversion codec is necessary, this attribute will have the same value as the input_codec. c Csy$t|tr|jdn t|d}Wntk rBtj|YnX|j}tj|||_ t j|j t t df\}}}|s~|j }||_ ||_tj|||_tj|j |j |_tj|j|j|_dS)Nr) isinstancestrr$ UnicodeErrorrZ CharsetErrorlowerrget input_charsetrrBASE64header_encoding body_encodingrr!Z input_codec output_codec)selfr-ZhencZbencZconvrrr__init__s&   zCharset.__init__cCs |jjS)N)r-r+)r2rrr__str__szCharset.__str__cCst|t|jkS)N)r)r+)r2otherrrr__eq__szCharset.__eq__cCs2|jtkst|jtkrdS|jtkr*dStSdS)aPReturn the content-transfer-encoding used for body encoding. This is either the string `quoted-printable' or `base64' depending on the encoding used, or it is a function in which case you should call the function with a single argument, the Message object being encoded. The function should then set the Content-Transfer-Encoding header itself to whatever is appropriate. Returns "quoted-printable" if self.body_encoding is QP. Returns "base64" if self.body_encoding is BASE64. Returns conversion function otherwise. zquoted-printablebase64N)r0rAssertionErrorQPr.r)r2rrrget_body_encodings   zCharset.get_body_encodingcCs |jp |jS)zReturn the output character set. This is self.output_charset if that is not None, otherwise it is self.input_charset. )rr-)r2rrrget_output_charsetszCharset.get_output_charsetcCs6|jpd}t||}|j|}|dkr*|S|j||S)aHeader-encode a string by converting it first to bytes. The type of encoding (base64 or quoted-printable) will be based on this charset's `header_encoding`. :param string: A unicode string for the header. It must be possible to encode this string to bytes using the character set's output codec. :return: The encoded string, with RFC 2047 chrome. zus-asciiN)r1r' _get_encoder header_encode)r2r%r& header_bytesencoder_modulerrrr=s   zCharset.header_encodecCs|jpd}t||}|j|}t|j|d}|j}t|t}g} g} t||} x|D]} | j | t j | } |j t| |}|| krZ| j | r| r| j dn.| rdnd}t j | }t||}| j ||| g} t||} qZWt j | }t||}| j ||| S)afHeader-encode a string by converting it first to bytes. This is similar to `header_encode()` except that the string is fit into maximum line lengths as given by the argument. :param string: A unicode string for the header. It must be possible to encode this string to bytes using the character set's output codec. :param maxlengths: Maximum line length iterator. Each element returned from this iterator will provide the next maximum line length. This parameter is used as an argument to built-in next() and should never be exhausted. The maximum line lengths should not count the RFC 2047 chrome. These line lengths are only a hint; the splitter does the best it can. :return: Lines of encoded strings, each with RFC 2047 chrome. zus-ascii)rN r )r1r'r<rr=r;lenRFC2047_CHROME_LENnextappend EMPTYSTRINGjoin header_lengthpop)r2r%Z maxlengthsr&r>r?encoderrZextralinesZ current_linemaxlen characterZ this_lineZlengthZ separatorZ joined_linerrrheader_encode_lines,s6               zCharset.header_encode_linescCs`|jtkrtjS|jtkr tjS|jtkrXtjj|}tjj|}||krPtjStjSndSdS)N)r/r.email base64mimer9 quoprimimerrG)r2r>Zlen64Zlenqprrrr<js     zCharset._get_encodercCs|s|S|jtkr4t|tr(|j|j}tjj|S|jt krjt|trT|j|j}|j d}tj j|St|tr|j|jj d}|SdS)avBody-encode a string by converting it first to bytes. The type of encoding (base64 or quoted-printable) will be based on self.body_encoding. If body_encoding is None, we assume the output charset is a 7bit encoding, so re-encoding the decoded string using the ascii codec produces the correct string version of the content. latin1rN) r0r.r(r)r$rrNrO body_encoder9decoderP)r2r%rrrrRys           zCharset.body_encodeN)__name__ __module__ __qualname____doc__DEFAULT_CHARSETr3r4__repr__r6r:r;r=rMr<rRrrrrrs+ !>)NNN)NNN)__all__ functoolsrZemail.base64mimerNZemail.quoprimimerZemail.encodersrr9r.rrBrXr#rErrr!rrrr'rrrrrs      contentmanager.cpython-36.opt-1.pyc000064400000016172147204636050013154 0ustar003 \)@s:ddlZddlZddlZddlZddlmZGdddZeZd%ddZej ded d Z xd j D]Z ej e e qhWd d Z x dj D]Zej dee qWddZej deddZddZddZddZd&ddZejeed'd d!Zejejjed(d#d$Zx eeefD]Zejeeq WdS))N) quoprimimec@s<eZdZddZddZddZddZd d Zd d Zd S)ContentManagercCsi|_i|_dS)N) get_handlers set_handlers)selfr,/usr/lib64/python3.6/email/contentmanager.py__init__ szContentManager.__init__cCs||j|<dS)N)r)rkeyhandlerrrradd_get_handler szContentManager.add_get_handlercOs||j}||jkr(|j||f||S|j}||jkrP|j||f||Sd|jkrp|jd|f||St|dS)N)Zget_content_typerget_content_maintypeKeyError)rmsgargskwZ content_typemaintyperrr get_contents   zContentManager.get_contentcCs||j|<dS)N)r)rZtypekeyr rrradd_set_handlerszContentManager.add_set_handlercOs>|jdkrtd|j||}|j|||f||dS)NZ multipartz"set_content not valid on multipart)r TypeError_find_set_handlerZ clear_content)rrobjrrr rrr set_contents   zContentManager.set_contentc Csd}xt|jD]}||jkr(|j|S|j}t|dd}|rLdj||fn|}|dkr\|}||jkrp|j|S||jkr|j|S|j}||jkr|j|SqWd|jkr|jdSt|dS)N __module__r .)type__mro__r __qualname__getattrjoin__name__r) rrrZfull_path_for_errortypZqnamemodname full_pathnamerrrr's&          z ContentManager._find_set_handlerN) r!rrr r rrrrrrrrrs   rreplacecCs&|jdd}|jdd}|j||dS)NT)decodecharsetASCII)errors) get_payloadZ get_paramr')rr*Zcontentr(rrrget_text_content@s  r,textcCs |jddS)NT)r')r+)rrrrget_non_text_contentGsr.zaudio image video applicationcCs |jdS)Nr)r+)rrrrget_message_contentMsr/zrfc822 external-bodyzmessage/cCst|jdS)Nr)bytesr+)rrrr%get_and_fixup_unknown_message_contentSsr1messagecsdj||f|d<|rt|dds<|jfdd|D}y,x&|D]}|jrX|jd|||j<qDWWn@tjjk r}z tdj |j |jd|WYdd}~XnXdS) N/z Content-Typerr%csg|]}jj|gqSr)Zheader_factoryZheader_source_parse).0header)mprr dsz _prepare_set..zInvalid header: {})policy) r hasattrr8Zdefectsr%emailr*Z HeaderDefect ValueErrorformatZfold)rrsubtypeheadersr5excr)r6r _prepare_set_s   r@cCs||dkr|dk rd}|dk r$||d<|dk r>|jd|ddd|dk rN||d<|dk rxx |jD]\}}|j||q`WdS)NZ attachmentzContent-DispositionfilenameT)r5r&z Content-ID) set_paramitems)r dispositionrAcidparamsr valuerrr _finalize_setpsrHcCsZg}|dd}x>tdt||D]*}||||}|jtj|jdq"Wdj|S)Nrasciir )rangelenappendbinascii b2a_base64r'r )datamax_line_lengthZ encoded_linesZunencoded_bytes_per_lineiZthislinerrr_encode_base64s  rTc s||j|j}|jjdfdd}dd}|dkryd||jdfStk r\YnX|jdkrtdd |D|jkrd||jdd fS||dd }tj |jd |j}t j |} t |t | krd }nd}t |d kr||fS|dkr ||jd} nj|dkr&||jdd } nN|dkrJtj ||jd |j} n*|d krft |||j} ntdj||| fS)NrKcsj|S)N)r )lines)lineseprr embedded_bodysz#_encode_text..embedded_bodycSsdj|dS)N )r )rUrrr normal_bodysz!_encode_text..normal_body7bit8bitcss|]}t|VqdS)N)rM)r4xrrr sz_encode_text..surrogateescape zlatin-1base64zquoted-printablez$Unknown content transfer encoding {})encode splitlinesrVr'UnicodeDecodeErrorZcte_typemaxrRrZ body_encoderOrPrMrTr;r<) stringr(cter8rUrWrYZsniffZsniff_qpZ sniff_base64rQr)rVr _encode_texts@           rgplainutf-8c Csdt|d|| t||||j\}} |j| |jdtjjj||dd||d<t |||||dS)Nr-r(T)r&zContent-Transfer-Encoding) r@rgr8 set_payloadrBr:r(ZALIASESgetrH) rrer=r(rfrDrArErFr>Zpayloadrrrset_text_contents rlrfc822c Cs|dkrtd|dkr@|d kr.tdj||dkr:dn|}n0|dkrd|d kr^td j|d}n |dkrpd}t|d |||j|g||d <t|||||dS)Npartialz4message/partial is not supported for Message objectsrmrZr[binaryz*message/rfc822 parts do not support cte={}z external-bodyz1message/external-body parts do not support cte={}r2zContent-Transfer-Encoding)NrZr[ro)NrZ)r;r<r@rjrH) rr2r=rfrDrArErFr>rrrset_message_contents$   rpr`c Cst|||| |dkr(t||jjd}nN|dkrNtj|dddd}|jd}n(|dkrb|jdn|d krv|jdd }|j|||d <t |||||dS)Nr`)rRzquoted-printableFT)istextr5Z quotetabsrKrZr[ror^zContent-Transfer-Encoding)r[ro) r@rTr8rRrOZb2a_qpr'rarjrH) rrQrr=rfrDrArErFr>rrrset_bytes_contents    rr)r&)rhriNNNNNN)rmNNNNNN)r`NNNNN)rOZ email.charsetr:Z email.messageZ email.errorsrrZraw_data_managerr,r r.splitrr/r=r1r@rHrTrgrlrstrrpr2ZMessagerrr0 bytearray memoryviewr"rrrrsD 6   '   contentmanager.cpython-36.opt-2.pyc000064400000016172147204636050013155 0ustar003 \)@s:ddlZddlZddlZddlZddlmZGdddZeZd%ddZej ded d Z xd j D]Z ej e e qhWd d Z x dj D]Zej dee qWddZej deddZddZddZddZd&ddZejeed'd d!Zejejjed(d#d$Zx eeefD]Zejeeq WdS))N) quoprimimec@s<eZdZddZddZddZddZd d Zd d Zd S)ContentManagercCsi|_i|_dS)N) get_handlers set_handlers)selfr,/usr/lib64/python3.6/email/contentmanager.py__init__ szContentManager.__init__cCs||j|<dS)N)r)rkeyhandlerrrradd_get_handler szContentManager.add_get_handlercOs||j}||jkr(|j||f||S|j}||jkrP|j||f||Sd|jkrp|jd|f||St|dS)N)Zget_content_typerget_content_maintypeKeyError)rmsgargskwZ content_typemaintyperrr get_contents   zContentManager.get_contentcCs||j|<dS)N)r)rZtypekeyr rrradd_set_handlerszContentManager.add_set_handlercOs>|jdkrtd|j||}|j|||f||dS)NZ multipartz"set_content not valid on multipart)r TypeError_find_set_handlerZ clear_content)rrobjrrr rrr set_contents   zContentManager.set_contentc Csd}xt|jD]}||jkr(|j|S|j}t|dd}|rLdj||fn|}|dkr\|}||jkrp|j|S||jkr|j|S|j}||jkr|j|SqWd|jkr|jdSt|dS)N __module__r .)type__mro__r __qualname__getattrjoin__name__r) rrrZfull_path_for_errortypZqnamemodname full_pathnamerrrr's&          z ContentManager._find_set_handlerN) r!rrr r rrrrrrrrrs   rreplacecCs&|jdd}|jdd}|j||dS)NT)decodecharsetASCII)errors) get_payloadZ get_paramr')rr*Zcontentr(rrrget_text_content@s  r,textcCs |jddS)NT)r')r+)rrrrget_non_text_contentGsr.zaudio image video applicationcCs |jdS)Nr)r+)rrrrget_message_contentMsr/zrfc822 external-bodyzmessage/cCst|jdS)Nr)bytesr+)rrrr%get_and_fixup_unknown_message_contentSsr1messagecsdj||f|d<|rt|dds<|jfdd|D}y,x&|D]}|jrX|jd|||j<qDWWn@tjjk r}z tdj |j |jd|WYdd}~XnXdS) N/z Content-Typerr%csg|]}jj|gqSr)Zheader_factoryZheader_source_parse).0header)mprr dsz _prepare_set..zInvalid header: {})policy) r hasattrr8Zdefectsr%emailr*Z HeaderDefect ValueErrorformatZfold)rrsubtypeheadersr5excr)r6r _prepare_set_s   r@cCs||dkr|dk rd}|dk r$||d<|dk r>|jd|ddd|dk rN||d<|dk rxx |jD]\}}|j||q`WdS)NZ attachmentzContent-DispositionfilenameT)r5r&z Content-ID) set_paramitems)r dispositionrAcidparamsr valuerrr _finalize_setpsrHcCsZg}|dd}x>tdt||D]*}||||}|jtj|jdq"Wdj|S)Nrasciir )rangelenappendbinascii b2a_base64r'r )datamax_line_lengthZ encoded_linesZunencoded_bytes_per_lineiZthislinerrr_encode_base64s  rTc s||j|j}|jjdfdd}dd}|dkryd||jdfStk r\YnX|jdkrtdd |D|jkrd||jdd fS||dd }tj |jd |j}t j |} t |t | krd }nd}t |d kr||fS|dkr ||jd} nj|dkr&||jdd } nN|dkrJtj ||jd |j} n*|d krft |||j} ntdj||| fS)NrKcsj|S)N)r )lines)lineseprr embedded_bodysz#_encode_text..embedded_bodycSsdj|dS)N )r )rUrrr normal_bodysz!_encode_text..normal_body7bit8bitcss|]}t|VqdS)N)rM)r4xrrr sz_encode_text..surrogateescape zlatin-1base64zquoted-printablez$Unknown content transfer encoding {})encode splitlinesrVr'UnicodeDecodeErrorZcte_typemaxrRrZ body_encoderOrPrMrTr;r<) stringr(cter8rUrWrYZsniffZsniff_qpZ sniff_base64rQr)rVr _encode_texts@           rgplainutf-8c Csdt|d|| t||||j\}} |j| |jdtjjj||dd||d<t |||||dS)Nr-r(T)r&zContent-Transfer-Encoding) r@rgr8 set_payloadrBr:r(ZALIASESgetrH) rrer=r(rfrDrArErFr>Zpayloadrrrset_text_contents rlrfc822c Cs|dkrtd|dkr@|d kr.tdj||dkr:dn|}n0|dkrd|d kr^td j|d}n |dkrpd}t|d |||j|g||d <t|||||dS)Npartialz4message/partial is not supported for Message objectsrmrZr[binaryz*message/rfc822 parts do not support cte={}z external-bodyz1message/external-body parts do not support cte={}r2zContent-Transfer-Encoding)NrZr[ro)NrZ)r;r<r@rjrH) rr2r=rfrDrArErFr>rrrset_message_contents$   rpr`c Cst|||| |dkr(t||jjd}nN|dkrNtj|dddd}|jd}n(|dkrb|jdn|d krv|jdd }|j|||d <t |||||dS)Nr`)rRzquoted-printableFT)istextr5Z quotetabsrKrZr[ror^zContent-Transfer-Encoding)r[ro) r@rTr8rRrOZb2a_qpr'rarjrH) rrQrr=rfrDrArErFr>rrrset_bytes_contents    rr)r&)rhriNNNNNN)rmNNNNNN)r`NNNNN)rOZ email.charsetr:Z email.messageZ email.errorsrrZraw_data_managerr,r r.splitrr/r=r1r@rHrTrgrlrstrrpr2ZMessagerrr0 bytearray memoryviewr"rrrrsD 6   '   errors.cpython-36.pyc000064400000014316147204636050010522 0ustar003 f@sdZGdddeZGdddeZGdddeZGdddeZGd d d eeZGd d d eZGd ddeZ Gddde Z Gddde Z Gddde Z Gddde ZGddde ZGddde ZGddde ZeZGddde ZGdd d e ZGd!d"d"e ZGd#d$d$e ZGd%d&d&e ZGd'd(d(e ZGd)d*d*e ZGd+d,d,eZGd-d.d.eZGd/d0d0eZGd1d2d2eZGd3d4d4eZd5S)6z email package exception classes.c@seZdZdZdS) MessageErrorz+Base class for errors in the email package.N)__name__ __module__ __qualname____doc__rr$/usr/lib64/python3.6/email/errors.pyrsrc@seZdZdZdS)MessageParseErrorz&Base class for message parsing errors.N)rrrrrrrrr src@seZdZdZdS)HeaderParseErrorzError while parsing headers.N)rrrrrrrrr sr c@seZdZdZdS) BoundaryErrorz#Couldn't find terminating boundary.N)rrrrrrrrr sr c@seZdZdZdS)MultipartConversionErrorz(Conversion to a multipart is prohibited.N)rrrrrrrrr sr c@seZdZdZdS) CharsetErrorzAn illegal charset was given.N)rrrrrrrrr sr c@seZdZdZdS)HeaderWriteErrorzError while writing headers.N)rrrrrrrrr sr cs"eZdZdZdfdd ZZS) MessageDefectz Base class for a message defect.Ncs|dk rtj|||_dS)N)super__init__line)selfr) __class__rrr(s zMessageDefect.__init__)N)rrrrr __classcell__rr)rrr%src@seZdZdZdS)NoBoundaryInMultipartDefectzBA message claimed to be a multipart but had no boundary parameter.N)rrrrrrrrr-src@seZdZdZdS)StartBoundaryNotFoundDefectz+The claimed start boundary was never found.N)rrrrrrrrr0src@seZdZdZdS)CloseBoundaryNotFoundDefectzEA start boundary was found, but not the corresponding close boundary.N)rrrrrrrrr3src@seZdZdZdS)#FirstHeaderLineIsContinuationDefectz;A message had a continuation line as its first header line.N)rrrrrrrrr6src@seZdZdZdS)MisplacedEnvelopeHeaderDefectz?A 'Unix-from' header was found in the middle of a header block.N)rrrrrrrrr9src@seZdZdZdS) MissingHeaderBodySeparatorDefectzEFound line with no leading whitespace and no colon before blank line.N)rrrrrrrrr<src@seZdZdZdS)!MultipartInvariantViolationDefectz?A message claimed to be a multipart but no subparts were found.N)rrrrrrrrrAsrc@seZdZdZdS)-InvalidMultipartContentTransferEncodingDefectzEAn invalid content transfer encoding was set on the multipart itself.N)rrrrrrrrrDsrc@seZdZdZdS)UndecodableBytesDefectz0Header contained bytes that could not be decodedN)rrrrrrrrrGsrc@seZdZdZdS)InvalidBase64PaddingDefectz/base64 encoded sequence had an incorrect lengthN)rrrrrrrrrJsrc@seZdZdZdS)InvalidBase64CharactersDefectz=base64 encoded sequence had characters not in base64 alphabetN)rrrrrrrrrMsrc@seZdZdZdS)InvalidBase64LengthDefectz4base64 encoded sequence had invalid length (1 mod 4)N)rrrrrrrrr Psr cs eZdZdZfddZZS) HeaderDefectzBase class for a header defect.cstj||dS)N)rr)rargskw)rrrrXszHeaderDefect.__init__)rrrrrrrr)rrr!Usr!c@seZdZdZdS)InvalidHeaderDefectz+Header is not valid, message gives details.N)rrrrrrrrr$[sr$c@seZdZdZdS)HeaderMissingRequiredValuez(A header that must have a value had noneN)rrrrrrrrr%^sr%cs(eZdZdZfddZddZZS)NonPrintableDefectz8ASCII characters outside the ascii-printable range foundcstj|||_dS)N)rrnon_printables)rr')rrrrds zNonPrintableDefect.__init__cCs dj|jS)Nz6the following ASCII non-printables found in header: {})formatr')rrrr__str__hszNonPrintableDefect.__str__)rrrrrr)rrr)rrr&as r&c@seZdZdZdS)ObsoleteHeaderDefectz0Header uses syntax declared obsolete by RFC 5322N)rrrrrrrrr*lsr*c@seZdZdZdS)NonASCIILocalPartDefectz(local_part contains non-ASCII charactersN)rrrrrrrrr+osr+N)r Exceptionrrr r TypeErrorr r r ValueErrorrrrrrrrZMalformedHeaderDefectrrrrrr r!r$r%r&r*r+rrrrs6 feedparser.cpython-36.opt-2.pyc000064400000021173147204636050012265 0ustar003 \X@sddgZddlZddlmZddlmZddlmZddlm Z ej dZ ej d Z ej d Z ej d Zej d Zd Zd ZeZGdddeZGdddZGdddeZdS) FeedParserBytesFeedParserN)errors)compat32)deque)StringIOz \r\n|\r|\nz (\r\n|\r|\n)z(\r\n|\r|\n)\Zz%^(From |[\041-\071\073-\176]*:|[\t ]) c@s\eZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ dS)BufferedSubFilecCs$tdd|_t|_g|_d|_dS)Nr)newlineF)r_partialr_lines _eofstack_closed)selfr(/usr/lib64/python3.6/email/feedparser.py__init__5s zBufferedSubFile.__init__cCs|jj|dS)N)rappend)rZpredrrrpush_eof_matcher@sz BufferedSubFile.push_eof_matchercCs |jjS)N)rpop)rrrrpop_eof_matcherCszBufferedSubFile.pop_eof_matchercCs<|jjd|j|jj|jjd|jjd|_dS)NrT)r seek pushlines readlinestruncater)rrrrcloseFs    zBufferedSubFile.closecCsN|js|jrdStS|jj}x*t|jD]}||r*|jj|dSq*W|S)Nr)r r NeedMoreDatapopleftreversedr appendleft)rlineZateofrrrreadlineNs  zBufferedSubFile.readlinecCs|jj|dS)N)r r )rr!rrr unreadline`szBufferedSubFile.unreadlinecCsx|jj|d|kr d|kr dS|jjd|jj}|jjd|jj|djdsj|jj|j|j|dS)Nr  r)r writerrrendswithrr)rdatapartsrrrpushes     zBufferedSubFile.pushcCs|jj|dS)N)r extend)rlinesrrrrzszBufferedSubFile.pushlinescCs|S)Nr)rrrr__iter__}szBufferedSubFile.__iter__cCs|j}|dkrt|S)Nr)r" StopIteration)rr!rrr__next__szBufferedSubFile.__next__N) __name__ __module__ __qualname__rrrrr"r#r+rr.r0rrrrr -s r c@s\eZdZdedddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ dS)rN)policyc Cs||_d|_|dkr<|jdkr2ddlm}||_qn|j|_n2||_y||jdWntk rld|_YnXt|_g|_ |j j |_ d|_ d|_d|_dS)NFr)Message)r4T)r4_old_style_factoryZmessage_factoryZ email.messager5_factory TypeErrorr _input _msgstack _parsegenr0_parse_cur_last _headersonly)rr7r4r5rrrrs$     zFeedParser.__init__cCs d|_dS)NT)r?)rrrr_set_headersonlyszFeedParser._set_headersonlycCs|jj||jdS)N)r9r+ _call_parse)rr)rrrfeeds zFeedParser.feedc Cs&y |jWntk r YnXdS)N)r<r/)rrrrrAs zFeedParser._call_parsecCsJ|jj|j|j}|jdkrF|j rFtj}|jj |||S)N multipart) r9rrA _pop_messageget_content_maintypeZ is_multipartrZ!MultipartInvariantViolationDefectr4 handle_defect)rrootdefectrrrrs   zFeedParser.closecCsn|jr|j}n|j|jd}|jr<|jjdkr<|jd|jrR|jdj||jj|||_||_ dS)N)r4zmultipart/digestzmessage/rfc822r%r&) r6r7r4r=get_content_typeZset_default_typer:Zattachrr>)rmsgrrr _new_messages   zFeedParser._new_messagecCs(|jj}|jr|jd|_nd|_|S)Nr%r&)r:rr=)rretvalrrrrDs  zFeedParser._pop_messageccs6|jg}xb|jD]X}|tkr(tVqtj|sbtj|s`tj}|jj |j ||jj |P|j |qW|j ||jrg}x2|jj}|tkrtVq|dkrP|j |qW|j jtj|dS|j jdkrx|jjtjx$|jD]}|tkrtVqPqW|j}|jjx&|jj}|tkrFtVq(Pq(Wx&|jj}|tkrntVqPPqPW|dkrP|jj |qWdS|j jdkrx(|jD]}|tkrtVqPqW|jdS|j jdkr|j j}|dkrbtj}|jj |j |g}x.|jD]$}|tkrtj+}|jj |j ||j jtj| g}x$|jD]}|tkrtVqqWtj||j _'dS| s`tj,}|jj |j |dS| rndg}ng}x.|jD]$}|tkrtVqz|j |qzW|r|d}t-j|}|r|t$|j!dd|d<tj||j _'dSg}x.|jD]$}|tkrtVq|j |qW|j jtj|dS)Nrzmessage/delivery-statusmessagerCzcontent-transfer-encoding8bit7bitbinaryz--z(?Pz4)(?P--)?(?P[ \t]*)(?P\r\n|\r|\n)?$TFendlinesepr%r)rOrNrPr&r&).rKr9rheaderREmatchNLCRErZ MissingHeaderBodySeparatorDefectr4rFr=r#r_parse_headersr?r"Z set_payload EMPTYSTRINGjoinrIrr;rDrrEZ get_boundaryZNoBoundaryInMultipartDefectgetlowerZ-InvalidMultipartContentTransferEncodingDefectrecompileescapegroup NLCRE_eolsearchlenpreambler>epilogueZ_payload isinstancestrZStartBoundaryNotFoundDefectZCloseBoundaryNotFoundDefect NLCRE_bol)rZheadersr!rHr-rLrJboundaryZ separatorZ boundaryreZcapturing_preamblerbrRZclose_boundary_seenmoZlastlineZeolmorcrQZpayload firstlineZbolmorrrr;sf                                                zFeedParser._parsegenc Cs^d}g}x4t|D]&\}}|ddkrV|sJtj|}|jj|j|q|j|q|rx|jj|jj|dg}}|j dr|dkrt j |}|r|dt |j d }|jj|qn:|t |dkr|jj|dStj|}|jjj|q|jd}|dkr*tjd}|jjj|q|d|}|g}qW|rZ|jj|jj|dS)Nrrz zFrom r%:zMissing header name.) enumeraterZ#FirstHeaderLineIsContinuationDefectr4rFr=rZset_rawZheader_source_parse startswithr_r`rar^Z set_unixfromr9r#ZMisplacedEnvelopeHeaderDefectZdefectsfindZInvalidHeaderDefect) rr-Z lastheaderZ lastvaluelinenor!rHrhirrrrVsF              zFeedParser._parse_headers)N) r1r2r3rrr@rBrArrKrDr;rVrrrrrs  ~cseZdZfddZZS)rcstj|jdddS)Nasciisurrogateescape)superrBdecode)rr)) __class__rrrBszBytesFeedParser.feed)r1r2r3rB __classcell__rr)rtrrs)__all__r[ZemailrZemail._policybaser collectionsriorr\rUrfr_Z NLCRE_crackrSrWNLobjectrr rrrrrrs&         [feedparser.cpython-36.pyc000064400000024626147204636050011333 0ustar003 \X@sdZddgZddlZddlmZddlmZddlmZddl m Z ej d Z ej d Z ej d Zej d Zej d Zd ZdZeZGdddeZGdddZGdddeZdS)aFeedParser - An email feed parser. The feed parser implements an interface for incrementally parsing an email message, line by line. This has advantages for certain applications, such as those reading email messages off a socket. FeedParser.feed() is the primary interface for pushing new data into the parser. It returns when there's nothing more it can do with the available data. When you have no more data to push into the parser, call .close(). This completes the parsing and returns the root message object. The other advantage of this parser is that it will never raise a parsing exception. Instead, when it finds something unexpected, it adds a 'defect' to the current message. Defects are just instances that live on the message object's .defects attribute. FeedParserBytesFeedParserN)errors)compat32)deque)StringIOz \r\n|\r|\nz (\r\n|\r|\n)z(\r\n|\r|\n)\Zz%^(From |[\041-\071\073-\176]*:|[\t ]) c@s`eZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ ddZ ddZ dS)BufferedSubFileakA file-ish object that can have new data loaded into it. You can also push and pop line-matching predicates onto a stack. When the current predicate matches the current line, a false EOF response (i.e. empty string) is returned instead. This lets the parser adhere to a simple abstraction -- it parses until EOF closes the current message. cCs$tdd|_t|_g|_d|_dS)Nr)newlineF)r_partialr_lines _eofstack_closed)selfr(/usr/lib64/python3.6/email/feedparser.py__init__5s zBufferedSubFile.__init__cCs|jj|dS)N)rappend)rZpredrrrpush_eof_matcher@sz BufferedSubFile.push_eof_matchercCs |jjS)N)rpop)rrrrpop_eof_matcherCszBufferedSubFile.pop_eof_matchercCs<|jjd|j|jj|jjd|jjd|_dS)NrT)r seek pushlines readlinestruncater)rrrrcloseFs    zBufferedSubFile.closecCsN|js|jrdStS|jj}x*t|jD]}||r*|jj|dSq*W|S)Nr)r r NeedMoreDatapopleftreversedr appendleft)rlineZateofrrrreadlineNs  zBufferedSubFile.readlinecCs|tk s t|jj|dS)N)rAssertionErrorr r )rr!rrr unreadline`s zBufferedSubFile.unreadlinecCsx|jj|d|kr d|kr dS|jjd|jj}|jjd|jj|djdsj|jj|j|j|dS)z$Push some new data into this object.r  Nr)r writerrrendswithrr)rdatapartsrrrpushes     zBufferedSubFile.pushcCs|jj|dS)N)r extend)rlinesrrrrzszBufferedSubFile.pushlinescCs|S)Nr)rrrr__iter__}szBufferedSubFile.__iter__cCs|j}|dkrt|S)Nr)r" StopIteration)rr!rrr__next__szBufferedSubFile.__next__N)__name__ __module__ __qualname____doc__rrrrr"r$r,rr/r1rrrrr -s r c@s`eZdZdZdedddZddZdd Zd d Zd d Z ddZ ddZ ddZ ddZ dS)rzA feed-style parser of email.N)policyc Cs||_d|_|dkr<|jdkr2ddlm}||_qn|j|_n2||_y||jdWntk rld|_YnXt|_g|_ |j j |_ d|_ d|_d|_dS)a_factory is called with no arguments to create a new message obj The policy keyword specifies a policy object that controls a number of aspects of the parser's operation. The default policy maintains backward compatibility. FNr)Message)r6T)r6_old_style_factoryZmessage_factoryZ email.messager7_factory TypeErrorr _input _msgstack _parsegenr1_parse_cur_last _headersonly)rr9r6r7rrrrs$     zFeedParser.__init__cCs d|_dS)NT)rA)rrrr_set_headersonlyszFeedParser._set_headersonlycCs|jj||jdS)zPush more data into the parser.N)r;r, _call_parse)rr*rrrfeeds zFeedParser.feedc Cs&y |jWntk r YnXdS)N)r>r0)rrrrrCs zFeedParser._call_parsecCsV|jj|j|j}|j s&t|jdkrR|j rRtj }|j j |||S)zz4)(?P--)?(?P[ \t]*)(?P\r\n|\r|\n)?$TFendlinesepr&r)rQrPrRr'r')/rMr;rheaderREmatchNLCRErZ MissingHeaderBodySeparatorDefectr6rHr?r$r_parse_headersrAr"Z set_payload EMPTYSTRINGjoinrKrr=rFrrGZ get_boundaryZNoBoundaryInMultipartDefectgetlowerZ-InvalidMultipartContentTransferEncodingDefectrecompileescapegroup NLCRE_eolsearchlenpreambler@epilogueZ_payload isinstancestrr#ZStartBoundaryNotFoundDefectZCloseBoundaryNotFoundDefect NLCRE_bol)rZheadersr!rJr.rNrLboundaryZ separatorZ boundaryreZcapturing_preamblerdrTZclose_boundary_seenmoZlastlineZeolmorerSZpayload firstlineZbolmorrrr=sh                                                 zFeedParser._parsegenc Cspd}g}xFt|D]8\}}|ddkrV|sJtj|}|jj|j|q|j|q|rx|jj|jj|dg}}|j dr|dkrt j |}|r|dt |j d }|jj|qn:|t |dkr|jj|dStj|}|jjj|q|jd}|dkr*tjd}|jjj|q|dkss(         [generator.cpython-36.opt-1.pyc000064400000031205147204636050012127 0ustar003 fP@sdZdddgZddlZddlZddlZddlZddlmZddlm Z m Z ddl m Z dd l mZd Zd Zejd Zejd ejZejdZGdddZGdddeZdZGdddeZeeejdZdeZejZdS)z:Classes to generate plain text from a message object tree. GeneratorDecodedGeneratorBytesGeneratorN)deepcopy)StringIOBytesIO)_has_surrogates)HeaderWriteError_ z \r\n|\r|\nz^From z\r\n[^ \t]|\r[^ \n\t]|\n[^ \t]c@seZdZdZd'ddddZddZd(d d Zd d Zd dZddZ ddZ ddZ ddZ ddZ ddZeZddZddZdd Zd!d"Zed)d#d$Zed%d&ZdS)*rzGenerates output from a Message object tree. This basic generator writes the message to the given file object as plain text. N)policycCs6|dkr|dkrdn|j}||_||_||_||_dS)aCreate the generator for message flattening. outfp is the output file-like object for writing the message to. It must have a write() method. Optional mangle_from_ is a flag that, when True (the default if policy is not set), escapes From_ lines in the body of the message by putting a `>' in front of them. Optional maxheaderlen specifies the longest length for a non-continued header. When a header line is longer (in characters, with tabs expanded to 8 spaces) than maxheaderlen, the header will split as defined in the Header class. Set maxheaderlen to zero to disable header wrapping. The default is 78, as recommended (but not required) by RFC 2822. The policy keyword specifies a policy object that controls a number of aspects of the generator's operation. If no policy is specified, the policy associated with the Message object passed to the flatten method is used. NT) mangle_from__fp _mangle_from_ maxheaderlenr )selfoutfpr rr r'/usr/lib64/python3.6/email/generator.py__init__&s zGenerator.__init__cCs|jj|dS)N)rwrite)rsrrrrFszGenerator.writeFc Cs|jdkr|jn|j}|dk r*|j|d}|jdk rB|j|jd}|j|_|j|j|_d|_|j|j|_|j}|j}zL||_||_|r|j }|sdt j t j }|j ||j|j |Wd||_||_XdS)aPrint the message object tree rooted at msg to the output file specified when the Generator instance was created. unixfrom is a flag that forces the printing of a Unix From_ delimiter before the first object in the message tree. If the original message has no From_ delimiter, a `standard' one is crafted. By default, this is False to inhibit the printing of any From_ delimiter. Note that for subobjects, no From_ line is printed. linesep specifies the characters used to indicate a new line in the output. The default value is determined by the policy specified when the Generator instance was created or, if none was specified, from the policy associated with the msg. N)linesep)max_line_lengthz From nobody )r clonerr_NL_encode _encoded_NLZ_EMPTY_encoded_EMPTYZ get_unixfromtimeZctimer_write)rmsgunixfromrr Zold_gen_policyZold_msg_policyZufromrrrflattenJs,  zGenerator.flattencCs|j||jd|jdS)z1Clone this generator with the exact same options.N)r ) __class__rr )rfprrrr{szGenerator.clonecCstS)N)r)rrrr _new_bufferszGenerator._new_buffercCs|S)Nr)rrrrrrszGenerator._encodecCsX|sdStj|}x*|ddD]}|j||j|jq W|drT|j|ddS)Nr)r))NLCREsplitrr)rlineslinerrr _write_liness  zGenerator._write_linesc Cs|j}z"d|_|j|_}|j|Wd||_|j}|`X|rht|}|jd|d|jd|dt|dd}|dkr|j|n|||jj|j dS)Nzcontent-transfer-encodingrz content-typer(_write_headers) r _munge_cter' _dispatchrZreplace_headergetattrr/rgetvalue)rr"ZoldfpZsfpZ munge_ctemethrrrr!s"   zGenerator._writecCst|j}|j}tj||fjdd}t|d|d}|dkrh|jdd}t|d|d}|dkrh|j}||dS)N-r Z_handle_)get_content_maintypeget_content_subtype UNDERSCOREjoinreplacer2 _writeBody)rr"mainsubZspecificr4Zgenericrrrr1s zGenerator._dispatchcCsx|jD]\}}|jj||}|jjr|jj}|j|jjsRtd|d||}|j|rr|dt| }tj |rtd||j |q W|j |j dS)Nz folded header does not end with z: z folded header contains newline: ) raw_itemsr ZfoldZverify_generated_headersrendswithr lenNEWLINE_WITHOUT_FWSPsearchrr)rr"hvZfoldedrZfolded_no_lineseprrrr/s   zGenerator._write_headerscCs|j}|dkrdSt|ts.tdt|t|jr~|jd}|dk r~t|}|d=|j |||j}|d|df|_ |j rt j d|}|j|dS)Nzstring payload expected: %scharsetzcontent-transfer-encodingz content-typez>From ) get_payload isinstancestr TypeErrortyper_payloadZ get_paramrZ set_payloadr0rfcrer=r.)rr"payloadrErrr _handle_texts"      zGenerator._handle_textc Csg}|j}|dkrg}n(t|tr2|j|dSt|tsB|g}x>|D]6}|j}|j|}|j|d|jd|j |j qHW|j }|s|j j |}|j|}|j||jdk r|jrtjd|j} n|j} |j| |j|j|jd||j|r|jj|jdx4|D],} |j|jd||j|jj| qW|j|jd|d|j|jdk r|jrtjd|j} n|j} |j| dS)NF)r#rz>From z--r)rFrGrHrlistr'rr$rappendr3Z get_boundaryrr9_make_boundaryZ set_boundarypreamblerrLr=r.rpopepilogue) rr"ZmsgtextsZsubpartspartrgboundaryZalltextrRZ body_partrTrrr_handle_multipart sJ             zGenerator._handle_multipartc Cs0|j}|jdd|_z|j|Wd||_XdS)Nr)r)r rrX)rr"prrr_handle_multipart_signedFs z"Generator._handle_multipart_signedcCsg}x|jD]t}|j}|j|}|j|d|jd|j}|j|j}|rx|d|jkrx|j |jj |ddq|j |qW|j j |jj |dS)NF)r#rr(r)r)) rFr'rr$rr3r+rrrPr9rr)rr"ZblocksrUrrVtextr,rrr_handle_message_delivery_statusQs  z)Generator._handle_message_delivery_statuscCs^|j}|j|}|j}t|trD|j|jdd|jd|j}n |j |}|j j |dS)NrF)r#r) r'rrKrGrOr$rFrr3rrr)rr"rrVrMrrr_handle_messagefs    zGenerator._handle_messagecCsztjtj}d t|d}|dkr(|S|}d}xD|jdtj|dtj}|j |sZP|dt |}|d7}q2W|S) N=z==rz^--z(--)?$.r(z===============) randomZ randrangesysmaxsize_fmt _compile_rereescape MULTILINErBrH)clsr[tokenrWbZcounterZcrerrrrQs   zGenerator._make_boundarycCs tj||S)N)rfcompile)rirflagsrrrreszGenerator._compile_re)NN)FN)N)__name__ __module__ __qualname____doc__rrr$rr'rr.r!r1r/rNr;rXrZr\r] classmethodrQrerrrrrs* 1#:  csPeZdZdZddZddZddZdd Zfd d ZeZ e d d Z Z S)raGenerates a bytes version of a Message object tree. Functionally identical to the base Generator except that the output is bytes and not string. When surrogates were used in the input to encode bytes, these are decoded back to bytes for output. If the policy has cte_type set to 7bit, then the message is transformed such that the non-ASCII bytes are properly content transfer encoded, using the charset unknown-8bit. The outfp object must accept bytes in its write method. cCs|jj|jdddS)Nasciisurrogateescape)rrencode)rrrrrrszBytesGenerator.writecCstS)N)r)rrrrr'szBytesGenerator._new_buffercCs |jdS)Nrs)ru)rrrrrrszBytesGenerator._encodecCs<x*|jD]\}}|jj|jj||q W|j|jdS)N)r>rrr Z fold_binaryr)rr"rCrDrrrr/szBytesGenerator._write_headerscs^|jdkrdSt|jrJ|jjdk rJ|jrFrom ) rKrr Zcte_typerrLr=r.superrrN)rr")r%rrrNs zBytesGenerator._handle_textcCstj|jd|S)Nrs)rfrlru)rirrmrrrreszBytesGenerator._compile_re) rnrorprqrr'rr/rNr;rrre __classcell__rr)r%rrs  zD[Non-text (%(type)s) part of message omitted, filename %(filename)s]c@s(eZdZdZdddddZddZdS) rzGenerates a text representation of a message. Like the Generator base class, except that non-text parts are substituted with a format string representing the part. N)r cCs.tj|||||d|dkr$t|_n||_dS)aLike Generator.__init__() except that an additional optional argument is allowed. Walks through all subparts of a message. If the subpart is of main type `text', then it prints the decoded payload of the subpart. Otherwise, fmt is a format string that is used instead of the message payload. fmt is expanded with the following keywords (in %(keyword)s format): type : Full MIME type of the non-text part maintype : Main MIME type of the non-text part subtype : Sub-MIME type of the non-text part filename : Filename of the non-text part description: Description associated with the non-text part encoding : Content transfer encoding of the non-text part The default value for fmt is None, meaning [Non-text (%(type)s) part of message omitted, filename %(filename)s] )r N)rr_FMTrd)rrr rZfmtr rrrrs  zDecodedGenerator.__init__c Csx|jD]v}|j}|dkr4t|jdd|dq |dkr>q t|j|j|j|j|jd|jdd|jd d d |dq WdS) Nr[F)decode)fileZ multipartz [no filename]zContent-Descriptionz[no description]zContent-Transfer-Encodingz [no encoding])rJmaintypesubtypefilenameZ descriptionencoding) walkr6printrFrdZget_content_typer7 get_filenameget)rr"rUr{rrrr1s  zDecodedGenerator._dispatch)NNN)rnrorprqrr1rrrrrsr(z%%0%dd) rq__all__rfrbr racopyriorrZ email.utilsrZ email.errorsr r8NLrlr*rhrLrArrrxrr@reprrcZ_widthrdrQrrrrs.      |3;generator.cpython-36.pyc000064400000031205147204636050011170 0ustar003 fP@sdZdddgZddlZddlZddlZddlZddlmZddlm Z m Z ddl m Z dd l mZd Zd Zejd Zejd ejZejdZGdddZGdddeZdZGdddeZeeejdZdeZejZdS)z:Classes to generate plain text from a message object tree. GeneratorDecodedGeneratorBytesGeneratorN)deepcopy)StringIOBytesIO)_has_surrogates)HeaderWriteError_ z \r\n|\r|\nz^From z\r\n[^ \t]|\r[^ \n\t]|\n[^ \t]c@seZdZdZd'ddddZddZd(d d Zd d Zd dZddZ ddZ ddZ ddZ ddZ ddZeZddZddZdd Zd!d"Zed)d#d$Zed%d&ZdS)*rzGenerates output from a Message object tree. This basic generator writes the message to the given file object as plain text. N)policycCs6|dkr|dkrdn|j}||_||_||_||_dS)aCreate the generator for message flattening. outfp is the output file-like object for writing the message to. It must have a write() method. Optional mangle_from_ is a flag that, when True (the default if policy is not set), escapes From_ lines in the body of the message by putting a `>' in front of them. Optional maxheaderlen specifies the longest length for a non-continued header. When a header line is longer (in characters, with tabs expanded to 8 spaces) than maxheaderlen, the header will split as defined in the Header class. Set maxheaderlen to zero to disable header wrapping. The default is 78, as recommended (but not required) by RFC 2822. The policy keyword specifies a policy object that controls a number of aspects of the generator's operation. If no policy is specified, the policy associated with the Message object passed to the flatten method is used. NT) mangle_from__fp _mangle_from_ maxheaderlenr )selfoutfpr rr r'/usr/lib64/python3.6/email/generator.py__init__&s zGenerator.__init__cCs|jj|dS)N)rwrite)rsrrrrFszGenerator.writeFc Cs|jdkr|jn|j}|dk r*|j|d}|jdk rB|j|jd}|j|_|j|j|_d|_|j|j|_|j}|j}zL||_||_|r|j }|sdt j t j }|j ||j|j |Wd||_||_XdS)aPrint the message object tree rooted at msg to the output file specified when the Generator instance was created. unixfrom is a flag that forces the printing of a Unix From_ delimiter before the first object in the message tree. If the original message has no From_ delimiter, a `standard' one is crafted. By default, this is False to inhibit the printing of any From_ delimiter. Note that for subobjects, no From_ line is printed. linesep specifies the characters used to indicate a new line in the output. The default value is determined by the policy specified when the Generator instance was created or, if none was specified, from the policy associated with the msg. N)linesep)max_line_lengthz From nobody )r clonerr_NL_encode _encoded_NLZ_EMPTY_encoded_EMPTYZ get_unixfromtimeZctimer_write)rmsgunixfromrr Zold_gen_policyZold_msg_policyZufromrrrflattenJs,  zGenerator.flattencCs|j||jd|jdS)z1Clone this generator with the exact same options.N)r ) __class__rr )rfprrrr{szGenerator.clonecCstS)N)r)rrrr _new_bufferszGenerator._new_buffercCs|S)Nr)rrrrrrszGenerator._encodecCsX|sdStj|}x*|ddD]}|j||j|jq W|drT|j|ddS)Nr)r))NLCREsplitrr)rlineslinerrr _write_liness  zGenerator._write_linesc Cs|j}z"d|_|j|_}|j|Wd||_|j}|`X|rht|}|jd|d|jd|dt|dd}|dkr|j|n|||jj|j dS)Nzcontent-transfer-encodingrz content-typer(_write_headers) r _munge_cter' _dispatchrZreplace_headergetattrr/rgetvalue)rr"ZoldfpZsfpZ munge_ctemethrrrr!s"   zGenerator._writecCst|j}|j}tj||fjdd}t|d|d}|dkrh|jdd}t|d|d}|dkrh|j}||dS)N-r Z_handle_)get_content_maintypeget_content_subtype UNDERSCOREjoinreplacer2 _writeBody)rr"mainsubZspecificr4Zgenericrrrr1s zGenerator._dispatchcCsx|jD]\}}|jj||}|jjr|jj}|j|jjsRtd|d||}|j|rr|dt| }tj |rtd||j |q W|j |j dS)Nz folded header does not end with z: z folded header contains newline: ) raw_itemsr ZfoldZverify_generated_headersrendswithr lenNEWLINE_WITHOUT_FWSPsearchrr)rr"hvZfoldedrZfolded_no_lineseprrrr/s   zGenerator._write_headerscCs|j}|dkrdSt|ts.tdt|t|jr~|jd}|dk r~t|}|d=|j |||j}|d|df|_ |j rt j d|}|j|dS)Nzstring payload expected: %scharsetzcontent-transfer-encodingz content-typez>From ) get_payload isinstancestr TypeErrortyper_payloadZ get_paramrZ set_payloadr0rfcrer=r.)rr"payloadrErrr _handle_texts"      zGenerator._handle_textc Csg}|j}|dkrg}n(t|tr2|j|dSt|tsB|g}x>|D]6}|j}|j|}|j|d|jd|j |j qHW|j }|s|j j |}|j|}|j||jdk r|jrtjd|j} n|j} |j| |j|j|jd||j|r|jj|jdx4|D],} |j|jd||j|jj| qW|j|jd|d|j|jdk r|jrtjd|j} n|j} |j| dS)NF)r#rz>From z--r)rFrGrHrlistr'rr$rappendr3Z get_boundaryrr9_make_boundaryZ set_boundarypreamblerrLr=r.rpopepilogue) rr"ZmsgtextsZsubpartspartrgboundaryZalltextrRZ body_partrTrrr_handle_multipart sJ             zGenerator._handle_multipartc Cs0|j}|jdd|_z|j|Wd||_XdS)Nr)r)r rrX)rr"prrr_handle_multipart_signedFs z"Generator._handle_multipart_signedcCsg}x|jD]t}|j}|j|}|j|d|jd|j}|j|j}|rx|d|jkrx|j |jj |ddq|j |qW|j j |jj |dS)NF)r#rr(r)r)) rFr'rr$rr3r+rrrPr9rr)rr"ZblocksrUrrVtextr,rrr_handle_message_delivery_statusQs  z)Generator._handle_message_delivery_statuscCs^|j}|j|}|j}t|trD|j|jdd|jd|j}n |j |}|j j |dS)NrF)r#r) r'rrKrGrOr$rFrr3rrr)rr"rrVrMrrr_handle_messagefs    zGenerator._handle_messagecCsztjtj}d t|d}|dkr(|S|}d}xD|jdtj|dtj}|j |sZP|dt |}|d7}q2W|S) N=z==rz^--z(--)?$.r(z===============) randomZ randrangesysmaxsize_fmt _compile_rereescape MULTILINErBrH)clsr[tokenrWbZcounterZcrerrrrQs   zGenerator._make_boundarycCs tj||S)N)rfcompile)rirflagsrrrreszGenerator._compile_re)NN)FN)N)__name__ __module__ __qualname____doc__rrr$rr'rr.r!r1r/rNr;rXrZr\r] classmethodrQrerrrrrs* 1#:  csPeZdZdZddZddZddZdd Zfd d ZeZ e d d Z Z S)raGenerates a bytes version of a Message object tree. Functionally identical to the base Generator except that the output is bytes and not string. When surrogates were used in the input to encode bytes, these are decoded back to bytes for output. If the policy has cte_type set to 7bit, then the message is transformed such that the non-ASCII bytes are properly content transfer encoded, using the charset unknown-8bit. The outfp object must accept bytes in its write method. cCs|jj|jdddS)Nasciisurrogateescape)rrencode)rrrrrrszBytesGenerator.writecCstS)N)r)rrrrr'szBytesGenerator._new_buffercCs |jdS)Nrs)ru)rrrrrrszBytesGenerator._encodecCs<x*|jD]\}}|jj|jj||q W|j|jdS)N)r>rrr Z fold_binaryr)rr"rCrDrrrr/szBytesGenerator._write_headerscs^|jdkrdSt|jrJ|jjdk rJ|jrFrom ) rKrr Zcte_typerrLr=r.superrrN)rr")r%rrrNs zBytesGenerator._handle_textcCstj|jd|S)Nrs)rfrlru)rirrmrrrreszBytesGenerator._compile_re) rnrorprqrr'rr/rNr;rrre __classcell__rr)r%rrs  zD[Non-text (%(type)s) part of message omitted, filename %(filename)s]c@s(eZdZdZdddddZddZdS) rzGenerates a text representation of a message. Like the Generator base class, except that non-text parts are substituted with a format string representing the part. N)r cCs.tj|||||d|dkr$t|_n||_dS)aLike Generator.__init__() except that an additional optional argument is allowed. Walks through all subparts of a message. If the subpart is of main type `text', then it prints the decoded payload of the subpart. Otherwise, fmt is a format string that is used instead of the message payload. fmt is expanded with the following keywords (in %(keyword)s format): type : Full MIME type of the non-text part maintype : Main MIME type of the non-text part subtype : Sub-MIME type of the non-text part filename : Filename of the non-text part description: Description associated with the non-text part encoding : Content transfer encoding of the non-text part The default value for fmt is None, meaning [Non-text (%(type)s) part of message omitted, filename %(filename)s] )r N)rr_FMTrd)rrr rZfmtr rrrrs  zDecodedGenerator.__init__c Csx|jD]v}|j}|dkr4t|jdd|dq |dkr>q t|j|j|j|j|jd|jdd|jd d d |dq WdS) Nr[F)decode)fileZ multipartz [no filename]zContent-Descriptionz[no description]zContent-Transfer-Encodingz [no encoding])rJmaintypesubtypefilenameZ descriptionencoding) walkr6printrFrdZget_content_typer7 get_filenameget)rr"rUr{rrrr1s  zDecodedGenerator._dispatch)NNN)rnrorprqrr1rrrrrsr(z%%0%dd) rq__all__rfrbr racopyriorrZ email.utilsrZ email.errorsr r8NLrlr*rhrLrArrrxrr@reprrcZ_widthrdrQrrrrs.      |3;header.cpython-36.opt-1.pyc000064400000040142147204636050011371 0ustar003 \&^@sdZdddgZddlZddlZddlZddlZddlmZddlm Z e j Z dZ d Z d ZdZd Zd ZdZe dZe dZejdejejBejBZejdZejdZejjZddZdddZGdddZ GdddZ!Gddde"Z#dS)z+Header encoding and decoding functionality.Header decode_header make_headerN)HeaderParseError)charset   Nz zus-asciizutf-8ai =\? # literal =? (?P[^?]*?) # non-greedy up to the next ? is the charset \? # literal ? (?P[qb]) # either a "q" or a "b", case insensitive \? # literal ? (?P.*?) # non-greedy up to the next ?= is the encoded string \?= # literal ?= z[\041-\176]+:$z \n[^ \t]+:c Cst|drdd|jDStj|s.|dfgSg}x|jD]}tj|}d}xp|r|jd}|rn|j}d}|r|j|ddf|rP|jdj }|jdj }|jd}|j|||fqPWqMsz!decode_header..NTrFqbz===zBase64 decoding errorzUnexpected encoding: zraw-unicode-escape)hasattrr ecresearch splitlinessplitpoplstripappendlower enumerateisspacereversedemail quoprimimeZ header_decodelenZ base64mimedecodebinasciiErrorrAssertionError isinstancerbytesBSPACE)headerZwordslinepartsfirstZ unencodedrencodingZencodedZdroplistnwdZ decoded_wordsZencoded_stringZwordZpaderrZ collapsedZ last_word last_charsetrrrr=sz       4           cCsLt|||d}x8|D]0\}}|dk r8t|t r8t|}|j||qW|S)aCreate a Header from a sequence of pairs as returned by decode_header() decode_header() takes a header value string and returns a sequence of pairs of the format (decoded_string, charset) where charset is the string name of the character set. This function takes one of those sequence of pairs and returns a Header instance. Optional maxlinelen, header_name, and continuation_ws are as in the Header constructor. ) maxlinelen header_namecontinuation_wsN)rr-Charsetr!)Z decoded_seqr9r:r;hsrrrrrs c@sJeZdZdddZddZdd Zdd d Zd d ZdddZddZ dS)rNrstrictcCs||dkrt}nt|ts t|}||_||_g|_|dk rH|j||||dkrTt}||_|dkrjd|_ nt |d|_ dS)aDCreate a MIME-compliant header that can contain many character sets. Optional s is the initial header value. If None, the initial header value is not set. You can later append to the header with .append() method calls. s may be a byte string or a Unicode string, but see the .append() documentation for semantics. Optional charset serves two purposes: it has the same meaning as the charset argument to the .append() method. It also sets the default character set for all subsequent .append() calls that omit the charset argument. If charset is not provided in the constructor, the us-ascii charset is used both as s's initial charset and as the default for subsequent .append() calls. The maximum line length can be specified explicitly via maxlinelen. For splitting the first line to a shorter value (to account for the field header which isn't included in s, e.g. `Subject') pass in the name of the field in header_name. The default maxlinelen is 78 as recommended by RFC 2822. continuation_ws must be RFC 2822 compliant folding whitespace (usually either a space or a hard tab) which will be prepended to continuation lines. errors is passed through to the .append() call. Nrr) USASCIIr-r<r_continuation_wsr r! MAXLINELEN _maxlinelen _headerlenr()selfr>rr9r:r;errorsrrr__init__s zHeader.__init__c Cs|jg}d}d}x|jD]\}}|}|tjkrJ|jdd}|jdd}|r|o^|j|d}|dkr|d kr| r|jtd}n|d kr| r|jt|o|j|d }|}|j|qWt j |S) z&Return the string value of the header.Nasciisurrogateescapereplacerus-asciir)NrK)NrK)NrK) _normalizer r UNKNOWN8BITencoder) _nonctextr!SPACE EMPTYSTRINGjoin) rEZuchunkslastcs lastspacerrZnextcsZoriginal_byteshasspacerrr__str__s*     zHeader.__str__cCs |t|kS)N)r)rEotherrrr__eq__sz Header.__eq__c Cs|dkr|j}nt|ts"t|}t|tsZ|jp4d}|tjkrN|jdd}n |j||}|jpbd}|tjkry|j||Wn"t k r|dkrt }YnX|j j ||fdS)a.Append a string to the MIME header. Optional charset, if given, should be a Charset instance or the name of a character set (which will be converted to a Charset instance). A value of None (the default) means that the charset given in the constructor is used. s may be a byte string or a Unicode string. If it is a byte string (i.e. isinstance(s, str) is false), then charset is the encoding of that byte string, and a UnicodeError will be raised if the string cannot be decoded with that charset. If s is a Unicode string, then charset is a hint specifying the character set of the characters in the string. In either case, when producing an RFC 2822 compliant header using RFC 2047 rules, the string will be encoded using the output codec of the charset. If the string cannot be encoded to the output codec, a UnicodeError will be raised. Optional `errors' is passed as the errors argument to the decode call if s is a byte string. Nzus-asciirI) rr-r<rZ input_codecrNr)Z output_codecrOUnicodeEncodeErrorUTF8r r!)rEr>rrFZ input_charsetZoutput_charsetrrrr! s$        z Header.appendcCs|jp|dkS)z=True if string s is not a ctext character of RFC822. ()\)r\r]r^)r$)rEr>rrrrP4szHeader._nonctext;, rcCs|j|dkr|j}|dkr"d}t|j||j|}d}d}}x4|jD](\}} |dk r|ol|j|d}|d kr| s| d kr|jn| d kr| r|j|o|j|d }| }d}|j} | r|j d| d| n|j dd| xr| ddD]b} |j | j dk r,|j |jd| j | n.| j } | dt | t | } |j | | | qWt | dkrJ|j qJW|jr|j|j|}tj|rtd j||S)aEncode a message header into an RFC-compliant format. There are many issues involved in converting a given string for use in an email header. Only certain character sets are readable in most email clients, and as header strings can only contain a subset of 7-bit ASCII, care must be taken to properly convert and encode (with Base64 or quoted-printable) header strings. In addition, there is a 75-character length limit on any given encoded header field, so line-wrapping must be performed, even with double-byte character sets. Optional maxlinelen specifies the maximum length of each generated line, exclusive of the linesep string. Individual lines may be longer than maxlinelen if a folding point cannot be found. The first line will be shorter by the length of the header name plus ": " if a header name was specified at Header construction time. The default value for maxlinelen is determined at header construction time. Optional splitchars is a string containing characters which should be given extra weight by the splitting algorithm during normal header wrapping. This is in very rough support of RFC 2822's `higher level syntactic breaks': split points preceded by a splitchar are preferred during line splitting, with the characters preferred in the order in which they appear in the string. Space and tab may be included in the string to indicate whether preference should be given to one over the other as a split point when other split chars do not appear in the line being split. Splitchars does not affect RFC 2047 encoded lines. Optional linesep is a string to be used to separate the lines of the value. The default value is the most useful for typical Python applications, but it can be set to \r\n to produce RFC-compliant line separators when needed. Nri@Bus-asciirFr rz8header value appears to contain an embedded header: {!r})Nr`)Nr`)Nr`rL)rMrC_ValueFormatterrDrAr rPadd_transitionrfeednewlineheader_encodingr r(_str_embedded_headerrrformat)rE splitcharsr9linesepZ formatterrTrVrUrrlinesr1ZslinefwsvaluerrrrO9sR!       z Header.encodecCs|g}d}g}xL|jD]B\}}||kr0|j|q|dk rL|jtj||f|g}|}qW|rr|jtj||f||_dS)N)r r!rQrS)rEZchunksr8Z last_chunkrrrrrrMs zHeader._normalize)NNNNrr?)Nr?)r_Nr) __name__ __module__ __qualname__rGrWrYr!rPrOrMrrrrrs -  + Pc@sTeZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ dS)racCs0||_||_t||_||_g|_t||_dS)N)_maxlenrAr(_continuation_ws_len _splitchars_lines _Accumulator _current_line)rEZ headerlenmaxlenr;rirrrrGs  z_ValueFormatter.__init__cCs|j|j|jS)N)rdrSrt)rErjrrrrfsz_ValueFormatter._strcCs |jtS)N)rfNL)rErrrrWsz_ValueFormatter.__str__cCsp|jj}|dkr|jj|t|jdkrb|jjrP|jdt|j7<n|jjt|j|jjdS)Nrr rr)rr rL) rvrpushr( is_onlywsrtrr!reset)rEZ end_of_linerrrrds   z_ValueFormatter.newlinecCs|jjdddS)Nrr )rvry)rErrrrbsz_ValueFormatter.add_transitioncCs|jdkr|j|||jdS|j||j}y|jd}Wntk rPdSX|dk rf|j||y |j}Wntk rdSX|j|j j |j |x|D]}|j j |j |qWdS)Nr)re _ascii_splitrsZheader_encode_lines _maxlengthsr IndexError _append_chunkrdrvryrArtr!)rErlrrZ encoded_linesZ first_line last_liner1rrrrcs$    z_ValueFormatter.feedccs*|jt|jVx|j|jVqWdS)N)rqr(rvrr)rErrrr}sz_ValueFormatter._maxlengthscCsjtjdtd||}|dr0dg|dd<n |jdx*tt|gdD]\}}|j||qNWdS)Nz([z]+)rr r)rerFWSrzipiterr)rErlrrir2partrrrr|s  z_ValueFormatter._ascii_splitcCs |jj||t|j|jkrx|jD]t}xlt|jjdddD]P}|jrp|j|d}|rp|d|krpP|j|dd}|rD|d|krDPqDWq(Pq(W|jj\}}|jj dkr|j |sd}|jj||dS|jj |}|j j t|j|jj|dS)NrrrrLrL)rvryr(rqrsrange part_countr$r _initial_sizerdpop_fromrtr!rr{)rErlrZchiZprevpartrZ remainderrrrrs.   z_ValueFormatter._append_chunkN) rnrorprGrfrWrdrbrcr}r|rrrrrras %racsjeZdZdfdd ZddZdddZfdd Zd d Zd d ZdddZ ddZ fddZ Z S)rurcs||_tjdS)N)rsuperrG)rEZ initial_size) __class__rrrGsz_Accumulator.__init__cCs|j||fdS)N)r!)rErlrrrrry#sz_Accumulator.pushcCs||d}g||d<|S)Nr)rErZpoppedrrrr&s  z_Accumulator.pop_fromcs|jdkrdStjS)Nrr )r r )rrr)rE)rrrr+s z_Accumulator.popcCstdd|D|jS)Ncss"|]\}}t|t|VqdS)N)r()rrlrrrr 1sz'_Accumulator.__len__..)sumr)rErrr__len__0sz_Accumulator.__len__cCstjdd|DS)Ncss |]\}}tj||fVqdS)N)rRrS)rrlrrrrr5sz'_Accumulator.__str__..)rRrS)rErrrrW4s z_Accumulator.__str__NcCs"|dkr g}||dd<d|_dS)Nr)r)rEZstartvalrrrr{8s z_Accumulator.resetcCs|jdko| pt|jS)Nr)rrr$)rErrrrz>sz_Accumulator.is_onlywscs tjS)N)rr)rE)rrrrAsz_Accumulator.part_count)r)r)N) rnrorprGryrrrrWr{rzr __classcell__rr)rrrus   ruz )NNr)$__doc____all__rr*Zemail.quoprimimer&Zemail.base64mimeZ email.errorsrrrr<rxrQr/ZSPACE8rRrBrr@r[compileVERBOSE IGNORECASE MULTILINErZfcrergr'Z _max_appendrrrralistrurrrrs@    _ kheader.cpython-36.pyc000064400000040142147204636050010432 0ustar003 \&^@sdZdddgZddlZddlZddlZddlZddlmZddlm Z e j Z dZ d Z d ZdZd Zd ZdZe dZe dZejdejejBejBZejdZejdZejjZddZdddZGdddZ GdddZ!Gddde"Z#dS)z+Header encoding and decoding functionality.Header decode_header make_headerN)HeaderParseError)charset   Nz zus-asciizutf-8ai =\? # literal =? (?P[^?]*?) # non-greedy up to the next ? is the charset \? # literal ? (?P[qb]) # either a "q" or a "b", case insensitive \? # literal ? (?P.*?) # non-greedy up to the next ?= is the encoded string \?= # literal ?= z[\041-\176]+:$z \n[^ \t]+:c Cst|drdd|jDStj|s.|dfgSg}x|jD]}tj|}d}xp|r|jd}|rn|j}d}|r|j|ddf|rP|jdj }|jdj }|jd}|j|||fqPWqMsz!decode_header..NTrFqbz===zBase64 decoding errorzUnexpected encoding: zraw-unicode-escape)hasattrr ecresearch splitlinessplitpoplstripappendlower enumerateisspacereversedemail quoprimimeZ header_decodelenZ base64mimedecodebinasciiErrorrAssertionError isinstancerbytesBSPACE)headerZwordslinepartsfirstZ unencodedrencodingZencodedZdroplistnwdZ decoded_wordsZencoded_stringZwordZpaderrZ collapsedZ last_word last_charsetrrrr=sz       4           cCsLt|||d}x8|D]0\}}|dk r8t|t r8t|}|j||qW|S)aCreate a Header from a sequence of pairs as returned by decode_header() decode_header() takes a header value string and returns a sequence of pairs of the format (decoded_string, charset) where charset is the string name of the character set. This function takes one of those sequence of pairs and returns a Header instance. Optional maxlinelen, header_name, and continuation_ws are as in the Header constructor. ) maxlinelen header_namecontinuation_wsN)rr-Charsetr!)Z decoded_seqr9r:r;hsrrrrrs c@sJeZdZdddZddZdd Zdd d Zd d ZdddZddZ dS)rNrstrictcCs||dkrt}nt|ts t|}||_||_g|_|dk rH|j||||dkrTt}||_|dkrjd|_ nt |d|_ dS)aDCreate a MIME-compliant header that can contain many character sets. Optional s is the initial header value. If None, the initial header value is not set. You can later append to the header with .append() method calls. s may be a byte string or a Unicode string, but see the .append() documentation for semantics. Optional charset serves two purposes: it has the same meaning as the charset argument to the .append() method. It also sets the default character set for all subsequent .append() calls that omit the charset argument. If charset is not provided in the constructor, the us-ascii charset is used both as s's initial charset and as the default for subsequent .append() calls. The maximum line length can be specified explicitly via maxlinelen. For splitting the first line to a shorter value (to account for the field header which isn't included in s, e.g. `Subject') pass in the name of the field in header_name. The default maxlinelen is 78 as recommended by RFC 2822. continuation_ws must be RFC 2822 compliant folding whitespace (usually either a space or a hard tab) which will be prepended to continuation lines. errors is passed through to the .append() call. Nrr) USASCIIr-r<r_continuation_wsr r! MAXLINELEN _maxlinelen _headerlenr()selfr>rr9r:r;errorsrrr__init__s zHeader.__init__c Cs|jg}d}d}x|jD]\}}|}|tjkrJ|jdd}|jdd}|r|o^|j|d}|dkr|d kr| r|jtd}n|d kr| r|jt|o|j|d }|}|j|qWt j |S) z&Return the string value of the header.Nasciisurrogateescapereplacerus-asciir)NrK)NrK)NrK) _normalizer r UNKNOWN8BITencoder) _nonctextr!SPACE EMPTYSTRINGjoin) rEZuchunkslastcs lastspacerrZnextcsZoriginal_byteshasspacerrr__str__s*     zHeader.__str__cCs |t|kS)N)r)rEotherrrr__eq__sz Header.__eq__c Cs|dkr|j}nt|ts"t|}t|tsZ|jp4d}|tjkrN|jdd}n |j||}|jpbd}|tjkry|j||Wn"t k r|dkrt }YnX|j j ||fdS)a.Append a string to the MIME header. Optional charset, if given, should be a Charset instance or the name of a character set (which will be converted to a Charset instance). A value of None (the default) means that the charset given in the constructor is used. s may be a byte string or a Unicode string. If it is a byte string (i.e. isinstance(s, str) is false), then charset is the encoding of that byte string, and a UnicodeError will be raised if the string cannot be decoded with that charset. If s is a Unicode string, then charset is a hint specifying the character set of the characters in the string. In either case, when producing an RFC 2822 compliant header using RFC 2047 rules, the string will be encoded using the output codec of the charset. If the string cannot be encoded to the output codec, a UnicodeError will be raised. Optional `errors' is passed as the errors argument to the decode call if s is a byte string. Nzus-asciirI) rr-r<rZ input_codecrNr)Z output_codecrOUnicodeEncodeErrorUTF8r r!)rEr>rrFZ input_charsetZoutput_charsetrrrr! s$        z Header.appendcCs|jp|dkS)z=True if string s is not a ctext character of RFC822. ()\)r\r]r^)r$)rEr>rrrrP4szHeader._nonctext;, rcCs|j|dkr|j}|dkr"d}t|j||j|}d}d}}x4|jD](\}} |dk r|ol|j|d}|d kr| s| d kr|jn| d kr| r|j|o|j|d }| }d}|j} | r|j d| d| n|j dd| xr| ddD]b} |j | j dk r,|j |jd| j | n.| j } | dt | t | } |j | | | qWt | dkrJ|j qJW|jr|j|j|}tj|rtd j||S)aEncode a message header into an RFC-compliant format. There are many issues involved in converting a given string for use in an email header. Only certain character sets are readable in most email clients, and as header strings can only contain a subset of 7-bit ASCII, care must be taken to properly convert and encode (with Base64 or quoted-printable) header strings. In addition, there is a 75-character length limit on any given encoded header field, so line-wrapping must be performed, even with double-byte character sets. Optional maxlinelen specifies the maximum length of each generated line, exclusive of the linesep string. Individual lines may be longer than maxlinelen if a folding point cannot be found. The first line will be shorter by the length of the header name plus ": " if a header name was specified at Header construction time. The default value for maxlinelen is determined at header construction time. Optional splitchars is a string containing characters which should be given extra weight by the splitting algorithm during normal header wrapping. This is in very rough support of RFC 2822's `higher level syntactic breaks': split points preceded by a splitchar are preferred during line splitting, with the characters preferred in the order in which they appear in the string. Space and tab may be included in the string to indicate whether preference should be given to one over the other as a split point when other split chars do not appear in the line being split. Splitchars does not affect RFC 2047 encoded lines. Optional linesep is a string to be used to separate the lines of the value. The default value is the most useful for typical Python applications, but it can be set to \r\n to produce RFC-compliant line separators when needed. Nri@Bus-asciirFr rz8header value appears to contain an embedded header: {!r})Nr`)Nr`)Nr`rL)rMrC_ValueFormatterrDrAr rPadd_transitionrfeednewlineheader_encodingr r(_str_embedded_headerrrformat)rE splitcharsr9linesepZ formatterrTrVrUrrlinesr1ZslinefwsvaluerrrrO9sR!       z Header.encodecCs|g}d}g}xL|jD]B\}}||kr0|j|q|dk rL|jtj||f|g}|}qW|rr|jtj||f||_dS)N)r r!rQrS)rEZchunksr8Z last_chunkrrrrrrMs zHeader._normalize)NNNNrr?)Nr?)r_Nr) __name__ __module__ __qualname__rGrWrYr!rPrOrMrrrrrs -  + Pc@sTeZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ dS)racCs0||_||_t||_||_g|_t||_dS)N)_maxlenrAr(_continuation_ws_len _splitchars_lines _Accumulator _current_line)rEZ headerlenmaxlenr;rirrrrGs  z_ValueFormatter.__init__cCs|j|j|jS)N)rdrSrt)rErjrrrrfsz_ValueFormatter._strcCs |jtS)N)rfNL)rErrrrWsz_ValueFormatter.__str__cCsp|jj}|dkr|jj|t|jdkrb|jjrP|jdt|j7<n|jjt|j|jjdS)Nrr rr)rr rL) rvrpushr( is_onlywsrtrr!reset)rEZ end_of_linerrrrds   z_ValueFormatter.newlinecCs|jjdddS)Nrr )rvry)rErrrrbsz_ValueFormatter.add_transitioncCs|jdkr|j|||jdS|j||j}y|jd}Wntk rPdSX|dk rf|j||y |j}Wntk rdSX|j|j j |j |x|D]}|j j |j |qWdS)Nr)re _ascii_splitrsZheader_encode_lines _maxlengthsr IndexError _append_chunkrdrvryrArtr!)rErlrrZ encoded_linesZ first_line last_liner1rrrrcs$    z_ValueFormatter.feedccs*|jt|jVx|j|jVqWdS)N)rqr(rvrr)rErrrr}sz_ValueFormatter._maxlengthscCsjtjdtd||}|dr0dg|dd<n |jdx*tt|gdD]\}}|j||qNWdS)Nz([z]+)rr r)rerFWSrzipiterr)rErlrrir2partrrrr|s  z_ValueFormatter._ascii_splitcCs |jj||t|j|jkrx|jD]t}xlt|jjdddD]P}|jrp|j|d}|rp|d|krpP|j|dd}|rD|d|krDPqDWq(Pq(W|jj\}}|jj dkr|j |sd}|jj||dS|jj |}|j j t|j|jj|dS)NrrrrLrL)rvryr(rqrsrange part_countr$r _initial_sizerdpop_fromrtr!rr{)rErlrZchiZprevpartrZ remainderrrrrs.   z_ValueFormatter._append_chunkN) rnrorprGrfrWrdrbrcr}r|rrrrrras %racsjeZdZdfdd ZddZdddZfdd Zd d Zd d ZdddZ ddZ fddZ Z S)rurcs||_tjdS)N)rsuperrG)rEZ initial_size) __class__rrrGsz_Accumulator.__init__cCs|j||fdS)N)r!)rErlrrrrry#sz_Accumulator.pushcCs||d}g||d<|S)Nr)rErZpoppedrrrr&s  z_Accumulator.pop_fromcs|jdkrdStjS)Nrr )r r )rrr)rE)rrrr+s z_Accumulator.popcCstdd|D|jS)Ncss"|]\}}t|t|VqdS)N)r()rrlrrrr 1sz'_Accumulator.__len__..)sumr)rErrr__len__0sz_Accumulator.__len__cCstjdd|DS)Ncss |]\}}tj||fVqdS)N)rRrS)rrlrrrrr5sz'_Accumulator.__str__..)rRrS)rErrrrW4s z_Accumulator.__str__NcCs"|dkr g}||dd<d|_dS)Nr)r)rEZstartvalrrrr{8s z_Accumulator.resetcCs|jdko| pt|jS)Nr)rrr$)rErrrrz>sz_Accumulator.is_onlywscs tjS)N)rr)rE)rrrrAsz_Accumulator.part_count)r)r)N) rnrorprGryrrrrWr{rzr __classcell__rr)rrrus   ruz )NNr)$__doc____all__rr*Zemail.quoprimimer&Zemail.base64mimeZ email.errorsrrrr<rxrQr/ZSPACE8rRrBrr@r[compileVERBOSE IGNORECASE MULTILINErZfcrergr'Z _max_appendrrrralistrurrrrs@    _ kheaderregistry.cpython-36.opt-2.pyc000064400000036135147204636050013172 0ustar003 \O@sfddlmZddlmZddlmZddlmZGdddZGdddZGd d d e Z d d Z Gd ddZ Gddde Z GdddZGdddeZGdddZGdddeZGdddeZGdddeZGdddZGdd d ZGd!d"d"eZGd#d$d$eZGd%d&d&Ze eeeeeeeeeeeeeeeeeed'ZGd(d)d)Zd*S)+)MappingProxyType)utils)errors)_header_value_parserc@s^eZdZdddZeddZeddZed d Zed d Zd dZ ddZ ddZ dS)AddressNcCsl|dk rV|s|rtdtj|\}}|r:tdj|||jrJ|jd|j}|j}||_||_ ||_ dS)Nz=addrspec specified when username and/or domain also specifiedz6Invalid addr_spec; only '{}' could be parsed from '{}'r) TypeErrorparserZ get_addr_spec ValueErrorformat all_defects local_partdomain _display_name _username_domain)self display_nameusernamer addr_specZa_srestr,/usr/lib64/python3.6/email/headerregistry.py__init__s  zAddress.__init__cCs|jS)N)r)rrrrr7szAddress.display_namecCs|jS)N)r)rrrrr;szAddress.usernamecCs|jS)N)r)rrrrr?szAddress.domaincCsTt|j}t|t|tjkr.tj|j}n|j}|jrH|d|jS|sPdS|S)N@z<>)setrlenr Z DOT_ATOM_ENDS quote_stringr)rnamesetZlprrrrCs zAddress.addr_speccCsdj|jj|j|j|jS)Nz1{}(display_name={!r}, username={!r}, domain={!r}))r __class____name__rrr)rrrr__repr__SszAddress.__repr__cCs^t|j}t|t|tjkr.tj|j}n|j}|rX|jdkrFdn|j}dj||S|jS)Nz<>rz{} <{}>)rrrr SPECIALSrrr )rrdisprrrr__str__Xs  zAddress.__str__cCs8t|t|krdS|j|jko6|j|jko6|j|jkS)NF)typerrr)rotherrrr__eq__cs   zAddress.__eq__)rrrN) r __module__ __qualname__rpropertyrrrrr!r$r'rrrrrs %     rc@sFeZdZdddZeddZeddZdd Zd d Zd d Z dS)GroupNcCs||_|rt|nt|_dS)N)rtuple _addresses)rr addressesrrrrmszGroup.__init__cCs|jS)N)r)rrrrrszGroup.display_namecCs|jS)N)r-)rrrrr.szGroup.addressescCsdj|jj|j|jS)Nz${}(display_name={!r}, addresses={!r})r rr rr.)rrrrr!szGroup.__repr__cCs|jdkr&t|jdkr&t|jdS|j}|dk r\t|}t|t|tjkr\tj|}djdd|jD}|r~d|n|}dj ||S)Nrz, css|]}t|VqdS)N)str).0xrrr sz Group.__str__.. z{}:{};) rrr.r0rr r"rjoinr )rr#rZadrstrrrrr$s z Group.__str__cCs,t|t|krdS|j|jko*|j|jkS)NF)r%rr.)rr&rrrr's z Group.__eq__)NN) r r(r)rr*rr.r!r$r'rrrrr+ks     r+c@sPeZdZddZddZeddZeddZd d Ze d d Z d dZ dS) BaseHeadercCs\dgi}|j||tj|dr4tj|d|d<tj||d}|d=|j|f||S)Ndefectsdecoded)parserZ_has_surrogates _sanitizer0__new__init)clsnamevaluekwdsrrrrr;s zBaseHeader.__new__cCs||_||_||_dS)N)_name _parse_tree_defects)rr> parse_treer7rrrr<szBaseHeader.initcCs|jS)N)rA)rrrrr>szBaseHeader.namecCs t|jS)N)r,rC)rrrrr7szBaseHeader.defectscCst|jj|jjt|f|jfS)N)_reconstruct_headerrr __bases__r0__dict__)rrrr __reduce__s zBaseHeader.__reduce__cCs tj||S)N)r0r;)r=r?rrr _reconstructszBaseHeader._reconstructcCs`tjtjtj|jdtjddgg}|jrH|jtjtjddg|j|j|j |dS)Nz header-name:z header-sepr4Zfws)policy) r ZHeaderZ HeaderLabelZ ValueTerminalr>rBappendZCFWSListZWhiteSpaceTerminalfold)rrKheaderrrrrMs  zBaseHeader.foldN) r r(r)r;r<r*r>r7rH classmethodrIrMrrrrr6s"    r6cCst||ij|S)N)r%rI)Zcls_namebasesr?rrrrEsrEc@s&eZdZdZeejZeddZ dS)UnstructuredHeaderNcCs"|j||d<t|d|d<dS)NrDr8) value_parserr0)r=r?r@rrrr9szUnstructuredHeader.parse) r r(r) max_count staticmethodr get_unstructuredrRrOr9rrrrrQ s rQc@seZdZdZdS)UniqueUnstructuredHeaderr/N)r r(r)rSrrrrrVsrVcsBeZdZdZeejZeddZ fddZ e ddZ Z S) DateHeaderNcCsz|s6|djtjd|d<d|d<tj|d<dSt|trJtj|}||d<tj |d|d<|j |d|d<dS)Nr7datetimerr8rD) rLrZHeaderMissingRequiredValuer Z TokenList isinstancer0rZparsedate_to_datetimeZformat_datetimerR)r=r?r@rrrr9)s   zDateHeader.parsecs|jd|_tj||dS)NrX)pop _datetimesuperr<)rargskw)rrrr<7s zDateHeader.initcCs|jS)N)r[)rrrrrX;szDateHeader.datetime)r r(r)rSrTr rUrRrOr9r<r*rX __classcell__rr)rrrWs     rWc@seZdZdZdS)UniqueDateHeaderr/N)r r(r)rSrrrrr`@sr`csPeZdZdZeddZeddZfddZe dd Z e d d Z Z S) AddressHeaderNcCstj|\}}|S)N)r Zget_address_list)r? address_listrrrrRIszAddressHeader.value_parsercCst|trZ|j||d<}g}x,|jD]"}|jt|jdd|jDq(Wt|j }n"t |dsj|g}dd|D}g}||d<||d<dj d d|D|d <d|kr|j|d |d<dS) NrDcSs*g|]"}t|jpd|jpd|jp"dqS)r)rrr r)r1Zmbrrr Xsz'AddressHeader.parse..__iter__cSs&g|]}t|dstd|gn|qS)r.N)hasattrr+)r1itemrrrrcasgroupsr7z, cSsg|] }t|qSr)r0)r1rfrrrrcgsr8) rYr0rRr.rLr+rZ all_mailboxeslistr rer5)r=r?r@rbrgZaddrr7rrrr9Os$     zAddressHeader.parsecs(t|jd|_d|_tj||dS)Nrg)r,rZ_groupsr-r\r<)rr]r^)rrrr<kszAddressHeader.initcCs|jS)N)ri)rrrrrgpszAddressHeader.groupscCs&|jdkr tdd|jD|_|jS)NcSsg|]}|jD]}|qqSr)r.)r1groupaddressrrrrcwsz+AddressHeader.addresses..)r-r,ri)rrrrr.ts zAddressHeader.addresses) r r(r)rSrTrRrOr9r<r*rgr.r_rr)rrraEs     rac@seZdZdZdS)UniqueAddressHeaderr/N)r r(r)rSrrrrrl|srlc@seZdZeddZdS)SingleAddressHeadercCs(t|jdkrtdj|j|jdS)Nr/z9value of single address header {} is not a single addressr)rr.r r r>)rrrrrks zSingleAddressHeader.addressN)r r(r)r*rkrrrrrmsrmc@seZdZdZdS)UniqueSingleAddressHeaderr/N)r r(r)rSrrrrrnsrncsZeZdZdZeejZeddZ fddZ e ddZ e dd Z e d d ZZS) MIMEVersionHeaderr/cCs|j||d<}t||d<|dj|j|jdkrr?rrr sz1ParameterizedMIMEHeader.parse..)rRr0rsr rx)r=r?r@rDrrrr9s   zParameterizedMIMEHeader.parsecs|jd|_tj||dS)Nrx)rZ_paramsr\r<)rr]r^)rrrr<s zParameterizedMIMEHeader.initcCs t|jS)N)rr{)rrrrrxszParameterizedMIMEHeader.params) r r(r)rSrOr9r<r*rxr_rr)rrrws rwcsJeZdZeejZfddZeddZ eddZ eddZ Z S) ContentTypeHeadercs2tj||tj|jj|_tj|jj|_dS)N) r\r<rr:rBmaintype _maintypesubtype_subtype)rr]r^)rrrr<szContentTypeHeader.initcCs|jS)N)r~)rrrrr}szContentTypeHeader.maintypecCs|jS)N)r)rrrrrszContentTypeHeader.subtypecCs|jd|jS)N/)r}r)rrrr content_typeszContentTypeHeader.content_type) r r(r)rTr Zparse_content_type_headerrRr<r*r}rrr_rr)rrr|s     r|cs2eZdZeejZfddZeddZ Z S)ContentDispositionHeadercs2tj|||jj}|dkr"|ntj||_dS)N)r\r<rBcontent_dispositionrr:_content_disposition)rr]r^Zcd)rrrr<szContentDispositionHeader.initcCs|jS)N)r)rrrrrsz,ContentDispositionHeader.content_disposition) r r(r)rTr Z parse_content_disposition_headerrRr<r*rr_rr)rrrs  rcsBeZdZdZeejZeddZ fddZ e ddZ Z S)ContentTransferEncodingHeaderr/cCs2|j||d<}t||d<|dj|jdS)NrDr8r7)rRr0rsr )r=r?r@rDrrrr9s z#ContentTransferEncodingHeader.parsecs"tj||tj|jj|_dS)N)r\r<rr:rBcte_cte)rr]r^)rrrr<sz"ContentTransferEncodingHeader.initcCs|jS)N)r)rrrrrsz!ContentTransferEncodingHeader.cte)r r(r)rSrTr Z&parse_content_transfer_encoding_headerrRrOr9r<r*rr_rr)rrrs    r)ZsubjectZdatez resent-datez orig-dateZsenderz resent-senderZtoz resent-toZccz resent-ccZbccz resent-bccfromz resent-fromzreply-toz mime-versionz content-typezcontent-dispositionzcontent-transfer-encodingc@s4eZdZeedfddZddZddZdd Zd S) HeaderRegistryTcCs&i|_||_||_|r"|jjtdS)N)registry base_class default_classupdate_default_header_map)rrrZuse_default_maprrrr's zHeaderRegistry.__init__cCs||j|j<dS)N)rry)rr>r=rrr map_to_type9szHeaderRegistry.map_to_typecCs,|jj|j|j}td|j||jfiS)N_)rgetryrr%r r)rr>r=rrr __getitem__?szHeaderRegistry.__getitem__cCs||||S)Nr)rr>r?rrr__call__Cs zHeaderRegistry.__call__N) r r(r)r6rQrrrrrrrrr#s  rN)typesrZemailrrrr rr+r0r6rErQrVrWr`rarlrmrnrorwr|rrrrrrrr sP    [6d '7 %headerregistry.cpython-36.pyc000064400000051440147204636050012226 0ustar003 \O@sjdZddlmZddlmZddlmZddlmZGdddZGdd d Z Gd d d e Z d d Z GdddZ Gddde ZGdddZGdddeZGdddZGdddeZGdddeZGdddeZGdddZGd d!d!ZGd"d#d#eZGd$d%d%eZGd&d'd'Zeeeeeeeeeeeeeeeeeeed(ZGd)d*d*Zd+S),a;Representing and manipulating email headers via custom objects. This module provides an implementation of the HeaderRegistry API. The implementation is designed to flexibly follow RFC5322 rules. Eventually HeaderRegistry will be a public API, but it isn't yet, and will probably change some before that happens. )MappingProxyType)utils)errors)_header_value_parserc@s^eZdZdddZeddZeddZed d Zed d Zd dZ ddZ ddZ dS)AddressNcCsl|dk rV|s|rtdtj|\}}|r:tdj|||jrJ|jd|j}|j}||_||_ ||_ dS)aCreate an object representing a full email address. An address can have a 'display_name', a 'username', and a 'domain'. In addition to specifying the username and domain separately, they may be specified together by using the addr_spec keyword *instead of* the username and domain keywords. If an addr_spec string is specified it must be properly quoted according to RFC 5322 rules; an error will be raised if it is not. An Address object has display_name, username, domain, and addr_spec attributes, all of which are read-only. The addr_spec and the string value of the object are both quoted according to RFC5322 rules, but without any Content Transfer Encoding. Nz=addrspec specified when username and/or domain also specifiedz6Invalid addr_spec; only '{}' could be parsed from '{}'r) TypeErrorparserZ get_addr_spec ValueErrorformat all_defects local_partdomain _display_name _username_domain)self display_nameusernamer addr_specZa_srestr,/usr/lib64/python3.6/email/headerregistry.py__init__s  zAddress.__init__cCs|jS)N)r)rrrrr7szAddress.display_namecCs|jS)N)r)rrrrr;szAddress.usernamecCs|jS)N)r)rrrrr?szAddress.domaincCsTt|j}t|t|tjkr.tj|j}n|j}|jrH|d|jS|sPdS|S)zThe addr_spec (username@domain) portion of the address, quoted according to RFC 5322 rules, but with no Content Transfer Encoding. @z<>)setrlenr Z DOT_ATOM_ENDS quote_stringr)rnamesetZlprrrrCs zAddress.addr_speccCsdj|jj|j|j|jS)Nz1{}(display_name={!r}, username={!r}, domain={!r}))r __class____name__rrr)rrrr__repr__SszAddress.__repr__cCs^t|j}t|t|tjkr.tj|j}n|j}|rX|jdkrFdn|j}dj||S|jS)Nz<>rz{} <{}>)rrrr SPECIALSrrr )rrdisprrrr__str__Xs  zAddress.__str__cCs8t|t|krdS|j|jko6|j|jko6|j|jkS)NF)typerrr)rotherrrr__eq__cs   zAddress.__eq__)rrrN) r __module__ __qualname__rpropertyrrrrr!r$r'rrrrrs %     rc@sFeZdZdddZeddZeddZdd Zd d Zd d Z dS)GroupNcCs||_|rt|nt|_dS)aCreate an object representing an address group. An address group consists of a display_name followed by colon and a list of addresses (see Address) terminated by a semi-colon. The Group is created by specifying a display_name and a possibly empty list of Address objects. A Group can also be used to represent a single address that is not in a group, which is convenient when manipulating lists that are a combination of Groups and individual Addresses. In this case the display_name should be set to None. In particular, the string representation of a Group whose display_name is None is the same as the Address object, if there is one and only one Address object in the addresses list. N)rtuple _addresses)rr addressesrrrrmszGroup.__init__cCs|jS)N)r)rrrrrszGroup.display_namecCs|jS)N)r-)rrrrr.szGroup.addressescCsdj|jj|j|jS)Nz${}(display_name={!r}, addresses={!r})r rr rr.)rrrrr!szGroup.__repr__cCs|jdkr&t|jdkr&t|jdS|j}|dk r\t|}t|t|tjkr\tj|}djdd|jD}|r~d|n|}dj ||S)Nrz, css|]}t|VqdS)N)str).0xrrr sz Group.__str__.. z{}:{};) rrr.r0rr r"rjoinr )rr#rZadrstrrrrr$s z Group.__str__cCs,t|t|krdS|j|jko*|j|jkS)NF)r%rr.)rr&rrrr's z Group.__eq__)NN) r r(r)rr*rr.r!r$r'rrrrr+ks     r+c@sTeZdZdZddZddZeddZedd Zd d Z e d d Z ddZ dS) BaseHeadera|Base class for message headers. Implements generic behavior and provides tools for subclasses. A subclass must define a classmethod named 'parse' that takes an unfolded value string and a dictionary as its arguments. The dictionary will contain one key, 'defects', initialized to an empty list. After the call the dictionary must contain two additional keys: parse_tree, set to the parse tree obtained from parsing the header, and 'decoded', set to the string value of the idealized representation of the data from the value. (That is, encoded words are decoded, and values that have canonical representations are so represented.) The defects key is intended to collect parsing defects, which the message parser will subsequently dispose of as appropriate. The parser should not, insofar as practical, raise any errors. Defects should be added to the list instead. The standard header parsers register defects for RFC compliance issues, for obsolete RFC syntax, and for unrecoverable parsing errors. The parse method may add additional keys to the dictionary. In this case the subclass must define an 'init' method, which will be passed the dictionary as its keyword arguments. The method should use (usually by setting them as the value of similarly named attributes) and remove all the extra keys added by its parse method, and then use super to call its parent class with the remaining arguments and keywords. The subclass should also make sure that a 'max_count' attribute is defined that is either None or 1. XXX: need to better define this API. cCs\dgi}|j||tj|dr4tj|d|d<tj||d}|d=|j|f||S)Ndefectsdecoded)parserZ_has_surrogates _sanitizer0__new__init)clsnamevaluekwdsrrrrr;s zBaseHeader.__new__cCs||_||_||_dS)N)_name _parse_tree_defects)rr> parse_treer7rrrr<szBaseHeader.initcCs|jS)N)rA)rrrrr>szBaseHeader.namecCs t|jS)N)r,rC)rrrrr7szBaseHeader.defectscCst|jj|jjt|f|jfS)N)_reconstruct_headerrr __bases__r0__dict__)rrrr __reduce__s zBaseHeader.__reduce__cCs tj||S)N)r0r;)r=r?rrr _reconstructszBaseHeader._reconstructcCs`tjtjtj|jdtjddgg}|jrH|jtjtjddg|j|j|j |dS)atFold header according to policy. The parsed representation of the header is folded according to RFC5322 rules, as modified by the policy. If the parse tree contains surrogateescaped bytes, the bytes are CTE encoded using the charset 'unknown-8bit". Any non-ASCII characters in the parse tree are CTE encoded using charset utf-8. XXX: make this a policy setting. The returned value is an ASCII-only string possibly containing linesep characters, and ending with a linesep character. The string includes the header name and the ': ' separator. z header-name:z header-sepr4Zfws)policy) r ZHeaderZ HeaderLabelZ ValueTerminalr>rBappendZCFWSListZWhiteSpaceTerminalfold)rrKheaderrrrrMs  zBaseHeader.foldN) r r(r)__doc__r;r<r*r>r7rH classmethodrIrMrrrrr6s     r6cCst||ij|S)N)r%rI)Zcls_namebasesr?rrrrEsrEc@s&eZdZdZeejZeddZ dS)UnstructuredHeaderNcCs"|j||d<t|d|d<dS)NrDr8) value_parserr0)r=r?r@rrrr9szUnstructuredHeader.parse) r r(r) max_count staticmethodr get_unstructuredrSrPr9rrrrrR s rRc@seZdZdZdS)UniqueUnstructuredHeaderr/N)r r(r)rTrrrrrWsrWcsFeZdZdZdZeejZe ddZ fddZ e ddZ ZS) DateHeaderaHeader whose value consists of a single timestamp. Provides an additional attribute, datetime, which is either an aware datetime using a timezone, or a naive datetime if the timezone in the input string is -0000. Also accepts a datetime as input. The 'value' attribute is the normalized form of the timestamp, which means it is the output of format_datetime on the datetime. NcCsz|s6|djtjd|d<d|d<tj|d<dSt|trJtj|}||d<tj |d|d<|j |d|d<dS)Nr7datetimerr8rD) rLrZHeaderMissingRequiredValuer Z TokenList isinstancer0rZparsedate_to_datetimeZformat_datetimerS)r=r?r@rrrr9)s   zDateHeader.parsecs|jd|_tj||dS)NrY)pop _datetimesuperr<)rargskw)rrrr<7s zDateHeader.initcCs|jS)N)r\)rrrrrY;szDateHeader.datetime)r r(r)rOrTrUr rVrSrPr9r<r*rY __classcell__rr)rrrXs     rXc@seZdZdZdS)UniqueDateHeaderr/N)r r(r)rTrrrrra@sracsPeZdZdZeddZeddZfddZe dd Z e d d Z Z S) AddressHeaderNcCs tj|\}}| std|S)Nzthis should not happen)r Zget_address_listAssertionError)r? address_listrrrrSIszAddressHeader.value_parsercCst|trZ|j||d<}g}x,|jD]"}|jt|jdd|jDq(Wt|j }n"t |dsj|g}dd|D}g}||d<||d<dj d d|D|d <d|kr|j|d |d<dS) NrDcSs*g|]"}t|jpd|jpd|jp"dqS)r)rrr r)r1Zmbrrr Xsz'AddressHeader.parse..__iter__cSs&g|]}t|dstd|gn|qS)r.N)hasattrr+)r1itemrrrreasgroupsr7z, cSsg|] }t|qSr)r0)r1rhrrrregsr8) rZr0rSr.rLr+rZ all_mailboxeslistr rgr5)r=r?r@rdriZaddrr7rrrr9Os$     zAddressHeader.parsecs(t|jd|_d|_tj||dS)Nri)r,r[_groupsr-r]r<)rr^r_)rrrr<kszAddressHeader.initcCs|jS)N)rk)rrrrripszAddressHeader.groupscCs&|jdkr tdd|jD|_|jS)NcSsg|]}|jD]}|qqSr)r.)r1groupaddressrrrrewsz+AddressHeader.addresses..)r-r,rk)rrrrr.ts zAddressHeader.addresses) r r(r)rTrUrSrPr9r<r*rir.r`rr)rrrbEs     rbc@seZdZdZdS)UniqueAddressHeaderr/N)r r(r)rTrrrrrn|srnc@seZdZeddZdS)SingleAddressHeadercCs(t|jdkrtdj|j|jdS)Nr/z9value of single address header {} is not a single addressr)rr.r r r>)rrrrrms zSingleAddressHeader.addressN)r r(r)r*rmrrrrrosroc@seZdZdZdS)UniqueSingleAddressHeaderr/N)r r(r)rTrrrrrpsrpcsZeZdZdZeejZeddZ fddZ e ddZ e dd Z e d d ZZS) MIMEVersionHeaderr/cCs|j||d<}t||d<|dj|j|jdkrr?rrr sz1ParameterizedMIMEHeader.parse..)rSr0rur rz)r=r?r@rDrrrr9s   zParameterizedMIMEHeader.parsecs|jd|_tj||dS)Nrz)r[_paramsr]r<)rr^r_)rrrr<s zParameterizedMIMEHeader.initcCs t|jS)N)rr})rrrrrzszParameterizedMIMEHeader.params) r r(r)rTrPr9r<r*rzr`rr)rrrys rycsJeZdZeejZfddZeddZ eddZ eddZ Z S) ContentTypeHeadercs2tj||tj|jj|_tj|jj|_dS)N) r]r<rr:rBmaintype _maintypesubtype_subtype)rr^r_)rrrr<szContentTypeHeader.initcCs|jS)N)r)rrrrrszContentTypeHeader.maintypecCs|jS)N)r)rrrrrszContentTypeHeader.subtypecCs|jd|jS)N/)rr)rrrr content_typeszContentTypeHeader.content_type) r r(r)rUr Zparse_content_type_headerrSr<r*rrrr`rr)rrr~s     r~cs2eZdZeejZfddZeddZ Z S)ContentDispositionHeadercs2tj|||jj}|dkr"|ntj||_dS)N)r]r<rBcontent_dispositionrr:_content_disposition)rr^r_Zcd)rrrr<szContentDispositionHeader.initcCs|jS)N)r)rrrrrsz,ContentDispositionHeader.content_disposition) r r(r)rUr Z parse_content_disposition_headerrSr<r*rr`rr)rrrs  rcsBeZdZdZeejZeddZ fddZ e ddZ Z S)ContentTransferEncodingHeaderr/cCs2|j||d<}t||d<|dj|jdS)NrDr8r7)rSr0rur )r=r?r@rDrrrr9s z#ContentTransferEncodingHeader.parsecs"tj||tj|jj|_dS)N)r]r<rr:rBcte_cte)rr^r_)rrrr<sz"ContentTransferEncodingHeader.initcCs|jS)N)r)rrrrrsz!ContentTransferEncodingHeader.cte)r r(r)rTrUr Z&parse_content_transfer_encoding_headerrSrPr9r<r*rr`rr)rrrs    r)ZsubjectZdatez resent-datez orig-dateZsenderz resent-senderZtoz resent-toZccz resent-ccZbccz resent-bccfromz resent-fromzreply-toz mime-versionz content-typezcontent-dispositionzcontent-transfer-encodingc@s8eZdZdZeedfddZddZddZd d Z d S) HeaderRegistryz%A header_factory and header registry.TcCs&i|_||_||_|r"|jjtdS)aCreate a header_factory that works with the Policy API. base_class is the class that will be the last class in the created header class's __bases__ list. default_class is the class that will be used if "name" (see __call__) does not appear in the registry. use_default_map controls whether or not the default mapping of names to specialized classes is copied in to the registry when the factory is created. The default is True. N)registry base_class default_classupdate_default_header_map)rrrZuse_default_maprrrr's zHeaderRegistry.__init__cCs||j|j<dS)zLRegister cls as the specialized class for handling "name" headers. N)rr{)rr>r=rrr map_to_type9szHeaderRegistry.map_to_typecCs,|jj|j|j}td|j||jfiS)N_)rgetr{rr%r r)rr>r=rrr __getitem__?szHeaderRegistry.__getitem__cCs||||S)aCreate a header instance for header 'name' from 'value'. Creates a header instance by creating a specialized class for parsing and representing the specified header by combining the factory base_class with a specialized class from the registry or the default_class, and passing the name and value to the constructed class's constructor. r)rr>r?rrr__call__Cs zHeaderRegistry.__call__N) r r(r)rOr6rRrrrrrrrrr#s  rN)rOtypesrZemailrrrr rr+r0r6rErRrWrXrarbrnrorprqryr~rrrrrrrr sR    [6d '7 %iterators.cpython-36.opt-1.pyc000064400000003570147204636050012161 0ustar003 \W@sLdZdddgZddlZddlmZddZdd dZdd dZdd d ZdS)z1Various types of useful iterators and generators.body_line_iteratortyped_subpart_iteratorwalkN)StringIOccs2|V|jr.x|jD]}|jEdHqWdS)zWalk over the message tree, yielding each subpart. The walk is performed in depth-first order. This method is a generator. N) is_multipart get_payloadr)selfsubpartr '/usr/lib64/python3.6/email/iterators.pyrsFccs:x4|jD](}|j|d}t|tr t|EdHq WdS)zIterate over the parts, returning string payloads line-by-line. Optional decode (default False) is passed through to .get_payload(). )decodeN)rr isinstancestrr)msgr r Zpayloadr r r r"s  textccs<x6|jD]*}|j|kr |dks.|j|kr |Vq WdS)zIterate over the subparts with a given MIME type. Use `maintype' as the main MIME type to match against; this defaults to "text". Optional `subtype' is the MIME subtype to match against; if omitted, only the main type is matched. N)rZget_content_maintypeZget_content_subtype)rZmaintypesubtyper r r r r-s cCs|dkrtj}d|d}t||jd|d|rJtd|j|dn t|d|jrx"|jD]}t|||d|qfWdS) zA handy debugging aidN )endfilez [%s])r)sysstdoutprintZget_content_typeZget_default_typerr _structure)rfplevelZinclude_defaultZtabr r r r r;s  r)F)rN)NrF) __doc____all__riorrrrrr r r r s  iterators.cpython-36.pyc000064400000003570147204636050011222 0ustar003 \W@sLdZdddgZddlZddlmZddZdd dZdd dZdd d ZdS)z1Various types of useful iterators and generators.body_line_iteratortyped_subpart_iteratorwalkN)StringIOccs2|V|jr.x|jD]}|jEdHqWdS)zWalk over the message tree, yielding each subpart. The walk is performed in depth-first order. This method is a generator. N) is_multipart get_payloadr)selfsubpartr '/usr/lib64/python3.6/email/iterators.pyrsFccs:x4|jD](}|j|d}t|tr t|EdHq WdS)zIterate over the parts, returning string payloads line-by-line. Optional decode (default False) is passed through to .get_payload(). )decodeN)rr isinstancestrr)msgr r Zpayloadr r r r"s  textccs<x6|jD]*}|j|kr |dks.|j|kr |Vq WdS)zIterate over the subparts with a given MIME type. Use `maintype' as the main MIME type to match against; this defaults to "text". Optional `subtype' is the MIME subtype to match against; if omitted, only the main type is matched. N)rZget_content_maintypeZget_content_subtype)rZmaintypesubtyper r r r r-s cCs|dkrtj}d|d}t||jd|d|rJtd|j|dn t|d|jrx"|jD]}t|||d|qfWdS) zA handy debugging aidN )endfilez [%s])r)sysstdoutprintZget_content_typeZget_default_typerr _structure)rfplevelZinclude_defaultZtabr r r r r;s  r)F)rN)NrF) __doc____all__riorrrrrr r r r s  message.cpython-36.pyc000064400000112152147204636050010627 0ustar003 \@sdZddgZddlZddlZddlZddlmZmZddlm Z ddlm Z ddl m Z m Z dd lmZdd lmZejZd Zejd Zd dZdddZddZddZGdddZGdddeZGdddeZdS)z8Basic message object for the email package object model.Message EmailMessageN)BytesIOStringIO)utils)errors)Policycompat32)charset)decode_bz; z[ \(\)<>@,;:\\"/\[\]\?=]cCs4t|jd\}}}|s$|jdfS|j|jfS)N;)str partitionstrip)paramasepbr%/usr/lib64/python3.6/email/message.py _splitparams rTc Cs|dk rt|dkrt|trL|d7}tj|d|d|d}d||fSy|jdWn2tk r|d7}tj|dd }d||fSX|stj|rd |tj |fSd||fSn|SdS) a~Convenience function to format and return a key=value pair. This will quote the value if needed or if quote is true. If value is a three tuple (charset, language, value), it will be encoded according to RFC2231 rules. If it contains non-ascii characters it will likewise be encoded according to RFC2231 rules, using the utf-8 charset and a null language. Nr*z%s=%sasciizutf-8z%s="%s") len isinstancetuplerZencode_rfc2231encodeUnicodeEncodeError tspecialssearchquote)rvaluer#rrr _formatparam's   r%cCsdt|}g}x|dddkr|dd}|jd}x<|dkrt|jdd||jdd|drt|jd|d}q:W|dkrt|}|d|}d|kr|jd}|d|jjd||ddj}|j|j||d}qW|S)Nr rr"z\"r=)r findcountrindexrlowerappend)sZplistendfirrr _parseparamIs    *  ,r1cCs4t|tr&|d|dtj|dfStj|SdS)Nrrr)rrrunquote)r$rrr _unquotevalue]s r3c@seZdZdZefddZddZddd d Zd d Zded dZ ddZ ddZ ddZ ddZ dfddZdgddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+d,Zd-d.Zd/d0Zdhd1d2Zd3d4Zd5d6Zdid7d8Zd9d:Zd;d<Z d=d>Z!d?d@Z"dAdBZ#dCdDZ$dEdFZ%dGdHZ&djdKdLZ'dkdMdNZ(dldQdRZ)dmdSdTZ*dndUdVZ+dodWdXZ,dpdYdZZ-d[d\Z.dqd]d^Z/drd_d`Z0dadbZ1ddcl2m3Z3dS)sraBasic message object. A message object is defined as something that has a bunch of RFC 2822 headers and a payload. It may optionally have an envelope header (a.k.a. Unix-From or From_ header). If the message is a container (i.e. a multipart or a message/rfc822), then the payload is a list of Message objects, otherwise it is a string. Message objects implement part of the `mapping' interface, which assumes there is exactly one occurrence of the header per message. Some headers do in fact appear multiple times (e.g. Received) and for those headers, you must use the explicit API to set or get all the headers. Not all of the mapping methods are implemented. cCs:||_g|_d|_d|_d|_d|_|_g|_d|_dS)Nz text/plain) policy_headers _unixfrom_payload_charsetZpreambleZepiloguedefects _default_type)selfr4rrr__init__xs zMessage.__init__cCs|jS)z9Return the entire formatted message as a string. ) as_string)r;rrr__str__szMessage.__str__FrNcCsJddlm}|dkr|jn|}t}||d||d}|j||d|jS)aReturn the entire formatted message as a string. Optional 'unixfrom', when true, means include the Unix From_ envelope header. For backward compatibility reasons, if maxheaderlen is not specified it defaults to 0, so you must override it explicitly if you want a different maxheaderlen. 'policy' is passed to the Generator instance used to serialize the mesasge; if it is not specified the policy associated with the message instance is used. If the message object contains binary data that is not encoded according to RFC standards, the non-compliant data will be replaced by unicode "unknown character" code points. r) GeneratorNF) mangle_from_ maxheaderlenr4)unixfrom)email.generatorr?r4rflattengetvalue)r;rBrAr4r?fpgrrrr=s zMessage.as_stringcCs|jS)z?Return the entire formatted message as a bytes object. )as_bytes)r;rrr __bytes__szMessage.__bytes__cCsHddlm}|dkr|jn|}t}||d|d}|j||d|jS)aJReturn the entire formatted message as a bytes object. Optional 'unixfrom', when true, means include the Unix From_ envelope header. 'policy' is passed to the BytesGenerator instance used to serialize the message; if not specified the policy associated with the message instance is used. r)BytesGeneratorNF)r@r4)rB)rCrJr4rrDrE)r;rBr4rJrFrGrrrrHs  zMessage.as_bytescCs t|jtS)z6Return True if the message consists of multiple parts.)rr7list)r;rrr is_multipartszMessage.is_multipartcCs ||_dS)N)r6)r;rBrrr set_unixfromszMessage.set_unixfromcCs|jS)N)r6)r;rrr get_unixfromszMessage.get_unixfromc CsF|jdkr|g|_n.y|jj|Wntk r@tdYnXdS)zAdd the given payload to the current payload. The current payload will always be a list of objects after this method is called. If you want to set the payload to a scalar object, use set_payload() instead. Nz=Attach is not valid on a message with a non-multipart payload)r7r,AttributeError TypeError)r;payloadrrrattachs   zMessage.attachc Cs|jr(|rdS|dkr|jS|j|S|dk rPt|jt rPtdt|j|j}t|jddj}t|trt j |r|j dd}|sy|j |j ddd}Wn tk r|j dd}YnXn6|ry|j d}Wn tk r|j d }YnX|s |S|d kr tj|S|d krbtd j|j\}}x|D]}|jj||qFW|S|dkrt|} t} ytj | | dd| jStjk r|SXt|tr|S|S)aZReturn a reference to the payload. The payload will either be a list object or a string. If you mutate the list object, you modify the message's payload in place. Optional i returns that index into the payload. Optional decode is a flag indicating whether the payload should be decoded or not, according to the Content-Transfer-Encoding header (default is False). When True and the message is not a multipart, the payload will be decoded if this header's value is `quoted-printable' or `base64'. If some other encoding is used, or the header is missing, or if the payload has bogus data (i.e. bogus base64 or uuencoded data), the payload is returned as-is. If the message is a multipart and the decode flag is True, then None is returned. NzExpected list, got %szcontent-transfer-encodingrrsurrogateescaper replacezraw-unicode-escapezquoted-printablebase64 x-uuencodeuuencodeuuex-uueT)quiet)rWrXrYrZ)rLr7rrKrPtyper getr+rZ_has_surrogatesrdecode get_param LookupError UnicodeErrorquopriZ decodestringr join splitlinesr4Z handle_defectruurEError) r;r0r^rQcteZbpayloadr$r9ZdefectZin_fileZout_filerrr get_payloadsV"          zMessage.get_payloadcCspt|dr:|dkr||_dSt|ts.t|}|j|j}t|drT|jdd|_n||_|dk rl|j|dS)zSet the payload to the given value. Optional charset sets the message's default character set. See set_charset() for details. rNr^rrS)hasattrr7rCharsetroutput_charsetr^ set_charset)r;rQr rrr set_payload/s    zMessage.set_payloadcCs|dkr|jdd|_dSt|ts.t|}||_d|krH|jddd|krf|jdd|jdn|jd|j||jkr|j|j|_d|kr|j }y ||Wnjt k r|j}|ry|j d d }Wn t k r|j |j }YnX|j||_|jd|YnXdS) aSet the charset of the payload to a given character set. charset can be a Charset instance, a string naming a character set, or None. If it is a string it will be converted to a Charset instance. If charset is None, the charset parameter will be removed from the Content-Type field. Anything else will generate a TypeError. The message will be assumed to be of type text/* encoded with charset.input_charset. It will be converted to charset.output_charset and encoded properly, if needed, when generating the plain text representation of the message. MIME headers (MIME-Version, Content-Type, Content-Transfer-Encoding) will be added as needed. Nr z MIME-Versionz1.0z Content-Typez text/plain)r zContent-Transfer-EncodingrrS) del_paramr8rrj add_headerZget_output_charset set_paramZ body_encoder7Zget_body_encodingrPrrark)r;r rgrQrrrrlCs8       zMessage.set_charsetcCs|jS)zKReturn the Charset instance associated with the message's payload. )r8)r;rrr get_charsetrszMessage.get_charsetcCs t|jS)z9Return the total number of headers, including duplicates.)rr5)r;rrr__len__zszMessage.__len__cCs |j|S)a-Get a header value. Return None if the header is missing instead of raising an exception. Note that if the header appeared multiple times, exactly which occurrence gets returned is undefined. Use get_all() to get all the values matching a header field name. )r])r;namerrr __getitem__~s zMessage.__getitem__cCsv|jj|}|r\|j}d}x>|jD]4\}}|j|kr$|d7}||kr$tdj||q$W|jj|jj||dS)zSet the value of a header. Note: this does not overwrite an existing header with the same field name. Use __delitem__() first to delete any existing headers. rrz/There may be at most {} {} headers in a messageN)r4Zheader_max_countr+r5 ValueErrorformatr,header_store_parse)r;rsvalZ max_countZlnamefoundkvrrr __setitem__s  zMessage.__setitem__cCsD|j}g}x,|jD]"\}}|j|kr|j||fqW||_dS)zwDelete all occurrences of a header, if present. Does not raise an exception if the header is missing. N)r+r5r,)r;rs newheadersrzr{rrr __delitem__s  zMessage.__delitem__cCs|jdd|jDkS)NcSsg|]\}}|jqSr)r+).0rzr{rrr sz(Message.__contains__..)r+r5)r;rsrrr __contains__szMessage.__contains__ccsx|jD]\}}|VqWdS)N)r5)r;Zfieldr$rrr__iter__szMessage.__iter__cCsdd|jDS)a.Return a list of all the message's header field names. These will be sorted in the order they appeared in the original message, or were added to the message, and may contain duplicates. Any fields deleted and re-inserted are always appended to the header list. cSsg|] \}}|qSrr)rrzr{rrrrsz Message.keys..)r5)r;rrrkeyssz Message.keyscsfddjDS)a)Return a list of all the message's header values. These will be sorted in the order they appeared in the original message, or were added to the message, and may contain duplicates. Any fields deleted and re-inserted are always appended to the header list. csg|]\}}jj||qSr)r4header_fetch_parse)rrzr{)r;rrrsz"Message.values..)r5)r;r)r;rvaluess zMessage.valuescsfddjDS)a'Get all the message's header fields and values. These will be sorted in the order they appeared in the original message, or were added to the message, and may contain duplicates. Any fields deleted and re-inserted are always appended to the header list. cs"g|]\}}|jj||fqSr)r4r)rrzr{)r;rrrsz!Message.items..)r5)r;r)r;ritemss z Message.itemscCs:|j}x,|jD]"\}}|j|kr|jj||SqW|S)z~Get a header value. Like __getitem__() but return failobj instead of None when the field is missing. )r+r5r4r)r;rsfailobjrzr{rrrr]s  z Message.getcCs|jj||fdS)zStore name and value in the model without modification. This is an "internal" API, intended only for use by a parser. N)r5r,)r;rsr$rrrset_rawszMessage.set_rawcCst|jjS)zReturn the (name, value) header pairs without modification. This is an "internal" API, intended only for use by a generator. )iterr5copy)r;rrr raw_itemsszMessage.raw_itemscCsLg}|j}x2|jD](\}}|j|kr|j|jj||qW|sH|S|S)aQReturn a list of all the values for the named field. These will be sorted in the order they appeared in the original message, and may contain duplicates. Any fields deleted and re-inserted are always appended to the header list. If no such fields exist, failobj is returned (defaults to None). )r+r5r,r4r)r;rsrrrzr{rrrget_alls  zMessage.get_allcKstg}xH|jD]<\}}|dkr2|j|jddq|jt|jdd|qW|dk rb|jd|tj|||<dS)uExtended header setting. name is the header field to add. keyword arguments can be used to set additional parameters for the header field, with underscores converted to dashes. Normally the parameter will be added as key="value" unless value is None, in which case only the key will be added. If a parameter value contains non-ASCII characters it can be specified as a three-tuple of (charset, language, value), in which case it will be encoded according to RFC2231 rules. Otherwise it will be encoded using the utf-8 charset and a language of ''. Examples: msg.add_header('content-disposition', 'attachment', filename='bud.gif') msg.add_header('content-disposition', 'attachment', filename=('utf-8', '', Fußballer.ppt')) msg.add_header('content-disposition', 'attachment', filename='Fußballer.ppt')) N_-r)rr,rTr%insert SEMISPACErc)r;_name_valueZ_paramspartsrzr{rrrros zMessage.add_headercCs^|j}xPttt|j|jD].\}\}}|j|kr |jj|||j|<Pq Wt|dS)zReplace a header. Replace the first matching header found in the message, retaining header order and case. If no matching header was found, a KeyError is raised. N)r+ziprangerr5r4rwKeyError)r;rrr0rzr{rrrreplace_header!s $ zMessage.replace_headercCsHt}|jd|}||kr"|jSt|dj}|jddkrDdS|S)a0Return the message's content type. The returned string is coerced to lower case of the form `maintype/subtype'. If there was no Content-Type header in the message, the default type as given by get_default_type() will be returned. Since according to RFC 2045, messages always have a default type this will always return a value. RFC 2045 defines a message's default type to be text/plain unless it appears inside a multipart/digest container, in which case it would be message/rfc822. z content-typer/rz text/plain)objectr]get_default_typerr+r))r;missingr$ctyperrrget_content_type4s  zMessage.get_content_typecCs|j}|jddS)zReturn the message's main content type. This is the `maintype' part of the string returned by get_content_type(). rr)rsplit)r;rrrrget_content_maintypeLszMessage.get_content_maintypecCs|j}|jddS)zReturns the message's sub-content type. This is the `subtype' part of the string returned by get_content_type(). rr)rr)r;rrrrget_content_subtypeUszMessage.get_content_subtypecCs|jS)aReturn the `default' content type. Most messages have a default content type of text/plain, except for messages that are subparts of multipart/digest containers. Such subparts have a default content type of message/rfc822. )r:)r;rrrr^szMessage.get_default_typecCs ||_dS)zSet the `default' content type. ctype should be either "text/plain" or "message/rfc822", although this is not enforced. The default content type is not stored in the Content-Type header. N)r:)r;rrrrset_default_typegszMessage.set_default_typec Cst}|j||}||kr|Sg}xdt|D]X}y$|jdd\}}|j}|j}Wn tk rt|j}d}YnX|j||fq,Wtj|}|S)Nr'rr) rr]r1rrrur,rZ decode_params) r;rheaderrr$paramsprsrxrrr_get_params_preserveps     zMessage._get_params_preserve content-typeTcCs8t}|j||}||kr|S|r0dd|DS|SdS)amReturn the message's Content-Type parameters, as a list. The elements of the returned list are 2-tuples of key/value pairs, as split on the `=' sign. The left hand side of the `=' is the key, while the right hand side is the value. If there is no `=' sign in the parameter the value is the empty string. The value is as described in the get_param() method. Optional failobj is the object to return if there is no Content-Type header. Optional header is the header to search instead of Content-Type. If unquote is True, the value is unquoted. cSsg|]\}}|t|fqSr)r3)rrzr{rrrrsz&Message.get_params..N)rr)r;rrr2rrrrr get_paramss  zMessage.get_paramscCsJ||kr |Sx8|j||D](\}}|j|jkr|r>t|S|SqW|S)aReturn the parameter value if found in the Content-Type header. Optional failobj is the object to return if there is no Content-Type header, or the Content-Type header has no such parameter. Optional header is the header to search instead of Content-Type. Parameter keys are always compared case insensitively. The return value can either be a string, or a 3-tuple if the parameter was RFC 2231 encoded. When it's a 3-tuple, the elements of the value are of the form (CHARSET, LANGUAGE, VALUE). Note that both CHARSET and LANGUAGE can be None, in which case you should consider VALUE to be encoded in the us-ascii charset. You can usually ignore LANGUAGE. The parameter value (either the returned string, or the VALUE item in the 3-tuple) is always unquoted, unless unquote is set to False. If your application doesn't care whether the parameter was RFC 2231 encoded, it can turn the return value into a string as follows: rawparam = msg.get_param('foo') param = email.utils.collapse_rfc2231_value(rawparam) )rr+r3)r;rrrr2rzr{rrrr_szMessage.get_param Content-Typerc Cst|t r|r|||f}||kr4|jdkr4d}n |j|}|j||dsv|s^t|||}qtj|t|||g}nfd}x`|j||dD]N\} } d} | j|jkrt|||} n t| | |} |s| }qtj|| g}qW||j|kr|r|j ||n||=|||<dS)aSet a parameter in the Content-Type header. If the parameter already exists in the header, its value will be replaced with the new value. If header is Content-Type and has not yet been defined for this message, it will be set to "text/plain" and the new parameter and value will be appended as per RFC 2045. An alternate header can be specified in the header argument, and all parameters will be quoted as necessary unless requote is False. If charset is specified, the parameter will be encoded according to RFC 2231. Optional language specifies the RFC 2231 language, defaulting to the empty string. Both charset and language should be strings. z content-typez text/plain)rr)rr2N) rrr+r]r_r%rrcrr) r;rr$rrequoter ZlanguagerTrZ old_paramZ old_valueZ append_paramrrrrps2   zMessage.set_paramcCs||kr dSd}xR|j||dD]@\}}|j|jkr |sJt|||}q tj|t|||g}q W||j|kr||=|||<dS)a>Remove the given parameter completely from the Content-Type header. The header will be re-written in place without the parameter or its value. All values will be quoted as necessary unless requote is False. Optional header specifies an alternative to the Content-Type header. Nr)rr2)rr+r%rrcr])r;rrrZ new_ctyperr{rrrrnszMessage.del_paramcCs|jddkst|jdkr,|d=d|d<||kr@|||<dS|j||d}||=|||<x(|ddD]\}}|j||||qjWdS) aKSet the main type and subtype for the Content-Type header. type must be a string in the form "maintype/subtype", otherwise a ValueError is raised. This method replaces the Content-Type header, keeping all the parameters in place. If requote is False, this leaves the existing header's quoting as is. Otherwise, the parameters will be quoted (the default). An alternative header can be specified in the header argument. When the Content-Type header is set, we'll always also add a MIME-Version header. rrz content-typez mime-versionz1.0z MIME-VersionN)rr2)r)rur+rrp)r;r\rrrrr{rrrset_types zMessage.set_typecCsDt}|jd|d}||kr*|jd|d}||kr6|Stj|jS)a@Return the filename associated with the payload if present. The filename is extracted from the Content-Disposition header's `filename' parameter, and it is unquoted. If that header is missing the `filename' parameter, this method falls back to looking for the `name' parameter. filenamezcontent-dispositionrsz content-type)rr_rcollapse_rfc2231_valuer)r;rrrrrr get_filename&szMessage.get_filenamecCs,t}|jd|}||kr|Stj|jS)zReturn the boundary associated with the payload if present. The boundary is extracted from the Content-Type header's `boundary' parameter, and it is unquoted. boundary)rr_rrrstrip)r;rrrrrr get_boundary6s  zMessage.get_boundarycCs t}|j|d}||kr$tjdg}d}xB|D]:\}}|jdkr^|jdd|fd}q2|j||fq2W|s|jdd|fg}x|jD]\} } | jdkrg} x6|D].\} } | dkr| j| q| jd| | fqWtj| } |j|j j | | q|j| | fqW||_d S) aSet the boundary parameter in Content-Type to 'boundary'. This is subtly different than deleting the Content-Type header and adding a new one with a new boundary parameter via add_header(). The main difference is that using the set_boundary() method preserves the order of the Content-Type header in the original message. HeaderParseError is raised if the message has no Content-Type header. z content-typezNo Content-Type header foundFrz"%s"Trz%s=%sN) rrrZHeaderParseErrorr+r,r5rrcr4rw)r;rrrZ newparamsZfoundpZpkZpvr}hr{rrzrxrrr set_boundaryCs2      zMessage.set_boundarycCst}|jd|}||kr|St|trr|dp2d}y|djd}t||}Wn ttfk rp|d}YnXy|jdWntk r|SX|jS)zReturn the charset parameter of the Content-Type header. The returned string is always coerced to lower case. If there is no Content-Type header, or if that header has no charset parameter, failobj is returned. r rzus-asciirzraw-unicode-escape) rr_rrrr r`rar+)r;rrr ZpcharsetrHrrrget_content_charsetqs    zMessage.get_content_charsetcsfdd|jDS)aReturn a list containing the charset(s) used in this message. The returned list of items describes the Content-Type headers' charset parameter for this message and all the subparts in its payload. Each item will either be a string (the value of the charset parameter in the Content-Type header of that part) or the value of the 'failobj' parameter (defaults to None), if the part does not have a main MIME type of "text", or the charset is not defined. The list will contain one string for each part of the message, plus one for the container message (i.e. self), so that a non-multipart message will still return a list of length 1. csg|]}|jqSr)r)rpart)rrrrsz(Message.get_charsets..)walk)r;rr)rr get_charsetsszMessage.get_charsetscCs*|jd}|dkrdSt|dj}|S)zReturn the message's content-disposition if it exists, or None. The return values can be either 'inline', 'attachment' or None according to the rfc2183. zcontent-dispositionNr)r]rr+)r;r$c_drrrget_content_dispositions  zMessage.get_content_disposition)r)FrN)FN)NF)N)N)N)NrT)NrT)rTNrF)rT)rT)N)N)N)N)4__name__ __module__ __qualname____doc__r r<r>r=rIrHrLrMrNrRrhrmrlrqrrrtr|r~rrrrrr]rrrrorrrrrrrrr_rprnrrrrrrrZemail.iteratorsrrrrrrisb    Z /            ! 2   .   cseZdZd3ddZd4fdd ZddZd d Zd d Zd6ddZd7d8d9d:hZ ddZ ddZ ddddZ ddddZ ddZd;d d!ZdMIMEPartNcCs(|dkrddlm}|}tj||dS)Nr)default)Z email.policyrrr<)r;r4rrrrr<s zMIMEPart.__init__Fcs0|dkr|jn|}|dkr |j}tj||dS)aReturn the entire formatted message as a string. Optional 'unixfrom', when true, means include the Unix From_ envelope header. maxheaderlen is retained for backward compatibility with the base Message class, but defaults to None, meaning that the policy value for max_line_length controls the header maximum length. 'policy' is passed to the Generator instance used to serialize the mesasge; if it is not specified the policy associated with the message instance is used. N)rAr4)r4Zmax_line_lengthsuperr=)r;rBrAr4) __class__rrr=s zMIMEPart.as_stringcCs|j|jjdddS)NT)utf8)r4)r=r4Zclone)r;rrrr>szMIMEPart.__str__cCs |jd}|dkrdS|jdkS)Nzcontent-dispositionF attachment)r]Zcontent_disposition)r;rrrr is_attachments zMIMEPart.is_attachmentc cs |jr dS|jjd\}}|dkrB||kr>|j||fVdS|dkrNdS|dkr~x"|jD]}|j||EdHq`WdSd|kr|jd|fVd}|jd}|rx"|jD]}|d|kr|}PqW|dkr|j}|r|dnd}|dk r|j||EdHdS)Nrtext multipartrelatedstartz content-idr)rrrr* iter_parts _find_bodyr_rh) r;rpreferencelistmaintypesubtypeZsubpart candidaterZsubpartsrrrrs6   zMIMEPart._find_bodyrhtmlplaincCsDt|}d}x2|j||D]"\}}||kr|}|}|dkrPqW|S)aReturn best candidate mime part for display as 'body' of message. Do a depth first search, starting with self, looking for the first part matching each of the items in preferencelist, and return the part corresponding to the first item that has a match, or None if no items have a match. If 'related' is not included in preferencelist, consider the root part of any multipart/related encountered as a candidate match. Ignore parts with 'Content-Disposition: attachment'. Nr)rr)r;rZ best_prioZbodyZpriorrrrget_bodys zMIMEPart.get_bodyrr alternativec cs|jjd\}}|dks"|dkr&dS|jj}|dkr|dkr|jd}|rd}g}x*|D]"}|jd|krvd }q^|j|q^W|r|EdHdS|jd |EdHdSg}xP|D]H}|jjd\}}||f|jkr|j r||kr|j|q|VqWdS) aReturn an iterator over the non-main parts of a multipart. Skip the first of each occurrence of text/plain, text/html, multipart/related, or multipart/alternative in the multipart (unless they have a 'Content-Disposition: attachment' header) and include all remaining subparts in the returned iterator. When applied to a multipart/related, return all parts except the root part. Return an empty iterator when applied to a multipart/alternative or a non-multipart. rrrNrrFz content-idTr) rrrhrr_r]r,pop _body_typesr) r;rrrrryZ attachmentsrseenrrriter_attachmentss6         zMIMEPart.iter_attachmentsccs|jdkr|jEdHdS)z~Return an iterator over all immediate subparts of a multipart. Return an empty iterator for a non-multipart. rN)rrh)r;rrrr4s zMIMEPart.iter_parts)content_managercOs"|dkr|jj}|j|f||S)N)r4r get_content)r;rargskwrrrr<szMIMEPart.get_contentcOs&|dkr|jj}|j|f||dS)N)r4r set_content)r;rrrrrrrAszMIMEPart.set_contentc Cs|jdkr6|j}||f}||kr6tdj||g}g}x>|jD]4\}}|jjdrl|j||fqF|j||fqFW|rt||j d} || _|j | _ | g|_ ng|_ ||_d||d<|dk r|j d|dS)NrzCannot convert {} to {}zcontent-)r4z multipart/z Content-Typer) rrrurvr5r+ startswithr,r\r4r7rp) r;rZdisallowed_subtypesrZexisting_subtypeZ keep_headersZ part_headersrsr$rrrr_make_multipartFs,     zMIMEPart._make_multipartcCs|jdd|dS)Nrrmixed)rr)r)r;rrrr make_relatedaszMIMEPart.make_relatedcCs|jdd|dS)Nrr)r)r)r;rrrrmake_alternativedszMIMEPart.make_alternativecCs|jdf|dS)Nr)r)r;rrrr make_mixedgszMIMEPart.make_mixed)_dispcOsf|jdks|j|kr(t|d|t||jd}|j|||rXd|krX||d<|j|dS)NrZmake_)r4zcontent-dispositionzContent-Disposition)rrgetattrr\r4rrR)r;Z_subtyperrrrrrr_add_multipartjs    zMIMEPart._add_multipartcOs|jd|ddi|dS)NrrZinline)r)r)r;rrrrr add_relatedtszMIMEPart.add_relatedcOs|jd||dS)Nr)r)r)r;rrrrradd_alternativewszMIMEPart.add_alternativecOs|jd|ddi|dS)Nrrr)r)r)r;rrrrradd_attachmentzszMIMEPart.add_attachmentcCsg|_d|_dS)N)r5r7)r;rrrclear}szMIMEPart.clearcCsdd|jD|_d|_dS)NcSs&g|]\}}|jjds||fqS)zcontent-)r+r)rnr{rrrrsz*MIMEPart.clear_content..)r5r7)r;rrr clear_contentszMIMEPart.clear_content)N)FNNrrr)r)rr)rr)rr)rr)N)N)N)rrrr<r=r>rrrrrrrrrrrrrrrrrr __classcell__rr)rrrs0  .    rcseZdZfddZZS)rcs"tj||d|krd|d<dS)Nz MIME-Versionz1.0)rr)r;rr)rrrrszEmailMessage.set_content)rrrrrrr)rrrs)NT)r__all__rererbiorrZemailrrZemail._policybaserr r r8Zemail._encoded_wordsr rjrcompiler!rr%r1r3rrrrrrrs6      " NWparser.cpython-36.pyc000064400000013137147204636050010502 0ustar003 \@sdZddddddgZddlmZmZdd lmZmZdd lm Z Gd ddZ Gd dde Z Gd ddZ Gddde Z dS)z-A parser of RFC 2822 and MIME email messages.Parser HeaderParser BytesParserBytesHeaderParser FeedParserBytesFeedParser)StringIO TextIOWrapper)rr)compat32c@s0eZdZd edddZd ddZd dd ZdS) rN)policycCs||_||_dS)aParser of RFC 2822 and MIME email messages. Creates an in-memory object tree representing the email message, which can then be manipulated and turned over to a Generator to return the textual representation of the message. The string must be formatted as a block of RFC 2822 headers and header continuation lines, optionally preceded by a `Unix-from' header. The header block is terminated either by the end of the string or by a blank line. _class is the class to instantiate for new message objects when they must be created. This class must have a constructor that can take zero arguments. Default is Message.Message. The policy keyword specifies a policy object that controls a number of aspects of the parser's operation. The default policy maintains backward compatibility. N)_classr )selfr r r$/usr/lib64/python3.6/email/parser.py__init__szParser.__init__FcCsDt|j|jd}|r|jx|jd}|s.P|j|qW|jS)a\Create a message structure from the data in a file. Reads all the data from the file and returns the root of the message structure. Optional headersonly is a flag specifying whether to stop parsing after reading the headers or not. The default is False, meaning it parses the entire contents of the file. )r i )rr r Z_set_headersonlyreadZfeedclose)r fp headersonlyZ feedparserdatarrrparse*s z Parser.parsecCs|jt||dS)a-Create a message structure from a string. Returns the root of the message structure. Optional headersonly is a flag specifying whether to stop parsing after reading the headers or not. The default is False, meaning it parses the entire contents of the file. )r)rr)r textrrrrparsestr<szParser.parsestr)N)F)F)__name__ __module__ __qualname__r rrrrrrrrs c@s eZdZdddZdddZdS) rTcCstj||dS)NT)rr)r rrrrrrIszHeaderParser.parsecCstj||dS)NT)rr)r rrrrrrLszHeaderParser.parsestrN)T)T)rrrrrrrrrrHs c@s(eZdZddZd ddZd ddZdS) rcOst|||_dS)aParser of binary RFC 2822 and MIME email messages. Creates an in-memory object tree representing the email message, which can then be manipulated and turned over to a Generator to return the textual representation of the message. The input must be formatted as a block of RFC 2822 headers and header continuation lines, optionally preceded by a `Unix-from' header. The header block is terminated either by the end of the input or by a blank line. _class is the class to instantiate for new message objects when they must be created. This class must have a constructor that can take zero arguments. Default is Message.Message. N)rparser)r argskwrrrrRszBytesParser.__init__Fc Cs,t|ddd}z|jj||S|jXdS)acCreate a message structure from the data in a binary file. Reads all the data from the file and returns the root of the message structure. Optional headersonly is a flag specifying whether to stop parsing after reading the headers or not. The default is False, meaning it parses the entire contents of the file. asciisurrogateescape)encodingerrorsN)r rrdetach)r rrrrrrdszBytesParser.parsecCs|jddd}|jj||S)a2Create a message structure from a byte string. Returns the root of the message structure. Optional headersonly is a flag specifying whether to stop parsing after reading the headers or not. The default is False, meaning it parses the entire contents of the file. ASCIIr )r")decoderr)r rrrrr parsebytessszBytesParser.parsebytesN)F)F)rrrrrr&rrrrrPs c@s eZdZdddZdddZdS) rTcCstj||ddS)NT)r)rr)r rrrrrrszBytesHeaderParser.parsecCstj||ddS)NT)r)rr&)r rrrrrr&szBytesHeaderParser.parsebytesN)T)T)rrrrr&rrrrrs N)__doc____all__iorr Zemail.feedparserrrZemail._policybaser rrrrrrrrs 7/policy.cpython-36.pyc000064400000022624147204636050010506 0ustar003 \(@sdZddlZddlmZmZmZmZddlmZddl m Z ddl m Z ddl mZdd d d d d ddgZejdZeGdd d eZeZe`ejddZejddZejdddZejddZdS)zcThis will be the home for the policy that hooks in the new code that adds all the email6 features. N)PolicyCompat32compat32_extend_docstrings)_has_surrogates)HeaderRegistry)raw_data_manager) EmailMessagerrr EmailPolicydefaultstrictSMTPHTTPz\n|\rcspeZdZdZeZdZdZeZ e Z fddZ ddZ dd Zd d Zd d ZddZddZdddZZS)r aQ + PROVISIONAL The API extensions enabled by this policy are currently provisional. Refer to the documentation for details. This policy adds new header parsing and folding algorithms. Instead of simple strings, headers are custom objects with custom attributes depending on the type of the field. The folding algorithm fully implements RFCs 2047 and 5322. In addition to the settable attributes listed above that apply to all Policies, this policy adds the following additional attributes: utf8 -- if False (the default) message headers will be serialized as ASCII, using encoded words to encode any non-ASCII characters in the source strings. If True, the message headers will be serialized using utf8 and will not contain encoded words (see RFC 6532 for more on this serialization format). refold_source -- if the value for a header in the Message object came from the parsing of some source, this attribute indicates whether or not a generator should refold that value when transforming the message back into stream form. The possible values are: none -- all source values use original folding long -- source values that have any line that is longer than max_line_length will be refolded all -- all values are refolded. The default is 'long'. header_factory -- a callable that takes two arguments, 'name' and 'value', where 'name' is a header field name and 'value' is an unfolded header field value, and returns a string-like object that represents that header. A default header_factory is provided that understands some of the RFC5322 header field types. (Currently address fields and date fields have special treatment, while all other fields are treated as unstructured. This list will be completed before the extension is marked stable.) content_manager -- an object with at least two methods: get_content and set_content. When the get_content or set_content method of a Message object is called, it calls the corresponding method of this object, passing it the message object as its first argument, and any arguments or keywords that were passed to it as additional arguments. The default content_manager is :data:`~email.contentmanager.raw_data_manager`. Flongc s*d|krtj|dttjf|dS)Nheader_factory)object __setattr__rsuper__init__)selfkw) __class__$/usr/lib64/python3.6/email/policy.pyr\szEmailPolicy.__init__cCs |j|jS)z+ The implementation for this class returns the max_count attribute from the specialized header class that would be used to construct a header of type 'name'. )rZ max_count)rnamerrrheader_max_countcszEmailPolicy.header_max_countcCs>|djdd\}}|jddj|dd}||jdfS)ac+ The name is parsed as everything up to the ':' and returned unmodified. The value is determined by stripping leading whitespace off the remainder of the first line, joining all subsequent lines together, and stripping any trailing carriage return or linefeed characters. (This is the same as Compat32). r:z Nz )splitlstripjoinrstrip)rZ sourcelinesrvaluerrrheader_source_parseus zEmailPolicy.header_source_parsecCsVt|dr$|jj|jkr$||fSt|trFt|jdkrFtd||j||fS)a+ The name is returned unchanged. If the input value has a 'name' attribute and it matches the name ignoring case, the value is returned unchanged. Otherwise the name and value are passed to header_factory method, and the resulting custom header object is returned as the value. In this case a ValueError is raised if the input value contains CR or LF characters. rrzDHeader values may not contain linefeed or carriage return characters) hasattrrlower isinstancestrlen splitlines ValueErrorr)rrr#rrrheader_store_parses zEmailPolicy.header_store_parsecCs*t|dr|Sdjtj|}|j||S)ai+ If the value has a 'name' attribute, it is returned to unmodified. Otherwise the name and the value with any linesep characters removed are passed to the header_factory method, and the resulting custom header object is returned. Any surrogateescaped bytes get turned into the unicode unknown-character glyph. rr)r%r!linesep_splitterrr)rrr#rrrheader_fetch_parses zEmailPolicy.header_fetch_parsecCs|j||ddS)a + Header folding is controlled by the refold_source policy setting. A value is considered to be a 'source value' if and only if it does not have a 'name' attribute (having a 'name' attribute means it is a header object of some sort). If a source value needs to be refolded according to the policy, it is converted into a custom header object by passing the name and the value with any linesep characters removed to the header_factory method. Folding of a custom header object is done by calling its fold method with the current policy. Source values are split into lines using splitlines. If the value is not to be refolded, the lines are rejoined using the linesep from the policy and returned. The exception is lines containing non-ascii binary data. In that case the value is refolded regardless of the refold_source setting, which causes the binary data to be CTE encoded using the unknown-8bit charset. T) refold_binary)_fold)rrr#rrrfoldszEmailPolicy.foldcCs0|j|||jdkd}|jr dnd}|j|dS)a+ The same as fold if cte_type is 7bit, except that the returned value is bytes. If cte_type is 8bit, non-ASCII binary data is converted back into bytes. Headers with binary data are not refolded, regardless of the refold_header setting, since there is no way to know whether the binary data consists of single byte characters or multibyte characters. If utf8 is true, headers are encoded to utf8, otherwise to ascii with non-ASCII unicode rendered as encoded words. Z7bit)r/utf8asciisurrogateescape)r0Zcte_typer2encode)rrr#Zfoldedcharsetrrr fold_binaryszEmailPolicy.fold_binarycst|dr|j|dS|jr"|jntd|j}|jdkp|jdko|rft|dt|dkptfdd |d dD}|s|rt|r|j |d j |j|dS|d |j j ||j S) Nr)Zpolicyinfallrrc3s|]}t|kVqdS)N)r)).0x)maxlenrr sz$EmailPolicy._fold..rrz: ) r%r1max_line_lengthfloatr* refold_sourcer)anyrrr!linesep)rrr#r/linesZrefoldr)r=rr0s     zEmailPolicy._fold)F)__name__ __module__ __qualname____doc__r Zmessage_factoryr2rArrrZcontent_managerrrr$r,r.r1r7r0 __classcell__rr)rrr s;  T)Zraise_on_defectz )rC)rCr?)r2)rHreZemail._policybaserrrrZ email.utilsrZemail.headerregistryrZemail.contentmanagerrZ email.messager __all__compiler-r r rZcloner r rZSMTPUTF8rrrrs0      @  quoprimime.cpython-36.pyc000064400000017002147204636050011370 0ustar003 \& @sddZddddddddd d g Zd d lZd d lmZmZmZdZdZdZ dde dDZ e d d Z e d d Z x,dejdejdD]Zeee e<qWde ed<xdD]Zeee e<qWddZddZddZddZd,dd Zd!d Zd"d Zd-d$dZe d d Zxd%D]Zeeee<qWd&efd'dZefd(dZeZeZd)d*Zd+dZ d S).aFQuoted-printable content transfer encoding per RFCs 2045-2047. This module handles the content transfer encoding method defined in RFC 2045 to encode US ASCII-like 8-bit data called `quoted-printable'. It is used to safely encode text that is in a character set similar to the 7-bit US ASCII character set, but that includes some 8-bit characters that are normally not allowed in email bodies or headers. Quoted-printable is very space-inefficient for encoding binary files; use the email.base64mime module for that instead. This module provides an interface to encode and decode both headers and bodies with quoted-printable encoding. RFC 2045 defines a method for including character set information in an `encoded-word' in a header. This method is commonly used for 8-bit real names in To:/From:/Cc: etc. fields, as well as Subject: lines. This module does not do the line wrapping or end-of-line character conversion necessary for proper internationalized headers; it only does dumb encoding and decoding. To deal with the various line wrapping issues, use the email.header module. body_decode body_encode body_lengthdecode decodestring header_decode header_encode header_lengthquoteunquoteN) ascii_lettersdigits hexdigitsz  cCsg|] }d|qS)z=%02X).0crr(/usr/lib64/python3.6/email/quoprimime.py 7srs-!*+/ascii_ s_ !"#$%&'()*+,-./0123456789:;<>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ cCst|t|kS)z>Return True if the octet should be escaped with header quopri.)chr_QUOPRI_HEADER_MAP)octetrrr header_checkJsrcCst|t|kS)z^sz header_length..)sum) bytearrayrrrrTs cCstdd|DS)zReturn a body quoted-printable encoding length. :param bytearray: An array of bytes (a.k.a. octets). :return: The length in bytes of the byte array when it is encoded with quoted-printable for bodies. css|]}tt|VqdS)N)r r)rrrrrr!hszbody_length..)r")r#rrrrascCsft|tst|}|s&|j|jnn^|d|kr||dtkr||dtkr|t|||d7}|d7}n||7}|d7}||kr>||7}q>WqW|d dkr|j|r|dd }|S) z_Decode a quoted-printable string. Lines are separated with eol, which defaults to \n. rr r:r$r;r.z Nr%r%)r>rstripr rr endswith)r7rAZdecodedrBinrrrrrs8   ,  cCs|jd}t|S)zCTurn a match in the form =AB to the ASCII character with value 0xabr )groupr )matchr+rrr_unquote_matchs rLcCs |jdd}tjdt|tjdS)aDecode a string encoded with RFC 2045 MIME header `Q' encoding. This function does not parse a full MIME header value encoded with quoted-printable (like =?iso-8859-1?q?Hello_World?=) -- please use the high level email.header class for that functionality. rrz=[a-fA-F0-9]{2})flags)replaceresubrLASCII)r+rrrr#s )r)r3)!__doc____all__rOstringr r rr?NLZ EMPTYSTRINGranger1rrencoderrr2rrrrr-r r rr=rrrrrLrrrrrsP         O 0utils.cpython-36.pyc000064400000031627147204636050010352 0ustar003 fJ@sdZddddddddd d d d d ddgZddlZddlZddlZddlZddlZddlZddlZ ddl m Z ddl m Z ddl mZddl mZmZmZddlmZdZdZdZdZdZejdZejdZdZdaddZd d!Zd"d#Z d$d%Z!dId'dZ"d(d)Z#d*d+Z$d,Z%dd-d.dZ&d/d0Z'd1d2Z(d3d4Z)ejd5ej*ej+BZ,d6d7Z-dJd9dZ.dKd:dZ/dLd;d Z0ddZ3d?dZ4dMd@dZ5ejdAej6Z7dBdZ8dNdEdZ9dPdGdHZ:dS)QzMiscellaneous utilities.collapse_rfc2231_value decode_paramsdecode_rfc2231encode_rfc2231 formataddr formatdateformat_datetime getaddresses make_msgid mktime_tz parseaddr parsedate parsedate_tzparsedate_to_datetimeunquoteN)quote) AddressList)r )r r _parsedate_tz)Charsetz, z 'z[][\\()<>@,:;".]z[\\"]z/etc/python/email.cfgcCstdkrtatS)z5"Cache implementation for _cached_strict_addr_parsingN)_cached_strict_addr_parsing_use_strict_email_parsing_implrr#/usr/lib64/python3.6/email/utils.py_use_strict_email_parsing7srcCsttjjd}|rdSy tt}Wntk r8YnBX|6ddl}|jdd d}|j ||j dddd}WdQRX|rdSd S) z]Returns True if strict email parsing is not disabled by config file or env variable. Z(PYTHON_EMAIL_DISABLE_STRICT_ADDR_PARSINGFrN#)Z interpolationZcomment_prefixesZemail_addr_parsing)ZfallbackT)r) boolosenvirongetopen_EMAIL_CONFIG_FILEFileNotFoundError configparserZ ConfigParserZ read_fileZ getboolean)Zdisabledfiler$configrrrr?s"  rc Cs&y |jdStk r dSXdS)z8Return True if s contains surrogate-escaped binary data.FTN)encodeUnicodeEncodeError)srrr_has_surrogates\s r*cCs|jdd}|jddS)Nzutf-8surrogateescapereplace)r'decode)stringZoriginal_bytesrrr _sanitizeis r/utf-8c Cs|\}}|jd|ry|jdWn8tk r\t|trFt|}|j|}d||fSXd}tj|rpd}tj d|}d||||fS|S)aThe inverse of parseaddr(), this takes a 2-tuple of the form (realname, email_address) and returns the string value suitable for an RFC 2822 From, To or Cc header. If the first element of pair is false, then the second element is returned unmodified. Optional charset if given is the character set that is used to encode realname in case realname is not ASCII safe. Can be an instance of str or a Charset-like object which has a header_encode method. Default is 'utf-8'. asciiz%s <%s>r"z\\\g<0>z %s%s%s <%s>) r'r( isinstancestrrZ header_encode specialsresearch escapesresub)ZpaircharsetnameZaddressZ encoded_nameZquotesrrrrus      ccs`d}d}xDt|D]8\}}|r2|d|fVd}q|dkr@d}q||fVqW|r\|dfVdS)NrF\T) enumerate)addrposescapechrrr_iter_escaped_charssrAcCsd|kr |Sd}d}g}xPt|D]D\}}|dkr"|dkr@|}q"||krZ|j||||d}d}q"W|t|kr|j||ddj|S)z Strip real names between quotes.r2rNr)rAappendlenjoin)r=startZopen_posresultr>r@rrr_strip_quoted_realnamess  rHT)strictcCs|dkrt}|s4tjdd|D}t|}|jSdd|D}t|}tj|}t|}t|j}d}x&|D]}t|}|d|jd7}qpWt ||krd gS|S) zReturn a list of (REALNAME, EMAIL) or ('','') for each fieldvalue. When parsing fails for a fieldvalue, a 2-tuple of ('', '') is returned in its place. If strict is true, use a strict parser which rejects malformed inputs. Ncss|]}t|VqdS)N)r4).0vrrr szgetaddresses..cSsg|] }t|qSr)r4)rJrKrrr sz getaddresses..rrB,r)rr) r COMMASPACErE _AddressList addresslist_pre_parse_validation_post_parse_validationrHcountrD)Z fieldvaluesrIallar=rGnrKrrrrs$      cCsXt|}d}xBt|D]6\}}|dkr0|d7}q|dkr|d8}|dkrdSqW|dkS)Nr(rB)F)rHrA)r=Zopensr>r@rrr_check_parenthesiss rZcCs,g}x"|D]}t|sd}|j|q W|S)Nz('', ''))rZrC)Zemail_header_fieldsaccepted_valuesrKrrrrRs  rRcCs0g}x&|D]}d|dkrd}|j|q W|S)N[rBr)rr)rC)Zparsed_email_header_tuplesr[rKrrrrS s   rSa_ =\? # literal =? (?P[^?]*?) # non-greedy up to the next ? is the charset \? # literal ? (?P[qb]) # either a "q" or a "b", case insensitive \? # literal ? (?P.*?) # non-greedy up to the next ?= is the atom \?= # literal ?= cCsfddddddddg|d |d d d d dddddddddg |dd|d|d|d|d|fS)Nz"%s, %02d %s %04d %02d:%02d:%02d %sZMonZTueZWedZThuZFriZSatZSunZJanZFebZMarZAprZMayZJunZJulZAugZSepZOctZNovZDecrBrr) timetuplezonerrr_format_timetuple_and_zone"s rdFcCsR|dkrtj}|s|r,tjj|tjj}n tjj|}|rH|j}d}t||S)aReturns a date string as specified by RFC 2822, e.g.: Fri, 09 Nov 2001 01:08:47 -0000 Optional timeval if given is a floating point time value as accepted by gmtime() and localtime(), otherwise the current time is used. Optional localtime is a flag that when True, interprets timeval, and returns a date relative to the local timezone instead of UTC, properly taking daylight savings time into account. Optional argument usegmt means that the timezone is written out as an ascii string, not numeric one (so "GMT" instead of "+0000"). This is needed for HTTP, and is only used when localtime==False. NF)timedatetimeZ fromtimestamptimezoneutcZutcfromtimestamp astimezoner)timeval localtimeusegmtdtrrrr+s cCsV|j}|r2|jdks$|jtjjkr,tdd}n|jdkrBd}n |jd}t||S)a$Turn a datetime into a date string as specified in RFC 2822. If usegmt is True, dt must be an aware datetime with an offset of zero. In this case 'GMT' will be rendered instead of the normal +0000 required by RFC2822. This is to support HTTP headers involving date stamps. Nz%usegmt option requires a UTC datetimeZGMTz-0000z%z)rbtzinforfrgrh ValueErrorZstrftimerd)rmrlnowrcrrrrHs  cCs^ttjd}tj}tjd}|dkr0d}nd|}|dkrHtj}d|||||f}|S)a{Returns a string suitable for RFC 2822 compliant Message-ID, e.g: <142480216486.20800.16526388040877946887@nightshade.la.mastaler.com> Optional idstring if given is a string used to strengthen the uniqueness of the message id. Optional domain if given provides the portion of the message id after the '@'. It defaults to the locally defined hostname. d@Nr.z<%d.%d.%d%s@%s>)intrergetpidrandomZ getrandbitssocketZgetfqdn)ZidstringZdomainrjpidZrandintZmsgidrrrr [s  cCsNt|^}}|dkr(tj|ddStj|dddtjtj|diS)Nr]rn)seconds)rrfrg timedelta)dataZdtupletzrrrrrs cCs|dkrt}|s,t|j}|s$dS|dSt|tr>|d}t|tsLdSt|gd}tt|j}| szt|dkr~dS|dS)a Parse addr into its constituent realname and email address parts. Return a tuple of realname and email address, unless the parse fails, in which case return a 2-tuple of ('', ''). If strict is True, use a strict parser which rejects malformed inputs. NrrrB)rr)rr)rr) rrPrQr3listr4rRrSrD)r=rIZaddrsrrrr zs    cCs`t|dkr\|jdr<|jdr<|ddjddjddS|jdr\|jdr\|dd S|S) zRemove quotes from a string.rBr2z\\r;z\"<>r)rD startswithendswithr,)r4rrrrs   cCs&|jtd}t|dkr"dd|fS|S)z#Decode string according to RFC 2231r^N)splitTICKrD)r)partsrrrrs   cCsDtjj|d|pdd}|dkr*|dkr*|S|dkr6d}d|||fS)zEncode string according to RFC 2231. If neither charset nor language is given, then s is returned as-is. If charset is given but not language, the string is encoded using the empty string for language. rr1)ZsafeencodingNz%s'%s'%s)urllibparser)r)r9languagerrrrs z&^(?P\w+)\*((?P[0-9]+)\*?)?$c Csx|dd}g}i}|jd\}}|j||fx|r|jd\}}|jdrTd}nd}t|}tj|}|r|jdd\}}|dk rt|}|j|gj|||fq2|j|dt |fq2W|rtx|j D]\}}g}d} |j x6|D].\}} }|rt j j| d d } d} |j| qWt tj|}| r^t|\} } }|j|| | d|ffq|j|d|fqW|S) zDecode parameters list according to RFC 2231. params is a sequence of 2-tuples containing (param name, string value). Nr*TFr:numz"%s"zlatin-1)r)poprCrrrfc2231_continuationmatchgrouprt setdefaultritemssortrr EMPTYSTRINGrEr) ZparamsZ new_paramsZrfc2231_paramsr:valueZencodedZmorZ continuationsZextendedr)r9rrrrrsD   r,us-asciic Csjt|t st|dkr t|S|\}}}|dkr6|}t|d}y t|||Stk rdt|SXdS)Nr_zraw-unicode-escape)r3tuplerDrbytesr4 LookupError)rerrorsZfallback_charsetr9rtextZrawbytesrrrrs   rBc Cs|dkrtjjtjjjS|jdk r.|jS|jdd|f}tj|}tj |}y tj |j d}tj||j }Wnt k r|tjtj|dd}tjo|jdk}|rtjntj }|tj |dkrtj|tj|}n tj|}YnX|j|dS)aReturn local time as an aware datetime object. If called without arguments, return current time. Otherwise *dt* argument should be a datetime instance, and it is converted to the local time zone according to the system time zone database. If *dt* is naive (that is, dt.tzinfo is None), it is assumed to be in local time. In this case, a positive or zero value for *isdst* causes localtime to presume initially that summer time (for example, Daylight Saving Time) is or is not (respectively) in effect for the specified time. A negative value for *isdst* causes the localtime() function to attempt to divine whether summer time is in effect for the specified time. NrB)ryr]r)rnr)rfrprgrhrirnrbreZmktimerkrzZ tm_gmtoffZtm_zoneAttributeErrorZgmtimeZdaylightZtm_isdstZaltzoneZtznamer,) rmZisdstZtmryZlocaltmZdeltar|dstZgmtoffrrrrks$   rk)r0)NFF)F)NN)NN)r,rr)Nr);__doc____all__rrerervrwrfZ urllib.parserZemail._parseaddrrrrPr r r rZ email.charsetrrOrZ UEMPTYSTRINGZCRLFrcompiler5r7r"rrrr*r/rrArHZsupports_strict_parsingrrZrRrSVERBOSE IGNORECASEZecrerdrrr rr rrrASCIIrrrrkrrrrs        !1     $  8 _encoded_words.cpython-36.opt-2.pyc000064400000007164147204636050013127 0ustar003 \F!@sddlZddlZddlZddlZddlmZmZddlmZdddddd d d gZ ej ej d j d dZ ddZGdddeZeZdeed<ddZddZddZddZdd ZeedZdd ZeedZeedZddd ZdS)N) ascii_lettersdigits)errorsdecode_qencode_qdecode_bencode_blen_qlen_bdecodeencodes=([a-fA-F0-9]{2})cCstt|jddgS)N)bytesintgroup)mr,/usr/lib64/python3.6/email/_encoded_words.pyAsrcCs|jdd}t|gfS)N_ )replace_q_byte_subber)encodedrrrrCs c@s,eZdZdejdejdZddZdS) _QByteMaps-!*+/asciicCs.||jkrt|||<ndj|||<||S)Nz={:02X})safechrformat)selfkeyrrr __missing__Ms z_QByteMap.__missing__N)__name__ __module__ __qualname__rr rrr"rrrrrIsr_ cCsdjdd|DS)Ncss|]}t|VqdS)N) _q_byte_map).0xrrr Zszencode_q..)join)bstringrrrrYscCstdd|DS)Ncss|]}tt|VqdS)N)lenr))r*r+rrrr,]szlen_q..)sum)r.rrrr \scCst|d}|r ddd|nd}y$tj||dd|rDtjgngfStjk rytj|ddtjgfStjk ry"tj|dddtjtjgfStjk r|tjgfSXYnXYnXdS)Ns===T)ZvalidateFs==) r/base64Z b64decoderZInvalidBase64PaddingDefectbinasciiErrorZInvalidBase64CharactersDefectZInvalidBase64LengthDefect)rZpad_errZmissing_paddingrrrrds     cCstj|jdS)Nr)r3Z b64encoder )r.rrrrscCs&tt|d\}}|d|r dndS)Nr1r)divmodr/)r.Z groups_of_3Zleftoverrrrr s)qbc Cs|jd\}}}}}|jd\}}}|j}|jdd}t||\}}y|j|}Wnvtk r|jtj dj ||j|d}YnBt k r|jdd}|jdkr|jtj dj |YnX||||fS)N?*rsurrogateescapez:Encoded word contains bytes not decodable using {} charsetz unknown-8bitz*s@    &+_header_value_parser.cpython-36.opt-1.pyc000064400000224527147204636050014313 0ustar003 f@szdZddlZddlZddlmZddlmZddlmZddl m Z ddl m Z ddl m Z ed Zeed BZed ZeeBZeed Zeed ZeedBed ZeeBZeedBZeeBZeedZddhZeeBZddZGdddeZGdddeZGdddeZ GdddeZ!GdddeZ"Gdd d eZ#Gd!d"d"eZ$Gd#d$d$eZ%Gd%d&d&eZ&Gd'd(d(eZ'Gd)d*d*e'Z(Gd+d,d,eZ)Gd-d.d.eZ*Gd/d0d0eZ+Gd1d2d2eZ,Gd3d4d4eZ-Gd5d6d6eZ.Gd7d8d8eZ/Gd9d:d:eZ0Gd;d<dd>eZ2Gd?d@d@eZ3GdAdBdBeZ4GdCdDdDeZ5GdEdFdFeZ6GdGdHdHeZ7GdIdJdJeZ8GdKdLdLe!Z9GdMdNdNeZ:GdOdPdPeZ;GdQdRdReZGdWdXdXeZ?GdYdZdZeZ@Gd[d\d\eZAGd]d^d^eZBGd_d`d`eZCGdadbdbeCZDGdcddddeCZEGdedfdfeZFGdgdhdheZGGdidjdjeZHGdkdldleIZJGdmdndneJZKGdodpdpeJZLGdqdrdreKZMeLd dsZNeLdtduZOeLdvdwZPejQdxjRdyjSejTZUejQdzjRdyjSejVd{d|jVd}d~jWZXejQdjYZZejQdzjRdyjSejVd{d|jVd}d~jWZ[ejQdzjRdyjSejVd{d|jVd}d~jWZ\ejQdzjRdyjSejVd{d|jVd}d~jWZ]ddZ^ddZ_ddZ`ddZaddZbddZcddZdddZeddZfddZgddZhddZiddZjddZkddZlddZmddZnddZoddZpddZqddZrddZsddZtddZuddZvddZwddZxddZyddZzddZ{ddZ|ddZ}ddZ~ddÄZddńZddDŽZddɄZdd˄Zdd̈́ZddτZddфZddӄZddՄZddׄZddلZddۄZdd݄Zdd߄ZddZddZddZddZddZddZddZdS)alHeader value parser implementing various email-related RFC parsing rules. The parsing methods defined in this module implement various email related parsing rules. Principal among them is RFC 5322, which is the followon to RFC 2822 and primarily a clarification of the former. It also implements RFC 2047 encoded word decoding. RFC 5322 goes to considerable trouble to maintain backward compatibility with RFC 822 in the parse phase, while cleaning up the structure on the generation phase. This parser supports correct RFC 5322 generation by tagging white space as folding white space only when folding is allowed in the non-obsolete rule sets. Actually, the parser is even more generous when accepting input than RFC 5322 mandates, following the spirit of Postel's Law, which RFC 5322 encourages. Where possible deviations from the standard are annotated on the 'defects' attribute of tokens that deviate. The general structure of the parser follows RFC 5322, and uses its terminology where there is a direct correspondence. Where the implementation requires a somewhat different structure than that used by the formal grammar, new terms that mimic the closest existing terms are used. Thus, it really helps to have a copy of RFC 5322 handy when studying this code. Input to the parser is a string that has already been unfolded according to RFC 5322 rules. According to the RFC this unfolding is the very first step, and this parser leaves the unfolding step to a higher level message parser, which will have already detected the line breaks that need unfolding while determining the beginning and end of each header. The output of the parser is a TokenList object, which is a list subclass. A TokenList is a recursive data structure. The terminal nodes of the structure are Terminal objects, which are subclasses of str. These do not correspond directly to terminal objects in the formal grammar, but are instead more practical higher level combinations of true terminals. All TokenList and Terminal objects have a 'value' attribute, which produces the semantically meaningful value of that part of the parse subtree. The value of all whitespace tokens (no matter how many sub-tokens they may contain) is a single space, as per the RFC rules. This includes 'CFWS', which is herein included in the general class of whitespace tokens. There is one exception to the rule that whitespace tokens are collapsed into single spaces in values: in the value of a 'bare-quoted-string' (a quoted-string with no leading or trailing whitespace), any whitespace that appeared between the quotation marks is preserved in the returned value. Note that in all Terminal strings quoted pairs are turned into their unquoted values. All TokenList and Terminal objects also have a string value, which attempts to be a "canonical" representation of the RFC-compliant form of the substring that produced the parsed subtree, including minimal use of quoted pair quoting. Whitespace runs are not collapsed. Comment tokens also have a 'content' attribute providing the string found between the parens (including any nested comments) with whitespace preserved. All TokenList and Terminal objects have a 'defects' attribute which is a possibly empty list all of the defects found while creating the token. Defects may appear on any token in the tree, and a composite list of all defects in the subtree is available through the 'all_defects' attribute of any node. (For Terminal notes x.defects == x.all_defects.) Each object in a parse tree is called a 'token', and each has a 'token_type' attribute that gives the name from the RFC 5322 grammar that it represents. Not all RFC 5322 nodes are produced, and there is one non-RFC 5322 node that may be produced: 'ptext'. A 'ptext' is a string of printable ascii characters. It is returned in place of lists of (ctext/quoted-pair) and (qtext/quoted-pair). XXX: provide complete list of token types. N) hexdigits) OrderedDict) itemgetter)_encoded_words)errors)utilsz (z ()<>@,:;.\"[].z."(z/?=z*'%%  cCs dt|jddjdddS)N"\z\\z\")strreplace)valuer2/usr/lib64/python3.6/email/_header_value_parser.py quote_stringbsrcseZdZdZdZdZfddZddZfddZe d d Z e d d Z d dZ e ddZ e ddZddZdddZdddZdddZZS) TokenListNTcstj||g|_dS)N)super__init__defects)selfargskw) __class__rrroszTokenList.__init__cCsdjdd|DS)Ncss|]}t|VqdS)N)r).0xrrr tsz$TokenList.__str__..)join)rrrr__str__sszTokenList.__str__csdj|jjtjS)Nz{}({}))formatr__name__r__repr__)r)rrrr%vs zTokenList.__repr__cCsdjdd|DS)Nrcss|]}|jr|jVqdS)N)r)rrrrrr |sz"TokenList.value..)r!)rrrrrzszTokenList.valuecCstdd|D|jS)Ncss|] }|jVqdS)N) all_defects)rrrrrr sz(TokenList.all_defects..)sumr)rrrrr&~szTokenList.all_defectscCs |djS)Nr)startswith_fws)rrrrr(szTokenList.startswith_fwscCstdd|DS)zATrue if all top level tokens of this part may be RFC2047 encoded.css|] }|jVqdS)N) as_ew_allowed)rpartrrrr sz*TokenList.as_ew_allowed..)all)rrrrr)szTokenList.as_ew_allowedcCs"g}x|D]}|j|jq W|S)N)extendcomments)rr-tokenrrrr-s zTokenList.commentscCs t||dS)N)policy)_refold_parse_tree)rr/rrrfoldszTokenList.foldrcCst|j|ddS)N)indent)printppstr)rr2rrrpprintszTokenList.pprintcCsdj|j|dS)Nr )r2)r!_pp)rr2rrrr4szTokenList.ppstrccs~dj||jj|jVx<|D]4}t|ds<|dj|Vq|j|dEdHqW|jrhdj|j}nd}dj||VdS)Nz{}{}/{}(r6z* !! invalid element in token list: {!r}z z Defects: {}rz{}){})r#rr$ token_typehasattrr6r)rr2r.Zextrarrrr6s    z TokenList._pp)r)r)r)r$ __module__ __qualname__r7syntactic_breakew_combine_allowedrr"r%propertyrr&r(r)r-r1r5r4r6 __classcell__rr)rrris        rc@s$eZdZeddZeddZdS)WhiteSpaceTokenListcCsdS)N r)rrrrrszWhiteSpaceTokenList.valuecCsdd|DS)NcSsg|]}|jdkr|jqS)comment)r7content)rrrrr sz0WhiteSpaceTokenList.comments..r)rrrrr-szWhiteSpaceTokenList.commentsN)r$r9r:r=rr-rrrrr?s r?c@seZdZdZdS)UnstructuredTokenList unstructuredN)r$r9r:r7rrrrrDsrDc@seZdZdZdS)PhrasephraseN)r$r9r:r7rrrrrFsrFc@seZdZdZdS)WordZwordN)r$r9r:r7rrrrrHsrHc@seZdZdZdS)CFWSListcfwsN)r$r9r:r7rrrrrIsrIc@seZdZdZdS)AtomatomN)r$r9r:r7rrrrrKsrKc@seZdZdZdZdS)Tokenr.FN)r$r9r:r7Z encode_as_ewrrrrrMsrMc@seZdZdZdZdZdZdS) EncodedWordz encoded-wordN)r$r9r:r7ctecharsetlangrrrrrNsrNc@s4eZdZdZeddZeddZeddZdS) QuotedStringz quoted-stringcCs"x|D]}|jdkr|jSqWdS)Nzbare-quoted-string)r7r)rrrrrrBs  zQuotedString.contentcCsBg}x2|D]*}|jdkr(|jt|q |j|jq Wdj|S)Nzbare-quoted-stringr)r7appendrrr!)rresrrrr quoted_values   zQuotedString.quoted_valuecCs"x|D]}|jdkr|jSqWdS)Nzbare-quoted-string)r7r)rr.rrrstripped_values  zQuotedString.stripped_valueN)r$r9r:r7r=rBrUrVrrrrrRs  rRc@s$eZdZdZddZeddZdS)BareQuotedStringzbare-quoted-stringcCstdjdd|DS)Nrcss|]}t|VqdS)N)r)rrrrrr sz+BareQuotedString.__str__..)rr!)rrrrr"szBareQuotedString.__str__cCsdjdd|DS)Nrcss|]}t|VqdS)N)r)rrrrrr sz)BareQuotedString.value..)r!)rrrrrszBareQuotedString.valueN)r$r9r:r7r"r=rrrrrrWsrWc@s8eZdZdZddZddZeddZedd Zd S) CommentrAcs(djtdgfddDdgggS)Nrrcsg|]}j|qSr)quote)rr)rrrrC sz#Comment.__str__..))r!r')rr)rrr"s zComment.__str__cCs2|jdkrt|St|jddjddjddS)NrArz\\rz\(rZz\))r7rr)rrrrrrYs  z Comment.quotecCsdjdd|DS)Nrcss|]}t|VqdS)N)r)rrrrrr sz"Comment.content..)r!)rrrrrBszComment.contentcCs|jgS)N)rB)rrrrr-szComment.commentsN) r$r9r:r7r"rYr=rBr-rrrrrXs  rXc@s4eZdZdZeddZeddZeddZdS) AddressListz address-listcCsdd|DS)NcSsg|]}|jdkr|qS)address)r7)rrrrrrC$sz)AddressList.addresses..r)rrrr addresses"szAddressList.addressescCstdd|DgS)Ncss|]}|jdkr|jVqdS)r\N)r7 mailboxes)rrrrrr (sz(AddressList.mailboxes..)r')rrrrr^&szAddressList.mailboxescCstdd|DgS)Ncss|]}|jdkr|jVqdS)r\N)r7 all_mailboxes)rrrrrr -sz,AddressList.all_mailboxes..)r')rrrrr_+szAddressList.all_mailboxesN)r$r9r:r7r=r]r^r_rrrrr[s  r[c@s4eZdZdZeddZeddZeddZdS) Addressr\cCs|djdkr|djSdS)Nrgroup)r7 display_name)rrrrrb5szAddress.display_namecCs4|djdkr|dgS|djdkr*gS|djS)Nrmailboxzinvalid-mailbox)r7r^)rrrrr^:s  zAddress.mailboxescCs:|djdkr|dgS|djdkr0|dgS|djS)Nrrczinvalid-mailbox)r7r_)rrrrr_Bs   zAddress.all_mailboxesN)r$r9r:r7r=rbr^r_rrrrr`1s  r`c@s(eZdZdZeddZeddZdS) MailboxListz mailbox-listcCsdd|DS)NcSsg|]}|jdkr|qS)rc)r7)rrrrrrCPsz)MailboxList.mailboxes..r)rrrrr^NszMailboxList.mailboxescCsdd|DS)NcSsg|]}|jdkr|qS)rcinvalid-mailbox)rcre)r7)rrrrrrCTsz-MailboxList.all_mailboxes..r)rrrrr_RszMailboxList.all_mailboxesN)r$r9r:r7r=r^r_rrrrrdJs rdc@s(eZdZdZeddZeddZdS) GroupListz group-listcCs"| s|djdkrgS|djS)Nrz mailbox-list)r7r^)rrrrr^\szGroupList.mailboxescCs"| s|djdkrgS|djS)Nrz mailbox-list)r7r_)rrrrr_bszGroupList.all_mailboxesN)r$r9r:r7r=r^r_rrrrrfXs rfc@s4eZdZdZeddZeddZeddZdS) GroupracCs|djdkrgS|djS)Nz group-list)r7r^)rrrrr^mszGroup.mailboxescCs|djdkrgS|djS)Nrhz group-list)r7r_)rrrrr_sszGroup.all_mailboxescCs |djS)Nr)rb)rrrrrbyszGroup.display_nameN)r$r9r:r7r=r^r_rbrrrrrgis  rgc@sLeZdZdZeddZeddZeddZedd Zed d Z d S) NameAddrz name-addrcCst|dkrdS|djS)Nr)lenrb)rrrrrbs zNameAddr.display_namecCs |djS)Nrj) local_part)rrrrrmszNameAddr.local_partcCs |djS)Nrjrl)domain)rrrrrnszNameAddr.domaincCs |djS)Nrjrl)route)rrrrroszNameAddr.routecCs |djS)Nrjrl) addr_spec)rrrrrpszNameAddr.addr_specN) r$r9r:r7r=rbrmrnrorprrrrri~s     ric@s@eZdZdZeddZeddZeddZedd Zd S) AngleAddrz angle-addrcCs"x|D]}|jdkr|jSqWdS)Nz addr-spec)r7rm)rrrrrrms  zAngleAddr.local_partcCs"x|D]}|jdkr|jSqWdS)Nz addr-spec)r7rn)rrrrrrns  zAngleAddr.domaincCs"x|D]}|jdkr|jSqWdS)Nz obs-route)r7domains)rrrrrros  zAngleAddr.routecCs<x6|D]*}|jdkr|jr |jSt|j|jSqWdSdS)Nz addr-specz<>)r7rmrpr)rrrrrrps   zAngleAddr.addr_specN) r$r9r:r7r=rmrnrorprrrrrqs    rqc@seZdZdZeddZdS)ObsRoutez obs-routecCsdd|DS)NcSsg|]}|jdkr|jqS)rn)r7rn)rrrrrrCsz$ObsRoute.domains..r)rrrrrrszObsRoute.domainsN)r$r9r:r7r=rrrrrrrssrsc@sLeZdZdZeddZeddZeddZedd Zed d Z d S) MailboxrccCs|djdkr|djSdS)Nrz name-addr)r7rb)rrrrrbszMailbox.display_namecCs |djS)Nr)rm)rrrrrmszMailbox.local_partcCs |djS)Nr)rn)rrrrrnszMailbox.domaincCs|djdkr|djSdS)Nrz name-addr)r7ro)rrrrrosz Mailbox.routecCs |djS)Nr)rp)rrrrrpszMailbox.addr_specN) r$r9r:r7r=rbrmrnrorprrrrrts     rtc@s,eZdZdZeddZeZZZZ dS)InvalidMailboxzinvalid-mailboxcCsdS)Nr)rrrrrbszInvalidMailbox.display_nameN) r$r9r:r7r=rbrmrnrorprrrrrus rucs(eZdZdZdZefddZZS)DomainrnFcsdjtjjS)Nr)r!rrsplit)r)rrrrnsz Domain.domain)r$r9r:r7r)r=rnr>rr)rrrvsrvc@seZdZdZdS)DotAtomzdot-atomN)r$r9r:r7rrrrrxsrxc@seZdZdZdZdS) DotAtomTextz dot-atom-textTN)r$r9r:r7r)rrrrrysryc@sDeZdZdZdZeddZeddZeddZed d Z d S) AddrSpecz addr-specFcCs |djS)Nr)rm)rrrrrmszAddrSpec.local_partcCst|dkrdS|djS)Nrjrl)rkrn)rrrrrns zAddrSpec.domaincCs<t|dkr|djS|djj|dj|djjS)Nr{rrjrh)rkrrstriplstrip)rrrrrs  zAddrSpec.valuecCsLt|j}t|t|tkr*t|j}n|j}|jdk rH|d|jS|S)N@)setrmrk DOT_ATOM_ENDSrrn)rZnamesetZlprrrrps   zAddrSpec.addr_specN) r$r9r:r7r)r=rmrnrrprrrrrzs    rzc@seZdZdZdZdS) ObsLocalPartzobs-local-partFN)r$r9r:r7r)rrrrr srcs4eZdZdZdZeddZefddZZS) DisplayNamez display-nameFcCst|}|djdkr"|jdn*|ddjdkrLt|ddd|d<|djdkrd|jn*|ddjdkrt|ddd|d <|jS) NrrJrjrlrlrlrlrlrl)rr7popr)rrTrrrrb+s  zDisplayName.display_namecsd}|jrd}nx|D]}|jdkrd}qW|rd}}|djdksX|ddjdkr\d}|d jdks||d d jdkrd}|t|j|StjSdS) NFTz quoted-stringrrrJr@rjrlrlrl)rr7rrbrr)rrYrZpreZpost)rrrr:s    zDisplayName.value) r$r9r:r7r<r=rbrr>rr)rrr&s rc@s,eZdZdZdZeddZeddZdS) LocalPartz local-partFcCs&|djdkr|djS|djSdS)Nrz quoted-string)r7rUr)rrrrrSs zLocalPart.valuecCstg}t}d}x|dtgD]}|jdkr.q|r^|jdkr^|djdkr^t|dd|d<t|t}|r|jdkr|djdkr|jt|ddn |j||d }|}qWt|dd }|jS) NFrrJdotrjrlrlrlrlrl)DOTr7r isinstancerSr)rrTZlastZ last_is_tltokZis_tlrrrrmZs$   zLocalPart.local_partN)r$r9r:r7r)r=rrmrrrrrNs rcs4eZdZdZdZefddZeddZZS) DomainLiteralzdomain-literalFcsdjtjjS)Nr)r!rrrw)r)rrrrnwszDomainLiteral.domaincCs"x|D]}|jdkr|jSqWdS)Nptext)r7r)rrrrrip{s  zDomainLiteral.ip) r$r9r:r7r)r=rnrr>rr)rrrrsrc@seZdZdZdZdZdS) MIMEVersionz mime-versionN)r$r9r:r7majorminorrrrrrsrc@s4eZdZdZdZdZdZeddZeddZ dS) Parameter parameterFzus-asciicCs|jr|djSdS)Nrjr) sectionednumber)rrrrsection_numberszParameter.section_numbercCsbx\|D]T}|jdkr|jS|jdkrx4|D],}|jdkr*x|D]}|jdkr>|jSq>Wq*WqWdS)Nrz quoted-stringzbare-quoted-stringr)r7rV)rr.rrr param_values       zParameter.param_valueN) r$r9r:r7rextendedrPr=rrrrrrrs  rc@seZdZdZdS)InvalidParameterzinvalid-parameterN)r$r9r:r7rrrrrsrc@seZdZdZeddZdS) Attribute attributecCs$x|D]}|jjdr|jSqWdS)Nattrtext)r7endswithr)rr.rrrrVs  zAttribute.stripped_valueN)r$r9r:r7r=rVrrrrrsrc@seZdZdZdZdS)SectionsectionN)r$r9r:r7rrrrrrsrc@seZdZdZeddZdS)ValuercCs2|d}|jdkr|d}|jjdr,|jS|jS)NrrJrj quoted-stringrextended-attribute)rrr)r7rrVr)rr.rrrrVs zValue.stripped_valueN)r$r9r:r7r=rVrrrrrsrc@s(eZdZdZdZeddZddZdS)MimeParameterszmime-parametersFc cst}x\|D]T}|jjdsq |djdkr.q |djj}||krLg||<||j|j|fq Wx|jD]\}}t|t dd}|dd}|j }|j rt |dkr|dddkr|ddj jtjd|dd}g}d}x|D]\} } | |kr6| j s$| j jtjdqn| j jtjd|d7}| j} | j rytjj| } Wn&tk rtjj| d d } YnRXy| j|d } Wn"tk r| jd d } YnXtj| r| j jtj|j| qWd j|} || fVqpWdS)Nrrr)keyrjz.duplicate parameter name; duplicate(s) ignoredz+duplicate parameter name; duplicate ignoredz(inconsistent RFC2231 parameter numberingzlatin-1)encodingsurrogateescapezus-asciir)rr7rrstriprSritemssortedrrPrrkrrInvalidHeaderDefectrurllibparseZunquote_to_bytesUnicodeEncodeErrorZunquotedecode LookupErrorr_has_surrogatesUndecodableBytesDefectr!) rparamsr.namepartsZ first_paramrPZ value_partsirparamrrrrrsZ         zMimeParameters.paramscCsXg}x8|jD].\}}|r0|jdj|t|q |j|q Wdj|}|rTd|SdS)Nz{}={}z; r@r)rrSr#rr!)rrrrrrrr"s zMimeParameters.__str__N)r$r9r:r7r;r=rr"rrrrrs Frc@seZdZdZeddZdS)ParameterizedHeaderValueFcCs&x t|D]}|jdkr |jSq WiS)Nzmime-parameters)reversedr7r)rr.rrrr%s  zParameterizedHeaderValue.paramsN)r$r9r:r;r=rrrrrrsrc@seZdZdZdZdZdZdS) ContentTypez content-typeFtextZplainN)r$r9r:r7r)maintypesubtyperrrrr-src@seZdZdZdZdZdS)ContentDispositionzcontent-dispositionFN)r$r9r:r7r)content_dispositionrrrrr5src@seZdZdZdZdZdS)ContentTransferEncodingzcontent-transfer-encodingFZ7bitN)r$r9r:r7r)rOrrrrr<src@seZdZdZdZdS) HeaderLabelz header-labelFN)r$r9r:r7r)rrrrrCsrc@seZdZdZdS)HeaderheaderN)r$r9r:r7rrrrrIsrcsreZdZdZdZdZfddZfddZddZe dd Z dfd d Z d dZ e ddZ ddZZS)TerminalTcstj||}||_g|_|S)N)r__new__r7r)clsrr7r)rrrrXszTerminal.__new__csdj|jjtjS)Nz{}({}))r#rr$rr%)r)rrrr%^szTerminal.__repr__cCst|jjd|jdS)N/)r3rr$r7)rrrrr5aszTerminal.pprintcCs t|jS)N)listr)rrrrr&dszTerminal.all_defectsrcs2dj||jj|jtj|js"dn dj|jgS)Nz {}{}/{}({}){}rz {})r#rr$r7rr%r)rr2)rrrr6hs z Terminal._ppcCsdS)Nr)rrrrpop_trailing_wsqszTerminal.pop_trailing_wscCsgS)Nr)rrrrr-uszTerminal.commentscCst||jfS)N)rr7)rrrr__getnewargs__yszTerminal.__getnewargs__)r)r$r9r:r)r<r;rr%r5r=r&r6rr-rr>rr)rrrRs     rc@s eZdZeddZddZdS)WhiteSpaceTerminalcCsdS)Nr@r)rrrrrszWhiteSpaceTerminal.valuecCsdS)NTr)rrrrr(sz!WhiteSpaceTerminal.startswith_fwsN)r$r9r:r=rr(rrrrr}s rc@s eZdZeddZddZdS) ValueTerminalcCs|S)Nr)rrrrrszValueTerminal.valuecCsdS)NFr)rrrrr(szValueTerminal.startswith_fwsN)r$r9r:r=rr(rrrrrs rc@s eZdZeddZddZdS)EWWhiteSpaceTerminalcCsdS)Nrr)rrrrrszEWWhiteSpaceTerminal.valuecCsdS)Nrr)rrrrr"szEWWhiteSpaceTerminal.__str__N)r$r9r:r=rr"rrrrrs rr,zlist-separatorr~zroute-component-markerz([{}]+)rz[^{}]+rz\\]z\]z[\x00-\x20\x7F]cCs>t|}|r|jjtj|tj|r:|jjtjddS)z@If input token contains ASCII non-printables, register a defect.z*Non-ASCII characters found in header tokenN)_non_printable_finderrrSrZNonPrintableDefectrrr)xtextZnon_printablesrrr_validate_xtexts   rcCst|d^}}g}d}d}xbtt|D]J}||dkrL|rFd}d}nd}q(|rVd}n|||krdP|j||q(W|d}dj|dj||dg||fS)akScan printables/quoted-pairs until endchars and return unquoted ptext. This function turns a run of qcontent, ccontent-without-comments, or dtext-with-quoted-printables into a single string by unquoting any quoted printables. It returns the string, the remaining value, and a flag that is True iff there were any quoted printables decoded. rjFrTrN) _wsp_splitterrangerkrSr!)rendcharsZfragment remainderZvcharsescapehad_qpposrrr_get_ptext_to_endcharss$   rcCs.|j}t|dt|t|d}||fS)zFWS = 1*WSP This isn't the RFC definition. We're using fws to represent tokens where folding can be done, but when we are parsing the *un*folding has already been done so we don't need to watch out for CRLF. Nfws)r}rrk)rZnewvaluerrrrget_fwssrc Cst}|jds tjdj||ddjdd^}}||ddkrXtjdj|dj|}t|dkr|dtkr|dtkr|jdd^}}|d|}t|jdkr|j j tj d ||_ dj|}yt jd|d\}}}} Wn(tk rtjd j|j YnX||_||_|j j| xh|r|dtkrdt|\} }|j | q6t|d^} }t| d } t| |j | dj|}q6W||fS) zE encoded-word = "=?" charset "?" encoding "?" encoded-text "?=" z=?z"expected encoded word but found {}rhNz?=rjrrzwhitespace inside encoded wordz!encoded word format invalid: '{}'vtext)rN startswithrHeaderParseErrorr#rwr!rkrrrSrrO_ewr ValueErrorrPrQr,WSPrrrr) rewrrZremstrrestrrPrQrr.charsrrrrget_encoded_wordsH    $        rc Cst}x|r |dtkr4t|\}}|j|q |jdryt|\}}Wntjk rdYnrXd}t|dkr|d j dkr|j jtj dd}|rt|dkr|d j d krt |dd|d<|j|q t |d^}}t|d }t||j|d j|}q W|S)aOunstructured = (*([FWS] vchar) *WSP) / obs-unstruct obs-unstruct = *((*LF *CR *(obs-utext) *LF *CR)) / FWS) obs-utext = %d0 / obs-NO-WS-CTL / LF / CR obs-NO-WS-CTL is control characters except WSP/CR/LF. So, basically, we have printable runs, plus control characters or nulls in the obsolete syntax, separated by whitespace. Since RFC 2047 uses the obsolete syntax in its specification, but requires whitespace on either side of the encoded words, I can see no reason to need to separate the non-printable-non-whitespace from the printable runs if they occur, so we parse this into xtext tokens separated by WSP tokens. Because an 'unstructured' value must by definition constitute the entire value, this 'get' routine does not return a remaining value, only the parsed TokenList. rz=?Trjrz&missing whitespace before encoded wordFrhz encoded-wordrrrlrlrl)rDrrrSrrrrrkr7rrrrrrr!)rrEr.Zhave_wsrrrrrrget_unstructured!s:          rcCs*t|d\}}}t|d}t|||fS)actext = This is not the RFC ctext, since we are handling nested comments in comment and unquoting quoted-pairs here. We allow anything except the '()' characters, but if we find any ASCII other than the RFC defined printable ASCII, a NonPrintableDefect is added to the token's defects list. Since quoted pairs are converted to their unquoted values, what is returned is a 'ptext' token. In this case it is a WhiteSpaceTerminal, so it's value is ' '. z()r)rrr)rr_rrr get_qp_ctextYs  rcCs*t|d\}}}t|d}t|||fS)aoqcontent = qtext / quoted-pair We allow anything except the DQUOTE character, but if we find any ASCII other than the RFC defined printable ASCII, a NonPrintableDefect is added to the token's defects list. Any quoted pairs are converted to their unquoted values, so what is returned is a 'ptext' token. In this case it is a ValueTerminal. r r)rrr)rrrrrr get_qcontentjs  rcCsNt|}|stjdj||j}|t|d}t|d}t|||fS)zatext = We allow any non-ATOM_ENDS in atext, but add an InvalidATextDefect to the token's defects list if we find non-atext characters. zexpected atext but found '{}'Natext)_non_atom_end_matcherrrr#rarkrr)rmrrrr get_atextys  rc Cs|ddkrtjdj|t}|dd}|ddkrPt|\}}|j|x|r|ddkr|dtkr|t|\}}nd|dddkry"t|\}}|j jtj dWqtjk rt|\}}YqXn t|\}}|j|qRW|s|j jtj d ||fS||ddfS) zbare-quoted-string = DQUOTE *([FWS] qcontent) [FWS] DQUOTE A quoted-string without the leading or trailing white space. Its value is the text between the quote marks, with whitespace preserved and quoted pairs decoded. rr zexpected '"' but found '{}'rjNrhz=?z!encoded word inside quoted stringz"end of header inside quoted string) rrr#rWrrSrrrrr)rZbare_quoted_stringr.rrrget_bare_quoted_strings2            rcCs|r |ddkr tjdj|t}|dd}x^|r|ddkr|dtkr^t|\}}n&|ddkrxt|\}}n t|\}}|j|q4W|s|j jtj d||fS||ddfS)zcomment = "(" *([FWS] ccontent) [FWS] ")" ccontent = ctext / quoted-pair / comment We handle nested comments here, and quoted-pair in our qp-ctext routine. rrzexpected '(' but found '{}'rjNrZzend of header inside comment) rrr#rXrr get_commentrrSrr)rrAr.rrrrs"      rcCsTt}xD|rJ|dtkrJ|dtkr2t|\}}n t|\}}|j|qW||fS)z,CFWS = (1*([FWS] comment) [FWS]) / FWS r)rI CFWS_LEADERrrrrS)rrJr.rrrget_cfwss  rcCspt}|r,|dtkr,t|\}}|j|t|\}}|j||rh|dtkrht|\}}|j|||fS)zquoted-string = [CFWS] [CFWS] 'bare-quoted-string' is an intermediate class defined by this parser and not by the RFC grammar. It is the quoted string without any attached CFWS. r)rRrrrSr)rZ quoted_stringr.rrrget_quoted_strings      rc Cst}|r,|dtkr,t|\}}|j||rL|dtkrLtjdj||jdryt |\}}Wqtjk rt |\}}YqXn t |\}}|j||r|dtkrt|\}}|j|||fS)zPatom = [CFWS] 1*atext [CFWS] An atom could be an rfc2047 encoded word. rzexpected atom but found '{}'z=?) rKrrrS ATOM_ENDSrrr#rrr)rrLr.rrrget_atoms$        rcCst}| s|dtkr(tjdj|xP|rx|dtkrxt|\}}|j||r*|ddkr*|jt|dd}q*W|dtkrtjdjd|||fS)z( dot-text = 1*atext *("." 1*atext) rz8expected atom at a start of dot-atom-text but found '{}'r rjNz4expected atom at end of dot-atom-text but found '{}'rl)ryrrrr#rrSr)rZ dot_atom_textr.rrrget_dot_atom_texts     rc Cst}|dtkr(t|\}}|j||jdrhyt|\}}Wqttjk rdt|\}}YqtXn t|\}}|j||r|dtkrt|\}}|j|||fS)z dot-atom = [CFWS] dot-atom-text [CFWS] Any place we can have a dot atom, we could instead have an rfc2047 encoded word. rz=?) rxrrrSrrrrr)rZdot_atomr.rrr get_dot_atoms        rcCs|dtkrt|\}}nd}|ddkr8t|\}}n*|dtkrVtjdj|n t|\}}|dk rx|g|dd<||fS)aword = atom / quoted-string Either atom or quoted-string may start with CFWS. We have to peel off this CFWS first to determine which type of word to parse. Afterward we splice the leading CFWS, if any, into the parsed sub-token. If neither an atom or a quoted-string is found before the next special, a HeaderParseError is raised. The token returned is either an Atom or a QuotedString, as appropriate. This means the 'word' level of the formal grammar is not represented in the parse tree; this is because having that extra layer when manipulating the parse tree is more confusing than it is helpful. rNr z1Expected 'atom' or 'quoted-string' but found '{}')rrrSPECIALSrrr#r)rleaderr.rrrget_word*s     rcCst}yt|\}}|j|Wn(tjk rH|jjtjdYnXx|r|dtkr|ddkr|jt|jjtj d|dd}qLyt|\}}WnDtjk r|dt krt |\}}|jjtj dnYnX|j|qLW||fS)a phrase = 1*word / obs-phrase obs-phrase = word *(word / "." / CFWS) This means a phrase can be a sequence of words, periods, and CFWS in any order as long as it starts with at least one word. If anything other than words is detected, an ObsoleteHeaderDefect is added to the token's defect list. We also accept a phrase that starts with CFWS followed by a dot; this is registered as an InvalidHeaderDefect, since it is not supported by even the obsolete grammar. zphrase does not start with wordrr zperiod in 'phrase'rjNzcomment found without atom) rFrrSrrrr PHRASE_ENDSrObsoleteHeaderDefectrr)rrGr.rrr get_phraseIs.          rcCstt}d}|dtkr"t|\}}|s6tjdj|yt|\}}Wn^tjk ryt|\}}Wn6tjk r|ddkr|dtkrt }YnXYnX|dk r|g|dd<|j ||o|ddks|dtkr2t t ||\}}|j dkr|jj tjdn|jj tjd||d<y|jjdWn(tk rj|jj tjd YnX||fS) z= local-part = dot-atom / quoted-string / obs-local-part Nrz"expected local-part but found '{}'rzinvalid-obs-local-partz / obs-dtext obs-dtext = obs-NO-WS-CTL / quoted-pair We allow anything except the excluded characters, but if we find any ASCII other than the RFC defined printable ASCII, a NonPrintableDefect is added to the token's defects list. Quoted pairs are converted to their unquoted values, so what is returned is a ptext token, in this case a ValueTerminal. If there were quoted-printables, an ObsoleteHeaderDefect is added to the returned token's defect list. z[]rz(quoted printable found in domain-literal)rrrrSrrr)rrrrrr get_dtexts   rcCs,|rdS|jtjd|jtdddS)NFz"end of input inside domain-literalrzdomain-literal-endT)rSrrr)rdomain_literalrrr_check_for_early_dl_ends rcCslt}|dtkr(t|\}}|j||s6tjd|ddkrRtjdj||dd}t||rp||fS|jtdd|dt krt |\}}|j|t |\}}|j|t||r||fS|dt krt |\}}|j|t||r||fS|ddkrtjd j||jtdd |dd}|rd|dtkrdt|\}}|j|||fS) zB domain-literal = [CFWS] "[" *([FWS] dtext) [FWS] "]" [CFWS] rzexpected domain-literal[z6expected '[' at start of domain-literal but found '{}'rjNzdomain-literal-startrz4expected ']' at end of domain-literal but found '{}'zdomain-literal-end) rrrrSrrr#rrrrr)rrr.rrrget_domain_literalsD                    rc Cstt}d}|dtkr"t|\}}|s6tjdj||ddkrvt|\}}|dk rd|g|dd<|j|||fSyt|\}}Wn"tjk rt |\}}YnX|r|ddkrtjd|dk r|g|dd<|j||o|ddkrl|j jtj d|dj d kr(|d|dd<xB|rj|ddkrj|jt t |d d\}}|j|q*W||fS) z] domain = dot-atom / domain-literal / obs-domain obs-domain = atom *("." atom)) Nrzexpected domain but found '{}'rr~zInvalid Domainr z(domain is not a dot-atom (contains CFWS)zdot-atomrj)rvrrrrr#rrSrrrrr7r)rrnrr.rrr get_domains@          rcCs~t}t|\}}|j|| s.|ddkrH|jjtjd||fS|jtddt|dd\}}|j|||fS)z( addr-spec = local-part "@" domain rr~z"add-spec local part with no domainzaddress-at-symbolrjN)rzrrSrrrrr)rrpr.rrr get_addr_spec.s    rcCst}xf|rl|ddks$|dtkrl|dtkrHt|\}}|j|q|ddkr|jt|dd}qW| s|ddkrtjdj||jtt |dd\}}|j|x|o|ddkrB|jt|dd}|sP|dtkr t|\}}|j||ddkr|jtt |dd\}}|j|qW|sTtjd|ddkrrtjd j||jt dd ||ddfS) z obs-route = obs-domain-list ":" obs-domain-list = *(CFWS / ",") "@" domain *("," [CFWS] ["@" domain]) Returns an obs-route token with the appropriate sub-tokens (that is, there is no obs-domain-list in the parse tree). rrrjNr~z(expected obs-route domain but found '{}'z%end of header while parsing obs-route:z4expected ':' marking end of obs-route but found '{}'zend-of-obs-route-marker) rsrrrS ListSeparatorrrr#RouteComponentMarkerrr)rZ obs_router.rrr get_obs_route>sB               r cCst}|dtkr(t|\}}|j|| s:|ddkrJtjdj||jtdd|dd}|ddkr|jtdd|jjtj d |dd}||fSyt |\}}Wnztjk r2y"t |\}}|jjtj d Wn(tjk rtjd j|YnX|j|t |\}}YnX|j||r`|ddkr`|dd}n|jjtj d |jtdd|r|dtkrt|\}}|j|||fS) z angle-addr = [CFWS] "<" addr-spec ">" [CFWS] / obs-angle-addr obs-angle-addr = [CFWS] "<" obs-route addr-spec ">" [CFWS] rzangle-addr-endznull addr-spec in angle-addrz*obsolete route specification in angle-addrz.expected addr-spec or obs-route but found '{}'z"missing trailing '>' on angle-addr) rqrrrSrrr#rrrrr r)rZ angle_addrr.rrrget_angle_addrgsJ                r cCs<t}t|\}}|j|dd|jdd|_||fS)z display-name = phrase Because this is simply a name-rule, we don't return a display-name token containing a phrase, but rather a display-name token with the content of the phrase. N)rrr,r)rrbr.rrrget_display_names  rcCst}d}|dtkr6t|\}}|s6tjdj||ddkr|dtkr^tjdj|t|\}}|s~tjdj||dk r|g|ddd<d}|j|t |\}}|dk r|g|dd<|j|||fS)z, name-addr = [display-name] angle-addr Nrz!expected name-addr but found '{}'r ) rirrrrr#rrrSr )rZ name_addrrr.rrr get_name_addrs0           rcCst}yt|\}}WnNtjk rdyt|\}}Wn&tjk r^tjdj|YnXYnXtdd|jDrd|_|j |||fS)z& mailbox = name-addr / addr-spec zexpected mailbox but found '{}'css|]}t|tjVqdS)N)rrr)rrrrrr szget_mailbox..zinvalid-mailbox) rtrrrrr#anyr&r7rS)rrcr.rrr get_mailboxs  rcCsht}xX|r^|d|kr^|dtkrF|jt|dd|dd}qt|\}}|j|qW||fS)z Read everything up to one of the chars in endchars. This is outside the formal grammar. The InvalidMailbox TokenList that is returned acts like a Mailbox, but the data attributes are None. rzmisplaced-specialrjN)rurrSrr)rrZinvalid_mailboxr.rrrget_invalid_mailboxs   rc Cst}x|o|ddkryt|\}}|j|Wntjk r@d}|dtkrt|\}}| sz|ddkr|j||jjtjdn@t |d\}}|dk r|g|dd<|j||jjtj dnb|ddkr|jjtjdnBt |d\}}|dk r |g|dd<|j||jjtj dYnX|r|ddkr|d }d |_ t |d\}}|j ||jjtj d|r |ddkr |jt |dd}q W||fS) aJ mailbox-list = (mailbox *("," mailbox)) / obs-mbox-list obs-mbox-list = *([CFWS] ",") mailbox *("," [mailbox / CFWS]) For this routine we go outside the formal grammar in order to improve error handling. We recognize the end of the mailbox list only at the end of the value or at a ';' (the group terminator). This is so that we can turn invalid mailboxes into InvalidMailbox tokens and continue parsing any remaining valid mailboxes. We also allow all mailbox entries to be null, and this condition is handled appropriately at a higher level. r;Nz,;zempty element in mailbox-listzinvalid mailbox in mailbox-listrrjzinvalid-mailboxrl)rdrrSrrrrrrrrr7r,r)rZ mailbox_listr.rrcrrrget_mailbox_listsN                   rcCst}|s$|jjtjd||fSd}|r|dtkrt|\}}|sl|jjtjd|j|||fS|ddkr|j|||fSt|\}}t|j dkr|dk r|j||j ||jjtj d||fS|dk r|g|dd<|j|||fS)zg group-list = mailbox-list / CFWS / obs-group-list obs-group-list = 1*([CFWS] ",") [CFWS] zend of header before group-listNrzend of header in group-listrzgroup-list with empty entries) rfrrSrrrrrrkr_r,r)rZ group_listrr.rrrget_group_list"s8           rcCs"t}t|\}}| s$|ddkr4tjdj||j||jtdd|dd}|r|ddkr|jtdd||ddfSt|\}}|j||s|jjtj d n|ddkrtjd j||jtdd|dd}|r|dt krt |\}}|j|||fS) z7 group = display-name ":" [group-list] ";" [CFWS] rrz8expected ':' at end of group display name but found '{}'zgroup-display-name-terminatorrjNrzgroup-terminatorzend of header in groupz)expected ';' at end of group but found {}) rgrrrr#rSrrrrrr)rrar.rrr get_groupGs2            rcCsxt}yt|\}}WnNtjk rdyt|\}}Wn&tjk r^tjdj|YnXYnX|j|||fS)a address = mailbox / group Note that counter-intuitively, an address can be either a single address or a list of addresses (a group). This is why the returned Address object has a 'mailboxes' attribute which treats a single address as a list of length one. When you need to differentiate between to two cases, extract the single element, which is either a mailbox or a group token. zexpected address but found '{}')r`rrrrr#rS)rr\r.rrr get_addresses rcCst}x|ryt|\}}|j|Wn$tjk rP}zd}|dtkrt|\}}| sr|ddkr|j||jjtjdnFt |d\}}|dk r|g|dd<|jt |g|jjtj dnh|ddkr|jjtjdnHt |d\}}|dk r|g|dd<|jt |g|jjtj dWYdd}~XnX|r|ddkr|d d}d|_ t |d\}}|j ||jjtj d|r |jtdd |dd}q W||fS) a address_list = (address *("," address)) / obs-addr-list obs-addr-list = *([CFWS] ",") address *("," [address / CFWS]) We depart from the formal grammar here by continuing to parse until the end of the input, assuming the input to be entirely composed of an address-list. This is always true in email parsing, and allows us to skip invalid addresses to parse additional valid ones. Nrrz"address-list entry with no contentzinvalid address in address-listzempty element in address-listrjzinvalid-mailboxzlist-separatorrl)r[rrSrrrrrrrr`rr7r,r)rZ address_listr.errrrcrrrget_address_listsN                  rcCst}|s |jjtjd|S|dtkrXt|\}}|j||sX|jjtjdd}x8|r|ddkr|dtkr||d7}|dd}q^W|js|jjtjdj ||jt |d nt ||_ |jt |d |o|dtkr t|\}}|j|| s |ddkrX|j dk r>|jjtjd |rT|jt |d |S|jt dd |dd}|r|dtkrt|\}}|j||s|j dk r|jjtjd |Sd}x2|r|dtkr||d7}|dd}qW|js2|jjtjd j ||jt |d nt ||_ |jt |d |rv|dtkrvt|\}}|j||r|jjtjd|jt |d |S)zE mime-version = [CFWS] 1*digit [CFWS] "." [CFWS] 1*digit [CFWS] z%Missing MIME version number (eg: 1.0)rz0Expected MIME version number but found only CFWSrr rjNz1Expected MIME major version number but found {!r}rdigitsz0Incomplete MIME version; found only major numberzversion-separatorz1Expected MIME minor version number but found {!r}z'Excess non-CFWS text after MIME version)rrrSrHeaderMissingRequiredValuerrisdigitrr#rintrr)rZ mime_versionr.rrrrparse_mime_versionsv                        rcCsht}xX|r^|ddkr^|dtkrF|jt|dd|dd}qt|\}}|j|qW||fS)z Read everything up to the next ';'. This is outside the formal grammar. The InvalidParameter TokenList that is returned acts like a Parameter, but the data attributes are None. rrzmisplaced-specialrjN)rrrSrr)rZinvalid_parameterr.rrrget_invalid_parameters   rcCsNt|}|stjdj||j}|t|d}t|d}t|||fS)a8ttext = We allow any non-TOKEN_ENDS in ttext, but add defects to the token's defects list if we find non-ttext characters. We also register defects for *any* non-printables even though the RFC doesn't exclude all of them, because we follow the spirit of RFC 5322. zexpected ttext but found '{}'Nttext)_non_token_end_matcherrrr#rarkrr)rrr rrr get_ttexts   r"cCst}|r,|dtkr,t|\}}|j||rL|dtkrLtjdj|t|\}}|j||r|dtkrt|\}}|j|||fS)ztoken = [CFWS] 1*ttext [CFWS] The RFC equivalent of ttext is any US-ASCII chars except space, ctls, or tspecials. We also exclude tabs even though the RFC doesn't. The RFC implies the CFWS but is not explicit about it in the BNF. rzexpected token but found '{}') rMrrrS TOKEN_ENDSrrr#r")rZmtokenr.rrr get_token)s        r$cCsNt|}|stjdj||j}|t|d}t|d}t|||fS)aQattrtext = 1*(any non-ATTRIBUTE_ENDS character) We allow any non-ATTRIBUTE_ENDS in attrtext, but add defects to the token's defects list if we find non-attrtext characters. We also register defects for *any* non-printables even though the RFC doesn't exclude all of them, because we follow the spirit of RFC 5322. z expected attrtext but found {!r}Nr)_non_attribute_end_matcherrrr#rarkrr)rrrrrr get_attrtext@s   r&cCst}|r,|dtkr,t|\}}|j||rL|dtkrLtjdj|t|\}}|j||r|dtkrt|\}}|j|||fS)aH [CFWS] 1*attrtext [CFWS] This version of the BNF makes the CFWS explicit, and as usual we use a value terminal for the actual run of characters. The RFC equivalent of attrtext is the token characters, with the subtraction of '*', "'", and '%'. We include tab in the excluded set just as we do for token. rzexpected token but found '{}') rrrrSATTRIBUTE_ENDSrrr#r&)rrr.rrr get_attributeSs        r(cCsNt|}|stjdj||j}|t|d}t|d}t|||fS)zattrtext = 1*(any non-ATTRIBUTE_ENDS character plus '%') This is a special parsing routine so that we get a value that includes % escapes as a single string (which we decode as a single string later). z)expected extended attrtext but found {!r}Nzextended-attrtext)#_non_extended_attribute_end_matcherrrr#rarkrr)rrrrrrget_extended_attrtextjs  r*cCst}|r,|dtkr,t|\}}|j||rL|dtkrLtjdj|t|\}}|j||r|dtkrt|\}}|j|||fS)z [CFWS] 1*extended_attrtext [CFWS] This is like the non-extended version except we allow % characters, so that we can pick up an encoded value as a single string. rzexpected token but found '{}') rrrrSEXTENDED_ATTRIBUTE_ENDSrrr#r*)rrr.rrrget_extended_attribute|s       r,cCst}| s|ddkr(tjdj||jtdd|dd}| sX|dj rhtjdj|d}x,|r|djr||d7}|dd}qnW|dd kr|d kr|jjtjd t ||_ |jt|d ||fS) a6 '*' digits The formal BNF is more complicated because leading 0s are not allowed. We check for that and add a defect. We also assume no CFWS is allowed between the '*' and the digits, though the RFC is not crystal clear on that. The caller should already have dealt with leading CFWS. r*zExpected section but found {}zsection-markerrjNz$Expected section number but found {}r0z'section number has an invalid leading 0r) rrrr#rSrrrZInvalidHeaderErrorrr)rrrrrr get_sections&     r/cCst}|stjdd}|dtkr0t|\}}|sDtjdj||ddkr^t|\}}n t|\}}|dk r|g|dd<|j|||fS)z quoted-string / attribute z&Expected value but found end of stringNrz Expected value but found only {}r ) rrrrrr#rr,rS)rvrr.rrr get_values       r1c Csvt}t|\}}|j|| s.|ddkrN|jjtjdj|||fS|ddkry t|\}}d|_|j|Wntj k rYnX|stj d|ddkr|jt dd|dd }d|_ |dd krtj d |jt d d |dd }d }|r.|dt kr.t |\}}|j|d }|}|j rH|rH|dd krHt|\}}|j}d}|jdkr|r|ddkrd}n$t|\}} | r| ddkrd}n(yt|\}} Wn Yn X| sd}|r2|jjtjd|j|x,|D]$} | jdkrg| d d <| }PqW|}nd }|jjtjd|rb|ddkrbd }n t|\}}|j s|jdkr| s|ddkr|j||d k r|}||fS|jjtjd|s|jjtjd|j||d kr||fSn|d k rFx|D]} | jdkrPqW| jdk|j| | j|_|ddkrdtj dj||jt dd|dd }|r|ddkrt|\}}|j||j|_| s|ddkrtj dj||jt dd|dd }|d k rJt} x>|rB|dtkr(t|\}}n t|\}}| j|qW| }n t|\}}|j||d k rn|}||fS)aY attribute [section] ["*"] [CFWS] "=" value The CFWS is implied by the RFC but not made explicit in the BNF. This simplified form of the BNF from the RFC is made to conform with the RFC BNF through some extra checks. We do it this way because it makes both error recovery and working with the resulting parse tree easier. rrz)Parameter contains name ({}) but no valuer-TzIncomplete parameterzextended-parameter-markerrjN=zParameter not followed by '='zparameter-separatorr F'z5Quoted string value for extended parameter is invalidzbare-quoted-stringzZParameter marked as extended but appears to have a quoted string value that is non-encodedzcApparent initial-extended-value but attribute was not marked as extended or was not initial sectionz(Missing required charset/lang delimiterszextended-attrtextrz=Expected RFC2231 char/lang encoding delimiter, but found {!r}zRFC2231-delimiterz;Expected RFC2231 char/lang encoding delimiter, but found {})rr(rSrrrr#r/rrrrrrrrVrr&r*r7r1rrPrQrrrr) rrr.rrZappendtoZqstringZ inner_valueZ semi_validrtr0rrr get_parameters                                             r5cCsht}xZ|rbyt|\}}|j|Wntjk r}zd}|dtkrZt|\}}|sl|j||S|ddkr|dk r|j||jjtjdn@t |\}}|r|g|dd<|j||jjtjdj |WYdd}~XnX|r@|ddkr@|d }d|_ t |\}}|j ||jjtjdj ||r |jt dd |dd}q W|S) a! parameter *( ";" parameter ) That BNF is meant to indicate this routine should only be called after finding and handling the leading ';'. There is no corresponding rule in the formal RFC grammar, but it is more convenient for us for the set of parameters to be treated as its own TokenList. This is 'parse' routine because it consumes the reminaing value, but it would never be called to parse a full header. Instead it is called to parse everything after the non-parameter value of a specific MIME header. Nrrzparameter entry with no contentzinvalid parameter {!r}rjzinvalid-parameterz)parameter with invalid trailing text {!r}zparameter-separatorrl)rr5rSrrrrrrrr#r7r,r)rZmime_parametersr.rrrrrrparse_mime_parametersQ sD                 r6cCsxX|rX|ddkrX|dtkr@|jt|dd|dd}qt|\}}|j|qW|sbdS|jtdd|jt|dddS)zBDo our best to find the parameters in an invalid MIME header rrzmisplaced-specialrjNzparameter-separator)rrSrrr6)Z tokenlistrr.rrr_find_mime_parameters s  r7cCst}d}|s$|jjtjd|Syt|\}}Wn8tjk rl|jjtjdj|t |||SX|j|| s|ddkr|jjtjd|rt |||S|j j j |_ |jtdd|dd }yt|\}}Wn:tjk r$|jjtjd j|t |||SX|j||j j j |_|sJ|S|dd kr|jjtjd j||` |`t |||S|jtd d |jt|dd |S)z maintype "/" subtype *( ";" parameter ) The maintype and substype are tokens. Theoretically they could be checked against the official IANA list + x-token, but we don't do that. Fz"Missing content type specificationz(Expected content maintype but found {!r}rrzInvalid content typezcontent-type-separatorrjNz'Expected content subtype but found {!r}rz.z unknown-8bitTzmime-parameters)r/rrlrlrlrlrlrl)Zmax_line_lengthfloatutf8rrrrr7 SPECIALSNL isdisjointNLSETrrrr&_fold_mime_parametersr)r;r1lineseprkr=rSr8 _fold_as_ewr<r(insertr!)Z parse_treer/maxlenrr<last_ewr>Z want_encodingZend_ew_not_allowedrr*tstrrPZ encoded_partnewlineZnewpartsrrrr0" s                 r0cCs|dk r<|rFold TokenList 'part' into the 'lines' list as mime parameters. Using the decoded list of parameters and values, format them according to the RFC rules, including using RFC2231 encoding if the value cannot be expressed in 'encoding' and/or the parameter+value is too long to fit within 'maxlen'. rjrstrictFTz unknown-8bitrzutf-8r)Zsaferz {}*={}''{}z{}={}r@rhrz''r{NNz {}*{}*={}{}rlrlrlrlrlrl)rr|rrrrrrrrYr#rrkrSr)r*r<rHrrrrPZ error_handlerZencoding_requiredZ encoded_valuerJrZ extra_chromeZ chrome_lenZ splitpointZmaxcharspartialrrrrD s\        rD)__doc__rerstringr collectionsroperatorrZemailrrrrrrrrrrrZ TSPECIALSr#Z ASPECIALSr'r+rCrArrrr?rDrFrHrIrKrMrNrRrWrXr[r`rdrfrgrirqrsrtrurvrxryrzrrrrrrrrrrrrrrrrrrrrrrrrr compiler#r!rwrrmatchrfindallrr!r%r)rrrrrrrrrrrrrrrrrrrrrrrrr r rrrrrrrrrrrr"r$r&r(r*r,r/r1r5r6r7r9r:r;r=r0rFrDrrrrDs           C  "   !($ V +            *8" &'/'&).9%>D 49/j7_parseaddr.cpython-36.opt-2.pyc000064400000022503147204636050012247 0ustar003 fD@sddddgZddlZddlZdZdZdZd d d d d dddddddddddd dddddddgZd d!d"d#d$d%d&gZddddd8d9d:d;dd?d@dAd-Zd.dZ d/d0Z d1dZ d2dZ d3dZ Gd4d5d5ZGd6d7d7eZdS)B mktime_tz parsedate parsedate_tzquoteN z, ZjanZfebZmarZaprZmayZjunZjulZaugsepoctZnovZdecZjanuaryZfebruaryZmarchZaprilZjuneZjulyZaugustZ septemberZoctoberZnovemberZdecemberZmonZtueZwedZthuZfriZsatZsunii,iiXii )ZUTZUTCZGMTZZASTZADTZESTZEDTZCSTZCDTZMSTZMDTZPSTZPDTcCs,t|}|sdS|ddkr$d|d<t|S)N r) _parsedate_tztuple)dataresr(/usr/lib64/python3.6/email/_parseaddr.pyr-s  cCs|sdS|j}|djds.|djtkr6|d=n.|djd}|dkrd|d|dd|d<t|dkr|djd}t|dkr||dd}t|dkr|d}|jd}|dkr|jd}|dkr|d|||dg|dd<n |jdt|d krdS|dd }|\}}}}}|j}|tkrZ||j}}|tkrZdStj |d}|d krz|d 8}|ddkr|dd}|jd }|dkr||}}|ddkr|dd}|dj s||}}|ddkr|dd}|jd }t|d kr$|\} } d } n~t|dkr>|\} } } ndt|dkrd|dkr|djd}t|d kr|\} } d} nt|dkr|\} } } ndSy,t |}t |}t | } t | } t | } Wnt k rdSX|dkr |dkr|d7}n|d7}d} |j }|tkr,t|} n>y t |} Wnt k rNYnX| dkrj|jdrjd} | r| dkrd} | } nd} | | dd| dd} |||| | | ddd| g S)Nr,-+r :0.dDilii<r!r!r!r!r!r!r!r!)splitendswithlower _daynamesrfindlenfindappend _monthnamesindexisdigitint ValueErrorupper _timezones startswith)riZstuffsZddZmmZyyZtmZtzZthhZtmmZtssZtzoffsetZtzsignrrrr 9s     "                       r cCs&t|}t|tr|ddS|SdS)Nr )r isinstancer )rtrrrrs  cCs<|ddkr"tj|dddStj|}||dSdS)Nr rr!)r!)timeZmktimecalendarZtimegm)rr5rrrrs  cCs|jddjddS)N\z\\"z\")replace)strrrrrsc@sxeZdZddZddZddZddZd d Zd d Zd dZ dddZ ddZ ddZ ddZ dddZddZdS) AddrlistClasscCsZd|_d|_d|_d|_|j|j|_|j|j|j|_|jjdd|_||_g|_ dS)Nz ()<>@,:;."[]rz z rr) specialsposLWSZCRFWSatomendsr; phraseendsfield commentlist)selfrDrrr__init__szAddrlistClass.__init__cCsg}x|jt|jkr|j|j|jdkr^|j|jdkrN|j|j|j|jd7_q|j|jdkr|jj|jqPqWtj|S)Nz r() r?r'rDr@r)rE getcomment EMPTYSTRINGjoin)rFZwslistrrrgotonextszAddrlistClass.gotonextcCs>g}x4|jt|jkr8|j}|r,||7}q|jdqW|S)Nr)rr)r?r'rD getaddressr))rFresultZadrrr getaddrlists zAddrlistClass.getaddrlistcCsg|_|j|j}|j}|j}|jg}|jt|jkr\|rXtj|j|dfg}n\|j|jdkr||_||_|j}tj|j|fg}n"|j|jdkrg}t|j}|jd7_x|jt|jkr|j|j|ko|j|jdkr |jd7_P||j }qWn|j|jdkrx|j }|jrftj|ddj|jd |fg}ntj||fg}n@|rtj|j|dfg}n"|j|j|j kr|jd7_|j|jt|jkr|j|jd kr|jd7_|S) Nrz.@rr;)rFZoldposZoldclplistZ returnlistZaddrspecZfieldlenZ routeaddrrrrrMsL &$zAddrlistClass.getaddresscCs|j|jdkrdSd}|jd7_|jd}x|jt|jkr|rV|jd}n~|j|jdkrx|jd7_Pn\|j|jdkr|jd7_d}n8|j|jdkr|jd7_n|j}|jd7_P|jq4W|S) NrQFrr>@Tr)rDr?rLr' getdomainrU)rFZ expectrouteZadlistrrrrV?s. zAddrlistClass.getrouteaddrcCs\g}|jx|jt|jkrd}|j|jdkrj|rL|dj rL|j|jd|jd7_d}nf|j|jdkr|jdt|jn>|j|j|j kr|r|d j r|jPn|j|j |j}|r|r|j|qW|jt|jks|j|jdkrt j |S|jd|jd7_|j|j }|sNt St j ||S) NTrrFr:z"%s"rYr!r!)rLr?r'rDstrippopr)rgetquoterBgetatomrJrKrZ)rFZaslistZ preserve_wsZwsZdomainrrrrU_s: $  zAddrlistClass.getaddrspeccCsg}x|jt|jkr|j|j|jkr8|jd7_q|j|jdkrZ|jj|jq|j|jdkrz|j|jq|j|jdkr|jd7_|jdq|j|jdkrtS|j|j|j krPq|j|j qWtj |S)NrrH[rrY) r?r'rDr@rEr)rIgetdomainliteralrJrBr^rK)rFZsdlistrrrrZs" zAddrlistClass.getdomainTcCs|j|j|krdSdg}d}|jd7_x|jt|jkr|rZ|j|j|jd}np|j|j|kr||jd7_PnN|r|j|jdkr|j|jq.n(|j|jdkrd}n|j|j|j|jd7_q.Wtj|S)NrFrrHr9T)rDr?r'r)rIrJrK)rFZ begincharZendcharsZ allowcommentsZslistrrrr getdelimiteds( zAddrlistClass.getdelimitedcCs|jdddS)Nr:z" F)ra)rFrrrr]szAddrlistClass.getquotecCs|jdddS)NrHz) T)ra)rFrrrrIszAddrlistClass.getcommentcCsd|jdddS)Nz[%s]r_z] F)ra)rFrrrr`szAddrlistClass.getdomainliteralNcCshdg}|dkr|j}xH|jt|jkr\|j|j|kr:Pn|j|j|j|jd7_qWtj|S)Nrr)rBr?r'rDr)rJrK)rFrBZatomlistrrrr^szAddrlistClass.getatomcCsg}x|jt|jkr|j|j|jkr8|jd7_q|j|jdkrX|j|jq|j|jdkrz|jj|jq|j|j|jkrPq|j|j |jqW|S)Nrr:rH) r?r'rDrAr)r]rErIrCr^)rFrWrrrrSszAddrlistClass.getphraselist)T)N)__name__ __module__ __qualname__rGrLrOrMrVrUrZrar]rIr`r^rSrrrrr=s ; & % r=c@sDeZdZddZddZddZddZd d Zd d Zd dZ dS) AddressListcCs&tj|||r|j|_ng|_dS)N)r=rGrO addresslist)rFrDrrrrGs  zAddressList.__init__cCs t|jS)N)r'rf)rFrrr__len__szAddressList.__len__cCsBtd}|jdd|_x$|jD]}||jkr |jj|q W|S)N)rerfr))rFothernewaddrxrrr__add__s   zAddressList.__add__cCs*x$|jD]}||jkr|jj|qW|S)N)rfr))rFrhrjrrr__iadd__ s  zAddressList.__iadd__cCs2td}x$|jD]}||jkr|jj|qW|S)N)rerfr))rFrhrirjrrr__sub__s   zAddressList.__sub__cCs*x$|jD]}||jkr|jj|qW|S)N)rfremove)rFrhrjrrr__isub__s  zAddressList.__isub__cCs |j|S)N)rf)rFr+rrr __getitem__#szAddressList.__getitem__N) rbrcrdrGrgrkrlrmrorprrrrres reipii ipii iDiiiD)__all__r7r8rTrJZ COMMASPACEr*r%r0rr rrrr=rerrrr s6   u   /_policybase.cpython-36.opt-1.pyc000064400000035670147204636050012444 0ustar003 f<@sdZddlZddlmZddlmZddlmZdddgZGd d d Z d d Z d dZ Gddde ej dZ e Gddde ZeZdS)zwPolicy framework for the email package. Allows fine grained feature control of how the package parses and emits data. N)header)charset)_has_surrogatesPolicyCompat32compat32cs@eZdZdZfddZddZddZdd Zd d ZZ S) _PolicyBaseaPolicy Object basic framework. This class is useless unless subclassed. A subclass should define class attributes with defaults for any values that are to be managed by the Policy object. The constructor will then allow non-default values to be set for these attributes at instance creation time. The instance will be callable, taking these same attributes keyword arguments, and returning a new instance identical to the called instance except for those values changed by the keyword arguments. Instances may be added, yielding new instances with any non-default values from the right hand operand overriding those in the left hand operand. That is, A + B == A() The repr of an instance can be used to reconstruct the object if and only if the repr of the values can be used to reconstruct those values. c sLxF|jD]:\}}t||r0tt|j||q tdj||jjq WdS)zCreate new Policy, possibly overriding some defaults. See class docstring for a list of overridable attributes. z*{!r} is an invalid keyword argument for {}N) itemshasattrsuperr __setattr__ TypeErrorformat __class____name__)selfkwnamevalue)r)/usr/lib64/python3.6/email/_policybase.py__init__)s  z_PolicyBase.__init__cCs*dd|jjD}dj|jjdj|S)NcSsg|]\}}dj||qS)z{}={!r})r).0rrrrr 8sz(_PolicyBase.__repr__..z{}({})z, )__dict__r rrrjoin)rargsrrr__repr__7sz_PolicyBase.__repr__cKsz|jj|j}x$|jjD]\}}tj|||qWx@|jD]4\}}t||sdtdj||jj tj|||q>W|S)zReturn a new instance with specified attributes changed. The new instance has the same attribute values as the current object, except for the changes passed in as keyword arguments. z*{!r} is an invalid keyword argument for {}) r__new__rr objectr r r rr)rrZ newpolicyattrrrrrclone<s z_PolicyBase.clonecCs,t||rd}nd}t|j|jj|dS)Nz'{!r} object attribute {!r} is read-onlyz!{!r} object has no attribute {!r})r AttributeErrorrrr)rrrmsgrrrr Ns z_PolicyBase.__setattr__cCs|jf|jS)zNon-default values from right operand override those from left. The object returned is a new instance of the subclass. )r!r)rotherrrr__add__Usz_PolicyBase.__add__) r __module__ __qualname____doc__rrr!r r% __classcell__rr)rrrs  rcCs,|jddd}|jddd}|d|S)N r)rsplitsplit)docZ added_docrrr _append_doc^sr/cCs|jr(|jjdr(t|jdj|j|_xf|jjD]X\}}|jr4|jjdr4xhsz%_extend_docstrings..r()r( startswithr/ __bases__rr getattr)clsrr r3r.rrr_extend_docstringscs r9c@seZdZdZdZdZdZdZdZdZ dZ dd Z d d Z d d Z ejddZejddZejddZejddZejddZdS)ra Controls for how messages are interpreted and formatted. Most of the classes and many of the methods in the email package accept Policy objects as parameters. A Policy object contains a set of values and functions that control how input is interpreted and how output is rendered. For example, the parameter 'raise_on_defect' controls whether or not an RFC violation results in an error being raised or not, while 'max_line_length' controls the maximum length of output lines when a Message is serialized. Any valid attribute may be overridden when a Policy is created by passing it as a keyword argument to the constructor. Policy objects are immutable, but a new Policy object can be created with only certain values changed by calling the Policy instance with keyword arguments. Policy objects can also be added, producing a new Policy object in which the non-default attributes set in the right hand operand overwrite those specified in the left operand. Settable attributes: raise_on_defect -- If true, then defects should be raised as errors. Default: False. linesep -- string containing the value to use as separation between output lines. Default '\n'. cte_type -- Type of allowed content transfer encodings 7bit -- ASCII only 8bit -- Content-Transfer-Encoding: 8bit is allowed Default: 8bit. Also controls the disposition of (RFC invalid) binary data in headers; see the documentation of the binary_fold method. max_line_length -- maximum length of lines, excluding 'linesep', during serialization. None or 0 means no line wrapping is done. Default is 78. mangle_from_ -- a flag that, when True escapes From_ lines in the body of the message by putting a `>' in front of them. This is used when the message is being serialized by a generator. Default: True. message_factory -- the class to use to create new message objects. If the value is None, the default is Message. verify_generated_headers -- if true, the generator verifies that each header they are properly folded, so that a parser won't treat it as multiple headers, start-of-body, or part of another header. This is a check against custom Header & fold() implementations. Fr*Z8bitNNTcCs|jr ||j||dS)aZBased on policy, either raise defect or call register_defect. handle_defect(obj, defect) defect should be a Defect subclass, but in any case must be an Exception subclass. obj is the object on which the defect should be registered if it is not raised. If the raise_on_defect is True, the defect is raised as an error, otherwise the object and the defect are passed to register_defect. This method is intended to be called by parsers that discover defects. The email package parsers always call it with Defect instances. N)raise_on_defectregister_defect)robjdefectrrr handle_defectszPolicy.handle_defectcCs|jj|dS)aRecord 'defect' on 'obj'. Called by handle_defect if raise_on_defect is False. This method is part of the Policy API so that Policy subclasses can implement custom defect handling. The default implementation calls the append method of the defects attribute of obj. The objects used by the email package by default that get passed to this method will always have a defects attribute with an append method. N)Zdefectsappend)rr=r>rrrr<s zPolicy.register_defectcCsdS)a[Return the maximum allowed number of headers named 'name'. Called when a header is added to a Message object. If the returned value is not 0 or None, and there are already a number of headers with the name 'name' equal to the value returned, a ValueError is raised. Because the default behavior of Message's __setitem__ is to append the value to the list of headers, it is easy to create duplicate headers without realizing it. This method allows certain headers to be limited in the number of instances of that header that may be added to a Message programmatically. (The limit is not observed by the parser, which will faithfully produce as many headers as exist in the message being parsed.) The default implementation returns None for all header names. Nr)rrrrrheader_max_countszPolicy.header_max_countcCstdS)aZGiven a list of linesep terminated strings constituting the lines of a single header, return the (name, value) tuple that should be stored in the model. The input lines should retain their terminating linesep characters. The lines passed in by the email package may contain surrogateescaped binary data. N)NotImplementedError)r sourcelinesrrrheader_source_parseszPolicy.header_source_parsecCstdS)zGiven the header name and the value provided by the application program, return the (name, value) that should be stored in the model. N)rB)rrrrrrheader_store_parseszPolicy.header_store_parsecCstdS)awGiven the header name and the value from the model, return the value to be returned to the application program that is requesting that header. The value passed in by the email package may contain surrogateescaped binary data if the lines were parsed by a BytesParser. The returned value should not contain any surrogateescaped data. N)rB)rrrrrrheader_fetch_parses zPolicy.header_fetch_parsecCstdS)aGiven the header name and the value from the model, return a string containing linesep characters that implement the folding of the header according to the policy controls. The value passed in by the email package may contain surrogateescaped binary data if the lines were parsed by a BytesParser. The returned value should not contain any surrogateescaped data. N)rB)rrrrrrfolds z Policy.foldcCstdS)a%Given the header name and the value from the model, return binary data containing linesep characters that implement the folding of the header according to the policy controls. The value passed in by the email package may contain surrogateescaped binary data. N)rB)rrrrrr fold_binary szPolicy.fold_binary)rr&r'r(r;linesepcte_typemax_line_length mangle_from_Zmessage_factoryZverify_generated_headersr?r<rAabcabstractmethodrDrErFrGrHrrrrrps 7    ) metaclassc@sLeZdZdZdZddZddZddZd d Zd d Z d dZ ddZ dS)rz+ This particular policy is the backward compatibility Policy. It replicates the behavior of the email package version 5.1. TcCs0t|ts|St|r(tj|tj|dS|SdS)N)r header_name) isinstancestrrrHeader_charset UNKNOWN8BIT)rrrrrr_sanitize_header!s   zCompat32._sanitize_headercCs>|djdd\}}|jddj|dd}||jdfS)a:+ The name is parsed as everything up to the ':' and returned unmodified. The value is determined by stripping leading whitespace off the remainder of the first line, joining all subsequent lines together, and stripping any trailing carriage return or linefeed characters. r:r+z Nz )r-lstriprrstrip)rrCrrrrrrD-szCompat32.header_source_parsecCs||fS)z>+ The name and value are returned unmodified. r)rrrrrrrE9szCompat32.header_store_parsecCs |j||S)z+ If the value contains binary data, it is converted into a Header object using the unknown-8bit charset. Otherwise it is returned unmodified. )rV)rrrrrrrF?szCompat32.header_fetch_parsecCs|j||ddS)a+ Headers are folded using the Header folding algorithm, which preserves existing line breaks in the value, and wraps each resulting line to the max_line_length. Non-ASCII binary data are CTE encoded using the unknown-8bit charset. T)sanitize)_fold)rrrrrrrGFsz Compat32.foldcCs"|j|||jdkd}|jddS)a+ Headers are folded using the Header folding algorithm, which preserves existing line breaks in the value, and wraps each resulting line to the max_line_length. If cte_type is 7bit, non-ascii binary data is CTE encoded using the unknown-8bit charset. Otherwise the original source header is used, with its existing line breaks and/or binary data. Z7bit)r[asciisurrogateescape)r\rJencode)rrrZfoldedrrrrHPs zCompat32.fold_binarycCsg}|jd|t|tr\t|rL|rs   L ( f_policybase.cpython-36.opt-2.pyc000064400000013600147204636050012432 0ustar003 f<@sddlZddlmZddlmZddlmZdddgZGdd d Zd d Z d d Z Gdddeej dZ e Gddde Z e ZdS)N)header)charset)_has_surrogatesPolicyCompat32compat32cs<eZdZfddZddZddZddZd d ZZS) _PolicyBasec sLxF|jD]:\}}t||r0tt|j||q tdj||jjq WdS)Nz*{!r} is an invalid keyword argument for {}) itemshasattrsuperr __setattr__ TypeErrorformat __class____name__)selfkwnamevalue)r)/usr/lib64/python3.6/email/_policybase.py__init__)s  z_PolicyBase.__init__cCs*dd|jjD}dj|jjdj|S)NcSsg|]\}}dj||qS)z{}={!r})r).0rrrrr 8sz(_PolicyBase.__repr__..z{}({})z, )__dict__r rrrjoin)rargsrrr__repr__7sz_PolicyBase.__repr__cKsz|jj|j}x$|jjD]\}}tj|||qWx@|jD]4\}}t||sdtdj||jj tj|||q>W|S)Nz*{!r} is an invalid keyword argument for {}) r__new__rr objectr r r rr)rrZ newpolicyattrrrrrclone<s z_PolicyBase.clonecCs,t||rd}nd}t|j|jj|dS)Nz'{!r} object attribute {!r} is read-onlyz!{!r} object has no attribute {!r})r AttributeErrorrrr)rrrmsgrrrr Ns z_PolicyBase.__setattr__cCs|jf|jS)N)r!r)rotherrrr__add__Usz_PolicyBase.__add__) r __module__ __qualname__rrr!r r% __classcell__rr)rrrs  rcCs,|jddd}|jddd}|d|S)N r)rsplitsplit)docZ added_docrrr _append_doc^sr.cCs|jr(|jjdr(t|jdj|j|_xf|jjD]X\}}|jr4|jjdr4xhsz%_extend_docstrings..__doc__)r4 startswithr. __bases__rr getattr)clsrr r2r-rrr_extend_docstringscs r9c@seZdZdZdZdZdZdZdZdZ ddZ d d Z d d Z e jd dZe jddZe jddZe jddZe jddZdS)rFr)Z8bitNNTcCs|jr ||j||dS)N)raise_on_defectregister_defect)robjdefectrrr handle_defectszPolicy.handle_defectcCs|jj|dS)N)Zdefectsappend)rr=r>rrrr<s zPolicy.register_defectcCsdS)Nr)rrrrrheader_max_countszPolicy.header_max_countcCstdS)N)NotImplementedError)r sourcelinesrrrheader_source_parseszPolicy.header_source_parsecCstdS)N)rB)rrrrrrheader_store_parseszPolicy.header_store_parsecCstdS)N)rB)rrrrrrheader_fetch_parses zPolicy.header_fetch_parsecCstdS)N)rB)rrrrrrfolds z Policy.foldcCstdS)N)rB)rrrrrr fold_binary szPolicy.fold_binary)rr&r'r;linesepcte_typemax_line_length mangle_from_Zmessage_factoryZverify_generated_headersr?r<rAabcabstractmethodrDrErFrGrHrrrrrps9    ) metaclassc@sHeZdZdZddZddZddZdd Zd d Zd d Z ddZ dS)rTcCs0t|ts|St|r(tj|tj|dS|SdS)N)r header_name) isinstancestrrrHeader_charset UNKNOWN8BIT)rrrrrr_sanitize_header!s   zCompat32._sanitize_headercCs>|djdd\}}|jddj|dd}||jdfS)Nr:r*z z )r,lstriprrstrip)rrCrrrrrrD-szCompat32.header_source_parsecCs||fS)Nr)rrrrrrrE9szCompat32.header_store_parsecCs |j||S)N)rV)rrrrrrrF?szCompat32.header_fetch_parsecCs|j||ddS)NT)sanitize)_fold)rrrrrrrGFsz Compat32.foldcCs"|j|||jdkd}|jddS)NZ7bit)r[asciisurrogateescape)r\rJencode)rrrZfoldedrrrrHPs zCompat32.fold_binarycCsg}|jd|t|tr\t|rL|rs   L ( fbase64mime.cpython-36.opt-2.pyc000064400000002643147204636050012102 0ustar003 \ @spddddddgZddlmZddlmZmZd Zd Zd Zd Z d dZ dddZ defddZ ddZ e Ze ZdS) body_decode body_encodedecode decodestring header_encode header_length) b64encode) b2a_base64 a2b_base64z  cCs*tt|d\}}|d}|r&|d7}|S)N)divmodlen) bytearrayZ groups_of_3Zleftovernr(/usr/lib64/python3.6/email/base64mime.pyr2s  iso-8859-1cCs6|sdSt|tr|j|}t|jd}d||fS)Nr asciiz =?%s?b?%s?=) isinstancestrencoderr)Z header_bytescharsetZencodedrrrr=s   LcCs|s|Sg}|dd}x^tdt||D]J}t||||jd}|jtrj|tkrj|dd|}|j|q*Wtj|S)Nrrrr) rangerr rendswithNLappend EMPTYSTRINGjoin)sZ maxlinelenZeolZencvecZ max_unencodediencrrrrLs  cCs.|s tSt|tr"t|jdSt|SdS)Nzraw-unicode-escape)bytesrrr r)stringrrrrfs  N)r)__all__base64rZbinasciir r ZCRLFr!r#ZMISC_LENrrrrrrrrrrs"  base64mime.cpython-36.pyc000064400000006224147204636050011141 0ustar003 \ @stdZddddddgZddlmZdd lmZmZd Zd Zd Z d Z ddZ dddZ defddZ ddZeZeZdS)aBase64 content transfer encoding per RFCs 2045-2047. This module handles the content transfer encoding method defined in RFC 2045 to encode arbitrary 8-bit data using the three 8-bit bytes in four 7-bit characters encoding known as Base64. It is used in the MIME standards for email to attach images, audio, and text using some 8-bit character sets to messages. This module provides an interface to encode and decode both headers and bodies with Base64 encoding. RFC 2045 defines a method for including character set information in an `encoded-word' in a header. This method is commonly used for 8-bit real names in To:, From:, Cc:, etc. fields, as well as Subject: lines. This module does not do the line wrapping or end-of-line character conversion necessary for proper internationalized headers; it only does dumb encoding and decoding. To deal with the various line wrapping issues, use the email.header module. body_decode body_encodedecode decodestring header_encode header_length) b64encode) b2a_base64 a2b_base64z  cCs*tt|d\}}|d}|r&|d7}|S)z6Return the length of s when it is encoded with base64.)divmodlen) bytearrayZ groups_of_3Zleftovernr(/usr/lib64/python3.6/email/base64mime.pyr2s  iso-8859-1cCs6|sdSt|tr|j|}t|jd}d||fS)zEncode a single header line with Base64 encoding in a given charset. charset names the character set to use to encode the header. It defaults to iso-8859-1. Base64 encoding is defined in RFC 2045. r asciiz =?%s?b?%s?=) isinstancestrencoderr)Z header_bytescharsetZencodedrrrr=s   LcCs|s|Sg}|dd}x^tdt||D]J}t||||jd}|jtrj|tkrj|dd|}|j|q*Wtj|S)a1Encode a string with base64. Each line will be wrapped at, at most, maxlinelen characters (defaults to 76 characters). Each line of encoded text will end with eol, which defaults to "\n". Set this to "\r\n" if you will be using the result of this function directly in an email. rrrrN) rangerr rendswithNLappend EMPTYSTRINGjoin)sZ maxlinelenZeolZencvecZ max_unencodediencrrrrLs  cCs.|s tSt|tr"t|jdSt|SdS)zDecode a raw base64 string, returning a bytes object. This function does not parse a full MIME header value encoded with base64 (like =?iso-8859-1?b?bmloISBuaWgh?=) -- please use the high level email.header class for that functionality. zraw-unicode-escapeN)bytesrrr r)stringrrrrfs  N)r)__doc____all__base64rZbinasciir r ZCRLFr!r#ZMISC_LENrrrrrrrrrrs$  charset.cpython-36.opt-1.pyc000064400000026324147204636050011600 0ustar003 \B@srddddgZddlmZddlZddlZddlmZddlmZd Z d Z d Z d Z d Z dZdZe e dfe e dfe e dfe e dfe e dfe e dfe e dfe e dfe e dfe e dfe e dfe e dfd*e e dfe e dfe ddfe ddfe ddfe e dfe e dfdZdddddddddddddddddddddddd d Zd!d"dd#Zd+d$dZd%dZd&dZd'd(ZGd)ddZdS),Charset add_alias add_charset add_codec)partialN)errors)encode_7or8bitzus-asciiz unknown-8bitz iso-2022-jpzutf-8)z iso-8859-1z iso-8859-2z iso-8859-3z iso-8859-4z iso-8859-9z iso-8859-10z iso-8859-13z iso-8859-14z iso-8859-15z iso-8859-16z windows-1252Zvisciizus-asciibig5gb2312zeuc-jp shift_jisz iso-2022-jpzkoi8-rzutf-8z iso-8859-1z iso-8859-2z iso-8859-3z iso-8859-4z iso-8859-9z iso-8859-10z iso-8859-13z iso-8859-14z iso-8859-15z iso-8859-16zks_c_5601-1987zeuc-jpzeuc-kr)latin_1zlatin-1Zlatin_2zlatin-2Zlatin_3zlatin-3Zlatin_4zlatin-4Zlatin_5zlatin-5Zlatin_6zlatin-6Zlatin_7zlatin-7Zlatin_8zlatin-8Zlatin_9zlatin-9Zlatin_10zlatin-10cp949euc_jpeuc_krascii eucgb2312_cnbig5_tw)rrzus-asciicCs"|tkrtd|||ft|<dS)a>Add character set properties to the global registry. charset is the input character set, and must be the canonical name of a character set. Optional header_enc and body_enc is either Charset.QP for quoted-printable, Charset.BASE64 for base64 encoding, Charset.SHORTEST for the shortest of qp or base64 encoding, or None for no encoding. SHORTEST is only valid for header_enc. It describes how message headers and message bodies in the input charset are to be encoded. Default is no encoding. Optional output_charset is the character set that the output should be in. Conversions will proceed from input charset, to Unicode, to the output charset when the method Charset.convert() is called. The default is to output in the same character set as the input. Both input_charset and output_charset must have Unicode codec entries in the module's charset-to-codec mapping; use add_codec(charset, codecname) to add codecs the module does not know about. See the codecs module's documentation for more information. z!SHORTEST not allowed for body_encN)SHORTEST ValueErrorCHARSETS)charsetZ header_encZbody_encoutput_charsetr%/usr/lib64/python3.6/email/charset.pyrmscCs |t|<dS)zAdd a character set alias. alias is the alias name, e.g. latin-1 canonical is the character set's canonical name, e.g. iso-8859-1 N)ALIASES)aliasZ canonicalrrrrscCs |t|<dS)a$Add a codec that map characters in the given charset to/from Unicode. charset is the canonical name of a character set. codecname is the name of a Python codec, as appropriate for the second argument to the unicode() built-in, or to the encode() method of a Unicode string. N) CODEC_MAP)rZ codecnamerrrrscCs"|tkr|jddS|j|SdS)Nrsurrogateescape) UNKNOWN8BITencode)stringcodecrrr_encodes r'c@s`eZdZdZefddZddZeZddZdd Z d d Z d d Z ddZ ddZ ddZdS)ra@ Map character sets to their email properties. This class provides information about the requirements imposed on email for a specific character set. It also provides convenience routines for converting between character sets, given the availability of the applicable codecs. Given a character set, it will do its best to provide information on how to use that character set in an email in an RFC-compliant way. Certain character sets must be encoded with quoted-printable or base64 when used in email headers or bodies. Certain character sets must be converted outright, and are not allowed in email. Instances of this module expose the following information about a character set: input_charset: The initial character set specified. Common aliases are converted to their `official' email names (e.g. latin_1 is converted to iso-8859-1). Defaults to 7-bit us-ascii. header_encoding: If the character set must be encoded before it can be used in an email header, this attribute will be set to Charset.QP (for quoted-printable), Charset.BASE64 (for base64 encoding), or Charset.SHORTEST for the shortest of QP or BASE64 encoding. Otherwise, it will be None. body_encoding: Same as header_encoding, but describes the encoding for the mail message's body, which indeed may be different than the header encoding. Charset.SHORTEST is not allowed for body_encoding. output_charset: Some character sets must be converted before they can be used in email headers or bodies. If the input_charset is one of them, this attribute will contain the name of the charset output will be converted to. Otherwise, it will be None. input_codec: The name of the Python codec used to convert the input_charset to Unicode. If no conversion codec is necessary, this attribute will be None. output_codec: The name of the Python codec used to convert Unicode to the output_charset. If no conversion codec is necessary, this attribute will have the same value as the input_codec. c Csy$t|tr|jdn t|d}Wntk rBtj|YnX|j}tj|||_ t j|j t t df\}}}|s~|j }||_ ||_tj|||_tj|j |j |_tj|j|j|_dS)Nr) isinstancestrr$ UnicodeErrorrZ CharsetErrorlowerrget input_charsetrrBASE64header_encoding body_encodingrr!Z input_codec output_codec)selfr-ZhencZbencZconvrrr__init__s&   zCharset.__init__cCs |jjS)N)r-r+)r2rrr__str__szCharset.__str__cCst|t|jkS)N)r)r+)r2otherrrr__eq__szCharset.__eq__cCs$|jtkrdS|jtkrdStSdS)aPReturn the content-transfer-encoding used for body encoding. This is either the string `quoted-printable' or `base64' depending on the encoding used, or it is a function in which case you should call the function with a single argument, the Message object being encoded. The function should then set the Content-Transfer-Encoding header itself to whatever is appropriate. Returns "quoted-printable" if self.body_encoding is QP. Returns "base64" if self.body_encoding is BASE64. Returns conversion function otherwise. zquoted-printablebase64N)r0QPr.r)r2rrrget_body_encodings   zCharset.get_body_encodingcCs |jp |jS)zReturn the output character set. This is self.output_charset if that is not None, otherwise it is self.input_charset. )rr-)r2rrrget_output_charsetszCharset.get_output_charsetcCs6|jpd}t||}|j|}|dkr*|S|j||S)aHeader-encode a string by converting it first to bytes. The type of encoding (base64 or quoted-printable) will be based on this charset's `header_encoding`. :param string: A unicode string for the header. It must be possible to encode this string to bytes using the character set's output codec. :return: The encoded string, with RFC 2047 chrome. zus-asciiN)r1r' _get_encoder header_encode)r2r%r& header_bytesencoder_modulerrrr<s   zCharset.header_encodecCs|jpd}t||}|j|}t|j|d}|j}t|t}g} g} t||} x|D]} | j | t j | } |j t| |}|| krZ| j | r| r| j dn.| rdnd}t j | }t||}| j ||| g} t||} qZWt j | }t||}| j ||| S)afHeader-encode a string by converting it first to bytes. This is similar to `header_encode()` except that the string is fit into maximum line lengths as given by the argument. :param string: A unicode string for the header. It must be possible to encode this string to bytes using the character set's output codec. :param maxlengths: Maximum line length iterator. Each element returned from this iterator will provide the next maximum line length. This parameter is used as an argument to built-in next() and should never be exhausted. The maximum line lengths should not count the RFC 2047 chrome. These line lengths are only a hint; the splitter does the best it can. :return: Lines of encoded strings, each with RFC 2047 chrome. zus-ascii)rN r )r1r'r;rr<r:lenRFC2047_CHROME_LENnextappend EMPTYSTRINGjoin header_lengthpop)r2r%Z maxlengthsr&r=r>encoderrZextralinesZ current_linemaxlen characterZ this_lineZlengthZ separatorZ joined_linerrrheader_encode_lines,s6               zCharset.header_encode_linescCs`|jtkrtjS|jtkr tjS|jtkrXtjj|}tjj|}||krPtjStjSndSdS)N)r/r.email base64mimer8 quoprimimerrF)r2r=Zlen64Zlenqprrrr;js     zCharset._get_encodercCs|s|S|jtkr4t|tr(|j|j}tjj|S|jt krjt|trT|j|j}|j d}tj j|St|tr|j|jj d}|SdS)avBody-encode a string by converting it first to bytes. The type of encoding (base64 or quoted-printable) will be based on self.body_encoding. If body_encoding is None, we assume the output charset is a 7bit encoding, so re-encoding the decoded string using the ascii codec produces the correct string version of the content. latin1rN) r0r.r(r)r$rrMrN body_encoder8decoderO)r2r%rrrrQys           zCharset.body_encodeN)__name__ __module__ __qualname____doc__DEFAULT_CHARSETr3r4__repr__r6r9r:r<rLr;rQrrrrrs+ !>)NNN)NNN)__all__ functoolsrZemail.base64mimerMZemail.quoprimimerZemail.encodersrr8r.rrArWr#rDrrr!rrrr'rrrrrs      contentmanager.cpython-36.pyc000064400000016172147204636050012215 0ustar003 \)@s:ddlZddlZddlZddlZddlmZGdddZeZd%ddZej ded d Z xd j D]Z ej e e qhWd d Z x dj D]Zej dee qWddZej deddZddZddZddZd&ddZejeed'd d!Zejejjed(d#d$Zx eeefD]Zejeeq WdS))N) quoprimimec@s<eZdZddZddZddZddZd d Zd d Zd S)ContentManagercCsi|_i|_dS)N) get_handlers set_handlers)selfr,/usr/lib64/python3.6/email/contentmanager.py__init__ szContentManager.__init__cCs||j|<dS)N)r)rkeyhandlerrrradd_get_handler szContentManager.add_get_handlercOs||j}||jkr(|j||f||S|j}||jkrP|j||f||Sd|jkrp|jd|f||St|dS)N)Zget_content_typerget_content_maintypeKeyError)rmsgargskwZ content_typemaintyperrr get_contents   zContentManager.get_contentcCs||j|<dS)N)r)rZtypekeyr rrradd_set_handlerszContentManager.add_set_handlercOs>|jdkrtd|j||}|j|||f||dS)NZ multipartz"set_content not valid on multipart)r TypeError_find_set_handlerZ clear_content)rrobjrrr rrr set_contents   zContentManager.set_contentc Csd}xt|jD]}||jkr(|j|S|j}t|dd}|rLdj||fn|}|dkr\|}||jkrp|j|S||jkr|j|S|j}||jkr|j|SqWd|jkr|jdSt|dS)N __module__r .)type__mro__r __qualname__getattrjoin__name__r) rrrZfull_path_for_errortypZqnamemodname full_pathnamerrrr's&          z ContentManager._find_set_handlerN) r!rrr r rrrrrrrrrs   rreplacecCs&|jdd}|jdd}|j||dS)NT)decodecharsetASCII)errors) get_payloadZ get_paramr')rr*Zcontentr(rrrget_text_content@s  r,textcCs |jddS)NT)r')r+)rrrrget_non_text_contentGsr.zaudio image video applicationcCs |jdS)Nr)r+)rrrrget_message_contentMsr/zrfc822 external-bodyzmessage/cCst|jdS)Nr)bytesr+)rrrr%get_and_fixup_unknown_message_contentSsr1messagecsdj||f|d<|rt|dds<|jfdd|D}y,x&|D]}|jrX|jd|||j<qDWWn@tjjk r}z tdj |j |jd|WYdd}~XnXdS) N/z Content-Typerr%csg|]}jj|gqSr)Zheader_factoryZheader_source_parse).0header)mprr dsz _prepare_set..zInvalid header: {})policy) r hasattrr8Zdefectsr%emailr*Z HeaderDefect ValueErrorformatZfold)rrsubtypeheadersr5excr)r6r _prepare_set_s   r@cCs||dkr|dk rd}|dk r$||d<|dk r>|jd|ddd|dk rN||d<|dk rxx |jD]\}}|j||q`WdS)NZ attachmentzContent-DispositionfilenameT)r5r&z Content-ID) set_paramitems)r dispositionrAcidparamsr valuerrr _finalize_setpsrHcCsZg}|dd}x>tdt||D]*}||||}|jtj|jdq"Wdj|S)Nrasciir )rangelenappendbinascii b2a_base64r'r )datamax_line_lengthZ encoded_linesZunencoded_bytes_per_lineiZthislinerrr_encode_base64s  rTc s||j|j}|jjdfdd}dd}|dkryd||jdfStk r\YnX|jdkrtdd |D|jkrd||jdd fS||dd }tj |jd |j}t j |} t |t | krd }nd}t |d kr||fS|dkr ||jd} nj|dkr&||jdd } nN|dkrJtj ||jd |j} n*|d krft |||j} ntdj||| fS)NrKcsj|S)N)r )lines)lineseprr embedded_bodysz#_encode_text..embedded_bodycSsdj|dS)N )r )rUrrr normal_bodysz!_encode_text..normal_body7bit8bitcss|]}t|VqdS)N)rM)r4xrrr sz_encode_text..surrogateescape zlatin-1base64zquoted-printablez$Unknown content transfer encoding {})encode splitlinesrVr'UnicodeDecodeErrorZcte_typemaxrRrZ body_encoderOrPrMrTr;r<) stringr(cter8rUrWrYZsniffZsniff_qpZ sniff_base64rQr)rVr _encode_texts@           rgplainutf-8c Csdt|d|| t||||j\}} |j| |jdtjjj||dd||d<t |||||dS)Nr-r(T)r&zContent-Transfer-Encoding) r@rgr8 set_payloadrBr:r(ZALIASESgetrH) rrer=r(rfrDrArErFr>Zpayloadrrrset_text_contents rlrfc822c Cs|dkrtd|dkr@|d kr.tdj||dkr:dn|}n0|dkrd|d kr^td j|d}n |dkrpd}t|d |||j|g||d <t|||||dS)Npartialz4message/partial is not supported for Message objectsrmrZr[binaryz*message/rfc822 parts do not support cte={}z external-bodyz1message/external-body parts do not support cte={}r2zContent-Transfer-Encoding)NrZr[ro)NrZ)r;r<r@rjrH) rr2r=rfrDrArErFr>rrrset_message_contents$   rpr`c Cst|||| |dkr(t||jjd}nN|dkrNtj|dddd}|jd}n(|dkrb|jdn|d krv|jdd }|j|||d <t |||||dS)Nr`)rRzquoted-printableFT)istextr5Z quotetabsrKrZr[ror^zContent-Transfer-Encoding)r[ro) r@rTr8rRrOZb2a_qpr'rarjrH) rrQrr=rfrDrArErFr>rrrset_bytes_contents    rr)r&)rhriNNNNNN)rmNNNNNN)r`NNNNN)rOZ email.charsetr:Z email.messageZ email.errorsrrZraw_data_managerr,r r.splitrr/r=r1r@rHrTrgrlrstrrpr2ZMessagerrr0 bytearray memoryviewr"rrrrsD 6   '   encoders.cpython-36.opt-1.pyc000064400000003152147204636050011743 0ustar003 \@sTdZddddgZddlmZddlmZdd Zd dZ d dZ d dZ d dZ dS)z Encodings and related functions.encode_7or8bit encode_base64 encode_noop encode_quopri) encodebytes) encodestringcCst|dd}|jddS)NT)Z quotetabs s=20) _encodestringreplace)sencr &/usr/lib64/python3.6/email/encoders.py_qencodes rcCs0|jdd}tt|d}|j|d|d<dS)zlEncode the message's payload in Base64. Also, add an appropriate Content-Transfer-Encoding header. T)decodeasciibase64zContent-Transfer-EncodingN) get_payloadstr_bencode set_payload)msgorigencdatar r rrs  cCs*|jdd}t|}|j|d|d<dS)zvEncode the message's payload in quoted-printable. Also, add an appropriate Content-Transfer-Encoding header. T)rzquoted-printablezContent-Transfer-EncodingN)rrr)rrrr r rr&s  c CsX|jdd}|dkr d|d<dSy|jdWntk rJd|d<Yn Xd|d<dS)z9Set the Content-Transfer-Encoding header to 7bit or 8bit.T)rNZ7bitzContent-Transfer-EncodingrZ8bit)rr UnicodeError)rrr r rr2s cCsdS)z Do nothing.Nr )rr r rrDsN) __doc____all__rrrquoprirr rrrrrr r r rs    encoders.cpython-36.opt-2.pyc000064400000002413147204636050011743 0ustar003 \@sPddddgZddlmZddlmZddZd dZd dZ d dZ d dZ d S)encode_7or8bit encode_base64 encode_noop encode_quopri) encodebytes) encodestringcCst|dd}|jddS)NT)Z quotetabs s=20) _encodestringreplace)sencr &/usr/lib64/python3.6/email/encoders.py_qencodes rcCs0|jdd}tt|d}|j|d|d<dS)NT)decodeasciibase64zContent-Transfer-Encoding) get_payloadstr_bencode set_payload)msgorigencdatar r rrs  cCs*|jdd}t|}|j|d|d<dS)NT)rzquoted-printablezContent-Transfer-Encoding)rrr)rrrr r rr&s  c CsX|jdd}|dkr d|d<dSy|jdWntk rJd|d<Yn Xd|d<dS)NT)rZ7bitzContent-Transfer-EncodingrZ8bit)rr UnicodeError)rrr r rr2s cCsdS)Nr )rr r rrDsN) __all__rrrquoprirr rrrrrr r r rs    encoders.cpython-36.pyc000064400000003152147204636050011004 0ustar003 \@sTdZddddgZddlmZddlmZdd Zd dZ d dZ d dZ d dZ dS)z Encodings and related functions.encode_7or8bit encode_base64 encode_noop encode_quopri) encodebytes) encodestringcCst|dd}|jddS)NT)Z quotetabs s=20) _encodestringreplace)sencr &/usr/lib64/python3.6/email/encoders.py_qencodes rcCs0|jdd}tt|d}|j|d|d<dS)zlEncode the message's payload in Base64. Also, add an appropriate Content-Transfer-Encoding header. T)decodeasciibase64zContent-Transfer-EncodingN) get_payloadstr_bencode set_payload)msgorigencdatar r rrs  cCs*|jdd}t|}|j|d|d<dS)zvEncode the message's payload in quoted-printable. Also, add an appropriate Content-Transfer-Encoding header. T)rzquoted-printablezContent-Transfer-EncodingN)rrr)rrrr r rr&s  c CsX|jdd}|dkr d|d<dSy|jdWntk rJd|d<Yn Xd|d<dS)z9Set the Content-Transfer-Encoding header to 7bit or 8bit.T)rNZ7bitzContent-Transfer-EncodingrZ8bit)rr UnicodeError)rrr r rr2s cCsdS)z Do nothing.Nr )rr r rrDsN) __doc____all__rrrquoprirr rrrrrr r r rs    errors.cpython-36.opt-1.pyc000064400000014316147204636050011461 0ustar003 f@sdZGdddeZGdddeZGdddeZGdddeZGd d d eeZGd d d eZGd ddeZ Gddde Z Gddde Z Gddde Z Gddde ZGddde ZGddde ZGddde ZeZGddde ZGdd d e ZGd!d"d"e ZGd#d$d$e ZGd%d&d&e ZGd'd(d(e ZGd)d*d*e ZGd+d,d,eZGd-d.d.eZGd/d0d0eZGd1d2d2eZGd3d4d4eZd5S)6z email package exception classes.c@seZdZdZdS) MessageErrorz+Base class for errors in the email package.N)__name__ __module__ __qualname____doc__rr$/usr/lib64/python3.6/email/errors.pyrsrc@seZdZdZdS)MessageParseErrorz&Base class for message parsing errors.N)rrrrrrrrr src@seZdZdZdS)HeaderParseErrorzError while parsing headers.N)rrrrrrrrr sr c@seZdZdZdS) BoundaryErrorz#Couldn't find terminating boundary.N)rrrrrrrrr sr c@seZdZdZdS)MultipartConversionErrorz(Conversion to a multipart is prohibited.N)rrrrrrrrr sr c@seZdZdZdS) CharsetErrorzAn illegal charset was given.N)rrrrrrrrr sr c@seZdZdZdS)HeaderWriteErrorzError while writing headers.N)rrrrrrrrr sr cs"eZdZdZdfdd ZZS) MessageDefectz Base class for a message defect.Ncs|dk rtj|||_dS)N)super__init__line)selfr) __class__rrr(s zMessageDefect.__init__)N)rrrrr __classcell__rr)rrr%src@seZdZdZdS)NoBoundaryInMultipartDefectzBA message claimed to be a multipart but had no boundary parameter.N)rrrrrrrrr-src@seZdZdZdS)StartBoundaryNotFoundDefectz+The claimed start boundary was never found.N)rrrrrrrrr0src@seZdZdZdS)CloseBoundaryNotFoundDefectzEA start boundary was found, but not the corresponding close boundary.N)rrrrrrrrr3src@seZdZdZdS)#FirstHeaderLineIsContinuationDefectz;A message had a continuation line as its first header line.N)rrrrrrrrr6src@seZdZdZdS)MisplacedEnvelopeHeaderDefectz?A 'Unix-from' header was found in the middle of a header block.N)rrrrrrrrr9src@seZdZdZdS) MissingHeaderBodySeparatorDefectzEFound line with no leading whitespace and no colon before blank line.N)rrrrrrrrr<src@seZdZdZdS)!MultipartInvariantViolationDefectz?A message claimed to be a multipart but no subparts were found.N)rrrrrrrrrAsrc@seZdZdZdS)-InvalidMultipartContentTransferEncodingDefectzEAn invalid content transfer encoding was set on the multipart itself.N)rrrrrrrrrDsrc@seZdZdZdS)UndecodableBytesDefectz0Header contained bytes that could not be decodedN)rrrrrrrrrGsrc@seZdZdZdS)InvalidBase64PaddingDefectz/base64 encoded sequence had an incorrect lengthN)rrrrrrrrrJsrc@seZdZdZdS)InvalidBase64CharactersDefectz=base64 encoded sequence had characters not in base64 alphabetN)rrrrrrrrrMsrc@seZdZdZdS)InvalidBase64LengthDefectz4base64 encoded sequence had invalid length (1 mod 4)N)rrrrrrrrr Psr cs eZdZdZfddZZS) HeaderDefectzBase class for a header defect.cstj||dS)N)rr)rargskw)rrrrXszHeaderDefect.__init__)rrrrrrrr)rrr!Usr!c@seZdZdZdS)InvalidHeaderDefectz+Header is not valid, message gives details.N)rrrrrrrrr$[sr$c@seZdZdZdS)HeaderMissingRequiredValuez(A header that must have a value had noneN)rrrrrrrrr%^sr%cs(eZdZdZfddZddZZS)NonPrintableDefectz8ASCII characters outside the ascii-printable range foundcstj|||_dS)N)rrnon_printables)rr')rrrrds zNonPrintableDefect.__init__cCs dj|jS)Nz6the following ASCII non-printables found in header: {})formatr')rrrr__str__hszNonPrintableDefect.__str__)rrrrrr)rrr)rrr&as r&c@seZdZdZdS)ObsoleteHeaderDefectz0Header uses syntax declared obsolete by RFC 5322N)rrrrrrrrr*lsr*c@seZdZdZdS)NonASCIILocalPartDefectz(local_part contains non-ASCII charactersN)rrrrrrrrr+osr+N)r Exceptionrrr r TypeErrorr r r ValueErrorrrrrrrrZMalformedHeaderDefectrrrrrr r!r$r%r&r*r+rrrrs6 errors.cpython-36.opt-2.pyc000064400000011241147204636050011454 0ustar003 f@sGdddeZGdddeZGdddeZGdddeZGdd d eeZGd d d eZGd d d eZGddde Z Gddde Z Gddde Z Gddde Z Gddde ZGddde ZGddde ZeZGddde ZGddde ZGd d!d!e ZGd"d#d#e ZGd$d%d%e ZGd&d'd'e ZGd(d)d)e ZGd*d+d+eZGd,d-d-eZGd.d/d/eZGd0d1d1eZGd2d3d3eZd4S)5c@s eZdZdS) MessageErrorN)__name__ __module__ __qualname__rr$/usr/lib64/python3.6/email/errors.pyrsrc@s eZdZdS)MessageParseErrorN)rrrrrrrr src@s eZdZdS)HeaderParseErrorN)rrrrrrrrsrc@s eZdZdS) BoundaryErrorN)rrrrrrrr sr c@s eZdZdS)MultipartConversionErrorN)rrrrrrrr sr c@s eZdZdS) CharsetErrorN)rrrrrrrr sr c@s eZdZdS)HeaderWriteErrorN)rrrrrrrr sr cseZdZdfdd ZZS) MessageDefectNcs|dk rtj|||_dS)N)super__init__line)selfr) __class__rrr(s zMessageDefect.__init__)N)rrrr __classcell__rr)rrr %sr c@s eZdZdS)NoBoundaryInMultipartDefectN)rrrrrrrr-src@s eZdZdS)StartBoundaryNotFoundDefectN)rrrrrrrr0src@s eZdZdS)CloseBoundaryNotFoundDefectN)rrrrrrrr3src@s eZdZdS)#FirstHeaderLineIsContinuationDefectN)rrrrrrrr6src@s eZdZdS)MisplacedEnvelopeHeaderDefectN)rrrrrrrr9src@s eZdZdS) MissingHeaderBodySeparatorDefectN)rrrrrrrr<src@s eZdZdS)!MultipartInvariantViolationDefectN)rrrrrrrrAsrc@s eZdZdS)-InvalidMultipartContentTransferEncodingDefectN)rrrrrrrrDsrc@s eZdZdS)UndecodableBytesDefectN)rrrrrrrrGsrc@s eZdZdS)InvalidBase64PaddingDefectN)rrrrrrrrJsrc@s eZdZdS)InvalidBase64CharactersDefectN)rrrrrrrrMsrc@s eZdZdS)InvalidBase64LengthDefectN)rrrrrrrrPsrcseZdZfddZZS) HeaderDefectcstj||dS)N)rr)rargskw)rrrrXszHeaderDefect.__init__)rrrrrrr)rrr Usr c@s eZdZdS)InvalidHeaderDefectN)rrrrrrrr#[sr#c@s eZdZdS)HeaderMissingRequiredValueN)rrrrrrrr$^sr$cs$eZdZfddZddZZS)NonPrintableDefectcstj|||_dS)N)rrnon_printables)rr&)rrrrds zNonPrintableDefect.__init__cCs dj|jS)Nz6the following ASCII non-printables found in header: {})formatr&)rrrr__str__hszNonPrintableDefect.__str__)rrrrr(rrr)rrr%as r%c@s eZdZdS)ObsoleteHeaderDefectN)rrrrrrrr)lsr)c@s eZdZdS)NonASCIILocalPartDefectN)rrrrrrrr*osr*N) Exceptionrrrr TypeErrorr r r ValueErrorr rrrrrrZMalformedHeaderDefectrrrrrrr r#r$r%r)r*rrrrs4 feedparser.cpython-36.opt-1.pyc000064400000024374147204636050012272 0ustar003 \X@sdZddgZddlZddlmZddlmZddlmZddl m Z ej d Z ej d Z ej d Zej d Zej d Zd ZdZeZGdddeZGdddZGdddeZdS)aFeedParser - An email feed parser. The feed parser implements an interface for incrementally parsing an email message, line by line. This has advantages for certain applications, such as those reading email messages off a socket. FeedParser.feed() is the primary interface for pushing new data into the parser. It returns when there's nothing more it can do with the available data. When you have no more data to push into the parser, call .close(). This completes the parsing and returns the root message object. The other advantage of this parser is that it will never raise a parsing exception. Instead, when it finds something unexpected, it adds a 'defect' to the current message. Defects are just instances that live on the message object's .defects attribute. FeedParserBytesFeedParserN)errors)compat32)deque)StringIOz \r\n|\r|\nz (\r\n|\r|\n)z(\r\n|\r|\n)\Zz%^(From |[\041-\071\073-\176]*:|[\t ]) c@s`eZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ ddZ ddZ dS)BufferedSubFileakA file-ish object that can have new data loaded into it. You can also push and pop line-matching predicates onto a stack. When the current predicate matches the current line, a false EOF response (i.e. empty string) is returned instead. This lets the parser adhere to a simple abstraction -- it parses until EOF closes the current message. cCs$tdd|_t|_g|_d|_dS)Nr)newlineF)r_partialr_lines _eofstack_closed)selfr(/usr/lib64/python3.6/email/feedparser.py__init__5s zBufferedSubFile.__init__cCs|jj|dS)N)rappend)rZpredrrrpush_eof_matcher@sz BufferedSubFile.push_eof_matchercCs |jjS)N)rpop)rrrrpop_eof_matcherCszBufferedSubFile.pop_eof_matchercCs<|jjd|j|jj|jjd|jjd|_dS)NrT)r seek pushlines readlinestruncater)rrrrcloseFs    zBufferedSubFile.closecCsN|js|jrdStS|jj}x*t|jD]}||r*|jj|dSq*W|S)Nr)r r NeedMoreDatapopleftreversedr appendleft)rlineZateofrrrreadlineNs  zBufferedSubFile.readlinecCs|jj|dS)N)r r )rr!rrr unreadline`szBufferedSubFile.unreadlinecCsx|jj|d|kr d|kr dS|jjd|jj}|jjd|jj|djdsj|jj|j|j|dS)z$Push some new data into this object.r  Nr)r writerrrendswithrr)rdatapartsrrrpushes     zBufferedSubFile.pushcCs|jj|dS)N)r extend)rlinesrrrrzszBufferedSubFile.pushlinescCs|S)Nr)rrrr__iter__}szBufferedSubFile.__iter__cCs|j}|dkrt|S)Nr)r" StopIteration)rr!rrr__next__szBufferedSubFile.__next__N)__name__ __module__ __qualname____doc__rrrrr"r#r+rr.r0rrrrr -s r c@s`eZdZdZdedddZddZdd Zd d Zd d Z ddZ ddZ ddZ ddZ dS)rzA feed-style parser of email.N)policyc Cs||_d|_|dkr<|jdkr2ddlm}||_qn|j|_n2||_y||jdWntk rld|_YnXt|_g|_ |j j |_ d|_ d|_d|_dS)a_factory is called with no arguments to create a new message obj The policy keyword specifies a policy object that controls a number of aspects of the parser's operation. The default policy maintains backward compatibility. FNr)Message)r5T)r5_old_style_factoryZmessage_factoryZ email.messager6_factory TypeErrorr _input _msgstack _parsegenr0_parse_cur_last _headersonly)rr8r5r6rrrrs$     zFeedParser.__init__cCs d|_dS)NT)r@)rrrr_set_headersonlyszFeedParser._set_headersonlycCs|jj||jdS)zPush more data into the parser.N)r:r+ _call_parse)rr)rrrfeeds zFeedParser.feedc Cs&y |jWntk r YnXdS)N)r=r/)rrrrrBs zFeedParser._call_parsecCsJ|jj|j|j}|jdkrF|j rFtj}|jj |||S)zget_content_typeZset_default_typer;Zattachrr?)rmsgrrr _new_messages   zFeedParser._new_messagecCs(|jj}|jr|jd|_nd|_|S)Nr%r&)r;rr>)rretvalrrrrEs  zFeedParser._pop_messageccs6|jg}xb|jD]X}|tkr(tVqtj|sbtj|s`tj}|jj |j ||jj |P|j |qW|j ||jrg}x2|jj}|tkrtVq|dkrP|j |qW|j jtj|dS|j jdkrx|jjtjx$|jD]}|tkrtVqPqW|j}|jjx&|jj}|tkrFtVq(Pq(Wx&|jj}|tkrntVqPPqPW|dkrP|jj |qWdS|j jdkrx(|jD]}|tkrtVqPqW|jdS|j jdkr|j j}|dkrbtj}|jj |j |g}x.|jD]$}|tkrtj+}|jj |j ||j jtj| g}x$|jD]}|tkrtVqqWtj||j _'dS| s`tj,}|jj |j |dS| rndg}ng}x.|jD]$}|tkrtVqz|j |qzW|r|d}t-j|}|r|t$|j!dd|d<tj||j _'dSg}x.|jD]$}|tkrtVq|j |qW|j jtj|dS)Nrzmessage/delivery-statusmessagerDzcontent-transfer-encoding8bit7bitbinaryz--z(?Pz4)(?P--)?(?P[ \t]*)(?P\r\n|\r|\n)?$TFendlinesepr%r)rPrOrQr&r&).rLr:rheaderREmatchNLCRErZ MissingHeaderBodySeparatorDefectr5rGr>r#r_parse_headersr@r"Z set_payload EMPTYSTRINGjoinrJrr<rErrFZ get_boundaryZNoBoundaryInMultipartDefectgetlowerZ-InvalidMultipartContentTransferEncodingDefectrecompileescapegroup NLCRE_eolsearchlenpreambler?epilogueZ_payload isinstancestrZStartBoundaryNotFoundDefectZCloseBoundaryNotFoundDefect NLCRE_bol)rZheadersr!rIr-rMrKboundaryZ separatorZ boundaryreZcapturing_preamblercrSZclose_boundary_seenmoZlastlineZeolmordrRZpayload firstlineZbolmorrrr<sf                                                zFeedParser._parsegenc Cs^d}g}x4t|D]&\}}|ddkrV|sJtj|}|jj|j|q|j|q|rx|jj|jj|dg}}|j dr|dkrt j |}|r|dt |j d }|jj|qn:|t |dkr|jj|dStj|}|jjj|q|jd}|dkr*tjd}|jjj|q|d|}|g}qW|rZ|jj|jj|dS)Nrrz zFrom r%:zMissing header name.) enumeraterZ#FirstHeaderLineIsContinuationDefectr5rGr>rZset_rawZheader_source_parse startswithr`rarbr_Z set_unixfromr:r#ZMisplacedEnvelopeHeaderDefectZdefectsfindZInvalidHeaderDefect) rr-Z lastheaderZ lastvaluelinenor!rIriirrrrWsF              zFeedParser._parse_headers)N)r1r2r3r4rrrArCrBrrLrEr<rWrrrrrs  ~cs eZdZdZfddZZS)rz(Like FeedParser, but feed accepts bytes.cstj|jdddS)Nasciisurrogateescape)superrCdecode)rr)) __class__rrrCszBytesFeedParser.feed)r1r2r3r4rC __classcell__rr)rurrs)r4__all__r\ZemailrZemail._policybaser collectionsriorr]rVrgr`Z NLCRE_crackrTrXNLobjectrr rrrrrrs(         [generator.cpython-36.opt-2.pyc000064400000022025147204636050012130 0ustar003 fP@sdddgZddlZddlZddlZddlZddlmZddlmZm Z ddl m Z ddl m Z d Zd Zejd Zejd ejZejd ZGdddZGdddeZdZGdddeZeeejdZdeZejZdS) GeneratorDecodedGeneratorBytesGeneratorN)deepcopy)StringIOBytesIO)_has_surrogates)HeaderWriteError_ z \r\n|\r|\nz^From z\r\n[^ \t]|\r[^ \n\t]|\n[^ \t]c@seZdZd&ddddZddZd'dd Zd d Zd d ZddZddZ ddZ ddZ ddZ ddZ e ZddZddZddZd d!Zed(d"d#Zed$d%ZdS))rN)policycCs6|dkr|dkrdn|j}||_||_||_||_dS)NT) mangle_from__fp _mangle_from_ maxheaderlenr )selfoutfpr rr r'/usr/lib64/python3.6/email/generator.py__init__&s zGenerator.__init__cCs|jj|dS)N)rwrite)rsrrrrFszGenerator.writeFc Cs|jdkr|jn|j}|dk r*|j|d}|jdk rB|j|jd}|j|_|j|j|_d|_|j|j|_|j}|j}zL||_||_|r|j }|sdt j t j }|j ||j|j |Wd||_||_XdS)N)linesep)max_line_lengthz From nobody )r clonerr_NL_encode _encoded_NLZ_EMPTY_encoded_EMPTYZ get_unixfromtimeZctimer_write)rmsgunixfromrr Zold_gen_policyZold_msg_policyZufromrrrflattenJs,  zGenerator.flattencCs|j||jd|jdS)N)r ) __class__rr )rfprrrr{szGenerator.clonecCstS)N)r)rrrr _new_bufferszGenerator._new_buffercCs|S)Nr)rrrrrrszGenerator._encodecCsX|sdStj|}x*|ddD]}|j||j|jq W|drT|j|ddS)Nr)r))NLCREsplitrr)rlineslinerrr _write_liness  zGenerator._write_linesc Cs|j}z"d|_|j|_}|j|Wd||_|j}|`X|rht|}|jd|d|jd|dt|dd}|dkr|j|n|||jj|j dS)Nzcontent-transfer-encodingrz content-typer(_write_headers) r _munge_cter' _dispatchrZreplace_headergetattrr/rgetvalue)rr"ZoldfpZsfpZ munge_ctemethrrrr!s"   zGenerator._writecCst|j}|j}tj||fjdd}t|d|d}|dkrh|jdd}t|d|d}|dkrh|j}||dS)N-r Z_handle_)get_content_maintypeget_content_subtype UNDERSCOREjoinreplacer2 _writeBody)rr"mainsubZspecificr4Zgenericrrrr1s zGenerator._dispatchcCsx|jD]\}}|jj||}|jjr|jj}|j|jjsRtd|d||}|j|rr|dt| }tj |rtd||j |q W|j |j dS)Nz folded header does not end with z: z folded header contains newline: ) raw_itemsr ZfoldZverify_generated_headersrendswithr lenNEWLINE_WITHOUT_FWSPsearchrr)rr"hvZfoldedrZfolded_no_lineseprrrr/s   zGenerator._write_headerscCs|j}|dkrdSt|ts.tdt|t|jr~|jd}|dk r~t|}|d=|j |||j}|d|df|_ |j rt j d|}|j|dS)Nzstring payload expected: %scharsetzcontent-transfer-encodingz content-typez>From ) get_payload isinstancestr TypeErrortyper_payloadZ get_paramrZ set_payloadr0rfcrer=r.)rr"payloadrErrr _handle_texts"      zGenerator._handle_textc Csg}|j}|dkrg}n(t|tr2|j|dSt|tsB|g}x>|D]6}|j}|j|}|j|d|jd|j |j qHW|j }|s|j j |}|j|}|j||jdk r|jrtjd|j} n|j} |j| |j|j|jd||j|r|jj|jdx4|D],} |j|jd||j|jj| qW|j|jd|d|j|jdk r|jrtjd|j} n|j} |j| dS)NF)r#rz>From z--r)rFrGrHrlistr'rr$rappendr3Z get_boundaryrr9_make_boundaryZ set_boundarypreamblerrLr=r.rpopepilogue) rr"ZmsgtextsZsubpartspartrgboundaryZalltextrRZ body_partrTrrr_handle_multipart sJ             zGenerator._handle_multipartc Cs0|j}|jdd|_z|j|Wd||_XdS)Nr)r)r rrX)rr"prrr_handle_multipart_signedFs z"Generator._handle_multipart_signedcCsg}x|jD]t}|j}|j|}|j|d|jd|j}|j|j}|rx|d|jkrx|j |jj |ddq|j |qW|j j |jj |dS)NF)r#rr(r)r)) rFr'rr$rr3r+rrrPr9rr)rr"ZblocksrUrrVtextr,rrr_handle_message_delivery_statusQs  z)Generator._handle_message_delivery_statuscCs^|j}|j|}|j}t|trD|j|jdd|jd|j}n |j |}|j j |dS)NrF)r#r) r'rrKrGrOr$rFrr3rrr)rr"rrVrMrrr_handle_messagefs    zGenerator._handle_messagecCsztjtj}d t|d}|dkr(|S|}d}xD|jdtj|dtj}|j |sZP|dt |}|d7}q2W|S) N=z==rz^--z(--)?$.r(z===============) randomZ randrangesysmaxsize_fmt _compile_rereescape MULTILINErBrH)clsr[tokenrWbZcounterZcrerrrrQs   zGenerator._make_boundarycCs tj||S)N)rfcompile)rirflagsrrrreszGenerator._compile_re)NN)FN)N)__name__ __module__ __qualname__rrr$rr'rr.r!r1r/rNr;rXrZr\r] classmethodrQrerrrrrs(  1#:  csLeZdZddZddZddZddZfd d ZeZe d d Z Z S) rcCs|jj|jdddS)Nasciisurrogateescape)rrencode)rrrrrrszBytesGenerator.writecCstS)N)r)rrrrr'szBytesGenerator._new_buffercCs |jdS)Nrr)rt)rrrrrrszBytesGenerator._encodecCs<x*|jD]\}}|jj|jj||q W|j|jdS)N)r>rrr Z fold_binaryr)rr"rCrDrrrr/szBytesGenerator._write_headerscs^|jdkrdSt|jrJ|jjdk rJ|jrFrom ) rKrr Zcte_typerrLr=r.superrrN)rr")r%rrrNs zBytesGenerator._handle_textcCstj|jd|S)Nrr)rfrlrt)rirrmrrrreszBytesGenerator._compile_re) rnrorprr'rr/rNr;rqre __classcell__rr)r%rrs  zD[Non-text (%(type)s) part of message omitted, filename %(filename)s]c@s$eZdZdddddZddZdS)rN)r cCs.tj|||||d|dkr$t|_n||_dS)N)r )rr_FMTrd)rrr rZfmtr rrrrs  zDecodedGenerator.__init__c Csx|jD]v}|j}|dkr4t|jdd|dq |dkr>q t|j|j|j|j|jd|jdd|jd d d |dq WdS) Nr[F)decode)fileZ multipartz [no filename]zContent-Descriptionz[no description]zContent-Transfer-Encodingz [no encoding])rJmaintypesubtypefilenameZ descriptionencoding) walkr6printrFrdZget_content_typer7 get_filenameget)rr"rUrzrrrr1s  zDecodedGenerator._dispatch)NNN)rnrorprr1rrrrrsr(z%%0%dd)__all__rfrbr racopyriorrZ email.utilsrZ email.errorsr r8NLrlr*rhrLrArrrwrr@reprrcZ_widthrdrQrrrrs,      |3;header.cpython-36.opt-2.pyc000064400000025152147204636050011376 0ustar003 \&^@sdddgZddlZddlZddlZddlZddlmZddlmZ e j Z dZ dZ d Z dZd Zd Zd Ze dZe dZejdejejBejBZejdZejdZejjZddZdddZGdddZGdddZ Gddde!Z"dS)Header decode_header make_headerN)HeaderParseError)charset   Nz zus-asciizutf-8ai =\? # literal =? (?P[^?]*?) # non-greedy up to the next ? is the charset \? # literal ? (?P[qb]) # either a "q" or a "b", case insensitive \? # literal ? (?P.*?) # non-greedy up to the next ?= is the encoded string \?= # literal ?= z[\041-\176]+:$z \n[^ \t]+:c Cst|drdd|jDStj|s.|dfgSg}x|jD]}tj|}d}xp|r|jd}|rn|j}d}|r|j|ddf|rP|jdj }|jdj }|jd}|j|||fqPWqMsz!decode_header..TrFqbz===zBase64 decoding errorzUnexpected encoding: zraw-unicode-escape)hasattrr ecresearch splitlinessplitpoplstripappendlower enumerateisspacereversedemail quoprimimeZ header_decodelenZ base64mimedecodebinasciiErrorrAssertionError isinstancerbytesBSPACE)headerZwordslinepartsfirstZ unencodedrencodingZencodedZdroplistnwdZ decoded_wordsZencoded_stringZwordZpaderrZ collapsedZ last_word last_charsetrrrr=sz       4           cCsLt|||d}x8|D]0\}}|dk r8t|t r8t|}|j||qW|S)N) maxlinelen header_namecontinuation_ws)rr-Charsetr!)Z decoded_seqr9r:r;hsrrrrrs c@sJeZdZdddZddZdd Zdd d Zd d ZdddZddZ dS)rNrstrictcCs||dkrt}nt|ts t|}||_||_g|_|dk rH|j||||dkrTt}||_|dkrjd|_ nt |d|_ dS)Nrr) USASCIIr-r<r_continuation_wsr r! MAXLINELEN _maxlinelen _headerlenr()selfr>rr9r:r;errorsrrr__init__s zHeader.__init__c Cs|jg}d}d}x|jD]\}}|}|tjkrJ|jdd}|jdd}|r|o^|j|d}|dkr|dkr| r|jtd}n|d kr| r|jt|o|j|d }|}|j|qWt j |S) Nasciisurrogateescapereplacerus-asciir)NrK)NrK)NrK) _normalizer r UNKNOWN8BITencoder) _nonctextr!SPACE EMPTYSTRINGjoin) rEZuchunkslastcs lastspacerrZnextcsZoriginal_byteshasspacerrr__str__s*     zHeader.__str__cCs |t|kS)N)r)rEotherrrr__eq__sz Header.__eq__c Cs|dkr|j}nt|ts"t|}t|tsZ|jp4d}|tjkrN|jdd}n |j||}|jpbd}|tjkry|j||Wn"t k r|dkrt }YnX|j j ||fdS)Nzus-asciirI) rr-r<rZ input_codecrNr)Z output_codecrOUnicodeEncodeErrorUTF8r r!)rEr>rrFZ input_charsetZoutput_charsetrrrr! s$        z Header.appendcCs|jp|dkS)N()\)r\r]r^)r$)rEr>rrrrP4szHeader._nonctext;, rcCs|j|dkr|j}|dkr"d}t|j||j|}d}d}}x4|jD](\}} |dk r|ol|j|d}|d kr| s| d kr|jn| d kr| r|j|o|j|d }| }d}|j} | r|j d| d| n|j dd| xr| ddD]b} |j | j dk r,|j |jd| j | n.| j } | dt | t | } |j | | | qWt | dkrJ|j qJW|jr|j|j|}tj|rtdj||S) Nri@Bus-asciirFr rz8header value appears to contain an embedded header: {!r})Nr`)Nr`)Nr`rL)rMrC_ValueFormatterrDrAr rPadd_transitionrfeednewlineheader_encodingr r(_str_embedded_headerrrformat)rE splitcharsr9linesepZ formatterrTrVrUrrlinesr1ZslinefwsvaluerrrrO9sR!       z Header.encodecCs|g}d}g}xL|jD]B\}}||kr0|j|q|dk rL|jtj||f|g}|}qW|rr|jtj||f||_dS)N)r r!rQrS)rEZchunksr8Z last_chunkrrrrrrMs zHeader._normalize)NNNNrr?)Nr?)r_Nr) __name__ __module__ __qualname__rGrWrYr!rPrOrMrrrrrs -  + Pc@sTeZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ dS)racCs0||_||_t||_||_g|_t||_dS)N)_maxlenrAr(_continuation_ws_len _splitchars_lines _Accumulator _current_line)rEZ headerlenmaxlenr;rirrrrGs  z_ValueFormatter.__init__cCs|j|j|jS)N)rdrSrt)rErjrrrrfsz_ValueFormatter._strcCs |jtS)N)rfNL)rErrrrWsz_ValueFormatter.__str__cCsp|jj}|dkr|jj|t|jdkrb|jjrP|jdt|j7<n|jjt|j|jjdS)Nrr rr)rr rL) rvrpushr( is_onlywsrtrr!reset)rEZ end_of_linerrrrds   z_ValueFormatter.newlinecCs|jjdddS)Nrr )rvry)rErrrrbsz_ValueFormatter.add_transitioncCs|jdkr|j|||jdS|j||j}y|jd}Wntk rPdSX|dk rf|j||y |j}Wntk rdSX|j|j j |j |x|D]}|j j |j |qWdS)Nr)re _ascii_splitrsZheader_encode_lines _maxlengthsr IndexError _append_chunkrdrvryrArtr!)rErlrrZ encoded_linesZ first_line last_liner1rrrrcs$    z_ValueFormatter.feedccs*|jt|jVx|j|jVqWdS)N)rqr(rvrr)rErrrr}sz_ValueFormatter._maxlengthscCsjtjdtd||}|dr0dg|dd<n |jdx*tt|gdD]\}}|j||qNWdS)Nz([z]+)rr r)rerFWSrzipiterr)rErlrrir2partrrrr|s  z_ValueFormatter._ascii_splitcCs |jj||t|j|jkrx|jD]t}xlt|jjdddD]P}|jrp|j|d}|rp|d|krpP|j|dd}|rD|d|krDPqDWq(Pq(W|jj\}}|jj dkr|j |sd}|jj||dS|jj |}|j j t|j|jj|dS)NrrrrLrL)rvryr(rqrsrange part_countr$r _initial_sizerdpop_fromrtr!rr{)rErlrZchiZprevpartrZ remainderrrrrs.   z_ValueFormatter._append_chunkN) rnrorprGrfrWrdrbrcr}r|rrrrrras %racsjeZdZdfdd ZddZdddZfdd Zd d Zd d ZdddZ ddZ fddZ Z S)rurcs||_tjdS)N)rsuperrG)rEZ initial_size) __class__rrrGsz_Accumulator.__init__cCs|j||fdS)N)r!)rErlrrrrry#sz_Accumulator.pushcCs||d}g||d<|S)Nr)rErZpoppedrrrr&s  z_Accumulator.pop_fromcs|jdkrdStjS)Nrr )r r )rrr)rE)rrrr+s z_Accumulator.popcCstdd|D|jS)Ncss"|]\}}t|t|VqdS)N)r()rrlrrrr 1sz'_Accumulator.__len__..)sumr)rErrr__len__0sz_Accumulator.__len__cCstjdd|DS)Ncss |]\}}tj||fVqdS)N)rRrS)rrlrrrrr5sz'_Accumulator.__str__..)rRrS)rErrrrW4s z_Accumulator.__str__NcCs"|dkr g}||dd<d|_dS)Nr)r)rEZstartvalrrrr{8s z_Accumulator.resetcCs|jdko| pt|jS)Nr)rrr$)rErrrrz>sz_Accumulator.is_onlywscs tjS)N)rr)rE)rrrrAsz_Accumulator.part_count)r)r)N) rnrorprGryrrrrWr{rzr __classcell__rr)rrrus   ruz )NNr)#__all__rr*Zemail.quoprimimer&Zemail.base64mimeZ email.errorsrrrr<rxrQr/ZSPACE8rRrBrr@r[compileVERBOSE IGNORECASE MULTILINErZfcrergr'Z _max_appendrrrralistrurrrrs>    _ kheaderregistry.cpython-36.opt-1.pyc000064400000051350147204636050013165 0ustar003 \O@sjdZddlmZddlmZddlmZddlmZGdddZGdd d Z Gd d d e Z d d Z GdddZ Gddde ZGdddZGdddeZGdddZGdddeZGdddeZGdddeZGdddZGd d!d!ZGd"d#d#eZGd$d%d%eZGd&d'd'Zeeeeeeeeeeeeeeeeeeed(ZGd)d*d*Zd+S),a;Representing and manipulating email headers via custom objects. This module provides an implementation of the HeaderRegistry API. The implementation is designed to flexibly follow RFC5322 rules. Eventually HeaderRegistry will be a public API, but it isn't yet, and will probably change some before that happens. )MappingProxyType)utils)errors)_header_value_parserc@s^eZdZdddZeddZeddZed d Zed d Zd dZ ddZ ddZ dS)AddressNcCsl|dk rV|s|rtdtj|\}}|r:tdj|||jrJ|jd|j}|j}||_||_ ||_ dS)aCreate an object representing a full email address. An address can have a 'display_name', a 'username', and a 'domain'. In addition to specifying the username and domain separately, they may be specified together by using the addr_spec keyword *instead of* the username and domain keywords. If an addr_spec string is specified it must be properly quoted according to RFC 5322 rules; an error will be raised if it is not. An Address object has display_name, username, domain, and addr_spec attributes, all of which are read-only. The addr_spec and the string value of the object are both quoted according to RFC5322 rules, but without any Content Transfer Encoding. Nz=addrspec specified when username and/or domain also specifiedz6Invalid addr_spec; only '{}' could be parsed from '{}'r) TypeErrorparserZ get_addr_spec ValueErrorformat all_defects local_partdomain _display_name _username_domain)self display_nameusernamer addr_specZa_srestr,/usr/lib64/python3.6/email/headerregistry.py__init__s  zAddress.__init__cCs|jS)N)r)rrrrr7szAddress.display_namecCs|jS)N)r)rrrrr;szAddress.usernamecCs|jS)N)r)rrrrr?szAddress.domaincCsTt|j}t|t|tjkr.tj|j}n|j}|jrH|d|jS|sPdS|S)zThe addr_spec (username@domain) portion of the address, quoted according to RFC 5322 rules, but with no Content Transfer Encoding. @z<>)setrlenr Z DOT_ATOM_ENDS quote_stringr)rnamesetZlprrrrCs zAddress.addr_speccCsdj|jj|j|j|jS)Nz1{}(display_name={!r}, username={!r}, domain={!r}))r __class____name__rrr)rrrr__repr__SszAddress.__repr__cCs^t|j}t|t|tjkr.tj|j}n|j}|rX|jdkrFdn|j}dj||S|jS)Nz<>rz{} <{}>)rrrr SPECIALSrrr )rrdisprrrr__str__Xs  zAddress.__str__cCs8t|t|krdS|j|jko6|j|jko6|j|jkS)NF)typerrr)rotherrrr__eq__cs   zAddress.__eq__)rrrN) r __module__ __qualname__rpropertyrrrrr!r$r'rrrrrs %     rc@sFeZdZdddZeddZeddZdd Zd d Zd d Z dS)GroupNcCs||_|rt|nt|_dS)aCreate an object representing an address group. An address group consists of a display_name followed by colon and a list of addresses (see Address) terminated by a semi-colon. The Group is created by specifying a display_name and a possibly empty list of Address objects. A Group can also be used to represent a single address that is not in a group, which is convenient when manipulating lists that are a combination of Groups and individual Addresses. In this case the display_name should be set to None. In particular, the string representation of a Group whose display_name is None is the same as the Address object, if there is one and only one Address object in the addresses list. N)rtuple _addresses)rr addressesrrrrmszGroup.__init__cCs|jS)N)r)rrrrrszGroup.display_namecCs|jS)N)r-)rrrrr.szGroup.addressescCsdj|jj|j|jS)Nz${}(display_name={!r}, addresses={!r})r rr rr.)rrrrr!szGroup.__repr__cCs|jdkr&t|jdkr&t|jdS|j}|dk r\t|}t|t|tjkr\tj|}djdd|jD}|r~d|n|}dj ||S)Nrz, css|]}t|VqdS)N)str).0xrrr sz Group.__str__.. z{}:{};) rrr.r0rr r"rjoinr )rr#rZadrstrrrrr$s z Group.__str__cCs,t|t|krdS|j|jko*|j|jkS)NF)r%rr.)rr&rrrr's z Group.__eq__)NN) r r(r)rr*rr.r!r$r'rrrrr+ks     r+c@sTeZdZdZddZddZeddZedd Zd d Z e d d Z ddZ dS) BaseHeadera|Base class for message headers. Implements generic behavior and provides tools for subclasses. A subclass must define a classmethod named 'parse' that takes an unfolded value string and a dictionary as its arguments. The dictionary will contain one key, 'defects', initialized to an empty list. After the call the dictionary must contain two additional keys: parse_tree, set to the parse tree obtained from parsing the header, and 'decoded', set to the string value of the idealized representation of the data from the value. (That is, encoded words are decoded, and values that have canonical representations are so represented.) The defects key is intended to collect parsing defects, which the message parser will subsequently dispose of as appropriate. The parser should not, insofar as practical, raise any errors. Defects should be added to the list instead. The standard header parsers register defects for RFC compliance issues, for obsolete RFC syntax, and for unrecoverable parsing errors. The parse method may add additional keys to the dictionary. In this case the subclass must define an 'init' method, which will be passed the dictionary as its keyword arguments. The method should use (usually by setting them as the value of similarly named attributes) and remove all the extra keys added by its parse method, and then use super to call its parent class with the remaining arguments and keywords. The subclass should also make sure that a 'max_count' attribute is defined that is either None or 1. XXX: need to better define this API. cCs\dgi}|j||tj|dr4tj|d|d<tj||d}|d=|j|f||S)Ndefectsdecoded)parserZ_has_surrogates _sanitizer0__new__init)clsnamevaluekwdsrrrrr;s zBaseHeader.__new__cCs||_||_||_dS)N)_name _parse_tree_defects)rr> parse_treer7rrrr<szBaseHeader.initcCs|jS)N)rA)rrrrr>szBaseHeader.namecCs t|jS)N)r,rC)rrrrr7szBaseHeader.defectscCst|jj|jjt|f|jfS)N)_reconstruct_headerrr __bases__r0__dict__)rrrr __reduce__s zBaseHeader.__reduce__cCs tj||S)N)r0r;)r=r?rrr _reconstructszBaseHeader._reconstructcCs`tjtjtj|jdtjddgg}|jrH|jtjtjddg|j|j|j |dS)atFold header according to policy. The parsed representation of the header is folded according to RFC5322 rules, as modified by the policy. If the parse tree contains surrogateescaped bytes, the bytes are CTE encoded using the charset 'unknown-8bit". Any non-ASCII characters in the parse tree are CTE encoded using charset utf-8. XXX: make this a policy setting. The returned value is an ASCII-only string possibly containing linesep characters, and ending with a linesep character. The string includes the header name and the ': ' separator. z header-name:z header-sepr4Zfws)policy) r ZHeaderZ HeaderLabelZ ValueTerminalr>rBappendZCFWSListZWhiteSpaceTerminalfold)rrKheaderrrrrMs  zBaseHeader.foldN) r r(r)__doc__r;r<r*r>r7rH classmethodrIrMrrrrr6s     r6cCst||ij|S)N)r%rI)Zcls_namebasesr?rrrrEsrEc@s&eZdZdZeejZeddZ dS)UnstructuredHeaderNcCs"|j||d<t|d|d<dS)NrDr8) value_parserr0)r=r?r@rrrr9szUnstructuredHeader.parse) r r(r) max_count staticmethodr get_unstructuredrSrPr9rrrrrR s rRc@seZdZdZdS)UniqueUnstructuredHeaderr/N)r r(r)rTrrrrrWsrWcsFeZdZdZdZeejZe ddZ fddZ e ddZ ZS) DateHeaderaHeader whose value consists of a single timestamp. Provides an additional attribute, datetime, which is either an aware datetime using a timezone, or a naive datetime if the timezone in the input string is -0000. Also accepts a datetime as input. The 'value' attribute is the normalized form of the timestamp, which means it is the output of format_datetime on the datetime. NcCsz|s6|djtjd|d<d|d<tj|d<dSt|trJtj|}||d<tj |d|d<|j |d|d<dS)Nr7datetimerr8rD) rLrZHeaderMissingRequiredValuer Z TokenList isinstancer0rZparsedate_to_datetimeZformat_datetimerS)r=r?r@rrrr9)s   zDateHeader.parsecs|jd|_tj||dS)NrY)pop _datetimesuperr<)rargskw)rrrr<7s zDateHeader.initcCs|jS)N)r\)rrrrrY;szDateHeader.datetime)r r(r)rOrTrUr rVrSrPr9r<r*rY __classcell__rr)rrrXs     rXc@seZdZdZdS)UniqueDateHeaderr/N)r r(r)rTrrrrra@sracsPeZdZdZeddZeddZfddZe dd Z e d d Z Z S) AddressHeaderNcCstj|\}}|S)N)r Zget_address_list)r? address_listrrrrSIszAddressHeader.value_parsercCst|trZ|j||d<}g}x,|jD]"}|jt|jdd|jDq(Wt|j }n"t |dsj|g}dd|D}g}||d<||d<dj d d|D|d <d|kr|j|d |d<dS) NrDcSs*g|]"}t|jpd|jpd|jp"dqS)r)rrr r)r1Zmbrrr Xsz'AddressHeader.parse..__iter__cSs&g|]}t|dstd|gn|qS)r.N)hasattrr+)r1itemrrrrdasgroupsr7z, cSsg|] }t|qSr)r0)r1rgrrrrdgsr8) rZr0rSr.rLr+rZ all_mailboxeslistr rfr5)r=r?r@rcrhZaddrr7rrrr9Os$     zAddressHeader.parsecs(t|jd|_d|_tj||dS)Nrh)r,r[_groupsr-r]r<)rr^r_)rrrr<kszAddressHeader.initcCs|jS)N)rj)rrrrrhpszAddressHeader.groupscCs&|jdkr tdd|jD|_|jS)NcSsg|]}|jD]}|qqSr)r.)r1groupaddressrrrrdwsz+AddressHeader.addresses..)r-r,rj)rrrrr.ts zAddressHeader.addresses) r r(r)rTrUrSrPr9r<r*rhr.r`rr)rrrbEs     rbc@seZdZdZdS)UniqueAddressHeaderr/N)r r(r)rTrrrrrm|srmc@seZdZeddZdS)SingleAddressHeadercCs(t|jdkrtdj|j|jdS)Nr/z9value of single address header {} is not a single addressr)rr.r r r>)rrrrrls zSingleAddressHeader.addressN)r r(r)r*rlrrrrrnsrnc@seZdZdZdS)UniqueSingleAddressHeaderr/N)r r(r)rTrrrrrosrocsZeZdZdZeejZeddZ fddZ e ddZ e dd Z e d d ZZS) MIMEVersionHeaderr/cCs|j||d<}t||d<|dj|j|jdkrr?rrr sz1ParameterizedMIMEHeader.parse..)rSr0rtr ry)r=r?r@rDrrrr9s   zParameterizedMIMEHeader.parsecs|jd|_tj||dS)Nry)r[_paramsr]r<)rr^r_)rrrr<s zParameterizedMIMEHeader.initcCs t|jS)N)rr|)rrrrryszParameterizedMIMEHeader.params) r r(r)rTrPr9r<r*ryr`rr)rrrxs rxcsJeZdZeejZfddZeddZ eddZ eddZ Z S) ContentTypeHeadercs2tj||tj|jj|_tj|jj|_dS)N) r]r<rr:rBmaintype _maintypesubtype_subtype)rr^r_)rrrr<szContentTypeHeader.initcCs|jS)N)r)rrrrr~szContentTypeHeader.maintypecCs|jS)N)r)rrrrrszContentTypeHeader.subtypecCs|jd|jS)N/)r~r)rrrr content_typeszContentTypeHeader.content_type) r r(r)rUr Zparse_content_type_headerrSr<r*r~rrr`rr)rrr}s     r}cs2eZdZeejZfddZeddZ Z S)ContentDispositionHeadercs2tj|||jj}|dkr"|ntj||_dS)N)r]r<rBcontent_dispositionrr:_content_disposition)rr^r_Zcd)rrrr<szContentDispositionHeader.initcCs|jS)N)r)rrrrrsz,ContentDispositionHeader.content_disposition) r r(r)rUr Z parse_content_disposition_headerrSr<r*rr`rr)rrrs  rcsBeZdZdZeejZeddZ fddZ e ddZ Z S)ContentTransferEncodingHeaderr/cCs2|j||d<}t||d<|dj|jdS)NrDr8r7)rSr0rtr )r=r?r@rDrrrr9s z#ContentTransferEncodingHeader.parsecs"tj||tj|jj|_dS)N)r]r<rr:rBcte_cte)rr^r_)rrrr<sz"ContentTransferEncodingHeader.initcCs|jS)N)r)rrrrrsz!ContentTransferEncodingHeader.cte)r r(r)rTrUr Z&parse_content_transfer_encoding_headerrSrPr9r<r*rr`rr)rrrs    r)ZsubjectZdatez resent-datez orig-dateZsenderz resent-senderZtoz resent-toZccz resent-ccZbccz resent-bccfromz resent-fromzreply-toz mime-versionz content-typezcontent-dispositionzcontent-transfer-encodingc@s8eZdZdZeedfddZddZddZd d Z d S) HeaderRegistryz%A header_factory and header registry.TcCs&i|_||_||_|r"|jjtdS)aCreate a header_factory that works with the Policy API. base_class is the class that will be the last class in the created header class's __bases__ list. default_class is the class that will be used if "name" (see __call__) does not appear in the registry. use_default_map controls whether or not the default mapping of names to specialized classes is copied in to the registry when the factory is created. The default is True. N)registry base_class default_classupdate_default_header_map)rrrZuse_default_maprrrr's zHeaderRegistry.__init__cCs||j|j<dS)zLRegister cls as the specialized class for handling "name" headers. N)rrz)rr>r=rrr map_to_type9szHeaderRegistry.map_to_typecCs,|jj|j|j}td|j||jfiS)N_)rgetrzrr%r r)rr>r=rrr __getitem__?szHeaderRegistry.__getitem__cCs||||S)aCreate a header instance for header 'name' from 'value'. Creates a header instance by creating a specialized class for parsing and representing the specified header by combining the factory base_class with a specialized class from the registry or the default_class, and passing the name and value to the constructed class's constructor. r)rr>r?rrr__call__Cs zHeaderRegistry.__call__N) r r(r)rOr6rRrrrrrrrrr#s  rN)rOtypesrZemailrrrr rr+r0r6rErRrWrXrarbrmrnrorprxr}rrrrrrrr sR    [6d '7 %iterators.cpython-36.opt-2.pyc000064400000002412147204636050012154 0ustar003 \W@sHdddgZddlZddlmZddZd ddZdd dZdd d ZdS)body_line_iteratortyped_subpart_iteratorwalkN)StringIOccs2|V|jr.x|jD]}|jEdHqWdS)N) is_multipart get_payloadr)selfsubpartr '/usr/lib64/python3.6/email/iterators.pyrsFccs:x4|jD](}|j|d}t|tr t|EdHq WdS)N)decode)rr isinstancestrr)msgr r Zpayloadr r r r"s  textccs<x6|jD]*}|j|kr |dks.|j|kr |Vq WdS)N)rZget_content_maintypeZget_content_subtype)rZmaintypesubtyper r r r r-s cCs|dkrtj}d|d}t||jd|d|rJtd|j|dn t|d|jrx"|jD]}t|||d|qfWdS)N )endfilez [%s])r)sysstdoutprintZget_content_typeZget_default_typerr _structure)rfplevelZinclude_defaultZtabr r r r r;s  r)F)rN)NrF)__all__riorrrrrr r r r s  message.cpython-36.opt-1.pyc000064400000112152147204636050011566 0ustar003 \@sdZddgZddlZddlZddlZddlmZmZddlm Z ddlm Z ddl m Z m Z dd lmZdd lmZejZd Zejd Zd dZdddZddZddZGdddZGdddeZGdddeZdS)z8Basic message object for the email package object model.Message EmailMessageN)BytesIOStringIO)utils)errors)Policycompat32)charset)decode_bz; z[ \(\)<>@,;:\\"/\[\]\?=]cCs4t|jd\}}}|s$|jdfS|j|jfS)N;)str partitionstrip)paramasepbr%/usr/lib64/python3.6/email/message.py _splitparams rTc Cs|dk rt|dkrt|trL|d7}tj|d|d|d}d||fSy|jdWn2tk r|d7}tj|dd }d||fSX|stj|rd |tj |fSd||fSn|SdS) a~Convenience function to format and return a key=value pair. This will quote the value if needed or if quote is true. If value is a three tuple (charset, language, value), it will be encoded according to RFC2231 rules. If it contains non-ascii characters it will likewise be encoded according to RFC2231 rules, using the utf-8 charset and a null language. Nr*z%s=%sasciizutf-8z%s="%s") len isinstancetuplerZencode_rfc2231encodeUnicodeEncodeError tspecialssearchquote)rvaluer#rrr _formatparam's   r%cCsdt|}g}x|dddkr|dd}|jd}x<|dkrt|jdd||jdd|drt|jd|d}q:W|dkrt|}|d|}d|kr|jd}|d|jjd||ddj}|j|j||d}qW|S)Nr rr"z\"r=)r findcountrindexrlowerappend)sZplistendfirrr _parseparamIs    *  ,r1cCs4t|tr&|d|dtj|dfStj|SdS)Nrrr)rrrunquote)r$rrr _unquotevalue]s r3c@seZdZdZefddZddZddd d Zd d Zded dZ ddZ ddZ ddZ ddZ dfddZdgddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+d,Zd-d.Zd/d0Zdhd1d2Zd3d4Zd5d6Zdid7d8Zd9d:Zd;d<Z d=d>Z!d?d@Z"dAdBZ#dCdDZ$dEdFZ%dGdHZ&djdKdLZ'dkdMdNZ(dldQdRZ)dmdSdTZ*dndUdVZ+dodWdXZ,dpdYdZZ-d[d\Z.dqd]d^Z/drd_d`Z0dadbZ1ddcl2m3Z3dS)sraBasic message object. A message object is defined as something that has a bunch of RFC 2822 headers and a payload. It may optionally have an envelope header (a.k.a. Unix-From or From_ header). If the message is a container (i.e. a multipart or a message/rfc822), then the payload is a list of Message objects, otherwise it is a string. Message objects implement part of the `mapping' interface, which assumes there is exactly one occurrence of the header per message. Some headers do in fact appear multiple times (e.g. Received) and for those headers, you must use the explicit API to set or get all the headers. Not all of the mapping methods are implemented. cCs:||_g|_d|_d|_d|_d|_|_g|_d|_dS)Nz text/plain) policy_headers _unixfrom_payload_charsetZpreambleZepiloguedefects _default_type)selfr4rrr__init__xs zMessage.__init__cCs|jS)z9Return the entire formatted message as a string. ) as_string)r;rrr__str__szMessage.__str__FrNcCsJddlm}|dkr|jn|}t}||d||d}|j||d|jS)aReturn the entire formatted message as a string. Optional 'unixfrom', when true, means include the Unix From_ envelope header. For backward compatibility reasons, if maxheaderlen is not specified it defaults to 0, so you must override it explicitly if you want a different maxheaderlen. 'policy' is passed to the Generator instance used to serialize the mesasge; if it is not specified the policy associated with the message instance is used. If the message object contains binary data that is not encoded according to RFC standards, the non-compliant data will be replaced by unicode "unknown character" code points. r) GeneratorNF) mangle_from_ maxheaderlenr4)unixfrom)email.generatorr?r4rflattengetvalue)r;rBrAr4r?fpgrrrr=s zMessage.as_stringcCs|jS)z?Return the entire formatted message as a bytes object. )as_bytes)r;rrr __bytes__szMessage.__bytes__cCsHddlm}|dkr|jn|}t}||d|d}|j||d|jS)aJReturn the entire formatted message as a bytes object. Optional 'unixfrom', when true, means include the Unix From_ envelope header. 'policy' is passed to the BytesGenerator instance used to serialize the message; if not specified the policy associated with the message instance is used. r)BytesGeneratorNF)r@r4)rB)rCrJr4rrDrE)r;rBr4rJrFrGrrrrHs  zMessage.as_bytescCs t|jtS)z6Return True if the message consists of multiple parts.)rr7list)r;rrr is_multipartszMessage.is_multipartcCs ||_dS)N)r6)r;rBrrr set_unixfromszMessage.set_unixfromcCs|jS)N)r6)r;rrr get_unixfromszMessage.get_unixfromc CsF|jdkr|g|_n.y|jj|Wntk r@tdYnXdS)zAdd the given payload to the current payload. The current payload will always be a list of objects after this method is called. If you want to set the payload to a scalar object, use set_payload() instead. Nz=Attach is not valid on a message with a non-multipart payload)r7r,AttributeError TypeError)r;payloadrrrattachs   zMessage.attachc Cs|jr(|rdS|dkr|jS|j|S|dk rPt|jt rPtdt|j|j}t|jddj}t|trt j |r|j dd}|sy|j |j ddd}Wn tk r|j dd}YnXn6|ry|j d}Wn tk r|j d }YnX|s |S|d kr tj|S|d krbtd j|j\}}x|D]}|jj||qFW|S|dkrt|} t} ytj | | dd| jStjk r|SXt|tr|S|S)aZReturn a reference to the payload. The payload will either be a list object or a string. If you mutate the list object, you modify the message's payload in place. Optional i returns that index into the payload. Optional decode is a flag indicating whether the payload should be decoded or not, according to the Content-Transfer-Encoding header (default is False). When True and the message is not a multipart, the payload will be decoded if this header's value is `quoted-printable' or `base64'. If some other encoding is used, or the header is missing, or if the payload has bogus data (i.e. bogus base64 or uuencoded data), the payload is returned as-is. If the message is a multipart and the decode flag is True, then None is returned. NzExpected list, got %szcontent-transfer-encodingrrsurrogateescaper replacezraw-unicode-escapezquoted-printablebase64 x-uuencodeuuencodeuuex-uueT)quiet)rWrXrYrZ)rLr7rrKrPtyper getr+rZ_has_surrogatesrdecode get_param LookupError UnicodeErrorquopriZ decodestringr join splitlinesr4Z handle_defectruurEError) r;r0r^rQcteZbpayloadr$r9ZdefectZin_fileZout_filerrr get_payloadsV"          zMessage.get_payloadcCspt|dr:|dkr||_dSt|ts.t|}|j|j}t|drT|jdd|_n||_|dk rl|j|dS)zSet the payload to the given value. Optional charset sets the message's default character set. See set_charset() for details. rNr^rrS)hasattrr7rCharsetroutput_charsetr^ set_charset)r;rQr rrr set_payload/s    zMessage.set_payloadcCs|dkr|jdd|_dSt|ts.t|}||_d|krH|jddd|krf|jdd|jdn|jd|j||jkr|j|j|_d|kr|j }y ||Wnjt k r|j}|ry|j d d }Wn t k r|j |j }YnX|j||_|jd|YnXdS) aSet the charset of the payload to a given character set. charset can be a Charset instance, a string naming a character set, or None. If it is a string it will be converted to a Charset instance. If charset is None, the charset parameter will be removed from the Content-Type field. Anything else will generate a TypeError. The message will be assumed to be of type text/* encoded with charset.input_charset. It will be converted to charset.output_charset and encoded properly, if needed, when generating the plain text representation of the message. MIME headers (MIME-Version, Content-Type, Content-Transfer-Encoding) will be added as needed. Nr z MIME-Versionz1.0z Content-Typez text/plain)r zContent-Transfer-EncodingrrS) del_paramr8rrj add_headerZget_output_charset set_paramZ body_encoder7Zget_body_encodingrPrrark)r;r rgrQrrrrlCs8       zMessage.set_charsetcCs|jS)zKReturn the Charset instance associated with the message's payload. )r8)r;rrr get_charsetrszMessage.get_charsetcCs t|jS)z9Return the total number of headers, including duplicates.)rr5)r;rrr__len__zszMessage.__len__cCs |j|S)a-Get a header value. Return None if the header is missing instead of raising an exception. Note that if the header appeared multiple times, exactly which occurrence gets returned is undefined. Use get_all() to get all the values matching a header field name. )r])r;namerrr __getitem__~s zMessage.__getitem__cCsv|jj|}|r\|j}d}x>|jD]4\}}|j|kr$|d7}||kr$tdj||q$W|jj|jj||dS)zSet the value of a header. Note: this does not overwrite an existing header with the same field name. Use __delitem__() first to delete any existing headers. rrz/There may be at most {} {} headers in a messageN)r4Zheader_max_countr+r5 ValueErrorformatr,header_store_parse)r;rsvalZ max_countZlnamefoundkvrrr __setitem__s  zMessage.__setitem__cCsD|j}g}x,|jD]"\}}|j|kr|j||fqW||_dS)zwDelete all occurrences of a header, if present. Does not raise an exception if the header is missing. N)r+r5r,)r;rs newheadersrzr{rrr __delitem__s  zMessage.__delitem__cCs|jdd|jDkS)NcSsg|]\}}|jqSr)r+).0rzr{rrr sz(Message.__contains__..)r+r5)r;rsrrr __contains__szMessage.__contains__ccsx|jD]\}}|VqWdS)N)r5)r;Zfieldr$rrr__iter__szMessage.__iter__cCsdd|jDS)a.Return a list of all the message's header field names. These will be sorted in the order they appeared in the original message, or were added to the message, and may contain duplicates. Any fields deleted and re-inserted are always appended to the header list. cSsg|] \}}|qSrr)rrzr{rrrrsz Message.keys..)r5)r;rrrkeyssz Message.keyscsfddjDS)a)Return a list of all the message's header values. These will be sorted in the order they appeared in the original message, or were added to the message, and may contain duplicates. Any fields deleted and re-inserted are always appended to the header list. csg|]\}}jj||qSr)r4header_fetch_parse)rrzr{)r;rrrsz"Message.values..)r5)r;r)r;rvaluess zMessage.valuescsfddjDS)a'Get all the message's header fields and values. These will be sorted in the order they appeared in the original message, or were added to the message, and may contain duplicates. Any fields deleted and re-inserted are always appended to the header list. cs"g|]\}}|jj||fqSr)r4r)rrzr{)r;rrrsz!Message.items..)r5)r;r)r;ritemss z Message.itemscCs:|j}x,|jD]"\}}|j|kr|jj||SqW|S)z~Get a header value. Like __getitem__() but return failobj instead of None when the field is missing. )r+r5r4r)r;rsfailobjrzr{rrrr]s  z Message.getcCs|jj||fdS)zStore name and value in the model without modification. This is an "internal" API, intended only for use by a parser. N)r5r,)r;rsr$rrrset_rawszMessage.set_rawcCst|jjS)zReturn the (name, value) header pairs without modification. This is an "internal" API, intended only for use by a generator. )iterr5copy)r;rrr raw_itemsszMessage.raw_itemscCsLg}|j}x2|jD](\}}|j|kr|j|jj||qW|sH|S|S)aQReturn a list of all the values for the named field. These will be sorted in the order they appeared in the original message, and may contain duplicates. Any fields deleted and re-inserted are always appended to the header list. If no such fields exist, failobj is returned (defaults to None). )r+r5r,r4r)r;rsrrrzr{rrrget_alls  zMessage.get_allcKstg}xH|jD]<\}}|dkr2|j|jddq|jt|jdd|qW|dk rb|jd|tj|||<dS)uExtended header setting. name is the header field to add. keyword arguments can be used to set additional parameters for the header field, with underscores converted to dashes. Normally the parameter will be added as key="value" unless value is None, in which case only the key will be added. If a parameter value contains non-ASCII characters it can be specified as a three-tuple of (charset, language, value), in which case it will be encoded according to RFC2231 rules. Otherwise it will be encoded using the utf-8 charset and a language of ''. Examples: msg.add_header('content-disposition', 'attachment', filename='bud.gif') msg.add_header('content-disposition', 'attachment', filename=('utf-8', '', Fußballer.ppt')) msg.add_header('content-disposition', 'attachment', filename='Fußballer.ppt')) N_-r)rr,rTr%insert SEMISPACErc)r;_name_valueZ_paramspartsrzr{rrrros zMessage.add_headercCs^|j}xPttt|j|jD].\}\}}|j|kr |jj|||j|<Pq Wt|dS)zReplace a header. Replace the first matching header found in the message, retaining header order and case. If no matching header was found, a KeyError is raised. N)r+ziprangerr5r4rwKeyError)r;rrr0rzr{rrrreplace_header!s $ zMessage.replace_headercCsHt}|jd|}||kr"|jSt|dj}|jddkrDdS|S)a0Return the message's content type. The returned string is coerced to lower case of the form `maintype/subtype'. If there was no Content-Type header in the message, the default type as given by get_default_type() will be returned. Since according to RFC 2045, messages always have a default type this will always return a value. RFC 2045 defines a message's default type to be text/plain unless it appears inside a multipart/digest container, in which case it would be message/rfc822. z content-typer/rz text/plain)objectr]get_default_typerr+r))r;missingr$ctyperrrget_content_type4s  zMessage.get_content_typecCs|j}|jddS)zReturn the message's main content type. This is the `maintype' part of the string returned by get_content_type(). rr)rsplit)r;rrrrget_content_maintypeLszMessage.get_content_maintypecCs|j}|jddS)zReturns the message's sub-content type. This is the `subtype' part of the string returned by get_content_type(). rr)rr)r;rrrrget_content_subtypeUszMessage.get_content_subtypecCs|jS)aReturn the `default' content type. Most messages have a default content type of text/plain, except for messages that are subparts of multipart/digest containers. Such subparts have a default content type of message/rfc822. )r:)r;rrrr^szMessage.get_default_typecCs ||_dS)zSet the `default' content type. ctype should be either "text/plain" or "message/rfc822", although this is not enforced. The default content type is not stored in the Content-Type header. N)r:)r;rrrrset_default_typegszMessage.set_default_typec Cst}|j||}||kr|Sg}xdt|D]X}y$|jdd\}}|j}|j}Wn tk rt|j}d}YnX|j||fq,Wtj|}|S)Nr'rr) rr]r1rrrur,rZ decode_params) r;rheaderrr$paramsprsrxrrr_get_params_preserveps     zMessage._get_params_preserve content-typeTcCs8t}|j||}||kr|S|r0dd|DS|SdS)amReturn the message's Content-Type parameters, as a list. The elements of the returned list are 2-tuples of key/value pairs, as split on the `=' sign. The left hand side of the `=' is the key, while the right hand side is the value. If there is no `=' sign in the parameter the value is the empty string. The value is as described in the get_param() method. Optional failobj is the object to return if there is no Content-Type header. Optional header is the header to search instead of Content-Type. If unquote is True, the value is unquoted. cSsg|]\}}|t|fqSr)r3)rrzr{rrrrsz&Message.get_params..N)rr)r;rrr2rrrrr get_paramss  zMessage.get_paramscCsJ||kr |Sx8|j||D](\}}|j|jkr|r>t|S|SqW|S)aReturn the parameter value if found in the Content-Type header. Optional failobj is the object to return if there is no Content-Type header, or the Content-Type header has no such parameter. Optional header is the header to search instead of Content-Type. Parameter keys are always compared case insensitively. The return value can either be a string, or a 3-tuple if the parameter was RFC 2231 encoded. When it's a 3-tuple, the elements of the value are of the form (CHARSET, LANGUAGE, VALUE). Note that both CHARSET and LANGUAGE can be None, in which case you should consider VALUE to be encoded in the us-ascii charset. You can usually ignore LANGUAGE. The parameter value (either the returned string, or the VALUE item in the 3-tuple) is always unquoted, unless unquote is set to False. If your application doesn't care whether the parameter was RFC 2231 encoded, it can turn the return value into a string as follows: rawparam = msg.get_param('foo') param = email.utils.collapse_rfc2231_value(rawparam) )rr+r3)r;rrrr2rzr{rrrr_szMessage.get_param Content-Typerc Cst|t r|r|||f}||kr4|jdkr4d}n |j|}|j||dsv|s^t|||}qtj|t|||g}nfd}x`|j||dD]N\} } d} | j|jkrt|||} n t| | |} |s| }qtj|| g}qW||j|kr|r|j ||n||=|||<dS)aSet a parameter in the Content-Type header. If the parameter already exists in the header, its value will be replaced with the new value. If header is Content-Type and has not yet been defined for this message, it will be set to "text/plain" and the new parameter and value will be appended as per RFC 2045. An alternate header can be specified in the header argument, and all parameters will be quoted as necessary unless requote is False. If charset is specified, the parameter will be encoded according to RFC 2231. Optional language specifies the RFC 2231 language, defaulting to the empty string. Both charset and language should be strings. z content-typez text/plain)rr)rr2N) rrr+r]r_r%rrcrr) r;rr$rrequoter ZlanguagerTrZ old_paramZ old_valueZ append_paramrrrrps2   zMessage.set_paramcCs||kr dSd}xR|j||dD]@\}}|j|jkr |sJt|||}q tj|t|||g}q W||j|kr||=|||<dS)a>Remove the given parameter completely from the Content-Type header. The header will be re-written in place without the parameter or its value. All values will be quoted as necessary unless requote is False. Optional header specifies an alternative to the Content-Type header. Nr)rr2)rr+r%rrcr])r;rrrZ new_ctyperr{rrrrnszMessage.del_paramcCs|jddkst|jdkr,|d=d|d<||kr@|||<dS|j||d}||=|||<x(|ddD]\}}|j||||qjWdS) aKSet the main type and subtype for the Content-Type header. type must be a string in the form "maintype/subtype", otherwise a ValueError is raised. This method replaces the Content-Type header, keeping all the parameters in place. If requote is False, this leaves the existing header's quoting as is. Otherwise, the parameters will be quoted (the default). An alternative header can be specified in the header argument. When the Content-Type header is set, we'll always also add a MIME-Version header. rrz content-typez mime-versionz1.0z MIME-VersionN)rr2)r)rur+rrp)r;r\rrrrr{rrrset_types zMessage.set_typecCsDt}|jd|d}||kr*|jd|d}||kr6|Stj|jS)a@Return the filename associated with the payload if present. The filename is extracted from the Content-Disposition header's `filename' parameter, and it is unquoted. If that header is missing the `filename' parameter, this method falls back to looking for the `name' parameter. filenamezcontent-dispositionrsz content-type)rr_rcollapse_rfc2231_valuer)r;rrrrrr get_filename&szMessage.get_filenamecCs,t}|jd|}||kr|Stj|jS)zReturn the boundary associated with the payload if present. The boundary is extracted from the Content-Type header's `boundary' parameter, and it is unquoted. boundary)rr_rrrstrip)r;rrrrrr get_boundary6s  zMessage.get_boundarycCs t}|j|d}||kr$tjdg}d}xB|D]:\}}|jdkr^|jdd|fd}q2|j||fq2W|s|jdd|fg}x|jD]\} } | jdkrg} x6|D].\} } | dkr| j| q| jd| | fqWtj| } |j|j j | | q|j| | fqW||_d S) aSet the boundary parameter in Content-Type to 'boundary'. This is subtly different than deleting the Content-Type header and adding a new one with a new boundary parameter via add_header(). The main difference is that using the set_boundary() method preserves the order of the Content-Type header in the original message. HeaderParseError is raised if the message has no Content-Type header. z content-typezNo Content-Type header foundFrz"%s"Trz%s=%sN) rrrZHeaderParseErrorr+r,r5rrcr4rw)r;rrrZ newparamsZfoundpZpkZpvr}hr{rrzrxrrr set_boundaryCs2      zMessage.set_boundarycCst}|jd|}||kr|St|trr|dp2d}y|djd}t||}Wn ttfk rp|d}YnXy|jdWntk r|SX|jS)zReturn the charset parameter of the Content-Type header. The returned string is always coerced to lower case. If there is no Content-Type header, or if that header has no charset parameter, failobj is returned. r rzus-asciirzraw-unicode-escape) rr_rrrr r`rar+)r;rrr ZpcharsetrHrrrget_content_charsetqs    zMessage.get_content_charsetcsfdd|jDS)aReturn a list containing the charset(s) used in this message. The returned list of items describes the Content-Type headers' charset parameter for this message and all the subparts in its payload. Each item will either be a string (the value of the charset parameter in the Content-Type header of that part) or the value of the 'failobj' parameter (defaults to None), if the part does not have a main MIME type of "text", or the charset is not defined. The list will contain one string for each part of the message, plus one for the container message (i.e. self), so that a non-multipart message will still return a list of length 1. csg|]}|jqSr)r)rpart)rrrrsz(Message.get_charsets..)walk)r;rr)rr get_charsetsszMessage.get_charsetscCs*|jd}|dkrdSt|dj}|S)zReturn the message's content-disposition if it exists, or None. The return values can be either 'inline', 'attachment' or None according to the rfc2183. zcontent-dispositionNr)r]rr+)r;r$c_drrrget_content_dispositions  zMessage.get_content_disposition)r)FrN)FN)NF)N)N)N)NrT)NrT)rTNrF)rT)rT)N)N)N)N)4__name__ __module__ __qualname____doc__r r<r>r=rIrHrLrMrNrRrhrmrlrqrrrtr|r~rrrrrr]rrrrorrrrrrrrr_rprnrrrrrrrZemail.iteratorsrrrrrrisb    Z /            ! 2   .   cseZdZd3ddZd4fdd ZddZd d Zd d Zd6ddZd7d8d9d:hZ ddZ ddZ ddddZ ddddZ ddZd;d d!ZdMIMEPartNcCs(|dkrddlm}|}tj||dS)Nr)default)Z email.policyrrr<)r;r4rrrrr<s zMIMEPart.__init__Fcs0|dkr|jn|}|dkr |j}tj||dS)aReturn the entire formatted message as a string. Optional 'unixfrom', when true, means include the Unix From_ envelope header. maxheaderlen is retained for backward compatibility with the base Message class, but defaults to None, meaning that the policy value for max_line_length controls the header maximum length. 'policy' is passed to the Generator instance used to serialize the mesasge; if it is not specified the policy associated with the message instance is used. N)rAr4)r4Zmax_line_lengthsuperr=)r;rBrAr4) __class__rrr=s zMIMEPart.as_stringcCs|j|jjdddS)NT)utf8)r4)r=r4Zclone)r;rrrr>szMIMEPart.__str__cCs |jd}|dkrdS|jdkS)Nzcontent-dispositionF attachment)r]Zcontent_disposition)r;rrrr is_attachments zMIMEPart.is_attachmentc cs |jr dS|jjd\}}|dkrB||kr>|j||fVdS|dkrNdS|dkr~x"|jD]}|j||EdHq`WdSd|kr|jd|fVd}|jd}|rx"|jD]}|d|kr|}PqW|dkr|j}|r|dnd}|dk r|j||EdHdS)Nrtext multipartrelatedstartz content-idr)rrrr* iter_parts _find_bodyr_rh) r;rpreferencelistmaintypesubtypeZsubpart candidaterZsubpartsrrrrs6   zMIMEPart._find_bodyrhtmlplaincCsDt|}d}x2|j||D]"\}}||kr|}|}|dkrPqW|S)aReturn best candidate mime part for display as 'body' of message. Do a depth first search, starting with self, looking for the first part matching each of the items in preferencelist, and return the part corresponding to the first item that has a match, or None if no items have a match. If 'related' is not included in preferencelist, consider the root part of any multipart/related encountered as a candidate match. Ignore parts with 'Content-Disposition: attachment'. Nr)rr)r;rZ best_prioZbodyZpriorrrrget_bodys zMIMEPart.get_bodyrr alternativec cs|jjd\}}|dks"|dkr&dS|jj}|dkr|dkr|jd}|rd}g}x*|D]"}|jd|krvd }q^|j|q^W|r|EdHdS|jd |EdHdSg}xP|D]H}|jjd\}}||f|jkr|j r||kr|j|q|VqWdS) aReturn an iterator over the non-main parts of a multipart. Skip the first of each occurrence of text/plain, text/html, multipart/related, or multipart/alternative in the multipart (unless they have a 'Content-Disposition: attachment' header) and include all remaining subparts in the returned iterator. When applied to a multipart/related, return all parts except the root part. Return an empty iterator when applied to a multipart/alternative or a non-multipart. rrrNrrFz content-idTr) rrrhrr_r]r,pop _body_typesr) r;rrrrryZ attachmentsrseenrrriter_attachmentss6         zMIMEPart.iter_attachmentsccs|jdkr|jEdHdS)z~Return an iterator over all immediate subparts of a multipart. Return an empty iterator for a non-multipart. rN)rrh)r;rrrr4s zMIMEPart.iter_parts)content_managercOs"|dkr|jj}|j|f||S)N)r4r get_content)r;rargskwrrrr<szMIMEPart.get_contentcOs&|dkr|jj}|j|f||dS)N)r4r set_content)r;rrrrrrrAszMIMEPart.set_contentc Cs|jdkr6|j}||f}||kr6tdj||g}g}x>|jD]4\}}|jjdrl|j||fqF|j||fqFW|rt||j d} || _|j | _ | g|_ ng|_ ||_d||d<|dk r|j d|dS)NrzCannot convert {} to {}zcontent-)r4z multipart/z Content-Typer) rrrurvr5r+ startswithr,r\r4r7rp) r;rZdisallowed_subtypesrZexisting_subtypeZ keep_headersZ part_headersrsr$rrrr_make_multipartFs,     zMIMEPart._make_multipartcCs|jdd|dS)Nrrmixed)rr)r)r;rrrr make_relatedaszMIMEPart.make_relatedcCs|jdd|dS)Nrr)r)r)r;rrrrmake_alternativedszMIMEPart.make_alternativecCs|jdf|dS)Nr)r)r;rrrr make_mixedgszMIMEPart.make_mixed)_dispcOsf|jdks|j|kr(t|d|t||jd}|j|||rXd|krX||d<|j|dS)NrZmake_)r4zcontent-dispositionzContent-Disposition)rrgetattrr\r4rrR)r;Z_subtyperrrrrrr_add_multipartjs    zMIMEPart._add_multipartcOs|jd|ddi|dS)NrrZinline)r)r)r;rrrrr add_relatedtszMIMEPart.add_relatedcOs|jd||dS)Nr)r)r)r;rrrrradd_alternativewszMIMEPart.add_alternativecOs|jd|ddi|dS)Nrrr)r)r)r;rrrrradd_attachmentzszMIMEPart.add_attachmentcCsg|_d|_dS)N)r5r7)r;rrrclear}szMIMEPart.clearcCsdd|jD|_d|_dS)NcSs&g|]\}}|jjds||fqS)zcontent-)r+r)rnr{rrrrsz*MIMEPart.clear_content..)r5r7)r;rrr clear_contentszMIMEPart.clear_content)N)FNNrrr)r)rr)rr)rr)rr)N)N)N)rrrr<r=r>rrrrrrrrrrrrrrrrrr __classcell__rr)rrrs0  .    rcseZdZfddZZS)rcs"tj||d|krd|d<dS)Nz MIME-Versionz1.0)rr)r;rr)rrrrszEmailMessage.set_content)rrrrrrr)rrrs)NT)r__all__rererbiorrZemailrrZemail._policybaserr r r8Zemail._encoded_wordsr rjrcompiler!rr%r1r3rrrrrrrs6      " NWmessage.cpython-36.opt-2.pyc000064400000051632147204636050011574 0ustar003 \@sddgZddlZddlZddlZddlmZmZddlmZddlm Z ddl m Z m Z ddlm Zdd lmZejZd Zejd Zd d ZdddZddZddZGdddZGdddeZGdddeZdS)Message EmailMessageN)BytesIOStringIO)utils)errors)Policycompat32)charset)decode_bz; z[ \(\)<>@,;:\\"/\[\]\?=]cCs4t|jd\}}}|s$|jdfS|j|jfS)N;)str partitionstrip)paramasepbr%/usr/lib64/python3.6/email/message.py _splitparams rTc Cs|dk rt|dkrt|trL|d7}tj|d|d|d}d||fSy|jdWn2tk r|d7}tj|dd}d||fSX|stj|rd |tj |fSd||fSn|SdS) Nr*z%s=%sasciizutf-8z%s="%s") len isinstancetuplerZencode_rfc2231encodeUnicodeEncodeError tspecialssearchquote)rvaluer#rrr _formatparam's   r%cCsdt|}g}x|dddkr|dd}|jd}x<|dkrt|jdd||jdd|drt|jd|d}q:W|dkrt|}|d|}d|kr|jd}|d|jjd||ddj}|j|j||d}qW|S)Nr rr"z\"r=)r findcountrindexrlowerappend)sZplistendfirrr _parseparamIs    *  ,r1cCs4t|tr&|d|dtj|dfStj|SdS)Nrrr)rrrunquote)r$rrr _unquotevalue]s r3c@seZdZefddZddZdcdd Zd d Zddd d ZddZ ddZ ddZ ddZ deddZ dfddZddZddZddZd d!Zd"d#Zd$d%Zd&d'Zd(d)Zd*d+Zd,d-Zd.d/Zdgd0d1Zd2d3Zd4d5Zdhd6d7Zd8d9Zd:d;Zdd?Z!d@dAZ"dBdCZ#dDdEZ$dFdGZ%didJdKZ&djdLdMZ'dkdPdQZ(dldRdSZ)dmdTdUZ*dndVdWZ+dodXdYZ,dZd[Z-dpd\d]Z.dqd^d_Z/d`daZ0ddbl1m2Z2dS)rrcCs:||_g|_d|_d|_d|_d|_|_g|_d|_dS)Nz text/plain) policy_headers _unixfrom_payload_charsetZpreambleZepiloguedefects _default_type)selfr4rrr__init__xs zMessage.__init__cCs|jS)N) as_string)r;rrr__str__szMessage.__str__FrNcCsJddlm}|dkr|jn|}t}||d||d}|j||d|jS)Nr) GeneratorF) mangle_from_ maxheaderlenr4)unixfrom)email.generatorr?r4rflattengetvalue)r;rBrAr4r?fpgrrrr=s zMessage.as_stringcCs|jS)N)as_bytes)r;rrr __bytes__szMessage.__bytes__cCsHddlm}|dkr|jn|}t}||d|d}|j||d|jS)Nr)BytesGeneratorF)r@r4)rB)rCrJr4rrDrE)r;rBr4rJrFrGrrrrHs  zMessage.as_bytescCs t|jtS)N)rr7list)r;rrr is_multipartszMessage.is_multipartcCs ||_dS)N)r6)r;rBrrr set_unixfromszMessage.set_unixfromcCs|jS)N)r6)r;rrr get_unixfromszMessage.get_unixfromc CsF|jdkr|g|_n.y|jj|Wntk r@tdYnXdS)Nz=Attach is not valid on a message with a non-multipart payload)r7r,AttributeError TypeError)r;payloadrrrattachs   zMessage.attachc Cs|jr(|rdS|dkr|jS|j|S|dk rPt|jt rPtdt|j|j}t|jddj}t|trt j |r|j dd}|sy|j |j ddd}Wn tk r|j dd}YnXn6|ry|j d}Wn tk r|j d}YnX|s |S|d kr tj|S|d krbtd j|j\}}x|D]}|jj||qFW|S|dkrt|} t} ytj | | dd| jStjk r|SXt|tr|S|S)NzExpected list, got %szcontent-transfer-encodingrrsurrogateescaper replacezraw-unicode-escapezquoted-printablebase64 x-uuencodeuuencodeuuex-uueT)quiet)rWrXrYrZ)rLr7rrKrPtyper getr+rZ_has_surrogatesrdecode get_param LookupError UnicodeErrorquopriZ decodestringr join splitlinesr4Z handle_defectruurEError) r;r0r^rQcteZbpayloadr$r9ZdefectZin_fileZout_filerrr get_payloadsV"          zMessage.get_payloadcCspt|dr:|dkr||_dSt|ts.t|}|j|j}t|drT|jdd|_n||_|dk rl|j|dS)Nrr^rrS)hasattrr7rCharsetroutput_charsetr^ set_charset)r;rQr rrr set_payload/s    zMessage.set_payloadcCs|dkr|jdd|_dSt|ts.t|}||_d|krH|jddd|krf|jdd|jdn|jd|j||jkr|j|j|_d|kr|j }y ||Wnjt k r|j}|ry|j dd }Wn t k r|j |j }YnX|j||_|jd|YnXdS) Nr z MIME-Versionz1.0z Content-Typez text/plain)r zContent-Transfer-EncodingrrS) del_paramr8rrj add_headerZget_output_charset set_paramZ body_encoder7Zget_body_encodingrPrrark)r;r rgrQrrrrlCs8       zMessage.set_charsetcCs|jS)N)r8)r;rrr get_charsetrszMessage.get_charsetcCs t|jS)N)rr5)r;rrr__len__zszMessage.__len__cCs |j|S)N)r])r;namerrr __getitem__~s zMessage.__getitem__cCsv|jj|}|r\|j}d}x>|jD]4\}}|j|kr$|d7}||kr$tdj||q$W|jj|jj||dS)Nrrz/There may be at most {} {} headers in a message)r4Zheader_max_countr+r5 ValueErrorformatr,header_store_parse)r;rsvalZ max_countZlnamefoundkvrrr __setitem__s  zMessage.__setitem__cCsD|j}g}x,|jD]"\}}|j|kr|j||fqW||_dS)N)r+r5r,)r;rs newheadersrzr{rrr __delitem__s  zMessage.__delitem__cCs|jdd|jDkS)NcSsg|]\}}|jqSr)r+).0rzr{rrr sz(Message.__contains__..)r+r5)r;rsrrr __contains__szMessage.__contains__ccsx|jD]\}}|VqWdS)N)r5)r;Zfieldr$rrr__iter__szMessage.__iter__cCsdd|jDS)NcSsg|] \}}|qSrr)rrzr{rrrrsz Message.keys..)r5)r;rrrkeyssz Message.keyscsfddjDS)Ncsg|]\}}jj||qSr)r4header_fetch_parse)rrzr{)r;rrrsz"Message.values..)r5)r;r)r;rvaluess zMessage.valuescsfddjDS)Ncs"g|]\}}|jj||fqSr)r4r)rrzr{)r;rrrsz!Message.items..)r5)r;r)r;ritemss z Message.itemscCs:|j}x,|jD]"\}}|j|kr|jj||SqW|S)N)r+r5r4r)r;rsfailobjrzr{rrrr]s  z Message.getcCs|jj||fdS)N)r5r,)r;rsr$rrrset_rawszMessage.set_rawcCst|jjS)N)iterr5copy)r;rrr raw_itemsszMessage.raw_itemscCsLg}|j}x2|jD](\}}|j|kr|j|jj||qW|sH|S|S)N)r+r5r,r4r)r;rsrrrzr{rrrget_alls  zMessage.get_allcKstg}xH|jD]<\}}|dkr2|j|jddq|jt|jdd|qW|dk rb|jd|tj|||<dS)N_-r)rr,rTr%insert SEMISPACErc)r;_name_valueZ_paramspartsrzr{rrrros zMessage.add_headercCs^|j}xPttt|j|jD].\}\}}|j|kr |jj|||j|<Pq Wt|dS)N)r+ziprangerr5r4rwKeyError)r;rrr0rzr{rrrreplace_header!s $ zMessage.replace_headercCsHt}|jd|}||kr"|jSt|dj}|jddkrDdS|S)Nz content-typer/rz text/plain)objectr]get_default_typerr+r))r;missingr$ctyperrrget_content_type4s  zMessage.get_content_typecCs|j}|jddS)Nrr)rsplit)r;rrrrget_content_maintypeLszMessage.get_content_maintypecCs|j}|jddS)Nrr)rr)r;rrrrget_content_subtypeUszMessage.get_content_subtypecCs|jS)N)r:)r;rrrr^szMessage.get_default_typecCs ||_dS)N)r:)r;rrrrset_default_typegszMessage.set_default_typec Cst}|j||}||kr|Sg}xdt|D]X}y$|jdd\}}|j}|j}Wn tk rt|j}d}YnX|j||fq,Wtj|}|S)Nr'rr) rr]r1rrrur,rZ decode_params) r;rheaderrr$paramsprsrxrrr_get_params_preserveps     zMessage._get_params_preserve content-typeTcCs8t}|j||}||kr|S|r0dd|DS|SdS)NcSsg|]\}}|t|fqSr)r3)rrzr{rrrrsz&Message.get_params..)rr)r;rrr2rrrrr get_paramss  zMessage.get_paramscCsJ||kr |Sx8|j||D](\}}|j|jkr|r>t|S|SqW|S)N)rr+r3)r;rrrr2rzr{rrrr_szMessage.get_param Content-Typerc Cst|t r|r|||f}||kr4|jdkr4d}n |j|}|j||dsv|s^t|||}qtj|t|||g}nfd}x`|j||dD]N\} } d} | j|jkrt|||} n t| | |} |s| }qtj|| g}qW||j|kr|r|j ||n||=|||<dS)Nz content-typez text/plain)rr)rr2) rrr+r]r_r%rrcrr) r;rr$rrequoter ZlanguagerTrZ old_paramZ old_valueZ append_paramrrrrps2   zMessage.set_paramcCs||kr dSd}xR|j||dD]@\}}|j|jkr |sJt|||}q tj|t|||g}q W||j|kr||=|||<dS)Nr)rr2)rr+r%rrcr])r;rrrZ new_ctyperr{rrrrnszMessage.del_paramcCs|jddkst|jdkr,|d=d|d<||kr@|||<dS|j||d}||=|||<x(|ddD]\}}|j||||qjWdS)Nrrz content-typez mime-versionz1.0z MIME-Version)rr2)r)rur+rrp)r;r\rrrrr{rrrset_types zMessage.set_typecCsDt}|jd|d}||kr*|jd|d}||kr6|Stj|jS)Nfilenamezcontent-dispositionrsz content-type)rr_rcollapse_rfc2231_valuer)r;rrrrrr get_filename&szMessage.get_filenamecCs,t}|jd|}||kr|Stj|jS)Nboundary)rr_rrrstrip)r;rrrrrr get_boundary6s  zMessage.get_boundarycCs t}|j|d}||kr$tjdg}d}xB|D]:\}}|jdkr^|jdd|fd}q2|j||fq2W|s|jdd|fg}x|jD]\} } | jdkrg} x6|D].\} } | dkr| j| q| jd| | fqWtj| } |j|j j | | q|j| | fqW||_dS) Nz content-typezNo Content-Type header foundFrz"%s"Trz%s=%s) rrrZHeaderParseErrorr+r,r5rrcr4rw)r;rrrZ newparamsZfoundpZpkZpvr}hr{rrzrxrrr set_boundaryCs2      zMessage.set_boundarycCst}|jd|}||kr|St|trr|dp2d}y|djd}t||}Wn ttfk rp|d}YnXy|jdWntk r|SX|jS)Nr rzus-asciirzraw-unicode-escape) rr_rrrr r`rar+)r;rrr ZpcharsetrHrrrget_content_charsetqs    zMessage.get_content_charsetcsfdd|jDS)Ncsg|]}|jqSr)r)rpart)rrrrsz(Message.get_charsets..)walk)r;rr)rr get_charsetsszMessage.get_charsetscCs*|jd}|dkrdSt|dj}|S)Nzcontent-dispositionr)r]rr+)r;r$c_drrrget_content_dispositions  zMessage.get_content_disposition)r)FrN)FN)NF)N)N)N)NrT)NrT)rTNrF)rT)rT)N)N)N)N)3__name__ __module__ __qualname__r r<r>r=rIrHrLrMrNrRrhrmrlrqrrrtr|r~rrrrrr]rrrrorrrrrrrrr_rprnrrrrrrrZemail.iteratorsrrrrrris`    Z /            ! 2   .   cseZdZd3ddZd4fdd ZddZd d Zd d Zd6ddZd7d8d9d:hZ ddZ ddZ ddddZ ddddZ ddZd;d d!ZdMIMEPartNcCs(|dkrddlm}|}tj||dS)Nr)default)Z email.policyrrr<)r;r4rrrrr<s zMIMEPart.__init__Fcs0|dkr|jn|}|dkr |j}tj||dS)N)rAr4)r4Zmax_line_lengthsuperr=)r;rBrAr4) __class__rrr=s zMIMEPart.as_stringcCs|j|jjdddS)NT)utf8)r4)r=r4Zclone)r;rrrr>szMIMEPart.__str__cCs |jd}|dkrdS|jdkS)Nzcontent-dispositionF attachment)r]Zcontent_disposition)r;rrrr is_attachments zMIMEPart.is_attachmentc cs |jr dS|jjd\}}|dkrB||kr>|j||fVdS|dkrNdS|dkr~x"|jD]}|j||EdHq`WdSd|kr|jd|fVd}|jd}|rx"|jD]}|d|kr|}PqW|dkr|j}|r|dnd}|dk r|j||EdHdS)Nrtext multipartrelatedstartz content-idr)rrrr* iter_parts _find_bodyr_rh) r;rpreferencelistmaintypesubtypeZsubpart candidaterZsubpartsrrrrs6   zMIMEPart._find_bodyrhtmlplaincCsDt|}d}x2|j||D]"\}}||kr|}|}|dkrPqW|S)Nr)rr)r;rZ best_prioZbodyZpriorrrrget_bodys zMIMEPart.get_bodyrr alternativec cs|jjd\}}|dks"|dkr&dS|jj}|dkr|dkr|jd}|rd}g}x*|D]"}|jd|krvd}q^|j|q^W|r|EdHdS|jd |EdHdSg}xP|D]H}|jjd\}}||f|jkr|j r||kr|j|q|VqWdS) NrrrrrFz content-idTr) rrrhrr_r]r,pop _body_typesr) r;rrrrryZ attachmentsrseenrrriter_attachmentss6         zMIMEPart.iter_attachmentsccs|jdkr|jEdHdS)Nr)rrh)r;rrrr4s zMIMEPart.iter_parts)content_managercOs"|dkr|jj}|j|f||S)N)r4r get_content)r;rargskwrrrr<szMIMEPart.get_contentcOs&|dkr|jj}|j|f||dS)N)r4r set_content)r;rrrrrrrAszMIMEPart.set_contentc Cs|jdkr6|j}||f}||kr6tdj||g}g}x>|jD]4\}}|jjdrl|j||fqF|j||fqFW|rt||j d} || _|j | _ | g|_ ng|_ ||_d||d<|dk r|j d|dS)NrzCannot convert {} to {}zcontent-)r4z multipart/z Content-Typer) rrrurvr5r+ startswithr,r\r4r7rp) r;rZdisallowed_subtypesrZexisting_subtypeZ keep_headersZ part_headersrsr$rrrr_make_multipartFs,     zMIMEPart._make_multipartcCs|jdd|dS)Nrrmixed)rr)r)r;rrrr make_relatedaszMIMEPart.make_relatedcCs|jdd|dS)Nrr)r)r)r;rrrrmake_alternativedszMIMEPart.make_alternativecCs|jdf|dS)Nr)r)r;rrrr make_mixedgszMIMEPart.make_mixed)_dispcOsf|jdks|j|kr(t|d|t||jd}|j|||rXd|krX||d<|j|dS)NrZmake_)r4zcontent-dispositionzContent-Disposition)rrgetattrr\r4rrR)r;Z_subtyperrrrrrr_add_multipartjs    zMIMEPart._add_multipartcOs|jd|ddi|dS)NrrZinline)r)r)r;rrrrr add_relatedtszMIMEPart.add_relatedcOs|jd||dS)Nr)r)r)r;rrrrradd_alternativewszMIMEPart.add_alternativecOs|jd|ddi|dS)Nrrr)r)r)r;rrrrradd_attachmentzszMIMEPart.add_attachmentcCsg|_d|_dS)N)r5r7)r;rrrclear}szMIMEPart.clearcCsdd|jD|_d|_dS)NcSs&g|]\}}|jjds||fqS)zcontent-)r+r)rnr{rrrrsz*MIMEPart.clear_content..)r5r7)r;rrr clear_contentszMIMEPart.clear_content)N)FNNrrr)r)rr)rr)rr)rr)N)N)N)rrrr<r=r>rrrrrrrrrrrrrrrrrr __classcell__rr)rrrs0  .    rcseZdZfddZZS)rcs"tj||d|krd|d<dS)Nz MIME-Versionz1.0)rr)r;rr)rrrrszEmailMessage.set_content)rrrrrrr)rrrs)NT)__all__rererbiorrZemailrrZemail._policybaserr r r8Zemail._encoded_wordsr rjrcompiler!rr%r1r3rrrrrrrs4      " NWparser.cpython-36.opt-1.pyc000064400000013137147204636050011441 0ustar003 \@sdZddddddgZddlmZmZdd lmZmZdd lm Z Gd ddZ Gd dde Z Gd ddZ Gddde Z dS)z-A parser of RFC 2822 and MIME email messages.Parser HeaderParser BytesParserBytesHeaderParser FeedParserBytesFeedParser)StringIO TextIOWrapper)rr)compat32c@s0eZdZd edddZd ddZd dd ZdS) rN)policycCs||_||_dS)aParser of RFC 2822 and MIME email messages. Creates an in-memory object tree representing the email message, which can then be manipulated and turned over to a Generator to return the textual representation of the message. The string must be formatted as a block of RFC 2822 headers and header continuation lines, optionally preceded by a `Unix-from' header. The header block is terminated either by the end of the string or by a blank line. _class is the class to instantiate for new message objects when they must be created. This class must have a constructor that can take zero arguments. Default is Message.Message. The policy keyword specifies a policy object that controls a number of aspects of the parser's operation. The default policy maintains backward compatibility. N)_classr )selfr r r$/usr/lib64/python3.6/email/parser.py__init__szParser.__init__FcCsDt|j|jd}|r|jx|jd}|s.P|j|qW|jS)a\Create a message structure from the data in a file. Reads all the data from the file and returns the root of the message structure. Optional headersonly is a flag specifying whether to stop parsing after reading the headers or not. The default is False, meaning it parses the entire contents of the file. )r i )rr r Z_set_headersonlyreadZfeedclose)r fp headersonlyZ feedparserdatarrrparse*s z Parser.parsecCs|jt||dS)a-Create a message structure from a string. Returns the root of the message structure. Optional headersonly is a flag specifying whether to stop parsing after reading the headers or not. The default is False, meaning it parses the entire contents of the file. )r)rr)r textrrrrparsestr<szParser.parsestr)N)F)F)__name__ __module__ __qualname__r rrrrrrrrs c@s eZdZdddZdddZdS) rTcCstj||dS)NT)rr)r rrrrrrIszHeaderParser.parsecCstj||dS)NT)rr)r rrrrrrLszHeaderParser.parsestrN)T)T)rrrrrrrrrrHs c@s(eZdZddZd ddZd ddZdS) rcOst|||_dS)aParser of binary RFC 2822 and MIME email messages. Creates an in-memory object tree representing the email message, which can then be manipulated and turned over to a Generator to return the textual representation of the message. The input must be formatted as a block of RFC 2822 headers and header continuation lines, optionally preceded by a `Unix-from' header. The header block is terminated either by the end of the input or by a blank line. _class is the class to instantiate for new message objects when they must be created. This class must have a constructor that can take zero arguments. Default is Message.Message. N)rparser)r argskwrrrrRszBytesParser.__init__Fc Cs,t|ddd}z|jj||S|jXdS)acCreate a message structure from the data in a binary file. Reads all the data from the file and returns the root of the message structure. Optional headersonly is a flag specifying whether to stop parsing after reading the headers or not. The default is False, meaning it parses the entire contents of the file. asciisurrogateescape)encodingerrorsN)r rrdetach)r rrrrrrdszBytesParser.parsecCs|jddd}|jj||S)a2Create a message structure from a byte string. Returns the root of the message structure. Optional headersonly is a flag specifying whether to stop parsing after reading the headers or not. The default is False, meaning it parses the entire contents of the file. ASCIIr )r")decoderr)r rrrrr parsebytessszBytesParser.parsebytesN)F)F)rrrrrr&rrrrrPs c@s eZdZdddZdddZdS) rTcCstj||ddS)NT)r)rr)r rrrrrrszBytesHeaderParser.parsecCstj||ddS)NT)r)rr&)r rrrrrr&szBytesHeaderParser.parsebytesN)T)T)rrrrr&rrrrrs N)__doc____all__iorr Zemail.feedparserrrZemail._policybaser rrrrrrrrs 7/parser.cpython-36.opt-2.pyc000064400000005223147204636050011437 0ustar003 \@s|ddddddgZddlmZmZddlmZmZdd lmZGd ddZ Gd dde Z Gd ddZ Gd dde Z dS)Parser HeaderParser BytesParserBytesHeaderParser FeedParserBytesFeedParser)StringIO TextIOWrapper)rr)compat32c@s0eZdZd edddZd ddZd dd ZdS) rN)policycCs||_||_dS)N)_classr )selfr r r$/usr/lib64/python3.6/email/parser.py__init__szParser.__init__FcCsDt|j|jd}|r|jx|jd}|s.P|j|qW|jS)N)r i )rr r Z_set_headersonlyreadZfeedclose)r fp headersonlyZ feedparserdatarrrparse*s z Parser.parsecCs|jt||dS)N)r)rr)r textrrrrparsestr<szParser.parsestr)N)F)F)__name__ __module__ __qualname__r rrrrrrrrs c@s eZdZdddZdddZdS) rTcCstj||dS)NT)rr)r rrrrrrIszHeaderParser.parsecCstj||dS)NT)rr)r rrrrrrLszHeaderParser.parsestrN)T)T)rrrrrrrrrrHs c@s(eZdZddZd ddZd ddZdS) rcOst|||_dS)N)rparser)r argskwrrrrRszBytesParser.__init__Fc Cs,t|ddd}z|jj||S|jXdS)Nasciisurrogateescape)encodingerrors)r rrdetach)r rrrrrrdszBytesParser.parsecCs|jddd}|jj||S)NASCIIr )r")decoderr)r rrrrr parsebytessszBytesParser.parsebytesN)F)F)rrrrrr&rrrrrPs c@s eZdZdddZdddZdS) rTcCstj||ddS)NT)r)rr)r rrrrrrszBytesHeaderParser.parsecCstj||ddS)NT)r)rr&)r rrrrrr&szBytesHeaderParser.parsebytesN)T)T)rrrrr&rrrrrs N) __all__iorr Zemail.feedparserrrZemail._policybaser rrrrrrrrs 7/policy.cpython-36.opt-1.pyc000064400000022624147204636050011445 0ustar003 \(@sdZddlZddlmZmZmZmZddlmZddl m Z ddl m Z ddl mZdd d d d d ddgZejdZeGdd d eZeZe`ejddZejddZejdddZejddZdS)zcThis will be the home for the policy that hooks in the new code that adds all the email6 features. N)PolicyCompat32compat32_extend_docstrings)_has_surrogates)HeaderRegistry)raw_data_manager) EmailMessagerrr EmailPolicydefaultstrictSMTPHTTPz\n|\rcspeZdZdZeZdZdZeZ e Z fddZ ddZ dd Zd d Zd d ZddZddZdddZZS)r aQ + PROVISIONAL The API extensions enabled by this policy are currently provisional. Refer to the documentation for details. This policy adds new header parsing and folding algorithms. Instead of simple strings, headers are custom objects with custom attributes depending on the type of the field. The folding algorithm fully implements RFCs 2047 and 5322. In addition to the settable attributes listed above that apply to all Policies, this policy adds the following additional attributes: utf8 -- if False (the default) message headers will be serialized as ASCII, using encoded words to encode any non-ASCII characters in the source strings. If True, the message headers will be serialized using utf8 and will not contain encoded words (see RFC 6532 for more on this serialization format). refold_source -- if the value for a header in the Message object came from the parsing of some source, this attribute indicates whether or not a generator should refold that value when transforming the message back into stream form. The possible values are: none -- all source values use original folding long -- source values that have any line that is longer than max_line_length will be refolded all -- all values are refolded. The default is 'long'. header_factory -- a callable that takes two arguments, 'name' and 'value', where 'name' is a header field name and 'value' is an unfolded header field value, and returns a string-like object that represents that header. A default header_factory is provided that understands some of the RFC5322 header field types. (Currently address fields and date fields have special treatment, while all other fields are treated as unstructured. This list will be completed before the extension is marked stable.) content_manager -- an object with at least two methods: get_content and set_content. When the get_content or set_content method of a Message object is called, it calls the corresponding method of this object, passing it the message object as its first argument, and any arguments or keywords that were passed to it as additional arguments. The default content_manager is :data:`~email.contentmanager.raw_data_manager`. Flongc s*d|krtj|dttjf|dS)Nheader_factory)object __setattr__rsuper__init__)selfkw) __class__$/usr/lib64/python3.6/email/policy.pyr\szEmailPolicy.__init__cCs |j|jS)z+ The implementation for this class returns the max_count attribute from the specialized header class that would be used to construct a header of type 'name'. )rZ max_count)rnamerrrheader_max_countcszEmailPolicy.header_max_countcCs>|djdd\}}|jddj|dd}||jdfS)ac+ The name is parsed as everything up to the ':' and returned unmodified. The value is determined by stripping leading whitespace off the remainder of the first line, joining all subsequent lines together, and stripping any trailing carriage return or linefeed characters. (This is the same as Compat32). r:z Nz )splitlstripjoinrstrip)rZ sourcelinesrvaluerrrheader_source_parseus zEmailPolicy.header_source_parsecCsVt|dr$|jj|jkr$||fSt|trFt|jdkrFtd||j||fS)a+ The name is returned unchanged. If the input value has a 'name' attribute and it matches the name ignoring case, the value is returned unchanged. Otherwise the name and value are passed to header_factory method, and the resulting custom header object is returned as the value. In this case a ValueError is raised if the input value contains CR or LF characters. rrzDHeader values may not contain linefeed or carriage return characters) hasattrrlower isinstancestrlen splitlines ValueErrorr)rrr#rrrheader_store_parses zEmailPolicy.header_store_parsecCs*t|dr|Sdjtj|}|j||S)ai+ If the value has a 'name' attribute, it is returned to unmodified. Otherwise the name and the value with any linesep characters removed are passed to the header_factory method, and the resulting custom header object is returned. Any surrogateescaped bytes get turned into the unicode unknown-character glyph. rr)r%r!linesep_splitterrr)rrr#rrrheader_fetch_parses zEmailPolicy.header_fetch_parsecCs|j||ddS)a + Header folding is controlled by the refold_source policy setting. A value is considered to be a 'source value' if and only if it does not have a 'name' attribute (having a 'name' attribute means it is a header object of some sort). If a source value needs to be refolded according to the policy, it is converted into a custom header object by passing the name and the value with any linesep characters removed to the header_factory method. Folding of a custom header object is done by calling its fold method with the current policy. Source values are split into lines using splitlines. If the value is not to be refolded, the lines are rejoined using the linesep from the policy and returned. The exception is lines containing non-ascii binary data. In that case the value is refolded regardless of the refold_source setting, which causes the binary data to be CTE encoded using the unknown-8bit charset. T) refold_binary)_fold)rrr#rrrfoldszEmailPolicy.foldcCs0|j|||jdkd}|jr dnd}|j|dS)a+ The same as fold if cte_type is 7bit, except that the returned value is bytes. If cte_type is 8bit, non-ASCII binary data is converted back into bytes. Headers with binary data are not refolded, regardless of the refold_header setting, since there is no way to know whether the binary data consists of single byte characters or multibyte characters. If utf8 is true, headers are encoded to utf8, otherwise to ascii with non-ASCII unicode rendered as encoded words. Z7bit)r/utf8asciisurrogateescape)r0Zcte_typer2encode)rrr#Zfoldedcharsetrrr fold_binaryszEmailPolicy.fold_binarycst|dr|j|dS|jr"|jntd|j}|jdkp|jdko|rft|dt|dkptfdd |d dD}|s|rt|r|j |d j |j|dS|d |j j ||j S) Nr)Zpolicyinfallrrc3s|]}t|kVqdS)N)r)).0x)maxlenrr sz$EmailPolicy._fold..rrz: ) r%r1max_line_lengthfloatr* refold_sourcer)anyrrr!linesep)rrr#r/linesZrefoldr)r=rr0s     zEmailPolicy._fold)F)__name__ __module__ __qualname____doc__r Zmessage_factoryr2rArrrZcontent_managerrrr$r,r.r1r7r0 __classcell__rr)rrr s;  T)Zraise_on_defectz )rC)rCr?)r2)rHreZemail._policybaserrrrZ email.utilsrZemail.headerregistryrZemail.contentmanagerrZ email.messager __all__compiler-r r rZcloner r rZSMTPUTF8rrrrs0      @  policy.cpython-36.opt-2.pyc000064400000006513147204636050011445 0ustar003 \(@sddlZddlmZmZmZmZddlmZddlm Z ddl m Z ddl m Z ddd d d d d dgZejdZeGdd d eZeZe`ejddZejddZejdddZejddZdS)N)PolicyCompat32compat32_extend_docstrings)_has_surrogates)HeaderRegistry)raw_data_manager) EmailMessagerrr EmailPolicydefaultstrictSMTPHTTPz\n|\rcsleZdZeZdZdZeZe Z fddZ ddZ ddZ d d Zd d Zd dZddZdddZZS)r Flongc s*d|krtj|dttjf|dS)Nheader_factory)object __setattr__rsuper__init__)selfkw) __class__$/usr/lib64/python3.6/email/policy.pyr\szEmailPolicy.__init__cCs |j|jS)N)rZ max_count)rnamerrrheader_max_countcszEmailPolicy.header_max_countcCs>|djdd\}}|jddj|dd}||jdfS)Nr:z z )splitlstripjoinrstrip)rZ sourcelinesrvaluerrrheader_source_parseus zEmailPolicy.header_source_parsecCsVt|dr$|jj|jkr$||fSt|trFt|jdkrFtd||j||fS)NrrzDHeader values may not contain linefeed or carriage return characters) hasattrrlower isinstancestrlen splitlines ValueErrorr)rrr#rrrheader_store_parses zEmailPolicy.header_store_parsecCs*t|dr|Sdjtj|}|j||S)Nrr)r%r!linesep_splitterrr)rrr#rrrheader_fetch_parses zEmailPolicy.header_fetch_parsecCs|j||ddS)NT) refold_binary)_fold)rrr#rrrfoldszEmailPolicy.foldcCs0|j|||jdkd}|jr dnd}|j|dS)NZ7bit)r/utf8asciisurrogateescape)r0Zcte_typer2encode)rrr#Zfoldedcharsetrrr fold_binaryszEmailPolicy.fold_binarycst|dr|j|dS|jr"|jntd|j}|jdkp|jdko|rft|dt|dkptfdd |d dD}|s|rt|r|j |d j |j|dS|d |j j ||j S) Nr)Zpolicyinfallrrc3s|]}t|kVqdS)N)r)).0x)maxlenrr sz$EmailPolicy._fold..rrz: ) r%r1max_line_lengthfloatr* refold_sourcer)anyrrr!linesep)rrr#r/linesZrefoldr)r=rr0s     zEmailPolicy._fold)F)__name__ __module__ __qualname__r Zmessage_factoryr2rArrrZcontent_managerrrr$r,r.r1r7r0 __classcell__rr)rrr s=  T)Zraise_on_defectz )rC)rCr?)r2)reZemail._policybaserrrrZ email.utilsrZemail.headerregistryrZemail.contentmanagerrZ email.messager __all__compiler-r r rZcloner r rZSMTPUTF8rrrrs.      @  quoprimime.cpython-36.opt-1.pyc000064400000017002147204636050012327 0ustar003 \& @sddZddddddddd d g Zd d lZd d lmZmZmZdZdZdZ dde dDZ e d d Z e d d Z x,dejdejdD]Zeee e<qWde ed<xdD]Zeee e<qWddZddZddZddZd,dd Zd!d Zd"d Zd-d$dZe d d Zxd%D]Zeeee<qWd&efd'dZefd(dZeZeZd)d*Zd+dZ d S).aFQuoted-printable content transfer encoding per RFCs 2045-2047. This module handles the content transfer encoding method defined in RFC 2045 to encode US ASCII-like 8-bit data called `quoted-printable'. It is used to safely encode text that is in a character set similar to the 7-bit US ASCII character set, but that includes some 8-bit characters that are normally not allowed in email bodies or headers. Quoted-printable is very space-inefficient for encoding binary files; use the email.base64mime module for that instead. This module provides an interface to encode and decode both headers and bodies with quoted-printable encoding. RFC 2045 defines a method for including character set information in an `encoded-word' in a header. This method is commonly used for 8-bit real names in To:/From:/Cc: etc. fields, as well as Subject: lines. This module does not do the line wrapping or end-of-line character conversion necessary for proper internationalized headers; it only does dumb encoding and decoding. To deal with the various line wrapping issues, use the email.header module. body_decode body_encode body_lengthdecode decodestring header_decode header_encode header_lengthquoteunquoteN) ascii_lettersdigits hexdigitsz  cCsg|] }d|qS)z=%02X).0crr(/usr/lib64/python3.6/email/quoprimime.py 7srs-!*+/ascii_ s_ !"#$%&'()*+,-./0123456789:;<>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ cCst|t|kS)z>Return True if the octet should be escaped with header quopri.)chr_QUOPRI_HEADER_MAP)octetrrr header_checkJsrcCst|t|kS)z^sz header_length..)sum) bytearrayrrrrTs cCstdd|DS)zReturn a body quoted-printable encoding length. :param bytearray: An array of bytes (a.k.a. octets). :return: The length in bytes of the byte array when it is encoded with quoted-printable for bodies. css|]}tt|VqdS)N)r r)rrrrrr!hszbody_length..)r")r#rrrrascCsft|tst|}|s&|j|jnn^|d|kr||dtkr||dtkr|t|||d7}|d7}n||7}|d7}||kr>||7}q>WqW|d dkr|j|r|dd }|S) z_Decode a quoted-printable string. Lines are separated with eol, which defaults to \n. rr r:r$r;r.z Nr%r%)r>rstripr rr endswith)r7rAZdecodedrBinrrrrrs8   ,  cCs|jd}t|S)zCTurn a match in the form =AB to the ASCII character with value 0xabr )groupr )matchr+rrr_unquote_matchs rLcCs |jdd}tjdt|tjdS)aDecode a string encoded with RFC 2045 MIME header `Q' encoding. This function does not parse a full MIME header value encoded with quoted-printable (like =?iso-8859-1?q?Hello_World?=) -- please use the high level email.header class for that functionality. rrz=[a-fA-F0-9]{2})flags)replaceresubrLASCII)r+rrrr#s )r)r3)!__doc____all__rOstringr r rr?NLZ EMPTYSTRINGranger1rrencoderrr2rrrrr-r r rr=rrrrrLrrrrrsP         O 0quoprimime.cpython-36.opt-2.pyc000064400000010155147204636050012332 0ustar003 \& @s`dddddddddd g Zd d lZd d lmZmZmZd ZdZdZdde dDZ e d d Z e d d Z x,dej dej dD]Zeee e<qWde ed<xdD]Zeee e<qWddZddZddZddZd+ddZd d Zd!dZd,d#dZe d d Zxd$D]Zeeee<qWd%efd&dZefd'dZeZeZd(d)Zd*dZd S)- body_decode body_encode body_lengthdecode decodestring header_decode header_encode header_lengthquoteunquoteN) ascii_lettersdigits hexdigitsz  cCsg|] }d|qS)z=%02X).0crr(/usr/lib64/python3.6/email/quoprimime.py 7srs-!*+/ascii_ s_ !"#$%&'()*+,-./0123456789:;<>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ cCst|t|kS)N)chr_QUOPRI_HEADER_MAP)octetrrr header_checkJsrcCst|t|kS)N)r_QUOPRI_BODY_MAP)rrrr body_checkOsrcCstdd|DS)Ncss|]}tt|VqdS)N)lenr)rrrrr ^sz header_length..)sum) bytearrayrrrrTs cCstdd|DS)Ncss|]}tt|VqdS)N)r r)rrrrrr!hszbody_length..)r")r#rrrrascCsft|tst|}|s&|j|jnn^|d|kr||dtkr||dtkr|t|||d7}|d7}n||7}|d7}||kr>||7}q>WqW|ddkr|j|r|dd }|S) Nrr r:r$r;r.z r%r%)r>rstripr rr endswith)r7rAZdecodedrBinrrrrrs8   ,  cCs|jd}t|S)Nr )groupr )matchr+rrr_unquote_matchs rLcCs |jdd}tjdt|tjdS)Nrrz=[a-fA-F0-9]{2})flags)replaceresubrLASCII)r+rrrr#s )r)r3) __all__rOstringr r rr?NLZ EMPTYSTRINGranger1rrencoderrr2rrrrr-r r rr=rrrrrLrrrrrsN         O 0utils.cpython-36.opt-1.pyc000064400000031627147204636050011311 0ustar003 fJ@sdZddddddddd d d d d ddgZddlZddlZddlZddlZddlZddlZddlZ ddl m Z ddl m Z ddl mZddl mZmZmZddlmZdZdZdZdZdZejdZejdZdZdaddZd d!Zd"d#Z d$d%Z!dId'dZ"d(d)Z#d*d+Z$d,Z%dd-d.dZ&d/d0Z'd1d2Z(d3d4Z)ejd5ej*ej+BZ,d6d7Z-dJd9dZ.dKd:dZ/dLd;d Z0ddZ3d?dZ4dMd@dZ5ejdAej6Z7dBdZ8dNdEdZ9dPdGdHZ:dS)QzMiscellaneous utilities.collapse_rfc2231_value decode_paramsdecode_rfc2231encode_rfc2231 formataddr formatdateformat_datetime getaddresses make_msgid mktime_tz parseaddr parsedate parsedate_tzparsedate_to_datetimeunquoteN)quote) AddressList)r )r r _parsedate_tz)Charsetz, z 'z[][\\()<>@,:;".]z[\\"]z/etc/python/email.cfgcCstdkrtatS)z5"Cache implementation for _cached_strict_addr_parsingN)_cached_strict_addr_parsing_use_strict_email_parsing_implrr#/usr/lib64/python3.6/email/utils.py_use_strict_email_parsing7srcCsttjjd}|rdSy tt}Wntk r8YnBX|6ddl}|jdd d}|j ||j dddd}WdQRX|rdSd S) z]Returns True if strict email parsing is not disabled by config file or env variable. Z(PYTHON_EMAIL_DISABLE_STRICT_ADDR_PARSINGFrN#)Z interpolationZcomment_prefixesZemail_addr_parsing)ZfallbackT)r) boolosenvirongetopen_EMAIL_CONFIG_FILEFileNotFoundError configparserZ ConfigParserZ read_fileZ getboolean)Zdisabledfiler$configrrrr?s"  rc Cs&y |jdStk r dSXdS)z8Return True if s contains surrogate-escaped binary data.FTN)encodeUnicodeEncodeError)srrr_has_surrogates\s r*cCs|jdd}|jddS)Nzutf-8surrogateescapereplace)r'decode)stringZoriginal_bytesrrr _sanitizeis r/utf-8c Cs|\}}|jd|ry|jdWn8tk r\t|trFt|}|j|}d||fSXd}tj|rpd}tj d|}d||||fS|S)aThe inverse of parseaddr(), this takes a 2-tuple of the form (realname, email_address) and returns the string value suitable for an RFC 2822 From, To or Cc header. If the first element of pair is false, then the second element is returned unmodified. Optional charset if given is the character set that is used to encode realname in case realname is not ASCII safe. Can be an instance of str or a Charset-like object which has a header_encode method. Default is 'utf-8'. asciiz%s <%s>r"z\\\g<0>z %s%s%s <%s>) r'r( isinstancestrrZ header_encode specialsresearch escapesresub)ZpaircharsetnameZaddressZ encoded_nameZquotesrrrrus      ccs`d}d}xDt|D]8\}}|r2|d|fVd}q|dkr@d}q||fVqW|r\|dfVdS)NrF\T) enumerate)addrposescapechrrr_iter_escaped_charssrAcCsd|kr |Sd}d}g}xPt|D]D\}}|dkr"|dkr@|}q"||krZ|j||||d}d}q"W|t|kr|j||ddj|S)z Strip real names between quotes.r2rNr)rAappendlenjoin)r=startZopen_posresultr>r@rrr_strip_quoted_realnamess  rHT)strictcCs|dkrt}|s4tjdd|D}t|}|jSdd|D}t|}tj|}t|}t|j}d}x&|D]}t|}|d|jd7}qpWt ||krd gS|S) zReturn a list of (REALNAME, EMAIL) or ('','') for each fieldvalue. When parsing fails for a fieldvalue, a 2-tuple of ('', '') is returned in its place. If strict is true, use a strict parser which rejects malformed inputs. Ncss|]}t|VqdS)N)r4).0vrrr szgetaddresses..cSsg|] }t|qSr)r4)rJrKrrr sz getaddresses..rrB,r)rr) r COMMASPACErE _AddressList addresslist_pre_parse_validation_post_parse_validationrHcountrD)Z fieldvaluesrIallar=rGnrKrrrrs$      cCsXt|}d}xBt|D]6\}}|dkr0|d7}q|dkr|d8}|dkrdSqW|dkS)Nr(rB)F)rHrA)r=Zopensr>r@rrr_check_parenthesiss rZcCs,g}x"|D]}t|sd}|j|q W|S)Nz('', ''))rZrC)Zemail_header_fieldsaccepted_valuesrKrrrrRs  rRcCs0g}x&|D]}d|dkrd}|j|q W|S)N[rBr)rr)rC)Zparsed_email_header_tuplesr[rKrrrrS s   rSa_ =\? # literal =? (?P[^?]*?) # non-greedy up to the next ? is the charset \? # literal ? (?P[qb]) # either a "q" or a "b", case insensitive \? # literal ? (?P.*?) # non-greedy up to the next ?= is the atom \?= # literal ?= cCsfddddddddg|d |d d d d dddddddddg |dd|d|d|d|d|fS)Nz"%s, %02d %s %04d %02d:%02d:%02d %sZMonZTueZWedZThuZFriZSatZSunZJanZFebZMarZAprZMayZJunZJulZAugZSepZOctZNovZDecrBrr) timetuplezonerrr_format_timetuple_and_zone"s rdFcCsR|dkrtj}|s|r,tjj|tjj}n tjj|}|rH|j}d}t||S)aReturns a date string as specified by RFC 2822, e.g.: Fri, 09 Nov 2001 01:08:47 -0000 Optional timeval if given is a floating point time value as accepted by gmtime() and localtime(), otherwise the current time is used. Optional localtime is a flag that when True, interprets timeval, and returns a date relative to the local timezone instead of UTC, properly taking daylight savings time into account. Optional argument usegmt means that the timezone is written out as an ascii string, not numeric one (so "GMT" instead of "+0000"). This is needed for HTTP, and is only used when localtime==False. NF)timedatetimeZ fromtimestamptimezoneutcZutcfromtimestamp astimezoner)timeval localtimeusegmtdtrrrr+s cCsV|j}|r2|jdks$|jtjjkr,tdd}n|jdkrBd}n |jd}t||S)a$Turn a datetime into a date string as specified in RFC 2822. If usegmt is True, dt must be an aware datetime with an offset of zero. In this case 'GMT' will be rendered instead of the normal +0000 required by RFC2822. This is to support HTTP headers involving date stamps. Nz%usegmt option requires a UTC datetimeZGMTz-0000z%z)rbtzinforfrgrh ValueErrorZstrftimerd)rmrlnowrcrrrrHs  cCs^ttjd}tj}tjd}|dkr0d}nd|}|dkrHtj}d|||||f}|S)a{Returns a string suitable for RFC 2822 compliant Message-ID, e.g: <142480216486.20800.16526388040877946887@nightshade.la.mastaler.com> Optional idstring if given is a string used to strengthen the uniqueness of the message id. Optional domain if given provides the portion of the message id after the '@'. It defaults to the locally defined hostname. d@Nr.z<%d.%d.%d%s@%s>)intrergetpidrandomZ getrandbitssocketZgetfqdn)ZidstringZdomainrjpidZrandintZmsgidrrrr [s  cCsNt|^}}|dkr(tj|ddStj|dddtjtj|diS)Nr]rn)seconds)rrfrg timedelta)dataZdtupletzrrrrrs cCs|dkrt}|s,t|j}|s$dS|dSt|tr>|d}t|tsLdSt|gd}tt|j}| szt|dkr~dS|dS)a Parse addr into its constituent realname and email address parts. Return a tuple of realname and email address, unless the parse fails, in which case return a 2-tuple of ('', ''). If strict is True, use a strict parser which rejects malformed inputs. NrrrB)rr)rr)rr) rrPrQr3listr4rRrSrD)r=rIZaddrsrrrr zs    cCs`t|dkr\|jdr<|jdr<|ddjddjddS|jdr\|jdr\|dd S|S) zRemove quotes from a string.rBr2z\\r;z\"<>r)rD startswithendswithr,)r4rrrrs   cCs&|jtd}t|dkr"dd|fS|S)z#Decode string according to RFC 2231r^N)splitTICKrD)r)partsrrrrs   cCsDtjj|d|pdd}|dkr*|dkr*|S|dkr6d}d|||fS)zEncode string according to RFC 2231. If neither charset nor language is given, then s is returned as-is. If charset is given but not language, the string is encoded using the empty string for language. rr1)ZsafeencodingNz%s'%s'%s)urllibparser)r)r9languagerrrrs z&^(?P\w+)\*((?P[0-9]+)\*?)?$c Csx|dd}g}i}|jd\}}|j||fx|r|jd\}}|jdrTd}nd}t|}tj|}|r|jdd\}}|dk rt|}|j|gj|||fq2|j|dt |fq2W|rtx|j D]\}}g}d} |j x6|D].\}} }|rt j j| d d } d} |j| qWt tj|}| r^t|\} } }|j|| | d|ffq|j|d|fqW|S) zDecode parameters list according to RFC 2231. params is a sequence of 2-tuples containing (param name, string value). Nr*TFr:numz"%s"zlatin-1)r)poprCrrrfc2231_continuationmatchgrouprt setdefaultritemssortrr EMPTYSTRINGrEr) ZparamsZ new_paramsZrfc2231_paramsr:valueZencodedZmorZ continuationsZextendedr)r9rrrrrsD   r,us-asciic Csjt|t st|dkr t|S|\}}}|dkr6|}t|d}y t|||Stk rdt|SXdS)Nr_zraw-unicode-escape)r3tuplerDrbytesr4 LookupError)rerrorsZfallback_charsetr9rtextZrawbytesrrrrs   rBc Cs|dkrtjjtjjjS|jdk r.|jS|jdd|f}tj|}tj |}y tj |j d}tj||j }Wnt k r|tjtj|dd}tjo|jdk}|rtjntj }|tj |dkrtj|tj|}n tj|}YnX|j|dS)aReturn local time as an aware datetime object. If called without arguments, return current time. Otherwise *dt* argument should be a datetime instance, and it is converted to the local time zone according to the system time zone database. If *dt* is naive (that is, dt.tzinfo is None), it is assumed to be in local time. In this case, a positive or zero value for *isdst* causes localtime to presume initially that summer time (for example, Daylight Saving Time) is or is not (respectively) in effect for the specified time. A negative value for *isdst* causes the localtime() function to attempt to divine whether summer time is in effect for the specified time. NrB)ryr]r)rnr)rfrprgrhrirnrbreZmktimerkrzZ tm_gmtoffZtm_zoneAttributeErrorZgmtimeZdaylightZtm_isdstZaltzoneZtznamer,) rmZisdstZtmryZlocaltmZdeltar|dstZgmtoffrrrrks$   rk)r0)NFF)F)NN)NN)r,rr)Nr);__doc____all__rrerervrwrfZ urllib.parserZemail._parseaddrrrrPr r r rZ email.charsetrrOrZ UEMPTYSTRINGZCRLFrcompiler5r7r"rrrr*r/rrArHZsupports_strict_parsingrrZrRrSVERBOSE IGNORECASEZecrerdrrr rr rrrASCIIrrrrkrrrrs        !1     $  8 utils.cpython-36.opt-2.pyc000064400000022323147204636050011303 0ustar003 fJ@sdddddddddd d d d d dgZddlZddlZddlZddlZddlZddlZddlZddl m Z ddl m Z ddl m Z ddl mZmZmZddlmZdZdZdZdZdZejdZejdZdZdaddZdd Zd!d"Zd#d$Z dHd&dZ!d'd(Z"d)d*Z#d+Z$dd,d-dZ%d.d/Z&d0d1Z'd2d3Z(ejd4ej)ej*BZ+d5d6Z,dId8dZ-dJd9dZ.dKd:dZ/d;d Z0dd,ddZ3dLd?dZ4ejd@ej5Z6dAdZ7dMdDdZ8dOdFdGZ9dS)Pcollapse_rfc2231_value decode_paramsdecode_rfc2231encode_rfc2231 formataddr formatdateformat_datetime getaddresses make_msgid mktime_tz parseaddr parsedate parsedate_tzparsedate_to_datetimeunquoteN)quote) AddressList)r )r r _parsedate_tz)Charsetz, z 'z[][\\()<>@,:;".]z[\\"]z/etc/python/email.cfgcCstdkrtatS)N)_cached_strict_addr_parsing_use_strict_email_parsing_implrr#/usr/lib64/python3.6/email/utils.py_use_strict_email_parsing7srcCsttjjd}|rdSy tt}Wntk r8YnBX|6ddl}|jdd d}|j ||j dddd}WdQRX|rdSdS) NZ(PYTHON_EMAIL_DISABLE_STRICT_ADDR_PARSINGFr#)Z interpolationZcomment_prefixesZemail_addr_parsing)ZfallbackT)r) boolosenvirongetopen_EMAIL_CONFIG_FILEFileNotFoundError configparserZ ConfigParserZ read_fileZ getboolean)Zdisabledfiler$configrrrr?s"  rc Cs&y |jdStk r dSXdS)NFT)encodeUnicodeEncodeError)srrr_has_surrogates\s r*cCs|jdd}|jddS)Nzutf-8surrogateescapereplace)r'decode)stringZoriginal_bytesrrr _sanitizeis r/utf-8c Cs|\}}|jd|ry|jdWn8tk r\t|trFt|}|j|}d||fSXd}tj|rpd}tj d|}d||||fS|S)Nasciiz%s <%s>r"z\\\g<0>z %s%s%s <%s>) r'r( isinstancestrrZ header_encode specialsresearch escapesresub)ZpaircharsetnameZaddressZ encoded_nameZquotesrrrrus      ccs`d}d}xDt|D]8\}}|r2|d|fVd}q|dkr@d}q||fVqW|r\|dfVdS)NrF\T) enumerate)addrposescapechrrr_iter_escaped_charssrAcCsd|kr |Sd}d}g}xPt|D]D\}}|dkr"|dkr@|}q"||krZ|j||||d}d}q"W|t|kr|j||ddj|S)Nr2rr)rAappendlenjoin)r=startZopen_posresultr>r@rrr_strip_quoted_realnamess  rHT)strictcCs|dkrt}|s4tjdd|D}t|}|jSdd|D}t|}tj|}t|}t|j}d}x&|D]}t|}|d|jd7}qpWt ||krd gS|S) Ncss|]}t|VqdS)N)r4).0vrrr szgetaddresses..cSsg|] }t|qSr)r4)rJrKrrr sz getaddresses..rrB,r)rr) r COMMASPACErE _AddressList addresslist_pre_parse_validation_post_parse_validationrHcountrD)Z fieldvaluesrIallar=rGnrKrrrrs$      cCsXt|}d}xBt|D]6\}}|dkr0|d7}q|dkr|d8}|dkrdSqW|dkS)Nr(rB)F)rHrA)r=Zopensr>r@rrr_check_parenthesiss rZcCs,g}x"|D]}t|sd}|j|q W|S)Nz('', ''))rZrC)Zemail_header_fieldsaccepted_valuesrKrrrrRs  rRcCs0g}x&|D]}d|dkrd}|j|q W|S)N[rBr)rr)rC)Zparsed_email_header_tuplesr[rKrrrrS s   rSa_ =\? # literal =? (?P[^?]*?) # non-greedy up to the next ? is the charset \? # literal ? (?P[qb]) # either a "q" or a "b", case insensitive \? # literal ? (?P.*?) # non-greedy up to the next ?= is the atom \?= # literal ?= cCsfddddddddg|d |d d d d dddddddddg |dd|d|d|d|d|fS)Nz"%s, %02d %s %04d %02d:%02d:%02d %sZMonZTueZWedZThuZFriZSatZSunZJanZFebZMarZAprZMayZJunZJulZAugZSepZOctZNovZDecrBrr) timetuplezonerrr_format_timetuple_and_zone"s rdFcCsR|dkrtj}|s|r,tjj|tjj}n tjj|}|rH|j}d}t||S)NF)timedatetimeZ fromtimestamptimezoneutcZutcfromtimestamp astimezoner)timeval localtimeusegmtdtrrrr+s cCsV|j}|r2|jdks$|jtjjkr,tdd}n|jdkrBd}n |jd}t||S)Nz%usegmt option requires a UTC datetimeZGMTz-0000z%z)rbtzinforfrgrh ValueErrorZstrftimerd)rmrlnowrcrrrrHs  cCs^ttjd}tj}tjd}|dkr0d}nd|}|dkrHtj}d|||||f}|S)Nd@r.z<%d.%d.%d%s@%s>)intrergetpidrandomZ getrandbitssocketZgetfqdn)ZidstringZdomainrjpidZrandintZmsgidrrrr [s  cCsNt|^}}|dkr(tj|ddStj|dddtjtj|diS)Nr]rn)seconds)rrfrg timedelta)dataZdtupletzrrrrrs cCs|dkrt}|s,t|j}|s$dS|dSt|tr>|d}t|tsLdSt|gd}tt|j}| szt|dkr~dS|dS)NrrrB)rr)rr)rr) rrPrQr3listr4rRrSrD)r=rIZaddrsrrrr zs    cCs`t|dkr\|jdr<|jdr<|ddjddjddS|jdr\|jdr\|dd S|S) NrBr2z\\r;z\"<>r)rD startswithendswithr,)r4rrrrs   cCs&|jtd}t|dkr"dd|fS|S)Nr^)splitTICKrD)r)partsrrrrs   cCsDtjj|d|pdd}|dkr*|dkr*|S|dkr6d}d|||fS)Nrr1)Zsafeencodingz%s'%s'%s)urllibparser)r)r9languagerrrrs z&^(?P\w+)\*((?P[0-9]+)\*?)?$c Csx|dd}g}i}|jd\}}|j||fx|r|jd\}}|jdrTd}nd}t|}tj|}|r|jdd\}}|dk rt|}|j|gj|||fq2|j|dt |fq2W|rtx|j D]\}}g}d} |j x6|D].\}} }|rt j j| dd } d} |j| qWt tj|}| r^t|\} } }|j|| | d|ffq|j|d|fqW|S) Nr*TFr:numz"%s"zlatin-1)r)poprCrrrfc2231_continuationmatchgrouprt setdefaultritemssortrr EMPTYSTRINGrEr) ZparamsZ new_paramsZrfc2231_paramsr:valueZencodedZmorZ continuationsZextendedr)r9rrrrrsD   r,us-asciic Csjt|t st|dkr t|S|\}}}|dkr6|}t|d}y t|||Stk rdt|SXdS)Nr_zraw-unicode-escape)r3tuplerDrbytesr4 LookupError)rerrorsZfallback_charsetr9rtextZrawbytesrrrrs   rBc Cs|dkrtjjtjjjS|jdk r.|jS|jdd|f}tj|}tj |}y tj |j d}tj||j }Wnt k r|tjtj|dd}tjo|jdk}|rtjntj }|tj |dkrtj|tj|}n tj|}YnX|j|dS)NrB)ryr]r)rnr)rfrprgrhrirnrbreZmktimerkrzZ tm_gmtoffZtm_zoneAttributeErrorZgmtimeZdaylightZtm_isdstZaltzoneZtznamer,) rmZisdstZtmryZlocaltmZdeltar|dstZgmtoffrrrrks$   rk)r0)NFF)F)NN)NN)r,rr)Nr):__all__rrerervrwrfZ urllib.parserZemail._parseaddrrrrPr r r rZ email.charsetrrOrZ UEMPTYSTRINGZCRLFrcompiler5r7r"rrrr*r/rrArHZsupports_strict_parsingrrZrRrSVERBOSE IGNORECASEZecrerdrrr rr rrrASCIIrrrrkrrrrs        !1     $  8 _encoded_words.cpython-36.opt-1.pyc000064400000012722147204636050013122 0ustar003 \F!@sdZddlZddlZddlZddlZddlmZmZddlm Z ddddd d d d gZ ej ej d j ddZddZGdddeZeZdeed<ddZdd ZddZddZdd ZeedZdd ZeedZeedZddd ZdS) z Routines for manipulating RFC2047 encoded words. This is currently a package-private API, but will be considered for promotion to a public API if there is demand. N) ascii_lettersdigits)errorsdecode_qencode_qdecode_bencode_blen_qlen_bdecodeencodes=([a-fA-F0-9]{2})cCstt|jddgS)N)bytesintgroup)mr,/usr/lib64/python3.6/email/_encoded_words.pyAsrcCs|jdd}t|gfS)N_ )replace_q_byte_subber)encodedrrrrCs c@s,eZdZdejdejdZddZdS) _QByteMaps-!*+/asciicCs.||jkrt|||<ndj|||<||S)Nz={:02X})safechrformat)selfkeyrrr __missing__Ms z_QByteMap.__missing__N)__name__ __module__ __qualname__rr rrr"rrrrrIsr_ cCsdjdd|DS)Ncss|]}t|VqdS)N) _q_byte_map).0xrrr Zszencode_q..)join)bstringrrrrYscCstdd|DS)Ncss|]}tt|VqdS)N)lenr))r*r+rrrr,]szlen_q..)sum)r.rrrr \scCst|d}|r ddd|nd}y$tj||dd|rDtjgngfStjk rytj|ddtjgfStjk ry"tj|dddtjtjgfStjk r|tjgfSXYnXYnXdS)Ns===T)ZvalidateFs==) r/base64Z b64decoderZInvalidBase64PaddingDefectbinasciiErrorZInvalidBase64CharactersDefectZInvalidBase64LengthDefect)rZpad_errZmissing_paddingrrrrds     cCstj|jdS)Nr)r3Z b64encoder )r.rrrrscCs&tt|d\}}|d|r dndS)Nr1r)divmodr/)r.Z groups_of_3Zleftoverrrrr s)qbc Cs|jd\}}}}}|jd\}}}|j}|jdd}t||\}}y|j|}Wnvtk r|jtj dj ||j|d}YnBt k r|jdd}|jdkr|jtj dj |YnX||||fS)aDecode encoded word and return (string, charset, lang, defects) tuple. An RFC 2047/2243 encoded word has the form: =?charset*lang?cte?encoded_string?= where '*lang' may be omitted but the other parts may not be. This function expects exactly such a string (that is, it does not check the syntax and may raise errors if the string is not well formed), and returns the encoded_string decoded first from its Content Transfer Encoding and then from the resulting bytes into unicode using the specified charset. If the cte-decoded string does not successfully decode using the specified character set, a defect is added to the defects list and the unknown octets are replaced by the unicode 'unknown' character \uFDFF. The specified charset and language are returned. The default for language, which is rarely if ever encountered, is the empty string. ?*rsurrogateescapez:Encoded word contains bytes not decodable using {} charsetz unknown-8bitzsB$    &+_encoded_words.cpython-36.pyc000064400000012722147204636050012163 0ustar003 \F!@sdZddlZddlZddlZddlZddlmZmZddlm Z ddddd d d d gZ ej ej d j ddZddZGdddeZeZdeed<ddZdd ZddZddZdd ZeedZdd ZeedZeedZddd ZdS) z Routines for manipulating RFC2047 encoded words. This is currently a package-private API, but will be considered for promotion to a public API if there is demand. N) ascii_lettersdigits)errorsdecode_qencode_qdecode_bencode_blen_qlen_bdecodeencodes=([a-fA-F0-9]{2})cCstt|jddgS)N)bytesintgroup)mr,/usr/lib64/python3.6/email/_encoded_words.pyAsrcCs|jdd}t|gfS)N_ )replace_q_byte_subber)encodedrrrrCs c@s,eZdZdejdejdZddZdS) _QByteMaps-!*+/asciicCs.||jkrt|||<ndj|||<||S)Nz={:02X})safechrformat)selfkeyrrr __missing__Ms z_QByteMap.__missing__N)__name__ __module__ __qualname__rr rrr"rrrrrIsr_ cCsdjdd|DS)Ncss|]}t|VqdS)N) _q_byte_map).0xrrr Zszencode_q..)join)bstringrrrrYscCstdd|DS)Ncss|]}tt|VqdS)N)lenr))r*r+rrrr,]szlen_q..)sum)r.rrrr \scCst|d}|r ddd|nd}y$tj||dd|rDtjgngfStjk rytj|ddtjgfStjk ry"tj|dddtjtjgfStjk r|tjgfSXYnXYnXdS)Ns===T)ZvalidateFs==) r/base64Z b64decoderZInvalidBase64PaddingDefectbinasciiErrorZInvalidBase64CharactersDefectZInvalidBase64LengthDefect)rZpad_errZmissing_paddingrrrrds     cCstj|jdS)Nr)r3Z b64encoder )r.rrrrscCs&tt|d\}}|d|r dndS)Nr1r)divmodr/)r.Z groups_of_3Zleftoverrrrr s)qbc Cs|jd\}}}}}|jd\}}}|j}|jdd}t||\}}y|j|}Wnvtk r|jtj dj ||j|d}YnBt k r|jdd}|jdkr|jtj dj |YnX||||fS)aDecode encoded word and return (string, charset, lang, defects) tuple. An RFC 2047/2243 encoded word has the form: =?charset*lang?cte?encoded_string?= where '*lang' may be omitted but the other parts may not be. This function expects exactly such a string (that is, it does not check the syntax and may raise errors if the string is not well formed), and returns the encoded_string decoded first from its Content Transfer Encoding and then from the resulting bytes into unicode using the specified charset. If the cte-decoded string does not successfully decode using the specified character set, a defect is added to the defects list and the unknown octets are replaced by the unicode 'unknown' character \uFDFF. The specified charset and language are returned. The default for language, which is rarely if ever encountered, is the empty string. ?*rsurrogateescapez:Encoded word contains bytes not decodable using {} charsetz unknown-8bitzsB$    &+__main__.cpython-36.opt-1.pyc000064400000000334147204650000011647 0ustar003 \X@s*ddlZddlZedkr&ejejdS)N__main__)Z ensurepipsys__name__exit_mainrr*/usr/lib64/python3.6/ensurepip/__main__.pys__main__.cpython-36.opt-2.pyc000064400000000334147204650000011650 0ustar003 \X@s*ddlZddlZedkr&ejejdS)N__main__)Z ensurepipsys__name__exit_mainrr*/usr/lib64/python3.6/ensurepip/__main__.pys__main__.cpython-36.pyc000064400000000334147204650000010710 0ustar003 \X@s*ddlZddlZedkr&ejejdS)N__main__)Z ensurepipsys__name__exit_mainrr*/usr/lib64/python3.6/ensurepip/__main__.pys_uninstall.cpython-36.opt-1.pyc000064400000001626147204650000012304 0ustar003 \(@s>dZddlZddlZddlZdddZedkr:ejedS)zDBasic pip uninstallation support, helper for the Windows uninstallerNcCsVtjdd}|jdddjtjdd|jdd d d d d d|j|}tj|jdS)Nzpython -m ensurepip._uninstall)progz --versionversionzpip {}z7Show the version of pip this will attempt to uninstall.)actionrhelpz-vz --verbosecountr verbosityzDGive more output. Option is additive, and can be used up to 3 times.)rdefaultdestr)r) argparseArgumentParser add_argumentformat ensurepipr parse_argsZ_uninstall_helperr)argvparserargsr,/usr/lib64/python3.6/ensurepip/_uninstall.py_mains   r__main__)N)__doc__r rsysr__name__exitrrrrs  _uninstall.cpython-36.opt-2.pyc000064400000001501147204650000012275 0ustar003 \(@s:ddlZddlZddlZdddZedkr6ejedS)NcCsVtjdd}|jdddjtjdd|jdd d d d d d|j|}tj|jdS)Nzpython -m ensurepip._uninstall)progz --versionversionzpip {}z7Show the version of pip this will attempt to uninstall.)actionrhelpz-vz --verbosecountr verbosityzDGive more output. Option is additive, and can be used up to 3 times.)rdefaultdestr)r) argparseArgumentParser add_argumentformat ensurepipr parse_argsZ_uninstall_helperr)argvparserargsr,/usr/lib64/python3.6/ensurepip/_uninstall.py_mains   r__main__)N)r rsysr__name__exitrrrrs  _uninstall.cpython-36.pyc000064400000001626147204650000011345 0ustar003 \(@s>dZddlZddlZddlZdddZedkr:ejedS)zDBasic pip uninstallation support, helper for the Windows uninstallerNcCsVtjdd}|jdddjtjdd|jdd d d d d d|j|}tj|jdS)Nzpython -m ensurepip._uninstall)progz --versionversionzpip {}z7Show the version of pip this will attempt to uninstall.)actionrhelpz-vz --verbosecountr verbosityzDGive more output. Option is additive, and can be used up to 3 times.)rdefaultdestr)r) argparseArgumentParser add_argumentformat ensurepipr parse_argsZ_uninstall_helperr)argvparserargsr,/usr/lib64/python3.6/ensurepip/_uninstall.py_mains   r__main__)N)__doc__r rsysr__name__exitrrrrs  _endian.cpython-36.opt-1.pyc000064400000003606147204665210011542 0ustar003 \@sddlZddlTeeZddZGdddeeZejdkr\dZ eZ Gd d d eed Z n0ejd krd Z eZ Gdddeed Z ne ddS)N)*cCsLt|trt|tSt|tr.t|j|jSt|t r<|St d|dS)zReturn the type with the 'other' byte order. Simple types like c_int and so on already have __ctype_be__ and __ctype_le__ attributes which contain the types, for more complicated types arrays and structures are supported. z+This type does not support other endian: %sN) hasattr _OTHER_ENDIANgetattr isinstance _array_type _other_endianZ_type_Z_length_ issubclass Structure TypeError)typr &/usr/lib64/python3.6/ctypes/_endian.pyrs    rcseZdZfddZZS) _swapped_metacsb|dkrPg}x>|D]6}|d}|d}|dd}|j|t|f|qW|}tj||dS)NZ_fields_r)appendrsuper __setattr__)selfZattrnamevalueZfieldsZdescnamer rest) __class__r rrs  z_swapped_meta.__setattr__)__name__ __module__ __qualname__r __classcell__r r )rrrsrlittleZ __ctype_be__c@seZdZdZfZdZdS)BigEndianStructurez$Structure with big endian byte orderN)rrr__doc__ __slots___swappedbytes_r r r rr.sr) metaclassZbigZ __ctype_le__c@seZdZdZfZdZdS)LittleEndianStructurez'Structure with little endian byte orderN)rrrr r!r"r r r rr$7sr$zInvalid byteorder) sysZctypestypeZArrayrrr r byteorderrr$r RuntimeErrorr r r rs  _endian.cpython-36.opt-2.pyc000064400000003054147204665210011540 0ustar003 \@sddlZddlTeeZddZGdddeeZejdkr\dZ eZ Gd d d eed Z n0ejd krd Z eZ Gdddeed Z ne ddS)N)*cCsLt|trt|tSt|tr.t|j|jSt|t r<|St d|dS)Nz+This type does not support other endian: %s) hasattr _OTHER_ENDIANgetattr isinstance _array_type _other_endianZ_type_Z_length_ issubclass Structure TypeError)typr &/usr/lib64/python3.6/ctypes/_endian.pyrs    rcseZdZfddZZS) _swapped_metacsb|dkrPg}x>|D]6}|d}|d}|dd}|j|t|f|qW|}tj||dS)NZ_fields_r)appendrsuper __setattr__)selfZattrnamevalueZfieldsZdescnamer rest) __class__r rrs  z_swapped_meta.__setattr__)__name__ __module__ __qualname__r __classcell__r r )rrrsrlittleZ __ctype_be__c@seZdZfZdZdS)BigEndianStructureN)rrr __slots___swappedbytes_r r r rr.sr) metaclassZbigZ __ctype_le__c@seZdZfZdZdS)LittleEndianStructureN)rrrr r!r r r rr#7sr#zInvalid byteorder) sysZctypestypeZArrayrrr r byteorderrr#r RuntimeErrorr r r rs  _endian.cpython-36.pyc000064400000003606147204665210010603 0ustar003 \@sddlZddlTeeZddZGdddeeZejdkr\dZ eZ Gd d d eed Z n0ejd krd Z eZ Gdddeed Z ne ddS)N)*cCsLt|trt|tSt|tr.t|j|jSt|t r<|St d|dS)zReturn the type with the 'other' byte order. Simple types like c_int and so on already have __ctype_be__ and __ctype_le__ attributes which contain the types, for more complicated types arrays and structures are supported. z+This type does not support other endian: %sN) hasattr _OTHER_ENDIANgetattr isinstance _array_type _other_endianZ_type_Z_length_ issubclass Structure TypeError)typr &/usr/lib64/python3.6/ctypes/_endian.pyrs    rcseZdZfddZZS) _swapped_metacsb|dkrPg}x>|D]6}|d}|d}|dd}|j|t|f|qW|}tj||dS)NZ_fields_r)appendrsuper __setattr__)selfZattrnamevalueZfieldsZdescnamer rest) __class__r rrs  z_swapped_meta.__setattr__)__name__ __module__ __qualname__r __classcell__r r )rrrsrlittleZ __ctype_be__c@seZdZdZfZdZdS)BigEndianStructurez$Structure with big endian byte orderN)rrr__doc__ __slots___swappedbytes_r r r rr.sr) metaclassZbigZ __ctype_le__c@seZdZdZfZdZdS)LittleEndianStructurez'Structure with little endian byte orderN)rrrr r!r"r r r rr$7sr$zInvalid byteorder) sysZctypestypeZArrayrrr r byteorderrr$r RuntimeErrorr r r rs  wintypes.cpython-36.opt-1.pyc000064400000011751147204665210012027 0ustar003 \@sddlZejZejZejZejZej Z ej Z ej ZejZejZeZejZGdddejZejZejZejZejZejZZej Z!Z"ej#Z$Z%Z&ej#Z'Z(ej)Z*Z+ej,Z-Z.ej/ejej/ej,krejZ0ejZ1n$ej/ejej/ej,krej Z0ejZ1eZ2eZ3eZ4eZ5eZ6eZ7ej,Z8e8Z9e8Z:e8Z;e8Ze8Z?e8Z@e8ZAe8ZBe8ZCe8ZDe8ZEe8ZFe8ZGe8ZHe8ZIe8ZJe8ZKe8ZLe8ZMe8ZNe8ZOe8ZPe8ZQe8ZRe8ZSe8ZTe8ZUe8ZVe8ZWGdddejXZYeYZZZ[Z\GdddejXZ]e]Z^Gdd d ejXZ_Gd d d ejXZ`e`ZaZbZcGd d d ejXZdedZeZfddZgGdddejXZhehZiGdddejXZjejZkdZlGdddejXZmGdddejXZnejoeZpZqejoeZrejoeZsZtejoeZuejoe4ZvejoeZwZxejoehZyZzejoeZ{ejoe8Z|Z}ejoeGZ~ejoeHZejoeZZejoeZejoe7ZejoeZZejoejZZejoe`ZZejoecZejoeYZZejoe\ZZejoeVZejoeZejoedZZejoefZZejoe^Zejoe ZZejoe"ZejoeZejoeZejoe ZejoemZZejoenZZejoeZZdS)Nc@seZdZdZddZdS) VARIANT_BOOLvcCsd|jj|jfS)Nz%s(%r)) __class____name__value)selfr'/usr/lib64/python3.6/ctypes/wintypes.py__repr__szVARIANT_BOOL.__repr__N)r __module__ __qualname__Z_type_r rrrr rsrc@s(eZdZdefdefdefdefgZdS)RECTlefttoprightZbottomN)rr r LONG_fields_rrrr r asr c@s(eZdZdefdefdefdefgZdS) _SMALL_RECTZLeftZTopZRightZBottomN)rr r SHORTrrrrr rhsrc@seZdZdefdefgZdS)_COORDXYN)rr r rrrrrr rosrc@seZdZdefdefgZdS)POINTxyN)rr r rrrrrr rssrc@seZdZdefdefgZdS)SIZEZcxZcyN)rr r rrrrrr rxsrcCs||d>|d>S)Nr)ZredZgreenZbluerrr RGB}src@seZdZdefdefgZdS)FILETIMEZ dwLowDateTimeZdwHighDateTimeN)rr r DWORDrrrrr rsrc@s4eZdZdefdefdefdefdefdefgZ dS)MSGZhWndmessageZwParamZlParamZtimeZptN) rr r HWNDUINTWPARAMLPARAMr rrrrrr r!s r!ic @sTeZdZdefdefdefdefdefdefdefdefd eefd ed fg Zd S) WIN32_FIND_DATAAdwFileAttributesftCreationTimeftLastAccessTimeftLastWriteTime nFileSizeHigh nFileSizeLow dwReserved0 dwReserved1 cFileNamecAlternateFileNameN)rr r r rCHARMAX_PATHrrrrr r's r'c @sTeZdZdefdefdefdefdefdefdefdefd eefd ed fg Zd S) WIN32_FIND_DATAWr(r)r*r+r,r-r.r/r0r1r2N)rr r r rWCHARr4rrrrr r5s r5)ZctypesZc_byteZBYTEZc_ushortZWORDZc_ulongr Zc_charr3Zc_wcharr6Zc_uintr$Zc_intZINTZc_doubleZDOUBLEZc_floatZFLOATZBOOLEANZc_longZBOOLZ _SimpleCDatarZULONGrZUSHORTZc_shortrZ c_longlongZ_LARGE_INTEGERZ LARGE_INTEGERZ c_ulonglongZ_ULARGE_INTEGERZULARGE_INTEGERZ c_wchar_pZ LPCOLESTRZLPOLESTRZOLESTRZLPCWSTRZLPWSTRZc_char_pZLPCSTRZLPSTRZc_void_pZLPCVOIDZLPVOIDZsizeofr%r&ZATOMZLANGIDZCOLORREFZLGRPIDZLCTYPEZLCIDZHANDLEZHACCELZHBITMAPZHBRUSHZ HCOLORSPACEZHDCZHDESKZHDWPZ HENHMETAFILEZHFONTZHGDIOBJZHGLOBALZHHOOKZHICONZ HINSTANCEZHKEYZHKLZHLOCALZHMENUZ HMETAFILEZHMODULEZHMONITORZHPALETTEZHPENZHRGNZHRSRCZHSTRZHTASKZHWINSTAr#Z SC_HANDLEZSERVICE_STATUS_HANDLEZ Structurer ZtagRECTZ_RECTLZRECTLrZ SMALL_RECTrrZtagPOINTZ_POINTLZPOINTLrZtagSIZEZSIZELrrZ _FILETIMEr!ZtagMSGr4r'r5ZPOINTERZLPBOOLZPBOOLZPBOOLEANZLPBYTEZPBYTEZPCHARZ LPCOLORREFZLPDWORDZPDWORDZ LPFILETIMEZ PFILETIMEZPFLOATZLPHANDLEZPHANDLEZPHKEYZLPHKLZLPINTZPINTZPLARGE_INTEGERZPLCIDZLPLONGZPLONGZLPMSGZPMSGZLPPOINTZPPOINTZPPOINTLZLPRECTZPRECTZLPRECTLZPRECTLZ LPSC_HANDLEZPSHORTZLPSIZEZPSIZEZLPSIZELZPSIZELZ PSMALL_RECTZLPUINTZPUINTZPULARGE_INTEGERZPULONGZPUSHORTZPWCHARZLPWIN32_FIND_DATAAZPWIN32_FIND_DATAAZLPWIN32_FIND_DATAWZPWIN32_FIND_DATAWZLPWORDZPWORDrrrr s                        wintypes.cpython-36.opt-2.pyc000064400000011751147204665210012030 0ustar003 \@sddlZejZejZejZejZej Z ej Z ej ZejZejZeZejZGdddejZejZejZejZejZejZZej Z!Z"ej#Z$Z%Z&ej#Z'Z(ej)Z*Z+ej,Z-Z.ej/ejej/ej,krejZ0ejZ1n$ej/ejej/ej,krej Z0ejZ1eZ2eZ3eZ4eZ5eZ6eZ7ej,Z8e8Z9e8Z:e8Z;e8Ze8Z?e8Z@e8ZAe8ZBe8ZCe8ZDe8ZEe8ZFe8ZGe8ZHe8ZIe8ZJe8ZKe8ZLe8ZMe8ZNe8ZOe8ZPe8ZQe8ZRe8ZSe8ZTe8ZUe8ZVe8ZWGdddejXZYeYZZZ[Z\GdddejXZ]e]Z^Gdd d ejXZ_Gd d d ejXZ`e`ZaZbZcGd d d ejXZdedZeZfddZgGdddejXZhehZiGdddejXZjejZkdZlGdddejXZmGdddejXZnejoeZpZqejoeZrejoeZsZtejoeZuejoe4ZvejoeZwZxejoehZyZzejoeZ{ejoe8Z|Z}ejoeGZ~ejoeHZejoeZZejoeZejoe7ZejoeZZejoejZZejoe`ZZejoecZejoeYZZejoe\ZZejoeVZejoeZejoedZZejoefZZejoe^Zejoe ZZejoe"ZejoeZejoeZejoe ZejoemZZejoenZZejoeZZdS)Nc@seZdZdZddZdS) VARIANT_BOOLvcCsd|jj|jfS)Nz%s(%r)) __class____name__value)selfr'/usr/lib64/python3.6/ctypes/wintypes.py__repr__szVARIANT_BOOL.__repr__N)r __module__ __qualname__Z_type_r rrrr rsrc@s(eZdZdefdefdefdefgZdS)RECTlefttoprightZbottomN)rr r LONG_fields_rrrr r asr c@s(eZdZdefdefdefdefgZdS) _SMALL_RECTZLeftZTopZRightZBottomN)rr r SHORTrrrrr rhsrc@seZdZdefdefgZdS)_COORDXYN)rr r rrrrrr rosrc@seZdZdefdefgZdS)POINTxyN)rr r rrrrrr rssrc@seZdZdefdefgZdS)SIZEZcxZcyN)rr r rrrrrr rxsrcCs||d>|d>S)Nr)ZredZgreenZbluerrr RGB}src@seZdZdefdefgZdS)FILETIMEZ dwLowDateTimeZdwHighDateTimeN)rr r DWORDrrrrr rsrc@s4eZdZdefdefdefdefdefdefgZ dS)MSGZhWndmessageZwParamZlParamZtimeZptN) rr r HWNDUINTWPARAMLPARAMr rrrrrr r!s r!ic @sTeZdZdefdefdefdefdefdefdefdefd eefd ed fg Zd S) WIN32_FIND_DATAAdwFileAttributesftCreationTimeftLastAccessTimeftLastWriteTime nFileSizeHigh nFileSizeLow dwReserved0 dwReserved1 cFileNamecAlternateFileNameN)rr r r rCHARMAX_PATHrrrrr r's r'c @sTeZdZdefdefdefdefdefdefdefdefd eefd ed fg Zd S) WIN32_FIND_DATAWr(r)r*r+r,r-r.r/r0r1r2N)rr r r rWCHARr4rrrrr r5s r5)ZctypesZc_byteZBYTEZc_ushortZWORDZc_ulongr Zc_charr3Zc_wcharr6Zc_uintr$Zc_intZINTZc_doubleZDOUBLEZc_floatZFLOATZBOOLEANZc_longZBOOLZ _SimpleCDatarZULONGrZUSHORTZc_shortrZ c_longlongZ_LARGE_INTEGERZ LARGE_INTEGERZ c_ulonglongZ_ULARGE_INTEGERZULARGE_INTEGERZ c_wchar_pZ LPCOLESTRZLPOLESTRZOLESTRZLPCWSTRZLPWSTRZc_char_pZLPCSTRZLPSTRZc_void_pZLPCVOIDZLPVOIDZsizeofr%r&ZATOMZLANGIDZCOLORREFZLGRPIDZLCTYPEZLCIDZHANDLEZHACCELZHBITMAPZHBRUSHZ HCOLORSPACEZHDCZHDESKZHDWPZ HENHMETAFILEZHFONTZHGDIOBJZHGLOBALZHHOOKZHICONZ HINSTANCEZHKEYZHKLZHLOCALZHMENUZ HMETAFILEZHMODULEZHMONITORZHPALETTEZHPENZHRGNZHRSRCZHSTRZHTASKZHWINSTAr#Z SC_HANDLEZSERVICE_STATUS_HANDLEZ Structurer ZtagRECTZ_RECTLZRECTLrZ SMALL_RECTrrZtagPOINTZ_POINTLZPOINTLrZtagSIZEZSIZELrrZ _FILETIMEr!ZtagMSGr4r'r5ZPOINTERZLPBOOLZPBOOLZPBOOLEANZLPBYTEZPBYTEZPCHARZ LPCOLORREFZLPDWORDZPDWORDZ LPFILETIMEZ PFILETIMEZPFLOATZLPHANDLEZPHANDLEZPHKEYZLPHKLZLPINTZPINTZPLARGE_INTEGERZPLCIDZLPLONGZPLONGZLPMSGZPMSGZLPPOINTZPPOINTZPPOINTLZLPRECTZPRECTZLPRECTLZPRECTLZ LPSC_HANDLEZPSHORTZLPSIZEZPSIZEZLPSIZELZPSIZELZ PSMALL_RECTZLPUINTZPUINTZPULARGE_INTEGERZPULONGZPUSHORTZPWCHARZLPWIN32_FIND_DATAAZPWIN32_FIND_DATAAZLPWIN32_FIND_DATAWZPWIN32_FIND_DATAWZLPWORDZPWORDrrrr s                        wintypes.cpython-36.pyc000064400000011751147204665210011070 0ustar003 \@sddlZejZejZejZejZej Z ej Z ej ZejZejZeZejZGdddejZejZejZejZejZejZZej Z!Z"ej#Z$Z%Z&ej#Z'Z(ej)Z*Z+ej,Z-Z.ej/ejej/ej,krejZ0ejZ1n$ej/ejej/ej,krej Z0ejZ1eZ2eZ3eZ4eZ5eZ6eZ7ej,Z8e8Z9e8Z:e8Z;e8Ze8Z?e8Z@e8ZAe8ZBe8ZCe8ZDe8ZEe8ZFe8ZGe8ZHe8ZIe8ZJe8ZKe8ZLe8ZMe8ZNe8ZOe8ZPe8ZQe8ZRe8ZSe8ZTe8ZUe8ZVe8ZWGdddejXZYeYZZZ[Z\GdddejXZ]e]Z^Gdd d ejXZ_Gd d d ejXZ`e`ZaZbZcGd d d ejXZdedZeZfddZgGdddejXZhehZiGdddejXZjejZkdZlGdddejXZmGdddejXZnejoeZpZqejoeZrejoeZsZtejoeZuejoe4ZvejoeZwZxejoehZyZzejoeZ{ejoe8Z|Z}ejoeGZ~ejoeHZejoeZZejoeZejoe7ZejoeZZejoejZZejoe`ZZejoecZejoeYZZejoe\ZZejoeVZejoeZejoedZZejoefZZejoe^Zejoe ZZejoe"ZejoeZejoeZejoe ZejoemZZejoenZZejoeZZdS)Nc@seZdZdZddZdS) VARIANT_BOOLvcCsd|jj|jfS)Nz%s(%r)) __class____name__value)selfr'/usr/lib64/python3.6/ctypes/wintypes.py__repr__szVARIANT_BOOL.__repr__N)r __module__ __qualname__Z_type_r rrrr rsrc@s(eZdZdefdefdefdefgZdS)RECTlefttoprightZbottomN)rr r LONG_fields_rrrr r asr c@s(eZdZdefdefdefdefgZdS) _SMALL_RECTZLeftZTopZRightZBottomN)rr r SHORTrrrrr rhsrc@seZdZdefdefgZdS)_COORDXYN)rr r rrrrrr rosrc@seZdZdefdefgZdS)POINTxyN)rr r rrrrrr rssrc@seZdZdefdefgZdS)SIZEZcxZcyN)rr r rrrrrr rxsrcCs||d>|d>S)Nr)ZredZgreenZbluerrr RGB}src@seZdZdefdefgZdS)FILETIMEZ dwLowDateTimeZdwHighDateTimeN)rr r DWORDrrrrr rsrc@s4eZdZdefdefdefdefdefdefgZ dS)MSGZhWndmessageZwParamZlParamZtimeZptN) rr r HWNDUINTWPARAMLPARAMr rrrrrr r!s r!ic @sTeZdZdefdefdefdefdefdefdefdefd eefd ed fg Zd S) WIN32_FIND_DATAAdwFileAttributesftCreationTimeftLastAccessTimeftLastWriteTime nFileSizeHigh nFileSizeLow dwReserved0 dwReserved1 cFileNamecAlternateFileNameN)rr r r rCHARMAX_PATHrrrrr r's r'c @sTeZdZdefdefdefdefdefdefdefdefd eefd ed fg Zd S) WIN32_FIND_DATAWr(r)r*r+r,r-r.r/r0r1r2N)rr r r rWCHARr4rrrrr r5s r5)ZctypesZc_byteZBYTEZc_ushortZWORDZc_ulongr Zc_charr3Zc_wcharr6Zc_uintr$Zc_intZINTZc_doubleZDOUBLEZc_floatZFLOATZBOOLEANZc_longZBOOLZ _SimpleCDatarZULONGrZUSHORTZc_shortrZ c_longlongZ_LARGE_INTEGERZ LARGE_INTEGERZ c_ulonglongZ_ULARGE_INTEGERZULARGE_INTEGERZ c_wchar_pZ LPCOLESTRZLPOLESTRZOLESTRZLPCWSTRZLPWSTRZc_char_pZLPCSTRZLPSTRZc_void_pZLPCVOIDZLPVOIDZsizeofr%r&ZATOMZLANGIDZCOLORREFZLGRPIDZLCTYPEZLCIDZHANDLEZHACCELZHBITMAPZHBRUSHZ HCOLORSPACEZHDCZHDESKZHDWPZ HENHMETAFILEZHFONTZHGDIOBJZHGLOBALZHHOOKZHICONZ HINSTANCEZHKEYZHKLZHLOCALZHMENUZ HMETAFILEZHMODULEZHMONITORZHPALETTEZHPENZHRGNZHRSRCZHSTRZHTASKZHWINSTAr#Z SC_HANDLEZSERVICE_STATUS_HANDLEZ Structurer ZtagRECTZ_RECTLZRECTLrZ SMALL_RECTrrZtagPOINTZ_POINTLZPOINTLrZtagSIZEZSIZELrrZ _FILETIMEr!ZtagMSGr4r'r5ZPOINTERZLPBOOLZPBOOLZPBOOLEANZLPBYTEZPBYTEZPCHARZ LPCOLORREFZLPDWORDZPDWORDZ LPFILETIMEZ PFILETIMEZPFLOATZLPHANDLEZPHANDLEZPHKEYZLPHKLZLPINTZPINTZPLARGE_INTEGERZPLCIDZLPLONGZPLONGZLPMSGZPMSGZLPPOINTZPPOINTZPPOINTLZLPRECTZPRECTZLPRECTLZPRECTLZ LPSC_HANDLEZPSHORTZLPSIZEZPSIZEZLPSIZELZPSIZELZ PSMALL_RECTZLPUINTZPUINTZPULARGE_INTEGERZPULONGZPUSHORTZPWCHARZLPWIN32_FIND_DATAAZPWIN32_FIND_DATAAZLPWIN32_FIND_DATAWZPWIN32_FIND_DATAWZLPWORDZPWORDrrrr s                        abc.cpython-36.opt-1.pyc000064400000000271147204733570010672 0ustar003 \D@sddlTddlmZdS))*)__all__N)_collections_abcrrr'/usr/lib64/python3.6/collections/abc.pysabc.cpython-36.opt-2.pyc000064400000000271147204733570010673 0ustar003 \D@sddlTddlmZdS))*)__all__N)_collections_abcrrr'/usr/lib64/python3.6/collections/abc.pysabc.cpython-36.pyc000064400000000271147204733570007733 0ustar003 \D@sddlTddlmZdS))*)__all__N)_collections_abcrrr'/usr/lib64/python3.6/collections/abc.pyseasy_install.cpython-36.opt-1.pyc000064400000000403147204744630012630 0ustar003 9f~@s"dZedkrddlmZedS)zRun the EasyInstall command__main__)mainN)__doc____name__Zsetuptools.command.easy_installrrr"/usr/lib/python3.6/easy_install.pys easy_install.cpython-36.pyc000064400000000403147204744630011671 0ustar003 9f~@s"dZedkrddlmZedS)zRun the EasyInstall command__main__)mainN)__doc____name__Zsetuptools.command.easy_installrrr"/usr/lib/python3.6/easy_install.pys six.cpython-36.opt-1.pyc000064400000060674147204744630010764 0ustar003 ]xK@sdZddlmZddlZddlZddlZddlZddlZdZdZ ej ddkZ ej ddkZ ej dddkZ e refZefZefZeZeZejZnefZeefZeejfZeZeZejjd redZnLGd d d eZ ye!e Wn e"k r edZYn XedZ[ ddZ#ddZ$GdddeZ%Gddde%Z&Gdddej'Z(Gddde%Z)GdddeZ*e*e+Z,Gddde(Z-e)ddd d!e)d"d#d$d%d"e)d&d#d#d'd&e)d(d)d$d*d(e)d+d)d,e)d-d#d$d.d-e)d/d0d0d1d/e)d2d0d0d/d2e)d3d4d5e)d6d)d$d7d6e)d8d)e r&d9nd:d;e)dd?d@dAe)d!d!d e)dBdBdCe)dDdDdCe)dEdEdCe)d7d)d$d7d6e)dFd#d$dGdFe)dHd#d#dIdHe&d$d)e&dJdKe&dLdMe&dNdOdPe&dQdRdQe&dSdTdUe&dVdWdXe&dYdZd[e&d\d]d^e&d_d`dae&dbdcdde&dedfdge&dhdidje&dkdldme&dndodpe&dqdqdre&dsdsdre&dtdtdre&dududve&dwdxe&dydze&d{d|e&d}d~d}e&dde&ddde&ddde&ddde&ddde&ddde&ddde&ddde&ddde&ddde&ddde&ddde&ddde&ddde&ddde&de+dde&de+dde&de+de+de&ddde&ddde&dddg@Z.ejdkrne.e&ddg7Z.x:e.D]2Z/e0e-e/j1e/e2e/e&rte,j3e/de/j1qtW[/e.e-_.e-e+dZ4e,j3e4dGddde(Z5e)ddde)ddde)ddde)ddde)ddde)ddde)ddde)ddde)ddde)ddde)dAdde)ddde)ddde)ddde)dddddσe)ddde)ddde)ddde)ddde)ddde)ddde)ddde)ddde)ddde)dddgZ6xe6D]Z/e0e5e/j1e/qW[/e6e5_.e,j3e5e+dddۃGdd݄de(Z7e)ddde)ddde)dddgZ8xe8D]Z/e0e7e/j1e/qPW[/e8e7_.e,j3e7e+dddGddde(Z9e)ddde)ddde)ddde)ddde)ddde)ddde)ddde)ddde)ddde)ddde)ddde)ddde)ddde)ddde)ddde)ddde)ddde)ddde)ddde)ddde)ddde)ddde)ddde)ddde)ddde)ddde)ddde)ddde)ddde)ddde)ddde)ddde)ddde)d dde)d ddg#Z:xe:D]Z/e0e9e/j1e/qW[/e:e9_.e,j3e9e+d d d Gddde(Z;e)ddde)ddde)ddde)dddgZxe>D]Z/e0e=e/j1e/ qW[/e>e=_.e,j3e=e+dddGdddej'Z?e,j3e?e+dd d!d"Z@d#d$ZAe rd%ZBd&ZCd'ZDd(ZEd)ZFd*ZGn$d+ZBd,ZCd-ZDd.ZEd/ZFd0ZGyeHZIWn"eJk r d1d2ZIYnXeIZHyeKZKWn"eJk r<d3d4ZKYnXe rhd5d6ZLejMZNd7d8ZOeZPn>d9d6ZLd:d;ZNd<d8ZOGd=d>d>eZPeKZKe#eLd?ejQeBZRejQeCZSejQeDZTejQeEZUejQeFZVejQeGZWe rJd@dAZXdBdCZYdDdEZZdFdGZ[ej\dHZ]ej\dIZ^ej\dJZ_nTdKdAZXdLdCZYdMdEZZdNdGZ[ej\dOZ]ej\dPZ^ej\dQZ_e#eXdRe#eYdSe#eZdTe#e[dUe rbdVdWZ`dXdYZaebZcddldZdedjedZjfZg[dejhdZiejjZkelZmddlnZnenjoZoenjpZpd[Zqej d d k rTd\Zrd]Zsn d^Zrd_Zsnjd`dWZ`dadYZaecZcebZgdbdcZidddeZkejtejuevZmddloZoeojoZoZpdfZqd\Zrd]Zse#e`dge#eadhdid[Zwdjd^Zxdkd_Zye r.eze4j{dlZ|ddmdnZ}nddodpZ|e|dqej dddk rje|drn.ej dddk re|dsn dtduZ~eze4j{dvdZedk rdwdxZej dddk reZdydxZe#e}dzej dddkrejejfd{d|ZnejZd}d~ZddZddZgZe+Zejddk rjge_ejrx>eejD]0\ZZeej+dkr~ej1e+kr~eje=Pq~W[[ejje,dS(z6Utilities for writing code that runs on Python 2 and 3)absolute_importNz'Benjamin Peterson z1.11.0javac@seZdZddZdS)XcCsdS)Nrrl)selfr r /usr/lib/python3.6/six.py__len__>sz X.__len__N)__name__ __module__ __qualname__r r r r r r <sr ?cCs ||_dS)z Add documentation to a function.N)__doc__)funcdocr r r _add_docKsrcCst|tj|S)z7Import module, returning the module after the last dot.) __import__sysmodules)namer r r _import_modulePsrc@seZdZddZddZdS) _LazyDescrcCs ||_dS)N)r)r rr r r __init__Xsz_LazyDescr.__init__c CsB|j}t||j|yt|j|jWntk r<YnX|S)N)_resolvesetattrrdelattr __class__AttributeError)r objtpresultr r r __get__[sz_LazyDescr.__get__N)rrrrr%r r r r rVsrcs.eZdZdfdd ZddZddZZS) MovedModuleNcs2tt|j|tr(|dkr |}||_n||_dS)N)superr&rPY3mod)r roldnew)r r r ris zMovedModule.__init__cCs t|jS)N)rr))r r r r rrszMovedModule._resolvecCs"|j}t||}t||||S)N)rgetattrr)r attr_modulevaluer r r __getattr__us  zMovedModule.__getattr__)N)rrrrrr0 __classcell__r r )r r r&gs r&cs(eZdZfddZddZgZZS) _LazyModulecstt|j||jj|_dS)N)r'r2rr r)r r)r r r r~sz_LazyModule.__init__cCs ddg}|dd|jD7}|S)NrrcSsg|] }|jqSr )r).0r-r r r sz'_LazyModule.__dir__..)_moved_attributes)r attrsr r r __dir__sz_LazyModule.__dir__)rrrrr7r5r1r r )r r r2|s r2cs&eZdZdfdd ZddZZS)MovedAttributeNcsdtt|j|trH|dkr |}||_|dkr@|dkr<|}n|}||_n||_|dkrZ|}||_dS)N)r'r8rr(r)r-)r rZold_modZnew_modZold_attrZnew_attr)r r r rszMovedAttribute.__init__cCst|j}t||jS)N)rr)r,r-)r moduler r r rs zMovedAttribute._resolve)NN)rrrrrr1r r )r r r8sr8c@sVeZdZdZddZddZddZdd d Zd d Zd dZ ddZ ddZ e Z dS)_SixMetaPathImporterz A meta path importer to import six.moves and its submodules. This class implements a PEP302 finder and loader. It should be compatible with Python 2.5 and all existing versions of Python3 cCs||_i|_dS)N)r known_modules)r Zsix_module_namer r r rsz_SixMetaPathImporter.__init__cGs&x |D]}||j|jd|<qWdS)N.)r;r)r r)Z fullnamesfullnamer r r _add_modules z _SixMetaPathImporter._add_modulecCs|j|jd|S)Nr<)r;r)r r=r r r _get_modulesz _SixMetaPathImporter._get_moduleNcCs||jkr|SdS)N)r;)r r=pathr r r find_modules z _SixMetaPathImporter.find_modulec Cs0y |j|Stk r*td|YnXdS)Nz!This loader does not know module )r;KeyError ImportError)r r=r r r Z __get_modules z!_SixMetaPathImporter.__get_modulec CsRy tj|Stk rYnX|j|}t|tr>|j}n||_|tj|<|S)N)rrrB _SixMetaPathImporter__get_module isinstancer&r __loader__)r r=r)r r r load_modules     z _SixMetaPathImporter.load_modulecCst|j|dS)z Return true, if the named module is a package. We need this method to get correct spec objects with Python 3.4 (see PEP451) __path__)hasattrrD)r r=r r r is_packagesz_SixMetaPathImporter.is_packagecCs|j|dS)z;Return None Required, if is_package is implementedN)rD)r r=r r r get_codes z_SixMetaPathImporter.get_code)N) rrrrrr>r?rArDrGrJrK get_sourcer r r r r:s  r:c@seZdZdZgZdS) _MovedItemszLazy loading of moved objectsN)rrrrrHr r r r rMsrMZ cStringIOioStringIOfilter itertoolsbuiltinsZifilter filterfalseZ ifilterfalseinputZ __builtin__Z raw_inputinternrmapimapgetcwdosZgetcwdugetcwdbZ getoutputZcommands subprocessrangeZxrangeZ reload_module importlibZimpreloadreduce functoolsZ shlex_quoteZpipesZshlexZquoteUserDict collectionsUserList UserStringzipZizip zip_longestZ izip_longestZ configparserZ ConfigParsercopyregZcopy_regZdbm_gnuZgdbmzdbm.gnuZ _dummy_threadZ dummy_threadZhttp_cookiejarZ cookielibzhttp.cookiejarZ http_cookiesZCookiez http.cookiesZ html_entitiesZhtmlentitydefsz html.entitiesZ html_parserZ HTMLParserz html.parserZ http_clientZhttplibz http.clientZemail_mime_basezemail.MIMEBasezemail.mime.baseZemail_mime_imagezemail.MIMEImagezemail.mime.imageZemail_mime_multipartzemail.MIMEMultipartzemail.mime.multipartZemail_mime_nonmultipartzemail.MIMENonMultipartzemail.mime.nonmultipartZemail_mime_textzemail.MIMETextzemail.mime.textZBaseHTTPServerz http.serverZ CGIHTTPServerZSimpleHTTPServerZcPicklepickleZqueueZQueuereprlibreprZ socketserverZ SocketServer_threadZthreadZtkinterZTkinterZtkinter_dialogZDialogztkinter.dialogZtkinter_filedialogZ FileDialogztkinter.filedialogZtkinter_scrolledtextZ ScrolledTextztkinter.scrolledtextZtkinter_simpledialogZ SimpleDialogztkinter.simpledialogZ tkinter_tixZTixz tkinter.tixZ tkinter_ttkZttkz tkinter.ttkZtkinter_constantsZ Tkconstantsztkinter.constantsZ tkinter_dndZTkdndz tkinter.dndZtkinter_colorchooserZtkColorChooserztkinter.colorchooserZtkinter_commondialogZtkCommonDialogztkinter.commondialogZtkinter_tkfiledialogZ tkFileDialogZ tkinter_fontZtkFontz tkinter.fontZtkinter_messageboxZ tkMessageBoxztkinter.messageboxZtkinter_tksimpledialogZtkSimpleDialogZ urllib_parsez.moves.urllib_parsez urllib.parseZ urllib_errorz.moves.urllib_errorz urllib.errorZurllibz .moves.urllibZurllib_robotparser robotparserzurllib.robotparserZ xmlrpc_clientZ xmlrpclibz xmlrpc.clientZ xmlrpc_serverZSimpleXMLRPCServerz xmlrpc.serverZwin32winreg_winregzmoves.z.movesmovesc@seZdZdZdS)Module_six_moves_urllib_parsez7Lazy loading of moved objects in six.moves.urllib_parseN)rrrrr r r r rpBsrpZ ParseResultZurlparseZ SplitResultZparse_qsZ parse_qslZ urldefragZurljoinZurlsplitZ urlunparseZ urlunsplitZ quote_plusZunquoteZ unquote_plusZunquote_to_bytesZ urlencodeZ splitqueryZsplittagZ splituserZ splitvalueZ uses_fragmentZ uses_netlocZ uses_paramsZ uses_queryZ uses_relativezmoves.urllib_parsezmoves.urllib.parsec@seZdZdZdS)Module_six_moves_urllib_errorz7Lazy loading of moved objects in six.moves.urllib_errorN)rrrrr r r r rqlsrqZURLErrorZurllib2Z HTTPErrorZContentTooShortErrorz.moves.urllib.errorzmoves.urllib_errorzmoves.urllib.errorc@seZdZdZdS)Module_six_moves_urllib_requestz9Lazy loading of moved objects in six.moves.urllib_requestN)rrrrr r r r rrsrrZurlopenzurllib.requestZinstall_openerZ build_openerZ pathname2urlZ url2pathnameZ getproxiesZRequestZOpenerDirectorZHTTPDefaultErrorHandlerZHTTPRedirectHandlerZHTTPCookieProcessorZ ProxyHandlerZ BaseHandlerZHTTPPasswordMgrZHTTPPasswordMgrWithDefaultRealmZAbstractBasicAuthHandlerZHTTPBasicAuthHandlerZProxyBasicAuthHandlerZAbstractDigestAuthHandlerZHTTPDigestAuthHandlerZProxyDigestAuthHandlerZ HTTPHandlerZ HTTPSHandlerZ FileHandlerZ FTPHandlerZCacheFTPHandlerZUnknownHandlerZHTTPErrorProcessorZ urlretrieveZ urlcleanupZ URLopenerZFancyURLopenerZ proxy_bypassZparse_http_listZparse_keqv_listz.moves.urllib.requestzmoves.urllib_requestzmoves.urllib.requestc@seZdZdZdS) Module_six_moves_urllib_responsez:Lazy loading of moved objects in six.moves.urllib_responseN)rrrrr r r r rssrsZaddbasezurllib.responseZ addclosehookZaddinfoZ addinfourlz.moves.urllib.responsezmoves.urllib_responsezmoves.urllib.responsec@seZdZdZdS)#Module_six_moves_urllib_robotparserz=Lazy loading of moved objects in six.moves.urllib_robotparserN)rrrrr r r r rtsrtZRobotFileParserz.moves.urllib.robotparserzmoves.urllib_robotparserzmoves.urllib.robotparserc@sNeZdZdZgZejdZejdZejdZ ejdZ ejdZ ddZ d S) Module_six_moves_urllibzICreate a six.moves.urllib namespace that resembles the Python 3 namespacezmoves.urllib_parsezmoves.urllib_errorzmoves.urllib_requestzmoves.urllib_responsezmoves.urllib_robotparsercCsdddddgS)Nparseerrorrequestresponserlr )r r r r r7szModule_six_moves_urllib.__dir__N) rrrrrH _importerr?rvrwrxryrlr7r r r r rus     ruz moves.urllibcCstt|j|dS)zAdd an item to six.moves.N)rrMr)Zmover r r add_movesr{cCsXytt|WnDtk rRy tj|=Wn"tk rLtd|fYnXYnXdS)zRemove item from six.moves.zno such move, %rN)rrMr!ro__dict__rB)rr r r remove_moves r}__func____self__ __closure____code__ __defaults__ __globals__im_funcZim_selfZ func_closureZ func_codeZ func_defaultsZ func_globalscCs|jS)N)next)itr r r advance_iteratorsrcCstddt|jDS)Ncss|]}d|jkVqdS)__call__N)r|)r3klassr r r szcallable..)anytype__mro__)r"r r r callablesrcCs|S)Nr )unboundr r r get_unbound_functionsrcCs|S)Nr )rclsr r r create_unbound_method#srcCs|jS)N)r)rr r r r(scCstj|||jS)N)types MethodTyper )rr"r r r create_bound_method+srcCstj|d|S)N)rr)rrr r r r.sc@seZdZddZdS)IteratorcCst|j|S)N)r__next__)r r r r r3sz Iterator.nextN)rrrrr r r r r1srz3Get the function out of a possibly unbound functioncKst|jf|S)N)iterkeys)dkwr r r iterkeysDsrcKst|jf|S)N)rvalues)rrr r r itervaluesGsrcKst|jf|S)N)ritems)rrr r r iteritemsJsrcKst|jf|S)N)rZlists)rrr r r iterlistsMsrrrrcKs |jf|S)N)r)rrr r r rVscKs |jf|S)N)r)rrr r r rYscKs |jf|S)N)r)rrr r r r\scKs |jf|S)N)r)rrr r r r_sviewkeys viewvalues viewitemsz1Return an iterator over the keys of a dictionary.z3Return an iterator over the values of a dictionary.z?Return an iterator over the (key, value) pairs of a dictionary.zBReturn an iterator over the (key, [values]) pairs of a dictionary.cCs |jdS)Nzlatin-1)encode)sr r r bqsrcCs|S)Nr )rr r r utsrz>BassertCountEqualZassertRaisesRegexpZassertRegexpMatchesassertRaisesRegex assertRegexcCs|S)Nr )rr r r rscCst|jdddS)Nz\\z\\\\Zunicode_escape)unicodereplace)rr r r rscCs t|dS)Nr)ord)Zbsr r r byte2intsrcCs t||S)N)r)Zbufir r r indexbytessrZassertItemsEqualz Byte literalz Text literalcOst|t||S)N)r,_assertCountEqual)r argskwargsr r r rscOst|t||S)N)r,_assertRaisesRegex)r rrr r r rscOst|t||S)N)r, _assertRegex)r rrr r r rsexecc Cs:z*|dkr|}|j|k r$|j||Wdd}d}XdS)N) __traceback__with_traceback)r#r/tbr r r reraises  rcCsB|dkr*tjd}|j}|dkr&|j}~n |dkr6|}tddS)zExecute code in a namespace.Nrzexec _code_ in _globs_, _locs_)r _getframe f_globalsf_localsr)Z_code_Z_globs_Z_locs_framer r r exec_s rzedef reraise(tp, value, tb=None): try: raise tp, value, tb finally: tb = None zdef raise_from(value, from_value): try: if from_value is None: raise value raise value from from_value finally: value = None zrdef raise_from(value, from_value): try: raise value from from_value finally: value = None cCs|dS)Nr )r/Z from_valuer r r raise_fromsrprintc s6|jdtjdkrdSfdd}d}|jdd}|dk r`t|trNd}nt|ts`td|jd d}|dk rt|trd}nt|tstd |rtd |sx|D]}t|trd}PqW|rtd }td }nd }d }|dkr|}|dkr|}x,t|D] \} }| r||||qW||dS)z4The new-style print function for Python 2.4 and 2.5.fileNcsdt|tst|}ttrVt|trVjdk rVtdd}|dkrHd}|jj|}j|dS)Nerrorsstrict) rE basestringstrrrencodingr,rwrite)datar)fpr r rs     zprint_..writeFsepTzsep must be None or a stringendzend must be None or a stringz$invalid keyword arguments to print()  )poprstdoutrErr TypeError enumerate) rrrZ want_unicoderrargnewlineZspacerr )rr print_sL           rcOs<|jdtj}|jdd}t|||r8|dk r8|jdS)NrflushF)getrrr_printr)rrrrr r r rs    zReraise an exception.csfdd}|S)Ncstj|}|_|S)N)r`wraps __wrapped__)f)assignedupdatedwrappedr r wrapper*szwraps..wrapperr )rrrrr )rrrr r(srcs&Gfdddt}tj|dfiS)z%Create a base class with a metaclass.cs,eZdZfddZefddZdS)z!with_metaclass..metaclasscs ||S)Nr )rr this_basesr)basesmetar r __new__:sz)with_metaclass..metaclass.__new__cs j|S)N) __prepare__)rrr)rrr r r=sz-with_metaclass..metaclass.__prepare__N)rrrr classmethodrr )rrr r metaclass8srZtemporary_class)rr)rrrr )rrr with_metaclass3srcsfdd}|S)z6Class decorator for creating a class with a metaclass.csl|jj}|jd}|dk rDt|tr,|g}x|D]}|j|q2W|jdd|jdd|j|j|S)N __slots__r| __weakref__)r|copyrrErrr __bases__)rZ orig_varsslotsZ slots_var)rr r rEs      zadd_metaclass..wrapperr )rrr )rr add_metaclassCs rcCs2tr.d|jkrtd|j|j|_dd|_|S)a A decorator that defines __unicode__ and __str__ methods under Python 2. Under Python 3 it does nothing. To support Python 2 and 3 with a single code base, define a __str__ method returning text and apply this decorator to the class. __str__zY@python_2_unicode_compatible cannot be applied to %s because it doesn't define __str__().cSs|jjdS)Nzutf-8) __unicode__r)r r r r asz-python_2_unicode_compatible..)PY2r| ValueErrorrrr)rr r r python_2_unicode_compatibleSs   r__spec__)rrlilill)N)NN)rr)rr)rr)rr)rZ __future__rr`rQoperatorrr __author__ __version__ version_inforr(ZPY34rZ string_typesintZ integer_typesrZ class_typesZ text_typebytesZ binary_typemaxsizeZMAXSIZErZlongZ ClassTyperplatform startswithobjectr len OverflowErrorrrrr& ModuleTyper2r8r:rrzrMr5r-rrrEr>rorpZ_urllib_parse_moved_attributesrqZ_urllib_error_moved_attributesrrZ _urllib_request_moved_attributesrsZ!_urllib_response_moved_attributesrtZ$_urllib_robotparser_moved_attributesrur{r}Z _meth_funcZ _meth_selfZ _func_closureZ _func_codeZ_func_defaultsZ _func_globalsrr NameErrorrrrrrr attrgetterZget_method_functionZget_method_selfZget_function_closureZget_function_codeZget_function_defaultsZget_function_globalsrrrr methodcallerrrrrrchrZunichrstructStructpackZint2byte itemgetterrgetitemrrZ iterbytesrNrOBytesIOrrrpartialrWrrrrr,rRrrrrrWRAPPER_ASSIGNMENTSWRAPPER_UPDATESrrrrrH __package__globalsrrsubmodule_search_locations meta_pathrrZimporterappendr r r r s     >                                                                                                                                                                5      six.cpython-36.pyc000064400000060674147204744630010025 0ustar003 ]xK@sdZddlmZddlZddlZddlZddlZddlZdZdZ ej ddkZ ej ddkZ ej dddkZ e refZefZefZeZeZejZnefZeefZeejfZeZeZejjd redZnLGd d d eZ ye!e Wn e"k r edZYn XedZ[ ddZ#ddZ$GdddeZ%Gddde%Z&Gdddej'Z(Gddde%Z)GdddeZ*e*e+Z,Gddde(Z-e)ddd d!e)d"d#d$d%d"e)d&d#d#d'd&e)d(d)d$d*d(e)d+d)d,e)d-d#d$d.d-e)d/d0d0d1d/e)d2d0d0d/d2e)d3d4d5e)d6d)d$d7d6e)d8d)e r&d9nd:d;e)dd?d@dAe)d!d!d e)dBdBdCe)dDdDdCe)dEdEdCe)d7d)d$d7d6e)dFd#d$dGdFe)dHd#d#dIdHe&d$d)e&dJdKe&dLdMe&dNdOdPe&dQdRdQe&dSdTdUe&dVdWdXe&dYdZd[e&d\d]d^e&d_d`dae&dbdcdde&dedfdge&dhdidje&dkdldme&dndodpe&dqdqdre&dsdsdre&dtdtdre&dududve&dwdxe&dydze&d{d|e&d}d~d}e&dde&ddde&ddde&ddde&ddde&ddde&ddde&ddde&ddde&ddde&ddde&ddde&ddde&ddde&ddde&de+dde&de+dde&de+de+de&ddde&ddde&dddg@Z.ejdkrne.e&ddg7Z.x:e.D]2Z/e0e-e/j1e/e2e/e&rte,j3e/de/j1qtW[/e.e-_.e-e+dZ4e,j3e4dGddde(Z5e)ddde)ddde)ddde)ddde)ddde)ddde)ddde)ddde)ddde)ddde)dAdde)ddde)ddde)ddde)dddddσe)ddde)ddde)ddde)ddde)ddde)ddde)ddde)ddde)ddde)dddgZ6xe6D]Z/e0e5e/j1e/qW[/e6e5_.e,j3e5e+dddۃGdd݄de(Z7e)ddde)ddde)dddgZ8xe8D]Z/e0e7e/j1e/qPW[/e8e7_.e,j3e7e+dddGddde(Z9e)ddde)ddde)ddde)ddde)ddde)ddde)ddde)ddde)ddde)ddde)ddde)ddde)ddde)ddde)ddde)ddde)ddde)ddde)ddde)ddde)ddde)ddde)ddde)ddde)ddde)ddde)ddde)ddde)ddde)ddde)ddde)ddde)ddde)d dde)d ddg#Z:xe:D]Z/e0e9e/j1e/qW[/e:e9_.e,j3e9e+d d d Gddde(Z;e)ddde)ddde)ddde)dddgZxe>D]Z/e0e=e/j1e/ qW[/e>e=_.e,j3e=e+dddGdddej'Z?e,j3e?e+dd d!d"Z@d#d$ZAe rd%ZBd&ZCd'ZDd(ZEd)ZFd*ZGn$d+ZBd,ZCd-ZDd.ZEd/ZFd0ZGyeHZIWn"eJk r d1d2ZIYnXeIZHyeKZKWn"eJk r<d3d4ZKYnXe rhd5d6ZLejMZNd7d8ZOeZPn>d9d6ZLd:d;ZNd<d8ZOGd=d>d>eZPeKZKe#eLd?ejQeBZRejQeCZSejQeDZTejQeEZUejQeFZVejQeGZWe rJd@dAZXdBdCZYdDdEZZdFdGZ[ej\dHZ]ej\dIZ^ej\dJZ_nTdKdAZXdLdCZYdMdEZZdNdGZ[ej\dOZ]ej\dPZ^ej\dQZ_e#eXdRe#eYdSe#eZdTe#e[dUe rbdVdWZ`dXdYZaebZcddldZdedjedZjfZg[dejhdZiejjZkelZmddlnZnenjoZoenjpZpd[Zqej d d k rTd\Zrd]Zsn d^Zrd_Zsnjd`dWZ`dadYZaecZcebZgdbdcZidddeZkejtejuevZmddloZoeojoZoZpdfZqd\Zrd]Zse#e`dge#eadhdid[Zwdjd^Zxdkd_Zye r.eze4j{dlZ|ddmdnZ}nddodpZ|e|dqej dddk rje|drn.ej dddk re|dsn dtduZ~eze4j{dvdZedk rdwdxZej dddk reZdydxZe#e}dzej dddkrejejfd{d|ZnejZd}d~ZddZddZgZe+Zejddk rjge_ejrx>eejD]0\ZZeej+dkr~ej1e+kr~eje=Pq~W[[ejje,dS(z6Utilities for writing code that runs on Python 2 and 3)absolute_importNz'Benjamin Peterson z1.11.0javac@seZdZddZdS)XcCsdS)Nrrl)selfr r /usr/lib/python3.6/six.py__len__>sz X.__len__N)__name__ __module__ __qualname__r r r r r r <sr ?cCs ||_dS)z Add documentation to a function.N)__doc__)funcdocr r r _add_docKsrcCst|tj|S)z7Import module, returning the module after the last dot.) __import__sysmodules)namer r r _import_modulePsrc@seZdZddZddZdS) _LazyDescrcCs ||_dS)N)r)r rr r r __init__Xsz_LazyDescr.__init__c CsB|j}t||j|yt|j|jWntk r<YnX|S)N)_resolvesetattrrdelattr __class__AttributeError)r objtpresultr r r __get__[sz_LazyDescr.__get__N)rrrrr%r r r r rVsrcs.eZdZdfdd ZddZddZZS) MovedModuleNcs2tt|j|tr(|dkr |}||_n||_dS)N)superr&rPY3mod)r roldnew)r r r ris zMovedModule.__init__cCs t|jS)N)rr))r r r r rrszMovedModule._resolvecCs"|j}t||}t||||S)N)rgetattrr)r attr_modulevaluer r r __getattr__us  zMovedModule.__getattr__)N)rrrrrr0 __classcell__r r )r r r&gs r&cs(eZdZfddZddZgZZS) _LazyModulecstt|j||jj|_dS)N)r'r2rr r)r r)r r r r~sz_LazyModule.__init__cCs ddg}|dd|jD7}|S)NrrcSsg|] }|jqSr )r).0r-r r r sz'_LazyModule.__dir__..)_moved_attributes)r attrsr r r __dir__sz_LazyModule.__dir__)rrrrr7r5r1r r )r r r2|s r2cs&eZdZdfdd ZddZZS)MovedAttributeNcsdtt|j|trH|dkr |}||_|dkr@|dkr<|}n|}||_n||_|dkrZ|}||_dS)N)r'r8rr(r)r-)r rZold_modZnew_modZold_attrZnew_attr)r r r rszMovedAttribute.__init__cCst|j}t||jS)N)rr)r,r-)r moduler r r rs zMovedAttribute._resolve)NN)rrrrrr1r r )r r r8sr8c@sVeZdZdZddZddZddZdd d Zd d Zd dZ ddZ ddZ e Z dS)_SixMetaPathImporterz A meta path importer to import six.moves and its submodules. This class implements a PEP302 finder and loader. It should be compatible with Python 2.5 and all existing versions of Python3 cCs||_i|_dS)N)r known_modules)r Zsix_module_namer r r rsz_SixMetaPathImporter.__init__cGs&x |D]}||j|jd|<qWdS)N.)r;r)r r)Z fullnamesfullnamer r r _add_modules z _SixMetaPathImporter._add_modulecCs|j|jd|S)Nr<)r;r)r r=r r r _get_modulesz _SixMetaPathImporter._get_moduleNcCs||jkr|SdS)N)r;)r r=pathr r r find_modules z _SixMetaPathImporter.find_modulec Cs0y |j|Stk r*td|YnXdS)Nz!This loader does not know module )r;KeyError ImportError)r r=r r r Z __get_modules z!_SixMetaPathImporter.__get_modulec CsRy tj|Stk rYnX|j|}t|tr>|j}n||_|tj|<|S)N)rrrB _SixMetaPathImporter__get_module isinstancer&r __loader__)r r=r)r r r load_modules     z _SixMetaPathImporter.load_modulecCst|j|dS)z Return true, if the named module is a package. We need this method to get correct spec objects with Python 3.4 (see PEP451) __path__)hasattrrD)r r=r r r is_packagesz_SixMetaPathImporter.is_packagecCs|j|dS)z;Return None Required, if is_package is implementedN)rD)r r=r r r get_codes z_SixMetaPathImporter.get_code)N) rrrrrr>r?rArDrGrJrK get_sourcer r r r r:s  r:c@seZdZdZgZdS) _MovedItemszLazy loading of moved objectsN)rrrrrHr r r r rMsrMZ cStringIOioStringIOfilter itertoolsbuiltinsZifilter filterfalseZ ifilterfalseinputZ __builtin__Z raw_inputinternrmapimapgetcwdosZgetcwdugetcwdbZ getoutputZcommands subprocessrangeZxrangeZ reload_module importlibZimpreloadreduce functoolsZ shlex_quoteZpipesZshlexZquoteUserDict collectionsUserList UserStringzipZizip zip_longestZ izip_longestZ configparserZ ConfigParsercopyregZcopy_regZdbm_gnuZgdbmzdbm.gnuZ _dummy_threadZ dummy_threadZhttp_cookiejarZ cookielibzhttp.cookiejarZ http_cookiesZCookiez http.cookiesZ html_entitiesZhtmlentitydefsz html.entitiesZ html_parserZ HTMLParserz html.parserZ http_clientZhttplibz http.clientZemail_mime_basezemail.MIMEBasezemail.mime.baseZemail_mime_imagezemail.MIMEImagezemail.mime.imageZemail_mime_multipartzemail.MIMEMultipartzemail.mime.multipartZemail_mime_nonmultipartzemail.MIMENonMultipartzemail.mime.nonmultipartZemail_mime_textzemail.MIMETextzemail.mime.textZBaseHTTPServerz http.serverZ CGIHTTPServerZSimpleHTTPServerZcPicklepickleZqueueZQueuereprlibreprZ socketserverZ SocketServer_threadZthreadZtkinterZTkinterZtkinter_dialogZDialogztkinter.dialogZtkinter_filedialogZ FileDialogztkinter.filedialogZtkinter_scrolledtextZ ScrolledTextztkinter.scrolledtextZtkinter_simpledialogZ SimpleDialogztkinter.simpledialogZ tkinter_tixZTixz tkinter.tixZ tkinter_ttkZttkz tkinter.ttkZtkinter_constantsZ Tkconstantsztkinter.constantsZ tkinter_dndZTkdndz tkinter.dndZtkinter_colorchooserZtkColorChooserztkinter.colorchooserZtkinter_commondialogZtkCommonDialogztkinter.commondialogZtkinter_tkfiledialogZ tkFileDialogZ tkinter_fontZtkFontz tkinter.fontZtkinter_messageboxZ tkMessageBoxztkinter.messageboxZtkinter_tksimpledialogZtkSimpleDialogZ urllib_parsez.moves.urllib_parsez urllib.parseZ urllib_errorz.moves.urllib_errorz urllib.errorZurllibz .moves.urllibZurllib_robotparser robotparserzurllib.robotparserZ xmlrpc_clientZ xmlrpclibz xmlrpc.clientZ xmlrpc_serverZSimpleXMLRPCServerz xmlrpc.serverZwin32winreg_winregzmoves.z.movesmovesc@seZdZdZdS)Module_six_moves_urllib_parsez7Lazy loading of moved objects in six.moves.urllib_parseN)rrrrr r r r rpBsrpZ ParseResultZurlparseZ SplitResultZparse_qsZ parse_qslZ urldefragZurljoinZurlsplitZ urlunparseZ urlunsplitZ quote_plusZunquoteZ unquote_plusZunquote_to_bytesZ urlencodeZ splitqueryZsplittagZ splituserZ splitvalueZ uses_fragmentZ uses_netlocZ uses_paramsZ uses_queryZ uses_relativezmoves.urllib_parsezmoves.urllib.parsec@seZdZdZdS)Module_six_moves_urllib_errorz7Lazy loading of moved objects in six.moves.urllib_errorN)rrrrr r r r rqlsrqZURLErrorZurllib2Z HTTPErrorZContentTooShortErrorz.moves.urllib.errorzmoves.urllib_errorzmoves.urllib.errorc@seZdZdZdS)Module_six_moves_urllib_requestz9Lazy loading of moved objects in six.moves.urllib_requestN)rrrrr r r r rrsrrZurlopenzurllib.requestZinstall_openerZ build_openerZ pathname2urlZ url2pathnameZ getproxiesZRequestZOpenerDirectorZHTTPDefaultErrorHandlerZHTTPRedirectHandlerZHTTPCookieProcessorZ ProxyHandlerZ BaseHandlerZHTTPPasswordMgrZHTTPPasswordMgrWithDefaultRealmZAbstractBasicAuthHandlerZHTTPBasicAuthHandlerZProxyBasicAuthHandlerZAbstractDigestAuthHandlerZHTTPDigestAuthHandlerZProxyDigestAuthHandlerZ HTTPHandlerZ HTTPSHandlerZ FileHandlerZ FTPHandlerZCacheFTPHandlerZUnknownHandlerZHTTPErrorProcessorZ urlretrieveZ urlcleanupZ URLopenerZFancyURLopenerZ proxy_bypassZparse_http_listZparse_keqv_listz.moves.urllib.requestzmoves.urllib_requestzmoves.urllib.requestc@seZdZdZdS) Module_six_moves_urllib_responsez:Lazy loading of moved objects in six.moves.urllib_responseN)rrrrr r r r rssrsZaddbasezurllib.responseZ addclosehookZaddinfoZ addinfourlz.moves.urllib.responsezmoves.urllib_responsezmoves.urllib.responsec@seZdZdZdS)#Module_six_moves_urllib_robotparserz=Lazy loading of moved objects in six.moves.urllib_robotparserN)rrrrr r r r rtsrtZRobotFileParserz.moves.urllib.robotparserzmoves.urllib_robotparserzmoves.urllib.robotparserc@sNeZdZdZgZejdZejdZejdZ ejdZ ejdZ ddZ d S) Module_six_moves_urllibzICreate a six.moves.urllib namespace that resembles the Python 3 namespacezmoves.urllib_parsezmoves.urllib_errorzmoves.urllib_requestzmoves.urllib_responsezmoves.urllib_robotparsercCsdddddgS)Nparseerrorrequestresponserlr )r r r r r7szModule_six_moves_urllib.__dir__N) rrrrrH _importerr?rvrwrxryrlr7r r r r rus     ruz moves.urllibcCstt|j|dS)zAdd an item to six.moves.N)rrMr)Zmover r r add_movesr{cCsXytt|WnDtk rRy tj|=Wn"tk rLtd|fYnXYnXdS)zRemove item from six.moves.zno such move, %rN)rrMr!ro__dict__rB)rr r r remove_moves r}__func____self__ __closure____code__ __defaults__ __globals__im_funcZim_selfZ func_closureZ func_codeZ func_defaultsZ func_globalscCs|jS)N)next)itr r r advance_iteratorsrcCstddt|jDS)Ncss|]}d|jkVqdS)__call__N)r|)r3klassr r r szcallable..)anytype__mro__)r"r r r callablesrcCs|S)Nr )unboundr r r get_unbound_functionsrcCs|S)Nr )rclsr r r create_unbound_method#srcCs|jS)N)r)rr r r r(scCstj|||jS)N)types MethodTyper )rr"r r r create_bound_method+srcCstj|d|S)N)rr)rrr r r r.sc@seZdZddZdS)IteratorcCst|j|S)N)r__next__)r r r r r3sz Iterator.nextN)rrrrr r r r r1srz3Get the function out of a possibly unbound functioncKst|jf|S)N)iterkeys)dkwr r r iterkeysDsrcKst|jf|S)N)rvalues)rrr r r itervaluesGsrcKst|jf|S)N)ritems)rrr r r iteritemsJsrcKst|jf|S)N)rZlists)rrr r r iterlistsMsrrrrcKs |jf|S)N)r)rrr r r rVscKs |jf|S)N)r)rrr r r rYscKs |jf|S)N)r)rrr r r r\scKs |jf|S)N)r)rrr r r r_sviewkeys viewvalues viewitemsz1Return an iterator over the keys of a dictionary.z3Return an iterator over the values of a dictionary.z?Return an iterator over the (key, value) pairs of a dictionary.zBReturn an iterator over the (key, [values]) pairs of a dictionary.cCs |jdS)Nzlatin-1)encode)sr r r bqsrcCs|S)Nr )rr r r utsrz>BassertCountEqualZassertRaisesRegexpZassertRegexpMatchesassertRaisesRegex assertRegexcCs|S)Nr )rr r r rscCst|jdddS)Nz\\z\\\\Zunicode_escape)unicodereplace)rr r r rscCs t|dS)Nr)ord)Zbsr r r byte2intsrcCs t||S)N)r)Zbufir r r indexbytessrZassertItemsEqualz Byte literalz Text literalcOst|t||S)N)r,_assertCountEqual)r argskwargsr r r rscOst|t||S)N)r,_assertRaisesRegex)r rrr r r rscOst|t||S)N)r, _assertRegex)r rrr r r rsexecc Cs:z*|dkr|}|j|k r$|j||Wdd}d}XdS)N) __traceback__with_traceback)r#r/tbr r r reraises  rcCsB|dkr*tjd}|j}|dkr&|j}~n |dkr6|}tddS)zExecute code in a namespace.Nrzexec _code_ in _globs_, _locs_)r _getframe f_globalsf_localsr)Z_code_Z_globs_Z_locs_framer r r exec_s rzedef reraise(tp, value, tb=None): try: raise tp, value, tb finally: tb = None zdef raise_from(value, from_value): try: if from_value is None: raise value raise value from from_value finally: value = None zrdef raise_from(value, from_value): try: raise value from from_value finally: value = None cCs|dS)Nr )r/Z from_valuer r r raise_fromsrprintc s6|jdtjdkrdSfdd}d}|jdd}|dk r`t|trNd}nt|ts`td|jd d}|dk rt|trd}nt|tstd |rtd |sx|D]}t|trd}PqW|rtd }td }nd }d }|dkr|}|dkr|}x,t|D] \} }| r||||qW||dS)z4The new-style print function for Python 2.4 and 2.5.fileNcsdt|tst|}ttrVt|trVjdk rVtdd}|dkrHd}|jj|}j|dS)Nerrorsstrict) rE basestringstrrrencodingr,rwrite)datar)fpr r rs     zprint_..writeFsepTzsep must be None or a stringendzend must be None or a stringz$invalid keyword arguments to print()  )poprstdoutrErr TypeError enumerate) rrrZ want_unicoderrargnewlineZspacerr )rr print_sL           rcOs<|jdtj}|jdd}t|||r8|dk r8|jdS)NrflushF)getrrr_printr)rrrrr r r rs    zReraise an exception.csfdd}|S)Ncstj|}|_|S)N)r`wraps __wrapped__)f)assignedupdatedwrappedr r wrapper*szwraps..wrapperr )rrrrr )rrrr r(srcs&Gfdddt}tj|dfiS)z%Create a base class with a metaclass.cs,eZdZfddZefddZdS)z!with_metaclass..metaclasscs ||S)Nr )rr this_basesr)basesmetar r __new__:sz)with_metaclass..metaclass.__new__cs j|S)N) __prepare__)rrr)rrr r r=sz-with_metaclass..metaclass.__prepare__N)rrrr classmethodrr )rrr r metaclass8srZtemporary_class)rr)rrrr )rrr with_metaclass3srcsfdd}|S)z6Class decorator for creating a class with a metaclass.csl|jj}|jd}|dk rDt|tr,|g}x|D]}|j|q2W|jdd|jdd|j|j|S)N __slots__r| __weakref__)r|copyrrErrr __bases__)rZ orig_varsslotsZ slots_var)rr r rEs      zadd_metaclass..wrapperr )rrr )rr add_metaclassCs rcCs2tr.d|jkrtd|j|j|_dd|_|S)a A decorator that defines __unicode__ and __str__ methods under Python 2. Under Python 3 it does nothing. To support Python 2 and 3 with a single code base, define a __str__ method returning text and apply this decorator to the class. __str__zY@python_2_unicode_compatible cannot be applied to %s because it doesn't define __str__().cSs|jjdS)Nzutf-8) __unicode__r)r r r r asz-python_2_unicode_compatible..)PY2r| ValueErrorrrr)rr r r python_2_unicode_compatibleSs   r__spec__)rrlilill)N)NN)rr)rr)rr)rr)rZ __future__rr`rQoperatorrr __author__ __version__ version_inforr(ZPY34rZ string_typesintZ integer_typesrZ class_typesZ text_typebytesZ binary_typemaxsizeZMAXSIZErZlongZ ClassTyperplatform startswithobjectr len OverflowErrorrrrr& ModuleTyper2r8r:rrzrMr5r-rrrEr>rorpZ_urllib_parse_moved_attributesrqZ_urllib_error_moved_attributesrrZ _urllib_request_moved_attributesrsZ!_urllib_response_moved_attributesrtZ$_urllib_robotparser_moved_attributesrur{r}Z _meth_funcZ _meth_selfZ _func_closureZ _func_codeZ_func_defaultsZ _func_globalsrr NameErrorrrrrrr attrgetterZget_method_functionZget_method_selfZget_function_closureZget_function_codeZget_function_defaultsZget_function_globalsrrrr methodcallerrrrrrchrZunichrstructStructpackZint2byte itemgetterrgetitemrrZ iterbytesrNrOBytesIOrrrpartialrWrrrrr,rRrrrrrWRAPPER_ASSIGNMENTSWRAPPER_UPDATESrrrrrH __package__globalsrrsubmodule_search_locations meta_pathrrZimporterappendr r r r s     >                                                                                                                                                                5      decorator.cpython-36.opt-1.pyc000064400000030070147204744630012126 0ustar003 5*[Z@@sdZddlmZddlZddlZddlZddlZddlZddlZdZ ej dkrdddlm Z ddZ nej d d Zd d Z d dZ y ejZWnek rddZYnXej ddZddZejdZGdddeZffddZd*ddZyddlmZWn"ek rddlmZYnXGdddeZe ejZe ej!Z"e"dkrhej# rhd d!Zee_n,e"dkr|ej#r|ne"d"krd#d!Zee_eeZ$d$d%Z%d&d'Z&d(d)Z'dS)+zT Decorator module, see http://pypi.python.org/pypi/decorator for the documentation. )print_functionNz4.2.13)getfullargspeccCs|jS)N)__init__)clsr/usr/lib/python3.6/decorator.pyget_init0sr FullArgSpecz5args varargs varkw defaults kwonlyargs kwonlydefaultscCstjtj|gdfS)z?A quick and dirty replacement for getfullargspec for Python 2.XN)r _makeinspect getargspec)frrrr7srcCs|jjS)N)r__func__)rrrrr ;scCsdS)NFr)rrrriscoroutinefunctionBsrArgSpeczargs varargs varkw defaultscCst|}t|j|j|j|jS)z$A replacement for inspect.getargspec)rrargsvarargsvarkwdefaults)rspecrrrr Jsr z\s*def\s*([_\w][_\w\d]*)\s*\(c@sZeZdZdZejZfZZZ Z Z Z d ddZ ddZddd Zedd d ZdS) FunctionMakerz An object with the ability to create functions with a given signature. It has attributes name, doc, module, signature, defaults, dict and methods update and make. NcCs||_|rf|j|_|jdkr$d|_|j|_|j|_tj|rft |}t |di|_ xdD]} t || t || q\Wx&t |jD]\} } t |d | | qWt|j} t|j} |jr| jd |j| jd |jn|jr| jd x.|jD]$} | jd | | jd | | fqW|jrB| jd|j| jd|jdj| |_dj| |_|jj|_|rr||_|dk r||_|r||_|r||_|r||_|r||_t|dstd|dS)Nz_lambda___annotations__rrrr kwonlyargskwonlydefaultszarg%d*z%s=Nonez%s=%sz**z, signaturez%You are decorating a non function: %s)rrrrrr)shortsignature__name__name__doc__doc __module__moduler isfunctionrgetattr annotationssetattr enumeraterlistrappendrrjoinr__dict__copydictrhasattr TypeError)selffuncr rrr"r$ZfuncdictZargspecaiargZallargsZ allshortargsrrrrasZ           zFunctionMaker.__init__c Ks|j|_t|dd|_t|di|_|j|_|jp4d|_t|dd|_ yt j d}Wnt k rld}YnX|j jdd}t|d||_|jj|dS) z2Update the signature of func with the data in selfr"Nr/r'?rr$)r rr&r!r-r __defaults__r__kwdefaults__rsys _getframeAttributeError f_globalsgetr#update)r2r3kwframeZ callermodulerrrr@s  zFunctionMaker.updateFc Ks|t|}|pi}tj|}|dkr2td||jd}t|gdd|jjdD}x$|D]} | dkrbtd | |fqbW|j d s|d 7}d t |j f} yt || d } t | |Wn*td tjdt|tjdYnX||} |r||d<|j| f|| S)zBMake a new function from a given template and update the signatureNz not a valid function template %scSsg|]}|jdqS)z *)strip).0r6rrr sz&FunctionMaker.make..,_func__call_z%s is overridden in %s zZsinglezError in generated code:)fileZ __source__)rHrI)varsDEFsearch SyntaxErrorgroupsetrsplit NameErrorendswithnext_compile_countcompileexecprintr;stderrr@) r2Z src_templevaldict addsourceattrssrcmor namesnfilenamecoder3rrrmakes4        zFunctionMaker.makeTcKst|tr0|jjdd\} } | dd } d} n d} d} |} || | | |||} djdd|jD}|jd}|rt|rd|jd d }nd |}| j |||f|S) z Create a function from the strings name, signature and body. evaldict is the evaluation dictionary. If addsource is true an attribute __source__ is added to the result. The attributes attrs are added, if any. (rCNrJcss|]}d|VqdS)z Nr)rElinerrr sz'FunctionMaker.create..rIz#async def %(name)s(%(signature)s): returnz return awaitzdef %(name)s(%(signature)s): ) isinstancestrrDrRr, splitlinesr?rreplacerd)robjZbodyr[rr"r$r\r]r restrr3r2Zibodycallerrrrcreates     zFunctionMaker.create)NNNNNNN)NF)NNNT)rr# __qualname__r! itertoolscountrVrrrrrrrr@rd classmethodrqrrrrrTs 3 "rc Csnt||d}d}x0t|D]$\}}d|}|||<||d7}qWtj|d|||d}t|drj|j|_|S)zE decorate(func, caller) decorates a function using a caller. )rIrHz_e%d_z, z,return _call_(_func_, %s%%(shortsignature)s)) __wrapped__rr)r/r)rrqr0rr) r3rpZextrasr[Zesr5ZextraZexZfunrrrdecorates   rxc Cs|dk rt||Sdf}}tj|rB|jj}d|j|jf}n~tj|r|jdkr\d}n|j}|j}|jj}t |j pzf}dj |jj |||}|r|d7}|j }n|j jj}|jj}t|td}tjd ||fd ||f|||j|d } |rd || _ | S) z=decorator(caller) converts a caller function into a decoratorNrvzHdecorator(%s) converts functions/generators into factories of %s objectszrz, rG)_callZ _decorate_z %s(func, %s)zhif func is None: return lambda func: _decorate_(func, _call, (%s)) return _decorate_(func, _call, (%s)))r"r$rw)N)rxr Zisclassrlowerr%r!__code__ co_argcountlenr9r, co_varnames __class____call__r/rrqr#) rpZ_funcZ defaultargsrr r"nargsZndefsr[decrrr decorators:          r)_GeneratorContextManager)GeneratorContextManagerc@seZdZddZdS)ContextManagercCstj|dt||d|dS)zContext manager decoratorz.with _self_: return _func_(%(shortsignature)s))Z_self_rH)rw)rrqr/)r2r3rrrr#szContextManager.__call__N)rr#rrrrrrrr"srcOstj||||S)N)rr)r2gr4krrrr-srcOstj||||S)N)rr)r2rr4rrrrr3scCst|S)N)_contextmanager)r3rrrcontextmanager:srcCsRd}x:t|D].\}}t||r&d}Pt||r|||<d}qW|rN|j|dS)z_ Append ``a`` to the list of the virtual ancestors, unless it is already included. TFN)r) issubclassr+)r4 vancestorsaddjvarrrr+As  r+cs@ddjtjdffdd fdd}d|_|S) zr Factory of decorators turning a function into a generic function dispatching on the given arguments. z(%s,)z, rvcs0|t|tr,tdtt||fdS)z5Make sure one passes the expected number of argumentszExpected %d arguments, got %d%sN)r}r1)Z argumentsZwrongmsg) dispatch_argsrrcheck[szdispatch_on..checkc sttj}t|ks&tdifddfddfdd}fdd }fd d }tjd t|d ||d S)z4Decorator turning a function into a generic functionzUnknown dispatch arguments %scsv|ddttD}xHD]@}x:t|||D]*\}}}t||r6||jkr6t||q6Wq$Wdd|DS)zU Get a list of sets of virtual ancestors for the given types cSsg|]}gqSrr)rE_rrrrFpszIdispatch_on..gen_func_dec..vancestors..cSsg|] }t|qSr)rQ)rErarrrrFus)ranger}ziprmror+)typesZrastypes_tZtype_r)rrtypemaprrrks z5dispatch_on..gen_func_dec..vancestorscs|g}xt||D]p\}}t|}|dkrFtd||fn4|dkrr|\}td||fijdd}n|j}|j|ddqW|S)zG Get a list of virtual MROs, one for each type rCzAmbiguous dispatch for %s: %srNri)rr} RuntimeErrortyperr+)rZlistsrZvasZn_vasrr)rrrr ancestorswsz4dispatch_on..gen_func_dec..ancestorscsfdd}|S)zU Decorator to register an implementation for the given types cs&t|jtjd|j|<|S)Nz in )rroperatorltr)r)rrrrrrsz@dispatch_on..gen_func_dec..register..decr)rr)rr)rrregistersz3dispatch_on..gen_func_dec..registercs@|g}x.tj|D]}|jtdd|DqW|S)zI An utility to introspect the dispatch algorithm css|] }|jVqdS)N)r)rEr4rrrrgszKdispatch_on..gen_func_dec..dispatch_info..)rsproductr+tuple)rZlstZanc)rrrr dispatch_infos z8dispatch_on..gen_func_dec..dispatch_infoc stdd|D}y |}Wntk r2Yn X|||Stj|}t|x(|D] }j|}|dk rZ|||SqZW||S)Ncss|]}t|VqdS)N)r)rEr6rrrrgszGdispatch_on..gen_func_dec.._dispatch..)rKeyErrorrsrrUr?)rrrArr combinationsr)rr3rrr _dispatchs    z4dispatch_on..gen_func_dec.._dispatchz#return _f_(%s, %%(shortsignature)s))Z_f_)rdefaultrrrrrw)rQrrrSrrqr/)r3Zargsetrrr)rr dispatch_str)rr3rrr gen_func_decas      z!dispatch_on..gen_func_dec dispatch_on)r,rner)rrr)rrrrrSs W r)N)(r!Z __future__rrer;r rrs collections __version__versionrr namedtupler rr=rr rWrMobjectrrxr contextlibr ImportErrorrrrZinitr}rZn_argsrrrr+rrrrr!s\        &   decorator.cpython-36.pyc000064400000030213147204744630011166 0ustar003 5*[Z@@sdZddlmZddlZddlZddlZddlZddlZddlZdZ ej dkrdddlm Z ddZ nej d d Zd d Z d dZ y ejZWnek rddZYnXej ddZddZejdZGdddeZffddZd*ddZyddlmZWn"ek rddlmZYnXGdddeZe ejZe ej!Z"e"dkrhej# rhd d!Zee_n,e"dkr|ej#r|ne"d"krd#d!Zee_eeZ$d$d%Z%d&d'Z&d(d)Z'dS)+zT Decorator module, see http://pypi.python.org/pypi/decorator for the documentation. )print_functionNz4.2.13)getfullargspeccCs|jS)N)__init__)clsr/usr/lib/python3.6/decorator.pyget_init0sr FullArgSpecz5args varargs varkw defaults kwonlyargs kwonlydefaultscCstjtj|gdfS)z?A quick and dirty replacement for getfullargspec for Python 2.XN)r _makeinspect getargspec)frrrr7srcCs|jjS)N)r__func__)rrrrr ;scCsdS)NFr)rrrriscoroutinefunctionBsrArgSpeczargs varargs varkw defaultscCst|}t|j|j|j|jS)z$A replacement for inspect.getargspec)rrargsvarargsvarkwdefaults)rspecrrrr Jsr z\s*def\s*([_\w][_\w\d]*)\s*\(c@sZeZdZdZejZfZZZ Z Z Z d ddZ ddZddd Zedd d ZdS) FunctionMakerz An object with the ability to create functions with a given signature. It has attributes name, doc, module, signature, defaults, dict and methods update and make. NcCs||_|rf|j|_|jdkr$d|_|j|_|j|_tj|rft |}t |di|_ xdD]} t || t || q\Wx&t |jD]\} } t |d | | qWt|j} t|j} |jr| jd |j| jd |jn|jr| jd x.|jD]$} | jd | | jd | | fqW|jrB| jd|j| jd|jdj| |_dj| |_|jj|_|rr||_|dk r||_|r||_|r||_|r||_|r||_t|dstt|dstd|dS)Nz_lambda___annotations__rrrr kwonlyargskwonlydefaultszarg%d*z%s=Nonez%s=%sz**z, name signaturez%You are decorating a non function: %s)rrrrrr)shortsignature__name__r__doc__doc __module__moduler isfunctionrgetattr annotationssetattr enumeraterlistrappendrrjoinr__dict__copydictrhasattrAssertionError TypeError)selffuncrrrr"r$ZfuncdictZargspecaiargZallargsZ allshortargsrrrras\           zFunctionMaker.__init__c Ks|j|_t|dd|_t|di|_|j|_|jp4d|_t|dd|_ yt j d}Wnt k rld}YnX|j jdd}t|d||_|jj|dS) z2Update the signature of func with the data in selfr"Nr/r'?r r$)rr r&r!r-r __defaults__r__kwdefaults__rsys _getframeAttributeError f_globalsgetr#update)r3r4kwframeZ callermodulerrrrAs  zFunctionMaker.updateFc Ks|t|}|pi}tj|}|dkr2td||jd}t|gdd|jjdD}x$|D]} | dkrbtd | |fqbW|j d s|d 7}d t |j f} yt || d } t | |Wn*td tjdt|tjdYnX||} |r||d<|j| f|| S)zBMake a new function from a given template and update the signatureNz not a valid function template %scSsg|]}|jdqS)z *)strip).0r7rrr sz&FunctionMaker.make..,_func__call_z%s is overridden in %s zZsinglezError in generated code:)fileZ __source__)rIrJ)varsDEFsearch SyntaxErrorgroupsetrsplit NameErrorendswithnext_compile_countcompileexecprintr<stderrrA) r3Z src_templevaldict addsourceattrssrcmornamesnfilenamecoder4rrrmakes4        zFunctionMaker.makeTcKst|tr0|jjdd\} } | dd } d} n d} d} |} || | | |||} djdd|jD}|jd}|rt|rd|jd d }nd |}| j |||f|S) z Create a function from the strings name, signature and body. evaldict is the evaluation dictionary. If addsource is true an attribute __source__ is added to the result. The attributes attrs are added, if any. (rDNrKcss|]}d|VqdS)z Nr)rFlinerrr sz'FunctionMaker.create..rJz#async def %(name)s(%(signature)s): returnz return awaitzdef %(name)s(%(signature)s): ) isinstancestrrErSr, splitlinesr@rreplacere)robjZbodyr\rr"r$r]r^rrestrr4r3Zibodycallerrrrcreates     zFunctionMaker.create)NNNNNNN)NF)NNNT)r r# __qualname__r! itertoolscountrWrrrrrrrrAre classmethodrrrrrrrTs 3 "rc Csnt||d}d}x0t|D]$\}}d|}|||<||d7}qWtj|d|||d}t|drj|j|_|S)zE decorate(func, caller) decorates a function using a caller. )rJrIz_e%d_z, z,return _call_(_func_, %s%%(shortsignature)s)) __wrapped__rs)r/r)rrrr0rs) r4rqZextrasr\Zesr6ZextraZexZfunrrrdecorates   ryc Cs|dk rt||Sdf}}tj|rB|jj}d|j|jf}n~tj|r|jdkr\d}n|j}|j}|jj}t |j pzf}dj |jj |||}|r|d7}|j }n|j jj}|jj}t|td}tjd ||fd ||f|||j|d } |rd || _ | S) z=decorator(caller) converts a caller function into a decoratorNrwzHdecorator(%s) converts functions/generators into factories of %s objectszrz, rH)_callZ _decorate_z %s(func, %s)zhif func is None: return lambda func: _decorate_(func, _call, (%s)) return _decorate_(func, _call, (%s)))r"r$rx)N)ryr Zisclassr lowerr%r!__code__ co_argcountlenr:r, co_varnames __class____call__r/rrrr#) rqZ_funcZ defaultargsrrr"nargsZndefsr\decrrr decorators:          r)_GeneratorContextManager)GeneratorContextManagerc@seZdZddZdS)ContextManagercCstj|dt||d|dS)zContext manager decoratorz.with _self_: return _func_(%(shortsignature)s))Z_self_rI)rx)rrrr/)r3r4rrrr#szContextManager.__call__N)r r#rsrrrrrr"srcOstj||||S)N)rr)r3gr5krrrr-srcOstj||||S)N)rr)r3rr5rrrrr3scCst|S)N)_contextmanager)r4rrrcontextmanager:srcCsRd}x:t|D].\}}t||r&d}Pt||r|||<d}qW|rN|j|dS)z_ Append ``a`` to the list of the virtual ancestors, unless it is already included. TFN)r) issubclassr+)r5 vancestorsaddjvarrrr+As  r+csLs tdddjtjdffdd fdd}d |_|S) zr Factory of decorators turning a function into a generic function dispatching on the given arguments. zNo dispatch args passedz(%s,)z, rwcs0|t|tr,tdtt||fdS)z5Make sure one passes the expected number of argumentszExpected %d arguments, got %d%sN)r~r2)Z argumentsZwrongmsg) dispatch_argsrrcheck[szdispatch_on..checkc sttj}t|ks&tdifddfddfdd}fdd }fd d }tjd t|d ||d S)z4Decorator turning a function into a generic functionzUnknown dispatch arguments %scsv|ddttD}xHD]@}x:t|||D]*\}}}t||r6||jkr6t||q6Wq$Wdd|DS)zU Get a list of sets of virtual ancestors for the given types cSsg|]}gqSrr)rF_rrrrGpszIdispatch_on..gen_func_dec..vancestors..cSsg|] }t|qSr)rR)rFrarrrrGus)ranger~ziprmror+)typesZrastypes_tZtype_r)rrtypemaprrrks z5dispatch_on..gen_func_dec..vancestorscs|g}xt||D]p\}}t|}|dkrFtd||fn4|dkrr|\}td||fijdd}n|j}|j|ddqW|S)zG Get a list of virtual MROs, one for each type rDzAmbiguous dispatch for %s: %srNrj)rr~ RuntimeErrortyperr+)rZlistsrZvasZn_vasrr)rrrr ancestorswsz4dispatch_on..gen_func_dec..ancestorscsfdd}|S)zU Decorator to register an implementation for the given types cs&t|jtjd|j|<|S)Nz in )rroperatorltr )r)rrrrrrsz@dispatch_on..gen_func_dec..register..decr)rr)rr)rrregistersz3dispatch_on..gen_func_dec..registercs@|g}x.tj|D]}|jtdd|DqW|S)zI An utility to introspect the dispatch algorithm css|] }|jVqdS)N)r )rFr5rrrrhszKdispatch_on..gen_func_dec..dispatch_info..)rtproductr+tuple)rZlstZanc)rrrr dispatch_infos z8dispatch_on..gen_func_dec..dispatch_infoc stdd|D}y |}Wntk r2Yn X|||Stj|}t|x(|D] }j|}|dk rZ|||SqZW||S)Ncss|]}t|VqdS)N)r)rFr7rrrrhszGdispatch_on..gen_func_dec.._dispatch..)rKeyErrorrtrrVr@)rrrBrr combinationsr)rr4rrr _dispatchs    z4dispatch_on..gen_func_dec.._dispatchz#return _f_(%s, %%(shortsignature)s))Z_f_)rdefaultrrrrrx)rRrrrTrrrr/)r4Zargsetrrr)rr dispatch_str)rr4rrr gen_func_decas      z!dispatch_on..gen_func_dec dispatch_on)r1r,rner )rrr)rrrrrSs  W r)N)(r!Z __future__rrer<r rrt collections __version__versionrr namedtupler rr>rr rXrNobjectrryr contextlibr ImportErrorrrrZinitr~rZn_argsrrrr+rrrrr!s\        &   pyparsing.cpython-36.opt-1.pyc000064400000610513147204744630012166 0ustar003 ]@s dZdZdZdZddlZddlmZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZddlZddlZddlmZyddlmZWn ek rddlmZYnXydd l mZWn>ek rydd lmZWnek rdZYnXYnXd d d d ddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;dd?d@dAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd[d\d]d^d_d`dadbdcdddedfdgdhdidjdkdldmdndodpdqdrgiZee jddsZeddskZer"e jZe Z!e"Z#e Z$e%e&e'e(e)ee*e+e,e-e.g Z/nbe j0Ze1Z2dtduZ$gZ/ddl3Z3xBdvj4D]6Z5ye/j6e7e3e5Wne8k r|wJYnXqJWe9dwdxe2dyDZ:dzd{Z;Gd|d}d}e<Z=ej>ej?Z@d~ZAeAdZBe@eAZCe"dZDdjEddxejFDZGGdd!d!eHZIGdd#d#eIZJGdd%d%eIZKGdd'd'eKZLGdd*d*eHZMGddde<ZNGdd&d&e<ZOe jPjQeOdd=ZRddNZSddKZTddZUddZVddZWddUZXd/ddZYGdd(d(e<ZZGdd0d0eZZ[Gddde[Z\Gddde[Z]Gddde[Z^e^Z_e^eZ_`Gddde[ZaGdd d e^ZbGdd d eaZcGddpdpe[ZdGdd3d3e[ZeGdd+d+e[ZfGdd)d)e[ZgGdd d e[ZhGdd2d2e[ZiGddde[ZjGdddejZkGdddejZlGdddejZmGdd.d.ejZnGdd-d-ejZoGdd5d5ejZpGdd4d4ejZqGdd$d$eZZrGdd d erZsGdd d erZtGddderZuGddderZvGdd"d"eZZwGdddewZxGdddewZyGdddewZzGdddezZ{Gdd6d6ezZ|Gddde<Z}e}Z~GdddewZGdd,d,ewZGdddewZGdddeZGdd1d1ewZGdddeZGdddeZGdddeZGdd/d/eZGddde<ZddfZd0ddDZd1dd@Zdd΄ZddSZddRZdd҄Zd2ddWZddEZd3ddkZddlZddnZe\jdGZeljdMZemjdLZenjdeZeojddZeeeDdddڍjdd܄Zefd݃jdd܄Zefd߃jdd܄ZeeBeBeeeGddydBefde jBZeeedeZe^dedjdee{eeBjddZddcZddQZdd`Zdd^ZddqZedd܄Zedd܄ZddZddOZddPZddiZe<e_d4ddoZe=Ze<e_e<e_ededfddmZeZeefddjdZeefddjdZeefddefddBjdZee_dejjdZdddejfddTZd5ddjZedZedZeeee@eCdjd\ZZeed j4d Zefd d jEejÃd jdZĐdd_ZeefddjdZefdjdZefdjȃjdZefdjdZeefddeBjdZeZefdjdZee{eeeGdɐdeeede^dɃemj΃jdZeeejeBddjd>ZGd drdrZeҐd!k rebd"Zebd#Zeee@eCd$ZeeՐd%dӐd&jeZeeeփjd'Zאd(eBZeeՐd%dӐd&jeZeeeكjd)ZeӐd*eؐd'eeڐd)Zejܐd+ejjܐd,ejjܐd,ejjܐd-ddlZejjeejejjܐd.dS(6aS pyparsing module - Classes and methods to define and execute parsing grammars The pyparsing module is an alternative approach to creating and executing simple grammars, vs. the traditional lex/yacc approach, or the use of regular expressions. With pyparsing, you don't need to learn a new syntax for defining grammars or matching expressions - the parsing module provides a library of classes that you use to construct the grammar directly in Python. Here is a program to parse "Hello, World!" (or any greeting of the form C{", !"}), built up using L{Word}, L{Literal}, and L{And} elements (L{'+'} operator gives L{And} expressions, strings are auto-converted to L{Literal} expressions):: from pyparsing import Word, alphas # define grammar of a greeting greet = Word(alphas) + "," + Word(alphas) + "!" hello = "Hello, World!" print (hello, "->", greet.parseString(hello)) The program outputs the following:: Hello, World! -> ['Hello', ',', 'World', '!'] The Python representation of the grammar is quite readable, owing to the self-explanatory class names, and the use of '+', '|' and '^' operators. The L{ParseResults} object returned from L{ParserElement.parseString} can be accessed as a nested list, a dictionary, or an object with named attributes. The pyparsing module handles some of the problems that are typically vexing when writing text parsers: - extra or missing whitespace (the above program will also handle "Hello,World!", "Hello , World !", etc.) - quoted strings - embedded comments z2.1.10z07 Oct 2016 01:31 UTCz*Paul McGuire N)ref)datetime)RLock) OrderedDictAndCaselessKeywordCaselessLiteral CharsNotInCombineDictEachEmpty FollowedByForward GoToColumnGroupKeywordLineEnd LineStartLiteral MatchFirstNoMatchNotAny OneOrMoreOnlyOnceOptionalOrParseBaseExceptionParseElementEnhanceParseExceptionParseExpressionParseFatalException ParseResultsParseSyntaxException ParserElement QuotedStringRecursiveGrammarExceptionRegexSkipTo StringEnd StringStartSuppressTokenTokenConverterWhiteWordWordEnd WordStart ZeroOrMore alphanumsalphas alphas8bit anyCloseTag anyOpenTag cStyleCommentcolcommaSeparatedListcommonHTMLEntity countedArraycppStyleCommentdblQuotedStringdblSlashComment delimitedListdictOfdowncaseTokensemptyhexnums htmlCommentjavaStyleCommentlinelineEnd lineStartlineno makeHTMLTags makeXMLTagsmatchOnlyAtColmatchPreviousExprmatchPreviousLiteral nestedExprnullDebugActionnumsoneOfopAssocoperatorPrecedence printablespunc8bitpythonStyleComment quotedString removeQuotesreplaceHTMLEntity replaceWith restOfLinesglQuotedStringsrange stringEnd stringStarttraceParseAction unicodeString upcaseTokens withAttribute indentedBlockoriginalTextForungroup infixNotation locatedExpr withClass CloseMatchtokenMappyparsing_commonc Cs`t|tr|Syt|Stk rZt|jtjd}td}|jdd|j |SXdS)aDrop-in replacement for str(obj) that tries to be Unicode friendly. It first tries str(obj). If that fails with a UnicodeEncodeError, then it tries unicode(obj). It then < returns the unicode object | encodes it with the default encoding | ... >. xmlcharrefreplacez&#\d+;cSs$dtt|dddddS)Nz\ur)hexint)trw/usr/lib/python3.6/pyparsing.pysz_ustr..N) isinstanceZunicodestrUnicodeEncodeErrorencodesysgetdefaultencodingr'setParseActiontransformString)objretZ xmlcharrefrwrwrx_ustrs rz6sum len sorted reversed list tuple set any all min maxccs|] }|VqdS)Nrw).0yrwrwrx srrrcCs>d}dddjD}x"t||D]\}}|j||}q"W|S)z/Escape &, <, >, ", ', etc. in a string of data.z&><"'css|]}d|dVqdS)&;Nrw)rsrwrwrxrsz_xml_escape..zamp gt lt quot apos)splitzipreplace)dataZ from_symbolsZ to_symbolsZfrom_Zto_rwrwrx _xml_escapes rc@s eZdZdS) _ConstantsN)__name__ __module__ __qualname__rwrwrwrxrsr 0123456789Z ABCDEFabcdef\ccs|]}|tjkr|VqdS)N)stringZ whitespace)rcrwrwrxrsc@sPeZdZdZdddZeddZdd Zd d Zd d Z dddZ ddZ dS)rz7base exception class for all parsing runtime exceptionsrNcCs>||_|dkr||_d|_n ||_||_||_|||f|_dS)Nr)locmsgpstr parserElementargs)selfrrrelemrwrwrx__init__szParseBaseException.__init__cCs||j|j|j|jS)z internal factory method to simplify creating one type of ParseException from another - avoids having __init__ signature conflicts among subclasses )rrrr)clsperwrwrx_from_exceptionsz"ParseBaseException._from_exceptioncCsN|dkrt|j|jS|dkr,t|j|jS|dkrBt|j|jSt|dS)zsupported attributes by name are: - lineno - returns the line number of the exception text - col - returns the column number of the exception text - line - returns the line containing the exception text rJr9columnrGN)r9r)rJrrr9rGAttributeError)rZanamerwrwrx __getattr__szParseBaseException.__getattr__cCsd|j|j|j|jfS)Nz"%s (at char %d), (line:%d, col:%d))rrrJr)rrwrwrx__str__szParseBaseException.__str__cCst|S)N)r)rrwrwrx__repr__szParseBaseException.__repr__>!} ('-' operator) indicates that parsing is to stop immediately because an unbacktrackable syntax error has been foundN)rrrrrwrwrwrxr#sc@s eZdZdZddZddZdS)r&zZexception thrown by L{ParserElement.validate} if the grammar could be improperly recursivecCs ||_dS)N)parseElementTrace)rparseElementListrwrwrxrsz"RecursiveGrammarException.__init__cCs d|jS)NzRecursiveGrammarException: %s)r)rrwrwrxr sz!RecursiveGrammarException.__str__N)rrrrrrrwrwrwrxr&sc@s,eZdZddZddZddZddZd S) _ParseResultsWithOffsetcCs||f|_dS)N)tup)rZp1Zp2rwrwrxr$sz _ParseResultsWithOffset.__init__cCs |j|S)N)r)rirwrwrx __getitem__&sz#_ParseResultsWithOffset.__getitem__cCst|jdS)Nr)reprr)rrwrwrxr(sz _ParseResultsWithOffset.__repr__cCs|jd|f|_dS)Nr)r)rrrwrwrx setOffset*sz!_ParseResultsWithOffset.setOffsetN)rrrrrrrrwrwrwrxr#src@seZdZdZd[ddZddddefddZdd Zefd d Zd d Z ddZ ddZ ddZ e Z ddZddZddZddZddZereZeZeZn$eZeZeZddZd d!Zd"d#Zd$d%Zd&d'Zd\d(d)Zd*d+Zd,d-Zd.d/Zd0d1Z d2d3Z!d4d5Z"d6d7Z#d8d9Z$d:d;Z%d} - see L{ParserElement.setResultsName}) Example:: integer = Word(nums) date_str = (integer.setResultsName("year") + '/' + integer.setResultsName("month") + '/' + integer.setResultsName("day")) # equivalent form: # date_str = integer("year") + '/' + integer("month") + '/' + integer("day") # parseString returns a ParseResults object result = date_str.parseString("1999/12/31") def test(s, fn=repr): print("%s -> %s" % (s, fn(eval(s)))) test("list(result)") test("result[0]") test("result['month']") test("result.day") test("'month' in result") test("'minutes' in result") test("result.dump()", str) prints:: list(result) -> ['1999', '/', '12', '/', '31'] result[0] -> '1999' result['month'] -> '12' result.day -> '31' 'month' in result -> True 'minutes' in result -> False result.dump() -> ['1999', '/', '12', '/', '31'] - day: 31 - month: 12 - year: 1999 NTcCs"t||r|Stj|}d|_|S)NT)rzobject__new___ParseResults__doinit)rtoklistnameasListmodalZretobjrwrwrxrTs   zParseResults.__new__c Cs`|jrvd|_d|_d|_i|_||_||_|dkr6g}||trP|dd|_n||trft||_n|g|_t |_ |dk o|r\|sd|j|<||t rt |}||_||t dttfo|ddgfks\||tr|g}|r&||trt|jd||<ntt|dd||<|||_n6y|d||<Wn$tttfk rZ|||<YnXdS)NFrr)r_ParseResults__name_ParseResults__parent_ParseResults__accumNames_ParseResults__asList_ParseResults__modallist_ParseResults__toklist_generatorTypedict_ParseResults__tokdictrurr basestringr"rcopyKeyError TypeError IndexError)rrrrrrzrwrwrxr]sB     $   zParseResults.__init__cCsPt|ttfr|j|S||jkr4|j|ddStdd|j|DSdS)NrrrcSsg|] }|dqS)rrw)rvrwrwrx sz,ParseResults.__getitem__..rs)rzruslicerrrr")rrrwrwrxrs   zParseResults.__getitem__cCs||tr0|jj|t|g|j|<|d}nD||ttfrN||j|<|}n&|jj|tt|dg|j|<|}||trt||_ dS)Nr) rrgetrrurrr"wkrefr)rkrrzsubrwrwrx __setitem__s   " zParseResults.__setitem__c Cst|ttfrt|j}|j|=t|trH|dkr:||7}t||d}tt|j|}|jx^|j j D]F\}}x<|D]4}x.t |D]"\}\}} t || | |k||<qWq|WqnWn|j |=dS)Nrrr) rzrurlenrrrangeindicesreverseritems enumerater) rrZmylenZremovedr occurrencesjrvaluepositionrwrwrx __delitem__s   $zParseResults.__delitem__cCs ||jkS)N)r)rrrwrwrx __contains__szParseResults.__contains__cCs t|jS)N)rr)rrwrwrx__len__szParseResults.__len__cCs |j S)N)r)rrwrwrx__bool__szParseResults.__bool__cCs t|jS)N)iterr)rrwrwrx__iter__szParseResults.__iter__cCst|jdddS)Nrrrs)rr)rrwrwrx __reversed__szParseResults.__reversed__cCs$t|jdr|jjSt|jSdS)Niterkeys)hasattrrrr)rrwrwrx _iterkeyss  zParseResults._iterkeyscsfddjDS)Nc3s|]}|VqdS)Nrw)rr)rrwrxrsz+ParseResults._itervalues..)r)rrw)rrx _itervaluesszParseResults._itervaluescsfddjDS)Nc3s|]}||fVqdS)Nrw)rr)rrwrxrsz*ParseResults._iteritems..)r)rrw)rrx _iteritemsszParseResults._iteritemscCs t|jS)zVReturns all named result keys (as a list in Python 2.x, as an iterator in Python 3.x).)rr)rrwrwrxkeysszParseResults.keyscCs t|jS)zXReturns all named result values (as a list in Python 2.x, as an iterator in Python 3.x).)r itervalues)rrwrwrxvaluesszParseResults.valuescCs t|jS)zfReturns all named result key-values (as a list of tuples in Python 2.x, as an iterator in Python 3.x).)r iteritems)rrwrwrxrszParseResults.itemscCs t|jS)zSince keys() returns an iterator, this method is helpful in bypassing code that looks for the existence of any defined results names.)boolr)rrwrwrxhaskeysszParseResults.haskeyscOs|s dg}x6|jD]*\}}|dkr2|d|f}qtd|qWt|dtsht|dksh|d|kr|d}||}||=|S|d}|SdS)a Removes and returns item at specified index (default=C{last}). Supports both C{list} and C{dict} semantics for C{pop()}. If passed no argument or an integer argument, it will use C{list} semantics and pop tokens from the list of parsed tokens. If passed a non-integer argument (most likely a string), it will use C{dict} semantics and pop the corresponding value from any defined results names. A second default return value argument is supported, just as in C{dict.pop()}. Example:: def remove_first(tokens): tokens.pop(0) print(OneOrMore(Word(nums)).parseString("0 123 321")) # -> ['0', '123', '321'] print(OneOrMore(Word(nums)).addParseAction(remove_first).parseString("0 123 321")) # -> ['123', '321'] label = Word(alphas) patt = label("LABEL") + OneOrMore(Word(nums)) print(patt.parseString("AAB 123 321").dump()) # Use pop() in a parse action to remove named result (note that corresponding value is not # removed from list form of results) def remove_LABEL(tokens): tokens.pop("LABEL") return tokens patt.addParseAction(remove_LABEL) print(patt.parseString("AAB 123 321").dump()) prints:: ['AAB', '123', '321'] - LABEL: AAB ['AAB', '123', '321'] rrdefaultrz-pop() got an unexpected keyword argument '%s'Nrs)rrrzrur)rrkwargsrrindexrZ defaultvaluerwrwrxpops"  zParseResults.popcCs||kr||S|SdS)ai Returns named result matching the given key, or if there is no such name, then returns the given C{defaultValue} or C{None} if no C{defaultValue} is specified. Similar to C{dict.get()}. Example:: integer = Word(nums) date_str = integer("year") + '/' + integer("month") + '/' + integer("day") result = date_str.parseString("1999/12/31") print(result.get("year")) # -> '1999' print(result.get("hour", "not specified")) # -> 'not specified' print(result.get("hour")) # -> None Nrw)rkey defaultValuerwrwrxrszParseResults.getcCsZ|jj||xF|jjD]8\}}x.t|D]"\}\}}t||||k||<q,WqWdS)a Inserts new element at location index in the list of parsed tokens. Similar to C{list.insert()}. Example:: print(OneOrMore(Word(nums)).parseString("0 123 321")) # -> ['0', '123', '321'] # use a parse action to insert the parse location in the front of the parsed results def insert_locn(locn, tokens): tokens.insert(0, locn) print(OneOrMore(Word(nums)).addParseAction(insert_locn).parseString("0 123 321")) # -> [0, '0', '123', '321'] N)rinsertrrrr)rrZinsStrrrrrrrwrwrxr2szParseResults.insertcCs|jj|dS)a Add single element to end of ParseResults list of elements. Example:: print(OneOrMore(Word(nums)).parseString("0 123 321")) # -> ['0', '123', '321'] # use a parse action to compute the sum of the parsed integers, and add it to the end def append_sum(tokens): tokens.append(sum(map(int, tokens))) print(OneOrMore(Word(nums)).addParseAction(append_sum).parseString("0 123 321")) # -> ['0', '123', '321', 444] N)rappend)ritemrwrwrxrFs zParseResults.appendcCs$t|tr||7}n |jj|dS)a Add sequence of elements to end of ParseResults list of elements. Example:: patt = OneOrMore(Word(alphas)) # use a parse action to append the reverse of the matched strings, to make a palindrome def make_palindrome(tokens): tokens.extend(reversed([t[::-1] for t in tokens])) return ''.join(tokens) print(patt.addParseAction(make_palindrome).parseString("lskdj sdlkjf lksd")) # -> 'lskdjsdlkjflksddsklfjkldsjdksl' N)rzr"rextend)rZitemseqrwrwrxrTs  zParseResults.extendcCs|jdd=|jjdS)z7 Clear all elements and results names. N)rrclear)rrwrwrxrfs zParseResults.clearc Csfy||Stk rdSX||jkr^||jkrD|j|ddStdd|j|DSndSdS)NrrrrcSsg|] }|dqS)rrw)rrrwrwrxrwsz,ParseResults.__getattr__..rs)rrrr")rrrwrwrxrms  zParseResults.__getattr__cCs|j}||7}|S)N)r)rotherrrwrwrx__add__{szParseResults.__add__cs|jrnt|jfdd|jj}fdd|D}x4|D],\}}|||<t|dtr>t||d_q>W|j|j7_|jj |j|S)Ncs|dkr S|S)Nrrw)a)offsetrwrxrysz'ParseResults.__iadd__..c s4g|],\}}|D]}|t|d|dfqqS)rrr)r)rrvlistr) addoffsetrwrxrsz)ParseResults.__iadd__..r) rrrrrzr"rrrupdate)rrZ otheritemsZotherdictitemsrrrw)rrrx__iadd__s    zParseResults.__iadd__cCs&t|tr|dkr|jS||SdS)Nr)rzrur)rrrwrwrx__radd__szParseResults.__radd__cCsdt|jt|jfS)Nz(%s, %s))rrr)rrwrwrxrszParseResults.__repr__cCsddjdd|jDdS)N[z, css(|] }t|trt|nt|VqdS)N)rzr"rr)rrrwrwrxrsz'ParseResults.__str__..])rr)rrwrwrxrszParseResults.__str__rcCsPg}xF|jD]<}|r"|r"|j|t|tr:||j7}q |jt|q W|S)N)rrrzr" _asStringListr)rsepoutrrwrwrxr s   zParseResults._asStringListcCsdd|jDS)a Returns the parse results as a nested list of matching tokens, all converted to strings. Example:: patt = OneOrMore(Word(alphas)) result = patt.parseString("sldkj lsdkj sldkj") # even though the result prints in string-like form, it is actually a pyparsing ParseResults print(type(result), result) # -> ['sldkj', 'lsdkj', 'sldkj'] # Use asList() to create an actual list result_list = result.asList() print(type(result_list), result_list) # -> ['sldkj', 'lsdkj', 'sldkj'] cSs"g|]}t|tr|jn|qSrw)rzr"r)rresrwrwrxrsz'ParseResults.asList..)r)rrwrwrxrszParseResults.asListcs6tr |j}n|j}fddtfdd|DS)a Returns the named parse results as a nested dictionary. Example:: integer = Word(nums) date_str = integer("year") + '/' + integer("month") + '/' + integer("day") result = date_str.parseString('12/31/1999') print(type(result), repr(result)) # -> (['12', '/', '31', '/', '1999'], {'day': [('1999', 4)], 'year': [('12', 0)], 'month': [('31', 2)]}) result_dict = result.asDict() print(type(result_dict), repr(result_dict)) # -> {'day': '1999', 'year': '12', 'month': '31'} # even though a ParseResults supports dict-like access, sometime you just need to have a dict import json print(json.dumps(result)) # -> Exception: TypeError: ... is not JSON serializable print(json.dumps(result.asDict())) # -> {"month": "31", "day": "1999", "year": "12"} cs6t|tr.|jr|jSfdd|DSn|SdS)Ncsg|] }|qSrwrw)rr)toItemrwrxrsz7ParseResults.asDict..toItem..)rzr"rasDict)r)rrwrxrs  z#ParseResults.asDict..toItemc3s|]\}}||fVqdS)Nrw)rrr)rrwrxrsz&ParseResults.asDict..)PY_3rrr)rZitem_fnrw)rrxrs  zParseResults.asDictcCs8t|j}|jj|_|j|_|jj|j|j|_|S)zA Returns a new copy of a C{ParseResults} object. )r"rrrrrrr)rrrwrwrxrs   zParseResults.copyFc CsPd}g}tdd|jjD}|d}|s8d}d}d}d} |dk rJ|} n |jrV|j} | sf|rbdSd} |||d| d g7}xt|jD]\} } t| tr| |kr|| j|| |o|dk||g7}n|| jd|o|dk||g7}qd} | |kr|| } | s |rqnd} t t | } |||d| d | d | d g 7}qW|||d | d g7}dj |S) z (Deprecated) Returns the parse results as XML. Tags are created for tokens and lists that have defined results names.  css(|] \}}|D]}|d|fVqqdS)rrNrw)rrrrrwrwrxrsz%ParseResults.asXML..z rNZITEM<>z.z %s%s- %s: z rrcss|]}t|tVqdS)N)rzr")rvvrwrwrxrssz %s%s[%d]: %s%s%sr) rrrrsortedrrzr"dumpranyrr) rrdepthfullr NLrrrrrrwrwrxrPs,   4.zParseResults.dumpcOstj|jf||dS)a Pretty-printer for parsed results as a list, using the C{pprint} module. Accepts additional positional or keyword args as defined for the C{pprint.pprint} method. (U{http://docs.python.org/3/library/pprint.html#pprint.pprint}) Example:: ident = Word(alphas, alphanums) num = Word(nums) func = Forward() term = ident | num | Group('(' + func + ')') func <<= ident + Group(Optional(delimitedList(term))) result = func.parseString("fna a,b,(fnb c,d,200),100") result.pprint(width=40) prints:: ['fna', ['a', 'b', ['(', 'fnb', ['c', 'd', '200'], ')'], '100']] N)pprintr)rrrrwrwrxr"}szParseResults.pprintcCs.|j|jj|jdk r|jp d|j|jffS)N)rrrrrr)rrwrwrx __getstate__s zParseResults.__getstate__cCsN|d|_|d\|_}}|_i|_|jj||dk rDt||_nd|_dS)Nrrr)rrrrrrr)rstaterZ inAccumNamesrwrwrx __setstate__s   zParseResults.__setstate__cCs|j|j|j|jfS)N)rrrr)rrwrwrx__getnewargs__szParseResults.__getnewargs__cCstt|t|jS)N)rrrr)rrwrwrxrszParseResults.__dir__)NNTT)N)r)NFrT)rrT)4rrrrrrzrrrrrrr __nonzero__rrrrrrrrrrrrrrrrrrrrrrrrrr rrrrrrrr"r#r%r&rrwrwrwrxr"-sh& ' 4  # =% - cCsF|}d|kot|knr4||ddkr4dS||jdd|S)aReturns current column within a string, counting newlines as line separators. The first column is number 1. Note: the default parsing behavior is to expand tabs in the input string before starting the parsing process. See L{I{ParserElement.parseString}} for more information on parsing strings containing C{}s, and suggested methods to maintain a consistent view of the parsed string, the parse location, and line and column positions within the parsed string. rrrr)rrfind)rstrgrrwrwrxr9s cCs|jdd|dS)aReturns current line number within a string, counting newlines as line separators. The first line is number 1. Note: the default parsing behavior is to expand tabs in the input string before starting the parsing process. See L{I{ParserElement.parseString}} for more information on parsing strings containing C{}s, and suggested methods to maintain a consistent view of the parsed string, the parse location, and line and column positions within the parsed string. rrrr)count)rr)rwrwrxrJs cCsF|jdd|}|jd|}|dkr2||d|S||ddSdS)zfReturns the line of text containing loc within a string, counting newlines as line separators. rrrrN)r(find)rr)ZlastCRZnextCRrwrwrxrGs  cCs8tdt|dt|dt||t||fdS)NzMatch z at loc z(%d,%d))printrrJr9)instringrexprrwrwrx_defaultStartDebugActionsr/cCs$tdt|dt|jdS)NzMatched z -> )r,rr{r)r-startlocZendlocr.toksrwrwrx_defaultSuccessDebugActionsr2cCstdt|dS)NzException raised:)r,r)r-rr.excrwrwrx_defaultExceptionDebugActionsr4cGsdS)zG'Do-nothing' debug action, to suppress debugging output during parsing.Nrw)rrwrwrxrQsrqc stkrfddSdgdgtdddkrFddd }dd d n tj}tjd }|dd d}|d|d|ffdd}d}ytdtdj}Wntk rt}YnX||_|S)Ncs|S)Nrw)rlrv)funcrwrxrysz_trim_arity..rFrqrocSs8tdkr dnd }tj| |dd|}|j|jfgS) Nror7rrqrr)limit)ror7r)system_version traceback extract_stackfilenamerJ)r8r frame_summaryrwrwrxr=sz"_trim_arity..extract_stackcSs$tj||d}|d}|j|jfgS)N)r8rrrs)r< extract_tbr>rJ)tbr8Zframesr?rwrwrxr@sz_trim_arity..extract_tb)r8rrcsxy |dd}dd<|Stk rdr>n4z.tjd}|dddddksjWd~Xdkrdd7<wYqXqWdS)NrTrrrq)r8rsrs)rr~exc_info)rrrA)r@ foundArityr6r8maxargspa_call_line_synthrwrxwrappers"  z_trim_arity..wrapperzr __class__)ror7)r)rrs) singleArgBuiltinsr;r<r=r@getattrr Exceptionr{)r6rEr=Z LINE_DIFFZ this_linerG func_namerw)r@rDr6r8rErFrx _trim_aritys*   rMcseZdZdZdZdZeddZeddZddd Z d d Z d d Z dddZ dddZ ddZddZddZddZddZddZddd Zd!d"Zdd#d$Zd%d&Zd'd(ZGd)d*d*eZed+k rGd,d-d-eZnGd.d-d-eZiZeZd/d/gZ dd0d1Z!eZ"ed2d3Z#dZ$edd5d6Z%dd7d8Z&e'dfd9d:Z(d;d<Z)e'fd=d>Z*e'dfd?d@Z+dAdBZ,dCdDZ-dEdFZ.dGdHZ/dIdJZ0dKdLZ1dMdNZ2dOdPZ3dQdRZ4dSdTZ5dUdVZ6dWdXZ7dYdZZ8dd[d\Z9d]d^Z:d_d`Z;dadbZdgdhZ?ddidjZ@dkdlZAdmdnZBdodpZCdqdrZDgfdsdtZEddudvZFfdwdxZGdydzZHd{d|ZId}d~ZJddZKdddZLdddZMZNS)r$z)Abstract base level parser element class.z FcCs |t_dS)a Overrides the default whitespace chars Example:: # default whitespace chars are space, and newline OneOrMore(Word(alphas)).parseString("abc def\nghi jkl") # -> ['abc', 'def', 'ghi', 'jkl'] # change to just treat newline as significant ParserElement.setDefaultWhitespaceChars(" \t") OneOrMore(Word(alphas)).parseString("abc def\nghi jkl") # -> ['abc', 'def'] N)r$DEFAULT_WHITE_CHARS)charsrwrwrxsetDefaultWhitespaceChars=s z'ParserElement.setDefaultWhitespaceCharscCs |t_dS)a Set class to be used for inclusion of string literals into a parser. Example:: # default literal class used is Literal integer = Word(nums) date_str = integer("year") + '/' + integer("month") + '/' + integer("day") date_str.parseString("1999/12/31") # -> ['1999', '/', '12', '/', '31'] # change to Suppress ParserElement.inlineLiteralsUsing(Suppress) date_str = integer("year") + '/' + integer("month") + '/' + integer("day") date_str.parseString("1999/12/31") # -> ['1999', '12', '31'] N)r$_literalStringClass)rrwrwrxinlineLiteralsUsingLsz!ParserElement.inlineLiteralsUsingcCst|_d|_d|_d|_||_d|_tj|_ d|_ d|_ d|_ t|_ d|_d|_d|_d|_d|_d|_d|_d|_d|_dS)NTFr)NNN)r parseAction failActionstrRepr resultsName saveAsListskipWhitespacer$rN whiteCharscopyDefaultWhiteCharsmayReturnEmptykeepTabs ignoreExprsdebug streamlined mayIndexErrorerrmsg modalResults debugActionsre callPreparse callDuringTry)rsavelistrwrwrxras(zParserElement.__init__cCs<tj|}|jdd|_|jdd|_|jr8tj|_|S)a$ Make a copy of this C{ParserElement}. Useful for defining different parse actions for the same parsing pattern, using copies of the original parse element. Example:: integer = Word(nums).setParseAction(lambda toks: int(toks[0])) integerK = integer.copy().addParseAction(lambda toks: toks[0]*1024) + Suppress("K") integerM = integer.copy().addParseAction(lambda toks: toks[0]*1024*1024) + Suppress("M") print(OneOrMore(integerK | integerM | integer).parseString("5K 100 640K 256M")) prints:: [5120, 100, 655360, 268435456] Equivalent form of C{expr.copy()} is just C{expr()}:: integerM = integer().addParseAction(lambda toks: toks[0]*1024*1024) + Suppress("M") N)rrSr]rZr$rNrY)rZcpyrwrwrxrxs  zParserElement.copycCs*||_d|j|_t|dr&|j|j_|S)af Define name for this expression, makes debugging and exception messages clearer. Example:: Word(nums).parseString("ABC") # -> Exception: Expected W:(0123...) (at char 0), (line:1, col:1) Word(nums).setName("integer").parseString("ABC") # -> Exception: Expected integer (at char 0), (line:1, col:1) z Expected exception)rrarrhr)rrrwrwrxsetNames    zParserElement.setNamecCs4|j}|jdr"|dd}d}||_| |_|S)aP Define name for referencing matching tokens as a nested attribute of the returned parse results. NOTE: this returns a *copy* of the original C{ParserElement} object; this is so that the client can define a basic element, such as an integer, and reference it in multiple places with different names. You can also set results names using the abbreviated syntax, C{expr("name")} in place of C{expr.setResultsName("name")} - see L{I{__call__}<__call__>}. Example:: date_str = (integer.setResultsName("year") + '/' + integer.setResultsName("month") + '/' + integer.setResultsName("day")) # equivalent form: date_str = integer("year") + '/' + integer("month") + '/' + integer("day") *NrrTrs)rendswithrVrb)rrlistAllMatchesZnewselfrwrwrxsetResultsNames  zParserElement.setResultsNameTcs@|r&|jdfdd }|_||_nt|jdr<|jj|_|S)zMethod to invoke the Python pdb debugger when this element is about to be parsed. Set C{breakFlag} to True to enable, False to disable. Tcsddl}|j||||S)Nr)pdbZ set_trace)r-r doActions callPreParsern) _parseMethodrwrxbreakersz'ParserElement.setBreak..breaker_originalParseMethod)TT)_parsersr)rZ breakFlagrrrw)rqrxsetBreaks  zParserElement.setBreakcOs&tttt||_|jdd|_|S)a  Define action to perform when successfully matching parse element definition. Parse action fn is a callable method with 0-3 arguments, called as C{fn(s,loc,toks)}, C{fn(loc,toks)}, C{fn(toks)}, or just C{fn()}, where: - s = the original string being parsed (see note below) - loc = the location of the matching substring - toks = a list of the matched tokens, packaged as a C{L{ParseResults}} object If the functions in fns modify the tokens, they can return them as the return value from fn, and the modified list of tokens will replace the original. Otherwise, fn does not need to return any value. Optional keyword arguments: - callDuringTry = (default=C{False}) indicate if parse action should be run during lookaheads and alternate testing Note: the default parsing behavior is to expand tabs in the input string before starting the parsing process. See L{I{parseString}} for more information on parsing strings containing C{}s, and suggested methods to maintain a consistent view of the parsed string, the parse location, and line and column positions within the parsed string. Example:: integer = Word(nums) date_str = integer + '/' + integer + '/' + integer date_str.parseString("1999/12/31") # -> ['1999', '/', '12', '/', '31'] # use parse action to convert to ints at parse time integer = Word(nums).setParseAction(lambda toks: int(toks[0])) date_str = integer + '/' + integer + '/' + integer # note that integer fields are now ints, not strings date_str.parseString("1999/12/31") # -> [1999, '/', 12, '/', 31] rfF)rmaprMrSrrf)rfnsrrwrwrxrs"zParserElement.setParseActioncOs4|jtttt|7_|jp,|jdd|_|S)z Add parse action to expression's list of parse actions. See L{I{setParseAction}}. See examples in L{I{copy}}. rfF)rSrrvrMrfr)rrwrrwrwrxaddParseActionszParserElement.addParseActioncsb|jdd|jddrtntx(|D] fdd}|jj|q&W|jpZ|jdd|_|S)aAdd a boolean predicate function to expression's list of parse actions. See L{I{setParseAction}} for function call signatures. Unlike C{setParseAction}, functions passed to C{addCondition} need to return boolean success/fail of the condition. Optional keyword arguments: - message = define a custom message to be used in the raised exception - fatal = if True, will raise ParseFatalException to stop parsing immediately; otherwise will raise ParseException Example:: integer = Word(nums).setParseAction(lambda toks: int(toks[0])) year_int = integer.copy() year_int.addCondition(lambda toks: toks[0] >= 2000, message="Only support years 2000 and later") date_str = year_int + '/' + integer + '/' + integer result = date_str.parseString("1999/12/31") # -> Exception: Only support years 2000 and later (at char 0), (line:1, col:1) messagezfailed user-defined conditionfatalFcs$tt|||s ||dS)N)rrM)rr5rv)exc_typefnrrwrxpasz&ParserElement.addCondition..parf)rr!rrSrrf)rrwrr}rw)r{r|rrx addConditions  zParserElement.addConditioncCs ||_|S)a Define action to perform if parsing fails at this expression. Fail acton fn is a callable function that takes the arguments C{fn(s,loc,expr,err)} where: - s = string being parsed - loc = location where expression match was attempted and failed - expr = the parse expression that failed - err = the exception thrown The function returns no value. It may throw C{L{ParseFatalException}} if it is desired to stop parsing immediately.)rT)rr|rwrwrx setFailActions zParserElement.setFailActionc CsZd}xP|rTd}xB|jD]8}yx|j||\}}d}qWWqtk rLYqXqWqW|S)NTF)r]rtr)rr-rZ exprsFoundeZdummyrwrwrx_skipIgnorables#s  zParserElement._skipIgnorablescCsL|jr|j||}|jrH|j}t|}x ||krF|||krF|d7}q(W|S)Nrr)r]rrXrYr)rr-rZwtinstrlenrwrwrxpreParse0s  zParserElement.preParsecCs|gfS)Nrw)rr-rrorwrwrx parseImpl<szParserElement.parseImplcCs|S)Nrw)rr-r tokenlistrwrwrx postParse?szParserElement.postParsec "Cs|j}|s|jr|jdr,|jd||||rD|jrD|j||}n|}|}yDy|j|||\}}Wn(tk rt|t||j |YnXWnXt k r} z<|jdr|jd|||| |jr|j|||| WYdd} ~ XnXn|o|jr|j||}n|}|}|j s$|t|krhy|j|||\}}Wn*tk rdt|t||j |YnXn|j|||\}}|j |||}t ||j|j|jd} |jr|s|jr|rVyRxL|jD]B} | ||| }|dk rt ||j|jot|t tf|jd} qWWnFt k rR} z(|jdr@|jd|||| WYdd} ~ XnXnNxL|jD]B} | ||| }|dk r^t ||j|jot|t tf|jd} q^W|r|jdr|jd||||| || fS)Nrrq)rrrr)r^rTrcrerrrrrrarr`rr"rVrWrbrSrfrzr) rr-rrorpZ debuggingprelocZ tokensStarttokenserrZ retTokensr|rwrwrx _parseNoCacheCsp             zParserElement._parseNoCachec Cs>y|j||dddStk r8t|||j|YnXdS)NF)ror)rtr!rra)rr-rrwrwrxtryParseszParserElement.tryParsec Cs2y|j||Wnttfk r(dSXdSdS)NFT)rrr)rr-rrwrwrx canParseNexts zParserElement.canParseNextc@seZdZddZdS)zParserElement._UnboundedCachecsdit|_fdd}fdd}fdd}tj|||_tj|||_tj|||_dS)Ncs j|S)N)r)rr)cache not_in_cacherwrxrsz3ParserElement._UnboundedCache.__init__..getcs ||<dS)Nrw)rrr)rrwrxsetsz3ParserElement._UnboundedCache.__init__..setcs jdS)N)r)r)rrwrxrsz5ParserElement._UnboundedCache.__init__..clear)rrtypes MethodTyperrr)rrrrrw)rrrxrs   z&ParserElement._UnboundedCache.__init__N)rrrrrwrwrwrx_UnboundedCachesrNc@seZdZddZdS)zParserElement._FifoCachecsht|_tfdd}fdd}fdd}tj|||_tj|||_tj|||_dS)Ncs j|S)N)r)rr)rrrwrxrsz.ParserElement._FifoCache.__init__..getcs"||<tkrjddS)NF)rpopitem)rrr)rsizerwrxrs z.ParserElement._FifoCache.__init__..setcs jdS)N)r)r)rrwrxrsz0ParserElement._FifoCache.__init__..clear)rr _OrderedDictrrrrr)rrrrrrw)rrrrxrs  z!ParserElement._FifoCache.__init__N)rrrrrwrwrwrx _FifoCachesrc@seZdZddZdS)zParserElement._FifoCachecsvt|_itjgfdd}fdd}fdd}tj|||_tj|||_tj|||_dS)Ncs j|S)N)r)rr)rrrwrxrsz.ParserElement._FifoCache.__init__..getcs2||<tkr$jjdj|dS)N)rrpopleftr)rrr)rkey_fiforrwrxrs z.ParserElement._FifoCache.__init__..setcsjjdS)N)r)r)rrrwrxrsz0ParserElement._FifoCache.__init__..clear) rr collectionsdequerrrrr)rrrrrrw)rrrrrxrs  z!ParserElement._FifoCache.__init__N)rrrrrwrwrwrxrsrc Csd\}}|||||f}tjtj}|j|} | |jkrtj|d7<y|j||||} Wn8tk r} z|j|| j | j WYdd} ~ XqX|j|| d| dj f| Sn4tj|d7<t | t r| | d| dj fSWdQRXdS)Nrrr)rrr)r$packrat_cache_lock packrat_cacherrpackrat_cache_statsrrrrHrrrzrK) rr-rrorpZHITZMISSlookuprrrrwrwrx _parseCaches$   zParserElement._parseCachecCs(tjjdgttjtjdd<dS)Nr)r$rrrrrwrwrwrx resetCaches zParserElement.resetCachecCs8tjs4dt_|dkr tjt_n tj|t_tjt_dS)aEnables "packrat" parsing, which adds memoizing to the parsing logic. Repeated parse attempts at the same string location (which happens often in many complex grammars) can immediately return a cached value, instead of re-executing parsing/validating code. Memoizing is done of both valid results and parsing exceptions. Parameters: - cache_size_limit - (default=C{128}) - if an integer value is provided will limit the size of the packrat cache; if None is passed, then the cache size will be unbounded; if 0 is passed, the cache will be effectively disabled. This speedup may break existing programs that use parse actions that have side-effects. For this reason, packrat parsing is disabled when you first import pyparsing. To activate the packrat feature, your program must call the class method C{ParserElement.enablePackrat()}. If your program uses C{psyco} to "compile as you go", you must call C{enablePackrat} before calling C{psyco.full()}. If you do not do this, Python will crash. For best results, call C{enablePackrat()} immediately after importing pyparsing. Example:: import pyparsing pyparsing.ParserElement.enablePackrat() TN)r$_packratEnabledrrrrrt)Zcache_size_limitrwrwrx enablePackrats   zParserElement.enablePackratcCstj|js|jx|jD] }|jqW|js<|j}y<|j|d\}}|rv|j||}t t }|j||Wn0t k r}ztj rn|WYdd}~XnX|SdS)aB Execute the parse expression with the given string. This is the main interface to the client code, once the complete expression has been built. If you want the grammar to require that the entire input string be successfully parsed, then set C{parseAll} to True (equivalent to ending the grammar with C{L{StringEnd()}}). Note: C{parseString} implicitly calls C{expandtabs()} on the input string, in order to report proper column numbers in parse actions. If the input string contains tabs and the grammar uses parse actions that use the C{loc} argument to index into the string being parsed, you can ensure you have a consistent view of the input string by: - calling C{parseWithTabs} on your grammar before calling C{parseString} (see L{I{parseWithTabs}}) - define your parse action using the full C{(s,loc,toks)} signature, and reference the input string using the parse action's C{s} argument - explictly expand the tabs in your input string before calling C{parseString} Example:: Word('a').parseString('aaaaabaaa') # -> ['aaaaa'] Word('a').parseString('aaaaabaaa', parseAll=True) # -> Exception: Expected end of text rN) r$rr_ streamliner]r\ expandtabsrtrr r)rverbose_stacktrace)rr-parseAllrrrZser3rwrwrx parseString#s$    zParserElement.parseStringccs@|js|jx|jD] }|jqW|js8t|j}t|}d}|j}|j}t j d} yx||kon| |kry |||} ||| dd\} } Wnt k r| d}Yq`X| |kr| d7} | | | fV|r|||} | |kr| }q|d7}n| }q`| d}q`WWn4t k r:}zt j r&n|WYdd}~XnXdS)a Scan the input string for expression matches. Each match will return the matching tokens, start location, and end location. May be called with optional C{maxMatches} argument, to clip scanning after 'n' matches are found. If C{overlap} is specified, then overlapping matches will be reported. Note that the start and end locations are reported relative to the string being parsed. See L{I{parseString}} for more information on parsing strings with embedded tabs. Example:: source = "sldjf123lsdjjkf345sldkjf879lkjsfd987" print(source) for tokens,start,end in Word(alphas).scanString(source): print(' '*start + '^'*(end-start)) print(' '*start + tokens[0]) prints:: sldjf123lsdjjkf345sldkjf879lkjsfd987 ^^^^^ sldjf ^^^^^^^ lsdjjkf ^^^^^^ sldkjf ^^^^^^ lkjsfd rF)rprrN)r_rr]r\rrrrrtr$rrrr)rr- maxMatchesZoverlaprrrZ preparseFnZparseFnmatchesrZnextLocrZnextlocr3rwrwrx scanStringUsB       zParserElement.scanStringcCsg}d}d|_yxh|j|D]Z\}}}|j||||rrt|trT||j7}nt|trh||7}n |j||}qW|j||ddd|D}djtt t |St k r}zt j rȂn|WYdd}~XnXdS)af Extension to C{L{scanString}}, to modify matching text with modified tokens that may be returned from a parse action. To use C{transformString}, define a grammar and attach a parse action to it that modifies the returned token list. Invoking C{transformString()} on a target string will then scan for matches, and replace the matched text patterns according to the logic in the parse action. C{transformString()} returns the resulting transformed string. Example:: wd = Word(alphas) wd.setParseAction(lambda toks: toks[0].title()) print(wd.transformString("now is the winter of our discontent made glorious summer by this sun of york.")) Prints:: Now Is The Winter Of Our Discontent Made Glorious Summer By This Sun Of York. rTNcSsg|] }|r|qSrwrw)rorwrwrxrsz1ParserElement.transformString..r)r\rrrzr"rrrrvr_flattenrr$r)rr-r ZlastErvrrr3rwrwrxrs(    zParserElement.transformStringcCsPytdd|j||DStk rJ}ztjr6n|WYdd}~XnXdS)a~ Another extension to C{L{scanString}}, simplifying the access to the tokens found to match the given parse expression. May be called with optional C{maxMatches} argument, to clip searching after 'n' matches are found. Example:: # a capitalized word starts with an uppercase letter, followed by zero or more lowercase letters cap_word = Word(alphas.upper(), alphas.lower()) print(cap_word.searchString("More than Iron, more than Lead, more than Gold I need Electricity")) prints:: ['More', 'Iron', 'Lead', 'Gold', 'I'] cSsg|]\}}}|qSrwrw)rrvrrrwrwrxrsz.ParserElement.searchString..N)r"rrr$r)rr-rr3rwrwrx searchStrings zParserElement.searchStringc csXd}d}x<|j||dD]*\}}}|||V|r>|dV|}qW||dVdS)a[ Generator method to split a string using the given expression as a separator. May be called with optional C{maxsplit} argument, to limit the number of splits; and the optional C{includeSeparators} argument (default=C{False}), if the separating matching text should be included in the split results. Example:: punc = oneOf(list(".,;:/-!?")) print(list(punc.split("This, this?, this sentence, is badly punctuated!"))) prints:: ['This', ' this', '', ' this sentence', ' is badly punctuated', ''] r)rN)r) rr-maxsplitZincludeSeparatorsZsplitsZlastrvrrrwrwrxrs  zParserElement.splitcCsFt|trtj|}t|ts:tjdt|tdddSt||gS)a Implementation of + operator - returns C{L{And}}. Adding strings to a ParserElement converts them to L{Literal}s by default. Example:: greet = Word(alphas) + "," + Word(alphas) + "!" hello = "Hello, World!" print (hello, "->", greet.parseString(hello)) Prints:: Hello, World! -> ['Hello', ',', 'World', '!'] z4Cannot combine element of type %s with ParserElementrq) stacklevelN) rzrr$rQwarningswarnr SyntaxWarningr)rrrwrwrxrs    zParserElement.__add__cCsBt|trtj|}t|ts:tjdt|tdddS||S)z] Implementation of + operator when left operand is not a C{L{ParserElement}} z4Cannot combine element of type %s with ParserElementrq)rN)rzrr$rQrrrr)rrrwrwrxrs    zParserElement.__radd__cCsLt|trtj|}t|ts:tjdt|tdddSt|tj |gS)zQ Implementation of - operator, returns C{L{And}} with error stop z4Cannot combine element of type %s with ParserElementrq)rN) rzrr$rQrrrrr _ErrorStop)rrrwrwrx__sub__s    zParserElement.__sub__cCsBt|trtj|}t|ts:tjdt|tdddS||S)z] Implementation of - operator when left operand is not a C{L{ParserElement}} z4Cannot combine element of type %s with ParserElementrq)rN)rzrr$rQrrrr)rrrwrwrx__rsub__ s    zParserElement.__rsub__cst|tr|d}}nt|tr|d dd}|ddkrHd|df}t|dtr|ddkr|ddkrvtS|ddkrtS|dtSnJt|dtrt|dtr|\}}||8}ntdt|dt|dntdt||dkr td|dkrtd||ko2dknrBtd |rfd d |r|dkrt|}ntg||}n|}n|dkr}ntg|}|S) a Implementation of * operator, allows use of C{expr * 3} in place of C{expr + expr + expr}. Expressions may also me multiplied by a 2-integer tuple, similar to C{{min,max}} multipliers in regular expressions. Tuples may also include C{None} as in: - C{expr*(n,None)} or C{expr*(n,)} is equivalent to C{expr*n + L{ZeroOrMore}(expr)} (read as "at least n instances of C{expr}") - C{expr*(None,n)} is equivalent to C{expr*(0,n)} (read as "0 to n instances of C{expr}") - C{expr*(None,None)} is equivalent to C{L{ZeroOrMore}(expr)} - C{expr*(1,None)} is equivalent to C{L{OneOrMore}(expr)} Note that C{expr*(None,n)} does not raise an exception if more than n exprs exist in the input stream; that is, C{expr*(None,n)} does not enforce a maximum number of expr occurrences. If this behavior is desired, then write C{expr*(None,n) + ~expr} rNrqrrz7cannot multiply 'ParserElement' and ('%s','%s') objectsz0cannot multiply 'ParserElement' and '%s' objectsz/cannot multiply ParserElement by negative valuez@second tuple value must be greater or equal to first tuple valuez+cannot multiply ParserElement by 0 or (0,0)cs(|dkrt|dStSdS)Nrr)r)n)makeOptionalListrrwrxr]sz/ParserElement.__mul__..makeOptionalList)NN) rzrutupler2rrr ValueErrorr)rrZ minElementsZ optElementsrrw)rrrx__mul__,sD             zParserElement.__mul__cCs |j|S)N)r)rrrwrwrx__rmul__pszParserElement.__rmul__cCsFt|trtj|}t|ts:tjdt|tdddSt||gS)zI Implementation of | operator - returns C{L{MatchFirst}} z4Cannot combine element of type %s with ParserElementrq)rN) rzrr$rQrrrrr)rrrwrwrx__or__ss    zParserElement.__or__cCsBt|trtj|}t|ts:tjdt|tdddS||BS)z] Implementation of | operator when left operand is not a C{L{ParserElement}} z4Cannot combine element of type %s with ParserElementrq)rN)rzrr$rQrrrr)rrrwrwrx__ror__s    zParserElement.__ror__cCsFt|trtj|}t|ts:tjdt|tdddSt||gS)zA Implementation of ^ operator - returns C{L{Or}} z4Cannot combine element of type %s with ParserElementrq)rN) rzrr$rQrrrrr)rrrwrwrx__xor__s    zParserElement.__xor__cCsBt|trtj|}t|ts:tjdt|tdddS||AS)z] Implementation of ^ operator when left operand is not a C{L{ParserElement}} z4Cannot combine element of type %s with ParserElementrq)rN)rzrr$rQrrrr)rrrwrwrx__rxor__s    zParserElement.__rxor__cCsFt|trtj|}t|ts:tjdt|tdddSt||gS)zC Implementation of & operator - returns C{L{Each}} z4Cannot combine element of type %s with ParserElementrq)rN) rzrr$rQrrrrr )rrrwrwrx__and__s    zParserElement.__and__cCsBt|trtj|}t|ts:tjdt|tdddS||@S)z] Implementation of & operator when left operand is not a C{L{ParserElement}} z4Cannot combine element of type %s with ParserElementrq)rN)rzrr$rQrrrr)rrrwrwrx__rand__s    zParserElement.__rand__cCst|S)zE Implementation of ~ operator - returns C{L{NotAny}} )r)rrwrwrx __invert__szParserElement.__invert__cCs|dk r|j|S|jSdS)a  Shortcut for C{L{setResultsName}}, with C{listAllMatches=False}. If C{name} is given with a trailing C{'*'} character, then C{listAllMatches} will be passed as C{True}. If C{name} is omitted, same as calling C{L{copy}}. Example:: # these are equivalent userdata = Word(alphas).setResultsName("name") + Word(nums+"-").setResultsName("socsecno") userdata = Word(alphas)("name") + Word(nums+"-")("socsecno") N)rmr)rrrwrwrx__call__s zParserElement.__call__cCst|S)z Suppresses the output of this C{ParserElement}; useful to keep punctuation from cluttering up returned output. )r+)rrwrwrxsuppressszParserElement.suppresscCs d|_|S)a Disables the skipping of whitespace before matching the characters in the C{ParserElement}'s defined pattern. This is normally only used internally by the pyparsing module, but may be needed in some whitespace-sensitive grammars. F)rX)rrwrwrxleaveWhitespaceszParserElement.leaveWhitespacecCsd|_||_d|_|S)z8 Overrides the default whitespace chars TF)rXrYrZ)rrOrwrwrxsetWhitespaceCharssz ParserElement.setWhitespaceCharscCs d|_|S)z Overrides default behavior to expand C{}s to spaces before parsing the input string. Must be called before C{parseString} when the input grammar contains elements that match C{} characters. T)r\)rrwrwrx parseWithTabsszParserElement.parseWithTabscCsLt|trt|}t|tr4||jkrH|jj|n|jjt|j|S)a Define expression to be ignored (e.g., comments) while doing pattern matching; may be called repeatedly, to define multiple comment or other ignorable patterns. Example:: patt = OneOrMore(Word(alphas)) patt.parseString('ablaj /* comment */ lskjd') # -> ['ablaj'] patt.ignore(cStyleComment) patt.parseString('ablaj /* comment */ lskjd') # -> ['ablaj', 'lskjd'] )rzrr+r]rr)rrrwrwrxignores   zParserElement.ignorecCs"|pt|p t|ptf|_d|_|S)zT Enable display of debugging messages while doing pattern matching. T)r/r2r4rcr^)rZ startActionZ successActionZexceptionActionrwrwrxsetDebugActions s  zParserElement.setDebugActionscCs|r|jtttnd|_|S)a Enable display of debugging messages while doing pattern matching. Set C{flag} to True to enable, False to disable. Example:: wd = Word(alphas).setName("alphaword") integer = Word(nums).setName("numword") term = wd | integer # turn on debugging for wd wd.setDebug() OneOrMore(term).parseString("abc 123 xyz 890") prints:: Match alphaword at loc 0(1,1) Matched alphaword -> ['abc'] Match alphaword at loc 3(1,4) Exception raised:Expected alphaword (at char 4), (line:1, col:5) Match alphaword at loc 7(1,8) Matched alphaword -> ['xyz'] Match alphaword at loc 11(1,12) Exception raised:Expected alphaword (at char 12), (line:1, col:13) Match alphaword at loc 15(1,16) Exception raised:Expected alphaword (at char 15), (line:1, col:16) The output shown is that produced by the default debug actions - custom debug actions can be specified using L{setDebugActions}. Prior to attempting to match the C{wd} expression, the debugging message C{"Match at loc (,)"} is shown. Then if the parse succeeds, a C{"Matched"} message is shown, or an C{"Exception raised"} message is shown. Also note the use of L{setName} to assign a human-readable name to the expression, which makes debugging and exception messages easier to understand - for instance, the default name created for the C{Word} expression without calling C{setName} is C{"W:(ABCD...)"}. F)rr/r2r4r^)rflagrwrwrxsetDebugs#zParserElement.setDebugcCs|jS)N)r)rrwrwrxr@szParserElement.__str__cCst|S)N)r)rrwrwrxrCszParserElement.__repr__cCsd|_d|_|S)NT)r_rU)rrwrwrxrFszParserElement.streamlinecCsdS)Nrw)rrrwrwrxcheckRecursionKszParserElement.checkRecursioncCs|jgdS)zj Check defined expressions for valid structure, check for infinite recursive definitions. N)r)r validateTracerwrwrxvalidateNszParserElement.validatecCsy |j}Wn2tk r>t|d}|j}WdQRXYnXy |j||Stk r|}ztjrhn|WYdd}~XnXdS)z Execute the parse expression on the given file or filename. If a filename is specified (instead of a file object), the entire file is opened, read, and closed before parsing. rN)readropenrrr$r)rZfile_or_filenamerZ file_contentsfr3rwrwrx parseFileTs   zParserElement.parseFilecsHt|tr"||kp t|t|kSt|tr6|j|Stt||kSdS)N)rzr$varsrrsuper)rr)rHrwrx__eq__hs    zParserElement.__eq__cCs ||k S)Nrw)rrrwrwrx__ne__pszParserElement.__ne__cCs tt|S)N)hashid)rrwrwrx__hash__sszParserElement.__hash__cCs||kS)Nrw)rrrwrwrx__req__vszParserElement.__req__cCs ||k S)Nrw)rrrwrwrx__rne__yszParserElement.__rne__c Cs0y|jt||ddStk r*dSXdS)a Method for quick testing of a parser against a test string. Good for simple inline microtests of sub expressions while building up larger parser. Parameters: - testString - to test against this expression for a match - parseAll - (default=C{True}) - flag to pass to C{L{parseString}} when running tests Example:: expr = Word(nums) assert expr.matches("100") )rTFN)rrr)rZ testStringrrwrwrxr|s zParserElement.matches#cCst|tr"tttj|jj}t|tr4t|}g}g}d} x|D]} |dk rb|j | dsl|rx| rx|j | qH| s~qHdj || g} g}y:| j dd} |j | |d} | j | j|d| o| } Wntk rx} zt| trdnd }d| kr0| j t| j| | j d t| j| d d |n| j d | jd || j d t| | ob|} | } WYdd} ~ XnDtk r}z&| j dt|| o|} |} WYdd}~XnX|r|r| j d tdj | |j | | fqHW| |fS)a3 Execute the parse expression on a series of test strings, showing each test, the parsed results or where the parse failed. Quick and easy way to run a parse expression against a list of sample strings. Parameters: - tests - a list of separate test strings, or a multiline string of test strings - parseAll - (default=C{True}) - flag to pass to C{L{parseString}} when running tests - comment - (default=C{'#'}) - expression for indicating embedded comments in the test string; pass None to disable comment filtering - fullDump - (default=C{True}) - dump results as list followed by results names in nested outline; if False, only dump nested list - printResults - (default=C{True}) prints test output to stdout - failureTests - (default=C{False}) indicates if these tests are expected to fail parsing Returns: a (success, results) tuple, where success indicates that all tests succeeded (or failed if C{failureTests} is True), and the results contain a list of lines of each test's output Example:: number_expr = pyparsing_common.number.copy() result = number_expr.runTests(''' # unsigned integer 100 # negative integer -100 # float with scientific notation 6.02e23 # integer with scientific notation 1e-12 ''') print("Success" if result[0] else "Failed!") result = number_expr.runTests(''' # stray character 100Z # missing leading digit before '.' -.100 # too many '.' 3.14.159 ''', failureTests=True) print("Success" if result[0] else "Failed!") prints:: # unsigned integer 100 [100] # negative integer -100 [-100] # float with scientific notation 6.02e23 [6.02e+23] # integer with scientific notation 1e-12 [1e-12] Success # stray character 100Z ^ FAIL: Expected end of text (at char 3), (line:1, col:4) # missing leading digit before '.' -.100 ^ FAIL: Expected {real number with scientific notation | real number | signed integer} (at char 0), (line:1, col:1) # too many '.' 3.14.159 ^ FAIL: Expected end of text (at char 4), (line:1, col:5) Success Each test string must be on a single line. If you want to test a string that spans multiple lines, create a test like this:: expr.runTest(r"this is a test\n of strings that spans \n 3 lines") (Note that this is a raw string literal, you must include the leading 'r'.) TNFrz\n)r)r z(FATAL)r rr^zFAIL: zFAIL-EXCEPTION: )rzrrrvr{rrstrip splitlinesrrrrrrrrr!rGrr9rKr,)rZtestsrZcommentZfullDumpZ printResultsZ failureTestsZ allResultsZcommentssuccessrvr resultrrzr3rwrwrxrunTestssNW     $   zParserElement.runTests)F)F)T)T)TT)TT)r)F)N)T)F)T)TrTTF)OrrrrrNr staticmethodrPrRrrrirmrurrxr~rrrrrrrrrrrrrrrrrrtrrrr_MAX_INTrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr __classcell__rwrw)rHrxr$8s     &     H   " 2G+    D           )    cs eZdZdZfddZZS)r,zT Abstract C{ParserElement} subclass, for defining atomic matching patterns. cstt|jdddS)NF)rg)rr,r)r)rHrwrxr szToken.__init__)rrrrrrrwrw)rHrxr, scs eZdZdZfddZZS)r z, An empty token, will always match. cs$tt|jd|_d|_d|_dS)Nr TF)rr rrr[r`)r)rHrwrxr szEmpty.__init__)rrrrrrrwrw)rHrxr  scs*eZdZdZfddZdddZZS)rz( A token that will never match. cs*tt|jd|_d|_d|_d|_dS)NrTFzUnmatchable token)rrrrr[r`ra)r)rHrwrxr* s zNoMatch.__init__TcCst|||j|dS)N)rra)rr-rrorwrwrxr1 szNoMatch.parseImpl)T)rrrrrrrrwrw)rHrxr& s cs*eZdZdZfddZdddZZS)ra Token to exactly match a specified string. Example:: Literal('blah').parseString('blah') # -> ['blah'] Literal('blah').parseString('blahfooblah') # -> ['blah'] Literal('blah').parseString('bla') # -> Exception: Expected "blah" For case-insensitive matching, use L{CaselessLiteral}. For keyword matching (force word break before and after the matched string), use L{Keyword} or L{CaselessKeyword}. c stt|j||_t||_y|d|_Wn*tk rVtj dt ddt |_ YnXdt |j|_d|j|_d|_d|_dS)Nrz2null string passed to Literal; use Empty() insteadrq)rz"%s"z Expected F)rrrmatchrmatchLenfirstMatchCharrrrrr rHrrrar[r`)r matchString)rHrwrxrC s    zLiteral.__init__TcCsJ|||jkr6|jdks&|j|j|r6||j|jfSt|||j|dS)Nrr)rr startswithrrra)rr-rrorwrwrxrV szLiteral.parseImpl)T)rrrrrrrrwrw)rHrxr5 s  csLeZdZdZedZdfdd Zddd Zfd d Ze d d Z Z S)ra\ Token to exactly match a specified string as a keyword, that is, it must be immediately followed by a non-keyword character. Compare with C{L{Literal}}: - C{Literal("if")} will match the leading C{'if'} in C{'ifAndOnlyIf'}. - C{Keyword("if")} will not; it will only match the leading C{'if'} in C{'if x=1'}, or C{'if(y==2)'} Accepts two optional constructor arguments in addition to the keyword string: - C{identChars} is a string of characters that would be valid identifier characters, defaulting to all alphanumerics + "_" and "$" - C{caseless} allows case-insensitive matching, default is C{False}. Example:: Keyword("start").parseString("start") # -> ['start'] Keyword("start").parseString("starting") # -> Exception For case-insensitive matching, use L{CaselessKeyword}. z_$NFc stt|j|dkrtj}||_t||_y|d|_Wn$tk r^t j dt ddYnXd|j|_ d|j |_ d|_d|_||_|r|j|_|j}t||_dS)Nrz2null string passed to Keyword; use Empty() insteadrq)rz"%s"z Expected F)rrrDEFAULT_KEYWORD_CHARSrrrrrrrrrrar[r`caselessupper caselessmatchr identChars)rrrr)rHrwrxrq s&    zKeyword.__init__TcCs|jr|||||jj|jkr|t||jksL|||jj|jkr|dksj||dj|jkr||j|jfSnv|||jkr|jdks|j|j|r|t||jks|||j|jkr|dks||d|jkr||j|jfSt |||j |dS)Nrrr) rrrrrrrrrrra)rr-rrorwrwrxr s*&zKeyword.parseImplcstt|j}tj|_|S)N)rrrrr)rr)rHrwrxr sz Keyword.copycCs |t_dS)z,Overrides the default Keyword chars N)rr)rOrwrwrxsetDefaultKeywordChars szKeyword.setDefaultKeywordChars)NF)T) rrrrr3rrrrrrrrwrw)rHrxr^ s   cs*eZdZdZfddZdddZZS)ral Token to match a specified string, ignoring case of letters. Note: the matched results will always be in the case of the given match string, NOT the case of the input text. Example:: OneOrMore(CaselessLiteral("CMD")).parseString("cmd CMD Cmd10") # -> ['CMD', 'CMD', 'CMD'] (Contrast with example for L{CaselessKeyword}.) cs6tt|j|j||_d|j|_d|j|_dS)Nz'%s'z Expected )rrrr returnStringrra)rr)rHrwrxr s zCaselessLiteral.__init__TcCs@||||jj|jkr,||j|jfSt|||j|dS)N)rrrrrra)rr-rrorwrwrxr szCaselessLiteral.parseImpl)T)rrrrrrrrwrw)rHrxr s  cs,eZdZdZdfdd Zd ddZZS) rz Caseless version of L{Keyword}. Example:: OneOrMore(CaselessKeyword("CMD")).parseString("cmd CMD Cmd10") # -> ['CMD', 'CMD'] (Contrast with example for L{CaselessLiteral}.) Ncstt|j||dddS)NT)r)rrr)rrr)rHrwrxr szCaselessKeyword.__init__TcCsj||||jj|jkrV|t||jksF|||jj|jkrV||j|jfSt|||j|dS)N)rrrrrrrra)rr-rrorwrwrxr s*zCaselessKeyword.parseImpl)N)T)rrrrrrrrwrw)rHrxr scs,eZdZdZdfdd Zd ddZZS) rlax A variation on L{Literal} which matches "close" matches, that is, strings with at most 'n' mismatching characters. C{CloseMatch} takes parameters: - C{match_string} - string to be matched - C{maxMismatches} - (C{default=1}) maximum number of mismatches allowed to count as a match The results from a successful parse will contain the matched text from the input string and the following named results: - C{mismatches} - a list of the positions within the match_string where mismatches were found - C{original} - the original match_string used to compare against the input string If C{mismatches} is an empty list, then the match was an exact match. Example:: patt = CloseMatch("ATCATCGAATGGA") patt.parseString("ATCATCGAAXGGA") # -> (['ATCATCGAAXGGA'], {'mismatches': [[9]], 'original': ['ATCATCGAATGGA']}) patt.parseString("ATCAXCGAAXGGA") # -> Exception: Expected 'ATCATCGAATGGA' (with up to 1 mismatches) (at char 0), (line:1, col:1) # exact match patt.parseString("ATCATCGAATGGA") # -> (['ATCATCGAATGGA'], {'mismatches': [[]], 'original': ['ATCATCGAATGGA']}) # close match allowing up to 2 mismatches patt = CloseMatch("ATCATCGAATGGA", maxMismatches=2) patt.parseString("ATCAXCGAAXGGA") # -> (['ATCAXCGAAXGGA'], {'mismatches': [[4, 9]], 'original': ['ATCATCGAATGGA']}) rrcsBtt|j||_||_||_d|j|jf|_d|_d|_dS)Nz&Expected %r (with up to %d mismatches)F) rrlrr match_string maxMismatchesrar`r[)rrr)rHrwrxr szCloseMatch.__init__TcCs|}t|}|t|j}||kr|j}d}g} |j} xtt||||jD]0\}} | \} } | | krP| j|t| | krPPqPW|d}t|||g}|j|d<| |d<||fSt|||j|dS)NrrrZoriginal mismatches) rrrrrrr"rra)rr-rrostartrmaxlocrZmatch_stringlocrrZs_msrcmatresultsrwrwrxr s("   zCloseMatch.parseImpl)rr)T)rrrrrrrrwrw)rHrxrl s cs8eZdZdZd fdd Zdd d Zfd d ZZS)r/a Token for matching words composed of allowed character sets. Defined with string containing all allowed initial characters, an optional string containing allowed body characters (if omitted, defaults to the initial character set), and an optional minimum, maximum, and/or exact length. The default value for C{min} is 1 (a minimum value < 1 is not valid); the default values for C{max} and C{exact} are 0, meaning no maximum or exact length restriction. An optional C{excludeChars} parameter can list characters that might be found in the input C{bodyChars} string; useful to define a word of all printables except for one or two characters, for instance. L{srange} is useful for defining custom character set strings for defining C{Word} expressions, using range notation from regular expression character sets. A common mistake is to use C{Word} to match a specific literal string, as in C{Word("Address")}. Remember that C{Word} uses the string argument to define I{sets} of matchable characters. This expression would match "Add", "AAA", "dAred", or any other word made up of the characters 'A', 'd', 'r', 'e', and 's'. To match an exact literal string, use L{Literal} or L{Keyword}. pyparsing includes helper strings for building Words: - L{alphas} - L{nums} - L{alphanums} - L{hexnums} - L{alphas8bit} (alphabetic characters in ASCII range 128-255 - accented, tilded, umlauted, etc.) - L{punc8bit} (non-alphabetic characters in ASCII range 128-255 - currency, symbols, superscripts, diacriticals, etc.) - L{printables} (any non-whitespace character) Example:: # a word composed of digits integer = Word(nums) # equivalent to Word("0123456789") or Word(srange("0-9")) # a word with a leading capital, and zero or more lowercase capital_word = Word(alphas.upper(), alphas.lower()) # hostnames are alphanumeric, with leading alpha, and '-' hostname = Word(alphas, alphanums+'-') # roman numeral (not a strict parser, accepts invalid mix of characters) roman = Word("IVXLCDM") # any string of non-whitespace characters, except for ',' csv_value = Word(printables, excludeChars=",") NrrrFc stt|jrFdjfdd|D}|rFdjfdd|D}||_t||_|rl||_t||_n||_t||_|dk|_ |dkrt d||_ |dkr||_ nt |_ |dkr||_ ||_ t||_d|j|_d |_||_d |j|jkr|dkr|dkr|dkr|j|jkr8d t|j|_nHt|jdkrfd tj|jt|jf|_nd t|jt|jf|_|jrd|jd|_ytj|j|_Wntk rd|_YnXdS)Nrc3s|]}|kr|VqdS)Nrw)rr) excludeCharsrwrxr7 sz Word.__init__..c3s|]}|kr|VqdS)Nrw)rr)rrwrxr9 srrrzZcannot specify a minimum length < 1; use Optional(Word()) if zero-length word is permittedz Expected Frz[%s]+z%s[%s]*z [%s][%s]*z\b)rr/rr initCharsOrigr initChars bodyCharsOrig bodyChars maxSpecifiedrminLenmaxLenrrrrar` asKeyword_escapeRegexRangeCharsreStringrrdescapecompilerK)rrrminmaxexactrr)rH)rrxr4 sT      0 z Word.__init__Tc CsD|jr<|jj||}|s(t|||j||j}||jfS|||jkrZt|||j||}|d7}t|}|j}||j }t ||}x ||kr|||kr|d7}qWd} |||j krd} |j r||kr|||krd} |j r|dkr||d|ks||kr|||krd} | r4t|||j|||||fS)NrrFTr)rdrrraendgrouprrrrr rrr) rr-rrorrrZ bodycharsrZthrowExceptionrwrwrxrj s6    4zWord.parseImplc stytt|jStk r"YnX|jdkrndd}|j|jkr^d||j||jf|_nd||j|_|jS)NcSs$t|dkr|dddS|SdS)Nz...)r)rrwrwrx charsAsStr s z Word.__str__..charsAsStrz W:(%s,%s)zW:(%s))rr/rrKrUrr)rr)rHrwrxr s  z Word.__str__)NrrrrFN)T)rrrrrrrrrwrw)rHrxr/ s.6 #csFeZdZdZeejdZd fdd Zd ddZ fd d Z Z S) r'a Token for matching strings that match a given regular expression. Defined with string specifying the regular expression in a form recognized by the inbuilt Python re module. If the given regex contains named groups (defined using C{(?P...)}), these will be preserved as named parse results. Example:: realnum = Regex(r"[+-]?\d+\.\d*") date = Regex(r'(?P\d{4})-(?P\d\d?)-(?P\d\d?)') # ref: http://stackoverflow.com/questions/267399/how-do-you-match-only-valid-roman-numerals-with-a-regular-expression roman = Regex(r"M{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})") z[A-Z]rc stt|jt|tr|s,tjdtdd||_||_ yt j |j|j |_ |j|_ Wqt jk rtjd|tddYqXn2t|tjr||_ t||_|_ ||_ ntdt||_d|j|_d|_d|_d S) zThe parameters C{pattern} and C{flags} are passed to the C{re.compile()} function as-is. See the Python C{re} module for an explanation of the acceptable patterns and flags.z0null string passed to Regex; use Empty() insteadrq)rz$invalid pattern (%s) passed to RegexzCRegex may only be constructed with a string or a compiled RE objectz Expected FTN)rr'rrzrrrrpatternflagsrdr r sre_constantserrorcompiledREtyper{rrrrar`r[)rrr)rHrwrxr s.         zRegex.__init__TcCsd|jj||}|s"t|||j||j}|j}t|j}|r\x|D]}||||<qHW||fS)N)rdrrrar  groupdictr"r)rr-rrordrrrwrwrxr s  zRegex.parseImplc sDytt|jStk r"YnX|jdkr>dt|j|_|jS)NzRe:(%s))rr'rrKrUrr)r)rHrwrxr s z Regex.__str__)r)T) rrrrrrdr rrrrrrwrw)rHrxr' s  " cs8eZdZdZd fdd Zd ddZfd d ZZS) r%a Token for matching strings that are delimited by quoting characters. Defined with the following parameters: - quoteChar - string of one or more characters defining the quote delimiting string - escChar - character to escape quotes, typically backslash (default=C{None}) - escQuote - special quote sequence to escape an embedded quote string (such as SQL's "" to escape an embedded ") (default=C{None}) - multiline - boolean indicating whether quotes can span multiple lines (default=C{False}) - unquoteResults - boolean indicating whether the matched text should be unquoted (default=C{True}) - endQuoteChar - string of one or more characters defining the end of the quote delimited string (default=C{None} => same as quoteChar) - convertWhitespaceEscapes - convert escaped whitespace (C{'\t'}, C{'\n'}, etc.) to actual whitespace (default=C{True}) Example:: qs = QuotedString('"') print(qs.searchString('lsjdf "This is the quote" sldjf')) complex_qs = QuotedString('{{', endQuoteChar='}}') print(complex_qs.searchString('lsjdf {{This is the "quote"}} sldjf')) sql_qs = QuotedString('"', escQuote='""') print(sql_qs.searchString('lsjdf "This is the quote with ""embedded"" quotes" sldjf')) prints:: [['This is the quote']] [['This is the "quote"']] [['This is the quote with "embedded" quotes']] NFTc sNttj|j}|s0tjdtddt|dkr>|}n"|j}|s`tjdtddt|_t |_ |d_ |_ t |_ |_|_|_|_|rtjtjB_dtjjtj d|dk rt|pdf_n.)z|(?:%s)z|(?:%s.)z(.)z)*%sz$invalid pattern (%s) passed to Regexz Expected FTrs)%rr%rrrrr SyntaxError quoteCharr quoteCharLenfirstQuoteCharrendQuoteCharLenescCharescQuoteunquoteResultsconvertWhitespaceEscapesrd MULTILINEDOTALLrrrrrrescCharReplacePatternr rrrrrrar`r[)rrrr Z multiliner!rr")rH)rrxr sf       6     zQuotedString.__init__c Cs|||jkr|jj||pd}|s4t|||j||j}|j}|jr||j|j }t |t rd|kr|j rddddd}x |j D]\}}|j||}qW|jrtj|jd|}|jr|j|j|j}||fS)N\ r  )z\tz\nz\fz\rz\g<1>)rrdrrrar rr!rrrzrr"rrrrr%r r) rr-rrorrZws_mapZwslitZwscharrwrwrxrG s(  zQuotedString.parseImplc sFytt|jStk r"YnX|jdkr@d|j|jf|_|jS)Nz.quoted string, starting with %s ending with %s)rr%rrKrUrr)r)rHrwrxrj s zQuotedString.__str__)NNFTNT)T)rrrrrrrrrwrw)rHrxr% sA #cs8eZdZdZd fdd Zd ddZfd d ZZS) r a Token for matching words composed of characters I{not} in a given set (will include whitespace in matched characters if not listed in the provided exclusion set - see example). Defined with string containing all disallowed characters, and an optional minimum, maximum, and/or exact length. The default value for C{min} is 1 (a minimum value < 1 is not valid); the default values for C{max} and C{exact} are 0, meaning no maximum or exact length restriction. Example:: # define a comma-separated-value as anything that is not a ',' csv_value = CharsNotIn(',') print(delimitedList(csv_value).parseString("dkls,lsdkjf,s12 34,@!#,213")) prints:: ['dkls', 'lsdkjf', 's12 34', '@!#', '213'] rrrcstt|jd|_||_|dkr*td||_|dkr@||_nt|_|dkrZ||_||_t ||_ d|j |_ |jdk|_ d|_ dS)NFrrzfcannot specify a minimum length < 1; use Optional(CharsNotIn()) if zero-length char group is permittedrz Expected )rr rrXnotCharsrrrrrrrar[r`)rr*r r r )rHrwrxr s    zCharsNotIn.__init__TcCs|||jkrt|||j||}|d7}|j}t||jt|}x ||krd|||krd|d7}qFW|||jkrt|||j|||||fS)Nrr)r*rrar rrr)rr-rrorZnotcharsmaxlenrwrwrxr s   zCharsNotIn.parseImplc sdytt|jStk r"YnX|jdkr^t|jdkrRd|jdd|_n d|j|_|jS)Nrz !W:(%s...)z!W:(%s))rr rrKrUrr*)r)rHrwrxr s  zCharsNotIn.__str__)rrrr)T)rrrrrrrrrwrw)rHrxr v s cs<eZdZdZddddddZdfd d ZdddZZS)r.a Special matching class for matching whitespace. Normally, whitespace is ignored by pyparsing grammars. This class is included when some whitespace structures are significant. Define with a string containing the whitespace characters to be matched; default is C{" \t\r\n"}. Also takes optional C{min}, C{max}, and C{exact} arguments, as defined for the C{L{Word}} class. zzzzz)rr'rr)r( rrrcsttj|_jdjfddjDdjddjD_d_dj_ |_ |dkrt|_ nt _ |dkr|_ |_ dS)Nrc3s|]}|jkr|VqdS)N) matchWhite)rr)rrwrxr sz!White.__init__..css|]}tj|VqdS)N)r. whiteStrs)rrrwrwrxr sTz Expected r) rr.rr-rrrYrr[rarrr)rZwsr r r )rH)rrxr s  zWhite.__init__TcCs|||jkrt|||j||}|d7}||j}t|t|}x"||krd|||jkrd|d7}qDW|||jkrt|||j|||||fS)Nrr)r-rrarr rr)rr-rrorrrwrwrxr s  zWhite.parseImpl)r,rrrr)T)rrrrr.rrrrwrw)rHrxr. scseZdZfddZZS)_PositionTokencs(tt|j|jj|_d|_d|_dS)NTF)rr/rrHrrr[r`)r)rHrwrxr s z_PositionToken.__init__)rrrrrrwrw)rHrxr/ sr/cs2eZdZdZfddZddZd ddZZS) rzb Token to advance to a specific column of input text; useful for tabular report scraping. cstt|j||_dS)N)rrrr9)rcolno)rHrwrxr szGoToColumn.__init__cCs`t|||jkr\t|}|jr*|j||}x0||krZ||jrZt|||jkrZ|d7}q,W|S)Nrr)r9rr]risspace)rr-rrrwrwrxr s & zGoToColumn.preParseTcCsDt||}||jkr"t||d|||j|}|||}||fS)NzText not in expected column)r9r)rr-rroZthiscolZnewlocrrwrwrxr s    zGoToColumn.parseImpl)T)rrrrrrrrrwrw)rHrxr s  cs*eZdZdZfddZdddZZS)ra Matches if current position is at the beginning of a line within the parse string Example:: test = ''' AAA this line AAA and this line AAA but not this one B AAA and definitely not this one ''' for t in (LineStart() + 'AAA' + restOfLine).searchString(test): print(t) Prints:: ['AAA', ' this line'] ['AAA', ' and this line'] cstt|jd|_dS)NzExpected start of line)rrrra)r)rHrwrxr& szLineStart.__init__TcCs*t||dkr|gfSt|||j|dS)Nrr)r9rra)rr-rrorwrwrxr* szLineStart.parseImpl)T)rrrrrrrrwrw)rHrxr s cs*eZdZdZfddZdddZZS)rzU Matches if current position is at the end of a line within the parse string cs,tt|j|jtjjddd|_dS)NrrzExpected end of line)rrrrr$rNrra)r)rHrwrxr3 szLineEnd.__init__TcCsb|t|kr6||dkr$|ddfSt|||j|n(|t|krN|dgfSt|||j|dS)Nrrr)rrra)rr-rrorwrwrxr8 s     zLineEnd.parseImpl)T)rrrrrrrrwrw)rHrxr/ s cs*eZdZdZfddZdddZZS)r*zM Matches if current position is at the beginning of the parse string cstt|jd|_dS)NzExpected start of text)rr*rra)r)rHrwrxrG szStringStart.__init__TcCs0|dkr(||j|dkr(t|||j||gfS)Nr)rrra)rr-rrorwrwrxrK szStringStart.parseImpl)T)rrrrrrrrwrw)rHrxr*C s cs*eZdZdZfddZdddZZS)r)zG Matches if current position is at the end of the parse string cstt|jd|_dS)NzExpected end of text)rr)rra)r)rHrwrxrV szStringEnd.__init__TcCs^|t|krt|||j|n<|t|kr6|dgfS|t|krJ|gfSt|||j|dS)Nrr)rrra)rr-rrorwrwrxrZ s    zStringEnd.parseImpl)T)rrrrrrrrwrw)rHrxr)R s cs.eZdZdZeffdd ZdddZZS)r1ap Matches if the current position is at the beginning of a Word, and is not preceded by any character in a given set of C{wordChars} (default=C{printables}). To emulate the C{} behavior of regular expressions, use C{WordStart(alphanums)}. C{WordStart} will also match at the beginning of the string being parsed, or at the beginning of a line. cs"tt|jt||_d|_dS)NzNot at the start of a word)rr1rr wordCharsra)rr2)rHrwrxrl s zWordStart.__init__TcCs@|dkr8||d|jks(|||jkr8t|||j||gfS)Nrrr)r2rra)rr-rrorwrwrxrq s zWordStart.parseImpl)T)rrrrrVrrrrwrw)rHrxr1d scs.eZdZdZeffdd ZdddZZS)r0aZ Matches if the current position is at the end of a Word, and is not followed by any character in a given set of C{wordChars} (default=C{printables}). To emulate the C{} behavior of regular expressions, use C{WordEnd(alphanums)}. C{WordEnd} will also match at the end of the string being parsed, or at the end of a line. cs(tt|jt||_d|_d|_dS)NFzNot at the end of a word)rr0rrr2rXra)rr2)rHrwrxr s zWordEnd.__init__TcCsPt|}|dkrH||krH|||jks8||d|jkrHt|||j||gfS)Nrrr)rr2rra)rr-rrorrwrwrxr s zWordEnd.parseImpl)T)rrrrrVrrrrwrw)rHrxr0x scseZdZdZdfdd ZddZddZd d Zfd d Zfd dZ fddZ dfdd Z gfddZ fddZ ZS)r z^ Abstract subclass of ParserElement, for combining and post-processing parsed tokens. Fc stt|j|t|tr"t|}t|tr.F)rr rrzrrrr$rQexprsrIterableallrvrre)rr3rg)rHrwrxr s     zParseExpression.__init__cCs |j|S)N)r3)rrrwrwrxr szParseExpression.__getitem__cCs|jj|d|_|S)N)r3rrU)rrrwrwrxr s zParseExpression.appendcCs4d|_dd|jD|_x|jD] }|jq W|S)z~Extends C{leaveWhitespace} defined in base class, and also invokes C{leaveWhitespace} on all contained expressions.FcSsg|] }|jqSrw)r)rrrwrwrxr sz3ParseExpression.leaveWhitespace..)rXr3r)rrrwrwrxr s   zParseExpression.leaveWhitespacecszt|trF||jkrvtt|j|xP|jD]}|j|jdq,Wn0tt|j|x|jD]}|j|jdq^W|S)Nrrrsrs)rzr+r]rr rr3)rrr)rHrwrxr s    zParseExpression.ignorec sLytt|jStk r"YnX|jdkrFd|jjt|jf|_|jS)Nz%s:(%s)) rr rrKrUrHrrr3)r)rHrwrxr s zParseExpression.__str__cs0tt|jx|jD] }|jqWt|jdkr|jd}t||jr|j r|jdkr|j r|jdd|jdg|_d|_ |j |j O_ |j |j O_ |jd}t||jo|j o|jdko|j r|jdd|jdd|_d|_ |j |j O_ |j |j O_ dt ||_|S)Nrqrrrz Expected rsrs)rr rr3rrzrHrSrVr^rUr[r`rra)rrr)rHrwrxr s0         zParseExpression.streamlinecstt|j||}|S)N)rr rm)rrrlr)rHrwrxrm szParseExpression.setResultsNamecCs:|dd|g}x|jD]}|j|qW|jgdS)N)r3rr)rrtmprrwrwrxr s zParseExpression.validatecs$tt|j}dd|jD|_|S)NcSsg|] }|jqSrw)r)rrrwrwrxr sz(ParseExpression.copy..)rr rr3)rr)rHrwrxr szParseExpression.copy)F)F)rrrrrrrrrrrrmrrrrwrw)rHrxr s " csTeZdZdZGdddeZdfdd ZdddZd d Zd d Z d dZ Z S)ra  Requires all given C{ParseExpression}s to be found in the given order. Expressions may be separated by whitespace. May be constructed using the C{'+'} operator. May also be constructed using the C{'-'} operator, which will suppress backtracking. Example:: integer = Word(nums) name_expr = OneOrMore(Word(alphas)) expr = And([integer("id"),name_expr("name"),integer("age")]) # more easily written as: expr = integer("id") + name_expr("name") + integer("age") cseZdZfddZZS)zAnd._ErrorStopcs&ttj|j||d|_|jdS)N-)rrrrrr)rrr)rHrwrxr szAnd._ErrorStop.__init__)rrrrrrwrw)rHrxr srTcsRtt|j||tdd|jD|_|j|jdj|jdj|_d|_ dS)Ncss|] }|jVqdS)N)r[)rrrwrwrxr szAnd.__init__..rT) rrrr5r3r[rrYrXre)rr3rg)rHrwrxr s z And.__init__c Cs|jdj|||dd\}}d}x|jddD]}t|tjrFd}q0|ry|j|||\}}Wqtk rvYqtk r}zd|_tj|WYdd}~Xqt k rt|t ||j |YqXn|j|||\}}|s|j r0||7}q0W||fS)NrF)rprrT) r3rtrzrrr#r __traceback__rrrrar) rr-rro resultlistZ errorStoprZ exprtokensrrwrwrxr s(   z And.parseImplcCst|trtj|}|j|S)N)rzrr$rQr)rrrwrwrxr5 s  z And.__iadd__cCs8|dd|g}x |jD]}|j||jsPqWdS)N)r3rr[)rrsubRecCheckListrrwrwrxr: s   zAnd.checkRecursioncCs@t|dr|jS|jdkr:ddjdd|jDd|_|jS)Nr{rcss|]}t|VqdS)N)r)rrrwrwrxrF szAnd.__str__..})rrrUrr3)rrwrwrxrA s    z And.__str__)T)T) rrrrr rrrrrrrrwrw)rHrxr s csDeZdZdZdfdd ZdddZdd Zd d Zd d ZZ S)ra Requires that at least one C{ParseExpression} is found. If two expressions match, the expression that matches the longest string will be used. May be constructed using the C{'^'} operator. Example:: # construct Or using '^' operator number = Word(nums) ^ Combine(Word(nums) + '.' + Word(nums)) print(number.searchString("123 3.1416 789")) prints:: [['123'], ['3.1416'], ['789']] Fcs:tt|j|||jr0tdd|jD|_nd|_dS)Ncss|] }|jVqdS)N)r[)rrrwrwrxr\ szOr.__init__..T)rrrr3rr[)rr3rg)rHrwrxrY sz Or.__init__Tc CsTd}d}g}x|jD]}y|j||}Wnvtk rd} z d| _| j|krT| }| j}WYdd} ~ Xqtk rt||krt|t||j|}t|}YqX|j||fqW|r*|j dddx`|D]X\} }y|j |||Stk r$} z"d| _| j|kr| }| j}WYdd} ~ XqXqW|dk rB|j|_ |nt||d|dS)NrrcSs |d S)Nrrw)xrwrwrxryu szOr.parseImpl..)rz no defined alternatives to matchrs) r3rrr8rrrrarsortrtr) rr-rro maxExcLoc maxExceptionrrZloc2r_rwrwrxr` s<     z Or.parseImplcCst|trtj|}|j|S)N)rzrr$rQr)rrrwrwrx__ixor__ s  z Or.__ixor__cCs@t|dr|jS|jdkr:ddjdd|jDd|_|jS)Nrr;z ^ css|]}t|VqdS)N)r)rrrwrwrxr szOr.__str__..r<)rrrUrr3)rrwrwrxr s    z Or.__str__cCs0|dd|g}x|jD]}|j|qWdS)N)r3r)rrr:rrwrwrxr s zOr.checkRecursion)F)T) rrrrrrrBrrrrwrw)rHrxrK s   & csDeZdZdZdfdd ZdddZdd Zd d Zd d ZZ S)ra Requires that at least one C{ParseExpression} is found. If two expressions match, the first one listed is the one that will match. May be constructed using the C{'|'} operator. Example:: # construct MatchFirst using '|' operator # watch the order of expressions to match number = Word(nums) | Combine(Word(nums) + '.' + Word(nums)) print(number.searchString("123 3.1416 789")) # Fail! -> [['123'], ['3'], ['1416'], ['789']] # put more selective expression first number = Combine(Word(nums) + '.' + Word(nums)) | Word(nums) print(number.searchString("123 3.1416 789")) # Better -> [['123'], ['3.1416'], ['789']] Fcs:tt|j|||jr0tdd|jD|_nd|_dS)Ncss|] }|jVqdS)N)r[)rrrwrwrxr sz&MatchFirst.__init__..T)rrrr3rr[)rr3rg)rHrwrxr szMatchFirst.__init__Tc Csd}d}x|jD]}y|j|||}|Stk r\}z|j|krL|}|j}WYdd}~Xqtk rt||krt|t||j|}t|}YqXqW|dk r|j|_|nt||d|dS)Nrrz no defined alternatives to matchrs)r3rtrrrrrar) rr-rror?r@rrrrwrwrxr s$   zMatchFirst.parseImplcCst|trtj|}|j|S)N)rzrr$rQr)rrrwrwrx__ior__ s  zMatchFirst.__ior__cCs@t|dr|jS|jdkr:ddjdd|jDd|_|jS)Nrr;z | css|]}t|VqdS)N)r)rrrwrwrxr sz%MatchFirst.__str__..r<)rrrUrr3)rrwrwrxr s    zMatchFirst.__str__cCs0|dd|g}x|jD]}|j|qWdS)N)r3r)rrr:rrwrwrxr s zMatchFirst.checkRecursion)F)T) rrrrrrrCrrrrwrw)rHrxr s   cs<eZdZdZd fdd Zd ddZddZd d ZZS) r am Requires all given C{ParseExpression}s to be found, but in any order. Expressions may be separated by whitespace. May be constructed using the C{'&'} operator. Example:: color = oneOf("RED ORANGE YELLOW GREEN BLUE PURPLE BLACK WHITE BROWN") shape_type = oneOf("SQUARE CIRCLE TRIANGLE STAR HEXAGON OCTAGON") integer = Word(nums) shape_attr = "shape:" + shape_type("shape") posn_attr = "posn:" + Group(integer("x") + ',' + integer("y"))("posn") color_attr = "color:" + color("color") size_attr = "size:" + integer("size") # use Each (using operator '&') to accept attributes in any order # (shape and posn are required, color and size are optional) shape_spec = shape_attr & posn_attr & Optional(color_attr) & Optional(size_attr) shape_spec.runTests(''' shape: SQUARE color: BLACK posn: 100, 120 shape: CIRCLE size: 50 color: BLUE posn: 50,80 color:GREEN size:20 shape:TRIANGLE posn:20,40 ''' ) prints:: shape: SQUARE color: BLACK posn: 100, 120 ['shape:', 'SQUARE', 'color:', 'BLACK', 'posn:', ['100', ',', '120']] - color: BLACK - posn: ['100', ',', '120'] - x: 100 - y: 120 - shape: SQUARE shape: CIRCLE size: 50 color: BLUE posn: 50,80 ['shape:', 'CIRCLE', 'size:', '50', 'color:', 'BLUE', 'posn:', ['50', ',', '80']] - color: BLUE - posn: ['50', ',', '80'] - x: 50 - y: 80 - shape: CIRCLE - size: 50 color: GREEN size: 20 shape: TRIANGLE posn: 20,40 ['color:', 'GREEN', 'size:', '20', 'shape:', 'TRIANGLE', 'posn:', ['20', ',', '40']] - color: GREEN - posn: ['20', ',', '40'] - x: 20 - y: 40 - shape: TRIANGLE - size: 20 Tcs8tt|j||tdd|jD|_d|_d|_dS)Ncss|] }|jVqdS)N)r[)rrrwrwrxrsz Each.__init__..T)rr rr5r3r[rXinitExprGroups)rr3rg)rHrwrxrsz Each.__init__c s|jrtdd|jD|_dd|jD}dd|jD}|||_dd|jD|_dd|jD|_dd|jD|_|j|j7_d |_|}|jdd}|jddg}d } x| rp||j|j} g} x~| D]v} y| j||}Wn t k r| j | YqX|j |jj t | | | |krD|j | q| krj | qWt| t| krd } qW|rd jd d|D} t ||d | |fdd|jD7}g}x*|D]"} | j|||\}}|j |qWt|tg}||fS)Ncss&|]}t|trt|j|fVqdS)N)rzrrr.)rrrwrwrxrsz!Each.parseImpl..cSsg|]}t|tr|jqSrw)rzrr.)rrrwrwrxrsz"Each.parseImpl..cSs"g|]}|jrt|t r|qSrw)r[rzr)rrrwrwrxrscSsg|]}t|tr|jqSrw)rzr2r.)rrrwrwrxr scSsg|]}t|tr|jqSrw)rzrr.)rrrwrwrxr!scSs g|]}t|tttfs|qSrw)rzrr2r)rrrwrwrxr"sFTz, css|]}t|VqdS)N)r)rrrwrwrxr=sz*Missing one or more required elements (%s)cs$g|]}t|tr|jkr|qSrw)rzrr.)rr)tmpOptrwrxrAs)rDrr3Zopt1mapZ optionalsZmultioptionalsZ multirequiredZrequiredrrrrrremoverrrtsumr")rr-rroZopt1Zopt2ZtmpLocZtmpReqdZ matchOrderZ keepMatchingZtmpExprsZfailedrZmissingr9rZ finalResultsrw)rErxrsP     zEach.parseImplcCs@t|dr|jS|jdkr:ddjdd|jDd|_|jS)Nrr;z & css|]}t|VqdS)N)r)rrrwrwrxrPszEach.__str__..r<)rrrUrr3)rrwrwrxrKs    z Each.__str__cCs0|dd|g}x|jD]}|j|qWdS)N)r3r)rrr:rrwrwrxrTs zEach.checkRecursion)T)T) rrrrrrrrrrwrw)rHrxr s 5 1 csleZdZdZdfdd ZdddZdd Zfd d Zfd d ZddZ gfddZ fddZ Z S)rza Abstract subclass of C{ParserElement}, for combining and post-processing parsed tokens. Fcstt|j|t|tr@ttjtr2tj|}ntjt |}||_ d|_ |dk r|j |_ |j |_ |j|j|j|_|j|_|j|_|jj|jdS)N)rrrrzr issubclassr$rQr,rr.rUr`r[rrYrXrWrer]r)rr.rg)rHrwrxr^s    zParseElementEnhance.__init__TcCs2|jdk r|jj|||ddStd||j|dS)NF)rpr)r.rtrra)rr-rrorwrwrxrps zParseElementEnhance.parseImplcCs*d|_|jj|_|jdk r&|jj|S)NF)rXr.rr)rrwrwrxrvs    z#ParseElementEnhance.leaveWhitespacecsrt|trB||jkrntt|j||jdk rn|jj|jdn,tt|j||jdk rn|jj|jd|S)Nrrrsrs)rzr+r]rrrr.)rr)rHrwrxr}s    zParseElementEnhance.ignorecs&tt|j|jdk r"|jj|S)N)rrrr.)r)rHrwrxrs  zParseElementEnhance.streamlinecCsB||krt||g|dd|g}|jdk r>|jj|dS)N)r&r.r)rrr:rwrwrxrs  z"ParseElementEnhance.checkRecursioncCs6|dd|g}|jdk r(|jj||jgdS)N)r.rr)rrr6rwrwrxrs  zParseElementEnhance.validatec sVytt|jStk r"YnX|jdkrP|jdk rPd|jjt|jf|_|jS)Nz%s:(%s)) rrrrKrUr.rHrr)r)rHrwrxrszParseElementEnhance.__str__)F)T) rrrrrrrrrrrrrrwrw)rHrxrZs   cs*eZdZdZfddZdddZZS)ra Lookahead matching of the given parse expression. C{FollowedBy} does I{not} advance the parsing position within the input string, it only verifies that the specified parse expression matches at the current position. C{FollowedBy} always returns a null token list. Example:: # use FollowedBy to match a label only if it is followed by a ':' data_word = Word(alphas) label = data_word + FollowedBy(':') attr_expr = Group(label + Suppress(':') + OneOrMore(data_word, stopOn=label).setParseAction(' '.join)) OneOrMore(attr_expr).parseString("shape: SQUARE color: BLACK posn: upper left").pprint() prints:: [['shape', 'SQUARE'], ['color', 'BLACK'], ['posn', 'upper left']] cstt|j|d|_dS)NT)rrrr[)rr.)rHrwrxrszFollowedBy.__init__TcCs|jj|||gfS)N)r.r)rr-rrorwrwrxrszFollowedBy.parseImpl)T)rrrrrrrrwrw)rHrxrs cs2eZdZdZfddZd ddZddZZS) ra Lookahead to disallow matching with the given parse expression. C{NotAny} does I{not} advance the parsing position within the input string, it only verifies that the specified parse expression does I{not} match at the current position. Also, C{NotAny} does I{not} skip over leading whitespace. C{NotAny} always returns a null token list. May be constructed using the '~' operator. Example:: cs0tt|j|d|_d|_dt|j|_dS)NFTzFound unwanted token, )rrrrXr[rr.ra)rr.)rHrwrxrszNotAny.__init__TcCs&|jj||rt|||j||gfS)N)r.rrra)rr-rrorwrwrxrszNotAny.parseImplcCs4t|dr|jS|jdkr.dt|jd|_|jS)Nrz~{r<)rrrUrr.)rrwrwrxrs   zNotAny.__str__)T)rrrrrrrrrwrw)rHrxrs   cs(eZdZdfdd ZdddZZS) _MultipleMatchNcsFtt|j|d|_|}t|tr.tj|}|dk r<|nd|_dS)NT) rrIrrWrzrr$rQ not_ender)rr.stopOnZender)rHrwrxrs   z_MultipleMatch.__init__Tc Cs|jj}|j}|jdk }|r$|jj}|r2|||||||dd\}}yZ|j } xJ|rb|||| rr|||} n|} ||| |\}} | s| jrT|| 7}qTWWnttfk rYnX||fS)NF)rp) r.rtrrJrr]rrr) rr-rroZself_expr_parseZself_skip_ignorablesZ check_enderZ try_not_enderrZhasIgnoreExprsrZ tmptokensrwrwrxrs,      z_MultipleMatch.parseImpl)N)T)rrrrrrrwrw)rHrxrIsrIc@seZdZdZddZdS)ra Repetition of one or more of the given expression. Parameters: - expr - expression that must match one or more times - stopOn - (default=C{None}) - expression for a terminating sentinel (only required if the sentinel would ordinarily match the repetition expression) Example:: data_word = Word(alphas) label = data_word + FollowedBy(':') attr_expr = Group(label + Suppress(':') + OneOrMore(data_word).setParseAction(' '.join)) text = "shape: SQUARE posn: upper left color: BLACK" OneOrMore(attr_expr).parseString(text).pprint() # Fail! read 'color' as data instead of next label -> [['shape', 'SQUARE color']] # use stopOn attribute for OneOrMore to avoid reading label string as part of the data attr_expr = Group(label + Suppress(':') + OneOrMore(data_word, stopOn=label).setParseAction(' '.join)) OneOrMore(attr_expr).parseString(text).pprint() # Better -> [['shape', 'SQUARE'], ['posn', 'upper left'], ['color', 'BLACK']] # could also be written as (attr_expr * (1,)).parseString(text).pprint() cCs4t|dr|jS|jdkr.dt|jd|_|jS)Nrr;z}...)rrrUrr.)rrwrwrxr!s   zOneOrMore.__str__N)rrrrrrwrwrwrxrscs8eZdZdZd fdd Zd fdd Zdd ZZS) r2aw Optional repetition of zero or more of the given expression. Parameters: - expr - expression that must match zero or more times - stopOn - (default=C{None}) - expression for a terminating sentinel (only required if the sentinel would ordinarily match the repetition expression) Example: similar to L{OneOrMore} Ncstt|j||dd|_dS)N)rKT)rr2rr[)rr.rK)rHrwrxr6szZeroOrMore.__init__Tc s6ytt|j|||Sttfk r0|gfSXdS)N)rr2rrr)rr-rro)rHrwrxr:szZeroOrMore.parseImplcCs4t|dr|jS|jdkr.dt|jd|_|jS)Nrrz]...)rrrUrr.)rrwrwrxr@s   zZeroOrMore.__str__)N)T)rrrrrrrrrwrw)rHrxr2*s c@s eZdZddZeZddZdS) _NullTokencCsdS)NFrw)rrwrwrxrJsz_NullToken.__bool__cCsdS)Nrrw)rrwrwrxrMsz_NullToken.__str__N)rrrrr'rrwrwrwrxrLIsrLcs6eZdZdZeffdd Zd ddZddZZS) raa Optional matching of the given expression. Parameters: - expr - expression that must match zero or more times - default (optional) - value to be returned if the optional expression is not found. Example:: # US postal code can be a 5-digit zip, plus optional 4-digit qualifier zip = Combine(Word(nums, exact=5) + Optional('-' + Word(nums, exact=4))) zip.runTests(''' # traditional ZIP code 12345 # ZIP+4 form 12101-0001 # invalid ZIP 98765- ''') prints:: # traditional ZIP code 12345 ['12345'] # ZIP+4 form 12101-0001 ['12101-0001'] # invalid ZIP 98765- ^ FAIL: Expected end of text (at char 5), (line:1, col:6) cs.tt|j|dd|jj|_||_d|_dS)NF)rgT)rrrr.rWrr[)rr.r)rHrwrxrts zOptional.__init__Tc Cszy|jj|||dd\}}WnTttfk rp|jtk rh|jjr^t|jg}|j||jj<ql|jg}ng}YnX||fS)NF)rp)r.rtrrr_optionalNotMatchedrVr")rr-rrorrwrwrxrzs    zOptional.parseImplcCs4t|dr|jS|jdkr.dt|jd|_|jS)Nrrr )rrrUrr.)rrwrwrxrs   zOptional.__str__)T) rrrrrMrrrrrwrw)rHrxrQs" cs,eZdZdZd fdd Zd ddZZS) r(a Token for skipping over all undefined text until the matched expression is found. Parameters: - expr - target expression marking the end of the data to be skipped - include - (default=C{False}) if True, the target expression is also parsed (the skipped text and target expression are returned as a 2-element list). - ignore - (default=C{None}) used to define grammars (typically quoted strings and comments) that might contain false matches to the target expression - failOn - (default=C{None}) define expressions that are not allowed to be included in the skipped test; if found before the target expression is found, the SkipTo is not a match Example:: report = ''' Outstanding Issues Report - 1 Jan 2000 # | Severity | Description | Days Open -----+----------+-------------------------------------------+----------- 101 | Critical | Intermittent system crash | 6 94 | Cosmetic | Spelling error on Login ('log|n') | 14 79 | Minor | System slow when running too many reports | 47 ''' integer = Word(nums) SEP = Suppress('|') # use SkipTo to simply match everything up until the next SEP # - ignore quoted strings, so that a '|' character inside a quoted string does not match # - parse action will call token.strip() for each matched token, i.e., the description body string_data = SkipTo(SEP, ignore=quotedString) string_data.setParseAction(tokenMap(str.strip)) ticket_expr = (integer("issue_num") + SEP + string_data("sev") + SEP + string_data("desc") + SEP + integer("days_open")) for tkt in ticket_expr.searchString(report): print tkt.dump() prints:: ['101', 'Critical', 'Intermittent system crash', '6'] - days_open: 6 - desc: Intermittent system crash - issue_num: 101 - sev: Critical ['94', 'Cosmetic', "Spelling error on Login ('log|n')", '14'] - days_open: 14 - desc: Spelling error on Login ('log|n') - issue_num: 94 - sev: Cosmetic ['79', 'Minor', 'System slow when running too many reports', '47'] - days_open: 47 - desc: System slow when running too many reports - issue_num: 79 - sev: Minor FNcs`tt|j|||_d|_d|_||_d|_t|t rFt j ||_ n||_ dt |j|_dS)NTFzNo match found for )rr(r ignoreExprr[r` includeMatchrrzrr$rQfailOnrr.ra)rrincluderrP)rHrwrxrs zSkipTo.__init__Tc Cs,|}t|}|j}|jj}|jdk r,|jjnd}|jdk rB|jjnd} |} x| |kr|dk rh||| rhP| dk rx*y| || } Wqrtk rPYqrXqrWy||| dddWn tt fk r| d7} YqLXPqLWt|||j || }|||} t | } |j r$||||dd\}} | | 7} || fS)NF)rorprr)rp) rr.rtrPrrNrrrrrar"rO)rr-rror0rr.Z expr_parseZself_failOn_canParseNextZself_ignoreExpr_tryParseZtmplocZskiptextZ skipresultrrwrwrxrs<    zSkipTo.parseImpl)FNN)T)rrrrrrrrwrw)rHrxr(s6 csbeZdZdZdfdd ZddZddZd d Zd d Zgfd dZ ddZ fddZ Z S)raK Forward declaration of an expression to be defined later - used for recursive grammars, such as algebraic infix notation. When the expression is known, it is assigned to the C{Forward} variable using the '<<' operator. Note: take care when assigning to C{Forward} not to overlook precedence of operators. Specifically, '|' has a lower precedence than '<<', so that:: fwdExpr << a | b | c will actually be evaluated as:: (fwdExpr << a) | b | c thereby leaving b and c out as parseable alternatives. It is recommended that you explicitly group the values inserted into the C{Forward}:: fwdExpr << (a | b | c) Converting to use the '<<=' operator instead will avoid this problem. See L{ParseResults.pprint} for an example of a recursive parser created using C{Forward}. Ncstt|j|dddS)NF)rg)rrr)rr)rHrwrxrszForward.__init__cCsjt|trtj|}||_d|_|jj|_|jj|_|j|jj |jj |_ |jj |_ |j j |jj |S)N)rzrr$rQr.rUr`r[rrYrXrWr]r)rrrwrwrx __lshift__s      zForward.__lshift__cCs||>S)Nrw)rrrwrwrx __ilshift__'szForward.__ilshift__cCs d|_|S)NF)rX)rrwrwrxr*szForward.leaveWhitespacecCs$|js d|_|jdk r |jj|S)NT)r_r.r)rrwrwrxr.s   zForward.streamlinecCs>||kr0|dd|g}|jdk r0|jj||jgdS)N)r.rr)rrr6rwrwrxr5s   zForward.validatec Cs>t|dr|jS|jjdSd}Wd|j|_X|jjd|S)Nrz: ...Nonez: )rrrHrZ _revertClass_ForwardNoRecurser.r)rZ retStringrwrwrxr<s   zForward.__str__cs.|jdk rtt|jSt}||K}|SdS)N)r.rrr)rr)rHrwrxrMs  z Forward.copy)N) rrrrrrRrSrrrrrrrwrw)rHrxrs  c@seZdZddZdS)rUcCsdS)Nz...rw)rrwrwrxrVsz_ForwardNoRecurse.__str__N)rrrrrwrwrwrxrUUsrUcs"eZdZdZdfdd ZZS)r-zQ Abstract subclass of C{ParseExpression}, for converting parsed results. Fcstt|j|d|_dS)NF)rr-rrW)rr.rg)rHrwrxr]szTokenConverter.__init__)F)rrrrrrrwrw)rHrxr-Yscs6eZdZdZd fdd ZfddZdd ZZS) r a Converter to concatenate all matching tokens to a single string. By default, the matching patterns must also be contiguous in the input string; this can be disabled by specifying C{'adjacent=False'} in the constructor. Example:: real = Word(nums) + '.' + Word(nums) print(real.parseString('3.1416')) # -> ['3', '.', '1416'] # will also erroneously match the following print(real.parseString('3. 1416')) # -> ['3', '.', '1416'] real = Combine(Word(nums) + '.' + Word(nums)) print(real.parseString('3.1416')) # -> ['3.1416'] # no match when there are internal spaces print(real.parseString('3. 1416')) # -> Exception: Expected W:(0123...) rTcs8tt|j||r|j||_d|_||_d|_dS)NT)rr rradjacentrX joinStringre)rr.rWrV)rHrwrxrrszCombine.__init__cs(|jrtj||ntt|j||S)N)rVr$rrr )rr)rHrwrxr|szCombine.ignorecCsP|j}|dd=|tdj|j|jg|jd7}|jrH|jrH|gS|SdS)Nr)r)rr"rr rWrbrVr)rr-rrZretToksrwrwrxrs  "zCombine.postParse)rT)rrrrrrrrrwrw)rHrxr as cs(eZdZdZfddZddZZS)ra Converter to return the matched tokens as a list - useful for returning tokens of C{L{ZeroOrMore}} and C{L{OneOrMore}} expressions. Example:: ident = Word(alphas) num = Word(nums) term = ident | num func = ident + Optional(delimitedList(term)) print(func.parseString("fn a,b,100")) # -> ['fn', 'a', 'b', '100'] func = ident + Group(Optional(delimitedList(term))) print(func.parseString("fn a,b,100")) # -> ['fn', ['a', 'b', '100']] cstt|j|d|_dS)NT)rrrrW)rr.)rHrwrxrszGroup.__init__cCs|gS)Nrw)rr-rrrwrwrxrszGroup.postParse)rrrrrrrrwrw)rHrxrs  cs(eZdZdZfddZddZZS)r aW Converter to return a repetitive expression as a list, but also as a dictionary. Each element can also be referenced using the first token in the expression as its key. Useful for tabular report scraping when the first column can be used as a item key. Example:: data_word = Word(alphas) label = data_word + FollowedBy(':') attr_expr = Group(label + Suppress(':') + OneOrMore(data_word).setParseAction(' '.join)) text = "shape: SQUARE posn: upper left color: light blue texture: burlap" attr_expr = (label + Suppress(':') + OneOrMore(data_word, stopOn=label).setParseAction(' '.join)) # print attributes as plain groups print(OneOrMore(attr_expr).parseString(text).dump()) # instead of OneOrMore(expr), parse using Dict(OneOrMore(Group(expr))) - Dict will auto-assign names result = Dict(OneOrMore(Group(attr_expr))).parseString(text) print(result.dump()) # access named fields as dict entries, or output as dict print(result['shape']) print(result.asDict()) prints:: ['shape', 'SQUARE', 'posn', 'upper left', 'color', 'light blue', 'texture', 'burlap'] [['shape', 'SQUARE'], ['posn', 'upper left'], ['color', 'light blue'], ['texture', 'burlap']] - color: light blue - posn: upper left - shape: SQUARE - texture: burlap SQUARE {'color': 'light blue', 'posn': 'upper left', 'texture': 'burlap', 'shape': 'SQUARE'} See more examples at L{ParseResults} of accessing fields by results name. cstt|j|d|_dS)NT)rr rrW)rr.)rHrwrxrsz Dict.__init__cCsxt|D]\}}t|dkr q |d}t|trBt|dj}t|dkr^td|||<q t|dkrt|dt rt|d|||<q |j}|d=t|dkst|tr|j rt||||<q t|d|||<q W|j r|gS|SdS)Nrrrrrq) rrrzrurrrr"rrrV)rr-rrrtokZikeyZ dictvaluerwrwrxrs$   zDict.postParse)rrrrrrrrwrw)rHrxr s# c@s eZdZdZddZddZdS)r+aV Converter for ignoring the results of a parsed expression. Example:: source = "a, b, c,d" wd = Word(alphas) wd_list1 = wd + ZeroOrMore(',' + wd) print(wd_list1.parseString(source)) # often, delimiters that are useful during parsing are just in the # way afterward - use Suppress to keep them out of the parsed output wd_list2 = wd + ZeroOrMore(Suppress(',') + wd) print(wd_list2.parseString(source)) prints:: ['a', ',', 'b', ',', 'c', ',', 'd'] ['a', 'b', 'c', 'd'] (See also L{delimitedList}.) cCsgS)Nrw)rr-rrrwrwrxrszSuppress.postParsecCs|S)Nrw)rrwrwrxrszSuppress.suppressN)rrrrrrrwrwrwrxr+sc@s(eZdZdZddZddZddZdS) rzI Wrapper for parse actions, to ensure they are only called once. cCst||_d|_dS)NF)rMcallablecalled)rZ methodCallrwrwrxrs zOnlyOnce.__init__cCs.|js|j|||}d|_|St||ddS)NTr)rZrYr)rrr5rvrrwrwrxrs zOnlyOnce.__call__cCs d|_dS)NF)rZ)rrwrwrxreset szOnlyOnce.resetN)rrrrrrr[rwrwrwrxrsc s:tfdd}y j|_Wntk r4YnX|S)as Decorator for debugging parse actions. When the parse action is called, this decorator will print C{">> entering I{method-name}(line:I{current_source_line}, I{parse_location}, I{matched_tokens})".} When the parse action completes, the decorator will print C{"<<"} followed by the returned value, or any exception that the parse action raised. Example:: wd = Word(alphas) @traceParseAction def remove_duplicate_chars(tokens): return ''.join(sorted(set(''.join(tokens))) wds = OneOrMore(wd).setParseAction(remove_duplicate_chars) print(wds.parseString("slkdjs sld sldd sdlf sdljf")) prints:: >>entering remove_duplicate_chars(line: 'slkdjs sld sldd sdlf sdljf', 0, (['slkdjs', 'sld', 'sldd', 'sdlf', 'sdljf'], {})) <>entering %s(line: '%s', %d, %r) z<.z)rMrr)rr_rw)rrxrb s  ,FcCs`t|dt|dt|d}|rBt|t||j|S|tt||j|SdS)a Helper to define a delimited list of expressions - the delimiter defaults to ','. By default, the list elements and delimiters can have intervening whitespace, and comments, but this can be overridden by passing C{combine=True} in the constructor. If C{combine} is set to C{True}, the matching tokens are returned as a single token string, with the delimiters included; otherwise, the matching tokens are returned as a list of tokens, with the delimiters suppressed. Example:: delimitedList(Word(alphas)).parseString("aa,bb,cc") # -> ['aa', 'bb', 'cc'] delimitedList(Word(hexnums), delim=':', combine=True).parseString("AA:BB:CC:DD:EE") # -> ['AA:BB:CC:DD:EE'] z [rz]...N)rr r2rir+)r.ZdelimcombineZdlNamerwrwrxr@9s $csjtfdd}|dkr0ttjdd}n|j}|jd|j|dd|jd td S) a: Helper to define a counted list of expressions. This helper defines a pattern of the form:: integer expr expr expr... where the leading integer tells how many expr expressions follow. The matched tokens returns the array of expr tokens as a list - the leading count token is suppressed. If C{intExpr} is specified, it should be a pyparsing expression that produces an integer value. Example:: countedArray(Word(alphas)).parseString('2 ab cd ef') # -> ['ab', 'cd'] # in this parser, the leading integer value is given in binary, # '10' indicating that 2 values are in the array binaryConstant = Word('01').setParseAction(lambda t: int(t[0], 2)) countedArray(Word(alphas), intExpr=binaryConstant).parseString('10 ab cd ef') # -> ['ab', 'cd'] cs.|d}|r ttg|p&tt>gS)Nr)rrrC)rr5rvr) arrayExprr.rwrxcountFieldParseAction_s"z+countedArray..countFieldParseActionNcSs t|dS)Nr)ru)rvrwrwrxrydszcountedArray..ZarrayLenT)rfz(len) z...)rr/rRrrrirxr)r.ZintExprrcrw)rbr.rxr<Ls cCs:g}x0|D](}t|tr(|jt|q |j|q W|S)N)rzrrrr)Lrrrwrwrxrks   rcs6tfdd}|j|ddjdt|S)a* Helper to define an expression that is indirectly defined from the tokens matched in a previous expression, that is, it looks for a 'repeat' of a previous expression. For example:: first = Word(nums) second = matchPreviousLiteral(first) matchExpr = first + ":" + second will match C{"1:1"}, but not C{"1:2"}. Because this matches a previous literal, will also match the leading C{"1:1"} in C{"1:10"}. If this is not desired, use C{matchPreviousExpr}. Do I{not} use with packrat parsing enabled. csP|rBt|dkr|d>qLt|j}tdd|D>n t>dS)Nrrrcss|]}t|VqdS)N)r)rttrwrwrxrszDmatchPreviousLiteral..copyTokenToRepeater..)rrrrr )rr5rvZtflat)reprwrxcopyTokenToRepeaters   z1matchPreviousLiteral..copyTokenToRepeaterT)rfz(prev) )rrxrir)r.rgrw)rfrxrOts  csFt|j}|Kfdd}|j|ddjdt|S)aS Helper to define an expression that is indirectly defined from the tokens matched in a previous expression, that is, it looks for a 'repeat' of a previous expression. For example:: first = Word(nums) second = matchPreviousExpr(first) matchExpr = first + ":" + second will match C{"1:1"}, but not C{"1:2"}. Because this matches by expressions, will I{not} match the leading C{"1:1"} in C{"1:10"}; the expressions are evaluated first, and then compared, so C{"1"} is compared with C{"10"}. Do I{not} use with packrat parsing enabled. cs*t|jfdd}j|dddS)Ncs$t|j}|kr tddddS)Nrr)rrr)rr5rvZ theseTokens) matchTokensrwrxmustMatchTheseTokenss zLmatchPreviousExpr..copyTokenToRepeater..mustMatchTheseTokensT)rf)rrr)rr5rvri)rf)rhrxrgs  z.matchPreviousExpr..copyTokenToRepeaterT)rfz(prev) )rrrxrir)r.Ze2rgrw)rfrxrNs cCs>xdD]}|j|t|}qW|jdd}|jdd}t|S)Nz\^-]rz\nr'z\t)r_bslashr)rrrwrwrxrs    rTc s|rdd}dd}tndd}dd}tg}t|trF|j}n&t|tjr\t|}ntj dt dd|svt Sd }x|t |d kr||}xnt ||d d D]N\}} || |r|||d =Pq||| r|||d =|j|| | }PqW|d 7}q|W| r|ryht |t d j|krZtd d jdd|Djdj|Stdjdd|Djdj|SWn&tk rtj dt ddYnXtfdd|Djdj|S)a Helper to quickly define a set of alternative Literals, and makes sure to do longest-first testing when there is a conflict, regardless of the input order, but returns a C{L{MatchFirst}} for best performance. Parameters: - strs - a string of space-delimited literals, or a collection of string literals - caseless - (default=C{False}) - treat all literals as caseless - useRegex - (default=C{True}) - as an optimization, will generate a Regex object; otherwise, will generate a C{MatchFirst} object (if C{caseless=True}, or if creating a C{Regex} raises an exception) Example:: comp_oper = oneOf("< = > <= >= !=") var = Word(alphas) number = Word(nums) term = var | number comparison_expr = term + comp_oper + term print(comparison_expr.searchString("B = 12 AA=23 B<=AA AA>12")) prints:: [['B', '=', '12'], ['AA', '=', '23'], ['B', '<=', 'AA'], ['AA', '>', '12']] cSs|j|jkS)N)r)rbrwrwrxryszoneOf..cSs|jj|jS)N)rr)rrkrwrwrxryscSs||kS)Nrw)rrkrwrwrxryscSs |j|S)N)r)rrkrwrwrxrysz6Invalid argument to oneOf, expected string or iterablerq)rrrrNrz[%s]css|]}t|VqdS)N)r)rsymrwrwrxrszoneOf..z | |css|]}tj|VqdS)N)rdr)rrlrwrwrxrsz7Exception creating Regex for oneOf, building MatchFirstc3s|]}|VqdS)Nrw)rrl)parseElementClassrwrxrs)rrrzrrrr4rrrrrrrrrr'rirKr) ZstrsrZuseRegexZisequalZmasksZsymbolsrZcurrrrw)rnrxrSsL         ((cCsttt||S)a Helper to easily and clearly define a dictionary by specifying the respective patterns for the key and value. Takes care of defining the C{L{Dict}}, C{L{ZeroOrMore}}, and C{L{Group}} tokens in the proper order. The key pattern can include delimiting markers or punctuation, as long as they are suppressed, thereby leaving the significant key text. The value pattern can include named results, so that the C{Dict} results can include named token fields. Example:: text = "shape: SQUARE posn: upper left color: light blue texture: burlap" attr_expr = (label + Suppress(':') + OneOrMore(data_word, stopOn=label).setParseAction(' '.join)) print(OneOrMore(attr_expr).parseString(text).dump()) attr_label = label attr_value = Suppress(':') + OneOrMore(data_word, stopOn=label).setParseAction(' '.join) # similar to Dict, but simpler call format result = dictOf(attr_label, attr_value).parseString(text) print(result.dump()) print(result['shape']) print(result.shape) # object attribute access works too print(result.asDict()) prints:: [['shape', 'SQUARE'], ['posn', 'upper left'], ['color', 'light blue'], ['texture', 'burlap']] - color: light blue - posn: upper left - shape: SQUARE - texture: burlap SQUARE SQUARE {'color': 'light blue', 'shape': 'SQUARE', 'posn': 'upper left', 'texture': 'burlap'} )r r2r)rrrwrwrxrAs!cCs^tjdd}|j}d|_|d||d}|r@dd}ndd}|j||j|_|S) a Helper to return the original, untokenized text for a given expression. Useful to restore the parsed fields of an HTML start tag into the raw tag text itself, or to revert separate tokens with intervening whitespace back to the original matching input text. By default, returns astring containing the original parsed text. If the optional C{asString} argument is passed as C{False}, then the return value is a C{L{ParseResults}} containing any results names that were originally matched, and a single token containing the original matched text from the input string. So if the expression passed to C{L{originalTextFor}} contains expressions with defined results names, you must set C{asString} to C{False} if you want to preserve those results name values. Example:: src = "this is test bold text normal text " for tag in ("b","i"): opener,closer = makeHTMLTags(tag) patt = originalTextFor(opener + SkipTo(closer) + closer) print(patt.searchString(src)[0]) prints:: [' bold text '] ['text'] cSs|S)Nrw)rrrvrwrwrxry8sz!originalTextFor..F_original_start _original_endcSs||j|jS)N)rorp)rr5rvrwrwrxry=scSs&||jd|jdg|dd<dS)Nrorp)r)rr5rvrwrwrx extractText?sz$originalTextFor..extractText)r rrrer])r.ZasStringZ locMarkerZ endlocMarker matchExprrqrwrwrxrg s  cCst|jddS)zp Helper to undo pyparsing's default grouping of And expressions, even if all but one are non-empty. cSs|dS)Nrrw)rvrwrwrxryJszungroup..)r-r)r.rwrwrxrhEscCs4tjdd}t|d|d|jjdS)a Helper to decorate a returned token with its starting and ending locations in the input string. This helper adds the following results names: - locn_start = location where matched expression begins - locn_end = location where matched expression ends - value = the actual parsed results Be careful if the input text contains C{} characters, you may want to call C{L{ParserElement.parseWithTabs}} Example:: wd = Word(alphas) for match in locatedExpr(wd).searchString("ljsdf123lksdjjf123lkkjj1222"): print(match) prints:: [[0, 'ljsdf', 5]] [[8, 'lksdjjf', 15]] [[18, 'lkkjj', 23]] cSs|S)Nrw)rr5rvrwrwrxry`szlocatedExpr..Z locn_startrZlocn_end)r rrrr)r.ZlocatorrwrwrxrjLsz\[]-*.$+^?()~ )r cCs |ddS)Nrrrrw)rr5rvrwrwrxryksryz\\0?[xX][0-9a-fA-F]+cCstt|djddS)Nrz\0x)unichrrulstrip)rr5rvrwrwrxrylsz \\0[0-7]+cCstt|ddddS)Nrrr)rtru)rr5rvrwrwrxrymsz\])rr z\wr7rrZnegatebodyr c sBddy djfddtj|jDStk r<dSXdS)a Helper to easily define string ranges for use in Word construction. Borrows syntax from regexp '[]' string range definitions:: srange("[0-9]") -> "0123456789" srange("[a-z]") -> "abcdefghijklmnopqrstuvwxyz" srange("[a-z$_]") -> "abcdefghijklmnopqrstuvwxyz$_" The input string must be enclosed in []'s, and the returned string is the expanded character set joined into a single string. The values enclosed in the []'s may be: - a single character - an escaped character with a leading backslash (such as C{\-} or C{\]}) - an escaped hex character with a leading C{'\x'} (C{\x21}, which is a C{'!'} character) (C{\0x##} is also supported for backwards compatibility) - an escaped octal character with a leading C{'\0'} (C{\041}, which is a C{'!'} character) - a range of any of the above, separated by a dash (C{'a-z'}, etc.) - any combination of the above (C{'aeiouy'}, C{'a-zA-Z0-9_$'}, etc.) cSs<t|ts|Sdjddtt|dt|ddDS)Nrcss|]}t|VqdS)N)rt)rrrwrwrxrsz+srange....rrr)rzr"rrord)prwrwrxryszsrange..rc3s|]}|VqdS)Nrw)rpart) _expandedrwrxrszsrange..N)r_reBracketExprrrwrK)rrw)r{rxr_rs  csfdd}|S)zt Helper method for defining parse actions that require matching at a specific column in the input text. cs"t||krt||ddS)Nzmatched token not at column %d)r9r)r)Zlocnr1)rrwrx verifyColsz!matchOnlyAtCol..verifyColrw)rr}rw)rrxrMs cs fddS)a Helper method for common parse actions that simply return a literal value. Especially useful when used with C{L{transformString}()}. Example:: num = Word(nums).setParseAction(lambda toks: int(toks[0])) na = oneOf("N/A NA").setParseAction(replaceWith(math.nan)) term = na | num OneOrMore(term).parseString("324 234 N/A 234") # -> [324, 234, nan, 234] csgS)Nrw)rr5rv)replStrrwrxryszreplaceWith..rw)r~rw)r~rxr\s cCs|dddS)a Helper parse action for removing quotation marks from parsed quoted strings. Example:: # by default, quotation marks are included in parsed results quotedString.parseString("'Now is the Winter of our Discontent'") # -> ["'Now is the Winter of our Discontent'"] # use removeQuotes to strip quotation marks from parsed results quotedString.setParseAction(removeQuotes) quotedString.parseString("'Now is the Winter of our Discontent'") # -> ["Now is the Winter of our Discontent"] rrrrsrw)rr5rvrwrwrxrZs c sNfdd}ytdtdj}Wntk rBt}YnX||_|S)aG Helper to define a parse action by mapping a function to all elements of a ParseResults list.If any additional args are passed, they are forwarded to the given function as additional arguments after the token, as in C{hex_integer = Word(hexnums).setParseAction(tokenMap(int, 16))}, which will convert the parsed data to an integer using base 16. Example (compare the last to example in L{ParserElement.transformString}:: hex_ints = OneOrMore(Word(hexnums)).setParseAction(tokenMap(int, 16)) hex_ints.runTests(''' 00 11 22 aa FF 0a 0d 1a ''') upperword = Word(alphas).setParseAction(tokenMap(str.upper)) OneOrMore(upperword).runTests(''' my kingdom for a horse ''') wd = Word(alphas).setParseAction(tokenMap(str.title)) OneOrMore(wd).setParseAction(' '.join).runTests(''' now is the winter of our discontent made glorious summer by this sun of york ''') prints:: 00 11 22 aa FF 0a 0d 1a [0, 17, 34, 170, 255, 10, 13, 26] my kingdom for a horse ['MY', 'KINGDOM', 'FOR', 'A', 'HORSE'] now is the winter of our discontent made glorious summer by this sun of york ['Now Is The Winter Of Our Discontent Made Glorious Summer By This Sun Of York'] csfdd|DS)Ncsg|]}|fqSrwrw)rZtokn)rr6rwrxrsz(tokenMap..pa..rw)rr5rv)rr6rwrxr}sztokenMap..parrH)rJrrKr{)r6rr}rLrw)rr6rxrms cCs t|jS)N)rr)rvrwrwrxryscCs t|jS)N)rlower)rvrwrwrxryscCst|tr|}t|| d}n|j}tttd}|rtjj t }t d|dt t t|t d|tddgdjd j d d t d }nd jddtD}tjj t t|B}t d|dt t t|j ttt d|tddgdjd j dd t d }ttd|d }|jdd j|jddjjjd|}|jdd j|jddjjjd|}||_||_||fS)zRInternal helper to construct opening and closing tag expressions, given a tag name)rz_-:rtag=/F)rrCcSs |ddkS)Nrrrw)rr5rvrwrwrxrysz_makeTags..rrcss|]}|dkr|VqdS)rNrw)rrrwrwrxrsz_makeTags..cSs |ddkS)Nrrrw)rr5rvrwrwrxryszr z)rzrrrr/r4r3r>rrrZr+r r2rrrmrrVrYrBr _Lrtitlerrir)tagStrZxmlZresnameZ tagAttrNameZ tagAttrValueZopenTagZprintablesLessRAbrackZcloseTagrwrwrx _makeTagss" T\..rcCs t|dS)a  Helper to construct opening and closing tag expressions for HTML, given a tag name. Matches tags in either upper or lower case, attributes with namespaces and with quoted or unquoted values. Example:: text = 'More info at the pyparsing wiki page' # makeHTMLTags returns pyparsing expressions for the opening and closing tags as a 2-tuple a,a_end = makeHTMLTags("A") link_expr = a + SkipTo(a_end)("link_text") + a_end for link in link_expr.searchString(text): # attributes in the tag (like "href" shown here) are also accessible as named results print(link.link_text, '->', link.href) prints:: pyparsing -> http://pyparsing.wikispaces.com F)r)rrwrwrxrKscCs t|dS)z Helper to construct opening and closing tag expressions for XML, given a tag name. Matches tags only in the given upper/lower case. Example: similar to L{makeHTMLTags} T)r)rrwrwrxrLscs8|r|ddn|jddDfdd}|S)a< Helper to create a validating parse action to be used with start tags created with C{L{makeXMLTags}} or C{L{makeHTMLTags}}. Use C{withAttribute} to qualify a starting tag with a required attribute value, to avoid false matches on common tags such as C{} or C{
}. Call C{withAttribute} with a series of attribute names and values. Specify the list of filter attributes names and values as: - keyword arguments, as in C{(align="right")}, or - as an explicit dict with C{**} operator, when an attribute name is also a Python reserved word, as in C{**{"class":"Customer", "align":"right"}} - a list of name-value tuples, as in ( ("ns1:class", "Customer"), ("ns2:align","right") ) For attribute names with a namespace prefix, you must use the second form. Attribute names are matched insensitive to upper/lower case. If just testing for C{class} (with or without a namespace), use C{L{withClass}}. To verify that the attribute exists, but without specifying a value, pass C{withAttribute.ANY_VALUE} as the value. Example:: html = '''
Some text
1 4 0 1 0
1,3 2,3 1,1
this has no type
''' div,div_end = makeHTMLTags("div") # only match div tag having a type attribute with value "grid" div_grid = div().setParseAction(withAttribute(type="grid")) grid_expr = div_grid + SkipTo(div | div_end)("body") for grid_header in grid_expr.searchString(html): print(grid_header.body) # construct a match with any div tag having a type attribute, regardless of the value div_any_type = div().setParseAction(withAttribute(type=withAttribute.ANY_VALUE)) div_expr = div_any_type + SkipTo(div | div_end)("body") for div_header in div_expr.searchString(html): print(div_header.body) prints:: 1 4 0 1 0 1 4 0 1 0 1,3 2,3 1,1 NcSsg|]\}}||fqSrwrw)rrrrwrwrxrQsz!withAttribute..cs^xXD]P\}}||kr&t||d||tjkr|||krt||d||||fqWdS)Nzno matching attribute z+attribute '%s' has value '%s', must be '%s')rre ANY_VALUE)rr5rZattrNameZ attrValue)attrsrwrxr}Rs zwithAttribute..pa)r)rZattrDictr}rw)rrxres 2 cCs|r d|nd}tf||iS)a Simplified version of C{L{withAttribute}} when matching on a div class - made difficult because C{class} is a reserved word in Python. Example:: html = '''
Some text
1 4 0 1 0
1,3 2,3 1,1
this <div> has no class
''' div,div_end = makeHTMLTags("div") div_grid = div().setParseAction(withClass("grid")) grid_expr = div_grid + SkipTo(div | div_end)("body") for grid_header in grid_expr.searchString(html): print(grid_header.body) div_any_type = div().setParseAction(withClass(withAttribute.ANY_VALUE)) div_expr = div_any_type + SkipTo(div | div_end)("body") for div_header in div_expr.searchString(html): print(div_header.body) prints:: 1 4 0 1 0 1 4 0 1 0 1,3 2,3 1,1 z%s:classclass)re)Z classname namespaceZ classattrrwrwrxrk\s (rcCst}||||B}x`t|D]R\}}|d dd\}} } } | dkrTd|nd|} | dkr|dksxt|dkrtd|\} }tj| }| tjkrd| dkrt||t|t |}n| dkr|dk rt|||t|t ||}nt||t|t |}nD| dkrZt|| |||t|| |||}ntd n| tj krH| dkrt |t st |}t|j |t||}n| dkr|dk rt|||t|t ||}nt||t|t |}nD| dkr>t|| |||t|| |||}ntd ntd | r`|j| ||j| |BK}|}q"W||K}|S) a Helper method for constructing grammars of expressions made up of operators working in a precedence hierarchy. Operators may be unary or binary, left- or right-associative. Parse actions can also be attached to operator expressions. The generated parser will also recognize the use of parentheses to override operator precedences (see example below). Note: if you define a deep operator list, you may see performance issues when using infixNotation. See L{ParserElement.enablePackrat} for a mechanism to potentially improve your parser performance. Parameters: - baseExpr - expression representing the most basic element for the nested - opList - list of tuples, one for each operator precedence level in the expression grammar; each tuple is of the form (opExpr, numTerms, rightLeftAssoc, parseAction), where: - opExpr is the pyparsing expression for the operator; may also be a string, which will be converted to a Literal; if numTerms is 3, opExpr is a tuple of two expressions, for the two operators separating the 3 terms - numTerms is the number of terms for this operator (must be 1, 2, or 3) - rightLeftAssoc is the indicator whether the operator is right or left associative, using the pyparsing-defined constants C{opAssoc.RIGHT} and C{opAssoc.LEFT}. - parseAction is the parse action to be associated with expressions matching this operator expression (the parse action tuple member may be omitted) - lpar - expression for matching left-parentheses (default=C{Suppress('(')}) - rpar - expression for matching right-parentheses (default=C{Suppress(')')}) Example:: # simple example of four-function arithmetic with ints and variable names integer = pyparsing_common.signed_integer varname = pyparsing_common.identifier arith_expr = infixNotation(integer | varname, [ ('-', 1, opAssoc.RIGHT), (oneOf('* /'), 2, opAssoc.LEFT), (oneOf('+ -'), 2, opAssoc.LEFT), ]) arith_expr.runTests(''' 5+3*6 (5+3)*6 -2--11 ''', fullDump=False) prints:: 5+3*6 [[5, '+', [3, '*', 6]]] (5+3)*6 [[[5, '+', 3], '*', 6]] -2--11 [[['-', 2], '-', ['-', 11]]] Nrroz%s termz %s%s termrqz@if numterms=3, opExpr must be a tuple or list of two expressionsrrz6operator must be unary (1), binary (2), or ternary (3)z2operator must indicate right or left associativity)N)rrrrrirTLEFTrrrRIGHTrzrr.r)ZbaseExprZopListZlparZrparrZlastExprrZoperDefZopExprZarityZrightLeftAssocr}ZtermNameZopExpr1ZopExpr2ZthisExprrrrwrwrxrisR;    &       &   z4"(?:[^"\n\r\\]|(?:"")|(?:\\(?:[^x]|x[0-9a-fA-F]+)))*"z string enclosed in double quotesz4'(?:[^'\n\r\\]|(?:'')|(?:\\(?:[^x]|x[0-9a-fA-F]+)))*'z string enclosed in single quotesz*quotedString using single or double quotesuzunicode string literalcCs||krtd|dkr(t|to,t|tr t|dkrt|dkr|dk rtt|t||tjddj dd}n$t j t||tjj dd}nx|dk rtt|t |t |ttjddj dd}n4ttt |t |ttjddj d d}ntd t }|dk rb|tt|t||B|Bt|K}n$|tt|t||Bt|K}|jd ||f|S) a~ Helper method for defining nested lists enclosed in opening and closing delimiters ("(" and ")" are the default). Parameters: - opener - opening character for a nested list (default=C{"("}); can also be a pyparsing expression - closer - closing character for a nested list (default=C{")"}); can also be a pyparsing expression - content - expression for items within the nested lists (default=C{None}) - ignoreExpr - expression for ignoring opening and closing delimiters (default=C{quotedString}) If an expression is not provided for the content argument, the nested expression will capture all whitespace-delimited content between delimiters as a list of separate values. Use the C{ignoreExpr} argument to define expressions that may contain opening or closing characters that should not be treated as opening or closing characters for nesting, such as quotedString or a comment expression. Specify multiple expressions using an C{L{Or}} or C{L{MatchFirst}}. The default is L{quotedString}, but if no expressions are to be ignored, then pass C{None} for this argument. Example:: data_type = oneOf("void int short long char float double") decl_data_type = Combine(data_type + Optional(Word('*'))) ident = Word(alphas+'_', alphanums+'_') number = pyparsing_common.number arg = Group(decl_data_type + ident) LPAR,RPAR = map(Suppress, "()") code_body = nestedExpr('{', '}', ignoreExpr=(quotedString | cStyleComment)) c_function = (decl_data_type("type") + ident("name") + LPAR + Optional(delimitedList(arg), [])("args") + RPAR + code_body("body")) c_function.ignore(cStyleComment) source_code = ''' int is_odd(int x) { return (x%2); } int dec_to_hex(char hchar) { if (hchar >= '0' && hchar <= '9') { return (ord(hchar)-ord('0')); } else { return (10+ord(hchar)-ord('A')); } } ''' for func in c_function.searchString(source_code): print("%(name)s (%(type)s) args: %(args)s" % func) prints:: is_odd (int) args: [['int', 'x']] dec_to_hex (int) args: [['char', 'hchar']] z.opening and closing strings cannot be the sameNrr)r cSs |djS)Nr)r)rvrwrwrxry9sznestedExpr..cSs |djS)Nr)r)rvrwrwrxry<scSs |djS)Nr)r)rvrwrwrxryBscSs |djS)Nr)r)rvrwrwrxryFszOopening and closing arguments must be strings if no content expression is givenznested %s%s expression)rrzrrr rr r$rNrrCrrrrr+r2ri)openerZcloserZcontentrNrrwrwrxrPs4:     *$c sfdd}fdd}fdd}ttjdj}ttj|jd}tj|jd }tj|jd } |rtt||t|t|t|| } n$tt|t|t|t|} |j t t| jd S) a Helper method for defining space-delimited indentation blocks, such as those used to define block statements in Python source code. Parameters: - blockStatementExpr - expression defining syntax of statement that is repeated within the indented block - indentStack - list created by caller to manage indentation stack (multiple statementWithIndentedBlock expressions within a single grammar should share a common indentStack) - indent - boolean indicating whether block must be indented beyond the the current level; set to False for block of left-most statements (default=C{True}) A valid block must contain at least one C{blockStatement}. Example:: data = ''' def A(z): A1 B = 100 G = A2 A2 A3 B def BB(a,b,c): BB1 def BBA(): bba1 bba2 bba3 C D def spam(x,y): def eggs(z): pass ''' indentStack = [1] stmt = Forward() identifier = Word(alphas, alphanums) funcDecl = ("def" + identifier + Group( "(" + Optional( delimitedList(identifier) ) + ")" ) + ":") func_body = indentedBlock(stmt, indentStack) funcDef = Group( funcDecl + func_body ) rvalue = Forward() funcCall = Group(identifier + "(" + Optional(delimitedList(rvalue)) + ")") rvalue << (funcCall | identifier | Word(nums)) assignment = Group(identifier + "=" + rvalue) stmt << ( funcDef | assignment | identifier ) module_body = OneOrMore(stmt) parseTree = module_body.parseString(data) parseTree.pprint() prints:: [['def', 'A', ['(', 'z', ')'], ':', [['A1'], [['B', '=', '100']], [['G', '=', 'A2']], ['A2'], ['A3']]], 'B', ['def', 'BB', ['(', 'a', 'b', 'c', ')'], ':', [['BB1'], [['def', 'BBA', ['(', ')'], ':', [['bba1'], ['bba2'], ['bba3']]]]]], 'C', 'D', ['def', 'spam', ['(', 'x', 'y', ')'], ':', [[['def', 'eggs', ['(', 'z', ')'], ':', [['pass']]]]]]] csN|t|krdSt||}|dkrJ|dkr>t||dt||ddS)Nrrzillegal nestingznot a peer entryrsrs)rr9r!r)rr5rvcurCol) indentStackrwrxcheckPeerIndents     z&indentedBlock..checkPeerIndentcs2t||}|dkr"j|n t||ddS)Nrrznot a subentryrs)r9rr)rr5rvr)rrwrxcheckSubIndents   z%indentedBlock..checkSubIndentcsN|t|krdSt||}o4|dko4|dksBt||djdS)Nrrrqznot an unindentrsr:)rr9rr)rr5rvr)rrwrx checkUnindents    z$indentedBlock..checkUnindentz INDENTrZUNINDENTzindented block) rrrrr rrirrrrj) ZblockStatementExprrrrrrr!rZPEERZUNDENTZsmExprrw)rrxrfQsN   ,z#[\0xc0-\0xd6\0xd8-\0xf6\0xf8-\0xff]z[\0xa1-\0xbf\0xd7\0xf7]z_:zany tagzgt lt amp nbsp quot aposz><& "'z &(?Prmz);zcommon HTML entitycCs tj|jS)zRHelper parser action to replace common HTML entities with their special characters)_htmlEntityMaprZentity)rvrwrwrxr[sz/\*(?:[^*]|\*(?!/))*z*/zC style commentzz HTML commentz.*z rest of linez//(?:\\\n|[^\n])*z // commentzC++ style commentz#.*zPython style comment)rz commaItem)rc@seZdZdZeeZeeZe e j dj eZ e ej dj eedZedj dj eZej edej ej dZejd d eeeed jeBj d Zejeed j dj eZedj dj eZeeBeBjZedj dj eZe ededj dZedj dZ edj dZ!e!de!dj dZ"ee!de!d>dee!de!d?j dZ#e#j$d d d!e j d"Z%e&e"e%Be#Bj d#j d#Z'ed$j d%Z(e)d@d'd(Z*e)dAd*d+Z+ed,j d-Z,ed.j d/Z-ed0j d1Z.e/je0jBZ1e)d2d3Z2e&e3e4d4e5e e6d4d5ee7d6jj d7Z8e9ee:j;e8Bd8d9j d:Zd=S)Brna Here are some common low-level expressions that may be useful in jump-starting parser development: - numeric forms (L{integers}, L{reals}, L{scientific notation}) - common L{programming identifiers} - network addresses (L{MAC}, L{IPv4}, L{IPv6}) - ISO8601 L{dates} and L{datetime} - L{UUID} - L{comma-separated list} Parse actions: - C{L{convertToInteger}} - C{L{convertToFloat}} - C{L{convertToDate}} - C{L{convertToDatetime}} - C{L{stripHTMLTags}} - C{L{upcaseTokens}} - C{L{downcaseTokens}} Example:: pyparsing_common.number.runTests(''' # any int or real number, returned as the appropriate type 100 -100 +100 3.14159 6.02e23 1e-12 ''') pyparsing_common.fnumber.runTests(''' # any int or real number, returned as float 100 -100 +100 3.14159 6.02e23 1e-12 ''') pyparsing_common.hex_integer.runTests(''' # hex numbers 100 FF ''') pyparsing_common.fraction.runTests(''' # fractions 1/2 -3/4 ''') pyparsing_common.mixed_integer.runTests(''' # mixed fractions 1 1/2 -3/4 1-3/4 ''') import uuid pyparsing_common.uuid.setParseAction(tokenMap(uuid.UUID)) pyparsing_common.uuid.runTests(''' # uuid 12345678-1234-5678-1234-567812345678 ''') prints:: # any int or real number, returned as the appropriate type 100 [100] -100 [-100] +100 [100] 3.14159 [3.14159] 6.02e23 [6.02e+23] 1e-12 [1e-12] # any int or real number, returned as float 100 [100.0] -100 [-100.0] +100 [100.0] 3.14159 [3.14159] 6.02e23 [6.02e+23] 1e-12 [1e-12] # hex numbers 100 [256] FF [255] # fractions 1/2 [0.5] -3/4 [-0.75] # mixed fractions 1 [1] 1/2 [0.5] -3/4 [-0.75] 1-3/4 [1.75] # uuid 12345678-1234-5678-1234-567812345678 [UUID('12345678-1234-5678-1234-567812345678')] integerz hex integerrsz[+-]?\d+zsigned integerrfractioncCs|d|dS)Nrrrrsrw)rvrwrwrxryszpyparsing_common.r7z"fraction or mixed integer-fractionz [+-]?\d+\.\d*z real numberz+[+-]?\d+([eE][+-]?\d+|\.\d*([eE][+-]?\d+)?)z$real number with scientific notationz[+-]?\d+\.?\d*([eE][+-]?\d+)?fnumberrA identifierzK(25[0-5]|2[0-4][0-9]|1?[0-9]{1,2})(\.(25[0-5]|2[0-4][0-9]|1?[0-9]{1,2})){3}z IPv4 addressz[0-9a-fA-F]{1,4} hex_integerrzfull IPv6 addressrrBz::zshort IPv6 addresscCstdd|DdkS)Ncss|]}tjj|rdVqdS)rrN)rn _ipv6_partr)rrerwrwrxrsz,pyparsing_common...rv)rG)rvrwrwrxrysz::ffff:zmixed IPv6 addressz IPv6 addressz:[0-9a-fA-F]{2}([:.-])[0-9a-fA-F]{2}(?:\1[0-9a-fA-F]{2}){4}z MAC address%Y-%m-%dcsfdd}|S)a Helper to create a parse action for converting parsed date string to Python datetime.date Params - - fmt - format to be passed to datetime.strptime (default=C{"%Y-%m-%d"}) Example:: date_expr = pyparsing_common.iso8601_date.copy() date_expr.setParseAction(pyparsing_common.convertToDate()) print(date_expr.parseString("1999-12-31")) prints:: [datetime.date(1999, 12, 31)] csLytj|djStk rF}zt||t|WYdd}~XnXdS)Nr)rstrptimeZdaterrr{)rr5rvve)fmtrwrxcvt_fnsz.pyparsing_common.convertToDate..cvt_fnrw)rrrw)rrx convertToDates zpyparsing_common.convertToDate%Y-%m-%dT%H:%M:%S.%fcsfdd}|S)a Helper to create a parse action for converting parsed datetime string to Python datetime.datetime Params - - fmt - format to be passed to datetime.strptime (default=C{"%Y-%m-%dT%H:%M:%S.%f"}) Example:: dt_expr = pyparsing_common.iso8601_datetime.copy() dt_expr.setParseAction(pyparsing_common.convertToDatetime()) print(dt_expr.parseString("1999-12-31T23:59:59.999")) prints:: [datetime.datetime(1999, 12, 31, 23, 59, 59, 999000)] csHytj|dStk rB}zt||t|WYdd}~XnXdS)Nr)rrrrr{)rr5rvr)rrwrxrsz2pyparsing_common.convertToDatetime..cvt_fnrw)rrrw)rrxconvertToDatetimes z"pyparsing_common.convertToDatetimez7(?P\d{4})(?:-(?P\d\d)(?:-(?P\d\d))?)?z ISO8601 datez(?P\d{4})-(?P\d\d)-(?P\d\d)[T ](?P\d\d):(?P\d\d)(:(?P\d\d(\.\d*)?)?)?(?PZ|[+-]\d\d:?\d\d)?zISO8601 datetimez2[0-9a-fA-F]{8}(-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}UUIDcCstjj|dS)a Parse action to remove HTML tags from web page HTML source Example:: # strip HTML links from normal text text = 'More info at the
pyparsing wiki page' td,td_end = makeHTMLTags("TD") table_text = td + SkipTo(td_end).setParseAction(pyparsing_common.stripHTMLTags)("body") + td_end print(table_text.parseString(text).body) # -> 'More info at the pyparsing wiki page' r)rn_html_stripperr)rr5rrwrwrx stripHTMLTagss zpyparsing_common.stripHTMLTagsr`)rz rr)rzcomma separated listcCs t|jS)N)rr)rvrwrwrxryscCs t|jS)N)rr)rvrwrwrxrysN)rrB)rrB)r)r)?rrrrrmruZconvertToIntegerfloatZconvertToFloatr/rRrirrrDrr'Zsigned_integerrrxrrZ mixed_integerrGrealZsci_realrnumberrr4r3rZ ipv4_addressrZ_full_ipv6_addressZ_short_ipv6_addressr~Z_mixed_ipv6_addressr Z ipv6_addressZ mac_addressrrrZ iso8601_dateZiso8601_datetimeuuidr7r6rrrrrrVr. _commasepitemr@rYrZcomma_separated_listrdrBrwrwrwrxrnsN"" 2   8__main__Zselectfromz_$r\)racolumnsrjZtablesZcommandaK # '*' as column list and dotted table name select * from SYS.XYZZY # caseless match on "SELECT", and casts back to "select" SELECT * from XYZZY, ABC # list of column names, and mixed case SELECT keyword Select AA,BB,CC from Sys.dual # multiple tables Select A, B, C from Sys.dual, Table2 # invalid SELECT keyword - should fail Xelect A, B, C from Sys.dual # incomplete command - should fail Select # invalid column name - should fail Select ^^^ frox Sys.dual z] 100 -100 +100 3.14159 6.02e23 1e-12 z 100 FF z6 12345678-1234-5678-1234-567812345678 )rq)r`F)N)FT)T)r)T)r __version__Z__versionTime__ __author__rweakrefrrrr~rrdrrr"r<rr_threadr ImportErrorZ threadingrrZ ordereddict__all__r version_infor;rmaxsizerr{rchrrtrrGrrreversedrrrr5r r rIZmaxintZxrangerZ __builtin__rZfnamerrJrrrrrrZascii_uppercaseZascii_lowercaser4rRrDr3rjrZ printablerVrKrrr!r#r&rr"MutableMappingregisterr9rJrGr/r2r4rQrMr$r,r rrrrQrrrrlr/r'r%r r.r/rrrr*r)r1r0r rrrr rrrrIrr2rLrMrr(rrUr-r rr r+rrbr@r<rrOrNrrSrArgrhrjrirCrIrHrar`rZ _escapedPuncZ_escapedHexCharZ_escapedOctCharUNICODEZ _singleCharZ _charRangermr|r_rMr\rZrmrdrBrrKrLrerrkrTrrrirUr>r^rYrcrPrfr5rWr7r6rrrrr;r[r8rErr]r?r=rFrXrrr:rnrZ selectTokenZ fromTokenZidentZ columnNameZcolumnNameListZ columnSpecZ tableNameZ tableNameListZ simpleSQLrrrrrrrwrwrwrx=s                 8      @d &A= I G3pLOD|M &#@sQ,A,    I# %     &0 ,   ? #k Zr   (  0     "pyparsing.cpython-36.pyc000064400000610513147204744630011227 0ustar003 ]@s dZdZdZdZddlZddlmZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZddlZddlZddlmZyddlmZWn ek rddlmZYnXydd l mZWn>ek rydd lmZWnek rdZYnXYnXd d d d ddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;dd?d@dAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd[d\d]d^d_d`dadbdcdddedfdgdhdidjdkdldmdndodpdqdrgiZee jddsZeddskZer"e jZe Z!e"Z#e Z$e%e&e'e(e)ee*e+e,e-e.g Z/nbe j0Ze1Z2dtduZ$gZ/ddl3Z3xBdvj4D]6Z5ye/j6e7e3e5Wne8k r|wJYnXqJWe9dwdxe2dyDZ:dzd{Z;Gd|d}d}e<Z=ej>ej?Z@d~ZAeAdZBe@eAZCe"dZDdjEddxejFDZGGdd!d!eHZIGdd#d#eIZJGdd%d%eIZKGdd'd'eKZLGdd*d*eHZMGddde<ZNGdd&d&e<ZOe jPjQeOdd=ZRddNZSddKZTddZUddZVddZWddUZXd/ddZYGdd(d(e<ZZGdd0d0eZZ[Gddde[Z\Gddde[Z]Gddde[Z^e^Z_e^eZ_`Gddde[ZaGdd d e^ZbGdd d eaZcGddpdpe[ZdGdd3d3e[ZeGdd+d+e[ZfGdd)d)e[ZgGdd d e[ZhGdd2d2e[ZiGddde[ZjGdddejZkGdddejZlGdddejZmGdd.d.ejZnGdd-d-ejZoGdd5d5ejZpGdd4d4ejZqGdd$d$eZZrGdd d erZsGdd d erZtGddderZuGddderZvGdd"d"eZZwGdddewZxGdddewZyGdddewZzGdddezZ{Gdd6d6ezZ|Gddde<Z}e}Z~GdddewZGdd,d,ewZGdddewZGdddeZGdd1d1ewZGdddeZGdddeZGdddeZGdd/d/eZGddde<ZddfZd0ddDZd1dd@Zdd΄ZddSZddRZdd҄Zd2ddWZddEZd3ddkZddlZddnZe\jdGZeljdMZemjdLZenjdeZeojddZeeeDdddڍjdd܄Zefd݃jdd܄Zefd߃jdd܄ZeeBeBeeeGddydBefde jBZeeedeZe^dedjdee{eeBjddZddcZddQZdd`Zdd^ZddqZedd܄Zedd܄ZddZddOZddPZddiZe<e_d4ddoZe=Ze<e_e<e_ededfddmZeZeefddjdZeefddjdZeefddefddBjdZee_dejjdZdddejfddTZd5ddjZedZedZeeee@eCdjd\ZZeed j4d Zefd d jEejÃd jdZĐdd_ZeefddjdZefdjdZefdjȃjdZefdjdZeefddeBjdZeZefdjdZee{eeeGdɐdeeede^dɃemj΃jdZeeejeBddjd>ZGd drdrZeҐd!k rebd"Zebd#Zeee@eCd$ZeeՐd%dӐd&jeZeeeփjd'Zאd(eBZeeՐd%dӐd&jeZeeeكjd)ZeӐd*eؐd'eeڐd)Zejܐd+ejjܐd,ejjܐd,ejjܐd-ddlZejjeejejjܐd.dS(6aS pyparsing module - Classes and methods to define and execute parsing grammars The pyparsing module is an alternative approach to creating and executing simple grammars, vs. the traditional lex/yacc approach, or the use of regular expressions. With pyparsing, you don't need to learn a new syntax for defining grammars or matching expressions - the parsing module provides a library of classes that you use to construct the grammar directly in Python. Here is a program to parse "Hello, World!" (or any greeting of the form C{", !"}), built up using L{Word}, L{Literal}, and L{And} elements (L{'+'} operator gives L{And} expressions, strings are auto-converted to L{Literal} expressions):: from pyparsing import Word, alphas # define grammar of a greeting greet = Word(alphas) + "," + Word(alphas) + "!" hello = "Hello, World!" print (hello, "->", greet.parseString(hello)) The program outputs the following:: Hello, World! -> ['Hello', ',', 'World', '!'] The Python representation of the grammar is quite readable, owing to the self-explanatory class names, and the use of '+', '|' and '^' operators. The L{ParseResults} object returned from L{ParserElement.parseString} can be accessed as a nested list, a dictionary, or an object with named attributes. The pyparsing module handles some of the problems that are typically vexing when writing text parsers: - extra or missing whitespace (the above program will also handle "Hello,World!", "Hello , World !", etc.) - quoted strings - embedded comments z2.1.10z07 Oct 2016 01:31 UTCz*Paul McGuire N)ref)datetime)RLock) OrderedDictAndCaselessKeywordCaselessLiteral CharsNotInCombineDictEachEmpty FollowedByForward GoToColumnGroupKeywordLineEnd LineStartLiteral MatchFirstNoMatchNotAny OneOrMoreOnlyOnceOptionalOrParseBaseExceptionParseElementEnhanceParseExceptionParseExpressionParseFatalException ParseResultsParseSyntaxException ParserElement QuotedStringRecursiveGrammarExceptionRegexSkipTo StringEnd StringStartSuppressTokenTokenConverterWhiteWordWordEnd WordStart ZeroOrMore alphanumsalphas alphas8bit anyCloseTag anyOpenTag cStyleCommentcolcommaSeparatedListcommonHTMLEntity countedArraycppStyleCommentdblQuotedStringdblSlashComment delimitedListdictOfdowncaseTokensemptyhexnums htmlCommentjavaStyleCommentlinelineEnd lineStartlineno makeHTMLTags makeXMLTagsmatchOnlyAtColmatchPreviousExprmatchPreviousLiteral nestedExprnullDebugActionnumsoneOfopAssocoperatorPrecedence printablespunc8bitpythonStyleComment quotedString removeQuotesreplaceHTMLEntity replaceWith restOfLinesglQuotedStringsrange stringEnd stringStarttraceParseAction unicodeString upcaseTokens withAttribute indentedBlockoriginalTextForungroup infixNotation locatedExpr withClass CloseMatchtokenMappyparsing_commonc Cs`t|tr|Syt|Stk rZt|jtjd}td}|jdd|j |SXdS)aDrop-in replacement for str(obj) that tries to be Unicode friendly. It first tries str(obj). If that fails with a UnicodeEncodeError, then it tries unicode(obj). It then < returns the unicode object | encodes it with the default encoding | ... >. xmlcharrefreplacez&#\d+;cSs$dtt|dddddS)Nz\ur)hexint)trw/usr/lib/python3.6/pyparsing.pysz_ustr..N) isinstanceZunicodestrUnicodeEncodeErrorencodesysgetdefaultencodingr'setParseActiontransformString)objretZ xmlcharrefrwrwrx_ustrs rz6sum len sorted reversed list tuple set any all min maxccs|] }|VqdS)Nrw).0yrwrwrx srrrcCs>d}dddjD}x"t||D]\}}|j||}q"W|S)z/Escape &, <, >, ", ', etc. in a string of data.z&><"'css|]}d|dVqdS)&;Nrw)rsrwrwrxrsz_xml_escape..zamp gt lt quot apos)splitzipreplace)dataZ from_symbolsZ to_symbolsZfrom_Zto_rwrwrx _xml_escapes rc@s eZdZdS) _ConstantsN)__name__ __module__ __qualname__rwrwrwrxrsr 0123456789Z ABCDEFabcdef\ccs|]}|tjkr|VqdS)N)stringZ whitespace)rcrwrwrxrsc@sPeZdZdZdddZeddZdd Zd d Zd d Z dddZ ddZ dS)rz7base exception class for all parsing runtime exceptionsrNcCs>||_|dkr||_d|_n ||_||_||_|||f|_dS)Nr)locmsgpstr parserElementargs)selfrrrelemrwrwrx__init__szParseBaseException.__init__cCs||j|j|j|jS)z internal factory method to simplify creating one type of ParseException from another - avoids having __init__ signature conflicts among subclasses )rrrr)clsperwrwrx_from_exceptionsz"ParseBaseException._from_exceptioncCsN|dkrt|j|jS|dkr,t|j|jS|dkrBt|j|jSt|dS)zsupported attributes by name are: - lineno - returns the line number of the exception text - col - returns the column number of the exception text - line - returns the line containing the exception text rJr9columnrGN)r9r)rJrrr9rGAttributeError)rZanamerwrwrx __getattr__szParseBaseException.__getattr__cCsd|j|j|j|jfS)Nz"%s (at char %d), (line:%d, col:%d))rrrJr)rrwrwrx__str__szParseBaseException.__str__cCst|S)N)r)rrwrwrx__repr__szParseBaseException.__repr__>!} ('-' operator) indicates that parsing is to stop immediately because an unbacktrackable syntax error has been foundN)rrrrrwrwrwrxr#sc@s eZdZdZddZddZdS)r&zZexception thrown by L{ParserElement.validate} if the grammar could be improperly recursivecCs ||_dS)N)parseElementTrace)rparseElementListrwrwrxrsz"RecursiveGrammarException.__init__cCs d|jS)NzRecursiveGrammarException: %s)r)rrwrwrxr sz!RecursiveGrammarException.__str__N)rrrrrrrwrwrwrxr&sc@s,eZdZddZddZddZddZd S) _ParseResultsWithOffsetcCs||f|_dS)N)tup)rZp1Zp2rwrwrxr$sz _ParseResultsWithOffset.__init__cCs |j|S)N)r)rirwrwrx __getitem__&sz#_ParseResultsWithOffset.__getitem__cCst|jdS)Nr)reprr)rrwrwrxr(sz _ParseResultsWithOffset.__repr__cCs|jd|f|_dS)Nr)r)rrrwrwrx setOffset*sz!_ParseResultsWithOffset.setOffsetN)rrrrrrrrwrwrwrxr#src@seZdZdZd[ddZddddefddZdd Zefd d Zd d Z ddZ ddZ ddZ e Z ddZddZddZddZddZereZeZeZn$eZeZeZddZd d!Zd"d#Zd$d%Zd&d'Zd\d(d)Zd*d+Zd,d-Zd.d/Zd0d1Z d2d3Z!d4d5Z"d6d7Z#d8d9Z$d:d;Z%d} - see L{ParserElement.setResultsName}) Example:: integer = Word(nums) date_str = (integer.setResultsName("year") + '/' + integer.setResultsName("month") + '/' + integer.setResultsName("day")) # equivalent form: # date_str = integer("year") + '/' + integer("month") + '/' + integer("day") # parseString returns a ParseResults object result = date_str.parseString("1999/12/31") def test(s, fn=repr): print("%s -> %s" % (s, fn(eval(s)))) test("list(result)") test("result[0]") test("result['month']") test("result.day") test("'month' in result") test("'minutes' in result") test("result.dump()", str) prints:: list(result) -> ['1999', '/', '12', '/', '31'] result[0] -> '1999' result['month'] -> '12' result.day -> '31' 'month' in result -> True 'minutes' in result -> False result.dump() -> ['1999', '/', '12', '/', '31'] - day: 31 - month: 12 - year: 1999 NTcCs"t||r|Stj|}d|_|S)NT)rzobject__new___ParseResults__doinit)rtoklistnameasListmodalZretobjrwrwrxrTs   zParseResults.__new__c Cs`|jrvd|_d|_d|_i|_||_||_|dkr6g}||trP|dd|_n||trft||_n|g|_t |_ |dk o|r\|sd|j|<||t rt |}||_||t dttfo|ddgfks\||tr|g}|r&||trt|jd||<ntt|dd||<|||_n6y|d||<Wn$tttfk rZ|||<YnXdS)NFrr)r_ParseResults__name_ParseResults__parent_ParseResults__accumNames_ParseResults__asList_ParseResults__modallist_ParseResults__toklist_generatorTypedict_ParseResults__tokdictrurr basestringr"rcopyKeyError TypeError IndexError)rrrrrrzrwrwrxr]sB     $   zParseResults.__init__cCsPt|ttfr|j|S||jkr4|j|ddStdd|j|DSdS)NrrrcSsg|] }|dqS)rrw)rvrwrwrx sz,ParseResults.__getitem__..rs)rzruslicerrrr")rrrwrwrxrs   zParseResults.__getitem__cCs||tr0|jj|t|g|j|<|d}nD||ttfrN||j|<|}n&|jj|tt|dg|j|<|}||trt||_ dS)Nr) rrgetrrurrr"wkrefr)rkrrzsubrwrwrx __setitem__s   " zParseResults.__setitem__c Cst|ttfrt|j}|j|=t|trH|dkr:||7}t||d}tt|j|}|jx^|j j D]F\}}x<|D]4}x.t |D]"\}\}} t || | |k||<qWq|WqnWn|j |=dS)Nrrr) rzrurlenrrrangeindicesreverseritems enumerater) rrZmylenZremovedr occurrencesjrvaluepositionrwrwrx __delitem__s   $zParseResults.__delitem__cCs ||jkS)N)r)rrrwrwrx __contains__szParseResults.__contains__cCs t|jS)N)rr)rrwrwrx__len__szParseResults.__len__cCs |j S)N)r)rrwrwrx__bool__szParseResults.__bool__cCs t|jS)N)iterr)rrwrwrx__iter__szParseResults.__iter__cCst|jdddS)Nrrrs)rr)rrwrwrx __reversed__szParseResults.__reversed__cCs$t|jdr|jjSt|jSdS)Niterkeys)hasattrrrr)rrwrwrx _iterkeyss  zParseResults._iterkeyscsfddjDS)Nc3s|]}|VqdS)Nrw)rr)rrwrxrsz+ParseResults._itervalues..)r)rrw)rrx _itervaluesszParseResults._itervaluescsfddjDS)Nc3s|]}||fVqdS)Nrw)rr)rrwrxrsz*ParseResults._iteritems..)r)rrw)rrx _iteritemsszParseResults._iteritemscCs t|jS)zVReturns all named result keys (as a list in Python 2.x, as an iterator in Python 3.x).)rr)rrwrwrxkeysszParseResults.keyscCs t|jS)zXReturns all named result values (as a list in Python 2.x, as an iterator in Python 3.x).)r itervalues)rrwrwrxvaluesszParseResults.valuescCs t|jS)zfReturns all named result key-values (as a list of tuples in Python 2.x, as an iterator in Python 3.x).)r iteritems)rrwrwrxrszParseResults.itemscCs t|jS)zSince keys() returns an iterator, this method is helpful in bypassing code that looks for the existence of any defined results names.)boolr)rrwrwrxhaskeysszParseResults.haskeyscOs|s dg}x6|jD]*\}}|dkr2|d|f}qtd|qWt|dtsht|dksh|d|kr|d}||}||=|S|d}|SdS)a Removes and returns item at specified index (default=C{last}). Supports both C{list} and C{dict} semantics for C{pop()}. If passed no argument or an integer argument, it will use C{list} semantics and pop tokens from the list of parsed tokens. If passed a non-integer argument (most likely a string), it will use C{dict} semantics and pop the corresponding value from any defined results names. A second default return value argument is supported, just as in C{dict.pop()}. Example:: def remove_first(tokens): tokens.pop(0) print(OneOrMore(Word(nums)).parseString("0 123 321")) # -> ['0', '123', '321'] print(OneOrMore(Word(nums)).addParseAction(remove_first).parseString("0 123 321")) # -> ['123', '321'] label = Word(alphas) patt = label("LABEL") + OneOrMore(Word(nums)) print(patt.parseString("AAB 123 321").dump()) # Use pop() in a parse action to remove named result (note that corresponding value is not # removed from list form of results) def remove_LABEL(tokens): tokens.pop("LABEL") return tokens patt.addParseAction(remove_LABEL) print(patt.parseString("AAB 123 321").dump()) prints:: ['AAB', '123', '321'] - LABEL: AAB ['AAB', '123', '321'] rrdefaultrz-pop() got an unexpected keyword argument '%s'Nrs)rrrzrur)rrkwargsrrindexrZ defaultvaluerwrwrxpops"  zParseResults.popcCs||kr||S|SdS)ai Returns named result matching the given key, or if there is no such name, then returns the given C{defaultValue} or C{None} if no C{defaultValue} is specified. Similar to C{dict.get()}. Example:: integer = Word(nums) date_str = integer("year") + '/' + integer("month") + '/' + integer("day") result = date_str.parseString("1999/12/31") print(result.get("year")) # -> '1999' print(result.get("hour", "not specified")) # -> 'not specified' print(result.get("hour")) # -> None Nrw)rkey defaultValuerwrwrxrszParseResults.getcCsZ|jj||xF|jjD]8\}}x.t|D]"\}\}}t||||k||<q,WqWdS)a Inserts new element at location index in the list of parsed tokens. Similar to C{list.insert()}. Example:: print(OneOrMore(Word(nums)).parseString("0 123 321")) # -> ['0', '123', '321'] # use a parse action to insert the parse location in the front of the parsed results def insert_locn(locn, tokens): tokens.insert(0, locn) print(OneOrMore(Word(nums)).addParseAction(insert_locn).parseString("0 123 321")) # -> [0, '0', '123', '321'] N)rinsertrrrr)rrZinsStrrrrrrrwrwrxr2szParseResults.insertcCs|jj|dS)a Add single element to end of ParseResults list of elements. Example:: print(OneOrMore(Word(nums)).parseString("0 123 321")) # -> ['0', '123', '321'] # use a parse action to compute the sum of the parsed integers, and add it to the end def append_sum(tokens): tokens.append(sum(map(int, tokens))) print(OneOrMore(Word(nums)).addParseAction(append_sum).parseString("0 123 321")) # -> ['0', '123', '321', 444] N)rappend)ritemrwrwrxrFs zParseResults.appendcCs$t|tr||7}n |jj|dS)a Add sequence of elements to end of ParseResults list of elements. Example:: patt = OneOrMore(Word(alphas)) # use a parse action to append the reverse of the matched strings, to make a palindrome def make_palindrome(tokens): tokens.extend(reversed([t[::-1] for t in tokens])) return ''.join(tokens) print(patt.addParseAction(make_palindrome).parseString("lskdj sdlkjf lksd")) # -> 'lskdjsdlkjflksddsklfjkldsjdksl' N)rzr"rextend)rZitemseqrwrwrxrTs  zParseResults.extendcCs|jdd=|jjdS)z7 Clear all elements and results names. N)rrclear)rrwrwrxrfs zParseResults.clearc Csfy||Stk rdSX||jkr^||jkrD|j|ddStdd|j|DSndSdS)NrrrrcSsg|] }|dqS)rrw)rrrwrwrxrwsz,ParseResults.__getattr__..rs)rrrr")rrrwrwrxrms  zParseResults.__getattr__cCs|j}||7}|S)N)r)rotherrrwrwrx__add__{szParseResults.__add__cs|jrnt|jfdd|jj}fdd|D}x4|D],\}}|||<t|dtr>t||d_q>W|j|j7_|jj |j|S)Ncs|dkr S|S)Nrrw)a)offsetrwrxrysz'ParseResults.__iadd__..c s4g|],\}}|D]}|t|d|dfqqS)rrr)r)rrvlistr) addoffsetrwrxrsz)ParseResults.__iadd__..r) rrrrrzr"rrrupdate)rrZ otheritemsZotherdictitemsrrrw)rrrx__iadd__s    zParseResults.__iadd__cCs&t|tr|dkr|jS||SdS)Nr)rzrur)rrrwrwrx__radd__szParseResults.__radd__cCsdt|jt|jfS)Nz(%s, %s))rrr)rrwrwrxrszParseResults.__repr__cCsddjdd|jDdS)N[z, css(|] }t|trt|nt|VqdS)N)rzr"rr)rrrwrwrxrsz'ParseResults.__str__..])rr)rrwrwrxrszParseResults.__str__rcCsPg}xF|jD]<}|r"|r"|j|t|tr:||j7}q |jt|q W|S)N)rrrzr" _asStringListr)rsepoutrrwrwrxr s   zParseResults._asStringListcCsdd|jDS)a Returns the parse results as a nested list of matching tokens, all converted to strings. Example:: patt = OneOrMore(Word(alphas)) result = patt.parseString("sldkj lsdkj sldkj") # even though the result prints in string-like form, it is actually a pyparsing ParseResults print(type(result), result) # -> ['sldkj', 'lsdkj', 'sldkj'] # Use asList() to create an actual list result_list = result.asList() print(type(result_list), result_list) # -> ['sldkj', 'lsdkj', 'sldkj'] cSs"g|]}t|tr|jn|qSrw)rzr"r)rresrwrwrxrsz'ParseResults.asList..)r)rrwrwrxrszParseResults.asListcs6tr |j}n|j}fddtfdd|DS)a Returns the named parse results as a nested dictionary. Example:: integer = Word(nums) date_str = integer("year") + '/' + integer("month") + '/' + integer("day") result = date_str.parseString('12/31/1999') print(type(result), repr(result)) # -> (['12', '/', '31', '/', '1999'], {'day': [('1999', 4)], 'year': [('12', 0)], 'month': [('31', 2)]}) result_dict = result.asDict() print(type(result_dict), repr(result_dict)) # -> {'day': '1999', 'year': '12', 'month': '31'} # even though a ParseResults supports dict-like access, sometime you just need to have a dict import json print(json.dumps(result)) # -> Exception: TypeError: ... is not JSON serializable print(json.dumps(result.asDict())) # -> {"month": "31", "day": "1999", "year": "12"} cs6t|tr.|jr|jSfdd|DSn|SdS)Ncsg|] }|qSrwrw)rr)toItemrwrxrsz7ParseResults.asDict..toItem..)rzr"rasDict)r)rrwrxrs  z#ParseResults.asDict..toItemc3s|]\}}||fVqdS)Nrw)rrr)rrwrxrsz&ParseResults.asDict..)PY_3rrr)rZitem_fnrw)rrxrs  zParseResults.asDictcCs8t|j}|jj|_|j|_|jj|j|j|_|S)zA Returns a new copy of a C{ParseResults} object. )r"rrrrrrr)rrrwrwrxrs   zParseResults.copyFc CsPd}g}tdd|jjD}|d}|s8d}d}d}d} |dk rJ|} n |jrV|j} | sf|rbdSd} |||d| d g7}xt|jD]\} } t| tr| |kr|| j|| |o|dk||g7}n|| jd|o|dk||g7}qd} | |kr|| } | s |rqnd} t t | } |||d| d | d | d g 7}qW|||d | d g7}dj |S) z (Deprecated) Returns the parse results as XML. Tags are created for tokens and lists that have defined results names.  css(|] \}}|D]}|d|fVqqdS)rrNrw)rrrrrwrwrxrsz%ParseResults.asXML..z rNZITEM<>z.z %s%s- %s: z rrcss|]}t|tVqdS)N)rzr")rvvrwrwrxrssz %s%s[%d]: %s%s%sr) rrrrsortedrrzr"dumpranyrr) rrdepthfullr NLrrrrrrwrwrxrPs,   4.zParseResults.dumpcOstj|jf||dS)a Pretty-printer for parsed results as a list, using the C{pprint} module. Accepts additional positional or keyword args as defined for the C{pprint.pprint} method. (U{http://docs.python.org/3/library/pprint.html#pprint.pprint}) Example:: ident = Word(alphas, alphanums) num = Word(nums) func = Forward() term = ident | num | Group('(' + func + ')') func <<= ident + Group(Optional(delimitedList(term))) result = func.parseString("fna a,b,(fnb c,d,200),100") result.pprint(width=40) prints:: ['fna', ['a', 'b', ['(', 'fnb', ['c', 'd', '200'], ')'], '100']] N)pprintr)rrrrwrwrxr"}szParseResults.pprintcCs.|j|jj|jdk r|jp d|j|jffS)N)rrrrrr)rrwrwrx __getstate__s zParseResults.__getstate__cCsN|d|_|d\|_}}|_i|_|jj||dk rDt||_nd|_dS)Nrrr)rrrrrrr)rstaterZ inAccumNamesrwrwrx __setstate__s   zParseResults.__setstate__cCs|j|j|j|jfS)N)rrrr)rrwrwrx__getnewargs__szParseResults.__getnewargs__cCstt|t|jS)N)rrrr)rrwrwrxrszParseResults.__dir__)NNTT)N)r)NFrT)rrT)4rrrrrrzrrrrrrr __nonzero__rrrrrrrrrrrrrrrrrrrrrrrrrr rrrrrrrr"r#r%r&rrwrwrwrxr"-sh& ' 4  # =% - cCsF|}d|kot|knr4||ddkr4dS||jdd|S)aReturns current column within a string, counting newlines as line separators. The first column is number 1. Note: the default parsing behavior is to expand tabs in the input string before starting the parsing process. See L{I{ParserElement.parseString}} for more information on parsing strings containing C{}s, and suggested methods to maintain a consistent view of the parsed string, the parse location, and line and column positions within the parsed string. rrrr)rrfind)rstrgrrwrwrxr9s cCs|jdd|dS)aReturns current line number within a string, counting newlines as line separators. The first line is number 1. Note: the default parsing behavior is to expand tabs in the input string before starting the parsing process. See L{I{ParserElement.parseString}} for more information on parsing strings containing C{}s, and suggested methods to maintain a consistent view of the parsed string, the parse location, and line and column positions within the parsed string. rrrr)count)rr)rwrwrxrJs cCsF|jdd|}|jd|}|dkr2||d|S||ddSdS)zfReturns the line of text containing loc within a string, counting newlines as line separators. rrrrN)r(find)rr)ZlastCRZnextCRrwrwrxrGs  cCs8tdt|dt|dt||t||fdS)NzMatch z at loc z(%d,%d))printrrJr9)instringrexprrwrwrx_defaultStartDebugActionsr/cCs$tdt|dt|jdS)NzMatched z -> )r,rr{r)r-startlocZendlocr.toksrwrwrx_defaultSuccessDebugActionsr2cCstdt|dS)NzException raised:)r,r)r-rr.excrwrwrx_defaultExceptionDebugActionsr4cGsdS)zG'Do-nothing' debug action, to suppress debugging output during parsing.Nrw)rrwrwrxrQsrqc stkrfddSdgdgtdddkrFddd }dd d n tj}tjd }|dd d}|d|d|ffdd}d}ytdtdj}Wntk rt}YnX||_|S)Ncs|S)Nrw)rlrv)funcrwrxrysz_trim_arity..rFrqrocSs8tdkr dnd }tj| |dd|}|j|jfgS) Nror7rrqrr)limit)ror7r)system_version traceback extract_stackfilenamerJ)r8r frame_summaryrwrwrxr=sz"_trim_arity..extract_stackcSs$tj||d}|d}|j|jfgS)N)r8rrrs)r< extract_tbr>rJ)tbr8Zframesr?rwrwrxr@sz_trim_arity..extract_tb)r8rrcsxy |dd}dd<|Stk rdr>n4z.tjd}|dddddksjWd~Xdkrdd7<wYqXqWdS)NrTrrrq)r8rsrs)rr~exc_info)rrrA)r@ foundArityr6r8maxargspa_call_line_synthrwrxwrappers"  z_trim_arity..wrapperzr __class__)ror7)r)rrs) singleArgBuiltinsr;r<r=r@getattrr Exceptionr{)r6rEr=Z LINE_DIFFZ this_linerG func_namerw)r@rDr6r8rErFrx _trim_aritys*   rMcseZdZdZdZdZeddZeddZddd Z d d Z d d Z dddZ dddZ ddZddZddZddZddZddZddd Zd!d"Zdd#d$Zd%d&Zd'd(ZGd)d*d*eZed+k rGd,d-d-eZnGd.d-d-eZiZeZd/d/gZ dd0d1Z!eZ"ed2d3Z#dZ$edd5d6Z%dd7d8Z&e'dfd9d:Z(d;d<Z)e'fd=d>Z*e'dfd?d@Z+dAdBZ,dCdDZ-dEdFZ.dGdHZ/dIdJZ0dKdLZ1dMdNZ2dOdPZ3dQdRZ4dSdTZ5dUdVZ6dWdXZ7dYdZZ8dd[d\Z9d]d^Z:d_d`Z;dadbZdgdhZ?ddidjZ@dkdlZAdmdnZBdodpZCdqdrZDgfdsdtZEddudvZFfdwdxZGdydzZHd{d|ZId}d~ZJddZKdddZLdddZMZNS)r$z)Abstract base level parser element class.z FcCs |t_dS)a Overrides the default whitespace chars Example:: # default whitespace chars are space, and newline OneOrMore(Word(alphas)).parseString("abc def\nghi jkl") # -> ['abc', 'def', 'ghi', 'jkl'] # change to just treat newline as significant ParserElement.setDefaultWhitespaceChars(" \t") OneOrMore(Word(alphas)).parseString("abc def\nghi jkl") # -> ['abc', 'def'] N)r$DEFAULT_WHITE_CHARS)charsrwrwrxsetDefaultWhitespaceChars=s z'ParserElement.setDefaultWhitespaceCharscCs |t_dS)a Set class to be used for inclusion of string literals into a parser. Example:: # default literal class used is Literal integer = Word(nums) date_str = integer("year") + '/' + integer("month") + '/' + integer("day") date_str.parseString("1999/12/31") # -> ['1999', '/', '12', '/', '31'] # change to Suppress ParserElement.inlineLiteralsUsing(Suppress) date_str = integer("year") + '/' + integer("month") + '/' + integer("day") date_str.parseString("1999/12/31") # -> ['1999', '12', '31'] N)r$_literalStringClass)rrwrwrxinlineLiteralsUsingLsz!ParserElement.inlineLiteralsUsingcCst|_d|_d|_d|_||_d|_tj|_ d|_ d|_ d|_ t|_ d|_d|_d|_d|_d|_d|_d|_d|_d|_dS)NTFr)NNN)r parseAction failActionstrRepr resultsName saveAsListskipWhitespacer$rN whiteCharscopyDefaultWhiteCharsmayReturnEmptykeepTabs ignoreExprsdebug streamlined mayIndexErrorerrmsg modalResults debugActionsre callPreparse callDuringTry)rsavelistrwrwrxras(zParserElement.__init__cCs<tj|}|jdd|_|jdd|_|jr8tj|_|S)a$ Make a copy of this C{ParserElement}. Useful for defining different parse actions for the same parsing pattern, using copies of the original parse element. Example:: integer = Word(nums).setParseAction(lambda toks: int(toks[0])) integerK = integer.copy().addParseAction(lambda toks: toks[0]*1024) + Suppress("K") integerM = integer.copy().addParseAction(lambda toks: toks[0]*1024*1024) + Suppress("M") print(OneOrMore(integerK | integerM | integer).parseString("5K 100 640K 256M")) prints:: [5120, 100, 655360, 268435456] Equivalent form of C{expr.copy()} is just C{expr()}:: integerM = integer().addParseAction(lambda toks: toks[0]*1024*1024) + Suppress("M") N)rrSr]rZr$rNrY)rZcpyrwrwrxrxs  zParserElement.copycCs*||_d|j|_t|dr&|j|j_|S)af Define name for this expression, makes debugging and exception messages clearer. Example:: Word(nums).parseString("ABC") # -> Exception: Expected W:(0123...) (at char 0), (line:1, col:1) Word(nums).setName("integer").parseString("ABC") # -> Exception: Expected integer (at char 0), (line:1, col:1) z Expected exception)rrarrhr)rrrwrwrxsetNames    zParserElement.setNamecCs4|j}|jdr"|dd}d}||_| |_|S)aP Define name for referencing matching tokens as a nested attribute of the returned parse results. NOTE: this returns a *copy* of the original C{ParserElement} object; this is so that the client can define a basic element, such as an integer, and reference it in multiple places with different names. You can also set results names using the abbreviated syntax, C{expr("name")} in place of C{expr.setResultsName("name")} - see L{I{__call__}<__call__>}. Example:: date_str = (integer.setResultsName("year") + '/' + integer.setResultsName("month") + '/' + integer.setResultsName("day")) # equivalent form: date_str = integer("year") + '/' + integer("month") + '/' + integer("day") *NrrTrs)rendswithrVrb)rrlistAllMatchesZnewselfrwrwrxsetResultsNames  zParserElement.setResultsNameTcs@|r&|jdfdd }|_||_nt|jdr<|jj|_|S)zMethod to invoke the Python pdb debugger when this element is about to be parsed. Set C{breakFlag} to True to enable, False to disable. Tcsddl}|j||||S)Nr)pdbZ set_trace)r-r doActions callPreParsern) _parseMethodrwrxbreakersz'ParserElement.setBreak..breaker_originalParseMethod)TT)_parsersr)rZ breakFlagrrrw)rqrxsetBreaks  zParserElement.setBreakcOs&tttt||_|jdd|_|S)a  Define action to perform when successfully matching parse element definition. Parse action fn is a callable method with 0-3 arguments, called as C{fn(s,loc,toks)}, C{fn(loc,toks)}, C{fn(toks)}, or just C{fn()}, where: - s = the original string being parsed (see note below) - loc = the location of the matching substring - toks = a list of the matched tokens, packaged as a C{L{ParseResults}} object If the functions in fns modify the tokens, they can return them as the return value from fn, and the modified list of tokens will replace the original. Otherwise, fn does not need to return any value. Optional keyword arguments: - callDuringTry = (default=C{False}) indicate if parse action should be run during lookaheads and alternate testing Note: the default parsing behavior is to expand tabs in the input string before starting the parsing process. See L{I{parseString}} for more information on parsing strings containing C{}s, and suggested methods to maintain a consistent view of the parsed string, the parse location, and line and column positions within the parsed string. Example:: integer = Word(nums) date_str = integer + '/' + integer + '/' + integer date_str.parseString("1999/12/31") # -> ['1999', '/', '12', '/', '31'] # use parse action to convert to ints at parse time integer = Word(nums).setParseAction(lambda toks: int(toks[0])) date_str = integer + '/' + integer + '/' + integer # note that integer fields are now ints, not strings date_str.parseString("1999/12/31") # -> [1999, '/', 12, '/', 31] rfF)rmaprMrSrrf)rfnsrrwrwrxrs"zParserElement.setParseActioncOs4|jtttt|7_|jp,|jdd|_|S)z Add parse action to expression's list of parse actions. See L{I{setParseAction}}. See examples in L{I{copy}}. rfF)rSrrvrMrfr)rrwrrwrwrxaddParseActionszParserElement.addParseActioncsb|jdd|jddrtntx(|D] fdd}|jj|q&W|jpZ|jdd|_|S)aAdd a boolean predicate function to expression's list of parse actions. See L{I{setParseAction}} for function call signatures. Unlike C{setParseAction}, functions passed to C{addCondition} need to return boolean success/fail of the condition. Optional keyword arguments: - message = define a custom message to be used in the raised exception - fatal = if True, will raise ParseFatalException to stop parsing immediately; otherwise will raise ParseException Example:: integer = Word(nums).setParseAction(lambda toks: int(toks[0])) year_int = integer.copy() year_int.addCondition(lambda toks: toks[0] >= 2000, message="Only support years 2000 and later") date_str = year_int + '/' + integer + '/' + integer result = date_str.parseString("1999/12/31") # -> Exception: Only support years 2000 and later (at char 0), (line:1, col:1) messagezfailed user-defined conditionfatalFcs$tt|||s ||dS)N)rrM)rr5rv)exc_typefnrrwrxpasz&ParserElement.addCondition..parf)rr!rrSrrf)rrwrr}rw)r{r|rrx addConditions  zParserElement.addConditioncCs ||_|S)a Define action to perform if parsing fails at this expression. Fail acton fn is a callable function that takes the arguments C{fn(s,loc,expr,err)} where: - s = string being parsed - loc = location where expression match was attempted and failed - expr = the parse expression that failed - err = the exception thrown The function returns no value. It may throw C{L{ParseFatalException}} if it is desired to stop parsing immediately.)rT)rr|rwrwrx setFailActions zParserElement.setFailActionc CsZd}xP|rTd}xB|jD]8}yx|j||\}}d}qWWqtk rLYqXqWqW|S)NTF)r]rtr)rr-rZ exprsFoundeZdummyrwrwrx_skipIgnorables#s  zParserElement._skipIgnorablescCsL|jr|j||}|jrH|j}t|}x ||krF|||krF|d7}q(W|S)Nrr)r]rrXrYr)rr-rZwtinstrlenrwrwrxpreParse0s  zParserElement.preParsecCs|gfS)Nrw)rr-rrorwrwrx parseImpl<szParserElement.parseImplcCs|S)Nrw)rr-r tokenlistrwrwrx postParse?szParserElement.postParsec "Cs|j}|s|jr|jdr,|jd||||rD|jrD|j||}n|}|}yDy|j|||\}}Wn(tk rt|t||j |YnXWnXt k r} z<|jdr|jd|||| |jr|j|||| WYdd} ~ XnXn|o|jr|j||}n|}|}|j s$|t|krhy|j|||\}}Wn*tk rdt|t||j |YnXn|j|||\}}|j |||}t ||j|j|jd} |jr|s|jr|rVyRxL|jD]B} | ||| }|dk rt ||j|jot|t tf|jd} qWWnFt k rR} z(|jdr@|jd|||| WYdd} ~ XnXnNxL|jD]B} | ||| }|dk r^t ||j|jot|t tf|jd} q^W|r|jdr|jd||||| || fS)Nrrq)rrrr)r^rTrcrerrrrrrarr`rr"rVrWrbrSrfrzr) rr-rrorpZ debuggingprelocZ tokensStarttokenserrZ retTokensr|rwrwrx _parseNoCacheCsp             zParserElement._parseNoCachec Cs>y|j||dddStk r8t|||j|YnXdS)NF)ror)rtr!rra)rr-rrwrwrxtryParseszParserElement.tryParsec Cs2y|j||Wnttfk r(dSXdSdS)NFT)rrr)rr-rrwrwrx canParseNexts zParserElement.canParseNextc@seZdZddZdS)zParserElement._UnboundedCachecsdit|_fdd}fdd}fdd}tj|||_tj|||_tj|||_dS)Ncs j|S)N)r)rr)cache not_in_cacherwrxrsz3ParserElement._UnboundedCache.__init__..getcs ||<dS)Nrw)rrr)rrwrxsetsz3ParserElement._UnboundedCache.__init__..setcs jdS)N)r)r)rrwrxrsz5ParserElement._UnboundedCache.__init__..clear)rrtypes MethodTyperrr)rrrrrw)rrrxrs   z&ParserElement._UnboundedCache.__init__N)rrrrrwrwrwrx_UnboundedCachesrNc@seZdZddZdS)zParserElement._FifoCachecsht|_tfdd}fdd}fdd}tj|||_tj|||_tj|||_dS)Ncs j|S)N)r)rr)rrrwrxrsz.ParserElement._FifoCache.__init__..getcs"||<tkrjddS)NF)rpopitem)rrr)rsizerwrxrs z.ParserElement._FifoCache.__init__..setcs jdS)N)r)r)rrwrxrsz0ParserElement._FifoCache.__init__..clear)rr _OrderedDictrrrrr)rrrrrrw)rrrrxrs  z!ParserElement._FifoCache.__init__N)rrrrrwrwrwrx _FifoCachesrc@seZdZddZdS)zParserElement._FifoCachecsvt|_itjgfdd}fdd}fdd}tj|||_tj|||_tj|||_dS)Ncs j|S)N)r)rr)rrrwrxrsz.ParserElement._FifoCache.__init__..getcs2||<tkr$jjdj|dS)N)rrpopleftr)rrr)rkey_fiforrwrxrs z.ParserElement._FifoCache.__init__..setcsjjdS)N)r)r)rrrwrxrsz0ParserElement._FifoCache.__init__..clear) rr collectionsdequerrrrr)rrrrrrw)rrrrrxrs  z!ParserElement._FifoCache.__init__N)rrrrrwrwrwrxrsrc Csd\}}|||||f}tjtj}|j|} | |jkrtj|d7<y|j||||} Wn8tk r} z|j|| j | j WYdd} ~ XqX|j|| d| dj f| Sn4tj|d7<t | t r| | d| dj fSWdQRXdS)Nrrr)rrr)r$packrat_cache_lock packrat_cacherrpackrat_cache_statsrrrrHrrrzrK) rr-rrorpZHITZMISSlookuprrrrwrwrx _parseCaches$   zParserElement._parseCachecCs(tjjdgttjtjdd<dS)Nr)r$rrrrrwrwrwrx resetCaches zParserElement.resetCachecCs8tjs4dt_|dkr tjt_n tj|t_tjt_dS)aEnables "packrat" parsing, which adds memoizing to the parsing logic. Repeated parse attempts at the same string location (which happens often in many complex grammars) can immediately return a cached value, instead of re-executing parsing/validating code. Memoizing is done of both valid results and parsing exceptions. Parameters: - cache_size_limit - (default=C{128}) - if an integer value is provided will limit the size of the packrat cache; if None is passed, then the cache size will be unbounded; if 0 is passed, the cache will be effectively disabled. This speedup may break existing programs that use parse actions that have side-effects. For this reason, packrat parsing is disabled when you first import pyparsing. To activate the packrat feature, your program must call the class method C{ParserElement.enablePackrat()}. If your program uses C{psyco} to "compile as you go", you must call C{enablePackrat} before calling C{psyco.full()}. If you do not do this, Python will crash. For best results, call C{enablePackrat()} immediately after importing pyparsing. Example:: import pyparsing pyparsing.ParserElement.enablePackrat() TN)r$_packratEnabledrrrrrt)Zcache_size_limitrwrwrx enablePackrats   zParserElement.enablePackratcCstj|js|jx|jD] }|jqW|js<|j}y<|j|d\}}|rv|j||}t t }|j||Wn0t k r}ztj rn|WYdd}~XnX|SdS)aB Execute the parse expression with the given string. This is the main interface to the client code, once the complete expression has been built. If you want the grammar to require that the entire input string be successfully parsed, then set C{parseAll} to True (equivalent to ending the grammar with C{L{StringEnd()}}). Note: C{parseString} implicitly calls C{expandtabs()} on the input string, in order to report proper column numbers in parse actions. If the input string contains tabs and the grammar uses parse actions that use the C{loc} argument to index into the string being parsed, you can ensure you have a consistent view of the input string by: - calling C{parseWithTabs} on your grammar before calling C{parseString} (see L{I{parseWithTabs}}) - define your parse action using the full C{(s,loc,toks)} signature, and reference the input string using the parse action's C{s} argument - explictly expand the tabs in your input string before calling C{parseString} Example:: Word('a').parseString('aaaaabaaa') # -> ['aaaaa'] Word('a').parseString('aaaaabaaa', parseAll=True) # -> Exception: Expected end of text rN) r$rr_ streamliner]r\ expandtabsrtrr r)rverbose_stacktrace)rr-parseAllrrrZser3rwrwrx parseString#s$    zParserElement.parseStringccs@|js|jx|jD] }|jqW|js8t|j}t|}d}|j}|j}t j d} yx||kon| |kry |||} ||| dd\} } Wnt k r| d}Yq`X| |kr| d7} | | | fV|r|||} | |kr| }q|d7}n| }q`| d}q`WWn4t k r:}zt j r&n|WYdd}~XnXdS)a Scan the input string for expression matches. Each match will return the matching tokens, start location, and end location. May be called with optional C{maxMatches} argument, to clip scanning after 'n' matches are found. If C{overlap} is specified, then overlapping matches will be reported. Note that the start and end locations are reported relative to the string being parsed. See L{I{parseString}} for more information on parsing strings with embedded tabs. Example:: source = "sldjf123lsdjjkf345sldkjf879lkjsfd987" print(source) for tokens,start,end in Word(alphas).scanString(source): print(' '*start + '^'*(end-start)) print(' '*start + tokens[0]) prints:: sldjf123lsdjjkf345sldkjf879lkjsfd987 ^^^^^ sldjf ^^^^^^^ lsdjjkf ^^^^^^ sldkjf ^^^^^^ lkjsfd rF)rprrN)r_rr]r\rrrrrtr$rrrr)rr- maxMatchesZoverlaprrrZ preparseFnZparseFnmatchesrZnextLocrZnextlocr3rwrwrx scanStringUsB       zParserElement.scanStringcCsg}d}d|_yxh|j|D]Z\}}}|j||||rrt|trT||j7}nt|trh||7}n |j||}qW|j||ddd|D}djtt t |St k r}zt j rȂn|WYdd}~XnXdS)af Extension to C{L{scanString}}, to modify matching text with modified tokens that may be returned from a parse action. To use C{transformString}, define a grammar and attach a parse action to it that modifies the returned token list. Invoking C{transformString()} on a target string will then scan for matches, and replace the matched text patterns according to the logic in the parse action. C{transformString()} returns the resulting transformed string. Example:: wd = Word(alphas) wd.setParseAction(lambda toks: toks[0].title()) print(wd.transformString("now is the winter of our discontent made glorious summer by this sun of york.")) Prints:: Now Is The Winter Of Our Discontent Made Glorious Summer By This Sun Of York. rTNcSsg|] }|r|qSrwrw)rorwrwrxrsz1ParserElement.transformString..r)r\rrrzr"rrrrvr_flattenrr$r)rr-r ZlastErvrrr3rwrwrxrs(    zParserElement.transformStringcCsPytdd|j||DStk rJ}ztjr6n|WYdd}~XnXdS)a~ Another extension to C{L{scanString}}, simplifying the access to the tokens found to match the given parse expression. May be called with optional C{maxMatches} argument, to clip searching after 'n' matches are found. Example:: # a capitalized word starts with an uppercase letter, followed by zero or more lowercase letters cap_word = Word(alphas.upper(), alphas.lower()) print(cap_word.searchString("More than Iron, more than Lead, more than Gold I need Electricity")) prints:: ['More', 'Iron', 'Lead', 'Gold', 'I'] cSsg|]\}}}|qSrwrw)rrvrrrwrwrxrsz.ParserElement.searchString..N)r"rrr$r)rr-rr3rwrwrx searchStrings zParserElement.searchStringc csXd}d}x<|j||dD]*\}}}|||V|r>|dV|}qW||dVdS)a[ Generator method to split a string using the given expression as a separator. May be called with optional C{maxsplit} argument, to limit the number of splits; and the optional C{includeSeparators} argument (default=C{False}), if the separating matching text should be included in the split results. Example:: punc = oneOf(list(".,;:/-!?")) print(list(punc.split("This, this?, this sentence, is badly punctuated!"))) prints:: ['This', ' this', '', ' this sentence', ' is badly punctuated', ''] r)rN)r) rr-maxsplitZincludeSeparatorsZsplitsZlastrvrrrwrwrxrs  zParserElement.splitcCsFt|trtj|}t|ts:tjdt|tdddSt||gS)a Implementation of + operator - returns C{L{And}}. Adding strings to a ParserElement converts them to L{Literal}s by default. Example:: greet = Word(alphas) + "," + Word(alphas) + "!" hello = "Hello, World!" print (hello, "->", greet.parseString(hello)) Prints:: Hello, World! -> ['Hello', ',', 'World', '!'] z4Cannot combine element of type %s with ParserElementrq) stacklevelN) rzrr$rQwarningswarnr SyntaxWarningr)rrrwrwrxrs    zParserElement.__add__cCsBt|trtj|}t|ts:tjdt|tdddS||S)z] Implementation of + operator when left operand is not a C{L{ParserElement}} z4Cannot combine element of type %s with ParserElementrq)rN)rzrr$rQrrrr)rrrwrwrxrs    zParserElement.__radd__cCsLt|trtj|}t|ts:tjdt|tdddSt|tj |gS)zQ Implementation of - operator, returns C{L{And}} with error stop z4Cannot combine element of type %s with ParserElementrq)rN) rzrr$rQrrrrr _ErrorStop)rrrwrwrx__sub__s    zParserElement.__sub__cCsBt|trtj|}t|ts:tjdt|tdddS||S)z] Implementation of - operator when left operand is not a C{L{ParserElement}} z4Cannot combine element of type %s with ParserElementrq)rN)rzrr$rQrrrr)rrrwrwrx__rsub__ s    zParserElement.__rsub__cst|tr|d}}nt|tr|d dd}|ddkrHd|df}t|dtr|ddkr|ddkrvtS|ddkrtS|dtSnJt|dtrt|dtr|\}}||8}ntdt|dt|dntdt||dkr td|dkrtd||ko2dknrBtd |rfd d |r|dkrt|}ntg||}n|}n|dkr}ntg|}|S) a Implementation of * operator, allows use of C{expr * 3} in place of C{expr + expr + expr}. Expressions may also me multiplied by a 2-integer tuple, similar to C{{min,max}} multipliers in regular expressions. Tuples may also include C{None} as in: - C{expr*(n,None)} or C{expr*(n,)} is equivalent to C{expr*n + L{ZeroOrMore}(expr)} (read as "at least n instances of C{expr}") - C{expr*(None,n)} is equivalent to C{expr*(0,n)} (read as "0 to n instances of C{expr}") - C{expr*(None,None)} is equivalent to C{L{ZeroOrMore}(expr)} - C{expr*(1,None)} is equivalent to C{L{OneOrMore}(expr)} Note that C{expr*(None,n)} does not raise an exception if more than n exprs exist in the input stream; that is, C{expr*(None,n)} does not enforce a maximum number of expr occurrences. If this behavior is desired, then write C{expr*(None,n) + ~expr} rNrqrrz7cannot multiply 'ParserElement' and ('%s','%s') objectsz0cannot multiply 'ParserElement' and '%s' objectsz/cannot multiply ParserElement by negative valuez@second tuple value must be greater or equal to first tuple valuez+cannot multiply ParserElement by 0 or (0,0)cs(|dkrt|dStSdS)Nrr)r)n)makeOptionalListrrwrxr]sz/ParserElement.__mul__..makeOptionalList)NN) rzrutupler2rrr ValueErrorr)rrZ minElementsZ optElementsrrw)rrrx__mul__,sD             zParserElement.__mul__cCs |j|S)N)r)rrrwrwrx__rmul__pszParserElement.__rmul__cCsFt|trtj|}t|ts:tjdt|tdddSt||gS)zI Implementation of | operator - returns C{L{MatchFirst}} z4Cannot combine element of type %s with ParserElementrq)rN) rzrr$rQrrrrr)rrrwrwrx__or__ss    zParserElement.__or__cCsBt|trtj|}t|ts:tjdt|tdddS||BS)z] Implementation of | operator when left operand is not a C{L{ParserElement}} z4Cannot combine element of type %s with ParserElementrq)rN)rzrr$rQrrrr)rrrwrwrx__ror__s    zParserElement.__ror__cCsFt|trtj|}t|ts:tjdt|tdddSt||gS)zA Implementation of ^ operator - returns C{L{Or}} z4Cannot combine element of type %s with ParserElementrq)rN) rzrr$rQrrrrr)rrrwrwrx__xor__s    zParserElement.__xor__cCsBt|trtj|}t|ts:tjdt|tdddS||AS)z] Implementation of ^ operator when left operand is not a C{L{ParserElement}} z4Cannot combine element of type %s with ParserElementrq)rN)rzrr$rQrrrr)rrrwrwrx__rxor__s    zParserElement.__rxor__cCsFt|trtj|}t|ts:tjdt|tdddSt||gS)zC Implementation of & operator - returns C{L{Each}} z4Cannot combine element of type %s with ParserElementrq)rN) rzrr$rQrrrrr )rrrwrwrx__and__s    zParserElement.__and__cCsBt|trtj|}t|ts:tjdt|tdddS||@S)z] Implementation of & operator when left operand is not a C{L{ParserElement}} z4Cannot combine element of type %s with ParserElementrq)rN)rzrr$rQrrrr)rrrwrwrx__rand__s    zParserElement.__rand__cCst|S)zE Implementation of ~ operator - returns C{L{NotAny}} )r)rrwrwrx __invert__szParserElement.__invert__cCs|dk r|j|S|jSdS)a  Shortcut for C{L{setResultsName}}, with C{listAllMatches=False}. If C{name} is given with a trailing C{'*'} character, then C{listAllMatches} will be passed as C{True}. If C{name} is omitted, same as calling C{L{copy}}. Example:: # these are equivalent userdata = Word(alphas).setResultsName("name") + Word(nums+"-").setResultsName("socsecno") userdata = Word(alphas)("name") + Word(nums+"-")("socsecno") N)rmr)rrrwrwrx__call__s zParserElement.__call__cCst|S)z Suppresses the output of this C{ParserElement}; useful to keep punctuation from cluttering up returned output. )r+)rrwrwrxsuppressszParserElement.suppresscCs d|_|S)a Disables the skipping of whitespace before matching the characters in the C{ParserElement}'s defined pattern. This is normally only used internally by the pyparsing module, but may be needed in some whitespace-sensitive grammars. F)rX)rrwrwrxleaveWhitespaceszParserElement.leaveWhitespacecCsd|_||_d|_|S)z8 Overrides the default whitespace chars TF)rXrYrZ)rrOrwrwrxsetWhitespaceCharssz ParserElement.setWhitespaceCharscCs d|_|S)z Overrides default behavior to expand C{}s to spaces before parsing the input string. Must be called before C{parseString} when the input grammar contains elements that match C{} characters. T)r\)rrwrwrx parseWithTabsszParserElement.parseWithTabscCsLt|trt|}t|tr4||jkrH|jj|n|jjt|j|S)a Define expression to be ignored (e.g., comments) while doing pattern matching; may be called repeatedly, to define multiple comment or other ignorable patterns. Example:: patt = OneOrMore(Word(alphas)) patt.parseString('ablaj /* comment */ lskjd') # -> ['ablaj'] patt.ignore(cStyleComment) patt.parseString('ablaj /* comment */ lskjd') # -> ['ablaj', 'lskjd'] )rzrr+r]rr)rrrwrwrxignores   zParserElement.ignorecCs"|pt|p t|ptf|_d|_|S)zT Enable display of debugging messages while doing pattern matching. T)r/r2r4rcr^)rZ startActionZ successActionZexceptionActionrwrwrxsetDebugActions s  zParserElement.setDebugActionscCs|r|jtttnd|_|S)a Enable display of debugging messages while doing pattern matching. Set C{flag} to True to enable, False to disable. Example:: wd = Word(alphas).setName("alphaword") integer = Word(nums).setName("numword") term = wd | integer # turn on debugging for wd wd.setDebug() OneOrMore(term).parseString("abc 123 xyz 890") prints:: Match alphaword at loc 0(1,1) Matched alphaword -> ['abc'] Match alphaword at loc 3(1,4) Exception raised:Expected alphaword (at char 4), (line:1, col:5) Match alphaword at loc 7(1,8) Matched alphaword -> ['xyz'] Match alphaword at loc 11(1,12) Exception raised:Expected alphaword (at char 12), (line:1, col:13) Match alphaword at loc 15(1,16) Exception raised:Expected alphaword (at char 15), (line:1, col:16) The output shown is that produced by the default debug actions - custom debug actions can be specified using L{setDebugActions}. Prior to attempting to match the C{wd} expression, the debugging message C{"Match at loc (,)"} is shown. Then if the parse succeeds, a C{"Matched"} message is shown, or an C{"Exception raised"} message is shown. Also note the use of L{setName} to assign a human-readable name to the expression, which makes debugging and exception messages easier to understand - for instance, the default name created for the C{Word} expression without calling C{setName} is C{"W:(ABCD...)"}. F)rr/r2r4r^)rflagrwrwrxsetDebugs#zParserElement.setDebugcCs|jS)N)r)rrwrwrxr@szParserElement.__str__cCst|S)N)r)rrwrwrxrCszParserElement.__repr__cCsd|_d|_|S)NT)r_rU)rrwrwrxrFszParserElement.streamlinecCsdS)Nrw)rrrwrwrxcheckRecursionKszParserElement.checkRecursioncCs|jgdS)zj Check defined expressions for valid structure, check for infinite recursive definitions. N)r)r validateTracerwrwrxvalidateNszParserElement.validatecCsy |j}Wn2tk r>t|d}|j}WdQRXYnXy |j||Stk r|}ztjrhn|WYdd}~XnXdS)z Execute the parse expression on the given file or filename. If a filename is specified (instead of a file object), the entire file is opened, read, and closed before parsing. rN)readropenrrr$r)rZfile_or_filenamerZ file_contentsfr3rwrwrx parseFileTs   zParserElement.parseFilecsHt|tr"||kp t|t|kSt|tr6|j|Stt||kSdS)N)rzr$varsrrsuper)rr)rHrwrx__eq__hs    zParserElement.__eq__cCs ||k S)Nrw)rrrwrwrx__ne__pszParserElement.__ne__cCs tt|S)N)hashid)rrwrwrx__hash__sszParserElement.__hash__cCs||kS)Nrw)rrrwrwrx__req__vszParserElement.__req__cCs ||k S)Nrw)rrrwrwrx__rne__yszParserElement.__rne__c Cs0y|jt||ddStk r*dSXdS)a Method for quick testing of a parser against a test string. Good for simple inline microtests of sub expressions while building up larger parser. Parameters: - testString - to test against this expression for a match - parseAll - (default=C{True}) - flag to pass to C{L{parseString}} when running tests Example:: expr = Word(nums) assert expr.matches("100") )rTFN)rrr)rZ testStringrrwrwrxr|s zParserElement.matches#cCst|tr"tttj|jj}t|tr4t|}g}g}d} x|D]} |dk rb|j | dsl|rx| rx|j | qH| s~qHdj || g} g}y:| j dd} |j | |d} | j | j|d| o| } Wntk rx} zt| trdnd }d| kr0| j t| j| | j d t| j| d d |n| j d | jd || j d t| | ob|} | } WYdd} ~ XnDtk r}z&| j dt|| o|} |} WYdd}~XnX|r|r| j d tdj | |j | | fqHW| |fS)a3 Execute the parse expression on a series of test strings, showing each test, the parsed results or where the parse failed. Quick and easy way to run a parse expression against a list of sample strings. Parameters: - tests - a list of separate test strings, or a multiline string of test strings - parseAll - (default=C{True}) - flag to pass to C{L{parseString}} when running tests - comment - (default=C{'#'}) - expression for indicating embedded comments in the test string; pass None to disable comment filtering - fullDump - (default=C{True}) - dump results as list followed by results names in nested outline; if False, only dump nested list - printResults - (default=C{True}) prints test output to stdout - failureTests - (default=C{False}) indicates if these tests are expected to fail parsing Returns: a (success, results) tuple, where success indicates that all tests succeeded (or failed if C{failureTests} is True), and the results contain a list of lines of each test's output Example:: number_expr = pyparsing_common.number.copy() result = number_expr.runTests(''' # unsigned integer 100 # negative integer -100 # float with scientific notation 6.02e23 # integer with scientific notation 1e-12 ''') print("Success" if result[0] else "Failed!") result = number_expr.runTests(''' # stray character 100Z # missing leading digit before '.' -.100 # too many '.' 3.14.159 ''', failureTests=True) print("Success" if result[0] else "Failed!") prints:: # unsigned integer 100 [100] # negative integer -100 [-100] # float with scientific notation 6.02e23 [6.02e+23] # integer with scientific notation 1e-12 [1e-12] Success # stray character 100Z ^ FAIL: Expected end of text (at char 3), (line:1, col:4) # missing leading digit before '.' -.100 ^ FAIL: Expected {real number with scientific notation | real number | signed integer} (at char 0), (line:1, col:1) # too many '.' 3.14.159 ^ FAIL: Expected end of text (at char 4), (line:1, col:5) Success Each test string must be on a single line. If you want to test a string that spans multiple lines, create a test like this:: expr.runTest(r"this is a test\n of strings that spans \n 3 lines") (Note that this is a raw string literal, you must include the leading 'r'.) TNFrz\n)r)r z(FATAL)r rr^zFAIL: zFAIL-EXCEPTION: )rzrrrvr{rrstrip splitlinesrrrrrrrrr!rGrr9rKr,)rZtestsrZcommentZfullDumpZ printResultsZ failureTestsZ allResultsZcommentssuccessrvr resultrrzr3rwrwrxrunTestssNW     $   zParserElement.runTests)F)F)T)T)TT)TT)r)F)N)T)F)T)TrTTF)OrrrrrNr staticmethodrPrRrrrirmrurrxr~rrrrrrrrrrrrrrrrrrtrrrr_MAX_INTrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr __classcell__rwrw)rHrxr$8s     &     H   " 2G+    D           )    cs eZdZdZfddZZS)r,zT Abstract C{ParserElement} subclass, for defining atomic matching patterns. cstt|jdddS)NF)rg)rr,r)r)rHrwrxr szToken.__init__)rrrrrrrwrw)rHrxr, scs eZdZdZfddZZS)r z, An empty token, will always match. cs$tt|jd|_d|_d|_dS)Nr TF)rr rrr[r`)r)rHrwrxr szEmpty.__init__)rrrrrrrwrw)rHrxr  scs*eZdZdZfddZdddZZS)rz( A token that will never match. cs*tt|jd|_d|_d|_d|_dS)NrTFzUnmatchable token)rrrrr[r`ra)r)rHrwrxr* s zNoMatch.__init__TcCst|||j|dS)N)rra)rr-rrorwrwrxr1 szNoMatch.parseImpl)T)rrrrrrrrwrw)rHrxr& s cs*eZdZdZfddZdddZZS)ra Token to exactly match a specified string. Example:: Literal('blah').parseString('blah') # -> ['blah'] Literal('blah').parseString('blahfooblah') # -> ['blah'] Literal('blah').parseString('bla') # -> Exception: Expected "blah" For case-insensitive matching, use L{CaselessLiteral}. For keyword matching (force word break before and after the matched string), use L{Keyword} or L{CaselessKeyword}. c stt|j||_t||_y|d|_Wn*tk rVtj dt ddt |_ YnXdt |j|_d|j|_d|_d|_dS)Nrz2null string passed to Literal; use Empty() insteadrq)rz"%s"z Expected F)rrrmatchrmatchLenfirstMatchCharrrrrr rHrrrar[r`)r matchString)rHrwrxrC s    zLiteral.__init__TcCsJ|||jkr6|jdks&|j|j|r6||j|jfSt|||j|dS)Nrr)rr startswithrrra)rr-rrorwrwrxrV szLiteral.parseImpl)T)rrrrrrrrwrw)rHrxr5 s  csLeZdZdZedZdfdd Zddd Zfd d Ze d d Z Z S)ra\ Token to exactly match a specified string as a keyword, that is, it must be immediately followed by a non-keyword character. Compare with C{L{Literal}}: - C{Literal("if")} will match the leading C{'if'} in C{'ifAndOnlyIf'}. - C{Keyword("if")} will not; it will only match the leading C{'if'} in C{'if x=1'}, or C{'if(y==2)'} Accepts two optional constructor arguments in addition to the keyword string: - C{identChars} is a string of characters that would be valid identifier characters, defaulting to all alphanumerics + "_" and "$" - C{caseless} allows case-insensitive matching, default is C{False}. Example:: Keyword("start").parseString("start") # -> ['start'] Keyword("start").parseString("starting") # -> Exception For case-insensitive matching, use L{CaselessKeyword}. z_$NFc stt|j|dkrtj}||_t||_y|d|_Wn$tk r^t j dt ddYnXd|j|_ d|j |_ d|_d|_||_|r|j|_|j}t||_dS)Nrz2null string passed to Keyword; use Empty() insteadrq)rz"%s"z Expected F)rrrDEFAULT_KEYWORD_CHARSrrrrrrrrrrar[r`caselessupper caselessmatchr identChars)rrrr)rHrwrxrq s&    zKeyword.__init__TcCs|jr|||||jj|jkr|t||jksL|||jj|jkr|dksj||dj|jkr||j|jfSnv|||jkr|jdks|j|j|r|t||jks|||j|jkr|dks||d|jkr||j|jfSt |||j |dS)Nrrr) rrrrrrrrrrra)rr-rrorwrwrxr s*&zKeyword.parseImplcstt|j}tj|_|S)N)rrrrr)rr)rHrwrxr sz Keyword.copycCs |t_dS)z,Overrides the default Keyword chars N)rr)rOrwrwrxsetDefaultKeywordChars szKeyword.setDefaultKeywordChars)NF)T) rrrrr3rrrrrrrrwrw)rHrxr^ s   cs*eZdZdZfddZdddZZS)ral Token to match a specified string, ignoring case of letters. Note: the matched results will always be in the case of the given match string, NOT the case of the input text. Example:: OneOrMore(CaselessLiteral("CMD")).parseString("cmd CMD Cmd10") # -> ['CMD', 'CMD', 'CMD'] (Contrast with example for L{CaselessKeyword}.) cs6tt|j|j||_d|j|_d|j|_dS)Nz'%s'z Expected )rrrr returnStringrra)rr)rHrwrxr s zCaselessLiteral.__init__TcCs@||||jj|jkr,||j|jfSt|||j|dS)N)rrrrrra)rr-rrorwrwrxr szCaselessLiteral.parseImpl)T)rrrrrrrrwrw)rHrxr s  cs,eZdZdZdfdd Zd ddZZS) rz Caseless version of L{Keyword}. Example:: OneOrMore(CaselessKeyword("CMD")).parseString("cmd CMD Cmd10") # -> ['CMD', 'CMD'] (Contrast with example for L{CaselessLiteral}.) Ncstt|j||dddS)NT)r)rrr)rrr)rHrwrxr szCaselessKeyword.__init__TcCsj||||jj|jkrV|t||jksF|||jj|jkrV||j|jfSt|||j|dS)N)rrrrrrrra)rr-rrorwrwrxr s*zCaselessKeyword.parseImpl)N)T)rrrrrrrrwrw)rHrxr scs,eZdZdZdfdd Zd ddZZS) rlax A variation on L{Literal} which matches "close" matches, that is, strings with at most 'n' mismatching characters. C{CloseMatch} takes parameters: - C{match_string} - string to be matched - C{maxMismatches} - (C{default=1}) maximum number of mismatches allowed to count as a match The results from a successful parse will contain the matched text from the input string and the following named results: - C{mismatches} - a list of the positions within the match_string where mismatches were found - C{original} - the original match_string used to compare against the input string If C{mismatches} is an empty list, then the match was an exact match. Example:: patt = CloseMatch("ATCATCGAATGGA") patt.parseString("ATCATCGAAXGGA") # -> (['ATCATCGAAXGGA'], {'mismatches': [[9]], 'original': ['ATCATCGAATGGA']}) patt.parseString("ATCAXCGAAXGGA") # -> Exception: Expected 'ATCATCGAATGGA' (with up to 1 mismatches) (at char 0), (line:1, col:1) # exact match patt.parseString("ATCATCGAATGGA") # -> (['ATCATCGAATGGA'], {'mismatches': [[]], 'original': ['ATCATCGAATGGA']}) # close match allowing up to 2 mismatches patt = CloseMatch("ATCATCGAATGGA", maxMismatches=2) patt.parseString("ATCAXCGAAXGGA") # -> (['ATCAXCGAAXGGA'], {'mismatches': [[4, 9]], 'original': ['ATCATCGAATGGA']}) rrcsBtt|j||_||_||_d|j|jf|_d|_d|_dS)Nz&Expected %r (with up to %d mismatches)F) rrlrr match_string maxMismatchesrar`r[)rrr)rHrwrxr szCloseMatch.__init__TcCs|}t|}|t|j}||kr|j}d}g} |j} xtt||||jD]0\}} | \} } | | krP| j|t| | krPPqPW|d}t|||g}|j|d<| |d<||fSt|||j|dS)NrrrZoriginal mismatches) rrrrrrr"rra)rr-rrostartrmaxlocrZmatch_stringlocrrZs_msrcmatresultsrwrwrxr s("   zCloseMatch.parseImpl)rr)T)rrrrrrrrwrw)rHrxrl s cs8eZdZdZd fdd Zdd d Zfd d ZZS)r/a Token for matching words composed of allowed character sets. Defined with string containing all allowed initial characters, an optional string containing allowed body characters (if omitted, defaults to the initial character set), and an optional minimum, maximum, and/or exact length. The default value for C{min} is 1 (a minimum value < 1 is not valid); the default values for C{max} and C{exact} are 0, meaning no maximum or exact length restriction. An optional C{excludeChars} parameter can list characters that might be found in the input C{bodyChars} string; useful to define a word of all printables except for one or two characters, for instance. L{srange} is useful for defining custom character set strings for defining C{Word} expressions, using range notation from regular expression character sets. A common mistake is to use C{Word} to match a specific literal string, as in C{Word("Address")}. Remember that C{Word} uses the string argument to define I{sets} of matchable characters. This expression would match "Add", "AAA", "dAred", or any other word made up of the characters 'A', 'd', 'r', 'e', and 's'. To match an exact literal string, use L{Literal} or L{Keyword}. pyparsing includes helper strings for building Words: - L{alphas} - L{nums} - L{alphanums} - L{hexnums} - L{alphas8bit} (alphabetic characters in ASCII range 128-255 - accented, tilded, umlauted, etc.) - L{punc8bit} (non-alphabetic characters in ASCII range 128-255 - currency, symbols, superscripts, diacriticals, etc.) - L{printables} (any non-whitespace character) Example:: # a word composed of digits integer = Word(nums) # equivalent to Word("0123456789") or Word(srange("0-9")) # a word with a leading capital, and zero or more lowercase capital_word = Word(alphas.upper(), alphas.lower()) # hostnames are alphanumeric, with leading alpha, and '-' hostname = Word(alphas, alphanums+'-') # roman numeral (not a strict parser, accepts invalid mix of characters) roman = Word("IVXLCDM") # any string of non-whitespace characters, except for ',' csv_value = Word(printables, excludeChars=",") NrrrFc stt|jrFdjfdd|D}|rFdjfdd|D}||_t||_|rl||_t||_n||_t||_|dk|_ |dkrt d||_ |dkr||_ nt |_ |dkr||_ ||_ t||_d|j|_d |_||_d |j|jkr|dkr|dkr|dkr|j|jkr8d t|j|_nHt|jdkrfd tj|jt|jf|_nd t|jt|jf|_|jrd|jd|_ytj|j|_Wntk rd|_YnXdS)Nrc3s|]}|kr|VqdS)Nrw)rr) excludeCharsrwrxr7 sz Word.__init__..c3s|]}|kr|VqdS)Nrw)rr)rrwrxr9 srrrzZcannot specify a minimum length < 1; use Optional(Word()) if zero-length word is permittedz Expected Frz[%s]+z%s[%s]*z [%s][%s]*z\b)rr/rr initCharsOrigr initChars bodyCharsOrig bodyChars maxSpecifiedrminLenmaxLenrrrrar` asKeyword_escapeRegexRangeCharsreStringrrdescapecompilerK)rrrminmaxexactrr)rH)rrxr4 sT      0 z Word.__init__Tc CsD|jr<|jj||}|s(t|||j||j}||jfS|||jkrZt|||j||}|d7}t|}|j}||j }t ||}x ||kr|||kr|d7}qWd} |||j krd} |j r||kr|||krd} |j r|dkr||d|ks||kr|||krd} | r4t|||j|||||fS)NrrFTr)rdrrraendgrouprrrrr rrr) rr-rrorrrZ bodycharsrZthrowExceptionrwrwrxrj s6    4zWord.parseImplc stytt|jStk r"YnX|jdkrndd}|j|jkr^d||j||jf|_nd||j|_|jS)NcSs$t|dkr|dddS|SdS)Nz...)r)rrwrwrx charsAsStr s z Word.__str__..charsAsStrz W:(%s,%s)zW:(%s))rr/rrKrUrr)rr)rHrwrxr s  z Word.__str__)NrrrrFN)T)rrrrrrrrrwrw)rHrxr/ s.6 #csFeZdZdZeejdZd fdd Zd ddZ fd d Z Z S) r'a Token for matching strings that match a given regular expression. Defined with string specifying the regular expression in a form recognized by the inbuilt Python re module. If the given regex contains named groups (defined using C{(?P...)}), these will be preserved as named parse results. Example:: realnum = Regex(r"[+-]?\d+\.\d*") date = Regex(r'(?P\d{4})-(?P\d\d?)-(?P\d\d?)') # ref: http://stackoverflow.com/questions/267399/how-do-you-match-only-valid-roman-numerals-with-a-regular-expression roman = Regex(r"M{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})") z[A-Z]rc stt|jt|tr|s,tjdtdd||_||_ yt j |j|j |_ |j|_ Wqt jk rtjd|tddYqXn2t|tjr||_ t||_|_ ||_ ntdt||_d|j|_d|_d|_d S) zThe parameters C{pattern} and C{flags} are passed to the C{re.compile()} function as-is. See the Python C{re} module for an explanation of the acceptable patterns and flags.z0null string passed to Regex; use Empty() insteadrq)rz$invalid pattern (%s) passed to RegexzCRegex may only be constructed with a string or a compiled RE objectz Expected FTN)rr'rrzrrrrpatternflagsrdr r sre_constantserrorcompiledREtyper{rrrrar`r[)rrr)rHrwrxr s.         zRegex.__init__TcCsd|jj||}|s"t|||j||j}|j}t|j}|r\x|D]}||||<qHW||fS)N)rdrrrar  groupdictr"r)rr-rrordrrrwrwrxr s  zRegex.parseImplc sDytt|jStk r"YnX|jdkr>dt|j|_|jS)NzRe:(%s))rr'rrKrUrr)r)rHrwrxr s z Regex.__str__)r)T) rrrrrrdr rrrrrrwrw)rHrxr' s  " cs8eZdZdZd fdd Zd ddZfd d ZZS) r%a Token for matching strings that are delimited by quoting characters. Defined with the following parameters: - quoteChar - string of one or more characters defining the quote delimiting string - escChar - character to escape quotes, typically backslash (default=C{None}) - escQuote - special quote sequence to escape an embedded quote string (such as SQL's "" to escape an embedded ") (default=C{None}) - multiline - boolean indicating whether quotes can span multiple lines (default=C{False}) - unquoteResults - boolean indicating whether the matched text should be unquoted (default=C{True}) - endQuoteChar - string of one or more characters defining the end of the quote delimited string (default=C{None} => same as quoteChar) - convertWhitespaceEscapes - convert escaped whitespace (C{'\t'}, C{'\n'}, etc.) to actual whitespace (default=C{True}) Example:: qs = QuotedString('"') print(qs.searchString('lsjdf "This is the quote" sldjf')) complex_qs = QuotedString('{{', endQuoteChar='}}') print(complex_qs.searchString('lsjdf {{This is the "quote"}} sldjf')) sql_qs = QuotedString('"', escQuote='""') print(sql_qs.searchString('lsjdf "This is the quote with ""embedded"" quotes" sldjf')) prints:: [['This is the quote']] [['This is the "quote"']] [['This is the quote with "embedded" quotes']] NFTc sNttj|j}|s0tjdtddt|dkr>|}n"|j}|s`tjdtddt|_t |_ |d_ |_ t |_ |_|_|_|_|rtjtjB_dtjjtj d|dk rt|pdf_n.)z|(?:%s)z|(?:%s.)z(.)z)*%sz$invalid pattern (%s) passed to Regexz Expected FTrs)%rr%rrrrr SyntaxError quoteCharr quoteCharLenfirstQuoteCharrendQuoteCharLenescCharescQuoteunquoteResultsconvertWhitespaceEscapesrd MULTILINEDOTALLrrrrrrescCharReplacePatternr rrrrrrar`r[)rrrr Z multiliner!rr")rH)rrxr sf       6     zQuotedString.__init__c Cs|||jkr|jj||pd}|s4t|||j||j}|j}|jr||j|j }t |t rd|kr|j rddddd}x |j D]\}}|j||}qW|jrtj|jd|}|jr|j|j|j}||fS)N\ r  )z\tz\nz\fz\rz\g<1>)rrdrrrar rr!rrrzrr"rrrrr%r r) rr-rrorrZws_mapZwslitZwscharrwrwrxrG s(  zQuotedString.parseImplc sFytt|jStk r"YnX|jdkr@d|j|jf|_|jS)Nz.quoted string, starting with %s ending with %s)rr%rrKrUrr)r)rHrwrxrj s zQuotedString.__str__)NNFTNT)T)rrrrrrrrrwrw)rHrxr% sA #cs8eZdZdZd fdd Zd ddZfd d ZZS) r a Token for matching words composed of characters I{not} in a given set (will include whitespace in matched characters if not listed in the provided exclusion set - see example). Defined with string containing all disallowed characters, and an optional minimum, maximum, and/or exact length. The default value for C{min} is 1 (a minimum value < 1 is not valid); the default values for C{max} and C{exact} are 0, meaning no maximum or exact length restriction. Example:: # define a comma-separated-value as anything that is not a ',' csv_value = CharsNotIn(',') print(delimitedList(csv_value).parseString("dkls,lsdkjf,s12 34,@!#,213")) prints:: ['dkls', 'lsdkjf', 's12 34', '@!#', '213'] rrrcstt|jd|_||_|dkr*td||_|dkr@||_nt|_|dkrZ||_||_t ||_ d|j |_ |jdk|_ d|_ dS)NFrrzfcannot specify a minimum length < 1; use Optional(CharsNotIn()) if zero-length char group is permittedrz Expected )rr rrXnotCharsrrrrrrrar[r`)rr*r r r )rHrwrxr s    zCharsNotIn.__init__TcCs|||jkrt|||j||}|d7}|j}t||jt|}x ||krd|||krd|d7}qFW|||jkrt|||j|||||fS)Nrr)r*rrar rrr)rr-rrorZnotcharsmaxlenrwrwrxr s   zCharsNotIn.parseImplc sdytt|jStk r"YnX|jdkr^t|jdkrRd|jdd|_n d|j|_|jS)Nrz !W:(%s...)z!W:(%s))rr rrKrUrr*)r)rHrwrxr s  zCharsNotIn.__str__)rrrr)T)rrrrrrrrrwrw)rHrxr v s cs<eZdZdZddddddZdfd d ZdddZZS)r.a Special matching class for matching whitespace. Normally, whitespace is ignored by pyparsing grammars. This class is included when some whitespace structures are significant. Define with a string containing the whitespace characters to be matched; default is C{" \t\r\n"}. Also takes optional C{min}, C{max}, and C{exact} arguments, as defined for the C{L{Word}} class. zzzzz)rr'rr)r( rrrcsttj|_jdjfddjDdjddjD_d_dj_ |_ |dkrt|_ nt _ |dkr|_ |_ dS)Nrc3s|]}|jkr|VqdS)N) matchWhite)rr)rrwrxr sz!White.__init__..css|]}tj|VqdS)N)r. whiteStrs)rrrwrwrxr sTz Expected r) rr.rr-rrrYrr[rarrr)rZwsr r r )rH)rrxr s  zWhite.__init__TcCs|||jkrt|||j||}|d7}||j}t|t|}x"||krd|||jkrd|d7}qDW|||jkrt|||j|||||fS)Nrr)r-rrarr rr)rr-rrorrrwrwrxr s  zWhite.parseImpl)r,rrrr)T)rrrrr.rrrrwrw)rHrxr. scseZdZfddZZS)_PositionTokencs(tt|j|jj|_d|_d|_dS)NTF)rr/rrHrrr[r`)r)rHrwrxr s z_PositionToken.__init__)rrrrrrwrw)rHrxr/ sr/cs2eZdZdZfddZddZd ddZZS) rzb Token to advance to a specific column of input text; useful for tabular report scraping. cstt|j||_dS)N)rrrr9)rcolno)rHrwrxr szGoToColumn.__init__cCs`t|||jkr\t|}|jr*|j||}x0||krZ||jrZt|||jkrZ|d7}q,W|S)Nrr)r9rr]risspace)rr-rrrwrwrxr s & zGoToColumn.preParseTcCsDt||}||jkr"t||d|||j|}|||}||fS)NzText not in expected column)r9r)rr-rroZthiscolZnewlocrrwrwrxr s    zGoToColumn.parseImpl)T)rrrrrrrrrwrw)rHrxr s  cs*eZdZdZfddZdddZZS)ra Matches if current position is at the beginning of a line within the parse string Example:: test = ''' AAA this line AAA and this line AAA but not this one B AAA and definitely not this one ''' for t in (LineStart() + 'AAA' + restOfLine).searchString(test): print(t) Prints:: ['AAA', ' this line'] ['AAA', ' and this line'] cstt|jd|_dS)NzExpected start of line)rrrra)r)rHrwrxr& szLineStart.__init__TcCs*t||dkr|gfSt|||j|dS)Nrr)r9rra)rr-rrorwrwrxr* szLineStart.parseImpl)T)rrrrrrrrwrw)rHrxr s cs*eZdZdZfddZdddZZS)rzU Matches if current position is at the end of a line within the parse string cs,tt|j|jtjjddd|_dS)NrrzExpected end of line)rrrrr$rNrra)r)rHrwrxr3 szLineEnd.__init__TcCsb|t|kr6||dkr$|ddfSt|||j|n(|t|krN|dgfSt|||j|dS)Nrrr)rrra)rr-rrorwrwrxr8 s     zLineEnd.parseImpl)T)rrrrrrrrwrw)rHrxr/ s cs*eZdZdZfddZdddZZS)r*zM Matches if current position is at the beginning of the parse string cstt|jd|_dS)NzExpected start of text)rr*rra)r)rHrwrxrG szStringStart.__init__TcCs0|dkr(||j|dkr(t|||j||gfS)Nr)rrra)rr-rrorwrwrxrK szStringStart.parseImpl)T)rrrrrrrrwrw)rHrxr*C s cs*eZdZdZfddZdddZZS)r)zG Matches if current position is at the end of the parse string cstt|jd|_dS)NzExpected end of text)rr)rra)r)rHrwrxrV szStringEnd.__init__TcCs^|t|krt|||j|n<|t|kr6|dgfS|t|krJ|gfSt|||j|dS)Nrr)rrra)rr-rrorwrwrxrZ s    zStringEnd.parseImpl)T)rrrrrrrrwrw)rHrxr)R s cs.eZdZdZeffdd ZdddZZS)r1ap Matches if the current position is at the beginning of a Word, and is not preceded by any character in a given set of C{wordChars} (default=C{printables}). To emulate the C{} behavior of regular expressions, use C{WordStart(alphanums)}. C{WordStart} will also match at the beginning of the string being parsed, or at the beginning of a line. cs"tt|jt||_d|_dS)NzNot at the start of a word)rr1rr wordCharsra)rr2)rHrwrxrl s zWordStart.__init__TcCs@|dkr8||d|jks(|||jkr8t|||j||gfS)Nrrr)r2rra)rr-rrorwrwrxrq s zWordStart.parseImpl)T)rrrrrVrrrrwrw)rHrxr1d scs.eZdZdZeffdd ZdddZZS)r0aZ Matches if the current position is at the end of a Word, and is not followed by any character in a given set of C{wordChars} (default=C{printables}). To emulate the C{} behavior of regular expressions, use C{WordEnd(alphanums)}. C{WordEnd} will also match at the end of the string being parsed, or at the end of a line. cs(tt|jt||_d|_d|_dS)NFzNot at the end of a word)rr0rrr2rXra)rr2)rHrwrxr s zWordEnd.__init__TcCsPt|}|dkrH||krH|||jks8||d|jkrHt|||j||gfS)Nrrr)rr2rra)rr-rrorrwrwrxr s zWordEnd.parseImpl)T)rrrrrVrrrrwrw)rHrxr0x scseZdZdZdfdd ZddZddZd d Zfd d Zfd dZ fddZ dfdd Z gfddZ fddZ ZS)r z^ Abstract subclass of ParserElement, for combining and post-processing parsed tokens. Fc stt|j|t|tr"t|}t|tr.F)rr rrzrrrr$rQexprsrIterableallrvrre)rr3rg)rHrwrxr s     zParseExpression.__init__cCs |j|S)N)r3)rrrwrwrxr szParseExpression.__getitem__cCs|jj|d|_|S)N)r3rrU)rrrwrwrxr s zParseExpression.appendcCs4d|_dd|jD|_x|jD] }|jq W|S)z~Extends C{leaveWhitespace} defined in base class, and also invokes C{leaveWhitespace} on all contained expressions.FcSsg|] }|jqSrw)r)rrrwrwrxr sz3ParseExpression.leaveWhitespace..)rXr3r)rrrwrwrxr s   zParseExpression.leaveWhitespacecszt|trF||jkrvtt|j|xP|jD]}|j|jdq,Wn0tt|j|x|jD]}|j|jdq^W|S)Nrrrsrs)rzr+r]rr rr3)rrr)rHrwrxr s    zParseExpression.ignorec sLytt|jStk r"YnX|jdkrFd|jjt|jf|_|jS)Nz%s:(%s)) rr rrKrUrHrrr3)r)rHrwrxr s zParseExpression.__str__cs0tt|jx|jD] }|jqWt|jdkr|jd}t||jr|j r|jdkr|j r|jdd|jdg|_d|_ |j |j O_ |j |j O_ |jd}t||jo|j o|jdko|j r|jdd|jdd|_d|_ |j |j O_ |j |j O_ dt ||_|S)Nrqrrrz Expected rsrs)rr rr3rrzrHrSrVr^rUr[r`rra)rrr)rHrwrxr s0         zParseExpression.streamlinecstt|j||}|S)N)rr rm)rrrlr)rHrwrxrm szParseExpression.setResultsNamecCs:|dd|g}x|jD]}|j|qW|jgdS)N)r3rr)rrtmprrwrwrxr s zParseExpression.validatecs$tt|j}dd|jD|_|S)NcSsg|] }|jqSrw)r)rrrwrwrxr sz(ParseExpression.copy..)rr rr3)rr)rHrwrxr szParseExpression.copy)F)F)rrrrrrrrrrrrmrrrrwrw)rHrxr s " csTeZdZdZGdddeZdfdd ZdddZd d Zd d Z d dZ Z S)ra  Requires all given C{ParseExpression}s to be found in the given order. Expressions may be separated by whitespace. May be constructed using the C{'+'} operator. May also be constructed using the C{'-'} operator, which will suppress backtracking. Example:: integer = Word(nums) name_expr = OneOrMore(Word(alphas)) expr = And([integer("id"),name_expr("name"),integer("age")]) # more easily written as: expr = integer("id") + name_expr("name") + integer("age") cseZdZfddZZS)zAnd._ErrorStopcs&ttj|j||d|_|jdS)N-)rrrrrr)rrr)rHrwrxr szAnd._ErrorStop.__init__)rrrrrrwrw)rHrxr srTcsRtt|j||tdd|jD|_|j|jdj|jdj|_d|_ dS)Ncss|] }|jVqdS)N)r[)rrrwrwrxr szAnd.__init__..rT) rrrr5r3r[rrYrXre)rr3rg)rHrwrxr s z And.__init__c Cs|jdj|||dd\}}d}x|jddD]}t|tjrFd}q0|ry|j|||\}}Wqtk rvYqtk r}zd|_tj|WYdd}~Xqt k rt|t ||j |YqXn|j|||\}}|s|j r0||7}q0W||fS)NrF)rprrT) r3rtrzrrr#r __traceback__rrrrar) rr-rro resultlistZ errorStoprZ exprtokensrrwrwrxr s(   z And.parseImplcCst|trtj|}|j|S)N)rzrr$rQr)rrrwrwrxr5 s  z And.__iadd__cCs8|dd|g}x |jD]}|j||jsPqWdS)N)r3rr[)rrsubRecCheckListrrwrwrxr: s   zAnd.checkRecursioncCs@t|dr|jS|jdkr:ddjdd|jDd|_|jS)Nr{rcss|]}t|VqdS)N)r)rrrwrwrxrF szAnd.__str__..})rrrUrr3)rrwrwrxrA s    z And.__str__)T)T) rrrrr rrrrrrrrwrw)rHrxr s csDeZdZdZdfdd ZdddZdd Zd d Zd d ZZ S)ra Requires that at least one C{ParseExpression} is found. If two expressions match, the expression that matches the longest string will be used. May be constructed using the C{'^'} operator. Example:: # construct Or using '^' operator number = Word(nums) ^ Combine(Word(nums) + '.' + Word(nums)) print(number.searchString("123 3.1416 789")) prints:: [['123'], ['3.1416'], ['789']] Fcs:tt|j|||jr0tdd|jD|_nd|_dS)Ncss|] }|jVqdS)N)r[)rrrwrwrxr\ szOr.__init__..T)rrrr3rr[)rr3rg)rHrwrxrY sz Or.__init__Tc CsTd}d}g}x|jD]}y|j||}Wnvtk rd} z d| _| j|krT| }| j}WYdd} ~ Xqtk rt||krt|t||j|}t|}YqX|j||fqW|r*|j dddx`|D]X\} }y|j |||Stk r$} z"d| _| j|kr| }| j}WYdd} ~ XqXqW|dk rB|j|_ |nt||d|dS)NrrcSs |d S)Nrrw)xrwrwrxryu szOr.parseImpl..)rz no defined alternatives to matchrs) r3rrr8rrrrarsortrtr) rr-rro maxExcLoc maxExceptionrrZloc2r_rwrwrxr` s<     z Or.parseImplcCst|trtj|}|j|S)N)rzrr$rQr)rrrwrwrx__ixor__ s  z Or.__ixor__cCs@t|dr|jS|jdkr:ddjdd|jDd|_|jS)Nrr;z ^ css|]}t|VqdS)N)r)rrrwrwrxr szOr.__str__..r<)rrrUrr3)rrwrwrxr s    z Or.__str__cCs0|dd|g}x|jD]}|j|qWdS)N)r3r)rrr:rrwrwrxr s zOr.checkRecursion)F)T) rrrrrrrBrrrrwrw)rHrxrK s   & csDeZdZdZdfdd ZdddZdd Zd d Zd d ZZ S)ra Requires that at least one C{ParseExpression} is found. If two expressions match, the first one listed is the one that will match. May be constructed using the C{'|'} operator. Example:: # construct MatchFirst using '|' operator # watch the order of expressions to match number = Word(nums) | Combine(Word(nums) + '.' + Word(nums)) print(number.searchString("123 3.1416 789")) # Fail! -> [['123'], ['3'], ['1416'], ['789']] # put more selective expression first number = Combine(Word(nums) + '.' + Word(nums)) | Word(nums) print(number.searchString("123 3.1416 789")) # Better -> [['123'], ['3.1416'], ['789']] Fcs:tt|j|||jr0tdd|jD|_nd|_dS)Ncss|] }|jVqdS)N)r[)rrrwrwrxr sz&MatchFirst.__init__..T)rrrr3rr[)rr3rg)rHrwrxr szMatchFirst.__init__Tc Csd}d}x|jD]}y|j|||}|Stk r\}z|j|krL|}|j}WYdd}~Xqtk rt||krt|t||j|}t|}YqXqW|dk r|j|_|nt||d|dS)Nrrz no defined alternatives to matchrs)r3rtrrrrrar) rr-rror?r@rrrrwrwrxr s$   zMatchFirst.parseImplcCst|trtj|}|j|S)N)rzrr$rQr)rrrwrwrx__ior__ s  zMatchFirst.__ior__cCs@t|dr|jS|jdkr:ddjdd|jDd|_|jS)Nrr;z | css|]}t|VqdS)N)r)rrrwrwrxr sz%MatchFirst.__str__..r<)rrrUrr3)rrwrwrxr s    zMatchFirst.__str__cCs0|dd|g}x|jD]}|j|qWdS)N)r3r)rrr:rrwrwrxr s zMatchFirst.checkRecursion)F)T) rrrrrrrCrrrrwrw)rHrxr s   cs<eZdZdZd fdd Zd ddZddZd d ZZS) r am Requires all given C{ParseExpression}s to be found, but in any order. Expressions may be separated by whitespace. May be constructed using the C{'&'} operator. Example:: color = oneOf("RED ORANGE YELLOW GREEN BLUE PURPLE BLACK WHITE BROWN") shape_type = oneOf("SQUARE CIRCLE TRIANGLE STAR HEXAGON OCTAGON") integer = Word(nums) shape_attr = "shape:" + shape_type("shape") posn_attr = "posn:" + Group(integer("x") + ',' + integer("y"))("posn") color_attr = "color:" + color("color") size_attr = "size:" + integer("size") # use Each (using operator '&') to accept attributes in any order # (shape and posn are required, color and size are optional) shape_spec = shape_attr & posn_attr & Optional(color_attr) & Optional(size_attr) shape_spec.runTests(''' shape: SQUARE color: BLACK posn: 100, 120 shape: CIRCLE size: 50 color: BLUE posn: 50,80 color:GREEN size:20 shape:TRIANGLE posn:20,40 ''' ) prints:: shape: SQUARE color: BLACK posn: 100, 120 ['shape:', 'SQUARE', 'color:', 'BLACK', 'posn:', ['100', ',', '120']] - color: BLACK - posn: ['100', ',', '120'] - x: 100 - y: 120 - shape: SQUARE shape: CIRCLE size: 50 color: BLUE posn: 50,80 ['shape:', 'CIRCLE', 'size:', '50', 'color:', 'BLUE', 'posn:', ['50', ',', '80']] - color: BLUE - posn: ['50', ',', '80'] - x: 50 - y: 80 - shape: CIRCLE - size: 50 color: GREEN size: 20 shape: TRIANGLE posn: 20,40 ['color:', 'GREEN', 'size:', '20', 'shape:', 'TRIANGLE', 'posn:', ['20', ',', '40']] - color: GREEN - posn: ['20', ',', '40'] - x: 20 - y: 40 - shape: TRIANGLE - size: 20 Tcs8tt|j||tdd|jD|_d|_d|_dS)Ncss|] }|jVqdS)N)r[)rrrwrwrxrsz Each.__init__..T)rr rr5r3r[rXinitExprGroups)rr3rg)rHrwrxrsz Each.__init__c s|jrtdd|jD|_dd|jD}dd|jD}|||_dd|jD|_dd|jD|_dd|jD|_|j|j7_d |_|}|jdd}|jddg}d } x| rp||j|j} g} x~| D]v} y| j||}Wn t k r| j | YqX|j |jj t | | | |krD|j | q| krj | qWt| t| krd } qW|rd jd d|D} t ||d | |fdd|jD7}g}x*|D]"} | j|||\}}|j |qWt|tg}||fS)Ncss&|]}t|trt|j|fVqdS)N)rzrrr.)rrrwrwrxrsz!Each.parseImpl..cSsg|]}t|tr|jqSrw)rzrr.)rrrwrwrxrsz"Each.parseImpl..cSs"g|]}|jrt|t r|qSrw)r[rzr)rrrwrwrxrscSsg|]}t|tr|jqSrw)rzr2r.)rrrwrwrxr scSsg|]}t|tr|jqSrw)rzrr.)rrrwrwrxr!scSs g|]}t|tttfs|qSrw)rzrr2r)rrrwrwrxr"sFTz, css|]}t|VqdS)N)r)rrrwrwrxr=sz*Missing one or more required elements (%s)cs$g|]}t|tr|jkr|qSrw)rzrr.)rr)tmpOptrwrxrAs)rDrr3Zopt1mapZ optionalsZmultioptionalsZ multirequiredZrequiredrrrrrremoverrrtsumr")rr-rroZopt1Zopt2ZtmpLocZtmpReqdZ matchOrderZ keepMatchingZtmpExprsZfailedrZmissingr9rZ finalResultsrw)rErxrsP     zEach.parseImplcCs@t|dr|jS|jdkr:ddjdd|jDd|_|jS)Nrr;z & css|]}t|VqdS)N)r)rrrwrwrxrPszEach.__str__..r<)rrrUrr3)rrwrwrxrKs    z Each.__str__cCs0|dd|g}x|jD]}|j|qWdS)N)r3r)rrr:rrwrwrxrTs zEach.checkRecursion)T)T) rrrrrrrrrrwrw)rHrxr s 5 1 csleZdZdZdfdd ZdddZdd Zfd d Zfd d ZddZ gfddZ fddZ Z S)rza Abstract subclass of C{ParserElement}, for combining and post-processing parsed tokens. Fcstt|j|t|tr@ttjtr2tj|}ntjt |}||_ d|_ |dk r|j |_ |j |_ |j|j|j|_|j|_|j|_|jj|jdS)N)rrrrzr issubclassr$rQr,rr.rUr`r[rrYrXrWrer]r)rr.rg)rHrwrxr^s    zParseElementEnhance.__init__TcCs2|jdk r|jj|||ddStd||j|dS)NF)rpr)r.rtrra)rr-rrorwrwrxrps zParseElementEnhance.parseImplcCs*d|_|jj|_|jdk r&|jj|S)NF)rXr.rr)rrwrwrxrvs    z#ParseElementEnhance.leaveWhitespacecsrt|trB||jkrntt|j||jdk rn|jj|jdn,tt|j||jdk rn|jj|jd|S)Nrrrsrs)rzr+r]rrrr.)rr)rHrwrxr}s    zParseElementEnhance.ignorecs&tt|j|jdk r"|jj|S)N)rrrr.)r)rHrwrxrs  zParseElementEnhance.streamlinecCsB||krt||g|dd|g}|jdk r>|jj|dS)N)r&r.r)rrr:rwrwrxrs  z"ParseElementEnhance.checkRecursioncCs6|dd|g}|jdk r(|jj||jgdS)N)r.rr)rrr6rwrwrxrs  zParseElementEnhance.validatec sVytt|jStk r"YnX|jdkrP|jdk rPd|jjt|jf|_|jS)Nz%s:(%s)) rrrrKrUr.rHrr)r)rHrwrxrszParseElementEnhance.__str__)F)T) rrrrrrrrrrrrrrwrw)rHrxrZs   cs*eZdZdZfddZdddZZS)ra Lookahead matching of the given parse expression. C{FollowedBy} does I{not} advance the parsing position within the input string, it only verifies that the specified parse expression matches at the current position. C{FollowedBy} always returns a null token list. Example:: # use FollowedBy to match a label only if it is followed by a ':' data_word = Word(alphas) label = data_word + FollowedBy(':') attr_expr = Group(label + Suppress(':') + OneOrMore(data_word, stopOn=label).setParseAction(' '.join)) OneOrMore(attr_expr).parseString("shape: SQUARE color: BLACK posn: upper left").pprint() prints:: [['shape', 'SQUARE'], ['color', 'BLACK'], ['posn', 'upper left']] cstt|j|d|_dS)NT)rrrr[)rr.)rHrwrxrszFollowedBy.__init__TcCs|jj|||gfS)N)r.r)rr-rrorwrwrxrszFollowedBy.parseImpl)T)rrrrrrrrwrw)rHrxrs cs2eZdZdZfddZd ddZddZZS) ra Lookahead to disallow matching with the given parse expression. C{NotAny} does I{not} advance the parsing position within the input string, it only verifies that the specified parse expression does I{not} match at the current position. Also, C{NotAny} does I{not} skip over leading whitespace. C{NotAny} always returns a null token list. May be constructed using the '~' operator. Example:: cs0tt|j|d|_d|_dt|j|_dS)NFTzFound unwanted token, )rrrrXr[rr.ra)rr.)rHrwrxrszNotAny.__init__TcCs&|jj||rt|||j||gfS)N)r.rrra)rr-rrorwrwrxrszNotAny.parseImplcCs4t|dr|jS|jdkr.dt|jd|_|jS)Nrz~{r<)rrrUrr.)rrwrwrxrs   zNotAny.__str__)T)rrrrrrrrrwrw)rHrxrs   cs(eZdZdfdd ZdddZZS) _MultipleMatchNcsFtt|j|d|_|}t|tr.tj|}|dk r<|nd|_dS)NT) rrIrrWrzrr$rQ not_ender)rr.stopOnZender)rHrwrxrs   z_MultipleMatch.__init__Tc Cs|jj}|j}|jdk }|r$|jj}|r2|||||||dd\}}yZ|j } xJ|rb|||| rr|||} n|} ||| |\}} | s| jrT|| 7}qTWWnttfk rYnX||fS)NF)rp) r.rtrrJrr]rrr) rr-rroZself_expr_parseZself_skip_ignorablesZ check_enderZ try_not_enderrZhasIgnoreExprsrZ tmptokensrwrwrxrs,      z_MultipleMatch.parseImpl)N)T)rrrrrrrwrw)rHrxrIsrIc@seZdZdZddZdS)ra Repetition of one or more of the given expression. Parameters: - expr - expression that must match one or more times - stopOn - (default=C{None}) - expression for a terminating sentinel (only required if the sentinel would ordinarily match the repetition expression) Example:: data_word = Word(alphas) label = data_word + FollowedBy(':') attr_expr = Group(label + Suppress(':') + OneOrMore(data_word).setParseAction(' '.join)) text = "shape: SQUARE posn: upper left color: BLACK" OneOrMore(attr_expr).parseString(text).pprint() # Fail! read 'color' as data instead of next label -> [['shape', 'SQUARE color']] # use stopOn attribute for OneOrMore to avoid reading label string as part of the data attr_expr = Group(label + Suppress(':') + OneOrMore(data_word, stopOn=label).setParseAction(' '.join)) OneOrMore(attr_expr).parseString(text).pprint() # Better -> [['shape', 'SQUARE'], ['posn', 'upper left'], ['color', 'BLACK']] # could also be written as (attr_expr * (1,)).parseString(text).pprint() cCs4t|dr|jS|jdkr.dt|jd|_|jS)Nrr;z}...)rrrUrr.)rrwrwrxr!s   zOneOrMore.__str__N)rrrrrrwrwrwrxrscs8eZdZdZd fdd Zd fdd Zdd ZZS) r2aw Optional repetition of zero or more of the given expression. Parameters: - expr - expression that must match zero or more times - stopOn - (default=C{None}) - expression for a terminating sentinel (only required if the sentinel would ordinarily match the repetition expression) Example: similar to L{OneOrMore} Ncstt|j||dd|_dS)N)rKT)rr2rr[)rr.rK)rHrwrxr6szZeroOrMore.__init__Tc s6ytt|j|||Sttfk r0|gfSXdS)N)rr2rrr)rr-rro)rHrwrxr:szZeroOrMore.parseImplcCs4t|dr|jS|jdkr.dt|jd|_|jS)Nrrz]...)rrrUrr.)rrwrwrxr@s   zZeroOrMore.__str__)N)T)rrrrrrrrrwrw)rHrxr2*s c@s eZdZddZeZddZdS) _NullTokencCsdS)NFrw)rrwrwrxrJsz_NullToken.__bool__cCsdS)Nrrw)rrwrwrxrMsz_NullToken.__str__N)rrrrr'rrwrwrwrxrLIsrLcs6eZdZdZeffdd Zd ddZddZZS) raa Optional matching of the given expression. Parameters: - expr - expression that must match zero or more times - default (optional) - value to be returned if the optional expression is not found. Example:: # US postal code can be a 5-digit zip, plus optional 4-digit qualifier zip = Combine(Word(nums, exact=5) + Optional('-' + Word(nums, exact=4))) zip.runTests(''' # traditional ZIP code 12345 # ZIP+4 form 12101-0001 # invalid ZIP 98765- ''') prints:: # traditional ZIP code 12345 ['12345'] # ZIP+4 form 12101-0001 ['12101-0001'] # invalid ZIP 98765- ^ FAIL: Expected end of text (at char 5), (line:1, col:6) cs.tt|j|dd|jj|_||_d|_dS)NF)rgT)rrrr.rWrr[)rr.r)rHrwrxrts zOptional.__init__Tc Cszy|jj|||dd\}}WnTttfk rp|jtk rh|jjr^t|jg}|j||jj<ql|jg}ng}YnX||fS)NF)rp)r.rtrrr_optionalNotMatchedrVr")rr-rrorrwrwrxrzs    zOptional.parseImplcCs4t|dr|jS|jdkr.dt|jd|_|jS)Nrrr )rrrUrr.)rrwrwrxrs   zOptional.__str__)T) rrrrrMrrrrrwrw)rHrxrQs" cs,eZdZdZd fdd Zd ddZZS) r(a Token for skipping over all undefined text until the matched expression is found. Parameters: - expr - target expression marking the end of the data to be skipped - include - (default=C{False}) if True, the target expression is also parsed (the skipped text and target expression are returned as a 2-element list). - ignore - (default=C{None}) used to define grammars (typically quoted strings and comments) that might contain false matches to the target expression - failOn - (default=C{None}) define expressions that are not allowed to be included in the skipped test; if found before the target expression is found, the SkipTo is not a match Example:: report = ''' Outstanding Issues Report - 1 Jan 2000 # | Severity | Description | Days Open -----+----------+-------------------------------------------+----------- 101 | Critical | Intermittent system crash | 6 94 | Cosmetic | Spelling error on Login ('log|n') | 14 79 | Minor | System slow when running too many reports | 47 ''' integer = Word(nums) SEP = Suppress('|') # use SkipTo to simply match everything up until the next SEP # - ignore quoted strings, so that a '|' character inside a quoted string does not match # - parse action will call token.strip() for each matched token, i.e., the description body string_data = SkipTo(SEP, ignore=quotedString) string_data.setParseAction(tokenMap(str.strip)) ticket_expr = (integer("issue_num") + SEP + string_data("sev") + SEP + string_data("desc") + SEP + integer("days_open")) for tkt in ticket_expr.searchString(report): print tkt.dump() prints:: ['101', 'Critical', 'Intermittent system crash', '6'] - days_open: 6 - desc: Intermittent system crash - issue_num: 101 - sev: Critical ['94', 'Cosmetic', "Spelling error on Login ('log|n')", '14'] - days_open: 14 - desc: Spelling error on Login ('log|n') - issue_num: 94 - sev: Cosmetic ['79', 'Minor', 'System slow when running too many reports', '47'] - days_open: 47 - desc: System slow when running too many reports - issue_num: 79 - sev: Minor FNcs`tt|j|||_d|_d|_||_d|_t|t rFt j ||_ n||_ dt |j|_dS)NTFzNo match found for )rr(r ignoreExprr[r` includeMatchrrzrr$rQfailOnrr.ra)rrincluderrP)rHrwrxrs zSkipTo.__init__Tc Cs,|}t|}|j}|jj}|jdk r,|jjnd}|jdk rB|jjnd} |} x| |kr|dk rh||| rhP| dk rx*y| || } Wqrtk rPYqrXqrWy||| dddWn tt fk r| d7} YqLXPqLWt|||j || }|||} t | } |j r$||||dd\}} | | 7} || fS)NF)rorprr)rp) rr.rtrPrrNrrrrrar"rO)rr-rror0rr.Z expr_parseZself_failOn_canParseNextZself_ignoreExpr_tryParseZtmplocZskiptextZ skipresultrrwrwrxrs<    zSkipTo.parseImpl)FNN)T)rrrrrrrrwrw)rHrxr(s6 csbeZdZdZdfdd ZddZddZd d Zd d Zgfd dZ ddZ fddZ Z S)raK Forward declaration of an expression to be defined later - used for recursive grammars, such as algebraic infix notation. When the expression is known, it is assigned to the C{Forward} variable using the '<<' operator. Note: take care when assigning to C{Forward} not to overlook precedence of operators. Specifically, '|' has a lower precedence than '<<', so that:: fwdExpr << a | b | c will actually be evaluated as:: (fwdExpr << a) | b | c thereby leaving b and c out as parseable alternatives. It is recommended that you explicitly group the values inserted into the C{Forward}:: fwdExpr << (a | b | c) Converting to use the '<<=' operator instead will avoid this problem. See L{ParseResults.pprint} for an example of a recursive parser created using C{Forward}. Ncstt|j|dddS)NF)rg)rrr)rr)rHrwrxrszForward.__init__cCsjt|trtj|}||_d|_|jj|_|jj|_|j|jj |jj |_ |jj |_ |j j |jj |S)N)rzrr$rQr.rUr`r[rrYrXrWr]r)rrrwrwrx __lshift__s      zForward.__lshift__cCs||>S)Nrw)rrrwrwrx __ilshift__'szForward.__ilshift__cCs d|_|S)NF)rX)rrwrwrxr*szForward.leaveWhitespacecCs$|js d|_|jdk r |jj|S)NT)r_r.r)rrwrwrxr.s   zForward.streamlinecCs>||kr0|dd|g}|jdk r0|jj||jgdS)N)r.rr)rrr6rwrwrxr5s   zForward.validatec Cs>t|dr|jS|jjdSd}Wd|j|_X|jjd|S)Nrz: ...Nonez: )rrrHrZ _revertClass_ForwardNoRecurser.r)rZ retStringrwrwrxr<s   zForward.__str__cs.|jdk rtt|jSt}||K}|SdS)N)r.rrr)rr)rHrwrxrMs  z Forward.copy)N) rrrrrrRrSrrrrrrrwrw)rHrxrs  c@seZdZddZdS)rUcCsdS)Nz...rw)rrwrwrxrVsz_ForwardNoRecurse.__str__N)rrrrrwrwrwrxrUUsrUcs"eZdZdZdfdd ZZS)r-zQ Abstract subclass of C{ParseExpression}, for converting parsed results. Fcstt|j|d|_dS)NF)rr-rrW)rr.rg)rHrwrxr]szTokenConverter.__init__)F)rrrrrrrwrw)rHrxr-Yscs6eZdZdZd fdd ZfddZdd ZZS) r a Converter to concatenate all matching tokens to a single string. By default, the matching patterns must also be contiguous in the input string; this can be disabled by specifying C{'adjacent=False'} in the constructor. Example:: real = Word(nums) + '.' + Word(nums) print(real.parseString('3.1416')) # -> ['3', '.', '1416'] # will also erroneously match the following print(real.parseString('3. 1416')) # -> ['3', '.', '1416'] real = Combine(Word(nums) + '.' + Word(nums)) print(real.parseString('3.1416')) # -> ['3.1416'] # no match when there are internal spaces print(real.parseString('3. 1416')) # -> Exception: Expected W:(0123...) rTcs8tt|j||r|j||_d|_||_d|_dS)NT)rr rradjacentrX joinStringre)rr.rWrV)rHrwrxrrszCombine.__init__cs(|jrtj||ntt|j||S)N)rVr$rrr )rr)rHrwrxr|szCombine.ignorecCsP|j}|dd=|tdj|j|jg|jd7}|jrH|jrH|gS|SdS)Nr)r)rr"rr rWrbrVr)rr-rrZretToksrwrwrxrs  "zCombine.postParse)rT)rrrrrrrrrwrw)rHrxr as cs(eZdZdZfddZddZZS)ra Converter to return the matched tokens as a list - useful for returning tokens of C{L{ZeroOrMore}} and C{L{OneOrMore}} expressions. Example:: ident = Word(alphas) num = Word(nums) term = ident | num func = ident + Optional(delimitedList(term)) print(func.parseString("fn a,b,100")) # -> ['fn', 'a', 'b', '100'] func = ident + Group(Optional(delimitedList(term))) print(func.parseString("fn a,b,100")) # -> ['fn', ['a', 'b', '100']] cstt|j|d|_dS)NT)rrrrW)rr.)rHrwrxrszGroup.__init__cCs|gS)Nrw)rr-rrrwrwrxrszGroup.postParse)rrrrrrrrwrw)rHrxrs  cs(eZdZdZfddZddZZS)r aW Converter to return a repetitive expression as a list, but also as a dictionary. Each element can also be referenced using the first token in the expression as its key. Useful for tabular report scraping when the first column can be used as a item key. Example:: data_word = Word(alphas) label = data_word + FollowedBy(':') attr_expr = Group(label + Suppress(':') + OneOrMore(data_word).setParseAction(' '.join)) text = "shape: SQUARE posn: upper left color: light blue texture: burlap" attr_expr = (label + Suppress(':') + OneOrMore(data_word, stopOn=label).setParseAction(' '.join)) # print attributes as plain groups print(OneOrMore(attr_expr).parseString(text).dump()) # instead of OneOrMore(expr), parse using Dict(OneOrMore(Group(expr))) - Dict will auto-assign names result = Dict(OneOrMore(Group(attr_expr))).parseString(text) print(result.dump()) # access named fields as dict entries, or output as dict print(result['shape']) print(result.asDict()) prints:: ['shape', 'SQUARE', 'posn', 'upper left', 'color', 'light blue', 'texture', 'burlap'] [['shape', 'SQUARE'], ['posn', 'upper left'], ['color', 'light blue'], ['texture', 'burlap']] - color: light blue - posn: upper left - shape: SQUARE - texture: burlap SQUARE {'color': 'light blue', 'posn': 'upper left', 'texture': 'burlap', 'shape': 'SQUARE'} See more examples at L{ParseResults} of accessing fields by results name. cstt|j|d|_dS)NT)rr rrW)rr.)rHrwrxrsz Dict.__init__cCsxt|D]\}}t|dkr q |d}t|trBt|dj}t|dkr^td|||<q t|dkrt|dt rt|d|||<q |j}|d=t|dkst|tr|j rt||||<q t|d|||<q W|j r|gS|SdS)Nrrrrrq) rrrzrurrrr"rrrV)rr-rrrtokZikeyZ dictvaluerwrwrxrs$   zDict.postParse)rrrrrrrrwrw)rHrxr s# c@s eZdZdZddZddZdS)r+aV Converter for ignoring the results of a parsed expression. Example:: source = "a, b, c,d" wd = Word(alphas) wd_list1 = wd + ZeroOrMore(',' + wd) print(wd_list1.parseString(source)) # often, delimiters that are useful during parsing are just in the # way afterward - use Suppress to keep them out of the parsed output wd_list2 = wd + ZeroOrMore(Suppress(',') + wd) print(wd_list2.parseString(source)) prints:: ['a', ',', 'b', ',', 'c', ',', 'd'] ['a', 'b', 'c', 'd'] (See also L{delimitedList}.) cCsgS)Nrw)rr-rrrwrwrxrszSuppress.postParsecCs|S)Nrw)rrwrwrxrszSuppress.suppressN)rrrrrrrwrwrwrxr+sc@s(eZdZdZddZddZddZdS) rzI Wrapper for parse actions, to ensure they are only called once. cCst||_d|_dS)NF)rMcallablecalled)rZ methodCallrwrwrxrs zOnlyOnce.__init__cCs.|js|j|||}d|_|St||ddS)NTr)rZrYr)rrr5rvrrwrwrxrs zOnlyOnce.__call__cCs d|_dS)NF)rZ)rrwrwrxreset szOnlyOnce.resetN)rrrrrrr[rwrwrwrxrsc s:tfdd}y j|_Wntk r4YnX|S)as Decorator for debugging parse actions. When the parse action is called, this decorator will print C{">> entering I{method-name}(line:I{current_source_line}, I{parse_location}, I{matched_tokens})".} When the parse action completes, the decorator will print C{"<<"} followed by the returned value, or any exception that the parse action raised. Example:: wd = Word(alphas) @traceParseAction def remove_duplicate_chars(tokens): return ''.join(sorted(set(''.join(tokens))) wds = OneOrMore(wd).setParseAction(remove_duplicate_chars) print(wds.parseString("slkdjs sld sldd sdlf sdljf")) prints:: >>entering remove_duplicate_chars(line: 'slkdjs sld sldd sdlf sdljf', 0, (['slkdjs', 'sld', 'sldd', 'sdlf', 'sdljf'], {})) <>entering %s(line: '%s', %d, %r) z<.z)rMrr)rr_rw)rrxrb s  ,FcCs`t|dt|dt|d}|rBt|t||j|S|tt||j|SdS)a Helper to define a delimited list of expressions - the delimiter defaults to ','. By default, the list elements and delimiters can have intervening whitespace, and comments, but this can be overridden by passing C{combine=True} in the constructor. If C{combine} is set to C{True}, the matching tokens are returned as a single token string, with the delimiters included; otherwise, the matching tokens are returned as a list of tokens, with the delimiters suppressed. Example:: delimitedList(Word(alphas)).parseString("aa,bb,cc") # -> ['aa', 'bb', 'cc'] delimitedList(Word(hexnums), delim=':', combine=True).parseString("AA:BB:CC:DD:EE") # -> ['AA:BB:CC:DD:EE'] z [rz]...N)rr r2rir+)r.ZdelimcombineZdlNamerwrwrxr@9s $csjtfdd}|dkr0ttjdd}n|j}|jd|j|dd|jd td S) a: Helper to define a counted list of expressions. This helper defines a pattern of the form:: integer expr expr expr... where the leading integer tells how many expr expressions follow. The matched tokens returns the array of expr tokens as a list - the leading count token is suppressed. If C{intExpr} is specified, it should be a pyparsing expression that produces an integer value. Example:: countedArray(Word(alphas)).parseString('2 ab cd ef') # -> ['ab', 'cd'] # in this parser, the leading integer value is given in binary, # '10' indicating that 2 values are in the array binaryConstant = Word('01').setParseAction(lambda t: int(t[0], 2)) countedArray(Word(alphas), intExpr=binaryConstant).parseString('10 ab cd ef') # -> ['ab', 'cd'] cs.|d}|r ttg|p&tt>gS)Nr)rrrC)rr5rvr) arrayExprr.rwrxcountFieldParseAction_s"z+countedArray..countFieldParseActionNcSs t|dS)Nr)ru)rvrwrwrxrydszcountedArray..ZarrayLenT)rfz(len) z...)rr/rRrrrirxr)r.ZintExprrcrw)rbr.rxr<Ls cCs:g}x0|D](}t|tr(|jt|q |j|q W|S)N)rzrrrr)Lrrrwrwrxrks   rcs6tfdd}|j|ddjdt|S)a* Helper to define an expression that is indirectly defined from the tokens matched in a previous expression, that is, it looks for a 'repeat' of a previous expression. For example:: first = Word(nums) second = matchPreviousLiteral(first) matchExpr = first + ":" + second will match C{"1:1"}, but not C{"1:2"}. Because this matches a previous literal, will also match the leading C{"1:1"} in C{"1:10"}. If this is not desired, use C{matchPreviousExpr}. Do I{not} use with packrat parsing enabled. csP|rBt|dkr|d>qLt|j}tdd|D>n t>dS)Nrrrcss|]}t|VqdS)N)r)rttrwrwrxrszDmatchPreviousLiteral..copyTokenToRepeater..)rrrrr )rr5rvZtflat)reprwrxcopyTokenToRepeaters   z1matchPreviousLiteral..copyTokenToRepeaterT)rfz(prev) )rrxrir)r.rgrw)rfrxrOts  csFt|j}|Kfdd}|j|ddjdt|S)aS Helper to define an expression that is indirectly defined from the tokens matched in a previous expression, that is, it looks for a 'repeat' of a previous expression. For example:: first = Word(nums) second = matchPreviousExpr(first) matchExpr = first + ":" + second will match C{"1:1"}, but not C{"1:2"}. Because this matches by expressions, will I{not} match the leading C{"1:1"} in C{"1:10"}; the expressions are evaluated first, and then compared, so C{"1"} is compared with C{"10"}. Do I{not} use with packrat parsing enabled. cs*t|jfdd}j|dddS)Ncs$t|j}|kr tddddS)Nrr)rrr)rr5rvZ theseTokens) matchTokensrwrxmustMatchTheseTokenss zLmatchPreviousExpr..copyTokenToRepeater..mustMatchTheseTokensT)rf)rrr)rr5rvri)rf)rhrxrgs  z.matchPreviousExpr..copyTokenToRepeaterT)rfz(prev) )rrrxrir)r.Ze2rgrw)rfrxrNs cCs>xdD]}|j|t|}qW|jdd}|jdd}t|S)Nz\^-]rz\nr'z\t)r_bslashr)rrrwrwrxrs    rTc s|rdd}dd}tndd}dd}tg}t|trF|j}n&t|tjr\t|}ntj dt dd|svt Sd }x|t |d kr||}xnt ||d d D]N\}} || |r|||d =Pq||| r|||d =|j|| | }PqW|d 7}q|W| r|ryht |t d j|krZtd d jdd|Djdj|Stdjdd|Djdj|SWn&tk rtj dt ddYnXtfdd|Djdj|S)a Helper to quickly define a set of alternative Literals, and makes sure to do longest-first testing when there is a conflict, regardless of the input order, but returns a C{L{MatchFirst}} for best performance. Parameters: - strs - a string of space-delimited literals, or a collection of string literals - caseless - (default=C{False}) - treat all literals as caseless - useRegex - (default=C{True}) - as an optimization, will generate a Regex object; otherwise, will generate a C{MatchFirst} object (if C{caseless=True}, or if creating a C{Regex} raises an exception) Example:: comp_oper = oneOf("< = > <= >= !=") var = Word(alphas) number = Word(nums) term = var | number comparison_expr = term + comp_oper + term print(comparison_expr.searchString("B = 12 AA=23 B<=AA AA>12")) prints:: [['B', '=', '12'], ['AA', '=', '23'], ['B', '<=', 'AA'], ['AA', '>', '12']] cSs|j|jkS)N)r)rbrwrwrxryszoneOf..cSs|jj|jS)N)rr)rrkrwrwrxryscSs||kS)Nrw)rrkrwrwrxryscSs |j|S)N)r)rrkrwrwrxrysz6Invalid argument to oneOf, expected string or iterablerq)rrrrNrz[%s]css|]}t|VqdS)N)r)rsymrwrwrxrszoneOf..z | |css|]}tj|VqdS)N)rdr)rrlrwrwrxrsz7Exception creating Regex for oneOf, building MatchFirstc3s|]}|VqdS)Nrw)rrl)parseElementClassrwrxrs)rrrzrrrr4rrrrrrrrrr'rirKr) ZstrsrZuseRegexZisequalZmasksZsymbolsrZcurrrrw)rnrxrSsL         ((cCsttt||S)a Helper to easily and clearly define a dictionary by specifying the respective patterns for the key and value. Takes care of defining the C{L{Dict}}, C{L{ZeroOrMore}}, and C{L{Group}} tokens in the proper order. The key pattern can include delimiting markers or punctuation, as long as they are suppressed, thereby leaving the significant key text. The value pattern can include named results, so that the C{Dict} results can include named token fields. Example:: text = "shape: SQUARE posn: upper left color: light blue texture: burlap" attr_expr = (label + Suppress(':') + OneOrMore(data_word, stopOn=label).setParseAction(' '.join)) print(OneOrMore(attr_expr).parseString(text).dump()) attr_label = label attr_value = Suppress(':') + OneOrMore(data_word, stopOn=label).setParseAction(' '.join) # similar to Dict, but simpler call format result = dictOf(attr_label, attr_value).parseString(text) print(result.dump()) print(result['shape']) print(result.shape) # object attribute access works too print(result.asDict()) prints:: [['shape', 'SQUARE'], ['posn', 'upper left'], ['color', 'light blue'], ['texture', 'burlap']] - color: light blue - posn: upper left - shape: SQUARE - texture: burlap SQUARE SQUARE {'color': 'light blue', 'shape': 'SQUARE', 'posn': 'upper left', 'texture': 'burlap'} )r r2r)rrrwrwrxrAs!cCs^tjdd}|j}d|_|d||d}|r@dd}ndd}|j||j|_|S) a Helper to return the original, untokenized text for a given expression. Useful to restore the parsed fields of an HTML start tag into the raw tag text itself, or to revert separate tokens with intervening whitespace back to the original matching input text. By default, returns astring containing the original parsed text. If the optional C{asString} argument is passed as C{False}, then the return value is a C{L{ParseResults}} containing any results names that were originally matched, and a single token containing the original matched text from the input string. So if the expression passed to C{L{originalTextFor}} contains expressions with defined results names, you must set C{asString} to C{False} if you want to preserve those results name values. Example:: src = "this is test bold text normal text " for tag in ("b","i"): opener,closer = makeHTMLTags(tag) patt = originalTextFor(opener + SkipTo(closer) + closer) print(patt.searchString(src)[0]) prints:: [' bold text '] ['text'] cSs|S)Nrw)rrrvrwrwrxry8sz!originalTextFor..F_original_start _original_endcSs||j|jS)N)rorp)rr5rvrwrwrxry=scSs&||jd|jdg|dd<dS)Nrorp)r)rr5rvrwrwrx extractText?sz$originalTextFor..extractText)r rrrer])r.ZasStringZ locMarkerZ endlocMarker matchExprrqrwrwrxrg s  cCst|jddS)zp Helper to undo pyparsing's default grouping of And expressions, even if all but one are non-empty. cSs|dS)Nrrw)rvrwrwrxryJszungroup..)r-r)r.rwrwrxrhEscCs4tjdd}t|d|d|jjdS)a Helper to decorate a returned token with its starting and ending locations in the input string. This helper adds the following results names: - locn_start = location where matched expression begins - locn_end = location where matched expression ends - value = the actual parsed results Be careful if the input text contains C{} characters, you may want to call C{L{ParserElement.parseWithTabs}} Example:: wd = Word(alphas) for match in locatedExpr(wd).searchString("ljsdf123lksdjjf123lkkjj1222"): print(match) prints:: [[0, 'ljsdf', 5]] [[8, 'lksdjjf', 15]] [[18, 'lkkjj', 23]] cSs|S)Nrw)rr5rvrwrwrxry`szlocatedExpr..Z locn_startrZlocn_end)r rrrr)r.ZlocatorrwrwrxrjLsz\[]-*.$+^?()~ )r cCs |ddS)Nrrrrw)rr5rvrwrwrxryksryz\\0?[xX][0-9a-fA-F]+cCstt|djddS)Nrz\0x)unichrrulstrip)rr5rvrwrwrxrylsz \\0[0-7]+cCstt|ddddS)Nrrr)rtru)rr5rvrwrwrxrymsz\])rr z\wr7rrZnegatebodyr c sBddy djfddtj|jDStk r<dSXdS)a Helper to easily define string ranges for use in Word construction. Borrows syntax from regexp '[]' string range definitions:: srange("[0-9]") -> "0123456789" srange("[a-z]") -> "abcdefghijklmnopqrstuvwxyz" srange("[a-z$_]") -> "abcdefghijklmnopqrstuvwxyz$_" The input string must be enclosed in []'s, and the returned string is the expanded character set joined into a single string. The values enclosed in the []'s may be: - a single character - an escaped character with a leading backslash (such as C{\-} or C{\]}) - an escaped hex character with a leading C{'\x'} (C{\x21}, which is a C{'!'} character) (C{\0x##} is also supported for backwards compatibility) - an escaped octal character with a leading C{'\0'} (C{\041}, which is a C{'!'} character) - a range of any of the above, separated by a dash (C{'a-z'}, etc.) - any combination of the above (C{'aeiouy'}, C{'a-zA-Z0-9_$'}, etc.) cSs<t|ts|Sdjddtt|dt|ddDS)Nrcss|]}t|VqdS)N)rt)rrrwrwrxrsz+srange....rrr)rzr"rrord)prwrwrxryszsrange..rc3s|]}|VqdS)Nrw)rpart) _expandedrwrxrszsrange..N)r_reBracketExprrrwrK)rrw)r{rxr_rs  csfdd}|S)zt Helper method for defining parse actions that require matching at a specific column in the input text. cs"t||krt||ddS)Nzmatched token not at column %d)r9r)r)Zlocnr1)rrwrx verifyColsz!matchOnlyAtCol..verifyColrw)rr}rw)rrxrMs cs fddS)a Helper method for common parse actions that simply return a literal value. Especially useful when used with C{L{transformString}()}. Example:: num = Word(nums).setParseAction(lambda toks: int(toks[0])) na = oneOf("N/A NA").setParseAction(replaceWith(math.nan)) term = na | num OneOrMore(term).parseString("324 234 N/A 234") # -> [324, 234, nan, 234] csgS)Nrw)rr5rv)replStrrwrxryszreplaceWith..rw)r~rw)r~rxr\s cCs|dddS)a Helper parse action for removing quotation marks from parsed quoted strings. Example:: # by default, quotation marks are included in parsed results quotedString.parseString("'Now is the Winter of our Discontent'") # -> ["'Now is the Winter of our Discontent'"] # use removeQuotes to strip quotation marks from parsed results quotedString.setParseAction(removeQuotes) quotedString.parseString("'Now is the Winter of our Discontent'") # -> ["Now is the Winter of our Discontent"] rrrrsrw)rr5rvrwrwrxrZs c sNfdd}ytdtdj}Wntk rBt}YnX||_|S)aG Helper to define a parse action by mapping a function to all elements of a ParseResults list.If any additional args are passed, they are forwarded to the given function as additional arguments after the token, as in C{hex_integer = Word(hexnums).setParseAction(tokenMap(int, 16))}, which will convert the parsed data to an integer using base 16. Example (compare the last to example in L{ParserElement.transformString}:: hex_ints = OneOrMore(Word(hexnums)).setParseAction(tokenMap(int, 16)) hex_ints.runTests(''' 00 11 22 aa FF 0a 0d 1a ''') upperword = Word(alphas).setParseAction(tokenMap(str.upper)) OneOrMore(upperword).runTests(''' my kingdom for a horse ''') wd = Word(alphas).setParseAction(tokenMap(str.title)) OneOrMore(wd).setParseAction(' '.join).runTests(''' now is the winter of our discontent made glorious summer by this sun of york ''') prints:: 00 11 22 aa FF 0a 0d 1a [0, 17, 34, 170, 255, 10, 13, 26] my kingdom for a horse ['MY', 'KINGDOM', 'FOR', 'A', 'HORSE'] now is the winter of our discontent made glorious summer by this sun of york ['Now Is The Winter Of Our Discontent Made Glorious Summer By This Sun Of York'] csfdd|DS)Ncsg|]}|fqSrwrw)rZtokn)rr6rwrxrsz(tokenMap..pa..rw)rr5rv)rr6rwrxr}sztokenMap..parrH)rJrrKr{)r6rr}rLrw)rr6rxrms cCs t|jS)N)rr)rvrwrwrxryscCs t|jS)N)rlower)rvrwrwrxryscCst|tr|}t|| d}n|j}tttd}|rtjj t }t d|dt t t|t d|tddgdjd j d d t d }nd jddtD}tjj t t|B}t d|dt t t|j ttt d|tddgdjd j dd t d }ttd|d }|jdd j|jddjjjd|}|jdd j|jddjjjd|}||_||_||fS)zRInternal helper to construct opening and closing tag expressions, given a tag name)rz_-:rtag=/F)rrCcSs |ddkS)Nrrrw)rr5rvrwrwrxrysz_makeTags..rrcss|]}|dkr|VqdS)rNrw)rrrwrwrxrsz_makeTags..cSs |ddkS)Nrrrw)rr5rvrwrwrxryszr z)rzrrrr/r4r3r>rrrZr+r r2rrrmrrVrYrBr _Lrtitlerrir)tagStrZxmlZresnameZ tagAttrNameZ tagAttrValueZopenTagZprintablesLessRAbrackZcloseTagrwrwrx _makeTagss" T\..rcCs t|dS)a  Helper to construct opening and closing tag expressions for HTML, given a tag name. Matches tags in either upper or lower case, attributes with namespaces and with quoted or unquoted values. Example:: text = 'More info at the pyparsing wiki page' # makeHTMLTags returns pyparsing expressions for the opening and closing tags as a 2-tuple a,a_end = makeHTMLTags("A") link_expr = a + SkipTo(a_end)("link_text") + a_end for link in link_expr.searchString(text): # attributes in the tag (like "href" shown here) are also accessible as named results print(link.link_text, '->', link.href) prints:: pyparsing -> http://pyparsing.wikispaces.com F)r)rrwrwrxrKscCs t|dS)z Helper to construct opening and closing tag expressions for XML, given a tag name. Matches tags only in the given upper/lower case. Example: similar to L{makeHTMLTags} T)r)rrwrwrxrLscs8|r|ddn|jddDfdd}|S)a< Helper to create a validating parse action to be used with start tags created with C{L{makeXMLTags}} or C{L{makeHTMLTags}}. Use C{withAttribute} to qualify a starting tag with a required attribute value, to avoid false matches on common tags such as C{} or C{
}. Call C{withAttribute} with a series of attribute names and values. Specify the list of filter attributes names and values as: - keyword arguments, as in C{(align="right")}, or - as an explicit dict with C{**} operator, when an attribute name is also a Python reserved word, as in C{**{"class":"Customer", "align":"right"}} - a list of name-value tuples, as in ( ("ns1:class", "Customer"), ("ns2:align","right") ) For attribute names with a namespace prefix, you must use the second form. Attribute names are matched insensitive to upper/lower case. If just testing for C{class} (with or without a namespace), use C{L{withClass}}. To verify that the attribute exists, but without specifying a value, pass C{withAttribute.ANY_VALUE} as the value. Example:: html = '''
Some text
1 4 0 1 0
1,3 2,3 1,1
this has no type
''' div,div_end = makeHTMLTags("div") # only match div tag having a type attribute with value "grid" div_grid = div().setParseAction(withAttribute(type="grid")) grid_expr = div_grid + SkipTo(div | div_end)("body") for grid_header in grid_expr.searchString(html): print(grid_header.body) # construct a match with any div tag having a type attribute, regardless of the value div_any_type = div().setParseAction(withAttribute(type=withAttribute.ANY_VALUE)) div_expr = div_any_type + SkipTo(div | div_end)("body") for div_header in div_expr.searchString(html): print(div_header.body) prints:: 1 4 0 1 0 1 4 0 1 0 1,3 2,3 1,1 NcSsg|]\}}||fqSrwrw)rrrrwrwrxrQsz!withAttribute..cs^xXD]P\}}||kr&t||d||tjkr|||krt||d||||fqWdS)Nzno matching attribute z+attribute '%s' has value '%s', must be '%s')rre ANY_VALUE)rr5rZattrNameZ attrValue)attrsrwrxr}Rs zwithAttribute..pa)r)rZattrDictr}rw)rrxres 2 cCs|r d|nd}tf||iS)a Simplified version of C{L{withAttribute}} when matching on a div class - made difficult because C{class} is a reserved word in Python. Example:: html = '''
Some text
1 4 0 1 0
1,3 2,3 1,1
this <div> has no class
''' div,div_end = makeHTMLTags("div") div_grid = div().setParseAction(withClass("grid")) grid_expr = div_grid + SkipTo(div | div_end)("body") for grid_header in grid_expr.searchString(html): print(grid_header.body) div_any_type = div().setParseAction(withClass(withAttribute.ANY_VALUE)) div_expr = div_any_type + SkipTo(div | div_end)("body") for div_header in div_expr.searchString(html): print(div_header.body) prints:: 1 4 0 1 0 1 4 0 1 0 1,3 2,3 1,1 z%s:classclass)re)Z classname namespaceZ classattrrwrwrxrk\s (rcCst}||||B}x`t|D]R\}}|d dd\}} } } | dkrTd|nd|} | dkr|dksxt|dkrtd|\} }tj| }| tjkrd| dkrt||t|t |}n| dkr|dk rt|||t|t ||}nt||t|t |}nD| dkrZt|| |||t|| |||}ntd n| tj krH| dkrt |t st |}t|j |t||}n| dkr|dk rt|||t|t ||}nt||t|t |}nD| dkr>t|| |||t|| |||}ntd ntd | r`|j| ||j| |BK}|}q"W||K}|S) a Helper method for constructing grammars of expressions made up of operators working in a precedence hierarchy. Operators may be unary or binary, left- or right-associative. Parse actions can also be attached to operator expressions. The generated parser will also recognize the use of parentheses to override operator precedences (see example below). Note: if you define a deep operator list, you may see performance issues when using infixNotation. See L{ParserElement.enablePackrat} for a mechanism to potentially improve your parser performance. Parameters: - baseExpr - expression representing the most basic element for the nested - opList - list of tuples, one for each operator precedence level in the expression grammar; each tuple is of the form (opExpr, numTerms, rightLeftAssoc, parseAction), where: - opExpr is the pyparsing expression for the operator; may also be a string, which will be converted to a Literal; if numTerms is 3, opExpr is a tuple of two expressions, for the two operators separating the 3 terms - numTerms is the number of terms for this operator (must be 1, 2, or 3) - rightLeftAssoc is the indicator whether the operator is right or left associative, using the pyparsing-defined constants C{opAssoc.RIGHT} and C{opAssoc.LEFT}. - parseAction is the parse action to be associated with expressions matching this operator expression (the parse action tuple member may be omitted) - lpar - expression for matching left-parentheses (default=C{Suppress('(')}) - rpar - expression for matching right-parentheses (default=C{Suppress(')')}) Example:: # simple example of four-function arithmetic with ints and variable names integer = pyparsing_common.signed_integer varname = pyparsing_common.identifier arith_expr = infixNotation(integer | varname, [ ('-', 1, opAssoc.RIGHT), (oneOf('* /'), 2, opAssoc.LEFT), (oneOf('+ -'), 2, opAssoc.LEFT), ]) arith_expr.runTests(''' 5+3*6 (5+3)*6 -2--11 ''', fullDump=False) prints:: 5+3*6 [[5, '+', [3, '*', 6]]] (5+3)*6 [[[5, '+', 3], '*', 6]] -2--11 [[['-', 2], '-', ['-', 11]]] Nrroz%s termz %s%s termrqz@if numterms=3, opExpr must be a tuple or list of two expressionsrrz6operator must be unary (1), binary (2), or ternary (3)z2operator must indicate right or left associativity)N)rrrrrirTLEFTrrrRIGHTrzrr.r)ZbaseExprZopListZlparZrparrZlastExprrZoperDefZopExprZarityZrightLeftAssocr}ZtermNameZopExpr1ZopExpr2ZthisExprrrrwrwrxrisR;    &       &   z4"(?:[^"\n\r\\]|(?:"")|(?:\\(?:[^x]|x[0-9a-fA-F]+)))*"z string enclosed in double quotesz4'(?:[^'\n\r\\]|(?:'')|(?:\\(?:[^x]|x[0-9a-fA-F]+)))*'z string enclosed in single quotesz*quotedString using single or double quotesuzunicode string literalcCs||krtd|dkr(t|to,t|tr t|dkrt|dkr|dk rtt|t||tjddj dd}n$t j t||tjj dd}nx|dk rtt|t |t |ttjddj dd}n4ttt |t |ttjddj d d}ntd t }|dk rb|tt|t||B|Bt|K}n$|tt|t||Bt|K}|jd ||f|S) a~ Helper method for defining nested lists enclosed in opening and closing delimiters ("(" and ")" are the default). Parameters: - opener - opening character for a nested list (default=C{"("}); can also be a pyparsing expression - closer - closing character for a nested list (default=C{")"}); can also be a pyparsing expression - content - expression for items within the nested lists (default=C{None}) - ignoreExpr - expression for ignoring opening and closing delimiters (default=C{quotedString}) If an expression is not provided for the content argument, the nested expression will capture all whitespace-delimited content between delimiters as a list of separate values. Use the C{ignoreExpr} argument to define expressions that may contain opening or closing characters that should not be treated as opening or closing characters for nesting, such as quotedString or a comment expression. Specify multiple expressions using an C{L{Or}} or C{L{MatchFirst}}. The default is L{quotedString}, but if no expressions are to be ignored, then pass C{None} for this argument. Example:: data_type = oneOf("void int short long char float double") decl_data_type = Combine(data_type + Optional(Word('*'))) ident = Word(alphas+'_', alphanums+'_') number = pyparsing_common.number arg = Group(decl_data_type + ident) LPAR,RPAR = map(Suppress, "()") code_body = nestedExpr('{', '}', ignoreExpr=(quotedString | cStyleComment)) c_function = (decl_data_type("type") + ident("name") + LPAR + Optional(delimitedList(arg), [])("args") + RPAR + code_body("body")) c_function.ignore(cStyleComment) source_code = ''' int is_odd(int x) { return (x%2); } int dec_to_hex(char hchar) { if (hchar >= '0' && hchar <= '9') { return (ord(hchar)-ord('0')); } else { return (10+ord(hchar)-ord('A')); } } ''' for func in c_function.searchString(source_code): print("%(name)s (%(type)s) args: %(args)s" % func) prints:: is_odd (int) args: [['int', 'x']] dec_to_hex (int) args: [['char', 'hchar']] z.opening and closing strings cannot be the sameNrr)r cSs |djS)Nr)r)rvrwrwrxry9sznestedExpr..cSs |djS)Nr)r)rvrwrwrxry<scSs |djS)Nr)r)rvrwrwrxryBscSs |djS)Nr)r)rvrwrwrxryFszOopening and closing arguments must be strings if no content expression is givenznested %s%s expression)rrzrrr rr r$rNrrCrrrrr+r2ri)openerZcloserZcontentrNrrwrwrxrPs4:     *$c sfdd}fdd}fdd}ttjdj}ttj|jd}tj|jd }tj|jd } |rtt||t|t|t|| } n$tt|t|t|t|} |j t t| jd S) a Helper method for defining space-delimited indentation blocks, such as those used to define block statements in Python source code. Parameters: - blockStatementExpr - expression defining syntax of statement that is repeated within the indented block - indentStack - list created by caller to manage indentation stack (multiple statementWithIndentedBlock expressions within a single grammar should share a common indentStack) - indent - boolean indicating whether block must be indented beyond the the current level; set to False for block of left-most statements (default=C{True}) A valid block must contain at least one C{blockStatement}. Example:: data = ''' def A(z): A1 B = 100 G = A2 A2 A3 B def BB(a,b,c): BB1 def BBA(): bba1 bba2 bba3 C D def spam(x,y): def eggs(z): pass ''' indentStack = [1] stmt = Forward() identifier = Word(alphas, alphanums) funcDecl = ("def" + identifier + Group( "(" + Optional( delimitedList(identifier) ) + ")" ) + ":") func_body = indentedBlock(stmt, indentStack) funcDef = Group( funcDecl + func_body ) rvalue = Forward() funcCall = Group(identifier + "(" + Optional(delimitedList(rvalue)) + ")") rvalue << (funcCall | identifier | Word(nums)) assignment = Group(identifier + "=" + rvalue) stmt << ( funcDef | assignment | identifier ) module_body = OneOrMore(stmt) parseTree = module_body.parseString(data) parseTree.pprint() prints:: [['def', 'A', ['(', 'z', ')'], ':', [['A1'], [['B', '=', '100']], [['G', '=', 'A2']], ['A2'], ['A3']]], 'B', ['def', 'BB', ['(', 'a', 'b', 'c', ')'], ':', [['BB1'], [['def', 'BBA', ['(', ')'], ':', [['bba1'], ['bba2'], ['bba3']]]]]], 'C', 'D', ['def', 'spam', ['(', 'x', 'y', ')'], ':', [[['def', 'eggs', ['(', 'z', ')'], ':', [['pass']]]]]]] csN|t|krdSt||}|dkrJ|dkr>t||dt||ddS)Nrrzillegal nestingznot a peer entryrsrs)rr9r!r)rr5rvcurCol) indentStackrwrxcheckPeerIndents     z&indentedBlock..checkPeerIndentcs2t||}|dkr"j|n t||ddS)Nrrznot a subentryrs)r9rr)rr5rvr)rrwrxcheckSubIndents   z%indentedBlock..checkSubIndentcsN|t|krdSt||}o4|dko4|dksBt||djdS)Nrrrqznot an unindentrsr:)rr9rr)rr5rvr)rrwrx checkUnindents    z$indentedBlock..checkUnindentz INDENTrZUNINDENTzindented block) rrrrr rrirrrrj) ZblockStatementExprrrrrrr!rZPEERZUNDENTZsmExprrw)rrxrfQsN   ,z#[\0xc0-\0xd6\0xd8-\0xf6\0xf8-\0xff]z[\0xa1-\0xbf\0xd7\0xf7]z_:zany tagzgt lt amp nbsp quot aposz><& "'z &(?Prmz);zcommon HTML entitycCs tj|jS)zRHelper parser action to replace common HTML entities with their special characters)_htmlEntityMaprZentity)rvrwrwrxr[sz/\*(?:[^*]|\*(?!/))*z*/zC style commentzz HTML commentz.*z rest of linez//(?:\\\n|[^\n])*z // commentzC++ style commentz#.*zPython style comment)rz commaItem)rc@seZdZdZeeZeeZe e j dj eZ e ej dj eedZedj dj eZej edej ej dZejd d eeeed jeBj d Zejeed j dj eZedj dj eZeeBeBjZedj dj eZe ededj dZedj dZ edj dZ!e!de!dj dZ"ee!de!d>dee!de!d?j dZ#e#j$d d d!e j d"Z%e&e"e%Be#Bj d#j d#Z'ed$j d%Z(e)d@d'd(Z*e)dAd*d+Z+ed,j d-Z,ed.j d/Z-ed0j d1Z.e/je0jBZ1e)d2d3Z2e&e3e4d4e5e e6d4d5ee7d6jj d7Z8e9ee:j;e8Bd8d9j d:Zd=S)Brna Here are some common low-level expressions that may be useful in jump-starting parser development: - numeric forms (L{integers}, L{reals}, L{scientific notation}) - common L{programming identifiers} - network addresses (L{MAC}, L{IPv4}, L{IPv6}) - ISO8601 L{dates} and L{datetime} - L{UUID} - L{comma-separated list} Parse actions: - C{L{convertToInteger}} - C{L{convertToFloat}} - C{L{convertToDate}} - C{L{convertToDatetime}} - C{L{stripHTMLTags}} - C{L{upcaseTokens}} - C{L{downcaseTokens}} Example:: pyparsing_common.number.runTests(''' # any int or real number, returned as the appropriate type 100 -100 +100 3.14159 6.02e23 1e-12 ''') pyparsing_common.fnumber.runTests(''' # any int or real number, returned as float 100 -100 +100 3.14159 6.02e23 1e-12 ''') pyparsing_common.hex_integer.runTests(''' # hex numbers 100 FF ''') pyparsing_common.fraction.runTests(''' # fractions 1/2 -3/4 ''') pyparsing_common.mixed_integer.runTests(''' # mixed fractions 1 1/2 -3/4 1-3/4 ''') import uuid pyparsing_common.uuid.setParseAction(tokenMap(uuid.UUID)) pyparsing_common.uuid.runTests(''' # uuid 12345678-1234-5678-1234-567812345678 ''') prints:: # any int or real number, returned as the appropriate type 100 [100] -100 [-100] +100 [100] 3.14159 [3.14159] 6.02e23 [6.02e+23] 1e-12 [1e-12] # any int or real number, returned as float 100 [100.0] -100 [-100.0] +100 [100.0] 3.14159 [3.14159] 6.02e23 [6.02e+23] 1e-12 [1e-12] # hex numbers 100 [256] FF [255] # fractions 1/2 [0.5] -3/4 [-0.75] # mixed fractions 1 [1] 1/2 [0.5] -3/4 [-0.75] 1-3/4 [1.75] # uuid 12345678-1234-5678-1234-567812345678 [UUID('12345678-1234-5678-1234-567812345678')] integerz hex integerrsz[+-]?\d+zsigned integerrfractioncCs|d|dS)Nrrrrsrw)rvrwrwrxryszpyparsing_common.r7z"fraction or mixed integer-fractionz [+-]?\d+\.\d*z real numberz+[+-]?\d+([eE][+-]?\d+|\.\d*([eE][+-]?\d+)?)z$real number with scientific notationz[+-]?\d+\.?\d*([eE][+-]?\d+)?fnumberrA identifierzK(25[0-5]|2[0-4][0-9]|1?[0-9]{1,2})(\.(25[0-5]|2[0-4][0-9]|1?[0-9]{1,2})){3}z IPv4 addressz[0-9a-fA-F]{1,4} hex_integerrzfull IPv6 addressrrBz::zshort IPv6 addresscCstdd|DdkS)Ncss|]}tjj|rdVqdS)rrN)rn _ipv6_partr)rrerwrwrxrsz,pyparsing_common...rv)rG)rvrwrwrxrysz::ffff:zmixed IPv6 addressz IPv6 addressz:[0-9a-fA-F]{2}([:.-])[0-9a-fA-F]{2}(?:\1[0-9a-fA-F]{2}){4}z MAC address%Y-%m-%dcsfdd}|S)a Helper to create a parse action for converting parsed date string to Python datetime.date Params - - fmt - format to be passed to datetime.strptime (default=C{"%Y-%m-%d"}) Example:: date_expr = pyparsing_common.iso8601_date.copy() date_expr.setParseAction(pyparsing_common.convertToDate()) print(date_expr.parseString("1999-12-31")) prints:: [datetime.date(1999, 12, 31)] csLytj|djStk rF}zt||t|WYdd}~XnXdS)Nr)rstrptimeZdaterrr{)rr5rvve)fmtrwrxcvt_fnsz.pyparsing_common.convertToDate..cvt_fnrw)rrrw)rrx convertToDates zpyparsing_common.convertToDate%Y-%m-%dT%H:%M:%S.%fcsfdd}|S)a Helper to create a parse action for converting parsed datetime string to Python datetime.datetime Params - - fmt - format to be passed to datetime.strptime (default=C{"%Y-%m-%dT%H:%M:%S.%f"}) Example:: dt_expr = pyparsing_common.iso8601_datetime.copy() dt_expr.setParseAction(pyparsing_common.convertToDatetime()) print(dt_expr.parseString("1999-12-31T23:59:59.999")) prints:: [datetime.datetime(1999, 12, 31, 23, 59, 59, 999000)] csHytj|dStk rB}zt||t|WYdd}~XnXdS)Nr)rrrrr{)rr5rvr)rrwrxrsz2pyparsing_common.convertToDatetime..cvt_fnrw)rrrw)rrxconvertToDatetimes z"pyparsing_common.convertToDatetimez7(?P\d{4})(?:-(?P\d\d)(?:-(?P\d\d))?)?z ISO8601 datez(?P\d{4})-(?P\d\d)-(?P\d\d)[T ](?P\d\d):(?P\d\d)(:(?P\d\d(\.\d*)?)?)?(?PZ|[+-]\d\d:?\d\d)?zISO8601 datetimez2[0-9a-fA-F]{8}(-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}UUIDcCstjj|dS)a Parse action to remove HTML tags from web page HTML source Example:: # strip HTML links from normal text text = 'More info at the
pyparsing wiki page' td,td_end = makeHTMLTags("TD") table_text = td + SkipTo(td_end).setParseAction(pyparsing_common.stripHTMLTags)("body") + td_end print(table_text.parseString(text).body) # -> 'More info at the pyparsing wiki page' r)rn_html_stripperr)rr5rrwrwrx stripHTMLTagss zpyparsing_common.stripHTMLTagsr`)rz rr)rzcomma separated listcCs t|jS)N)rr)rvrwrwrxryscCs t|jS)N)rr)rvrwrwrxrysN)rrB)rrB)r)r)?rrrrrmruZconvertToIntegerfloatZconvertToFloatr/rRrirrrDrr'Zsigned_integerrrxrrZ mixed_integerrGrealZsci_realrnumberrr4r3rZ ipv4_addressrZ_full_ipv6_addressZ_short_ipv6_addressr~Z_mixed_ipv6_addressr Z ipv6_addressZ mac_addressrrrZ iso8601_dateZiso8601_datetimeuuidr7r6rrrrrrVr. _commasepitemr@rYrZcomma_separated_listrdrBrwrwrwrxrnsN"" 2   8__main__Zselectfromz_$r\)racolumnsrjZtablesZcommandaK # '*' as column list and dotted table name select * from SYS.XYZZY # caseless match on "SELECT", and casts back to "select" SELECT * from XYZZY, ABC # list of column names, and mixed case SELECT keyword Select AA,BB,CC from Sys.dual # multiple tables Select A, B, C from Sys.dual, Table2 # invalid SELECT keyword - should fail Xelect A, B, C from Sys.dual # incomplete command - should fail Select # invalid column name - should fail Select ^^^ frox Sys.dual z] 100 -100 +100 3.14159 6.02e23 1e-12 z 100 FF z6 12345678-1234-5678-1234-567812345678 )rq)r`F)N)FT)T)r)T)r __version__Z__versionTime__ __author__rweakrefrrrr~rrdrrr"r<rr_threadr ImportErrorZ threadingrrZ ordereddict__all__r version_infor;rmaxsizerr{rchrrtrrGrrreversedrrrr5r r rIZmaxintZxrangerZ __builtin__rZfnamerrJrrrrrrZascii_uppercaseZascii_lowercaser4rRrDr3rjrZ printablerVrKrrr!r#r&rr"MutableMappingregisterr9rJrGr/r2r4rQrMr$r,r rrrrQrrrrlr/r'r%r r.r/rrrr*r)r1r0r rrrr rrrrIrr2rLrMrr(rrUr-r rr r+rrbr@r<rrOrNrrSrArgrhrjrirCrIrHrar`rZ _escapedPuncZ_escapedHexCharZ_escapedOctCharUNICODEZ _singleCharZ _charRangermr|r_rMr\rZrmrdrBrrKrLrerrkrTrrrirUr>r^rYrcrPrfr5rWr7r6rrrrr;r[r8rErr]r?r=rFrXrrr:rnrZ selectTokenZ fromTokenZidentZ columnNameZcolumnNameListZ columnSpecZ tableNameZ tableNameListZ simpleSQLrrrrrrrwrwrwrx=s                 8      @d &A= I G3pLOD|M &#@sQ,A,    I# %     &0 ,   ? #k Zr   (  0     "