Antoine Pitrou avatar Antoine Pitrou committed eee53f5

Add PurePath.anchor

Comments (0)

Files changed (4)

 Version 0.8
 ^^^^^^^^^^^
 
-- Add PurePath.name
+- Add PurePath.name and PurePath.anchor
 - Add Path.owner and Path.group
 
 Version 0.7
       >>> PureNTPath('//some/share').root
       '\\'
 
+.. data:: PurePath.anchor
+
+   The concatenation of the drive and root::
+
+      >>> PureNTPath('c:/Program Files/').anchor
+      'c:\\'
+      >>> PureNTPath('c:Program Files/').anchor
+      'c:'
+      >>> PurePosixPath('/etc').anchor
+      '/'
+      >>> PureNTPath('//some/share').anchor
+      '\\\\some\\share\\'
+
 .. data:: PurePath.name
 
    A string representing the final path component, excluding the drive and
                     doc="""The root of the path, if any""")
 
     @property
+    def anchor(self):
+        """The concatenation of the drive and root, or ''."""
+        anchor = self._drv + self._root
+        return anchor
+
+    @property
     def name(self):
         """The final path component, if any."""
         parts = self._parts
         self.assertEqual(P('/').root, sep)
         self.assertEqual(P('/a/b').root, sep)
 
+    def test_anchor_common(self):
+        P = self.cls
+        sep = self.sep
+        self.assertEqual(P('').anchor, '')
+        self.assertEqual(P('a/b').anchor, '')
+        self.assertEqual(P('/').anchor, sep)
+        self.assertEqual(P('/a/b').anchor, sep)
+
     def test_name_common(self):
         P = self.cls
         self.assertEqual(P('').name, '')
         self.assertEqual(P('//a/b/').root, '\\')
         self.assertEqual(P('//a/b/c/d').root, '\\')
 
+    def test_anchor(self):
+        P = self.cls
+        self.assertEqual(P('c:').anchor, 'c:')
+        self.assertEqual(P('c:a/b').anchor, 'c:')
+        self.assertEqual(P('c:/').anchor, 'c:\\')
+        self.assertEqual(P('c:/a/b/').anchor, 'c:\\')
+        self.assertEqual(P('//a/b').anchor, '\\\\a\\b\\')
+        self.assertEqual(P('//a/b/').anchor, '\\\\a\\b\\')
+        self.assertEqual(P('//a/b/c/d').anchor, '\\\\a\\b\\')
+
     def test_name(self):
         P = self.cls
         self.assertEqual(P('c:').name, '')
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.