本文整理汇总了Python中marshal.loads函数的典型用法代码示例。如果您正苦于以下问题:Python loads函数的具体用法?Python loads怎么用?Python loads使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了loads函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: loads
def loads(s):
"avoid this one if possible"
lc = marshal.loads(s)
llc = len(marshal.dumps(lc))
compressedObject = s[llc:]
marshalledObject = zlib.decompress(compressedObject)
return marshal.loads(marshalledObject)
开发者ID:kvermilion,项目名称:xbmc-script.subseek,代码行数:7,代码来源:cmarshal.py
示例2: __getitem__
def __getitem__(self, key):
# ====== multiple keys select ====== #
if isinstance(key, (tuple, list, np.ndarray)):
query = """SELECT value FROM {tb}
WHERE key IN {keyval};"""
keyval = '(' + ', '.join(['"%s"' % str(k) for k in key]) + ')'
self.cursor.execute(
query.format(tb=self._current_table, keyval=keyval))
results = self.cursor.fetchall()
# check if any not found keys
if len(results) != len(key):
raise KeyError("Cannot find all `key`='%s' in the dictionary." % keyval)
# load binary data
results = [marshal.loads(r[0]) for r in results]
# ====== single key select ====== #
else:
key = str(key)
if key in self.current_cache:
return self.current_cache[key]
query = """SELECT value FROM {tb} WHERE key="{keyval}" LIMIT 1;"""
results = self.connection.execute(
query.format(tb=self._current_table, keyval=key)).fetchone()
# results = self.cursor.fetchone()
if results is None:
raise KeyError("Cannot find `key`='%s' in the dictionary." % key)
results = marshal.loads(results[0])
return results
开发者ID:imito,项目名称:odin,代码行数:27,代码来源:utils.py
示例3: load_brain_2
def load_brain_2(brain_path):
"""1.2.0 marshal.zip loader
Returns tuple (words, lines)"""
saves_version = b"1.2.0"
try:
zfile = zipfile.ZipFile(brain_path, 'r')
for filename in zfile.namelist():
data = zfile.read(filename)
f = open(filename, 'w+b')
f.write(data)
f.close()
except (EOFError, IOError) as e:
logger.debug(e)
print("no zip found")
logger.info("No archive.zip (pyborg brain) found.")
with open("version", "rb") as vers, open("words.dat", "rb") as words, open("lines.dat", "rb") as lines:
x = vers.read()
logger.debug("Saves Version: %s", x)
if x != saves_version:
print("Error loading dictionary\nPlease convert it before launching pyborg")
logger.error("Error loading dictionary\nPlease convert it before launching pyborg")
logger.debug("Pyborg version: %s", saves_version)
sys.exit(1)
words = marshal.loads(words.read())
lines = marshal.loads(lines.read())
return words, lines
开发者ID:jrabbit,项目名称:pyborg-1up,代码行数:29,代码来源:pyborg.py
示例4: __init__
def __init__(self, settings):
"""
Open the dictionary. Resize as required.
"""
self.settings = settings
self.unfilterd = {}
# Read the dictionary
print(">>> [Gentbot] Reading dictionary...")
try:
with open(self.settings['data_dir'] + "words.dat", "rb") as f:
self.words = marshal.loads(f.read())
with open(self.settings['data_dir'] + "lines.dat", "rb") as f:
self.lines = marshal.loads(f.read())
except (ValueError, EOFError, IOError) as e:
# Create mew database
self.words = {}
self.lines = {}
print("Error reading saves. New database created.")
print(repr(e))
# Is a resizing required?
if len(self.words) != self.settings['num_words']:
print("Updating dictionary information...")
self.settings['num_words'] = len(self.words)
num_contexts = 0
# Get number of contexts
for x in list(self.lines.keys()):
num_contexts += len(self.lines[x][0].split())
self.settings['num_contexts'] = num_contexts
开发者ID:Ferus,项目名称:WhergBot2.0,代码行数:30,代码来源:pyborg.py
示例5: get_server_obj
def get_server_obj(doc, doclist = [], basedoctype = ''):
import marshal
import webnotes
dt = basedoctype and basedoctype or doc.doctype
# load from application or main
sc_compiled = None
try:
# get compiled code
sc_compiled = webnotes.conn.sql("select server_code_compiled from __DocTypeCache where name=%s", dt)[0][0]
# sc_compiled = None
except:
# no code yet
sc_compiled = None
if not sc_compiled:
sc_compiled = get_recompiled_code(dt)
try:
return execute(marshal.loads(sc_compiled), doc, doclist)
except TypeError, e:
# error? re-compile
sc_compiled = get_recompiled_code(dt)
return execute(marshal.loads(sc_compiled), doc, doclist)
开发者ID:ranjithtenz,项目名称:stable,代码行数:28,代码来源:code.py
示例6: add
def add(self, entry):
if self.os is None:
import os
self.os = os
nm = entry[0]
pth = entry[1]
base, ext = self.os.path.splitext(self.os.path.basename(pth))
ispkg = base == "__init__"
try:
txt = open(pth[:-1], "r").read() + "\n"
except (IOError, OSError):
try:
f = open(pth, "rb")
f.seek(8) # skip magic and timestamp
bytecode = f.read()
marshal.loads(bytecode).co_filename # to make sure it's valid
obj = zlib.compress(bytecode, self.LEVEL)
except (IOError, ValueError, EOFError, AttributeError):
raise ValueError("bad bytecode in %s and no source" % pth)
else:
txt = iu._string_replace(txt, "\r\n", "\n")
try:
co = compile(txt, "%s/%s" % (self.path, nm), "exec")
except SyntaxError, e:
print "Syntax error in", pth[:-1]
print e.args
raise
obj = zlib.compress(marshal.dumps(co), self.LEVEL)
开发者ID:BGCX067,项目名称:fabriciols-svn-to-git,代码行数:29,代码来源:archive.py
示例7: buy_group_package
def buy_group_package(self, buy_type):
if buy_type not in get_group_buy_conf().keys():
defer.returnValue( BUY_GROUP_TYPE_WRONG )
_conf = get_group_buy_conf(buy_type)
_stream = yield redis.hget(DICT_GROUP_BUY_PERSON_INFO, self.cid)
_data = loads(_stream)
#[[buy_count, [0,0,0,0]], ......]
bought_count, _info = _data[buy_type-1]
if bought_count + 1 > _conf["LimitNum"]:
defer.returnValue(GROUP_BUY_MAX_COUNT)
if self.user.credits < _conf["CurrentPrice"]:
defer.returnValue(CHAR_CREDIT_NOT_ENOUGH)
yield self.user.consume_credits(_conf["CurrentPrice"], WAY_GROUP_BUY)
bought_count +=1
_st = yield redis.hget(DICT_GROUP_BUY_INFO, buy_type)
_datas = loads(_st)
#buy_type:buy_num
_total_buy_count = _datas
if bought_count == 1:
_total_buy_count += 1
_data[buy_type-1] = [bought_count, _info]
yield redis.hset(DICT_GROUP_BUY_PERSON_INFO, self.cid, dumps(_data))
yield redis.hset(DICT_GROUP_BUY_INFO, buy_type, dumps(_total_buy_count))
_item_type, _item_id, _item_num = _conf['ItemType'], _conf['ItemID'], _conf['ItemNum']
_res = yield item_add(self.user, ItemType=_item_type, ItemID=_item_id, ItemNum = _item_num, AddType=WAY_GROUP_BUY)
_result = (buy_type, _total_buy_count, bought_count, _res[1][0], self.user.credits)
defer.returnValue( _result )
开发者ID:anson-tang,项目名称:3dkserver,代码行数:27,代码来源:gsexcite_activity.py
示例8: _read
def _read(self, event):
if event != select.EPOLLIN:
print "IPC problem (r):", event
self.stop()
return
while True:
try:
data = os.read(self._read_fd, 4096)
if not data:
print "IPC problem; unexpected EOF (r)", event
self.stop()
return
except OSError as e:
if e.errno == errno.EAGAIN:
return
self._temp += data
while len(self._temp) >= 8:
i, l = HDR.unpack_from(self._temp)
if len(self._temp) < 8 + l:
break
data = self._temp[8 : 8 + l]
self._temp = self._temp[8 + l:]
if i & 0x80000000:
response = marshal.loads(data)
self._outstanding.pop(i & 0x7FFFFFFF)(response)
else:
cmd, args, kw = marshal.loads(data)
self._call(i, cmd, args, kw)
开发者ID:apexo,项目名称:imes,代码行数:28,代码来源:ipc.py
示例9: test_unmarshal_evil_long
def test_unmarshal_evil_long(self):
import marshal
raises(ValueError, marshal.loads, 'l\x02\x00\x00\x00\x00\x00\x00\x00')
z = marshal.loads('I\x00\xe4\x0bT\x02\x00\x00\x00')
assert z == 10000000000
z = marshal.loads('I\x00\x1c\xf4\xab\xfd\xff\xff\xff')
assert z == -10000000000
开发者ID:alkorzt,项目名称:pypy,代码行数:7,代码来源:test_marshalimpl.py
示例10: add
def add(self, entry):
if self.os is None:
import os
self.os = os
nm = entry[0]
pth = entry[1]
base, ext = self.os.path.splitext(self.os.path.basename(pth))
ispkg = base == '__init__'
try:
txt = open(pth[:-1], 'rU').read() + '\n'
except (IOError, OSError):
try:
f = open(pth, 'rb')
f.seek(8) # skip magic and timestamp
bytecode = f.read()
marshal.loads(bytecode).co_filename # to make sure it's valid
obj = zlib.compress(bytecode, self.LEVEL)
except (IOError, ValueError, EOFError, AttributeError):
raise ValueError("bad bytecode in %s and no source" % pth)
else:
txt = txt.replace('\r\n', '\n')
try:
import os
co = compile(txt, self.os.path.join(self.path, nm), 'exec')
except SyntaxError, e:
print "Syntax error in", pth[:-1]
print e.args
raise
obj = zlib.compress(marshal.dumps(co), self.LEVEL)
开发者ID:3xp10it,项目名称:evlal_win,代码行数:29,代码来源:archive.py
示例11: recv_interest_voucher
def recv_interest_voucher(self, data):
msg, key = marshal.loads(data)
(nonce, leader_ip, leader_gui_port, leader_com_port) = marshal.loads(msg)
self.DEBUG(
"Start round voucher from %s:%s, communicating at port %s" % (leader_ip, leader_gui_port, leader_com_port)
)
# get the path to the file you want to share
self.emit(SIGNAL("getSharedFilename()"))
verified = self.verify(leader_ip, leader_gui_port, data)
""" generate temporary keys for this round so leader can aggregate """
self.gen_temp_keys()
temp1_str = AnonCrypto.pub_key_to_str(self.pubgenkey1)
temp2_str = AnonCrypto.pub_key_to_str(self.pubgenkey2)
""" default to random file of 128 bytes if you don't have anything to share """
if verified:
if os.path.exists(self.shared_filename):
self.DEBUG("You are sharing file %s" % (self.shared_filename))
else:
self.DEBUG("Not a valid file path, continuing without sharing...")
# respond with your interest
self.DEBUG("Verified leader, participating as %s:%s at port %s" % (self.ip, self.gui_port, self.com_port))
response = marshal.dumps((nonce, self.ip, self.gui_port, self.com_port, temp1_str, temp2_str))
cipher = AnonCrypto.sign_with_key(self.privKey, response)
AnonNet.send_to_addr(leader_ip, int(leader_gui_port), marshal.dumps(("interested", cipher)))
else:
self.DEBUG("Unkown leader, opting out...")
开发者ID:nya2,项目名称:Dissent-TCP-communication,代码行数:31,代码来源:net.py
示例12: load_web_plugins
def load_web_plugins(forwhat, globalvars):
plugins_path = defaults.web_dir + "/plugins/" + forwhat
if os.path.exists(plugins_path):
fns = os.listdir(plugins_path)
fns.sort()
for fn in fns:
file_path = plugins_path + "/" + fn
if fn.endswith(".py"):
if not os.path.exists(file_path + "c"):
execfile(file_path, globalvars)
elif fn.endswith(".pyc"):
code_bytes = file(file_path).read()[8:]
code = marshal.loads(code_bytes)
exec code in globalvars
if defaults.omd_root:
local_plugins_path = defaults.omd_root + "/local/share/check_mk/web/plugins/" + forwhat
if local_plugins_path != plugins_path: # honor ./setup.sh in site
if os.path.exists(local_plugins_path):
fns = os.listdir(local_plugins_path)
fns.sort()
for fn in fns:
file_path = local_plugins_path + "/" + fn
if fn.endswith(".py"):
execfile(file_path, globalvars)
elif fn.endswith(".pyc"):
code_bytes = file(file_path).read()[8:]
code = marshal.loads(code_bytes)
exec code in globalvars
开发者ID:hamcos,项目名称:check_mk,代码行数:29,代码来源:lib.py
示例13: recv_expel_voucher
def recv_expel_voucher(self, data):
msg, key = marshal.loads(data)
(vouch_ip, vouch_port, expel_ip, expel_port, expel_pubkey) = marshal.loads(msg)
self.DEBUG("Recieved a expel voucher from %s:%s against %s:%s" % (vouch_ip, vouch_port, expel_ip, expel_port))
# verify the expel voucher
verified = self.verify(vouch_ip, vouch_port, data)
# if verified, remove and save voucher
if verified:
try:
index = self.nodes.index((expel_ip, int(expel_port), expel_pubkey))
self.nodes.pop(index)
self.DEBUG("Expelled!")
self.update_peerlist()
except:
if self.ip == expel_ip and int(self.gui_port) == int(expel_port):
self.nodes = []
self.update_peerlist()
self.DEBUG("I'm being booted :(")
else:
self.DEBUG("Booting someone I don't know")
self.save_voucher(vouch_ip, vouch_port, data, "expelvoucher")
else:
self.DEBUG("Not a valid voucher -- not expelling")
开发者ID:nya2,项目名称:Dissent-TCP-communication,代码行数:25,代码来源:net.py
示例14: upVote
def upVote(self,vid, ip):
if self.active:
conn=sqlite3.connect(self.db)
c=conn.cursor()
num=c.execute("SELECT upvotes,total,upvoteip, downvotes, downvoteip FROM songs WHERE videoid=? AND party=?",(vid,self.k,)).fetchone()
x=m.loads(num[2])
y=m.loads(num[4])
if ip not in x:
if ip in y:
x.append(ip)
y.remove(ip)
x=m.dumps(x)
y=m.dumps(y)
c.execute("UPDATE songs SET upvotes=?, total=?, upvoteip=?, downvotes=?, downvoteip=? WHERE videoid=? AND party=",(num[0]+1,num[1]+2,x, num[3]-1,y,vid,self.k,))
else:
x.append(ip)
x=m.dumps(x)
c.execute("UPDATE songs SET upvotes=?, total=?, upvoteip=? WHERE videoid=? AND party=?",(num[0]+1,num[1]+1,x,vid,self.k,))
elif ip in x:
x.remove(ip)
x=m.dumps(x)
c.execute("UPDATE songs SET upvotes=?, total=?, upvoteip=? WHERE videoid=? AND party=?",(num[0]-1,num[1]-1,x,vid,self.k,))
conn.commit()
conn.close()
else:
return "Party not active."
开发者ID:y4smeen,项目名称:vynl-v0,代码行数:27,代码来源:party.py
示例15: test_floats
def test_floats(self):
# Test a few floats
small = 1e-25
n = sys.maxint * 3.7e250
while n > small:
for expected in (-n, n):
f = float(expected)
s = marshal.dumps(f)
got = marshal.loads(s)
self.assertEqual(f, got)
marshal.dump(f, file(test_support.TESTFN, "wb"))
got = marshal.load(file(test_support.TESTFN, "rb"))
self.assertEqual(f, got)
n /= 123.4567
f = 0.0
s = marshal.dumps(f)
got = marshal.loads(s)
self.assertEqual(f, got)
n = sys.maxint * 3.7e-250
while n < small:
for expected in (-n, n):
f = float(expected)
s = marshal.dumps(f)
got = marshal.loads(s)
self.assertEqual(f, got)
marshal.dump(f, file(test_support.TESTFN, "wb"))
got = marshal.load(file(test_support.TESTFN, "rb"))
self.assertEqual(f, got)
n *= 123.4567
os.unlink(test_support.TESTFN)
开发者ID:bushuhui,项目名称:pyKanjiDict,代码行数:32,代码来源:test_marshal.py
示例16: get_group_buy_info
def get_group_buy_info(self):
_infos = yield redis.hgetall(DICT_GROUP_BUY_INFO)
if not _infos:
_group_buy_info = {1:0,2:0,3:0,4:0} #buy_type:buy_num
for buy_type in xrange(1,5):
yield redis.hset(DICT_GROUP_BUY_INFO, buy_type, dumps(_group_buy_info[buy_type]))
else:
_group_buy_info = dict()
for k, v in _infos.iteritems():
_group_buy_info[k] = loads(v)
_res = []
_ret = []
for _buy_type, _bought_num in _group_buy_info.iteritems():
_res.append([_buy_type, _bought_num])
_stream = yield redis.hget(DICT_GROUP_BUY_PERSON_INFO, self.cid)#[[buy_count, [status,2,3,4]],..]
if _stream:
try:
_data = loads(_stream)
if _data:
# [bought_count, [0,0,0,0]]
for _bought_count_info, _info in zip(_data, _res):
_info.append(_bought_count_info)
_ret.append(_info)
except:
log.exception()
else:
_value = [[0,[0,0,0,0]]] * 4
yield redis.hset(DICT_GROUP_BUY_PERSON_INFO, self.cid, dumps(_value))
for _info in _res:
_info.append([0,[0,0,0,0]])
_ret.append(_info)
defer.returnValue( _ret )
开发者ID:anson-tang,项目名称:3dkserver,代码行数:34,代码来源:gsexcite_activity.py
示例17: test_floats
def test_floats(self):
# Test a few floats
small = 1e-25
n = sys.maxsize * 3.7e250
while n > small:
for expected in (-n, n):
self.helper(float(expected))
n /= 123.4567
f = 0.0
s = marshal.dumps(f, 2)
got = marshal.loads(s)
self.assertEqual(f, got)
# and with version <= 1 (floats marshalled differently then)
s = marshal.dumps(f, 1)
got = marshal.loads(s)
self.assertEqual(f, got)
n = sys.maxsize * 3.7e-250
while n < small:
for expected in (-n, n):
f = float(expected)
self.helper(f)
self.helper(f, 1)
n *= 123.4567
开发者ID:7modelsan,项目名称:kbengine,代码行数:25,代码来源:test_marshal.py
示例18: run
def run(self):
buf = ""
while True:
data = os.read(self._read_fd, 4096)
if not data:
print "IPC problem; unexpected EOF (r/s)"
raise SystemExit()
buf += data
if len(buf) < 8:
continue
i, l = HDR.unpack_from(buf)
if len(buf) < 8 + l:
continue
data = buf[8 : 8 + l]
buf = buf[8 + l:]
if i & 0x80000000:
response = marshal.loads(data)
self._outstanding.pop(i & 0x7FFFFFFF)(response)
else:
cmd, args, kw = marshal.loads(data)
result = self.commandMap[cmd](*args, **kw)
if i:
rdata = marshal.dumps(result)
hdr = HDR.pack(i | 0x80000000, len(rdata))
self._send_all(hdr + rdata)
开发者ID:apexo,项目名称:imes,代码行数:25,代码来源:ipc.py
示例19: test_FTPList
def test_FTPList(self):
from OFS.Folder import Folder
om = makerequest(self._makeOne())
om.isTopLevelPrincipiaApplicationObject = True
om._setObject('sub', Folder('sub'))
om.sub._setObject('subsub', Folder('subsub'))
req = om.REQUEST
req.PARENTS = [om]
# At the root we only see a single entry for the subfolder
data = marshal.loads(om.manage_FTPlist(req))
self.assertEqual(len(data), 1)
self.assertEqual(data[0][0], 'sub')
# In the subfolder, we see an entry for the current folder
# and the folder in it
data = marshal.loads(om.sub.manage_FTPlist(req))
self.assertEqual(len(data), 2)
self.assertEqual(data[0][0], '.')
self.assertEqual(data[1][0], 'subsub')
# In the leaf node we see entries for the parent and grandparent
data = marshal.loads(om.sub.subsub.manage_FTPlist(req))
self.assertEqual(len(data), 2)
self.assertEqual(data[0][0], '.')
self.assertEqual(data[1][0], '..')
开发者ID:zopefoundation,项目名称:Zope,代码行数:26,代码来源:testObjectManager.py
示例20: get_campcard_data
def get_campcard_data(self):
''' 获取玩家的阵营抽卡信息 '''
reset_flag = False
curr_time = int(time())
comm_data = yield redis.hget(HASH_CAMPRAND_COMMON, 'CAMPRAND')
if comm_data:
comm_data = loads(comm_data)
if curr_time >= comm_data[0]:
reset_flag = True
comm_data[0] += CAMP_RAND_TIME
comm_data[1] = 0 if len(CAMP_GROUP_IDS) <= comm_data[1]+1 else comm_data[1] + 1
yield redis.hset(HASH_CAMPRAND_COMMON, 'CAMPRAND', dumps(comm_data))
else:
camp_data = yield redis.hget(HASH_CAMPRAND_COMMON, self.cid)
if camp_data:
camp_data = loads(camp_data)
if 1 == timestamp_is_today(camp_data[0]):
curr_camp_data, next_camp_data = camp_data[1], camp_data[2]
else:
reset_flag = True
else:
reset_flag = True
else:
reset_flag = True
comm_data = [get_reset_timestamp() + CAMP_RAND_TIME, 0]
yield redis.hset(HASH_CAMPRAND_COMMON, 'CAMPRAND', dumps(comm_data))
if reset_flag:
curr_camp_data = [[camp_id, 0] for camp_id in CAMP_GROUP_IDS[comm_data[1]]]
next_group_id = 0 if len(CAMP_GROUP_IDS) <= comm_data[1]+1 else comm_data[1] + 1
next_camp_data = [[camp_id, 0] for camp_id in CAMP_GROUP_IDS[next_group_id]]
yield redis.hset(HASH_CAMPRAND_COMMON, self.cid, dumps([curr_time, curr_camp_data, next_camp_data]))
defer.returnValue( (comm_data[0], curr_camp_data, next_camp_data) )
开发者ID:anson-tang,项目名称:3dkserver,代码行数:34,代码来源:gsshop.py
注:本文中的marshal.loads函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论