Changeset 1697:a680bd74a37d

Show
Ignore:
Timestamp:
07/10/08 14:33:10 (3 months ago)
Author:
klai@…
Branch:
default
Message:

Sanity checking on output from bank (from Rik)

Location:
src/Tycoon
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • src/Tycoon/BankClient.py

    r1696 r1697  
    290290            raise BankClientException(e) 
    291291 
    292         ht = self.__bank_security.parse_receipt(receipt) 
     292        ht = self.__bank_security.parse_receipt(receipt, ('Tx_Amount', 'Transfer_From', 'Transfer_To', 'Tx_comment')) 
     293        for ht_key in ('Tx_Amount', 'Transfer_From', 'Transfer_To', 'Tx_Comment'): 
     294            if ht_key not in ht or ht[ht_key] is None: 
     295                raise BankClientException( 
     296                    'Malformed bank response, results does not contain the '+\ 
     297                    '%s key' % ht_key) 
    293298             
    294299        #convert the amount to decimal  
  • src/Tycoon/BankSecurity.py

    r1403 r1697  
    2020# 
    2121import datetime, decimal, os.path, re, time 
     22from types import TupleType 
    2223from KL.Security.Signer import Signer 
    2324from KL.Network.TimeStampBuffer import TimeStampBuffer 
     
    3940        self.__re = None 
    4041 
    41     def parse_receipt(self, receipt): 
     42    def parse_receipt(self, receipt, keys=None): 
    4243        #tokenize the receipt into a hashtable containing the receipt contents 
    4344        tokens = receipt.split("|") 
     
    4748            if t != None and len(t) == 2: 
    4849                 ht[t[0]] = t[1] 
     50 
     51        if keys is not None and isinstance(keys, TupleType): 
     52            for key in keys: 
     53                if key not in ht: 
     54                    ht[key] = None 
     55 
    4956        return ht 
    5057