本文整理匯總了Python中config.conf.session方法的典型用法代碼示例。如果您正苦於以下問題:Python conf.session方法的具體用法?Python conf.session怎麽用?Python conf.session使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類config.conf
的用法示例。
在下文中一共展示了conf.session方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: save_session
# 需要導入模塊: from config import conf [as 別名]
# 或者: from config.conf import session [as 別名]
def save_session(fname=None, session=None, pickleProto=-1):
if fname is None:
fname = conf.session
if not fname:
conf.session = fname = utils.get_temp_file(keep=True)
log_interactive.info("Use [%s] as session file" % fname)
if session is None:
session = __builtin__.__dict__["scapy_session"]
to_be_saved = session.copy()
if to_be_saved.has_key("__builtins__"):
del(to_be_saved["__builtins__"])
for k in to_be_saved.keys():
if type(to_be_saved[k]) in [types.TypeType, types.ClassType, types.ModuleType]:
log_interactive.error("[%s] (%s) can't be saved." % (k, type(to_be_saved[k])))
del(to_be_saved[k])
try:
os.rename(fname, fname+".bak")
except OSError:
pass
f=gzip.open(fname,"wb")
cPickle.dump(to_be_saved, f, pickleProto)
f.close()
示例2: load_session
# 需要導入模塊: from config import conf [as 別名]
# 或者: from config.conf import session [as 別名]
def load_session(fname=None):
if fname is None:
fname = conf.session
try:
s = cPickle.load(gzip.open(fname,"rb"))
except IOError:
s = cPickle.load(open(fname,"rb"))
scapy_session = __builtin__.__dict__["scapy_session"]
scapy_session.clear()
scapy_session.update(s)
示例3: update_session
# 需要導入模塊: from config import conf [as 別名]
# 或者: from config.conf import session [as 別名]
def update_session(fname=None):
if fname is None:
fname = conf.session
try:
s = cPickle.load(gzip.open(fname,"rb"))
except IOError:
s = cPickle.load(open(fname,"rb"))
scapy_session = __builtin__.__dict__["scapy_session"]
scapy_session.update(s)
################
##### Main #####
################