• File: progress.cpython-37.pyc
  • Full Path: /home3/farmfre2/public_html/ALFA_DATA/alfasymlink/root/opt/alt/python37/lib/python3.7/site-packages/paste/__pycache__/progress.cpython-37.pyc
  • Date Modified: 12/01/2019 7:09 PM
  • File size: 7.94 KB
  • MIME-type: text/x-bytecode.python
  • Charset: 8 bit
B

aN@sdZddlZddlmZdZdZdZdZdZGd	d
d
e	Z
Gddde	ZGd
dde	ZddgZ
dekrddlZejejddS)a~
Upload Progress Monitor

This is a WSGI middleware component which monitors the status of files
being uploaded.  It includes a small query application which will return
a list of all files being uploaded by particular session/user.

>>> from paste.httpserver import serve
>>> from paste.urlmap import URLMap
>>> from paste.auth.basic import AuthBasicHandler
>>> from paste.debug.debugapp import SlowConsumer, SimpleApplication
>>> # from paste.progress import *
>>> realm = 'Test Realm'
>>> def authfunc(username, password):
...     return username == password
>>> map = URLMap({})
>>> ups = UploadProgressMonitor(map, threshold=1024)
>>> map['/upload'] = SlowConsumer()
>>> map['/simple'] = SimpleApplication()
>>> map['/report'] = UploadProgressReporter(ups)
>>> serve(AuthBasicHandler(ups, realm, authfunc))
serving on...

.. note::

   This is experimental, and will change in the future.
N)catch_errorsii,zpaste.bytes_receivedzpaste.request_startedzpaste.request_finishedc@s<eZdZdZddZddZdddZd	d
Zddd
ZdS)
_ProgressFilezy
    This is the input-file wrapper used to record the number of
    ``paste.bytes_received`` for the given request.
    cCs(||_||_|j|_|j|_|j|_dS)N)_ProgressFile_environ_ProgressFile_rfileflushwrite
writelines)selfenvironZrfiler?/opt/alt/python37/lib/python3.7/site-packages/paste/progress.py__init__1s
z_ProgressFile.__init__cs&|jt|jfdd}t|S)Nc3s,x&D]}tt|7<|VqWdS)N)ENVIRON_RECEIVEDlen)chunk)r
riterrriterwrap;s
z(_ProgressFile.__iter__.<locals>.iterwrap)riterr)r	rr)r
rr__iter__8s
z_ProgressFile.__iter__cCs&|j|}|jtt|7<|S)N)rreadrrr)r	sizerrrrrAsz_ProgressFile.readcCs$|j}|jtt|7<|S)N)rreadlinerrr)r	rrrrrFs
z_ProgressFile.readlineNcCs&|j|}|jtt|7<|S)N)r	readlinesrrr)r	ZhintrrrrrKsz_ProgressFile.readlines)r)N)	__name__
__module____qualname____doc__r
rrrrrrrrr+s	
rc@s*eZdZdZd	ddZddZddZdS)
UploadProgressMonitora<
    monitors and reports on the status of uploads in progress

    Parameters:

        ``application``

            This is the next application in the WSGI stack.

        ``threshold``

            This is the size in bytes that is needed for the
            upload to be included in the monitor.

        ``timeout``

            This is the amount of time (in seconds) that a upload
            remains in the monitor after it has finished.

    Methods:

        ``uploads()``

            This returns a list of ``environ`` dict objects for each
            upload being currently monitored, or finished but whose time
            has not yet expired.

    For each request ``environ`` that is monitored, there are several
    variables that are stored:

        ``paste.bytes_received``

            This is the total number of bytes received for the given
            request; it can be compared with ``CONTENT_LENGTH`` to
            build a percentage complete.  This is an integer value.

        ``paste.request_started``

            This is the time (in seconds) when the request was started
            as obtained from ``time.time()``.  One would want to format
            this for presentation to the user, if necessary.

        ``paste.request_finished``

            This is the time (in seconds) when the request was finished,
            canceled, or otherwise disconnected.  This is None while
            the given upload is still in-progress.

    TODO: turn monitor into a queue and purge queue of finished
          requests that have passed the timeout period.
    NcCs$||_|pt|_|pt|_g|_dS)N)applicationDEFAULT_THRESHOLD	thresholdDEFAULT_TIMEOUTtimeoutmonitor)r	rr!r#rrrr
s

zUploadProgressMonitor.__init__csdd}|rxt||jkrx|jdt<tt<dt<t	dd<dfdd	}t
|j|||S||S)NCONTENT_LENGTHrz
wsgi.inputcstt<dS)N)timeREQUEST_FINISHED)exc_info)r
rr	finalizersz1UploadProgressMonitor.__call__.<locals>.finalizer)N)getintr!r$appendrr&REQUEST_STARTEDr'rrr)r	r
start_responselengthr)r)r
r__call__s
zUploadProgressMonitor.__call__cCs|jS)N)r$)r	rrruploadsszUploadProgressMonitor.uploads)NN)rrrrr
r0r1rrrrrPs3
rc@s0eZdZdZddZddZddZdd	Zd
S)UploadProgressReporterag
    reports on the progress of uploads for a given user

    This reporter returns a JSON file (for use in AJAX) listing the
    uploads in progress for the given user.  By default, this reporter
    uses the ``REMOTE_USER`` environment to compare between the current
    request and uploads in-progress.  If they match, then a response
    record is formed.

        ``match()``

            This member function can be overriden to provide alternative
            matching criteria.  It takes two environments, the first
            is the current request, the second is a current upload.

        ``report()``

            This member function takes an environment and builds a
            ``dict`` that will be used to create a JSON mapping for
            the given upload.  By default, this just includes the
            percent complete and the request url.

    cCs
||_dS)N)r$)r	r$rrrr
szUploadProgressReporter.__init__cCs |dd|ddkrdSdS)NZREMOTE_USERrTF)r*)r	Zsearch_environZupload_environrrrmatchs
zUploadProgressReporter.matchc	Csdtdt|td|d|t|dd|ddd}|t}|r`tdt||d<|S)	Nz%Y-%m-%d %H:%M:%Sr%Z	PATH_INFOZQUERY_STRING)startedfinishedZcontent_lengthZbytes_receivedZ	path_infoZquery_stringz%Y:%m:%d %H:%M:%Sr6)r&strftimegmtimer-r*rr')r	r
retvalr6rrrreports
zUploadProgressReporter.reportcsg}xzfddjDD]\}g}x>|D]2\}}t|dddd}|d||fq2W|dd	|q Wd
d	|}|ddd
t|fg|gS)Ncs"g|]}|r|qSr)r3r:).0env)r
r	rr
<listcomp>sz3UploadProgressReporter.__call__.<locals>.<listcomp>\z\\"z\"z%s: "%s"z{ %s }z, z[ %s ]z200 OK)zContent-Typez
text/plainzContent-Length)r$r1itemsstrreplacer,joinr)r	r
r.bodymappartskvr)r
r	rr0s zUploadProgressReporter.__call__N)rrrrr
r3r:r0rrrrr2s
r2__main__)Zoptionflags)rr&Z
paste.wsgilibrr r"rr-r'objectrrr2__all__rZdoctestZtestmodELLIPSISrrrr<module>!s%M=