
    qi8                        S r SSKrSSKrSSKrSSKrSSKJrJr  SSKJ	r	  SSK
JrJr  SSKJrJr  SSKJrJrJrJrJr  SSKJr  S	r\R2                  " \5      r/ S
QrSS/r " S S\5      r " S S\5      r " S S\5      r  " S S\5      r!g)a=	  
Abstract base class for DAV resource providers.

This module serves these purposes:

  1. Documentation of the DAVProvider interface
  2. Common base class for all DAV providers
  3. Default implementation for most functionality that a resource provider must
     deliver.

If no default implementation can be provided, then all write actions generate
FORBIDDEN errors. Read requests generate NOT_IMPLEMENTED errors.


**_DAVResource, DAVCollection, DAVNonCollection**

Represents an existing (i.e. mapped) WebDAV resource or collection.

A _DAVResource object is created by a call to the DAVProvider.

The resource may then be used to query different attributes like ``res.name``,
``res.is_collection``, ``res.get_content_length()``, and ``res.support_etag()``.

It also implements operations, that require an *existing* resource, like:
``get_preferred_path()``, ``create_collection()``, or ``get_property_value()``.

Usage::

    res = provider.get_resource_inst(path, environ)
    if res is not None:
        print(res.getName())



**DAVProvider**

A DAV provider represents a shared WebDAV system.

There is only one provider instance per share, which is created during
server start-up. After that, the dispatcher (``request_resolver.RequestResolver``)
parses the request URL and adds it to the WSGI environment, so it
can be accessed like this::

    provider = environ["wsgidav.provider"]

The main purpose of the provider is to create _DAVResource objects for URLs::

    res = provider.get_resource_inst(path, environ)


**Supporting Objects**
The DAVProvider takes two supporting objects:

propertyManager
   An object that provides storage for dead properties assigned for webDAV resources.

   PropertyManagers must provide the methods as described in
   ``wsgidav.interfaces.propertymanagerinterface``

   See prop_man.property_manager.PropertyManager for a sample implementation
   using shelve.

lockManager
   An object that implements locking on webDAV resources.
   It contains an instance of ``LockStorageDict``

lockStorage
   An object that provides storage for locks made on webDAV resources.

   LockStorages must provide the methods as described in
   ``wsgidav.interfaces.lockmanagerinterface``

   See lock_storage for a sample implementation using shelve.

See :doc:`reference_guide` for more information about the WsgiDAV architecture.
    N)ABCabstractmethod)Optional)quoteunquote)util	xml_tools)HTTP_FORBIDDENHTTP_NOT_FOUNDDAVError#PRECONDITION_CODE_ProtectedPropertyas_DAVError)etreereStructuredText){DAV:}creationdate{DAV:}displayname{DAV:}getcontenttype{DAV:}resourcetype{DAV:}getlastmodified{DAV:}getcontentlength{DAV:}getetagz{DAV:}getcontentlanguage{DAV:}lockdiscovery{DAV:}supportedlockc                      \ rS rSrSrS\S\S\4S jrS r	\
S\\   4S	 j5       rS\\   4S
 jrS\\   4S jrS rS\4S jrS rS rS\\   4S jrS\\   4S jrS rS rS rS rS rS rS rS rS rS r S r!S r"S r#SSS S!S S".S# jr$S$ r%S%S&.S' jr&S( r'S S).S* jr(S+ r)S, r*S- r+S. r,S/ r-S0 r.S1 r/S%S2.S3 jr0S4 r1S5 r2S6 r3S7 r4S8 r5S9 r6S: r7S; r8S< r9S= r:S> r;S?r<g%)@_DAVResourcez   a  Represents a single existing DAV resource instance.

A resource may be a collection (aka 'folder') or a non-collection (aka
'file').
_DAVResource is the common base class for the specialized classes::

    _DAVResource
      +- DAVCollection
      \- DAVNonCollection

Instances of this class are created through the DAVProvider::

    res = provider.get_resource_inst(path, environ)
    if res and res.is_collection():
        print(res.get_display_name())

In the example above, res will be ``None``, if the path cannot be mapped to
an existing resource.
The following attributes and methods are considered 'cheap'::

    res.path
    res.provider
    res.name
    res.is_collection
    res.environ

Querying other attributes is considered 'expensive' and may be delayed until
the first access.

    get_content_length()
    get_content_type()
    get_creation_date()
    get_display_name()
    get_etag()
    get_used_bytes()
    get_available_bytes()
    get_last_modified()
    support_ranges()

    support_etag()
    support_modified()
    support_content_length()

These functions return ``None``, if the property is not available, or
not supported.

See also DAVProvider.get_resource_inst().
pathis_collectionenvironc                     [         R                  " U5      (       d   eUS:X  d  UR                  S5      (       d   eUS   U l        Xl        X l        X0l        [         R                  " U R                  5      U l        g )N /zwsgidav.provider)	r   is_str
startswithproviderr   r   r   get_uri_namename)selfr   r   r   s       I/home/kali/flask_env/lib/python3.13/site-packages/wsgidav/dav_provider.py__init___DAVResource.__init__   se    {{4    rzT__S1111%,-?%@	#0$**4995	    c                 P    U R                   R                   SU R                  < S3$ )N())	__class____name__r   r(   s    r)   __repr___DAVResource.__repr__   s$    ..))*!DII=::r,   returnc                 2    U R                   (       a  g[        e)a  Contains the Content-Length header returned by a GET without accept
headers.

The getcontentlength property MUST be defined on any DAV compliant
resource that returns the Content-Length header in response to a GET.

This method MUST be implemented by non-collections only.
Nr   NotImplementedErrorr2   s    r)   get_content_length_DAVResource.get_content_length        !!r,   c                 2    U R                   (       a  g[        e)aQ  Contains the Content-Type header returned by a GET without accept
headers.

This getcontenttype property MUST be defined on any DAV compliant
resource that returns the Content-Type header in response to a GET.
See http://www.webdav.org/specs/rfc4918.html#PROPERTY_getcontenttype

This method MUST be implemented by non-collections only.
Nr7   r2   s    r)   get_content_type_DAVResource.get_content_type   r;   r,   c                     g)a>  Records the time and date the resource was created.

The creationdate property should be defined on all DAV compliant
resources. If present, it contains a timestamp of the moment when the
resource was created (i.e., the moment it had non-null state).

This method SHOULD be implemented, especially by non-collections.
N r2   s    r)   get_creation_date_DAVResource.get_creation_date   s     r,   c                 *    U R                   (       d   eg)zReturn a list of dictionaries with information for directory
rendering.

This default implementation return None, so the dir browser will
traverse all members.

This method COULD be implemented for collection resources.
N)r   r2   s    r)   get_directory_info_DAVResource.get_directory_info   s     !!!!r,   c                     U R                   $ )aT  Provides a name for the resource that is suitable for presentation to
a user.

The displayname property should be defined on all DAV compliant
resources. If present, the property contains a description of the
resource that is suitable for presentation to a user.

This default implementation returns `name`, which is the last path
segment.
)r'   r2   s    r)   get_display_name_DAVResource.get_display_name   s     yyr,   c                    U R                   (       a  SS0$ [        R                  U R                  ;   aP  U R                  R	                  [        R                  5      S   R                  5       n[        U5      S:  a  SU S30$ SS0$ )zReturn additional info dictionary for displaying (optional).

This information is not part of the DAV specification, but meant for use
by the dir browser middleware.

This default implementation returns ``{'type': '...'}``
type	Directory   z-FileFile)r   osextsepr'   splitupperlen)r(   exts     r)   get_display_info_DAVResource.get_display_info  ss     K((YY$))#))//")),R0668C3x!|3%u..r,   c                     g)z
See http://www.webdav.org/specs/rfc4918.html#PROPERTY_getetag

This method SHOULD be implemented, especially by non-collections.
Nr@   r2   s    r)   get_etag_DAVResource.get_etag       r,   c                     g)zReturn used bytes of the DAV collection.
See http://www.webdav.org/specs/rfc4331.html#quota-used-bytes

This method COULD be implemented for collection resources.
Nr@   r2   s    r)   get_used_bytes_DAVResource.get_used_bytes  rZ   r,   c                     g)zReturn available bytes of the DAV collection.
See http://www.webdav.org/specs/rfc4331.html#quota-available-bytes

This method COULD be implemented for collection resources.
Nr@   r2   s    r)   get_available_bytes _DAVResource.get_available_bytes!  rZ   r,   c                     g)aR  Contains the Last-Modified header returned by a GET method without
accept headers.

Return None, if this live property is not supported.

Note that the last-modified date on a resource may reflect changes in
any part of the state of the resource, not necessarily just a change to
the response to the GET method. For example, a change in a property may
cause the last-modified date to change. The getlastmodified property
MUST be defined on any DAV compliant resource that returns the
Last-Modified header in response to a GET.

This method SHOULD be implemented, especially by non-collections.
Nr@   r2   s    r)   get_last_modified_DAVResource.get_last_modified)  s     r,   c                     gNFr@   r2   s    r)   is_link_DAVResource.is_link:      r,   c                    [         e)z@Set last modified time for destPath to timeStamp on epoch-formatr8   )r(   	dest_path
time_stampdry_runs       r)   set_last_modified_DAVResource.set_last_modified=      !!r,   c                     [         e)z|Return True, if this non-resource supports Range on GET requests.

This method MUST be implemented by non-collections only.
rj   r2   s    r)   support_ranges_DAVResource.support_rangesA  
    
 "!r,   c                 &    U R                  5       SL$ )zReturn True, if this resource supports Content-Length.

This default implementation checks `self.get_content_length() is None`.
N)r9   r2   s    r)   support_content_length#_DAVResource.support_content_lengthH  s    
 &&(44r,   c                     [         e)z-Return True, if this resource supports ETags.rj   r2   s    r)   support_etag_DAVResource.support_etagO  rp   r,   c                 &    U R                  5       SL$ )zReturn True, if this resource supports last modified dates.

This default implementation checks `self.get_last_modified() is None`.
N)rb   r2   s    r)   support_modified_DAVResource.support_modifiedU  s    
 %%'t33r,   c                     U R                   S;   a  gU R                  (       a/  U R                   R                  S5      (       d  U R                   S-   $ U R                   $ )ax  Return preferred mapping for a resource mapping.

Different URLs may map to the same resource, e.g.:
    '/a/b' == '/A/b' == '/a/b/'
get_preferred_path() returns the same value for all these variants, e.g.:
    '/a/b/'   (assuming resource names considered case insensitive)

@param path: a UTF-8 encoded, unquoted byte string.
@return: a UTF-8 encoded, unquoted byte string.
r!   r"   r"   )r   r   endswithr2   s    r)   get_preferred_path_DAVResource.get_preferred_path\  sJ     99	!dii&8&8&=&=99s?" yyr,   c                 b    [        U R                  R                  U R                  5       -   5      $ )a3  Return the quoted, absolute, unique URL of a resource, relative to appRoot.

Byte string, UTF-8 encoded, quoted.
Starts with a '/'. Collections also have a trailing '/'.

This is basically the same as get_preferred_path, but deals with
'virtual locations' as well.

e.g. '/a/b' == '/A/b' == '/bykey/123' == '/byguid/abc532'

get_ref_url() returns the same value for all these URLs, so it can be
used as a key for locking and persistence storage.

DAV providers that allow virtual-mappings must override this method.

See also comments in DEVELOPERS.txt glossary.
)r   r%   
share_pathr   r2   s    r)   get_ref_url_DAVResource.get_ref_urls  s'    $ T]]--0G0G0IIJJr,   c                     Sn[        U R                  R                  U R                  R                  -   U R	                  5       -   US9$ )a  Convert path to a URL that can be passed to XML responses.

Byte string, UTF-8 encoded, quoted.

See http://www.webdav.org/specs/rfc4918.html#rfc.section.8.3
We are using the path-absolute option. i.e. starting with '/'.
URI ; See section 3.2.1 of [RFC2068]
z/!*'(),$-_|.)safe)r   r%   
mount_pathr   r   )r(   r   s     r)   get_href_DAVResource.get_href  sK     (MM$$mm&&'%%'( 	
 	
r,   c                     [         ezReturn child resource with a given name (None, if not found).

This method COULD be overridden by a derived class, for performance
reasons.
This default implementation calls self.provider.get_resource_inst().
rj   r(   r'   s     r)   
get_member_DAVResource.get_member  
     "!r,   c                     U R                   (       d  [        e/ nU R                  5        H*  nU R                  U5      nUc   eUR	                  U5        M,     U$ )zReturn a list of direct members (_DAVResource or derived objects).

This default implementation calls self.get_member_names() and
self.get_member() for each of them.
A provider COULD overwrite this for performance reasons.
)r   r8   get_member_namesr   append)r(   
memberListr'   members       r)   get_member_list_DAVResource.get_member_list  s[     !!%%
))+D__T*F%%%f% , r,   c                     [         e)zReturn list of (direct) collection member names (UTF-8 byte strings).

Every provider MUST provide this method for collection resources.
rj   r2   s    r)   r   _DAVResource.get_member_names  rt   r,   TFinfinitycollections	resourcesdepth_firstdepthadd_selfc                   US;   d   e/ nU(       a  U(       d  UR                  U 5        US:w  a  U R                  (       a  U R                  5        H  nU(       d  U R                  5         U=(       a    UR                  =(       d    U=(       a    UR                  (       + nU(       a  U(       d  UR                  U5        UR                  (       a(  US:X  a"  UR                  UR	                  UUUUSS95        U(       d  M  U(       d  M  UR                  U5        M     U(       a  U(       a  UR                  U 5        U$ )a  Return a list _DAVResource objects of a collection (children,
grand-children, ...).

This default implementation calls self.get_member_list() recursively.

This function may also be called for non-collections (with add_self=True).

:Parameters:
    depth_first : bool
        use <False>, to list containers before content.
        (e.g. when moving / copying branches.)
        Use <True>, to list content before containers.
        (e.g. when deleting branches.)
    depth : string
        '0' | '1' | 'infinity'
)01r   r   r   Fr   )r   r   r   extendget_descendants)	r(   r   r   r   r   r   reschildwants	            r)   r   _DAVResource.get_descendants  s   2 ....KJJtC<D..--/((*#;(;(; 9e&9&9"9  JJu%&&5J+>JJ--(3&/(3"'%* .  4KKJJu%' 0( JJt
r,   c                   / nUR                  S5        U R                  5       b  UR                  S5        U R                  5       b$  U R                  (       a   eUR                  S5        U R	                  5       b  UR                  S5        U R                  5       b  UR                  S5        U R                  5       b  UR                  S5        U R                  5       b  UR                  S5        U R                  5       b  UR                  S5        U R                  5       b  UR                  S	5        U R                  R                  (       a*  U R                  5       (       d  UR                  [        5        U R                  R                  (       aN  U R!                  5       nUR                  U R                  R                  R#                  X0R$                  5      5        U$ )
a  Return list of supported property names in Clark Notation.

Note that 'allprop', despite its name, which remains for
backward-compatibility, does not return every property, but only dead
properties and the live properties defined in RFC4918.

This default implementation returns a combination of:

- Supported standard live properties in the {DAV:} namespace, if the
  related getter method returns not None.
- {DAV:}lockdiscovery and {DAV:}supportedlock, if a lock manager is
  present
- If a property manager is present, then a list of dead properties is
  appended

A resource provider may override this method, to add a list of
supported custom live property names.
r   r   r   r   {DAV:}quota-used-bytes{DAV:}quota-available-bytesr   r   r   )r   rA   r9   r   r=   r\   r_   rb   rG   rX   r%   lock_managerprevent_lockingr   _lockPropertyNamesprop_managerr   get_propertiesr   )r(   
is_allproppropNameListrefUrls       r)   get_property_names_DAVResource.get_property_names
  s   ( 01!!#/ 45""$0)))) 89  ". 67 , 89##%1 =>!!#/ 78  ". 34==?&0 ==%%d.B.B.D.D 23 ==%%%%'F**99&,,O r,   N)	name_listc                8   US;   d   eUS;   a  Ub   eU R                  US:H  S9nOUc   e/ nUS:H  nU HC  n U(       a  UR                  US45        M   U R                  U5      nUR                  XV45        ME     U$ ! [         a  nUR                  XW45         SnAMk  SnAf[         al  nUR                  U[        U5      45        U R                  R                  S:  a+  [        R                  " S[        R                  5         SnAM   SnAM  SnAff = f)	a  Return properties as list of 2-tuples (name, value).

If mode is 'name', then None is returned for the value.

name
    the property name in Clark notation.
value
    may have different types, depending on the status:
    - string or unicode: for standard property values.
    - etree.Element: for complex values.
    - DAVError in case of errors.
    - None: if mode == 'name'.

@param mode: "allprop", "name", or "named"
@param name_list: list of property names in Clark Notation (required for mode 'named')

This default implementation basically calls self.get_property_names() to
get the list of names, then call self.get_property_value on each of them.
)allpropr'   named)r   r'   Nr   )r   r'      
   )r   r   get_property_valuer   	Exceptionr   r%   verbose	traceback	print_excsysstdout)r(   moder   propList	namesOnlyr'   valuees           r)   r   _DAVResource.get_propertiesA  s   ( 3333&& $$$//49;L/MI(((FN	D8OOT4L1 33D9EOOTM2    +	** 8{1~ 67==((A-''CJJ77 .8s*   A>#A>>
DB  D-ADDc           	         U R                  5       nU R                  R                  nU(       Ga?  US:X  Ga8  UR                  U5      n[        R
                  " U5      nU GH  n[        R                  " US5      n[        R                  " US5      n[        R                  " USR                  SUS   5      5        [        R                  " US5      n	[        R                  " U	SR                  SUS   5      5        US	   [        R                  " US
5      l        US   (       a*  [        R                  " US   5      n
UR                  U
5        US   nUS:  a  SnO2US   nS[        [        U[        R                  " 5       -
  5      5      -   nU[        R                  " US5      l        [        R                  " US5      nUS   [        R                  " US5      l        U R                  R                  US   5      nU R                  R!                  XR"                  5      nUR%                  5       n[        R                  " US5      nU[        R                  " US5      l        GM     U$ U(       Ga  US:X  a  [        R
                  " U5      n[        R                  " US5      n[        R                  " US5      n	[        R                  " U	S5        [        R                  " US5      n[        R                  " US5        [        R                  " US5      n[        R                  " US5      n	[        R                  " U	S5        [        R                  " US5      n[        R                  " US5        U$ UR'                  S5      (       Ga  US:X  a5  U R)                  5       b$  [*        R,                  " U R)                  5       5      $ US:X  a!  U R/                  5       b  U R/                  5       $ US:X  aA  U R0                  (       a/  [        R
                  " U5      n[        R                  " US5        U$ g US!:X  a  U R3                  5       $ US":X  a  U R5                  5       $ US#:X  a5  U R7                  5       b$  [*        R8                  " U R7                  5       5      $ US$:X  a*  U R;                  5       b  [        U R;                  5       5      $ US%:X  a!  U R=                  5       b  U R=                  5       $ US&:X  a!  U R?                  5       b  U R?                  5       $ [A        [B        5      eU R                  RD                  nU(       a5  URG                  X!U R"                  5      nUb  [        R                  " U5      $ [A        [B        5      e)'a  Return the value of a property.

name:
    the property name in Clark notation.
return value:
    may have different types, depending on the status:

    - string or unicode: for standard property values.
    - lxml.etree.Element: for complex values.

    If the property is not available, a DAVError is raised.

This default implementation handles ``{DAV:}lockdiscovery`` and
``{DAV:}supportedlock`` using the associated lock manager.

All other *live* properties (i.e. name starts with ``{DAV:}``) are
delegated to the self.xxx() getters.

Finally, other properties are considered *dead*, and are handled  by
the associated property manager.
r   z{DAV:}activelockz{DAV:}locktypez{}{}{DAV:}rJ   z{DAV:}lockscopescoper   z{DAV:}depthownertimeoutr   InfiniteexpirezSecond-z{DAV:}timeoutz{DAV:}locktokentokenz
{DAV:}hrefrootz{DAV:}lockrootr   z{DAV:}lockentryz{DAV:}exclusivez{DAV:}writez{DAV:}sharedr   r   r   z{DAV:}collectionr!   r   r   r   r   r   r   )$r   r%   r   get_url_lock_listr   Element
SubElementformattextr	   string_to_xmlr   strinttimeref_url_to_pathget_resource_instr   r   r$   rA   r   get_rfc3339_timer=   r   r\   r_   rb   get_rfc1123_timer9   rX   rG   r   r   r   get_property)r(   r'   r   lmactivelocklistlockdiscoveryELlockactivelockEL
locktypeELlockscopeELownerELr   r   locktokenELlockPathlockReslockHref
lockrootELsupportedlockELlockentryELresourcetypeELpmr   s                          r)   r   _DAVResource.get_property_valueq  s   , !!# ]]''$//  11&9N#mmD1O&$//AST"--l<LM
  V]]8T&\-RS#..|=NO  fmmHd7m.TUEI']  }=B= (55d7mDG ''0y/Q;(G "(^F'#c&499;2F.G*HHGGN  ?D#..|=NOCG=  l;@  ==88fF--99(LLQ"++-"--l<LM
BJ  \:?Q 'T #"D11 $mmD1O**?<MNK**;8IJK[*;<))+7GHJZ7**?<MNK**;8IJK[.9))+7GHJZ7""__X&&++0F0F0H0T,,T-C-C-EFF//D4I4I4K4W,,..--%%%*]]4%8N$$^5GH))11**,,66//11//D4J4J4L4X ,,T-C-C-EFF00++-9 422455(T]]_-H}}&,,1F1F1H1T,,.. >** ]]''OOF$,,?E  ..u55 ~&&r,   rm   c                z   Ub  [         R                  " U5      (       d   eU[        ;   a  [        [        [
        S9eU R                  S   nUR                  S/ 5      nUR                  S5      (       aJ  U[        ;   a@  X;   a;  US;   a&   U R                  U R                  UR                  US9$ [        [        5      eUR                  S	5      (       a  U R                  R                  S
S5      n[         R"                  " USSS9nUR                  SS5      nU(       aF  SU;  a@  SU;   a%  U R                  U R                  UR                  US9$ SU;   a  gSU;   a  gSU;   a  gU R$                  R&                  n	U	(       ax  UR                  S5      (       db  U R)                  5       n
Uc  U	R+                  XX0R                  5      $ [,        R.                  " U5      nU	R1                  XX#U R                  5      $ [        [        5      e! [         a'    [        R                  SU R                   S35         GNf = f)aB  Set a property value or remove a property.

value == None means 'remove property'.
Raise HTTP_FORBIDDEN if property is read-only, or not supported.

When dry_run is True, this function should raise errors, as in a real
run, but MUST NOT change any data.

This default implementation

- raises HTTP_FORBIDDEN, if trying to modify a locking property
- raises HTTP_FORBIDDEN, if trying to modify an immutable {DAV:}
  property
- handles Windows' Win32LastModifiedTime to set the getlastmodified
  property, if enabled
- stores everything else as dead property, if a property manager is
  present.
- raises HTTP_FORBIDDEN, else

Removing a non-existing prop is NOT an error.

Note: RFC 4918 states that {DAV:}displayname 'SHOULD NOT be protected'

A resource provider may override this method, to update supported custom
live properties.
)err_conditionzwsgidav.configmutable_live_propsr   )r   z{DAV:}last_modifiedr   z/Provider does not support set_last_modified on .z{urn:schemas-microsoft-com:}HTTP_USER_AGENTNonehotfixesT)as_dictemulate_win32_lastmodFzMiniRedir/6.1Win32LastModifiedTimeWin32FileAttributesWin32CreationTimeWin32LastAccessTime)r	   is_etree_elementr   r   r
   r   r   getr$   _standardLivePropNamesrn   r   r   r   _loggerwarningr   get_dict_valuer%   r   r   remove_propertyr   tostringwrite_property)r(   r'   r   rm   configmutableLivePropsagentr   	win32_emur   r   s              r)   set_property_value_DAVResource.set_property_value  s   6 }	 : :5 A AAA%%.Q 
 ./!::&:B? OOH%%..( GG11		5::w 2   >**
 ??9::LL$$%6?E**6:tLH %<eDI_E9*d211		5::w 2   +d2(D0*d2 ]]''dooh//%%'F}))&NNu-((ut||TT~&&K ! OOI$))TUVs   
$H	 	-H:9H:c                    U R                   R                  (       a?  U R                   R                  R                  U R                  5       U R                  5        gg)z&Remove all associated dead properties.N)r%   r   remove_propertiesr   r   r(   	recursives     r)   remove_all_properties"_DAVResource.remove_all_properties[  s>    ==%%MM&&88  "DLL &r,   c                     g)zReturn True, to prevent locking.

This default implementation returns ``False``, so standard processing
takes place: locking (and refreshing of locks) is implemented using
the lock manager, if one is configured.
Fr@   r2   s    r)   r   _DAVResource.prevent_lockingd  s     r,   c                     U R                   R                  c  gU R                   R                  R                  U R                  5       5      $ )zReturn True, if URI is locked.F)r%   r   is_url_lockedr   r2   s    r)   	is_locked_DAVResource.is_lockedm  s9    ==%%-}}))778H8H8JKKr,   c                    U R                   R                  (       a3  U R                   R                  R                  U R                  5       US9  g g )N)r  )r%   r   remove_all_locks_from_urlr   r  s     r)   remove_all_locks_DAVResource.remove_all_lockss  s@    ==%%MM&&@@  "i A  &r,   c                 F    U R                   (       d   e[        [        5      ea  Create and return an empty (length-0) resource as member of self.

Called for LOCK requests on unmapped URLs.

Preconditions (to be ensured by caller):

  - this must be a collection
  - <self.path + name> must not exist
  - there must be no conflicting locks

Returns a DAVResuource.

This method MUST be implemented by all providers that support write
access.
This default implementation simply raises HTTP_FORBIDDEN.
r   r   r
   r   s     r)   create_empty_resource"_DAVResource.create_empty_resource{  s    " !!!!~&&r,   c                 F    U R                   (       d   e[        [        5      eaA  Create a new collection as member of self.

Preconditions (to be ensured by caller):

  - this must be a collection
  - <self.path + name> must not exist
  - there must be no conflicting locks

This method MUST be implemented by all providers that support write
access.
This default implementation raises HTTP_FORBIDDEN.
r#  r   s     r)   create_collection_DAVResource.create_collection       !!!!~&&r,   c                 4    U R                   (       a   e[        e)zOpen content as a stream for reading.

Returns a file-like object / stream containing the contents of the
resource specified.
The calling application will close() the stream.

This method MUST be implemented by all providers.
r7   r2   s    r)   get_content_DAVResource.get_content  s     %%%%!!r,   content_typec                F    U R                   (       a   e[        [        5      ezsOpen content as a stream for writing.

This method MUST be implemented by all providers that support write
access.
r#  r(   r/  s     r)   begin_write_DAVResource.begin_write  s     %%%%~&&r,   c                    gzXCalled when PUT has finished writing.

This is only a notification that MAY be handled.
Nr@   r(   with_errorss     r)   	end_write_DAVResource.end_write  s    
 r,   c                     g)a
  Handle a DELETE request natively.

This method is called by the DELETE handler after checking for valid
request syntax and making sure that there are no conflicting locks and
If-headers.
Depending on the return value, this provider can control further
processing:

False:
    handle_delete() did not do anything. WsgiDAV will process the request
    by calling delete() for every resource, bottom-up.
True:
    handle_delete() has successfully performed the DELETE request.
    HTTP_NO_CONTENT will be reported to the DAV client.
List of errors:
    handle_delete() tried to perform the delete request, but failed
    completely or partially. A list of errors is returned like
    ``[ (<ref-url>, <DAVError>), ... ]``
    These errors will be reported to the client.
DAVError raised:
    handle_delete() refuses to perform the delete request. The DAVError
    will be reported to the client.

An implementation may choose to apply other semantics and return True.
For example deleting '/by_tag/cool/myres' may simply remove the 'cool'
tag from 'my_res'.
In this case, the resource might still be available by other URLs, so
locks and properties are not removed.

This default implementation returns ``False``, so standard processing
takes place.

Implementation of this method is OPTIONAL.
Fr@   r2   s    r)   handle_delete_DAVResource.handle_delete      F r,   c                 4    U R                   (       d   e[        e)zReturn True, if delete() may be called on non-empty collections
(see comments there).

This method MUST be implemented for collections (not called on
non-collections).
r7   r2   s    r)   support_recursive_delete%_DAVResource.support_recursive_delete  s     !!!!!!r,   c                     [         e)a  Remove this resource (recursive).

Preconditions (ensured by caller):

  - there are no conflicting locks or If-headers
  - if support_recursive_delete() is False, and this is a collection,
    all members have already been deleted.

When support_recursive_delete is True, this method must be prepared to
handle recursive deletes. This implies that child errors must be
reported as tuple list [ (<ref-url>, <DAVError>), ... ].
See http://www.webdav.org/specs/rfc4918.html#delete-collections

This function

  - removes this resource
  - if this is a non-empty collection, also removes all members.
    Note that this may only occur, if support_recursive_delete is True.
  - For recursive deletes, return a list of error tuples for all failed
    resource paths.
  - removes associated direct locks
  - removes associated dead properties
  - raises HTTP_FORBIDDEN for read-only resources
  - raises HTTP_INTERNAL_ERROR on error

This method MUST be implemented by all providers that support write
access.
rj   r2   s    r)   delete_DAVResource.delete  s
    : "!r,   c                    g)a  Handle a COPY request natively.

This method is called by the COPY handler after checking for valid
request syntax and making sure that there are no conflicting locks and
If-headers.
Depending on the return value, this provider can control further
processing:

False:
    handle_copy() did not do anything. WsgiDAV will process the request
    by calling copy_move_single() for every resource, bottom-up.
True:
    handle_copy() has successfully performed the COPY request.
    HTTP_NO_CONTENT/HTTP_CREATED will be reported to the DAV client.
List of errors:
    handle_copy() tried to perform the copy request, but failed
    completely or partially. A list of errors is returned like
    ``[ (<ref-url>, <DAVError>), ... ]``
    These errors will be reported to the client.
DAVError raised:
    handle_copy() refuses to perform the copy request. The DAVError
    will be reported to the client.

An implementation may choose to apply other semantics and return True.
For example copying '/by_tag/cool/myres' to '/by_tag/hot/myres' may
simply add a 'hot' tag.
In this case, the resource might still be available by other URLs, so
locks and properties are not removed.

This default implementation returns ``False``, so standard processing
takes place.

Implementation of this method is OPTIONAL.
Fr@   )r(   rk   depth_infinitys      r)   handle_copy_DAVResource.handle_copy	  r>  r,   c                    [         e)a  Copy or move this resource to destPath (non-recursive).

Preconditions (ensured by caller):

  - there must not be any conflicting locks on destination
  - overwriting is only allowed (i.e. destPath exists), when source and
    dest are of the same type ((non-)collections) and a Overwrite='T'
    was passed
  - destPath must not be a child path of this resource

This function

  - Overwrites non-collections content, if destination exists.
  - MUST NOT copy collection members.
  - MUST NOT copy locks.
  - SHOULD copy live properties, when appropriate.
    E.g. displayname should be copied, but creationdate should be
    reset if the target did not exist before.
    See http://www.webdav.org/specs/rfc4918.html#dav.properties
  - SHOULD copy dead properties.
  - raises HTTP_FORBIDDEN for read-only providers
  - raises HTTP_INTERNAL_ERROR on error

When is_move is True,

  - Live properties should be moved too (e.g. creationdate)
  - Non-collections must be moved, not copied
  - For collections, this function behaves like in copy-mode:
    destination collection must be created and properties are copied.
    Members are NOT created.
    The source collection MUST NOT be removed.

This method MUST be implemented by all providers that support write
access.
rj   r(   rk   is_moves      r)   copy_move_single_DAVResource.copy_move_single.  s    H "!r,   c                     g)aQ  Handle a MOVE request natively.

This method is called by the MOVE handler after checking for valid
request syntax and making sure that there are no conflicting locks and
If-headers.
Depending on the return value, this provider can control further
processing:

False:
    handle_move() did not do anything. WsgiDAV will process the request
    by calling delete() and copy_move_single() for every resource,
    bottom-up.
True:
    handle_move() has successfully performed the MOVE request.
    HTTP_NO_CONTENT/HTTP_CREATED will be reported to the DAV client.
List of errors:
    handle_move() tried to perform the move request, but failed
    completely or partially. A list of errors is returned like
    ``[ (<ref-url>, <DAVError>), ... ]``
    These errors will be reported to the client.
DAVError raised:
    handle_move() refuses to perform the move request. The DAVError
    will be reported to the client.

An implementation may choose to apply other semantics and return True.
For example moving '/by_tag/cool/myres' to '/by_tag/hot/myres' may
simply remove the 'cool' tag from 'my_res' and add a 'hot' tag instead.
In this case, the resource might still be available by other URLs, so
locks and properties are not removed.

This default implementation returns ``False``, so standard processing
takes place.

Implementation of this method is OPTIONAL.
Fr@   r(   rk   s     r)   handle_move_DAVResource.handle_moveT  s    H r,   c                 4    U R                   (       d   e[        e)CReturn True, if move_recursive() is available (see comments there).r7   rO  s     r)   support_recursive_move#_DAVResource.support_recursive_movez  s    !!!!!!r,   c                      [        [        5      e)a  Move this resource and members to destPath.

This method is only called, when support_recursive_move() returns True.

MOVE is frequently used by clients to rename a file without changing its
parent collection, so it's not appropriate to reset all live properties
that are set at resource creation. For example, the DAV:creationdate
property value SHOULD remain the same after a MOVE.

Preconditions (ensured by caller):

  - there must not be any conflicting locks or If-header on source
  - there must not be any conflicting locks or If-header on destination
  - destPath must not exist
  - destPath must not be a member of this resource

This method must be prepared to handle recursive moves. This implies
that child errors must be reported as tuple list
[ (<ref-url>, <DAVError>), ... ].
See http://www.webdav.org/specs/rfc4918.html#move-collections

This function

  - moves this resource and all members to destPath.
  - MUST NOT move associated locks.
    Instead, if the source (or children thereof) have locks, then
    these locks should be removed.
  - SHOULD maintain associated live properties, when applicable
    See http://www.webdav.org/specs/rfc4918.html#dav.properties
  - MUST maintain associated dead properties
  - raises HTTP_FORBIDDEN for read-only resources
  - raises HTTP_INTERNAL_ERROR on error

An implementation may choose to apply other semantics.
For example copying '/by_tag/cool/myres' to '/by_tag/new/myres' may
simply add a 'new' tag to 'my_res'.

This method is only called, when self.support_recursive_move() returns
True. Otherwise, the request server implements MOVE using delete/copy.

This method MAY be implemented in order to improve performance.
r   r
   rO  s     r)   move_recursive_DAVResource.move_recursive  s    V ~&&r,   c                     [         e)zReturn a _DAVResource object for the path (None, if not found).

`path_info`: is a URL relative to this object.

DAVCollection.resolve() provides an implementation.
rj   r(   script_name	path_infos      r)   resolve_DAVResource.resolve  r   r,   c                     g)zPerform custom operations on the response headers.

This gets called before the response is started.
It enables adding additional headers or modifying the default ones.
Nr@   )r(   r   response_headerss      r)   finalize_headers_DAVResource.finalize_headers  rZ   r,   )r   r   r'   r   r%   )=r1   
__module____qualname____firstlineno____doc__r   booldictr*   r3   r   r   r   r9   r=   floatrA   rD   rG   rU   rX   r\   r_   rb   rf   rn   rr   rv   ry   r|   r   r   r   r   r   r   r   r   r   r   r  r  r   r  r  r$  r(  r,  r3  r9  r<  r@  rC  rG  rL  rP  rT  rX  r^  rb  __static_attributes__r@   r,   r)   r   r   z   s   /b6S 6 6 6; "HSM " ""(3- "	8E? 	
#    Xc] """5"4.KD
:" " 4p5n 15 .`J'X :? \'|L'(' 
" +/ '#J"">#J$"L$L"
+'Z"r,   r   c                      ^  \ rS rSrSrS\S\4U 4S jjr\S 5       r	S r
\S 5       r\S	 5       r\S
 5       rS rSS.S jrS rS rSrU =r$ )DAVNonCollectioni  z
A DAVNonCollection is a _DAVResource, that has content (like a 'file' on
a filesystem).

A DAVNonCollecion is able to read and write file content.

See also _DAVResource
r   r   c                 (   > [         TU ]  USU5        g re   superr*   r(   r   r   r0   s      r)   r*   DAVNonCollection.__init__  s    ug.r,   c                     [         e)zjReturns the byte length of the content.

MUST be implemented.

See also _DAVResource.get_content_length()
rj   r2   s    r)   r9   #DAVNonCollection.get_content_length  s
     "!r,   c                 B    [         R                  " U R                  5      $ )aZ  Contains the Content-Type header returned by a GET without accept
headers.

This getcontenttype property MUST be defined on any DAV compliant
resource that returns the Content-Type header in response to a GET.
See http://www.webdav.org/specs/rfc4918.html#PROPERTY_getcontenttype

This default implementation guesses the type from the filen name.
)r   guess_mime_typer   r2   s    r)   r=   !DAVNonCollection.get_content_type  s     ##DII..r,   c                     [         e)zOpen content as a stream for reading.

Returns a file-like object / stream containing the contents of the
resource specified.
The application will close() the stream.

This method MUST be implemented by all providers.
rj   r2   s    r)   r,  DAVNonCollection.get_content  s
     "!r,   c                     g)a  
See http://www.webdav.org/specs/rfc4918.html#PROPERTY_getetag

This method SHOULD be implemented, especially by non-collections.
Return None if not supported for this resource instance.
See also `DAVNonCollection.support_etag()` and `util.get_file_etag(path)`.
Nr@   r2   s    r)   rX   DAVNonCollection.get_etag      r,   c                     g)zWReturn True, if this resource supports ETags.

See also `DAVNonCollection.get_etag()`.
Nr@   r2   s    r)   ry   DAVNonCollection.support_etag  r|  r,   c                     g)znReturn True, if this non-resource supports Range on GET requests.

This default implementation returns False.
Fr@   r2   s    r)   rr   DAVNonCollection.support_ranges  s    
 r,   Nr.  c                     [        [        5      er1  rW  r2  s     r)   r3  DAVNonCollection.begin_write  s     ~&&r,   c                    gr6  r@   r7  s     r)   r9  DAVNonCollection.end_write  s    
 	r,   c                     US;   a  U $ g)zReturn a _DAVResource object for the path (None, if not found).

Since non-collection don't have members, we return None if path is not
empty.
r   Nr@   r[  s      r)   r^  DAVNonCollection.resolve  s     	!Kr,   r@   )r1   rd  re  rf  rg  r   ri  r*   r   r9   r=   r,  rX   ry   rr   r3  r9  r^  rk  __classcell__r0   s   @r)   rm  rm    s    /S /4 / " "
/ 	" 	"     +/ ' r,   rm  c                      ^  \ rS rSrSrS\S\SS4U 4S jjrS\\	   4S jr
S\\   4S	 jrS
\S\4S jrS rS rS r\S 5       rS rS rS rS rS rS rS rSrU =r$ )DAVCollectioni%  a  
A DAVCollection is a _DAVResource, that has members (like a 'folder' on
a filesystem).

A DAVCollecion 'knows' its members, and how to obtain them from the backend
storage.
There is also optional built-in support for member caching.

See also _DAVResource
r   r   r5   Nc                 (   > [         TU ]  USU5        g )NTro  rq  s      r)   r*   DAVCollection.__init__1  s    tW-r,   c                     g Nr@   r2   s    r)   r9    DAVCollection.get_content_lengthX      r,   c                     g r  r@   r2   s    r)   r=   DAVCollection.get_content_type[  r  r,   r'   c                      [        [        5      er"  rW  r   s     r)   r$  #DAVCollection.create_empty_resource^  s    " ~&&r,   c                 F    U R                   (       d   e[        [        5      er'  r#  r   s     r)   r(  DAVCollection.create_collectionq  r*  r,   c                     g)z
See http://www.webdav.org/specs/rfc4918.html#PROPERTY_getetag

For non-collections we default to None, because it is harder to implement.
See also `DAVCollection.support_etag()`.
Nr@   r2   s    r)   rX   DAVCollection.get_etag  s     r,   c                     U R                   (       d   eU R                  R                  [        R                  " U R
                  U5      U R                  5      $ r   )r   r%   r   r   join_urir   r   r   s     r)   r   DAVCollection.get_member  sB     !!!!}}..MM$))T*DLL
 	
r,   c                 4    U R                   (       d   e[        e)zhReturn list of (direct) collection member names (UTF-8 byte strings).

This method MUST be implemented.
r7   r2   s    r)   r   DAVCollection.get_member_names  s     !!!!!!r,   c                     g)zReturn True, if this resource supports ETags.

For non-collections we default to False, because it is harder to implement.
See also `DAVCollection.get_etag()`.
Fr@   r2   s    r)   ry   DAVCollection.support_etag       r,   c                     g)zReturn True, if delete() may be called on non-empty collections
(see comments there).

This default implementation returns False.
Fr@   r2   s    r)   r@  &DAVCollection.support_recursive_delete  r  r,   c                      [        [        5      e)zRemove this resource (possibly recursive).

This method MUST be implemented if resource allows write access.

See _DAVResource.delete()
rW  r2   s    r)   rC  DAVCollection.delete       ~&&r,   c                     [        [        5      e)zCopy or move this resource to destPath (non-recursive).

This method MUST be implemented if resource allows write access.

See _DAVResource.copy_move_single()
rW  rJ  s      r)   rL  DAVCollection.copy_move_single  r  r,   c                     g)rS  Fr@   rO  s     r)   rT  $DAVCollection.support_recursive_move  s    r,   c                      [        [        5      e)zmMove this resource and members to destPath.

This method MAY be implemented in order to improve performance.
rW  rO  s     r)   rX  DAVCollection.move_recursive  s    
 ~&&r,   c                     US;   a  U $ UR                  S5      (       d   e[        R                  " U5      u  p4U R                  U5      nUb  US;   a  U$ UR	                  [        R
                  " X5      U5      $ )zpReturn a _DAVResource object for the path (None, if not found).

`path_info`: is a URL relative to this object.
r   r"   )r$   r   pop_pathr   r^  r  )r(   r\  r]  r'   restr   s         r)   r^  DAVCollection.resolve  sq    
 	!K##C((((]]9-
ood#;$)+J{{4==;TBBr,   r@   )r1   rd  re  rf  rg  r   ri  r*   r   r   r9   r=   r   r$  r(  rX   r   r   r   ry   r@  rC  rL  rT  rX  r^  rk  r  r  s   @r)   r  r  %  s    	.S .4 .D .NHSM (3- '# ', '&' 

 " "'''C Cr,   r  c                       \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 r\S\S\4S j5       rS\S\4S jrS\S\4S jrS rSrg)DAVProvideri  zzAbstract base class for DAV resource providers.

There will be only one DAVProvider instance per share (not per request).
c                 f    SU l         S U l        S U l        S U l        SU l        SU l        SU l        g )Nr!      r   )r   r   r   r   r   _count_get_resource_inst_count_get_resource_inst_initr2   s    r)   r*   DAVProvider.__init__  s7      ()%-.*r,   c                 .    U R                   R                  $ r  )r0   r1   r2   s    r)   r3   DAVProvider.__repr__  s    ~~&&&r,   c                     gre   r@   r2   s    r)   is_readonlyDAVProvider.is_readonly  rh   r,   c                 x    US;   d.  UR                  S5      (       a  UR                  S5      (       a   eXl        g)zoSet application root for this resource provider.

This is the value of SCRIPT_NAME, when WsgiDAVApp is called.
r   r"   N)r$   r   r   )r(   r   s     r)   set_mount_pathDAVProvider.set_mount_path  s>    
 Y&!!#&&z/B/B3/G/G	
 
 %r,   c                     US:X  d  UR                  S5      (       d   eUS:X  a  SnUS;   d  UR                  S5      (       a   eXl        g)zpSet application location for this resource provider.

@param share_path: a UTF-8 encoded, unquoted byte string.
r!   r"   r   N)r$   r   r   )r(   r   s     r)   set_share_pathDAVProvider.set_share_path  sR     R:#8#8#=#===JY&j.A.A#.F.FFF$r,   c                 V    U(       a  [        US5      (       d  [        S5      eXl        g )Ncheck_write_permissionzAMust be compatible with wsgidav.lock_man.lock_manager.LockManager)hasattr
ValueErrorr   )r(   r   s     r)   set_lock_managerDAVProvider.set_lock_manager  s*    6N O OS  )r,   c                 V    U(       a  [        US5      (       d  [        S5      eXl        g )Ncopy_propertieszIMust be compatible with wsgidav.prop_man.property_manager.PropertyManager)r  r  r   )r(   r   s     r)   set_prop_managerDAVProvider.set_prop_manager  s*    6G H H[  )r,   c                 x    S[        [        R                  " XR                  5      5      R	                  S5      -   $ )zConvert a refUrl to a path, by stripping the share prefix.

Used to calculate the <path> from a storage key by inverting get_ref_url().
r"   )r   r   removeprefixr   lstrip)r(   ref_urls     r)   r   DAVProvider.ref_url_to_path  s/    
 WT..wHIPPQTUUUr,   r   r   c                     [         e)a  Return a _DAVResource object for path.

Should be called only once per request and resource::

    res = provider.get_resource_inst(path, environ)
    if res and not res.is_collection:
        print(res.get_content_type())

If <path> does not exist, None is returned.
<environ> may be used by the provider to implement per-request caching.

See _DAVResource for details.

This method MUST be implemented.
rj   r(   r   r   s      r)   r   DAVProvider.get_resource_inst$  s
    " "!r,   c                 (    U R                  X5      SL$ )zReturn True, if path maps to an existing resource.

This method should only be used, if no other information is queried
for <path>. Otherwise a _DAVResource should be created first.

This method SHOULD be overridden by a more efficient implementation.
N)r   r  s      r)   existsDAVProvider.exists7  s     %%d4D@@r,   c                 N    U R                  X5      nU=(       a    UR                  $ )zReturn True, if path maps to an existing collection resource.

This method should only be used, if no other information is queried
for <path>. Otherwise a _DAVResource should be created first.
)r   r   )r(   r   r   r   s       r)   r   DAVProvider.is_collectionA  s%     $$T3(s(((r,   c                     U" X5      $ )zOptionally implement custom request handling.

requestmethod = environ["REQUEST_METHOD"]
Either

- handle the request completely
- do additional processing and call default_handler(environ, start_response)
r@   )r(   r   start_responsedefault_handlers       r)   custom_request_handler"DAVProvider.custom_request_handlerJ  s     w77r,   )r  r  r   r   r   r   r   N)r1   rd  re  rf  rg  r*   r3   r  r  r  r  r  r   r   r   ri  r   r  r   r  rk  r@   r,   r)   r  r    s    
/'%%))V "c "D " "$A3 A A)# ) )	8r,   r  )"rg  rO   r   r   r   abcr   r   typingr   urllib.parser   r   wsgidavr   r	   wsgidav.dav_errorr
   r   r   r   r   wsgidav.utilr   __docformat__get_module_loggerr1   r  r  r   r   rm  r  r  r@   r,   r)   <module>r     s   
KX 
 
   #  ' #  "

 
 
*
  ,-BC A3 AN"^| ^HsCL sCvs8# s8r,   