本文整理汇总了Python中cPickle.Unpickler.keys方法的典型用法代码示例。如果您正苦于以下问题:Python Unpickler.keys方法的具体用法?Python Unpickler.keys怎么用?Python Unpickler.keys使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cPickle.Unpickler
的用法示例。
在下文中一共展示了Unpickler.keys方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: network_setup
# 需要导入模块: from cPickle import Unpickler [as 别名]
# 或者: from cPickle.Unpickler import keys [as 别名]
def network_setup(self):
dict = {}
self.net_mtime = self.network_connect()
if self.net_mtime != None:
if os.path.exists( self.user_data_file ):
self.network_update()
local_mtime = int(os.stat( self.user_data_file ).st_mtime)
if local_mtime > self.net_mtime:
self.network_upload()
elif local_mtime < self.net_mtime:
self.network_download()
else:
self.network_download()
if os.path.exists( self.user_data_file ):
ph = open( self.user_data_file )
dict = Unpickler( ph ).load()[-1]
if not os.path.exists( self.user_data_file ) and self.net_mtime == None:
ph = open( self.user_data_file, 'w+' )
Pickler( ph ).dump( dict )
ph.close()
os.utime( self.user_data_file, (0,0) )
last_month = dateDelta( date.today() ).get_last_month()
keys = dict.keys()
keys.sort()
for key in keys:
if key[:7] < '%0.4d-%0.2d' % (last_month.year,last_month.month):
dict.pop( key )
else:
break
self.freetime.update( dict )
示例2: freetimeConfig
# 需要导入模块: from cPickle import Unpickler [as 别名]
# 或者: from cPickle.Unpickler import keys [as 别名]
#.........这里部分代码省略.........
self.error = 'Please add your Freetime key to use the calendar.'
return
self.category = userkey.get('UserKey', 'category')
pkey = StringIO()
pkey.write( userkey.get('UserKey','rsa').lstrip() )
pkey.seek(0)
self.pkey = RSAKey.from_private_key( pkey )
self.server = userkey.get('UserKey', 'server')
self.server_account = userkey.get('UserKey','account')
groups_file = os.path.join( config_path, 'groups.txt' )
if os.path.exists( groups_file ):
text = open( groups_file ).read()
try:
text = text.decode('utf8')
except:
text = text.decode('shift_jis')
print 'Barfed on groups file, using shift-jis encoding'
self.groups = [x[1:-1] for x in re.findall('\[[^]]+\]'.decode('utf8'), text )]
else:
self.groups = []
if self.groups:
self.groups.insert(0, 'Personal')
##print self.groups
#
# Reconcile old group data and current groups configuration
self.groups_data_file = os.path.join( config_path, 'groups.pkl' )
if os.path.exists( self.groups_data_file ):
ph = open( self.groups_data_file )
self.groups_data = Unpickler( ph ).load()
ph.close()
else:
self.groups_data = {}
for key in self.groups_data.keys():
if not key in self.groups:
self.groups_data.pop(key)
for group in self.groups:
if not self.groups_data.has_key( group ):
self.groups_data[ group ] = []
self.build_user_info()
self.known_hosts_file = os.path.join( defaults_dir, 'known_hosts')
self.user_data_file = os.path.join( data_path, self.category, self.userkey )
self.freetime = freeTime()
def build_user_info(self):
self.users = {'Staff': [], 'Student': []}
today = date.today()
self.user_index = {}
for category in ['Staff','Student']:
ids = os.listdir( self.category_path[ category ] )
for userid in ids:
userfile = os.path.join( self.category_path[ category ], userid )
ph = open( userfile )
try:
userdata = Unpickler( ph ).load()
doit = True
except EOFError:
ph.close()
os.unlink( userfile )
doit = False
if doit:
ph.close()
fullname = userdata[1].strip()