Exemple #1
0
 def __getattr__(self, name):
     if 'jid' == name:
         if self._jid is None: # Wait first call to compute it
             # 1DXFn72VHrXRVYJTTxjbmNXyXpYXmgiWfw
             # 1dxfn72vhrxrvyjttxjbmnxyxpyxmgiwfw (lowercase)
             # 1110  110111111100001101011000100 (mask on uppercase)
             # -> mask in base36 (should return x0l0p0)
             mask = long(0)
             gaps = 0
             for i, char in enumerate(reversed(self.address)):
                 if char.isupper():
                     mask += 2 ** (i - gaps)
                 elif char.isdigit():
                     gaps += 1
             suffix = ""
             while mask > 0:
                 suffix = "0123456789abcdefghijklmnopqrstuvwxyz"[mask % ENCODING_BASE] + suffix
                 mask //= ENCODING_BASE
             if ("" != suffix):
                 suffix = ENCODING_SEP + suffix
             self._jid = JID(node=self.address.lower() + suffix)
         return self._jid
     elif 'owner' == name:
         if self._owner is None: # Wait first call to compute it
             from useraccount import UserAccount
             self._owner = UserAccount(JID(node=self.account))
         return self._owner
     else:
         return BCAddress.__getattr__(self, name)
Exemple #2
0
 def __init__(self, address=None):
     '''Constructor. Initialize a bitcoin address normally.
        If the argument is a JID object, though, decode it first.
     '''
     self._jid = None
     self._owner = None
     if 'JID' == address.__class__.__name__:
         address.setResource('')
         self._jid = address
         address = address.getNode()
         parts = address.partition(ENCODING_SEP)
         if len(parts[2]):
             positions = int(parts[2], ENCODING_BASE)
             address = ''
             for c in reversed(parts[0]):
                 if c.isalpha():
                     if (positions % 2):
                         c = c.upper()
                     positions //= 2
                 address = c + address
     BCAddress.__init__(self, address)