
    qi5Z                     &   S r SSKrSSKrSSKrSSKJr  SSK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   SSKrSS	KJrJr  SS
KJr  Sr\R8                  " \5      rSr " S S\5      r  " S S\5      r!g! \ a    \" S\R4                  S9  e f = f)a	  
DAV provider that publishes a Mercurial repository.

Note: This is **not** production code!

The repository is rendered as three top level collections.

edit:
    Contains the working directory, i.e. all files. This includes uncommitted
    changes and untracked new files.
    This folder is writable.
released:
    Contains the latest committed files, also known as 'tip'.
    This folder is read-only.
archive:
    Contains the last 10 revisions as sub-folders.
    This folder is read-only.

Sample layout::

    /<share>/
        edit/
            server/
                ext_server.py
            README.txt
        released/
        archive/
            19/
            18/
            ...

Supported features:

#. Copying or moving files from ``/edit/..`` to the ``/edit/..`` folder will
   result in a ``hg copy`` or ``hg rename``.
#. Deleting resources from ``/edit/..`` will result in a ``hg remove``.
#. Copying or moving files from ``/edit/..`` to the ``/released`` folder will
   result in a ``hg commit``.
   Note that the destination path is ignored, instead the source path is used.
   So a user can drag a file or folder from somewhere under the ``edit/..``
   directory and drop it directly on the ``released`` directory to commit
   changes.
#. To commit all changes, simply drag'n'drop the ``/edit`` folder on the
   ``/released`` folder.
#. Creating new collections results in creation of a file called ``.directory``,
   which is then ``hg add`` ed since Mercurial doesn't track directories.
#. Some attributes are published as live properties, such as ``{hg:}date``.


Known limitations:

#. This 'commit by drag-and-drop' only works, if the WebDAV clients produces
   MOVE or COPY requests. Alas, some clients will send PUT, MKCOL, ... sequences
   instead.
#. Adding and then removing a file without committing after the 'add' will
   leave this file on disk (untracked)
   This happens for example whit lock files that Open Office Write and other
   applications will create.
#. Dragging the 'edit' folder onto 'released' with Windows File Explorer will
   remove the folder in the explorer view, although WsgiDAV did not delete it.
   This seems to be done by the client.


See:
    http://mercurial.selenic.com/wiki/MercurialApi
Requirements:
    ``easy_install mercurial`` or install the API as non-standalone version
    from here: http://mercurial.berkwood.com/
    http://mercurial.berkwood.com/binaries/mercurial-1.4.win32-py2.6.exe
    N)md5)pprint)util)HTTP_FORBIDDENDAVError)DAVProvider_DAVResource)VirtualCollection)commandshg)versionz@Could not import Mercurial API. Try 'easy_install -U mercurial'.)filezreStructuredText eni    c                      ^  \ rS rSrSrU 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U 4S jrU 4S jrS!S jrS rS rS rS rSS.S jrS rS rS rS rS rS r U =r!$ )"
HgResourcek   z&Abstract base class for all resources.c                 :  > [         TU ]  XU5        X@l        XPl        U R	                  5       U l        SU R                  ;  d   eSU R
                  ;  d   eU(       a  S U l        g U R                  R                  U R                     nX`R                     U l        g )N\/)	super__init__revlocalHgPath_getFilePathabsFilePathfctxproviderrepo)selfpathis_collectionenvironr   r   wdctx	__class__s          T/home/kali/flask_env/lib/python3.13/site-packages/wsgidav/samples/hg_dav_provider.pyr   HgResource.__init__n   s    g6&,,.4+++++$*****DI MM&&txx0E../DI    c                     U R                   R                  S5      nU(       a  UR                  U5        [        R                  R
                  " U R                  R                  R                  /UQ76 $ )Nr   )	r   splitextendosr   joinr   r   root)r   addPartspartss      r$   r   HgResource._getFilePath   sO      &&s+LL"ww||DMM..33<e<<r&   c           	          U R                   R                  S5      =(       d    Sn[        R                  " U R                  R
                  U R                  R                  U R                  SUUS9  g )Nzwsgidav.auth.user_name	AnonymousT)	addremoveusermessage)r!   getr   commitr   uir   r   )r   r4   r3   s      r$   _commitHgResource._commit   sT    || 89H[MMMM	
r&   c                 <    U R                   b  [        [        5      eg)z0Raise HTTP_FORBIDDEN, if resource is unwritable.N)r   r   r   r   s    r$   _check_write_accessHgResource._check_write_access   s    88>**  r&   c                 Z    U R                   (       a  g U R                  R                  5       $ N)r    r   sizer;   s    r$   get_content_lengthHgResource.get_content_length   s    yy~~r&   c                 f    U R                   (       a  g [        R                  " U R                  5      $ r?   )r    r   guess_mime_typer   r;   s    r$   get_content_typeHgResource.get_content_type   s%    
 ##DII..r&   c                     g r?    r;   s    r$   get_creation_dateHgResource.get_creation_date        r&   c                     U R                   (       d  U R                  R                  5       c  U R                  $ U R                   SU R                  R                  5        3$ )N@)r    r   filerevnamer;   s    r$   get_display_nameHgResource.get_display_name   sJ    !2!2!4!<99))Adii//1233r&   c                     [        U R                  5      R                  5       S-   [        R                  " U R                  5       5      -   S-   [        U R                  5       5      -   $ )N-)r   r   	hexdigestr   to_strget_last_modifiedstrrA   r;   s    r$   get_etagHgResource.get_etag   s_    		N$$&kk$00234  $))+,	-	
r&   c                 `    U R                   (       a  g U R                  R                  5       S   $ )Nr   )r    r   dater;   s    r$   rV   HgResource.get_last_modified   s$    yy~~""r&   c                     g)NFrH   r;   s    r$   support_rangesHgResource.support_ranges   s    r&   c                     U R                   (       d   eU R                  S   [        R                  " U R                  5         nUS   nU R
                  U;  a  / $ X R
                     S   X R
                     S   -   $ )Nwsgidav.hg.cachedirinfosr      )r    r!   r   rU   r   r   )r   cacherb   s      r$   get_member_namesHgResource.get_member_names   sv    !!!!/0TXX1FG$8+I(()!,x8H8H/I!/LLLr&   c                     U R                   (       d   eU R                  R                  [        R                  " U R
                  U5      U R                  5      $ r?   )r    r   get_resource_instr   join_urir   r!   )r   rO   s     r$   
get_memberHgResource.get_member   s@    !!!!}}..MM$))T*DLL
 	
r&   c                 4    U R                   (       a  SS0$ SS0$ )Ntype	DirectoryFile)r    r;   s    r$   get_display_infoHgResource.get_display_info   s!    K((r&   c                j   > [         TU ]  US9nU R                  (       a  UR                  / SQ5        U$ )zaReturn list of supported property names in Clark Notation.

See DAVResource.get_property_names()
)
is_allprop){hg:}branch	{hg:}date{hg:}description{hg:}filerev{hg:}rev	{hg:}user)r   get_property_namesr   r)   )r   rs   propNameListr#   s      r$   rz   HgResource.get_property_names   s9     w1Z1H99	 r&   c                 H  > US:X  a  U R                   R                  5       $ US:X  a1  [        R                  " U R                   R	                  5       S   5      $ US:X  a  U R                   R                  5       $ US:X  a.  [        R                  " U R                   R                  5       5      $ US:X  a.  [        R                  " U R                   R                  5       5      $ US:X  a.  [        R                  " U R                   R                  5       5      $ [        TU ])  U5      $ )z:Return the value of a property.

See get_property_value()
rt   ru   r   rv   rw   rx   ry   )r   branchr   rU   r[   descriptionrN   r   r3   r   get_property_value)r   rO   r#   s     r$   r   HgResource.get_property_value   s     = 99##%%[ ;;tyy~~/233''99((**^#;;tyy00233Z;;tyy}}//[ ;;tyy~~/00 w)$//r&   c                      [        [        5      e)zDSet or remove property value.

See DAVResource.set_property_value()
)r   r   )r   rO   valuedry_runs       r$   set_property_valueHgResource.set_property_value  s    
 ~&&r&   c                      U R                   b  gg)z8Return True, to prevent locking.

See prevent_locking()
TF)r   r;   s    r$   prevent_lockingHgResource.prevent_locking  s    
 88r&   c                    U R                   (       d   eU R                  5         U R                  U5      n[        US5      nUR	                  5         [
        R                  " U R                  R                  U R                  R                  U5        [        U R                  R                  S5      S-   U-   SU R                  U R                  U R                  S-   U-   5      $ )zkCreate and return an empty (length-0) resource as member of self.

See DAVResource.create_empty_resource()
wr   F)r    r<   r   opencloser   addr   r7   r   r   r   rstripr!   r   r   )r   rO   filepathfs       r$   create_empty_resource HgResource.create_empty_resource  s    
 !!!!  "$$T*3		T]]%%t}}'9'98D IIS!C'$.LLHHs"T)
 	
r&   c                    U R                   (       d   eU R                  5         U R                  U5      n[        R                  " U5        U R                  US5      n[        US5      nUR                  S5        UR                  5         [        R                  " U R                  R                  U R                  R                  U5        g)zqCreate a new collection as member of self.

A dummy member is created, because Mercurial doesn't handle folders.
z
.directoryr   zCreated by WsgiDAV.N)r    r<   r   r*   mkdirr   writer   r   r   r   r7   r   )r   rO   collpathr   r   s        r$   create_collectionHgResource.create_collection.  s    
 !!!!  "$$T*
$$T<83	%&		T]]%%t}}'9'98Dr&   c                     U R                   (       a   eU R                  R                  5       n[        R                  " U5      $ )zEOpen content as a stream for reading.

See DAVResource.get_content()
)r    r   datar   StringIO)r   ds     r$   get_contentHgResource.get_content=  s2    
 %%%%IINN}}Qr&   N)content_typec                    U R                   (       a   eU R                  5         Sn[        U R                  U[        5      $ )zEOpen content as a stream for writing.

See DAVResource.begin_write()
wb)r    r<   r   r   BUFFER_SIZE)r   r   modes      r$   begin_writeHgResource.begin_writeF  s;    
 %%%%  " D$$dK88r&   c                    U(       dK  [         R                  " U R                  R                  U R                  R                  U R
                  5        gg)zCCalled when PUT has finished writing.

See DAVResource.end_write()
N)r   r   r   r7   r   r   )r   with_errorss     r$   	end_writeHgResource.end_writeS  s6    
 LL))4==+=+=t?O?OP r&   c                     g)zUReturn True, if delete() may be called on non-empty collections
(see comments there).TrH   r;   s    r$   support_recursive_delete#HgResource.support_recursive_deleteb  rK   r&   c                     U R                  5         U R                  5       n[        R                  " U R                  R
                  U R                  R                  USS9  g)z!Remove this resource (recursive).TforceN)r<   r   r   remover   r7   r   )r   r   s     r$   deleteHgResource.deleteg  sB      "$$&(($--*<*<hdSr&   c                   [         R                  " U5      u  p4UR                  S5      nU R                  R                  nU R                  R
                  n[        R                  SU R                   SU 35        U R                  c(  US:X  a"  [        R                  " XVU R                  USS9  gU R                  c)  US:X  a#  U R                  SU R                   SU S	35        g[        [        5      e)
zHandle a COPY request natively.r   handle_copy  -> editTr   releasedzWsgiDAV commit (COPY ))r   pop_pathstripr   r7   r   _loggerinfor   r   r   copyr8   r   r   r   )r   	dest_pathdepth_infinitydestType
destHgPathr7   r   s          r$   handle_copyHgResource.handle_copym  s    #}}Y7%%c*
]]}}!!|D$4$4#5T*FG88F 2MM"D$4$4jM  XX(j"8 LL04	{!LM  >**r&   c                    [         R                  " U5      u  p#UR                  S5      nU R                  R                  nU R                  R
                  n[        R                  SU R                   SU 35        U R                  c(  US:X  a"  [        R                  " XEU R                  USS9  gU R                  c)  US:X  a#  U R                  SU R                   SU S	35        g[        [        5      e)
zHandle a MOVE request natively.r   r   r   r   Tr   r   zWsgiDAV commit (MOVE r   )r   r   r   r   r7   r   r   r   r   r   r   renamer8   r   r   r   )r   r   r   r   r7   r   s         r$   handle_moveHgResource.handle_move  s    #}}Y7%%c*
]]}}!!|D$4$4#5T*FG88F 2OOBd&6&6
$O  XX(j"8 LL04	{!LM  >**r&   )r   r   r   r   F)"__name__
__module____qualname____firstlineno____doc__r   r   r8   r<   rA   rE   rI   rP   rX   rV   r^   re   rj   rp   rz   r   r   r   r   r   r   r   r   r   r   r   r   __static_attributes____classcell__r#   s   @r$   r   r   k   s    00.=	
+ 
/
4

#M
 
*0.'
*E  +/ 9Q
T& r&   r   c                   F   ^  \ rS rSrSrU 4S jrSS jrS	S jrS rSr	U =r
$ )
HgResourceProvideri  z?
DAV provider that serves a VirtualResource derived structure.
c           	        > [         TU ]  5         Xl        [        S[        -  5        [
        R                  R                  5       U l        [        R                  " U R                  U5      U l	        U R                  R                  SU R                  R                  -  5        U R                  R                  U l        [        R                  " U R                  R                  5        [        R                  SU R                  R                  -  5        [         R"                  " U R                  U R                  5        [        S5        [%        U R                  R                  5       5        U R                  R                  R                  SU R                  R                  R'                  5       -  5        U R                  R                  SU R                  R                  R)                  U5      -  5        [        S5        U R                  R+                  5         [         R,                  " U R                  U R                  SS	9  U R                  R/                  5       R1                  5       nUR3                  S
5       Vs/ s H  n[5        UR3                  SS5      5      PM      nn[%        U5        [        S5        U R                  R+                  5         [         R6                  " U R                  U R                  SSSSS9  U R                  R/                  5       R1                  5       nUR3                  S
5       Vs/ s H  n[5        UR3                  SS5      5      PM      nn[%        U5        U R9                  5         g s  snf s  snf )NzMercurial version %szConnected to repository %s
zVerify repository '%s' tree...zStatus:z0the default user_name to be used in commits: %s
zExpandpath: %s
z Working directory state summary:F)remote
:rc   zRepository state summary:T)numidr~   tags)r   r   repoRootprint	hgversion	mercurialr7   r   
repositoryr   statusr,   r*   chdirr   warningr   verifyr   	user_name
expandpath
pushbuffersummary	popbufferr   r(   tupleidentify_get_log)r   r   reslinereslinesr#   s        r$   r   HgResourceProvider.__init__  sZ    $y01,,//#MM$''84	5		FG		 	  	8499>>IJ+ 	ityy!"		?iill$$&'	

 	)DIILL,C,CH,MMN01$))E:gg!''):=))D/J/$E$**S!,-/Jx)*$''499$4SWXgg!''):=))D/J/$E$**S!,-/Jx K Ks   %N%N	c           	      n   U R                   R                  5         [        R                  " U R                   U R                  USSSS9  U R                   R                  5       R                  5       n/ nUR                  S5       H  n0 nUR                  U5        UR                  S5       H?  nUR                  SS5      u  pxUS;   d   eUR                  5       XWR                  5       '   MA     [        R                  " US   5      US	'   US
   R                  S5      u  p[        U	5      US'   XS'   M     U$ )z-Read log entries into a list of dictionaries.N)limitr[   r   r3   z

r   r   rc   )	changesettagr3   r[   r   r[   parsed_dater   local_idunid)r7   r   r   logr   r   r   r(   appendr   parse_time_stringint)r   r   r   logListlogentryr   r   kvr   r   s              r$   r   HgResourceProvider._get_log  s	   TWWdiiu4TPTUgg!'')		&)HCNN3 t,zz#q)KKKK!"GGI - "&!7!7F!DC -33C8NH!(mC
OK * r&   c                 t   UR                  S0 5      nUR                  [        R                  " U5      5      b1  [        R                  SU-  5        U[        R                  " U5         $ [        R                  " 5       nU R                  R                  5         [        R                  " U R                  U R                  U5        U R                  R                  5       n/ n0 n0 n	UR                  S5       H  n
U
R                  5       S:X  a  M  U
R                  SS5      n
U
R                  S5      n[!        U5      S:  a  Sn[#        S[!        U5      S-
  5       HH  nX   nUR                  U/ / 45      nXS   ;  a  US   R%                  U5        US:X  a  UnMA  U SU 3nMJ     UR                  U/ / 45      S   R%                  US	   5        S
X'   M     UR'                  5         XxU	S.nUU[        R                  " U5      '   [        R)                  SU S[        R                  " 5       U-
  S 35        U$ )ak  Return a dictionary containing all files under source control.

dirinfos:
    Dictionary containing direct members for every collection.
    {folderpath: (collectionlist, filelist), ...}
files:
    Sorted list of all file paths in the manifest.
filedict:
    Dictionary containing all files under source control.

::

    {'dirinfos': {'': (['wsgidav',
                        'tools',
                        'WsgiDAV.egg-info',
                        'tests'],
                       ['index.rst',
                        'wsgidav MAKE_DAILY_BUILD.launch',
                        'wsgidav run_server.py DEBUG.launch',
                        'wsgidav-paste.conf',
                        ...
                        'setup.py']),
                  'wsgidav': (['addons', 'samples', 'server', 'interfaces'],
                              ['__init__.pyc',
                               'dav_error.pyc',
                               'dav_provider.pyc',
                               ...
                               'wsgidav_app.py']),
                   },
     'files': ['.hgignore',
               'ADDONS.txt',
               'wsgidav/samples/mysql_dav_provider.py',
               ...
               ],
     'filedict': {'.hgignore': True,
                   'README.txt': True,
                   'WsgiDAV.egg-info/PKG-INFO': True,
                   }
                   }
ra   z_get_repo_info(%s): cache hit.r    r   r   rc   r   T)filesrb   filedictz_getRepoInfo(z) took z.3f)
setdefaultr5   r   rU   r   debugtimer7   r   r   manifestr   r   r(   r   replacelenranger   sortr   )r   r!   r   reloadcaches
start_timer   r  rb   r  r   parentsp1ip2dirrd   s                    r$   _get_repo_info!HgResourceProvider._get_repo_info  s   R ##$6;::dkk#&'3MM:S@A$++c*++YY[
$''499c2gg!IIdODzz|r!<<c*DjjoG7|q q#g,"23A B"--b2r(;CQ'Ab)Rx "t1RD\ 4 ##BR1!4;;GBKH!HN% $& 	

8L#(t{{3 }SEz1I#0NOPr&   c                    U =R                   S-  sl         UR                  S5      nSn[        R                  " U5      u  pVUS:X  a  [	        XS/ SQ5      $ US:X  a  UR                  S5      nSnOUS:X  a  UR                  S5      nS	nOUS
:X  a  US:X  aE  U R                  SS9nU Vs/ s H  n[        R                  " US   5      PM     n	n[	        XSU	5      $ [        R                  " U5      u  p [        U
5        U
nUR                  S5      nOgU R                  X$5      nX;S   ;   a  [        USX$U5      $ X;S   ;   d  US:X  a  [        USX$U5      $ gs  snf ! [         a     gf = f)zHReturn HgResource object for path.

See DAVProvider.get_resource_inst()
rc   r   Nr  r,   )r   r   archiver   r   tipr  
   )r   r   	Revisionsr  Frb   T)_count_get_resource_instr   r   r   r
   r   rU   r   	Exceptionr  r   )r   r   r!   r   r   cmdrestloglistmmembersrevidrd   s               r$   rh   $HgResourceProvider.get_resource_inst<  sz   
 	%%*% jjoMM$'	"9$v'F  F]**S/KCJ**S/KCIs{--b-1?FGw!4;;q}5wG(WMM---KEE

 C**S/K ##G1
++dE7EE
++{b/@dD'DD1 H
  s   )#E4E 
E*)E*)r   r   r7   r?   r   )r   r   r   r   r   r   r   r  rh   r   r   r   s   @r$   r   r     s$    +Z*Mx2 2r&   r   )"r   r*   sysr  hashlibr   r   wsgidavr   wsgidav.dav_errorr   r   wsgidav.dav_providerr   r	   "wsgidav.samples.dav_provider_toolsr
   mercurial.uir   r   r   mercurial.__version__r   r   ImportErrorr   stderr__docformat__get_module_loggerr   r   r   r   r   rH   r&   r$   <module>r1     s   EL 
 
     6 : @
&: &

 
 
*f f\	U U	  
	JZZ 

s   A7 7B