def makewithurl(klass, url): """Make File object from file URL.""" obj = klass(_kNoPath) obj._desc = newdesc(kae.typeFileURL, url) obj._url = url obj._path = converturltopath(url, kCFURLPOSIXPathStyle) return obj
def path(self): if self._path is None: self._path = converturltopath(self.url, kCFURLPOSIXPathStyle) return self._path
class File(_Base): """A reference to a filesystem location.""" # Constructors def __init__(self, path): """Make File object from POSIX path.""" if path is not _kNoPath: if not isinstance(path, unicode): path = unicode(path) self._path = abspath(path) self._url = convertpathtourl(self._path, kCFURLPOSIXPathStyle) self._desc = newdesc(kae.typeFileURL, self._url) def makewithhfspath(klass, path): return klass.makewithurl(convertpathtourl(path, kCFURLHFSPathStyle)) makewithhfspath = classmethod(makewithhfspath) def makewithurl(klass, url): """Make File object from file URL.""" obj = klass(_kNoPath) obj._desc = newdesc(kae.typeFileURL, url) obj._url = url obj._path = converturltopath(url, kCFURLPOSIXPathStyle) return obj makewithurl = classmethod(makewithurl) def makewithdesc(klass, desc): """Make File object from aem.ae.AEDesc of typeFSS/typeFSRef/typeFileURL. Note: behaviour for other descriptor types is undefined: typeAlias will cause problems, others will probably fail. """ obj = klass(_kNoPath) obj._path = None obj._url = None if desc.type in [kae.typeFSS, kae.typeFSRef, kae.typeFileURL]: obj._desc = desc else: obj._desc = desc.coerce(kae.typeFileURL) return obj makewithdesc = classmethod(makewithdesc) # Instance methods def __repr__(self): return 'mactypes.File(%r)' % self.path # Properties def path(self): if self._path is None: self._path = converturltopath(self.url, kCFURLPOSIXPathStyle) return self._path path = property(path, doc="Get as POSIX path.") hfspath = property( lambda self: converturltopath(self.url, kCFURLHFSPathStyle), doc="Get as HFS path.") def url(self): if self._url is None: if self._desc.type == kae.typeFileURL: self._url = self._desc.data else: self._url = self._desc.coerce(kae.typeFileURL).data return self._url url = property(url, doc="Get as file URL.") file = property(lambda self: File(self.path), doc="Get as mactypes.File.") alias = property(lambda self: Alias.makewithdesc(self.desc), doc="Get as mactypes.Alias.") def desc(self): if self._desc is None: self._desc = newdesc(kae.typeFileURL, self.url) return self._desc desc = property(desc, doc="Get as aem.ae.AEDesc.")
desc = desc.coerce(kae.typeAlias) obj = klass(_kNoPath) obj._desc = desc return obj makewithdesc = classmethod(makewithdesc) # Instance methods def __repr__(self): return 'mactypes.Alias(%r)' % unicode(self.path) # Properties path = property( lambda self: converturltopath(self.url, kCFURLPOSIXPathStyle), doc="Get as POSIX path.") hfspath = property( lambda self: converturltopath(self.url, kCFURLHFSPathStyle), doc="Get as HFS path.") url = property(lambda self: self._desc.coerce(kae.typeFileURL).data, doc="Get as file URL.") file = property(lambda self: File.makewithdesc(self._desc), doc="Get as mactypes.File.") alias = property(lambda self: self, doc="Get as mactypes.Alias (i.e. itself).")
""" if desc.type != kae.typeAlias: desc = desc.coerce(kae.typeAlias) obj = klass(_kNoPath) obj._desc = desc return obj makewithdesc = classmethod(makewithdesc) # Instance methods def __repr__(self): return 'mactypes.Alias(%r)' % unicode(self.path) # Properties path = property(lambda self: converturltopath(self.url, kCFURLPOSIXPathStyle), doc="Get as POSIX path.") hfspath = property(lambda self: converturltopath(self.url, kCFURLHFSPathStyle), doc="Get as HFS path.") url = property(lambda self: self._desc.coerce(kae.typeFileURL).data, doc="Get as file URL.") file = property(lambda self: File.makewithdesc(self._desc), doc="Get as mactypes.File.") alias = property(lambda self: self, doc="Get as mactypes.Alias (i.e. itself).") desc = property(lambda self: self._desc, doc="Get as aem.ae.AEDesc.") class File(_Base): """A reference to a filesystem location."""