Package zope :: Package configuration :: Module fields :: Class Path
[show private | hide private]
[frames | no frames]

Type Path

object --+                
         |                
   Element --+            
             |            
     Attribute --+        
                 |        
             Field --+    
                     |    
        object --+   |    
                 |   |    
         MinMaxLen --+    
                     |    
                  Text --+
                         |
                        Path


A file path name, which may be input as a relative path

Input paths are converted to absolute paths and normalized.

Let's look at an example:

First, we need a "context" for the field that has a path function for converting relative path to an absolute path.

We'll be careful to do this in an os-independent fashion.

>>> class FauxContext(object):
...    def path(self, p):
...       return os.path.join(os.sep, 'faux', 'context', p)
>>> context = FauxContext()
>>> field = Path().bind(context)

Lets try an absolute path first:

>>> p = unicode(os.path.join(os.sep, 'a', 'b'))
>>> n = field.fromUnicode(p)
>>> n.split(os.sep)
[u'', u'a', u'b']

This should also work with extra spaces around the path:

>>> p = "   \n   %s   \n\n   " % p
>>> n = field.fromUnicode(p)
>>> n.split(os.sep)
[u'', u'a', u'b']

Now try a relative path:

>>> p = unicode(os.path.join('a', 'b'))
>>> n = field.fromUnicode(p)
>>> n.split(os.sep)
[u'', u'faux', u'context', u'a', u'b']

Method Summary
  fromUnicode(self, u)
    Inherited from object
  __delattr__(...)
x.__delattr__('name') <==> del x.name
  __getattribute__(...)
x.__getattribute__('name') <==> x.name
  __hash__(x)
x.__hash__() <==> hash(x)
  __new__(T, S, ...)
T.__new__(S, ...) -> a new object with type S, a subtype of T
  __reduce__(...)
helper for pickle
  __reduce_ex__(...)
helper for pickle
  __repr__(x)
x.__repr__() <==> repr(x)
  __setattr__(...)
x.__setattr__('name', value) <==> x.name = value
  __str__(x)
x.__str__() <==> str(x)

Class Variable Summary
Implements __implemented__ = <implementedBy zope.configuration.fiel...
ClassProvides __provides__ = <zope.interface.declarations.ClassProvide...

Class Variable Details

__implemented__

Type:
Implements
Value:
<implementedBy zope.configuration.fields.Path>                         

__provides__

Type:
ClassProvides
Value:
<zope.interface.declarations.ClassProvides object at 0xb64a804c>       

Generated by Epydoc 2.1 on Fri Jun 24 12:01:22 2005 http://epydoc.sf.net