当前位置: 首页>>代码示例>>Python>>正文


Python utils.expandpath函数代码示例

本文整理汇总了Python中utils.expandpath函数的典型用法代码示例。如果您正苦于以下问题:Python expandpath函数的具体用法?Python expandpath怎么用?Python expandpath使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了expandpath函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _changed

        def _changed(self):
            mtime=0
            filelist=[]
            try:
                fp = expandpath(self.filepath)
                mtime = stat(fp)[8]
                # some Windows directories don't change mtime 
                # when a file is added to or deleted from them :-(
                # So keep a list of files as well, and see if that
                # changes
                path.walk(fp,_walker,filelist)
                filelist.sort()
            except: 
                LOG('DirectoryView',
                    ERROR,
                    'Error checking for directory modification',
                    error=exc_info())
                
            if mtime != self._v_last_read or filelist != self._v_last_filelist:
                self._v_last_read = mtime
                self._v_last_filelist = filelist
                
                return 1

            return 0
开发者ID:goschtl,项目名称:zope,代码行数:25,代码来源:DirectoryView.py

示例2: _readFile

    def _readFile(self, reparse):
        fp = expandpath(self._filepath)
        file = open(fp, 'r')    # not 'rb', as this is a text file!
        try:
            data = file.read()
        finally: file.close()

        # parse parameters
        parameters={}
        start = data.find('<dtml-comment>')
        end   = data.find('</dtml-comment>')
        if start==-1 or end==-1 or start>end:
            raise ValueError,'Could not find parameter block'
        block = data[start+14:end]

        for line in block.split('\n'):
            pair = line.split(':',1)
            if len(pair)!=2:
                continue
            parameters[pair[0].strip().lower()]=pair[1].strip()
        
        # check for required parameters
        try:
            connection_id =   ( parameters.get('connection id', '') or
                                parameters['connection_id'] )
        except KeyError,e:
            raise ValueError("The '%s' parameter is required "
                             "but was not supplied" % e)
开发者ID:goschtl,项目名称:zope,代码行数:28,代码来源:FSZSQLMethod.py

示例3: getContents

    def getContents(self, registry):
        changed = 0
        if Globals.DevelopmentMode:
            try: mtime = stat(expandpath(self.filepath))[8]
            except: mtime = 0
            if mtime != self._v_last_read:
                self._v_last_read = mtime
                changed = 1

        if self.data is None or changed:
            try:
                self.data, self.objects = self.prepareContents(registry,
                    register_subdirs=changed)
            except:
                from zLOG import LOG, ERROR
                import sys, traceback
                type,value,tb = sys.exc_info()
                LOG( 'DirectoryView'
                   , ERROR
                   , 'Error during prepareContents:'
                   , traceback.format_exception( type, value, tb )
                   )
                self.data = {}
                self.objects = ()
                    
        return self.data, self.objects
开发者ID:goschtl,项目名称:zope,代码行数:26,代码来源:DirectoryView.py

示例4: _updateFromFS

 def _updateFromFS(self):
     if Globals.DevelopmentMode:
         fp = expandpath(self._filepath)
         try:    mtime=stat(fp)[8]
         except: mtime=0
         if mtime != self._file_mod_time:
             self._file_mod_time = mtime
             self._readFile(1)
开发者ID:goschtl,项目名称:zope,代码行数:8,代码来源:FSObject.py

示例5: _readFile

 def _readFile(self, reparse):
     fp = expandpath(self._filepath)
     file = open(fp, 'rb')
     try: data = file.read()
     finally: file.close()
     if reparse or self.content_type == 'unknown/unknown':
         self.ZCacheable_invalidate()
         self.content_type=self._get_content_type(file, data, self.id)
     return data
开发者ID:goschtl,项目名称:zope,代码行数:9,代码来源:FSFile.py

示例6: _updateFromFS

 def _updateFromFS(self):
     parsed = self._parsed
     if not parsed or Globals.DevelopmentMode:
         fp = expandpath(self._filepath)
         try:    mtime=stat(fp)[8]
         except: mtime=0
         if not parsed or mtime != self._file_mod_time:
             self._parsed = 1
             self._file_mod_time = mtime
             self._readFile(1)
开发者ID:goschtl,项目名称:zope,代码行数:10,代码来源:FSObject.py

示例7: _updateFromFS

 def _updateFromFS(self):
     parsed = self._parsed
     if not parsed or Globals.DevelopmentMode:
         fp = expandpath(self._filepath)
         try:    mtime=stat(fp)[8]
         except: mtime=0
         if not parsed or mtime != self._file_mod_time:
             # if we have to read the file again, remove the cache
             self.ZCacheable_invalidate()
             self._readFile(1)
             self._file_mod_time = mtime
             self._parsed = 1
开发者ID:goschtl,项目名称:zope,代码行数:12,代码来源:FSObject.py

示例8: _readFileAsResourceOrDirect

 def _readFileAsResourceOrDirect(self):
     """ Return our file's bits, looking in the appropriate place.
     """
     if self._filepath is None:
         return resource_string(self._package, self._entry_subpath)
     else:
         fp = expandpath(self._filepath)
         file = open(fp, 'r')    # not 'rb', as this is a text file!
         try:
             return file.read()
         finally:
             file.close()
开发者ID:goschtl,项目名称:zope,代码行数:12,代码来源:FSObject.py

示例9: __init__

    def __init__(self, id, filepath, fullname=None, properties=None):
        if properties:
            # Since props come from the filesystem, this should be
            # safe.
            self.__dict__.update(properties)

        self.id = id
        self._filepath = filepath
        fp = expandpath(self._filepath)
        
        try: self._file_mod_time = stat(fp)[8]
        except: pass
        self._readFile(0)
开发者ID:goschtl,项目名称:zope,代码行数:13,代码来源:FSObject.py

示例10: _readFile

    def _readFile( self, reparse ):

        fp = expandpath( self._filepath )
        file = open( fp, 'r' )  # not binary, we want CRLF munging here.

        try:
            data = file.read()
        finally:
            file.close()

        self.raw = data

        if reparse:
            self.cook()
开发者ID:goschtl,项目名称:zope,代码行数:14,代码来源:FSSTXMethod.py

示例11: _readFile

 def _readFile(self, reparse):
     fp = expandpath(self._filepath)
     file = open(fp, 'rb')
     try:
         data = self._data = file.read()
     finally:
         file.close()
     if reparse or self.content_type == 'unknown/unknown':
         self.ZCacheable_invalidate()
         ct, width, height = getImageInfo( data )
         self.content_type = ct
         self.width = width
         self.height = height
     return data
开发者ID:goschtl,项目名称:zope,代码行数:14,代码来源:FSImage.py

示例12: _readFile

 def _readFile(self, reparse):
     fp = expandpath(self._filepath)
     file = open(fp, 'r')    # not 'rb', as this is a text file!
     try:
         data = file.read()
     finally:
         file.close()
     self.raw = data
     if reparse:
         self._reading = 1  # Avoid infinite recursion
         try:
             self.cook()
         finally:
             self._reading = 0
开发者ID:goschtl,项目名称:zope,代码行数:14,代码来源:FSDTMLMethod.py

示例13: _readFile

    def _readFile(self, reparse):
        """Read the data from the filesystem.

        Read the file (indicated by exandpath(self._filepath), and parse the
        data if necessary.
        """
        warn('FSProperties objects will disappear in CMF 1.7 - Use '
             'FSMetadata objects instead.', DeprecationWarning)

        fp = expandpath(self._filepath)

        file = open(fp, 'r')    # not 'rb', as this is a text file!
        try:
            lines = file.readlines()
        finally:
            file.close()

        map = []
        lino=0

        for line in lines:

            lino = lino + 1
            line = line.strip()

            if not line or line[0] == '#':
                continue

            try:
                propname, proptv = line.split(':',1)
                #XXX multi-line properties?
                proptype, propvstr = proptv.split( '=', 1 )
                propname = propname.strip()
                proptype = proptype.strip()
                propvstr = propvstr.strip()
                converter = get_converter( proptype, lambda x: x )
                propvalue = converter( propvstr )
                # Should be safe since we're loading from
                # the filesystem.
                setattr(self, propname, propvalue)
                map.append({'id':propname,
                            'type':proptype,
                            'mode':'',
                            'default_value':propvalue,
                            })
            except:
                raise ValueError, ( 'Error processing line %s of %s:\n%s'
                                  % (lino,fp,line) )
        self._properties = tuple(map)
开发者ID:goschtl,项目名称:zope,代码行数:49,代码来源:FSPropertiesObject.py

示例14: __init__

    def __init__(self, id, filepath, fullname=None, properties=None):
        if properties:
            # Since props come from the filesystem, this should be
            # safe.
            self.__dict__.update(properties)
            if fullname and properties.get('keep_extension', 0):
                id = fullname

        self.id = id
        self.__name__ = id # __name__ is used in traceback reporting
        self._filepath = filepath
        fp = expandpath(self._filepath)
        
        try: self._file_mod_time = stat(fp)[8]
        except: pass
        self._readFile(0)
开发者ID:goschtl,项目名称:zope,代码行数:16,代码来源:FSObject.py

示例15: _readFile

    def _readFile(self, reparse):
        fp = expandpath(self._filepath)
        file = open(fp, 'r')    # not 'rb', as this is a text file!
        try:
            data = file.read()
        finally:
            file.close()
        if reparse:
            xml_info = xml_detect_re.match(data)
            if xml_info:
                # Smells like xml
                # set "content_type" from the XML declaration
                encoding = xml_info.group(1) or 'utf-8'
                self.content_type = 'text/xml; charset=%s' % encoding

            self.write(data)
开发者ID:goschtl,项目名称:zope,代码行数:16,代码来源:FSPageTemplate.py


注:本文中的utils.expandpath函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。