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


Python util.decode函数代码示例

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


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


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