+
    Bi                         R t ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RI	t	^ RI
Ht  ! R R]P                  P                  4      tR# )z8Utilities for using Motor with Tornado web applications.N)_hash_gridoutc                   P   a  ] tR t^&t o RtR
R ltR tRR ltR tR t	R t
RtV tR	# )GridFSHandleraF  A handler that can serve content from GridFS, very similar to
:class:`tornado.web.StaticFileHandler`.

.. code-block:: python

    db = motor.MotorClient().my_database
    application = web.Application(
        [
            (r"/static/(.*)", web.GridFSHandler, {"database": db}),
        ]
    )

By default, requests' If-Modified-Since headers are honored, but no
specific cache-control timeout is sent to clients. Thus each request for
a GridFS file requires a quick check of the file's ``uploadDate`` in
MongoDB. Override :meth:`get_cache_time` in a subclass to customize this.
c                    Wn         W n        R # )Ndatabaseroot_collection)selfr   r   s   &&&G/var/www/html/photoedit/myenv/lib/python3.14/site-packages/motor/web.py
initializeGridFSHandler.initialize9   s     .    c                $    VP                  V4      # )aS  Overridable method to choose a GridFS file to serve at a URL.

By default, if a URL pattern like ``"/static/(.*)"`` is mapped to this
``GridFSHandler``, then the trailing portion of the URL is used as the
filename, so a request for "/static/image.png" results in a call to
:meth:`MotorGridFSBucket.open_download_stream_by_name` with "image.png"
as the ``filename`` argument. To customize the mapping of path to
GridFS file, override ``get_gridfs_file`` and return a Future
:class:`~motor.MotorGridOut` from it.

For example, to retrieve the file by ``_id`` instead of filename::

    class CustomGridFSHandler(motor.web.GridFSHandler):
        def get_gridfs_file(self, bucket, filename, request):
            # Path is interpreted as _id instead of name.
            # Return a Future MotorGridOut.
            return fs.open_download_stream(file_id=ObjectId(path))

:Parameters:
  - `bucket`: A :class:`~motor.motor_tornado.MotorGridFSBucket`
  - `filename`: A string, the matched group of the URL pattern
  - `request`: An :class:`tornado.httputil.HTTPServerRequest`

.. versionchanged:: 1.0
  **BREAKING CHANGE**: Now takes a
  :class:`~motor.motor_tornado.MotorGridFSBucket`, not a
  ``MotorGridFS``.
  Also takes an additional ``request`` parameter.

.. versionchanged:: 0.2
   ``get_gridfs_file`` no longer accepts a callback, instead returns
   a Future.
)open_download_stream_by_name)r	   bucketfilenamerequests   &&&&r
   get_gridfs_fileGridFSHandler.get_gridfs_file=   s    D 228<<r   c                  "   \         P                  ! V P                  V P                  4      p V P	                  W1V P
                  4      G R j  xL
 pTP                  P                  ^ R7      pT P                  RT4       \        T4      pT P                  RRT,          4       TP                  pTf   \         P"                  ! T4      w  rxT'       d   T P                  RT4       T P%                  YT4      p	T	^ 8  d   T P                  R\&        P&                  P)                  \&        P*                  P,                  4      P                  R R7      \&        P.                  ! T	R	7      ,           4       T P                  R
R\1        T	4      ,           4       MT P                  R
R4       T P3                  Y4       T P
                  P4                  P7                  R4      p
T
e   \8        P:                  P=                  T
4      p\&        P&                  P?                  \@        PB                  ! T4      4      P                  TPD                  R7      pY8  d   T PG                  R4       R # T P
                  P4                  P7                  R4      pTe*   TPI                  R4      T8X  d   T PG                  R4       R # T P                  RTPJ                  4       T'       d   TPM                  T 4      G R j  xL
  T PO                  4        R #  EL  \        P                   d"    \        P                  P                  R4      R hi ; i LR5i)Ni  )microsecondzLast-ModifiedEtagz"%s"zContent-TypeExpires)tzinfo)secondszCache-Controlzmax-age=publiczIf-Modified-Sincei0  zIf-None-Match"zContent-Length)(motorMotorGridFSBucketr   r   r   r   gridfsNoFiletornadoweb	HTTPErrorupload_datereplace
set_headerr   content_type	mimetypes
guess_typeget_cache_timedatetimenowtimezoneutc	timedeltastrset_extra_headersheadersgetemailutils	parsedatefromtimestamptimemktimer   
set_statusstriplengthstream_to_handlerfinish)r	   pathinclude_bodyfsgridoutmodifiedchecksum	mime_typeencoding
cache_time	ims_value
date_tupleif_sinceetags   &&&           r
   r3   GridFSHandler.geta   s    $$T]]D4H4HI	7 004<<HHG
 &&..1.=2 !) 12((	 "+"6"6t"<I OONI6((C
>OO!!%%h&7&7&;&;<DDDDQ$$Z89
 OOOZ#j/-IJOOOX6t- LL((,,-@A	 ..y9J  ((66t{{:7NOWW X H #$ ||##''8

38 ;OOC ('..9++D111
 	E I}} 	7++'',$6	7x 2sH   ,ML LL BMHMM1M2ML 6MMc                (    V P                  VR R7      # )F)r@   )r3   )r	   r?   s   &&r
   headGridFSHandler.head   s    xx5x11r   c                    ^ # )zOverride to customize cache control behavior.

Return a positive number of seconds to trigger aggressive caching or 0
to mark resource as cacheable, only. 0 is the default.
 )r	   r?   rC   rE   s   &&&&r
   r*   GridFSHandler.get_cache_time   s     r   c                    R# )z1For subclass to add extra headers to the responseNrQ   )r	   r?   rB   s   &&&r
   r1   GridFSHandler.set_extra_headers   s    r   r   N)rA   )T)__name__
__module____qualname____firstlineno____doc__r   r   r3   rN   r*   r1   __static_attributes____classdictcell__)__classdict__s   @r
   r   r   &   s2     $/"=HFP2@ @r   r   )rY   r+   email.utilsr4   r(   r8   r   tornado.webr!   r   motor.motor_gridfsr   r"   RequestHandlerr   rQ   r   r
   <module>ra      s<    ?        ,P@GKK.. P@r   