[Python-checkins] python/nondist/sandbox/path path.py, 1.7, 1.8 test_path.py, 1.6, 1.7
birkenfeld@users.sourceforge.net
birkenfeld at users.sourceforge.net
Sat Jul 30 14:14:17 CEST 2005
Update of /cvsroot/python/python/nondist/sandbox/path
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13772
Modified Files:
path.py test_path.py
Log Message:
Allow constructor to take more args. Path("a", "b") => "a/b".
Index: path.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/path/path.py,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- path.py 25 Jul 2005 16:09:17 -0000 1.7
+++ path.py 30 Jul 2005 12:14:14 -0000 1.8
@@ -60,11 +60,13 @@
"""
if not args:
return Path(os.curdir)
- if len(args) > 1:
- raise TypeError("Path() takes at most 1 argument (%i given)" % len(args))
- if not isinstance(args[0], basestring):
- raise ValueError("Path() argument must be Path, str or unicode")
- return _base.__new__(typ, *args)
+ for arg in args:
+ if not isinstance(arg, basestring):
+ raise ValueError("Path() arguments must be Path, str or unicode")
+ if len(args) == 1:
+ return _base.__new__(typ, *args)
+ else:
+ return Path(os.path.join(*args))
# Iterating over a string yields its parts
def __iter__(self):
@@ -234,18 +236,12 @@
""" The UNC mount point for this path.
This is empty for paths on local drives. """)
- @staticmethod
- def join(*args):
- if args:
- return Path(args[0]).joinwith(args[1:])
- return Path('')
-
def joinwith(self, *args):
""" Join two or more path components, adding a separator
character (os.sep) if needed. Returns a new path
object.
"""
- return Path(os.path.join(self, *map(_base, args)))
+ return Path(os.path.join(self, *args))
joinpath = joinwith
@@ -257,7 +253,7 @@
this path (for example, '/' or 'C:\\'). The other items in
the list will be strings.
- Path.join(*result) will yield the original path.
+ Path(*result) will yield the original path.
"""
parts = []
loc = self
Index: test_path.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/path/test_path.py,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- test_path.py 25 Jul 2005 16:06:32 -0000 1.6
+++ test_path.py 30 Jul 2005 12:14:14 -0000 1.7
@@ -28,17 +28,19 @@
class BasicTestCase(unittest.TestCase):
def testConstructor(self):
- # constructor can only be called with zero or one arguments
+ # constructor can be called with zero arguments, which is os.curdir
p = Path()
- self.assert_(p.base() == os.curdir)
+ self.assertEquals(p.base(), os.curdir)
- self.assertRaises(TypeError, Path, "a", "b")
- self.assertRaises(TypeError, Path, 1, 2)
-
- # constructor can only be called with basestring as argument
+ # constructor can only be called with basestring(s) as argument
self.assertRaises(ValueError, Path, None)
self.assertRaises(ValueError, Path, 1)
+ # calling with more than one argument joins them
+ p1 = Path("a").joinwith("b")
+ p2 = Path("a", "b")
+ self.assertEquals(p1, p2)
+
def testRelpath(self):
root = Path(p(nt='C:\\',
posix='/'))
More information about the Python-checkins
mailing list