def __init__(self, *args):
        """Instances of :class:`IBAN` can be created in two ways, by providing
        a Unicode string representation of an IBAN or by providing a country
        code, a bank identifier and a bank account number.

        **1. Form**

        Args:
            iban (`Unicode string`): string representation of an IBAN

        Returns:
            instance of :class:`IBAN`

        Raises:
            TypeError: given `iban` is not a `Unicode string`
            ValueError: given `iban` contains an unknown country code
            ValueError: given `iban` contains wrong check digits
            ValueError: given `iban` does not follow the format required for
                the given country code

        **2. Form**

        Args:
            country_code (`Unicode string`): 2-character country code
                according to ISO 3166
            bank_identifier (`Unicode string` or `int`): code identifying the
                bank maintaining the account
            bank_account_number (`Unicode string` or `int`): code identifying
                the account (within the namespace of the bank)

        Returns:
            instance of :class:`IBAN`

        Raises:
            TypeError: invalid number of arguments
            TypeError: given `country_code` is not a `Unicode string`
            ValueError: given `country_code` contains an invalid or unknown
                country code
            TypeError: given `bank_identifier` is not a `Unicode string` or
                not an `int`
            ValueError: length of given `bank_identifier` not valid for
                the given country code
            TypeError: given `bank_account_number` is not a `Unicode string`
                or not an `int`
            ValueError: length of given `bank_account_number` not valid for
                the given country code
            ValueError: given `bank_identifier` and `bank_account_number` do
                not follow the BBAN format required for the given country code
        """
        n_args = len(args)
        if n_args == 1:
            arg0 = args[0]
            if not isinstance(arg0, str):
                raise TypeError("Argument must be instance of %s." % str)
            arg0 = arg0.strip()
            country_code, check_digits, bban = split_iban(arg0)
            try:
                bban_length, bban_structure, bban_split_pos, _ = \
                    get_iban_spec(country_code)
            except KeyError:
                raise ValueError("Unknown country code: '%s'." % country_code)
            if len(bban) == bban_length and bban_structure.match(bban):
                corr_check_digits = calc_iban_check_digits(country_code, bban)
                if check_digits != corr_check_digits:
                    raise ValueError(
                        "Wrong check digits: '%s'; should be '%s'."
                        % (check_digits, corr_check_digits))
                self._id = arg0
            else:
                raise ValueError('Invalid IBAN format.')
        elif n_args == 3:
            arg0 = args[0]
            if not isinstance(arg0, str):
                raise TypeError("Country code must be instance of %s." % str)
            if len(arg0) != 2:
                raise ValueError("Country code must be a 2-character string.")
            country_code = arg0
            try:
                bban_length, bban_structure, bban_split_pos, _ = \
                    get_iban_spec(country_code)
            except KeyError:
                raise ValueError("Unknown country code: '%s'." % country_code)
            arg1 = args[1]
            if isinstance(arg1, str):
                if len(arg1) == bban_split_pos:
                    bank_identifier = arg1
                else:
                    raise ValueError("Bank identifier, if given as a string, "
                                     "must contain %i chars."
                                     % bban_split_pos)
            elif isinstance(arg1, int):
                bank_identifier = format(arg1,
                                         '0%id' % bban_split_pos)
                if len(bank_identifier) != bban_split_pos:
                    raise ValueError("Bank identifier, if given as an int, "
                                     "must not have more than %i digits."
                                     % bban_split_pos)
            else:
                raise TypeError("Bank identifier must be instance of "
                                "%s or %s." % (str, int))
            arg2 = args[2]
            account_number_length = bban_length - bban_split_pos
            if isinstance(arg2, str):
                if len(arg2) == account_number_length:
                    bank_account_number = arg2
                else:
                    raise ValueError("Bank account number, if given as a "
                                     "string, must contain %i chars."
                                     % account_number_length)
            elif isinstance(arg2, int):
                bank_account_number = format(arg2,
                                             '0%id' % account_number_length)
                if len(bank_account_number) != account_number_length:
                    raise ValueError("Bank account number, if given as an "
                                     "int, must not have more than %i digits."
                                     % bban_split_pos)
            else:
                raise TypeError("Bank account number must be instance of "
                                "%s or %s." % (str, int))
            bban = bank_identifier + bank_account_number
            if bban_structure.match(bban):
                check_digits = calc_iban_check_digits(country_code, bban)
                self._id = ''.join((country_code, check_digits,
                                    bank_identifier, bank_account_number))
            else:
                raise ValueError('Invalid IBAN format.')
        else:
            raise TypeError('Invalid number of arguments.')
def __init__ ( self , * args ) : n_args = len ( args ) if n_args == 1 : arg0 = args [ 0 ] if not isinstance ( arg0 , str ) : raise TypeError ( "Argument must be instance of %s." % str ) arg0 = arg0 . strip ( ) country_code , check_digits , bban = split_iban ( arg0 ) try : bban_length , bban_structure , bban_split_pos , _ = get_iban_spec ( country_code ) except KeyError : raise ValueError ( "Unknown country code: '%s'." % country_code ) if len ( bban ) == bban_length and bban_structure . match ( bban ) : corr_check_digits = calc_iban_check_digits ( country_code , bban ) if check_digits != corr_check_digits : raise ValueError ( "Wrong check digits: '%s'; should be '%s'." % ( check_digits , corr_check_digits ) ) self . _id = arg0 else : raise ValueError ( 'Invalid IBAN format.' ) elif n_args == 3 : arg0 = args [ 0 ] if not isinstance ( arg0 , str ) : raise TypeError ( "Country code must be instance of %s." % str ) if len ( arg0 ) != 2 : raise ValueError ( "Country code must be a 2-character string." ) country_code = arg0 try : bban_length , bban_structure , bban_split_pos , _ = get_iban_spec ( country_code ) except KeyError : raise ValueError ( "Unknown country code: '%s'." % country_code ) arg1 = args [ 1 ] if isinstance ( arg1 , str ) : if len ( arg1 ) == bban_split_pos : bank_identifier = arg1 else : raise ValueError ( "Bank identifier, if given as a string, " "must contain %i chars." % bban_split_pos ) elif isinstance ( arg1 , int ) : bank_identifier = format ( arg1 , '0%id' % bban_split_pos ) if len ( bank_identifier ) != bban_split_pos : raise ValueError ( "Bank identifier, if given as an int, " "must not have more than %i digits." % bban_split_pos ) else : raise TypeError ( "Bank identifier must be instance of " "%s or %s." % ( str , int ) ) arg2 = args [ 2 ] account_number_length = bban_length - bban_split_pos if isinstance ( arg2 , str ) : if len ( arg2 ) == account_number_length : bank_account_number = arg2 else : raise ValueError ( "Bank account number, if given as a " "string, must contain %i chars." % account_number_length ) elif isinstance ( arg2 , int ) : bank_account_number = format ( arg2 , '0%id' % account_number_length ) if len ( bank_account_number ) != account_number_length : raise ValueError ( "Bank account number, if given as an " "int, must not have more than %i digits." % bban_split_pos ) else : raise TypeError ( "Bank account number must be instance of " "%s or %s." % ( str , int ) ) bban = bank_identifier + bank_account_number if bban_structure . match ( bban ) : check_digits = calc_iban_check_digits ( country_code , bban ) self . _id = '' . join ( ( country_code , check_digits , bank_identifier , bank_account_number ) ) else : raise ValueError ( 'Invalid IBAN format.' ) else : raise TypeError ( 'Invalid number of arguments.' )
Instances of :class:`IBAN` can be created in two ways, by providing
        a Unicode string representation of an IBAN or by providing a country
        code, a bank identifier and a bank account number.

        **1. Form**

        Args:
            iban (`Unicode string`): string representation of an IBAN

        Returns:
            instance of :class:`IBAN`

        Raises:
            TypeError: given `iban` is not a `Unicode string`
            ValueError: given `iban` contains an unknown country code
            ValueError: given `iban` contains wrong check digits
            ValueError: given `iban` does not follow the format required for
                the given country code

        **2. Form**

        Args:
            country_code (`Unicode string`): 2-character country code
                according to ISO 3166
            bank_identifier (`Unicode string` or `int`): code identifying the
                bank maintaining the account
            bank_account_number (`Unicode string` or `int`): code identifying
                the account (within the namespace of the bank)

        Returns:
            instance of :class:`IBAN`

        Raises:
            TypeError: invalid number of arguments
            TypeError: given `country_code` is not a `Unicode string`
            ValueError: given `country_code` contains an invalid or unknown
                country code
            TypeError: given `bank_identifier` is not a `Unicode string` or
                not an `int`
            ValueError: length of given `bank_identifier` not valid for
                the given country code
            TypeError: given `bank_account_number` is not a `Unicode string`
                or not an `int`
            ValueError: length of given `bank_account_number` not valid for
                the given country code
            ValueError: given `bank_identifier` and `bank_account_number` do
                not follow the BBAN format required for the given country code