[Subversion] / PEAK / src / peak / naming / factories / openable.py  

Diff of /PEAK/src/peak/naming/factories/openable.py

Parent Directory | Revision Log

version 1882, Thu Oct 21 03:58:37 2004 UTC version 1883, Fri Oct 22 02:54:52 2004 UTC
Line 1 
Line 1 
 from peak.api import *  from peak.api import *
 import sys, os, os.path  import sys, os, os.path, posixpath
 URL = naming.URL    # XXX can't import an un-loaded lazy module from its parent  URL = naming.URL    # XXX can't import an un-loaded lazy module from its parent
   
   
 class GenericPathURL(URL.Base):  class GenericPathURL(URL.Base):
   
       protocols.advise(
           instancesProvide=[naming.IBaseURL]
       )
   
     nameAttr = 'path'      nameAttr = 'path'
     supportedSchemes = 'http','https','ftp','file',      supportedSchemes = 'http','https','ftp','file',
   
     class user(URL.Field): pass      class user(URL.Field):
     class passwd(URL.Field): pass          pass
   
       class passwd(URL.Field):
           pass
   
     class host(URL.Field):      class host(URL.Field):
         defaultValue = None          defaultValue = None
Line 17 
Line 25 
             defaultValue = None              defaultValue = None
         )          )
   
     class port(URL.IntField): pass      class port(URL.IntField):
           pass
   
     class path(URL.NameField):      class path(URL.NameField):
         referencedType = naming.CompositeName          referencedType = naming.CompositeName
         canBeEmpty = True          canBeEmpty = True
   
     class query(URL.Field): pass      class query(URL.Field):
           pass
   
       class fragment(URL.Field):
           pass
   
     class fragment(URL.Field): pass  
   
     # Make syntax usable w/subclasses that redefine individual fields      # Make syntax usable w/subclasses that redefine individual fields
   
Line 39 
Line 51 
         )          )
     )      )
   
       def joinURL(self,relativeURL):
           from urlparse import urljoin
           return self.mdl_fromString(urljoin(str(self),relativeURL))
   
   
 class OpenableURL(GenericPathURL):  class OpenableURL(GenericPathURL):
     defaultFactory = 'peak.naming.factories.openable.URLStreamFactory'      defaultFactory = 'peak.naming.factories.openable.URLStreamFactory'
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
 class FileURL(OpenableURL):  class FileURL(OpenableURL):
   
     supportedSchemes = 'file',      supportedSchemes = 'file',
Line 80 
Line 118 
     fromFilename = classmethod(fromFilename)      fromFilename = classmethod(fromFilename)
   
   
   
   
   
 class PkgFileURL(URL.Base):  class PkgFileURL(URL.Base):
   
     protocols.advise(      protocols.advise(
         classProvides=[naming.IObjectFactory],          classProvides=[naming.IObjectFactory],
           instancesProvide=[naming.IBaseURL],
     )      )
   
     nameAttr = 'body'      nameAttr = 'path'
     supportedSchemes = 'pkgfile',      supportedSchemes = 'pkgfile',
     defaultFactory = 'peak.naming.factories.openable.PkgFileURL'      defaultFactory = 'peak.naming.factories.openable.PkgFileURL'
   
     class body(URL.NameField):  
         referencedType = naming.CompositeName  
         canBeEmpty = True  
   
     def getObjectInstance(klass, context, refInfo, name, attrs=None):  
         url, = refInfo.addresses  
         try:  
             module,path = str(url.body).split('/',1)  
         except ValueError:  
             raise exceptions.InvalidName(  
                 "Missing package name in %s" % url  
             )  
         return config.packageFile(module,path)  
   
     getObjectInstance = classmethod(getObjectInstance)  
   
   
   
   
   
   
   
   
   
       class module(URL.Field):
           pass
   
       class path(URL.NameField):
           referencedType = naming.CompositeName
           canBeEmpty = False
   
       syntax = URL.Sequence(module, '/', path)
   
       def joinURL(self,relativeURL):
           path = posixpath.normpath(
               posixpath.join(str(self.path[:-1]),relativeURL)
           )
           if path.startswith('/') or path.startswith('../'):
               raise exceptions.InvalidName(
                   "Invalid relative URL for pkgfile: URL",
                       resolvedName=self, remainingName=relativeURL
               )
           return self.__class__(self.scheme, module=self.module,
               path=path
           )
   
       def getObjectInstance(klass, context, refInfo, name, attrs=None):
           url, = refInfo.addresses
           return config.packageFile(url.module,str(url.path))
   
       getObjectInstance = classmethod(getObjectInstance)
   
   
 class DataURL(URL.Base):  class DataURL(URL.Base):


Generate output suitable for use with a patch program
Legend:
Removed from v.1882  
changed lines
  Added in v.1883

cvs-admin@eby-sarna.com

Powered by ViewCVS 1.0-dev

ViewCVS and CVS Help