當前位置: 首頁>>代碼示例>>Python>>正文


Python Result.none方法代碼示例

本文整理匯總了Python中result.Result.none方法的典型用法代碼示例。如果您正苦於以下問題:Python Result.none方法的具體用法?Python Result.none怎麽用?Python Result.none使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在result.Result的用法示例。


在下文中一共展示了Result.none方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: Interpreter

# 需要導入模塊: from result import Result [as 別名]
# 或者: from result.Result import none [as 別名]

#.........這裏部分代碼省略.........
                cmd['users'][self.sender.id] = cmd['users'][None]
            del cmd['users'][None]

        # prepare total amount
        amount = cmd['amount']

        # select currency to use and update amount if auto-converting
        cur = self.tr.dm.cur_mng.get_cur_for_user(self.sender, cid=cmd['currency'])
        self.log.cur = cur
        if cur is None:
            return self.res.not_found_error(currency=[cmd['currency']])

        # pre-process payment
        n_sharer = 0
        for uid in cmd['users']:
            u = cmd['users'][uid]
            u['payed'] = 0
            if u['modifier'] is None:
                n_sharer += 1
            elif u['modifier'] == '*':
                n_sharer += u['amount']
            elif u['modifier'] == '+':
                u['payed'] += u['amount']
                amount -= u['amount']
                n_sharer += 1
            elif u['modifier'] == '.':
                u['payed'] = u['amount']
                amount -= u['amount']

        # share and pay
        created_uids = []
        share = float(amount) / n_sharer
        for uid in cmd['users']:
            u = cmd['users'][uid]
            if u['modifier'] is None:
                u['payed'] += share
            elif u['modifier'] == '*':
                u['payed'] += u['amount'] * share
            elif u['modifier'] == '+':
                u['payed'] += share
            elif u['modifier'] == '.':
                pass

            user, created = self.tr.dm.user_mng.get_by_id(uid, auto_create=True)
            user.add_debit(cur, u['payed'])
            self.log.add_action('debit', user, u['payed'])

            if created:
                created_uids.append(uid)

        if len(created_uids):
            self.res.not_found_warning(new_users=created_uids)

        # give credit to payer
        payer_id = cmd['payer'] if cmd['payer'] is not None else self.sender.id
        payer = self.tr.dm.user_mng.get_by_id(payer_id)
        payer.add_credit(cur, cmd['amount'])
        self.log.add_action('credit', payer, cmd['amount'])

        return self.res.commit(cur_id=[cur.id])

    # endregion

    def interpret(self, message, cmd):
        """
        :param message: instance of Message
        :param cmd: the PARSED command to execute
        :return:
        """
        # make sure sender is known to Treasurer
        sender, created = self.tr.dm.user_mng.get_by_id(
            message.sender.lower(), auto_create=True)
        if sender.status is None:
            sender.status = 'confirmed'

        # fix special cases (BEFORE creating Log instance!)
        if 'currencies' in cmd and cmd['currencies'] == 'all':
            cmd['currencies'] = self.tr.dm.cur_mng.currencies.keys()
        if 'groups' in cmd and cmd['domain'] == 'groups' and cmd['groups'] == 'all':
            cmd['groups'] = self.tr.dm.group_mng.groups.keys()

        self.sender = sender
        self.res = Result(treasurer=self.tr, sender=sender.clone(), cmd=cmd)
        self.log = self.tr.lm.log_factory(message, cmd)
        try:
            f = getattr(self, '_cmd_' + cmd['domain'] + '_' + cmd['cmd'])
            f(cmd)
        except (AttributeError, TypeError):
            # includes those which need no processing. Incomplete list:
            #   easter_egg (who_is_your_daddy)
            #   error
            #   greetings, 'hi'
            #   stats / stats_plus
            #   help
            #   default
            self.res.none()
            # if IMP.DEBUG:
            #     raise

        return self.res, self.log
開發者ID:ric-101,項目名稱:Mike-the-treasurer,代碼行數:104,代碼來源:interpreter.py


注:本文中的result.Result.none方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。