*
 <c       s    d  Z  ! # h  d d <d d <d d <d d <d	 d
 <d d <d d <d d <Z 4 y 5 e d i d  d Z Wn 6 7 d Z n X< d k Z = d k Z > d k Z ? d k Z D d k l	 Z	 K d   Z
 Y d   Z m d   Z z d   Z  d   Z  d   Z d d  Z d   Z (d   Z ,d    Z 0d!   Z 4d"   Z 8d#   Z <d$   Z @d%   Z Dd&   Z Hd'   Z Md( e	 f d)     YZ d S(*   s   Provide a common set of path management functions.

Many of the os.path functions are fronted by functions here to allow
for tracing and consistent use of those functions.

s   $RCSfile: path.py,v $s   module_names9   $Id: path.py,v 1.5 2001/11/25 14:13:39 doughellmann Exp $s   rcs_ids(   Doug Hellmann <DougHellmann@bigfoot.com>s   creators   UNSPECIFIEDs   projects   Sat, 03-Feb-2001 12:49:56 ESTs   createds   $Author: doughellmann $s   authors   $Revision: 1.5 $s   versions   $Date: 2001/11/25 14:13:39 $s   dates    i   s   0.0N(   s   StreamFlushTestc    s   K L M |  o N d Sn O t i  i |   } P t |  d j oN Q | \ } } R t i  i |  p t i  i |  o S t	 |  n n T t i  i |   p t i  i |   o U t i
 |   n V d Sd S(   s+   Create a directory and all of its children.Ni   (   s   paths   oss   splits   partss   lens   parents   childs   isdirs   islinks   rmkdirs   mkdir(   s   paths   childs   parents   parts(    (    sN   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_0/happydoclib/path.pys   rmkdirK s   **c    s  Y Z [ t  i |  t i  } ] t |  } ^ g  } _ xs | d _ rf } ` | o a n? b | d d f j o | |  | j o d d | | f } n e | i |  qB Wh t t i i |  } i |  o |  d t i j o j t i | } n k | Sd S(   s3   Add the prefix value to every part of a given path.i    s   .s   ..s   %s%sN(   s   strings   splits   paths   oss   seps   partss   lens   prefixs
   prefix_lens
   real_partss   ps   appends   applys   joins   name(   s   paths   prefixs
   prefix_lens   names   ps   partss
   real_parts(    (    sN   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_0/happydoclib/path.pys   applyPrefixToPathY s   	 	'c    s   m n o t  i i |   } p t | |  } s | | j o t |  t |  }  n u x0 u |  o |  d t  i j o v |  d }  qZ Wx |  Sd S(   s5   Remove prefix from the beginning of path, if present.i    i   N(	   s   oss   paths   dirnames   one_ups   commonPrefixs   prefixs   common_prefixs   lens   sep(   s   paths   prefixs   common_prefixs   one_up(    (    sN   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_0/happydoclib/path.pys   removePrefixm s    c    s  z   |  p | o  d Sn  t i |  t i  }  t i | t i  }  g  }  xM t	 t
 | |  d  r4 \ } }  | | j o  | i |  n  Pqu W t i | t i  }  |  o& |  d d j o | o | d d j o  d | } n  | Sd S(   s  Find parts of path1 and path2 at the beginning of each which are the same.

    Arguments

      path1 -- A filesystem path.

      path2 -- A filesystem path.

    Returns a string containing the full path which occurs at the
    beginning of both path1 and path2.

    This function differs from os.path.commonprefix in that a part of
    the path is considered the same only if the *full* directory or
    subdirectory name matches.
    s    i    s   /N(   s   path1s   path2s   strings   splits   oss   seps   path1_partss   path2_partss   commons   maps   Nones   p1s   p2s   appends   join(   s   path1s   path2s   commons   path1_partss   path2_partss   p1s   p2(    (    sN   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_0/happydoclib/path.pys   commonPrefixz s   	 3c    sk      t  |  |  }  t | |  }  t  | |  }  t | |  }  t | |  }  | Sd S(   s  Join path1 and path2.

    Arguments

      path1prefix -- Beginning of path1 which should be ignored for
                     comparisons between path1 and path2.

      path1 -- First path to join.

      path2 -- Second path to join, may have part of path1 after
               path1prefix.

    This function is a bit weird.  The result of::

      joinWithCommonMiddle('/root/one', '/root/one/two', 'two/three/filename.txt')

    is::

      /root/one/two/three/filename.txt
    
    N(	   s   commonPrefixs   path1prefixs   path1s   common_prefixs   removePrefixs	   real_bases   path2s   joins   name(   s   path1prefixs   path1s   path2s   common_prefixs   names	   real_base(    (    sN   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_0/happydoclib/path.pys   joinWithCommonMiddle s   c    s     d }  | o  d G|  GHn  | o  d G| GHn  | o  d G| GHn  t i i |   }   t i i |  }  | o  d G|  GHn  | o  d G| GHn  t |  |  }   t | |  }  | o  d G|  GHn  | o  d G| GHn  |  | j o/  | o  d	 GHn  t i i |  } n t
 t i i |   t i i |   }  |  t |  }  xn  | o | d t i j oO  | d
 }  | o  d G| GHn  | o
 | d j o  d  n qW t i i |  }
  t i |
 t i  }  | o  d G| GHn  | o | d o"  t t i |
 t i   }	 n
  d }	  t i t i |	 }  | t |  } | o | d t i j o | d
 } n d | | f } | o d G| Gd GHn | Sd S(   s4  Compute the relative link between fromName and toName.

    Parameters

      'fromName' -- Named output node from which to compute the link.

      'toName' -- Named output node to which link should point.

      'baseDirectory' -- Name of the base directory in which both
      fromName and toName will reside.
      
    Both fromName and toName are strings refering to URL targets.
    This method computes the relative positions of the two nodes
    and returns a string which, if used as the HREF in a link in
    fromName will point directly to toName.
    i    s   
PATH: FROM: s   PATH: TO  : s   PATH: BASE: s   PATH: FROM NORMALIZED : s   PATH: TO NORMALIZED   : s   PATH: FROM - PREFIX : s   PATH: TO   - PREFIX : s   	PATH: same namei   s   	PATH: from, no prefix:s   z.htmls   debugs   	PATH: parts:s   %s%ss   PATH: LINK: s   
N(   s   dbgs   fromNames   toNames   baseDirectorys   oss   paths   normpaths   removePrefixs   basenames   relative_links   commonPrefixs   dirnames   common_prefixs   lens   from_name_no_prefixs   seps   subdir_paths   strings   splits   partss   levelss   pardirs	   up_levelss   to_name_no_prefix(   s   fromNames   toNames   baseDirectorys   common_prefixs	   up_levelss   partss   to_name_no_prefixs   dbgs   relative_links   levelss   subdir_paths   from_name_no_prefix(    (    sN   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_0/happydoclib/path.pys   computeRelativeHTMLLink s`   	
 
 
 
 
 
 
 
 * 
 
 "	
 s   *c    s;   t  i i |  |  } t i |  } | Sd S(   sR  Find all files in the directory which match the glob pattern.

    Parameters

      directoryName -- String containing the name of a directory on
      the file system.

      filenamePattern -- String containing a regular expression to be
      used by the glob module for matching when looking for files in
      'directoryName'.

    N(   s   oss   paths   joins   directoryNames   filenamePatterns
   search_pats   globs   found(   s   directoryNames   filenamePatterns   founds
   search_pat(    (    sN   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_0/happydoclib/path.pys   findFilesInDirs   c    sc   |  o |  d d j o7  x-  |  o |  d d j o !|  d }  q' Wn "|  Sd S(   sp   Remove './', '../', etc. from the front of filename.

    Returns a new string, unless no changes are made.
    i    s   .s   ./i   N(   s   filename(   s   filename(    (    sN   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_0/happydoclib/path.pys   removeRelativePrefixs    c     s    ()*t  t i i |   Sd S(   s   os.path.joinN(   s   applys   oss   paths   joins   args(   s   args(    (    sN   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_0/happydoclib/path.pys   join(s   c      s   ,-.t  i   Sd S(   s	   os.getcwdN(   s   oss   getcwd(    (    (    sN   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_0/happydoclib/path.pys   cwd,s   c    s   012t  i i |   Sd S(   s   os.path.normpathN(   s   oss   paths   normpaths   p(   s   p(    (    sN   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_0/happydoclib/path.pys   normpath0s   c    s   456t  i i |   Sd S(   s   os.path.isdirN(   s   oss   paths   isdirs   f(   s   f(    (    sN   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_0/happydoclib/path.pys   isdir4s   c    s   89:t  i i |   Sd S(   s   os.path.existsN(   s   oss   paths   existss   f(   s   f(    (    sN   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_0/happydoclib/path.pys   exists8s   c    s   <=>t  i i |   Sd S(   s   os.path.basenameN(   s   oss   paths   basenames   f(   s   f(    (    sN   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_0/happydoclib/path.pys   basename<s   c    s   @ABt  i i |   Sd S(   s   os.path.dirnameN(   s   oss   paths   dirnames   f(   s   f(    (    sN   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_0/happydoclib/path.pys   dirname@s   c    s   DEFt  i i |   Sd S(   s   os.path.splitextN(   s   oss   paths   splitexts   f(   s   f(    (    sN   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_0/happydoclib/path.pys   splitextDs   c    s   HIJt  i i |   Sd S(   s   os.path.splitN(   s   oss   paths   splits   f(   s   f(    (    sN   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_0/happydoclib/path.pys   splitHs   s   PathTestc      s  MOd   Z  Wd   Z _d   Z gd   Z od   Z wd   Z d   Z d   Z d	   Z d
   Z	 d   Z
 d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   Nc    sT   OPd } Qt d d  } Rt o! | | j p t d | | f  Ud  Sd  S(   Ns   /BLAH_tmp/BLAH_foos   /tmp/foos   BLAH_s8   Path modification failed.
	Expected "%s",
	got      "%s"(   s   expecteds   applyPrefixToPaths   actuals	   __debug__s   AssertionError(   s   selfs   actuals   expected(    (    sN   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_0/happydoclib/path.pys   testApplyPrefixToPathOs   	+c    sT   WXd } Yt d d  } Zt o! | | j p t d | | f  ]d  Sd  S(   Ns    s   BLAH_s8   Path modification failed.
	Expected "%s",
	got      "%s"(   s   expecteds   applyPrefixToPaths   actuals	   __debug__s   AssertionError(   s   selfs   actuals   expected(    (    sN   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_0/happydoclib/path.pys   testApplyPrefixToPathEmptyWs   	+c    sT   _`d } at d d  } bt o! | | j p t d | | f  ed  Sd  S(   Ns   ../BLAH_tmp/BLAH_foos
   ../tmp/foos   BLAH_s8   Path modification failed.
	Expected "%s",
	got      "%s"(   s   expecteds   applyPrefixToPaths   actuals	   __debug__s   AssertionError(   s   selfs   actuals   expected(    (    sN   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_0/happydoclib/path.pys   testApplyPrefixToPathRelative_s   	+c    sT   ghd } it d d  } jt o! | | j p t d | | f  md  Sd  S(   Ns   foos   /tmp/foos   /tmps8   Path modification failed.
	Expected "%s",
	got      "%s"(   s   expecteds   removePrefixs   actuals	   __debug__s   AssertionError(   s   selfs   actuals   expected(    (    sN   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_0/happydoclib/path.pys   testRemovePrefixgs   	+c    sT   opd } qt d d  } rt o! | | j p t d | | f  ud  Sd  S(   Ns   tmp/foos   /tmp/foos   /blahs8   Path modification failed.
	Expected "%s",
	got      "%s"(   s   expecteds   removePrefixs   actuals	   __debug__s   AssertionError(   s   selfs   actuals   expected(    (    sN   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_0/happydoclib/path.pys   testRemovePrefixNotThereos   	+c    sT   wxd } yt d d  } zt o! | | j p t d | | f  }d  Sd  S(   Ns    s   /blahs8   Path modification failed.
	Expected "%s",
	got      "%s"(   s   expecteds   removePrefixs   actuals	   __debug__s   AssertionError(   s   selfs   actuals   expected(    (    sN   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_0/happydoclib/path.pys   testRemovePrefixEmptyPathws   	+c    sT   d } t d d  } t o! | | j p t d | | f  d  Sd  S(   Ns   tmp/foos   /tmp/foos    s8   Path modification failed.
	Expected "%s",
	got      "%s"(   s   expecteds   removePrefixs   actuals	   __debug__s   AssertionError(   s   selfs   actuals   expected(    (    sN   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_0/happydoclib/path.pys   testRemovePrefixEmptyPrefixs   	+c    sT   d } t d d  } t o! | | j p t d | | f  d  Sd  S(   Ns   /tmps   /tmp/foos	   /tmp/blahs8   Path modification failed.
	Expected "%s",
	got      "%s"(   s   expecteds   commonPrefixs   actuals	   __debug__s   AssertionError(   s   selfs   actuals   expected(    (    sN   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_0/happydoclib/path.pys   testCommonPrefixs   	+c    sT   d } t d d  } t o! | | j p t d | | f  d  Sd  S(   Ns    s   /var/tmp/foos	   /tmp/blahs8   Path modification failed.
	Expected "%s",
	got      "%s"(   s   expecteds   commonPrefixs   actuals	   __debug__s   AssertionError(   s   selfs   actuals   expected(    (    sN   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_0/happydoclib/path.pys   testCommonPrefixNones   	+c    s   d } t d d  } t o! | | j p t d | | f  d } t d d  } t o! | | j p t d | | f  d  Sd  S(   Ns    s	   /tmp/blahs8   Path modification failed.
	Expected "%s",
	got      "%s"s   /var/tmp/foo(   s   expecteds   commonPrefixs   actuals	   __debug__s   AssertionError(   s   selfs   actuals   expected(    (    sN   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_0/happydoclib/path.pys   testCommonPrefixEmptyPathss   	+	+c    sW   d } t d d d  } t o! | | j p t d | | f  d  Sd  S(   Ns    /root/one/two/three/filename.txts	   /root/ones   /root/one/twos   two/three/filename.txts8   Path modification failed.
	Expected "%s",
	got      "%s"(   s   expecteds   joinWithCommonMiddles   actuals	   __debug__s   AssertionError(   s   selfs   actuals   expected(    (    sN   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_0/happydoclib/path.pys   testJoinWithCommonMiddles   	+c    sW   d } t d d d  } t o! | | j p t d | | f  d  Sd  S(   Ns%   /root/one/four/two/three/filename.txts   /root/one/fives   /root/one/fours   two/three/filename.txts8   Path modification failed.
	Expected "%s",
	got      "%s"(   s   expecteds   joinWithCommonMiddles   actuals	   __debug__s   AssertionError(   s   selfs   actuals   expected(    (    sN   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_0/happydoclib/path.pys!   testJoinWithCommonMiddleNotCommons   	+c    sW   d } t d d d  } t o! | | j p t d | | f  d  Sd  S(   Ns%   /root/one/four/two/three/filename.txts    s   /root/one/fours   two/three/filename.txts8   Path modification failed.
	Expected "%s",
	got      "%s"(   s   expecteds   joinWithCommonMiddles   actuals	   __debug__s   AssertionError(   s   selfs   actuals   expected(    (    sN   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_0/happydoclib/path.pys#   testJoinWithCommonMiddleEmptyPrefixs   	+c    sW   d } t d d d  } t o! | | j p t d | | f  d  Sd  S(   Ns   two/three/filename.txts   /root/one/fives    s8   Path modification failed.
	Expected "%s",
	got      "%s"(   s   expecteds   joinWithCommonMiddles   actuals	   __debug__s   AssertionError(   s   selfs   actuals   expected(    (    sN   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_0/happydoclib/path.pys"   testJoinWithCommonMiddleEmptyPath1s   	+c    sW   d } t d d d  } t o! | | j p t d | | f  d  Sd  S(   Ns   /root/one/two/s	   /root/ones   /root/one/twos    s8   Path modification failed.
	Expected "%s",
	got      "%s"(   s   expecteds   joinWithCommonMiddles   actuals	   __debug__s   AssertionError(   s   selfs   actuals   expected(    (    sN   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_0/happydoclib/path.pys"   testJoinWithCommonMiddleEmptyPath2s   	+c    sW   d } t d d d  } t o! | | j p t d | | f  d  Sd  S(   Ns   my.gifs
   index.htmls   /tmp/base/dirs8   Path modification failed.
	Expected "%s",
	got      "%s"(   s   expecteds   computeRelativeHTMLLinks   actuals	   __debug__s   AssertionError(   s   selfs   actuals   expected(    (    sN   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_0/happydoclib/path.pys   testComputeRelativeHTMLLinks   	+c    sW   d } t d d d  } t o! | | j p t d | | f  d  Sd  S(   Ns	   ../my.gifs
   index.htmls   /tmp/base/dirs8   Path modification failed.
	Expected "%s",
	got      "%s"(   s   expecteds   computeRelativeHTMLLinks   actuals	   __debug__s   AssertionError(   s   selfs   actuals   expected(    (    sN   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_0/happydoclib/path.pys)   testComputeRelativeHTMLLinkUpOneDirectorys   	+c    s]   d } t d d d  } t o! | | j p t d | | f  d  Sd  S(   Ns	   ../my.gifs   /tmp/base/dir/index.htmls   /tmp/base/my.gifs	   /tmp/bases8   Path modification failed.
	Expected "%s",
	got      "%s"(   s   expecteds   computeRelativeHTMLLinks   actuals	   __debug__s   AssertionError(   s   selfs   actuals   expected(    (    sN   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_0/happydoclib/path.pys,   testComputeRelativeHTMLLinkInParentDirectorys   		+c    sQ   d } t d  } t o! | | j p t d | | f  d  Sd  S(   Ns   foos   ./foos8   Path modification failed.
	Expected "%s",
	got      "%s"(   s   expecteds   removeRelativePrefixs   actuals	   __debug__s   AssertionError(   s   selfs   actuals   expected(    (    sN   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_0/happydoclib/path.pys"   testRemoveRelativePrefixCurrentDirs   	+c    sQ   d } t d  } t o! | | j p t d | | f  d  Sd  S(   Ns   foos   ../foos8   Path modification failed.
	Expected "%s",
	got      "%s"(   s   expecteds   removeRelativePrefixs   actuals	   __debug__s   AssertionError(   s   selfs   actuals   expected(    (    sN   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_0/happydoclib/path.pys!   testRemoveRelativePrefixParentDirs   	+c    sc   t  i i d d  } t d d  } t o! | | j p t d | | f  d  Sd  S(   Ns   tmps   foos8   Path modification failed.
	Expected "%s",
	got      "%s"(   s   oss   paths   joins   expecteds   actuals	   __debug__s   AssertionError(   s   selfs   actuals   expected(    (    sN   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_0/happydoclib/path.pys   testJoins   +(   s   testApplyPrefixToPaths   testApplyPrefixToPathEmptys   testApplyPrefixToPathRelatives   testRemovePrefixs   testRemovePrefixNotTheres   testRemovePrefixEmptyPaths   testRemovePrefixEmptyPrefixs   testCommonPrefixs   testCommonPrefixNones   testCommonPrefixEmptyPathss   testJoinWithCommonMiddles!   testJoinWithCommonMiddleNotCommons#   testJoinWithCommonMiddleEmptyPrefixs"   testJoinWithCommonMiddleEmptyPath1s"   testJoinWithCommonMiddleEmptyPath2s   testComputeRelativeHTMLLinks)   testComputeRelativeHTMLLinkUpOneDirectorys,   testComputeRelativeHTMLLinkInParentDirectorys"   testRemoveRelativePrefixCurrentDirs!   testRemoveRelativePrefixParentDirs   testJoin(    (    (    sN   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_0/happydoclib/path.pys   PathTestMs*   		
(   s   __doc__s   __rcs_info__s   splits   __version__s   strings   oss   syss   globs   happydoclib.StreamFlushTests   StreamFlushTests   rmkdirs   applyPrefixToPaths   removePrefixs   commonPrefixs   joinWithCommonMiddles   computeRelativeHTMLLinks   findFilesInDirs   removeRelativePrefixs   joins   cwds   normpaths   isdirs   existss   basenames   dirnames   splitexts   PathTest(   s   __rcs_info__s   cwds   oss   __version__s   PathTests   splits   basenames   rmkdirs   removePrefixs   normpaths   findFilesInDirs   joins   commonPrefixs   isdirs   joinWithCommonMiddles   dirnames   StreamFlushTests   computeRelativeHTMLLinks   syss   globs   splitexts   applyPrefixToPaths   existss   strings   removeRelativePrefix(    (    sN   /home/dhellmann/Personal/Devel/HappyDoc/dist/HappyDoc-r2_0/happydoclib/path.pys   ?! s8   Q!,A