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


Python marshal.dumps函数代码示例

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


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

示例1: run_phase4

	def run_phase4(self):
		self.advance_phase()
		if self.am_leader():
			self.debug("Leader broadcasting ciphers to all nodes")
			self.broadcast_to_all_nodes(marshal.dumps(self.final_ciphers))
			self.debug("Cipher set len %d" % (len(self.final_ciphers)))
		else:
			""" Get C' ciphertexts from leader. """
			self.final_ciphers = marshal.loads(self.recv_from_leader())

		"""
		self.final_ciphers holds an array of
		pickled (round_id, cipher_prime) tuples
		"""

		my_cipher_str = marshal.dumps((self.round_id, self.cipher_prime))

		go = False
		if my_cipher_str in self.final_ciphers:
			self.info("Found my ciphertext in set")
			go = True
			self.debug("Go = TRUE")
		else:
			self.critical("ABORT! My ciphertext is not in set!")
			self.debug(self.final_ciphers)
			go = False
			self.debug("Go = FALSE")
			raise RuntimeError, "Protocol violation: My ciphertext is missing!"

		#Pedro: Directly copy the final ciphers (plaintext in coinshuffle)
		self.anon_data = self.final_ciphers
开发者ID:ecrypto,项目名称:shuffle,代码行数:31,代码来源:shuffle_node.py

示例2: prepare_value

def prepare_value(val, compress):
    flag = 0
    if isinstance(val, six.binary_type):
        pass
    elif isinstance(val, bool):
        flag = FLAG_BOOL
        val = str(int(val)).encode('utf-8')
    elif isinstance(val, six.integer_types):
        flag = FLAG_INTEGER
        val = str(val).encode('utf-8')
    elif isinstance(val, six.text_type):
        flag = FLAG_MARSHAL
        val = marshal.dumps(val, 2)
    else:
        try:
            val = marshal.dumps(val, 2)
            flag = FLAG_MARSHAL
        except ValueError:
            val = cPickle.dumps(val, -1)
            flag = FLAG_PICKLE

    if compress and len(val) > 1024:
        flag |= FLAG_COMPRESS
        val = quicklz.compress(val)

    return flag, val
开发者ID:douban,项目名称:dpark,代码行数:26,代码来源:beansdb.py

示例3: get_config

    def get_config(self):
        py3 = sys.version_info[0] == 3

        if isinstance(self.function, python_types.LambdaType):
            if py3:
                function = marshal.dumps(self.function.__code__).decode('raw_unicode_escape')
            else:
                function = marshal.dumps(self.function.func_code).decode('raw_unicode_escape')
            function_type = 'lambda'
        else:
            function = self.function.__name__
            function_type = 'function'

        if isinstance(self._output_shape, python_types.LambdaType):
            if py3:
                output_shape = marshal.dumps(self._output_shape.__code__)
            else:
                output_shape = marshal.dumps(self._output_shape.func_code)
            output_shape_type = 'lambda'
        elif callable(self._output_shape):
            output_shape = self._output_shape.__name__
            output_shape_type = 'function'
        else:
            output_shape = self._output_shape
            output_shape_type = 'raw'

        config = {'function': function,
                  'function_type': function_type,
                  'output_shape': output_shape,
                  'output_shape_type': output_shape_type,
                  'arguments': self.arguments}
        base_config = super(Lambda, self).get_config()
        return dict(list(base_config.items()) + list(config.items()))
开发者ID:basveeling,项目名称:keras,代码行数:33,代码来源:core.py

示例4: Paser_SigMDB

def Paser_SigMDB(file, num) :
    fp = open(SIGDB_FILENAME)

    while 1: 
        lines = fp.readlines(100000) #메모리가 허용하는 적당한 양 
        if not lines: 
            break 
        for line in lines: 
            convert(line, num)

    fp.close()

    fname = '%s.c%02d' % (file, num)
    output = open(fname, 'wb')
    #s = pickle.dumps(db_size_pattern, -1)
    s = marshal.dumps(db_size_pattern)
    output.write(s)
    output.close()

    fname = '%s.i%02d' % (file, num)
    output = open(fname, 'wb')
    # s = pickle.dumps(db_vname, -1)
    s = marshal.dumps(db_vname)
    output.write(s)
    output.close()
开发者ID:idkwim,项目名称:kicomav,代码行数:25,代码来源:sigtool.py

示例5: accept_phase

    def accept_phase(self, ip, port, nonce):
        # package and encrypt data
        response = marshal.dumps((nonce, self.ip, self.gui_port))
        cipher = AnonCrypto.sign_with_key(self.privKey, response)

        # respond with ((ip, port), encrypted_data)
        AnonNet.send_to_addr(ip, int(port), marshal.dumps(("accept", cipher)))
开发者ID:nya2,项目名称:Dissent-TCP-communication,代码行数:7,代码来源:net.py

示例6: split

  def split(self):
    """Split a RecordIORecordsZipped data into two even chunks.

    :return: lower_entries, higher_entries, middle_entry
    """
    new_zipped_chunks = list(self.get_zipped_chunks_())
    if len(new_zipped_chunks) <= 1:
      raise RecordIOTooSmallToSplitError()
    lo_chunks = []
    hi_chunks = []
    lo_size = 0
    hi_size = 0
    left = -1
    right = len(new_zipped_chunks)
    while left + 1 != right:
      if lo_size <= hi_size:
        left += 1
        lo_chunks.append(new_zipped_chunks[left])
        lo_size += len(new_zipped_chunks[left][2])
      else:
        right -= 1
        hi_chunks.insert(0, new_zipped_chunks[right])
        hi_size += len(new_zipped_chunks[right][2])
    middle_entry_lo = new_zipped_chunks[right][0]
    self.records_ = []
    self.zipped_chunks_ = lo_chunks + hi_chunks
    return (marshal.dumps(lo_chunks, MARSHAL_VERSION),
            marshal.dumps(hi_chunks, MARSHAL_VERSION),
            middle_entry_lo)
开发者ID:n-dream,项目名称:recordio,代码行数:29,代码来源:recordio_records_zipped.py

示例7: __init__

 def __init__(self, layers, function, output_shape=None):
     if len(layers) < 2:
         raise Exception("Please specify two or more input layers (or containers) to merge")
     self.layers = layers
     self.params = []
     self.regularizers = []
     self.constraints = []
     self.updates = []
     for l in self.layers:
         params, regs, consts, updates = l.get_params()
         self.regularizers += regs
         self.updates += updates
         # params and constraints have the same size
         for p, c in zip(params, consts):
             if p not in self.params:
                 self.params.append(p)
                 self.constraints.append(c)
     py3 = sys.version_info[0] == 3
     if py3:
         self.function = marshal.dumps(function.__code__)
     else:
         self.function = marshal.dumps(function.func_code)
     if output_shape is None:
         self._output_shape = None
     elif type(output_shape) in {tuple, list}:
         self._output_shape = tuple(output_shape)
     else:
         if py3:
             self._output_shape = marshal.dumps(output_shape.__code__)
         else:
             self._output_shape = marshal.dumps(output_shape.func_code)
开发者ID:nickfrosst,项目名称:keras,代码行数:31,代码来源:core.py

示例8: addSong

 def addSong(self,vid,imgURL,title,artist):
     if self.active:
         #print "adding"
         conn=sqlite3.connect(self.db)
         x=m.dumps([])
         y=m.dumps([])
         args=(vid,imgURL,title,artist,x,y,self.k,)
         c=conn.cursor()
             #raise e
         L=c.execute("SELECT * FROM songs WHERE videoid=? AND played=1 AND party=? ",(vid,self.k,)).fetchall()
         if len(L)==0:
             L=c.execute("SELECT * FROM songs WHERE videoid=? AND played=0 AND party=? ",(vid,self.k,)).fetchall()
             if len(L)==0:
                 c.execute("INSERT INTO songs (videoid,imgURL,name,artist,upvotes,downvotes,total,upvoteip,downvoteip,played,party) VALUES (?,?,?,?,0,0,0,?,?,0,?)",args)
                 conn.commit()
                 conn.close()
                 return
             else:
                 conn.close()
             #print "in queue!"
                 return "The song is already in the queue!"
         else:
             c.execute("REPLACE INTO songs (videoid,imgURL,name,artist,upvotes,downvotes,total,upvoteip,downvoteip,played,party) VALUES (?,?,?,?,0,0,0,?,?,0,?)",args)
         conn.commit()
         conn.close()
     else:
         return "Party not active."
开发者ID:y4smeen,项目名称:vynl-v0,代码行数:27,代码来源:party.py

示例9: 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

示例10: add

	def add(self, document, defer_recalculate = True):
		# Retreive (if known URI) or assign document ID
		known_ID = self.db.get('U_'+ document.uri)
		if known_ID:
			document.id = int(known_ID)
		else:
			self.max_id += 1
			self.db['M_max_id'] = str(self.max_id)
			document.id = self.max_id
			self.db["U_" + document.uri] = str(document.id)
		# Add an entry for each document's metadata
		tokens = document.tokens
		del(document.tokens) # we don't want to store these
		doc_details = document.__dict__
		modified = time.localtime(document.modified)
		doc_details['str_modified'] = time.strftime('%d %B %Y', modified)
		self.db["D_%s" % document.id] = marshal.dumps(doc_details)
		# Add/update the entry for each term in the document
		for term in tokens:
			if self.db.has_key('T_' + term):
				term_data = marshal.loads(self.db['T_' + term])
			else:
				term_data = {}
			term_data[document.id] = (tokens[term], document.length)
			# TODO: optimise by chunking db inserts
			self.db['T_' + term] = marshal.dumps(term_data)
开发者ID:tomdyson,项目名称:dolphy,代码行数:26,代码来源:index.py

示例11: setup_default_condor_setup

def setup_default_condor_setup():
	"""
	Checks that all users have a default condor setup in their profile (for every plugin).
	Already existing values will remain untouched, missing default setup will be added.
	"""
	logger.setGroup('condor', 'Checking that all users have a default condor setup in their profile')
	users = User.objects.all()
	for user in users:
		p = user.get_profile()
		if len(p.dflt_condor_setup) == 0:
			# No default Condor setup rules
			logger.log("Missing Condor setup in %s's profile" % user.username)
			setup = {}
			for plugin in manager.plugins:
				# Default is to use the ALL policy
				setup[plugin.id] = {'DB': 'policy', 'DS': '', 'DP': 'ALL'}
			p.dflt_condor_setup = base64.encodestring(marshal.dumps(setup)).replace('\n', '')
			p.save()
			logger.log("Added default Condor setup rules for %s" % user.username)
		else:
			# Ok, existing but maybe default rules for some (newly created?) plugins are missing
			setup = marshal.loads(base64.decodestring(p.dflt_condor_setup))
			updated = False
			for plugin in manager.plugins:
				if not setup.has_key(plugin.id):
					setup[plugin.id] = {'DB': 'policy', 'DS': '', 'DP': 'ALL'}
					updated = True
			p.dflt_condor_setup = base64.encodestring(marshal.dumps(setup)).replace('\n', '')
			p.save()
			if updated:
				logger.log("Updated default Condor setup rules for %s" % user.username)
			else:
				logger.log("Default Condor setup rules for %s look good" % user.username)
开发者ID:gotsunami,项目名称:Youpi,代码行数:33,代码来源:checksetup.py

示例12: prepare_value

def prepare_value(val, compress):
    flag = 0
    if isinstance(val, str):
        pass
    elif isinstance(val, (bool)):
        flag = FLAG_BOOL
        val = str(int(val))
    elif isinstance(val, (int, long)):
        flag = FLAG_INTEGER
        val = str(val)
    elif isinstance(val, unicode):
        flag = FLAG_MARSHAL
        val = marshal.dumps(val, 2)
    else:
        try:
            val = marshal.dumps(val, 2)
            flag = FLAG_MARSHAL
        except ValueError:
            val = cPickle.dumps(val, -1)
            flag = FLAG_PICKLE

    if compress and len(val) > 1024:
        flag |= FLAG_COMPRESS
        val = quicklz.compress(val)

    return flag, val
开发者ID:windreamer,项目名称:dpark,代码行数:26,代码来源:beansdb.py

示例13: save_all_2

    def save_all_2(self):
        if self.settings.no_save != "True":
            print("Writing dictionary...")

            try:
                zfile = zipfile.ZipFile(self.brain_path, 'r')
                for filename in zfile.namelist():
                    data = zfile.read(filename)
                    f = open(filename, 'w+b')
                    f.write(data)
                    f.close()
            except (OSError, IOError):
                print("no zip found. Is the programm launch for first time ?")

            with open("words.dat", "wb") as f:
                f.write(marshal.dumps(self.words))

            with open("lines.dat", "wb") as f:
                f.write(marshal.dumps(self.lines))

            # save the version
            with open('version', 'w') as f:
                f.write(self.saves_version)

            # zip the files
            with zipfile.ZipFile(self.brain_path, "w") as f:
                f.write('words.dat')
                f.write('lines.dat')
                f.write('version')

            try:
                os.remove('words.dat')
                os.remove('lines.dat')
                os.remove('version')
            except (OSError, IOError):
                print("could not remove the files")

            f = open("words.txt", "w")
            # write each words known
            wordlist = []
            # Sort the list befor to export
            for key in self.words.keys():
                wordlist.append([key, len(self.words[key])])
            wordlist.sort(key=lambda x: x[1])
            list(map((lambda x: f.write(str(x[0]) + "\n\r")), wordlist))
            f.close()

            f = open("sentences.txt", "w")
            # write each words known
            wordlist = []
            # Sort the list befor to export
            for key in self.unfilterd.keys():
                wordlist.append([key, self.unfilterd[key]])
            # wordlist.sort(lambda x, y: cmp(y[1], x[1]))
            wordlist.sort(key=lambda x: x[1])
            list(map((lambda x: f.write(str(x[0]) + "\n")), wordlist))
            f.close()

            # Save settings
            self.settings.save()
开发者ID:jrabbit,项目名称:pyborg-1up,代码行数:60,代码来源:pyborg.py

示例14: encode_function

def encode_function(function):
  if type(function) != types.BuiltinFunctionType:
    builtin = False
    return marshal.dumps(((function.func_code, capture_globals(function)), builtin))
  else:
    builtin = True
    return marshal.dumps((function.__name__, builtin))
开发者ID:helfer,项目名称:py-rdd,代码行数:7,代码来源:util.py

示例15: 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


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