[Python-checkins] python/nondist/sandbox/path path.py, 1.4, 1.5 test_path.py, 1.4, 1.5
birkenfeld@users.sourceforge.net
birkenfeld at users.sourceforge.net
Mon Jul 25 09:34:26 CEST 2005
Update of /cvsroot/python/python/nondist/sandbox/path
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10847
Modified Files:
path.py test_path.py
Log Message:
* Add base() method to convert to str/unicode.
* Allow compare against normal strings.
Index: path.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/path/path.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- path.py 24 Jul 2005 15:51:07 -0000 1.4
+++ path.py 25 Jul 2005 07:34:21 -0000 1.5
@@ -69,17 +69,8 @@
def __repr__(self):
return 'Path(%s)' % repr(_base(self))
- def __str__(self):
- if _base is unicode:
- return str(self[:])
- else:
- return self[:]
-
- def __unicode__(self):
- if _base is unicode:
- return self[:]
- else:
- return unicode(self[:])
+ def base(self):
+ return _base(self)
# Adding path and string yields a path
# Caution: this is not a join!
@@ -99,37 +90,6 @@
__truediv__ = __div__
- if _base is str:
- # Rich comparison for string
- def __eq__(self, other):
- return isinstance(other, Path) and _base.__eq__(self, other)
-
- def __ne__(self, other):
- return (not isinstance(other, Path)) or _base.__ne__(self, other)
-
- def __lt__(self, other):
- if isinstance(other, Path):
- return _base.__lt__(self, other)
- return NotImplemented
- def __le__(self, other):
- if isinstance(other, Path):
- return _base.__le__(self, other)
- return NotImplemented
- def __gt__(self, other):
- if isinstance(other, Path):
- return _base.__gt__(self, other)
- return NotImplemented
- def __ge__(self, other):
- if isinstance(other, Path):
- return _base.__ge__(self, other)
- return NotImplemented
- else:
- # Unicode has no rich compare methods
- def __cmp__(self, other):
- if isinstance(other, Path):
- return _base.__cmp__(self, other)
- return NotImplemented
-
# Alternative constructor.
@staticmethod
Index: test_path.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/path/test_path.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- test_path.py 24 Jul 2005 15:51:07 -0000 1.4
+++ test_path.py 25 Jul 2005 07:34:23 -0000 1.5
@@ -58,14 +58,15 @@
d = Path('D:\\')
self.assertEqual(d.relpathto(boz), boz)
- ## this isn't going to work cause Paths won't compare
- ## to ordinary strings
- '''
def testStringCompatibility(self):
""" Test compatibility with ordinary strings. """
- #x = Path('xyzzy')
- #self.assertEqual(x, 'xyzzy')
- #self.assertEqual(x, u'xyzzy')
+ x = Path('xyzzy')
+ self.assertEqual(x, 'xyzzy')
+ self.assertEqual(x, u'xyzzy')
+
+ strx = x.base()
+ self.assertEqual(strx, x)
+ self.assert_(strx.__class__ in (str, unicode))
# sorting
items = [Path('fhj'),
@@ -77,7 +78,6 @@
'c']
items.sort()
self.assert_(items == ['A', 'B', 'E', 'c', 'd', 'fgh', 'fhj'])
- '''
def testProperties(self):
# Create sample Path object.
More information about the Python-checkins
mailing list