• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python util.decode函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: deserialize

  def deserialize(self, l):
    seed, pub, sig=l
    self.seed=decode(seed)
    self.pub=fixPub(rsa.key.PublicKey.load_pkcs1(decode(pub), 'DER'))
    self.sig=decode(sig)

    h=hashlib.sha1()
    h.update(self.pub.save_pkcs1('DER'))
    self.owner=base64.b32encode(h.digest())

    h=hashlib.sha1()
    h.update(self.serialize())
    self.id=base64.b32encode(h.digest())
开发者ID:antiface,项目名称:CreditCoin,代码行数:13,代码来源:coins.py


示例2: math_clean

def math_clean(form):
    """
    Cleans a form, validating answer to math question in the process.
    The given ``form`` must be an instance of either ``MathCaptchaModelForm``
    or ``MathCaptchaForm``.
    Answer keys are communicated in the ``math_captcha_question`` field which
    is evaluated to give the correct answer
    after being validated against the ``SECRET_KEY``
    """
    try:
        value = form.cleaned_data['math_captcha_field']
        test_secret, question = decode(
            form.cleaned_data['math_captcha_question'])
        assert len(test_secret) == 40 and question
    except (TypeError, AssertionError):
        # problem decoding, junky data
        form._errors['math_captcha_field'] = form.error_class(["Invalid token"])
        del form.cleaned_data['math_captcha_field']
    except KeyError:
        return

    if encode(question) != form.cleaned_data['math_captcha_question']:
        # security problem, hack attempt
        form._errors['math_captcha_field'] = form.error_class(["Invalid token"])
        del form.cleaned_data['math_captcha_field']
    if eval(question) != value:
        form._errors['math_captcha_field'] = form.error_class(["Wrong answer, try again"])
        del form.cleaned_data['math_captcha_field']
开发者ID:kajic,项目名称:django-math-captcha,代码行数:28,代码来源:forms.py


示例3: load

 def load(self, keepUndo=False):
     """Loads the current url.
     
     Returns True if loading succeeded, False if an error occurred,
     and None when the current url is empty or non-local.
     Currently only local files are supported.
     
     If keepUndo is True, the loading can be undone (with Ctrl-Z).
     
     """
     fileName = self.url().toLocalFile()
     if fileName:
         try:
             with open(fileName) as f:
                 data = f.read()
         except (IOError, OSError):
             return False # errors are caught in MainWindow.openUrl()
         text = util.decode(data)
         if keepUndo:
             c = QTextCursor(self)
             c.select(QTextCursor.Document)
             c.insertText(text)
         else:
             self.setPlainText(text)
         self.setModified(False)
         self.loaded()
         app.documentLoaded(self)
         return True
开发者ID:WedgeLeft,项目名称:frescobaldi,代码行数:28,代码来源:document.py


示例4: readPlayers

def readPlayers(url):
	"""
	Reads a player list from the given URL.
	@type url: strings
	@param url: The URL that holds the player list information.
	@rtype: list of strings
	@return: List of players in a special format that can be parsed into a player object.
	"""
	# Load the player list from URL into a string
	txt = util.getUrlAsString(url)
	if not txt is None:
		players = []
		for line in util.lineIter(txt): # Decode the player list from known format of tennischannel.com files
			line = util.decode(line)
			strings = line.split("\t")
			rank = int(strings[0])
			strings = strings[1].split(",")
			lastName = strings[0]
			strings = strings[1].split("(")
			firstName = strings[0].strip()
			country = strings[1][0:3]
			# Creating list of easily parsed strings representative of player objects.
			# These strings are "pretty" enough to use in dropdown list.
			players.append('{}. {}, {} ({})'.format(rank, lastName, firstName, country))
	else:
		print("readPlayers: Couldn't open {}, exiting.".format(url))
		# Maybe something better to do than exit. Consider in future version.
		sys.exit(1)
	return players
开发者ID:talasky,项目名称:tennis-score,代码行数:29,代码来源:setup3.py


示例5: handle_change

	def handle_change(self, thread_name, check_id, check_name, lock_uid, status, check_result):
		if status == 'offline':
			updown = 'down'
		elif status == 'online':
			updown = 'up'

		safe_print("[%s] ... confirmed, target is %s state now", (thread_name, status))
		update_result = Check.objects.raw("UPDATE checks SET status = %s, confirmations = 0, `lock` = '', last_checked = NOW() WHERE id = %s AND `lock` = %s", (status, check_id, lock_uid))

		if update_result.rowcount == 1:
			# we still had the lock at the point where status was toggled
			# then, send the alert
			alert_result = database.query("SELECT contacts.id, contacts.type, contacts.data FROM contacts, alerts WHERE contacts.id = alerts.contact_id AND alerts.check_id = %s AND alerts.type IN ('both', %s)", (check_id, updown))

			for alert_row in alert_result.fetchall():
				safe_print("[%s] ... alerting contact %d", (thread_name, alert_row['id']))
				alert_func = getattr(alerts, alert_row['type'], None)

				if not alert_func:
					util.die("Invalid alert handler [%s]!" % (alert_row['type']))

				# build context
				context = {}
				context['check_id'] = check_id
				context['check_name'] = check_name
				context['contact_id'] = alert_row['id']
				context['title'] = "Check %s: %s" % (status, check_name)
				context['status'] = status
				context['updown'] = updown
				context['message'] = check_result['message']

				alert_func(util.decode(alert_row['data']), context)

			# also add an event
			database.query("INSERT INTO check_events (check_id, type) VALUES (%s, %s)", (check_id, updown))
开发者ID:ZUNbado,项目名称:pymonitor,代码行数:35,代码来源:monitor.py


示例6: slotButtonShowDiff

 def slotButtonShowDiff(self):
     """Called when the user clicks Show Difference."""
     docs = self.selectedDocuments() or self.allDocuments()
     if not docs:
         return
     d = docs[0]
     if documentwatcher.DocumentWatcher.instance(d).isdeleted():
         return
     
     filename = d.url().toLocalFile()
     try:
         with open(filename) as f:
             disktext = util.decode(f.read())
     except (IOError, OSError):
         return
     
     currenttext = d.toPlainText()
     
     html = htmldiff.htmldiff(
         currenttext, disktext, 
         _("Current Document"), _("Document on Disk"), numlines=5)
     dlg = widgets.dialog.Dialog(self, buttons=('close',))
     view = QTextBrowser(lineWrapMode=QTextBrowser.NoWrap)
     view.setHtml(html)
     dlg.setMainWidget(view)
     dlg.setWindowTitle(app.caption("Differences"))
     dlg.setMessage(_(
         "Document: {url}\n"
         "Difference between the current document and the file on disk:").format(
             url=filename))
     dlg.setWindowModality(Qt.NonModal)
     dlg.setAttribute(Qt.WA_QuitOnClose, False)
     dlg.setAttribute(Qt.WA_DeleteOnClose)
     qutil.saveDialogSize(dlg, "externalchanges/diff/dialog/size", QSize(600, 300))
     dlg.show()
开发者ID:arnaldorusso,项目名称:frescobaldi,代码行数:35,代码来源:widget.py


示例7: version

def version(filename):
    """Returns the LilyPond version if set in the file, as a tuple of ints.
    
    First the function searches inside LilyPond syntax.
    Then it looks at the 'version' document variable.
    Then, if the document is not a LilyPond document, it simply searches for a
    \\version command string, possibly embedded in a comment.
    
    The version is cached until the file changes.
    
    """
    mkver = lambda strings: tuple(map(int, strings))
    with open(filename) as f:
        text = util.decode(f.read())
    mode = textmode(text)
    tokens_ = list(ly.lex.state(mode).tokens(text))

    version = ly.parse.version(tokens_)
    if version:
        return mkver(re.findall(r"\d+", version))
    # look at document variables
    version = variables.variables(text).get("version")
    if version:
        return mkver(re.findall(r"\d+", version))
    # parse whole document for non-lilypond comments
    if mode != "lilypond":
        m = re.search(r'\\version\s*"(\d+\.\d+(\.\d+)*)"', text)
        if m:
            return mkver(m.group(1).split('.'))
开发者ID:mbsrz1972,项目名称:frescobaldi,代码行数:29,代码来源:fileinfo.py


示例8: _serve_players

    def _serve_players(self):
        for socket, player_id in self.connected_sockets:
            try:
                data = socket.recv(MAX_DATA_LEN)
            except error:
                continue

            events = get_event_list(decode(data))
            # print("received ", events)

            if decode(data) != '':
                if events[0] == "start":
                    self._handle_start_event(socket, player_id)
                elif events[0] == "action":
                    self._handle_player_action_events(
                        socket,
                        player_id, events)
开发者ID:minh0722,项目名称:Bomberman,代码行数:17,代码来源:server.py


示例9: post

    def post(self):
        if "ROLE_USER" not in self.current_user['roles']:
            raise tornado.web.HTTPError(401)

        action = self.get_argument('action')
        user_id = self.current_user['_id']
        time = datetime.datetime.now()
        working_model = models.Workings(self.db)
        report_model = models.Reports(self.db)

        if action == 'working':
            if self.get_argument('do') == 'stop':
                wid = util.decode(str(self.get_argument('wid')), 'url')
                res = yield working_model.end(wid, time)
                # TODO: show a message?
                self.redirect(self.reverse_url('user'))
                return
            else:
                query = {'user_id': user_id, 'end': {'$exists': True}, 'end': None}
                started = yield working_model.get(query)
                if started:
                    wid = util.decode(str(self.get_argument('wid')), 'url')
                    res = yield working_model.end(wid, time)
                    # TODO: show a message?
                    self.redirect(self.reverse_url('user'))
                    return
                else:
                    res = working_model.start(time, user_id)
                    # TODO: show a message?
                    self.redirect(self.reverse_url('user'))
                    return
        elif action == 'report':
            report = self.get_argument('report')
            if len(report) < 10:
                self.notifications.set('user_messages', ['Length Of Report Is Very Low'])
                self.redirect(self.reverse_url('user'))
                return

            res = yield report_model.create(report, user_id, time)
            if res:
                self.notifications.set('user_messages', ['Report Is Saved!'])
            else:
                self.notifications.set('user_messages', ['Report Is not Saved!'])
            self.redirect(self.reverse_url('user'))
            return
开发者ID:ehsansh84,项目名称:ontime,代码行数:45,代码来源:handlers.py


示例10: get_persist

def get_persist( pfx, key ) :
    try:
        mc = memcache.Client( etc.memcached_addr, debug=0 )
        raw_data = mc.get( pfx+'_persist_'+str(key) )
        persist = None
        if raw_data :
            persist = util.decode( raw_data )
        return persist
    except Exception as e :
        log.exp( e )
        return None
开发者ID:huluo,项目名称:m-huluo-src,代码行数:11,代码来源:mc.py


示例11: get_node

def get_node( pfx, key ) :
    try:
        mc = memcache.Client( etc.memcached_addr, debug=0 )
        raw_data = mc.get( pfx+'_node_'+str(key) )
        node = None
        if raw_data :
            node = util.decode( raw_data )
        return node
    except Exception as e :
        log.exp( e )
        return None
开发者ID:huluo,项目名称:m-huluo-src,代码行数:11,代码来源:mc.py


示例12: get_item

def get_item( pfx, key ) :
    try:
        mc = memcache.Client( etc.memcached_addr, debug=0 )
        raw_data = mc.get( pfx+'_item_'+str(key) )
        item = None
        if raw_data :
            item = util.decode( raw_data )
        return item
    except Exception as e :
        log.exp( e )
        return None
开发者ID:huluo,项目名称:m-huluo-src,代码行数:11,代码来源:mc.py


示例13: get_ss

def get_ss( ss_id ) :
    try:
        mc = memcache.Client( etc.memcached_addr, debug=0 )
        raw_data = mc.get( 'ss_'+ss_id )
        ss_data = None
        if raw_data :
            ss_data = util.decode( raw_data )
        return ss_data
    except Exception as e:
        log.exp(e)
        return None
开发者ID:huluo,项目名称:m-huluo-src,代码行数:11,代码来源:session_mc.py


示例14: get_item

def get_item( pfx, key ) :
    try:
        r = redis.Redis( connection_pool=pool )
        raw_data = r.get( pfx+'_item_'+str(key) )
        item = None
        if raw_data :
            item = util.decode( raw_data )
        return item
    except Exception as e :
        log.exp( e )
        return None
开发者ID:huluo,项目名称:m-huluo-src,代码行数:11,代码来源:rds.py


示例15: _cached

def _cached(filename):
    """Return a _CachedDocument instance for the filename, else creates one."""
    filename = os.path.realpath(filename)
    try:
        c = _document_cache[filename]
    except KeyError:
        with open(filename, 'rb') as f:
            text = util.decode(f.read())
        c = _document_cache[filename] = _CachedDocument()
        c.variables = v = variables.variables(text)
        c.document = ly.document.Document(text, v.get("mode"))
        c.filename = c.document.filename = filename
    return c
开发者ID:EdwardBetts,项目名称:frescobaldi,代码行数:13,代码来源:fileinfo.py


示例16: parse

 def parse(self,reader:BGLReader,reset:bool=True):
     if reset:
         reader.reset()
     self.reader=reader
     
     self._read_properties(reader)
     #props at end sometimes
     reader.reset()
     
     charset_s=self.properties[gls.P_S_CHARSET]
     charset_t=self.properties[gls.P_T_CHARSET]
     
     while not reader.eof():
         rec=reader.next_rec()
         
         if rec[0] == gls.TERM_A or rec[0] == gls.TERM_1:
             (title_r,definition_r,alternatives_r,properties_r)=unpack_term(rec[1])
             title=util.decode(bytes(title_r),charset_s)
             
             definition=util.decode(bytes(definition_r), charset_s)
             
             alternatives=[]
             for alt in alternatives_r:
                 alternatives.append( util.decode(bytes(alt), charset_s) )
             
             properties=self._parse_term_properties(properties_r)
             
             self.handle_term(title, definition, alternatives, properties)
             
         elif rec[0] == gls.RESOURCE:
             (name_r,data)=unpack_res(rec[1])
             self.handle_res( bytes(name_r).decode('latin1'), bytes(data) )
             
         elif rec[0] ==  gls.TERM_B:
             raise Exception("TERM_B not implemented")
     
     self.reader.close()
     self.handle_parse_complete()
     return
开发者ID:amremam2004,项目名称:bgl-reverse,代码行数:39,代码来源:bgl.py


示例17: deserialize

  def deserialize(self, l):
    self.sig=decode(l[0])
    self.pub=l[1]
    self.pub=loadPublic(self.pub)
    self.time=l[2]
    self.cmd=l[3]
    self.coin=Coin()
    self.coin.deserialize(l[4])

    if len(l)==6:
      if self.cmd=='create':
        self.args=l[5]
      else:
        self.args=loadPublic(l[5])
开发者ID:antiface,项目名称:CreditCoin,代码行数:14,代码来源:receipts.py


示例18: get_item_dict

def get_item_dict( pfx, key_arr ) :
    item_dict = {}
    if len(key_arr) <= 0 :
        return item_dict
    try:
        mc = memcache.Client( etc.memcached_addr, debug=0 )
        str_key_arr = [ pfx+'_item_'+str(i) for i in key_arr ]
        raw_datas = mc.get_multi( str_key_arr )
        for (k,v) in raw_datas.items() :
            item = util.decode( v )
            item_dict[long(k.replace(pfx+'_item_',''))] = item
        return item_dict
    except Exception as e :
        log.exp( e )
        return {}
开发者ID:huluo,项目名称:m-huluo-src,代码行数:15,代码来源:mc.py


示例19: get_item_dict

def get_item_dict( pfx, key_arr ) :
    item_dict = {}
    if len(key_arr) <= 0 :
        return item_dict
    r = redis.Redis( connection_pool=pool )
    for key in key_arr :
        try:
            raw_data = r.get( pfx+'_item_'+str(key) )
            item = None
            if raw_data :
                item = util.decode( raw_data )
                item_dict[key] = item
        except Exception as e :
            log.exp( e )
    return item_dict
开发者ID:huluo,项目名称:m-huluo-src,代码行数:15,代码来源:rds.py


示例20: worker

	def worker(self):
		thread_name = threading.currentThread().getName()

		while True:
			check_id, check_name, check_type, check_data, status, max_confirmations, confirmations, lock_uid = self.q.get()

			safe_print("[%s] processing check %d: calling checks.%s", (thread_name, check_id, check_type))
			check_result = checks.run_check(check_type, util.decode(check_data), check_id)

			safe_print("[%s] check %d result: %s", (thread_name, check_id, str(check_result)))

			if not type(check_result) is dict or 'status' not in check_result:
				util.die("[%s] bad check handler [%s]: returned non-dict or missing status" % (thread_name, check_type))
			elif 'message' not in check_result:
				if check_result['status'] == 'fail':
					check_result['message'] = "Check offline: %s" % (check_name)
				else:
					check_result['message'] = "Check online: %s" % (check_name)

			if check_result['status'] == 'fail':
				safe_print("[%s] ... got failure!", (thread_name))

				if status == 'online':
					with recent_failures_lock:
						recent_failures.add((check_id, util.time()))

					if confirmations + 1 >= max_confirmations:
						# target has failed
						self.handle_change(thread_name, check_id, check_name, lock_uid, 'offline', check_result)
					else:
						# increase confirmations
						database.query("UPDATE checks SET confirmations = confirmations + 1, `lock` = '', last_checked = NOW() WHERE id = %s AND `lock` = %s", (check_id, lock_uid))
				else:
					database.query("UPDATE checks SET confirmations = 0, `lock` = '', last_checked = NOW() WHERE id = %s AND `lock` = %s", (check_id, lock_uid))
			elif check_result['status'] == 'success':
				safe_print("[%s] ... got success", (thread_name))

				if status == 'offline':
					if confirmations + 1 >= max_confirmations:
						# target has come back online
						self.handle_change(thread_name, check_id, check_name, lock_uid, 'online', check_result)
					else:
						# increase confirmations
						database.query("UPDATE checks SET confirmations = confirmations + 1, `lock` = '', last_checked = NOW() WHERE id = %s AND `lock` = %s", (check_id, lock_uid))
				else:
					database.query("UPDATE checks SET confirmations = 0, `lock` = '', last_checked = NOW() WHERE id = %s AND `lock` = %s", (check_id, lock_uid))
			else:
				util.die("Check handler [%s] returned invalid status code [%s]!") % (check_type, check_result['status'])
开发者ID:ZUNbado,项目名称:pybearmon,代码行数:48,代码来源:monitor.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python util.decode_html函数代码示例发布时间:2022-05-27
下一篇:
Python util.decToDeg函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap