Files
old-parkingkoncept/parkingkonceptvenv/lib/python3.7/site-packages/s3transfer/__pycache__/utils.cpython-37.pyc

285 lines
24 KiB
Plaintext
Raw Normal View History

2019-11-17 12:44:16 +01:00
B
<00>[<5B>]<5D>f<00>@s<>ddlZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl
Z
ddl m Z ddl mZddl mZddlmZddlmZddlmZddlmZd Zd
Zd Ze<08>e<19>ZejeeefZd3d d<0E>Zdd<10>Zdd<12>Zdd<14>Z d4dd<16>Z!dd<18>Z"dd<1A>Z#dd<1C>Z$Gdd<1E>de%<25>Z&Gdd <20>d e%<25>Z'Gd!d"<22>d"e%<25>Z(Gd#d$<24>d$e%<25>Z)Gd%d&<26>d&e%<25>Z*Gd'd(<28>d(e%<25>Z+Gd)d*<2A>d*e%<25>Z,Gd+d,<2C>d,e-<2D>Z.Gd-d.<2E>d.e%<25>Z/Gd/d0<64>d0e/<2F>Z0Gd1d2<64>d2e%<25>Z1dS)5<>N)<01> defaultdict)<01>IncompleteReadError)<01>ReadTimeoutError)<01> SOCKET_ERROR)<01> rename_file)<01>seekable)<01> fallocatei'liP<00>cCsd<01>dd<03>t|<00>D<00><01>S)N<>css|]}t<00>tj<03>VqdS)N)<04>random<6F>choice<63>string<6E> hexdigits)<02>.0<EFBFBD>_<>r<00>8/tmp/pip-install-u_6_z2pz/s3transfer/s3transfer/utils.py<70> <genexpr>2sz(random_file_extension.<locals>.<genexpr>)<02>join<69>range)Z
num_digitsrrr<00>random_file_extension1srcKs"|dkrt|jd<02>r|j<01><02>dS)N)<02> PutObject<63>
UploadPart<EFBFBD>signal_not_transferring)<03>hasattr<74>bodyr)<03>request<73>operation_name<6D>kwargsrrrr5s rcKs"|dkrt|jd<02>r|j<01><02>dS)N)rr<00>signal_transferring)rrr)rrrrrrr;s rcCstt<01>|t|<01><00><01>S)N)<04>int<6E>math<74>ceil<69>float)<02>size<7A> part_sizerrr<00>calculate_num_partsAsr&cCsJ||}||dkr.d}|dk r:t|d<00>}n ||d}d||f}|S)a<>Calculate the range parameter for multipart downloads/copies
:type part_size: int
:param part_size: The size of the part
:type part_index: int
:param part_index: The index for which this parts starts. This index starts
at zero
:type num_parts: int
:param num_parts: The total number of parts in the transfer
:returns: The value to use for Range parameter on downloads or
the CopySourceRange parameter for copies
<20>r
Nz bytes=%s-%s)<01>str)r%Z
part_index<EFBFBD> num_partsZ
total_sizeZ start_rangeZ end_rangeZ range_paramrrr<00>calculate_range_parameterEs   r*cCsHg}x>|jjjD]0}d|}t||<04>r|<02>tjt||<04>|d<02><02>qW|S)a Retrieves callbacks from a subscriber
:type transfer_future: s3transfer.futures.TransferFuture
:param transfer_future: The transfer future the subscriber is associated
to.
:type callback_type: str
:param callback_type: The type of callback to retrieve from the subscriber.
Valid types include:
* 'queued'
* 'progress'
* 'done'
:returns: A list of callbacks for the type specified. All callbacks are
preinjected with the transfer future.
Zon_)<01>future)<08>meta<74> call_argsZ subscribersr<00>append<6E> functools<6C>partial<61>getattr)Ztransfer_futureZ callback_type<70> callbacks<6B>
subscriberZ callback_namerrr<00> get_callbacksbs
r4cCs |rx|D]}||d<01>q
WdS)a<>Calls all progress callbacks
:param callbacks: A list of progress callbacks to invoke
:param bytes_transferred: The number of bytes transferred. This is passed
to the callbacks. If no bytes were transferred the callbacks will not
be invoked because no progress was achieved. It is also possible
to receive a negative amount which comes from retrying a transfer
request.
)<01>bytes_transferredNr)r2r5<00>callbackrrr<00>invoke_progress_callbacks<6B>s 
r7cCs.i}x$|<00><00>D]\}}||kr|||<qW|S)aoGets a dictionary filtered by whitelisted keys
:param original_dict: The original dictionary of arguments to source keys
and values.
:param whitelisted_key: A list of keys to include in the filtered
dictionary.
:returns: A dictionary containing key/values from the original dictionary
whose key was included in the whitelist
)<01>items)Z original_dictZwhitelisted_keysZ filtered_dict<63>key<65>valuerrr<00>get_filtered_dict<63>s
 r;c@seZdZdd<02>ZdS)<04>CallArgscKs&x |<01><00>D]\}}t|||<03>q
WdS)z<>A class that records call arguments
The call arguments must be passed as keyword arguments. It will set
each keyword argument as an attribute of the object along with its
associated value.
N)r8<00>setattr)<04>selfr<00>argr:rrr<00>__init__<5F>szCallArgs.__init__N)<04>__name__<5F>
__module__<EFBFBD> __qualname__r@rrrrr<<00>sr<c@s(eZdZdZdd<03>Zdd<05>Zdd<07>ZdS) <09>FunctionContainerz<72>An object that contains a function and any args or kwargs to call it
When called the provided function will be called with provided args
and kwargs.
cOs||_||_||_dS)N)<03>_func<6E>_args<67>_kwargs)r><00>func<6E>argsrrrrr@<00>szFunctionContainer.__init__cCsd|j|j|jfS)Nz'Function: %s with args %s and kwargs %s)rErFrG)r>rrr<00>__repr__<5F>szFunctionContainer.__repr__cCs|j|j|j<02>S)N)rErFrG)r>rrr<00>__call__<5F>szFunctionContainer.__call__N)rArBrC<00>__doc__r@rJrKrrrrrD<00>srDc@s<eZdZdZdd<03>Zedd<05><00>Zdd<07>Zdd <09>Zd
d <0B>Z d S) <0A>CountCallbackInvokerz<72>An abstraction to invoke a callback when a shared count reaches zero
:param callback: Callback invoke when finalized count reaches zero
cCs t<00><01>|_||_d|_d|_dS)NrF)<06> threading<6E>Lock<63>_lock<63> _callback<63>_count<6E> _is_finalized)r>r6rrrr@<00>s
zCountCallbackInvoker.__init__c Cs|j<00>|jSQRXdS)N)rPrR)r>rrr<00> current_count<6E>sz"CountCallbackInvoker.current_countc Cs2|j<00>"|jrtd<01><01>|jd7_WdQRXdS)zIncrement the count by onez;Counter has been finalized it can no longer be incremented.r'N)rPrS<00> RuntimeErrorrR)r>rrr<00> increment<6E>s
zCountCallbackInvoker.incrementc CsN|j<00>>|jdkrtd<02><01>|jd8_|jr@|jdkr@|<00><04>WdQRXdS)zDecrement the count by onerz,Counter is at zero. It cannot dip below zeror'N)rPrRrUrSrQ)r>rrr<00> decrement<6E>s
zCountCallbackInvoker.decrementc Cs.|j<00>d|_|jdkr |<00><03>WdQRXdS)z<>Finalize the counter
Once finalized, the counter never be incremented and the callback
can be invoked once the count reaches zero
TrN)rPrSrRrQ)r>rrr<00>finalize<7A>s
zCountCallbackInvoker.finalizeN)
rArBrCrLr@<00>propertyrTrVrWrXrrrrrM<00>s  

rMc@sVeZdZdd<02>Zdd<04>Zddd<07>Zdd <09>Zd
d <0B>Zd d <0A>Zdd<0F>Z dd<11>Z
dd<13>Z dS)<15>OSUtilscCs tj<01>|<01>S)N)<03>os<6F>path<74>getsize)r><00>filenamerrr<00> get_file_size<7A>szOSUtils.get_file_sizecCstj||||dd<02>S)NF)<01>enable_callbacks)<02> ReadFileChunk<6E> from_filename)r>r^<00>
start_byter$r2rrr<00>open_file_chunk_reader<65>szOSUtils.open_file_chunk_readerNcCst||||d|d<02>S)NF)r2r`<00>close_callbacks)ra)r><00>fileobj<62>
chunk_size<EFBFBD>full_file_sizer2rerrr<00>#open_file_chunk_reader_from_fileobj<62>sz+OSUtils.open_file_chunk_reader_from_fileobjcCs
t||<02>S)N)<01>open)r>r^<00>moderrrrjsz OSUtils.opencCs(yt<00>|<01>Wntk
r"YnXdS)z+Remove a file, noop if file does not exist.N)r[<00>remove<76>OSError)r>r^rrr<00> remove_fileszOSUtils.remove_filecCst||<02>dS)N)r)r>Zcurrent_filenameZ new_filenamerrrrszOSUtils.rename_filecCsXtj<01>|<01>sdSt<00>|<01>j}t<03>|<02>r*dSt<03>|<02>r8dSt<03>|<02>rFdSt<03>|<02>rTdSdS)aChecks to see if a file is a special UNIX file.
It checks if the file is a character special device, block special
device, FIFO, or socket.
:param filename: Name of the file
:returns: True if the file is a special file. False, if is not.
FT) r[r\<00>exists<74>stat<61>st_mode<64>S_ISCHR<48>S_ISBLK<4C>S_ISFIFO<46>S_ISSOCK)<03>clsr^rkrrr<00>is_special_files  



zOSUtils.is_special_filecCs|tjt<02>S)N)r[<00>extsepr)r>r^rrr<00>get_temp_filename.szOSUtils.get_temp_filenamec CsPy&|<00>|d<01><02>}t||<02>WdQRXWn$ttfk
rJ|<00>|<01><00>YnXdS)N<>wb)rjrrm<00>IOErrorrn)r>r^r$<00>frrr<00>allocate1s 
zOSUtils.allocate)N) rArBrCr_rdrirjrnrrwryr}rrrrrZ<00>s
 rZc@sjeZdZddefdd<04>Zdd<06>Zedd<08><00>Zdd
d <0B>Zd d <0A>Z dd<0F>Z
dd<11>Z dd<13>Z dd<15>Z dd<17>Zd S)<19>DeferredOpenFiler<00>rbcCs"||_d|_||_||_||_dS)a<>A class that defers the opening of a file till needed
This is useful for deferring opening of a file till it is needed
in a separate thread, as there is a limit of how many open files
there can be in a single thread for most operating systems. The
file gets opened in the following methods: ``read()``, ``seek()``,
and ``__enter__()``
:type filename: str
:param filename: The name of the file to open
:type start_byte: int
:param start_byte: The byte to seek to when the file is opened.
:type mode: str
:param mode: The mode to use to open the file
:type open_function: function
:param open_function: The function to use to open the file
N)<05> _filename<6D>_fileobj<62> _start_byte<74>_mode<64>_open_function)r>r^rcrkZ open_functionrrrr@;s
zDeferredOpenFile.__init__cCs8|jdkr4|<00>|j|j<03>|_|jdkr4|j<00>|j<04>dS)Nr)r<>r<>r<>r<>r<><00>seek)r>rrr<00>_open_if_neededVs

z DeferredOpenFile._open_if_neededcCs|jS)N)r<>)r>rrr<00>name\szDeferredOpenFile.nameNcCs|<00><00>|j<01>|<01>S)N)r<>r<><00>read)r><00>amountrrrr<>`szDeferredOpenFile.readcCs|<00><00>|j<01>|<01>dS)N)r<>r<><00>write)r><00>datarrrr<>dszDeferredOpenFile.writecCs|<00><00>|j<01>|<01>dS)N)r<>r<>r<>)r><00>whererrrr<>hszDeferredOpenFile.seekcCs|jdkr|jS|j<00><02>S)N)r<>r<><00>tell)r>rrrr<>ls
zDeferredOpenFile.tellcCs|jr|j<00><01>dS)N)r<><00>close)r>rrrr<>qszDeferredOpenFile.closecCs |<00><00>|S)N)r<>)r>rrr<00> __enter__uszDeferredOpenFile.__enter__cOs |<00><00>dS)N)r<>)r>rIrrrr<00>__exit__yszDeferredOpenFile.__exit__)N)rArBrCrjr@r<>rYr<>r<>r<>r<>r<>r<>r<>r<>rrrrr~:s 
r~c@s<>eZdZd!dd<04>Zed"dd<06><01>Zdd<08>Zd#d d
<EFBFBD>Zd d <0C>Zd d<0E>Z dd<10>Z
dd<12>Z dd<14>Z dd<16>Z dd<18>Zdd<1A>Zdd<1C>Zdd<1E>Zdd <20>ZdS)$raNTcCsb||_|j<00><01>|_|j|j||j|d<01>|_d|_||_|dkrDg|_||_||_|dkr^||_dS)a<>
Given a file object shown below::
|___________________________________________________|
0 | | full_file_size
|----chunk_size---|
f.tell()
:type fileobj: file
:param fileobj: File like object
:type chunk_size: int
:param chunk_size: The max chunk size to read. Trying to read
pass the end of the chunk size will behave like you've
reached the end of the file.
:type full_file_size: int
:param full_file_size: The entire content length associated
with ``fileobj``.
:type callbacks: A list of function(amount_read)
:param callbacks: Called whenever data is read from this object in the
order provided.
:type enable_callbacks: boolean
:param enable_callbacks: True if to run callbacks. Otherwise, do not
run callbacks
:type close_callbacks: A list of function()
:param close_callbacks: Called when close is called. The function
should take no arguments.
)<03>requested_sizerc<00>actual_file_sizerN) r<>r<>r<><00>_calculate_file_size<7A>_size<7A> _amount_read<61>
_callbacks<EFBFBD>_callbacks_enabled<65>_close_callbacks)r>rfrgrhr2r`rerrrr@~s# zReadFileChunk.__init__cCs4t|d<01>}|<06>|<02>t<02>|<06><04><00>j}||||||<05>S)a[Convenience factory function to create from a filename.
:type start_byte: int
:param start_byte: The first byte from which to start reading.
:type chunk_size: int
:param chunk_size: The max chunk size to read. Trying to read
pass the end of the chunk size will behave like you've
reached the end of the file.
:type full_file_size: int
:param full_file_size: The entire content length associated
with ``fileobj``.
:type callbacks: function(amount_read)
:param callbacks: Called whenever data is read from this object.
:type enable_callbacks: bool
:param enable_callbacks: Indicate whether to invoke callback
during read() calls.
:rtype: ``ReadFileChunk``
:return: A new instance of ``ReadFileChunk``
r)rjr<>r[<00>fstat<61>fileno<6E>st_size)rvr^rcrgr2r`r|<00> file_sizerrrrb<00>s

zReadFileChunk.from_filenamecCs||}t||<02>S)N)<01>min)r>rfr<>rcr<>Zmax_chunk_sizerrrr<><00>sz"ReadFileChunk._calculate_file_sizecCsj|dkr|j|j}nt|j|j|<01>}|j<03>|<02>}|jt|<03>7_|jdk rf|jrft|jt|<03><01>|S)N) r<>r<>r<>r<>r<><00>lenr<6E>r<>r7)r>r<>Zamount_to_readr<64>rrrr<><00>s zReadFileChunk.readcCs"|<00><00>t|jd<01>r|j<02><03>dS)Nr)<04>enable_callbackrr<>r)r>rrrr<00>s z!ReadFileChunk.signal_transferringcCs"|<00><00>t|jd<01>r|j<02><03>dS)Nr)<04>disable_callbackrr<>r)r>rrrr<00>s z%ReadFileChunk.signal_not_transferringcCs
d|_dS)NT)r<>)r>rrrr<><00>szReadFileChunk.enable_callbackcCs
d|_dS)NF)r<>)r>rrrr<><00>szReadFileChunk.disable_callbackcCs@|j<00>|j|<00>|jdk r6|jr6t|j||jd<01>||_dS)N)r5)r<>r<>r<>r<>r<>r7r<>)r>r<>rrrr<><00>s
zReadFileChunk.seekcCs4|jdk r&|jr&x|jD]
}|<01>qW|j<02><03>dS)N)r<>r<>r<>r<>)r>r6rrrr<><00>s 
zReadFileChunk.closecCs|jS)N)r<>)r>rrrr<><00>szReadFileChunk.tellcCs|jS)N)r<>)r>rrr<00>__len__szReadFileChunk.__len__cCs|S)Nr)r>rrrr<> szReadFileChunk.__enter__cOs |<00><00>dS)N)r<>)r>rIrrrrr<> szReadFileChunk.__exit__cCstg<00>S)N)<01>iter)r>rrr<00>__iter__szReadFileChunk.__iter__)NTN)NT)N)rArBrCr@<00> classmethodrbr<>r<>rrr<>r<>r<>r<>r<>r<>r<>r<>r<>rrrrra}s"
0 
rac@s"eZdZdZddd<04>Zdd<06>ZdS)<08>StreamReaderProgressz<Wrapper for a read only stream that adds progress callbacks.NcCs||_||_|dkrg|_dS)N)<02>_streamr<6D>)r><00>streamr2rrrr@szStreamReaderProgress.__init__cOs"|jj||<02>}t|jt|<03><01>|S)N)r<>r<>r7r<>r<>)r>rIrr:rrrr<> szStreamReaderProgress.read)N)rArBrCrLr@r<>rrrrr<>s
r<>c@s eZdZdS)<02>NoResourcesAvailableN)rArBrCrrrrr<>&sr<>c@s&eZdZdd<02>Zd dd<05>Zdd<07>ZdS)
<EFBFBD> TaskSemaphorecCst<00>|<01>|_dS)zqA semaphore for the purpose of limiting the number of tasks
:param count: The size of semaphore
N)rN<00> Semaphore<72>
_semaphore)r><00>countrrrr@+szTaskSemaphore.__init__TcCs(t<00>d|<01>|j<02>|<02>s$td|<00><01>dS)a<>Acquire the semaphore
:param tag: A tag identifying what is acquiring the semaphore. Note
that this is not really needed to directly use this class but is
needed for API compatibility with the SlidingWindowSemaphore
implementation.
:param block: If True, block until it can be acquired. If False,
do not block and raise an exception if cannot be aquired.
:returns: A token (can be None) to use when releasing the semaphore
z Acquiring %szCannot acquire tag '%s'N)<05>logger<65>debugr<67><00>acquirer<65>)r><00>tag<61>blockingrrrr<>2s  zTaskSemaphore.acquirecCs t<00>d||f<00>|j<02><03>dS)atRelease the semaphore
:param tag: A tag identifying what is releasing the semaphore
:param acquire_token: The token returned from when the semaphore was
acquired. Note that this is not really needed to directly use this
class but is needed for API compatibility with the
SlidingWindowSemaphore implementation.
zReleasing acquire %s/%sN)r<>r<>r<><00>release)r>r<><00> acquire_tokenrrrr<>Bs zTaskSemaphore.releaseN)T)rArBrCr@r<>r<>rrrrr<>*s
r<>c@s2eZdZdZdd<03>Zdd<05>Zd dd<08>Zd d
<EFBFBD>Zd S) <0A>SlidingWindowSemaphorea<65>A semaphore used to coordinate sequential resource access.
This class is similar to the stdlib BoundedSemaphore:
* It's initialized with a count.
* Each call to ``acquire()`` decrements the counter.
* If the count is at zero, then ``acquire()`` will either block until the
count increases, or if ``blocking=False``, then it will raise
a NoResourcesAvailable exception indicating that it failed to acquire the
semaphore.
The main difference is that this semaphore is used to limit
access to a resource that requires sequential access. For example,
if I want to access resource R that has 20 subresources R_0 - R_19,
this semaphore can also enforce that you only have a max range of
10 at any given point in time. You must also specify a tag name
when you acquire the semaphore. The sliding window semantics apply
on a per tag basis. The internal count will only be incremented
when the minimum sequence number for a tag is released.
cCs8||_tt<02>|_i|_t<05><06>|_t<05>|j<07>|_ i|_
dS)N) rRrr <00>_tag_sequences<65>_lowest_sequencerNrOrP<00> Condition<6F>
_condition<EFBFBD>_pending_release)r>r<>rrrr@es 

zSlidingWindowSemaphore.__init__c Cs|j<00>|jSQRXdS)N)rPrR)r>rrrrTosz$SlidingWindowSemaphore.current_countTcCs<>t<00>d|<01>|j<02><03>zv|jdkrN|s4td|<00><01>nx|jdkrL|j<02><06>q6W|j|}|dkrj||j|<|j|d7<|jd8_|S|j<02> <09>XdS)Nz Acquiring %srzCannot acquire tag '%s'r')
r<EFBFBD>r<>r<>r<>rRr<><00>waitr<74>r<>r<>)r>r<>r<><00>sequence_numberrrrr<>ss 

 

zSlidingWindowSemaphore.acquirecCs<|}t<00>d||<03>|j<02><03><00>z ||jkr6td|<00><01>|j|}|j||kr<>|j|d7<|jd7_|j<02><08>|j <09>
|g<00>}x<>|r<>|j||dkr<>|<05> <0B>|j|d7<|jd7_q<>Pq<>WnX|j||kr<>|k<00>rnn(|j <09> |g<00><02> |<03>|j |jdd<06>ntd||f<00><01>Wd|j<02><0F>XdS)NzReleasing acquire %s/%sz$Attempted to release unknown tag: %sr'<00><><EFBFBD><EFBFBD><EFBFBD>T)<01>reversez;Attempted to release unknown sequence number %s for tag: %s)r<>r<>r<>r<>r<><00>
ValueErrorr<EFBFBD>rR<00>notifyr<79><00>get<65>pop<6F>
setdefaultr.<00>sortr<74>)r>r<>r<>r<>Z max_sequenceZqueuedrrrr<><00>s4

 

 zSlidingWindowSemaphore.releaseN)T)rArBrCrLr@rTr<>r<>rrrrr<>Os


r<>c@s6eZdZeeefdd<02>Zd
dd<05>Zdd<07>Zdd <09>Z dS) <0B>ChunksizeAdjustercCs||_||_||_dS)N)<03>max_size<7A>min_size<7A> max_parts)r>r<>r<>r<>rrrr@<00>szChunksizeAdjuster.__init__NcCs"|}|dk r|<00>||<02>}|<00>|<03>S)a<>Get a chunksize close to current that fits within all S3 limits.
:type current_chunksize: int
:param current_chunksize: The currently configured chunksize.
:type file_size: int or None
:param file_size: The size of the file to upload. This might be None
if the object being transferred has an unknown size.
:returns: A valid chunksize that fits within configured limits.
N)<02>_adjust_for_max_parts<74>_adjust_for_chunksize_limits)r><00>current_chunksizer<65><00> chunksizerrr<00>adjust_chunksize<7A>s  z"ChunksizeAdjuster.adjust_chunksizecCsP||jkr$t<01>d|j|f<00>|jS||jkrHt<01>d|j|f<00>|jS|SdS)Nz@Chunksize greater than maximum chunksize. Setting to %s from %s.z=Chunksize less than minimum chunksize. Setting to %s from %s.)r<>r<>r<>r<>)r>r<>rrrr<><00>s

z.ChunksizeAdjuster._adjust_for_chunksize_limitscCsf|}tt<01>|t|<03><00><01>}x,||jkrF|d9}tt<01>|t|<03><00><01>}qW||krbt<05>d||f<00>|S)N<>z[Chunksize would result in the number of parts exceeding the maximum. Setting to %s from %s.)r r!r"r#r<>r<>r<>)r>r<>r<>r<>r)rrrr<><00>s  z'ChunksizeAdjuster._adjust_for_max_parts)N)
rArBrC<00>MAX_SINGLE_UPLOAD_SIZE<5A>MIN_UPLOAD_CHUNKSIZE<5A> MAX_PARTSr@r<>r<>r<>rrrrr<><00>s

r<>)r )N)2r <00>timer/r!r[<00>socketrpr <00>loggingrN<00>io<69> collectionsrZbotocore.exceptionsrrZs3transfer.compatrrrrr<>r<>r<><00> getLoggerrAr<><00>timeoutZS3_RETRYABLE_DOWNLOAD_ERRORSrrrr&r*r4r7r;<00>objectr<rDrMrZr~rar<><00> Exceptionr<6E>r<>r<>r<>rrrr<00><module> sT       


 0IC%_