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


Python LRU.pop方法代码示例

本文整理汇总了Python中lru.LRU.pop方法的典型用法代码示例。如果您正苦于以下问题:Python LRU.pop方法的具体用法?Python LRU.pop怎么用?Python LRU.pop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在lru.LRU的用法示例。


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

示例1: MTPStorage

# 需要导入模块: from lru import LRU [as 别名]
# 或者: from lru.LRU import pop [as 别名]

#.........这里部分代码省略.........
            #def __init__(self, path, id=-2, storageid=-2, folderid=-2, mtp=None, timestamp=0, is_refresh=True):
            self.directories.append(MTPFolder(path=dirname, id= -3, storageid= -3, folderid= -2, is_refresh=False)) 
         self.root = None
         self.contents[utf8(os.sep)] = self
      else:         
         self.storage = pstorage
         storage = pstorage.contents
         self.type = storage.StorageType
         self.freespace = storage.FreeSpaceInBytes
         self.capacity = storage.MaxCapacity
         path = os.sep + storage.StorageDescription
         MTPEntry.__init__(self, storage.id, path, storageid=None, folderid=0)
         self.root = MTPFolder(path=path, id=0, storageid=storage.id, folderid=0, mtp=self.mtp)
         self.contents[utf8(path)] = self.root
      
   def is_directory(self):
      return True     
   
   def get_attributes(self):
      return { 'st_atime': self.timestamp, 'st_ctime': self.timestamp, 'st_gid': os.getgid(),
               'st_mode': stat.S_IFDIR | 0755, 'st_mtime': self.timestamp, 'st_nlink': 1,
               'st_size': 0, 'st_uid': os.getuid() }
      
   def get_directories(self):
      if self.directories is None:
         if self.root is None:
            return ()
         else:
            return self.root.get_directories()
      else:
         return self.directories
      
   def get_files(self):
      if self.root is None:
         return ()
      else:
         return self.root.get_files()
      
   def add_file(self, file):
      if not self.root is None:
         self.root.add_file(self, file)
               
   def __str__(self):            
      s = "MTPStorage %s: id=%d, device=%s%s" % (self.name, self.id, self.open_device, os.linesep)      
      return s
         
   def find_entry(self, path):
      path = utf8(path)
      self.log.debug('find_entry(%s)' % (path,))
      try:
         if path.strip() == '':
            path = os.sep + self.name 
         entry = self.contents.get(path)
         if entry is None:         
            components = [comp for comp in path.split(os.sep) if len(comp.strip()) != 0]
            if len(components) == 0:
               return None
            if components[0] != self.name:
               raise LookupError('Invalid storage (expected %s, was %s)' % (self.name, components[0]))
            entry = self.__find_entry(self.root, components[1:])
         else:
            if entry.is_directory() and entry.must_refresh:
               entry.refresh()
         return entry
      except:
         self.log.exception("")
         return None
   
   def __find_entry(self, entry, components):
      self.log.debug("__find_entry(%s, %s)" % (entry, str(components)))
      if len(components) == 0:
         return entry
      name = components[0]
      path = entry.path + os.sep + name 
      en = self.contents.get(utf8(path))
      if not en is None:
         if en.is_directory() and en.must_refresh:
            en.refresh()
         return self.__find_entry(en, components[1:])
      en = entry.find_directory(name)
      if not en is None and en.is_directory():
         self.contents[utf8(path)] = en
         if en.must_refresh:
            en.refresh()
         return self.__find_entry(en, components[1:])
      return entry.find_file(name)
   
   def remove_entry(self, path):
      try:
         return self.contents.pop(utf8(path))
      except:
         #self.log.warn('MTPStorage.remove_entry: %s not found' % (path,))
         return None
      
   def refresh(self):
      if not self.root is None and self.must_refresh:
         self.must_refresh = not self.root.refresh()
   
   def close(self):
      pass
开发者ID:donaldmunro,项目名称:pymtpfs,代码行数:104,代码来源:mtp.py


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