Exemplo n.º 1
0
    def __init__(self, raw_number, country_code=None):
        # Bail if phonenumbers is not found.
        if phonenumbers is None:
            raise ImproperlyConfigured(
                "'phonenumbers' is required to use 'PhoneNumber'")

        self._phone_number = phonenumbers.parse(raw_number, country_code)
        super(PhoneNumber, self).__init__(
            country_code=self._phone_number.country_code,
            national_number=self._phone_number.national_number,
            extension=self._phone_number.extension,
            italian_leading_zero=self._phone_number.italian_leading_zero,
            raw_input=self._phone_number.raw_input,
            country_code_source=self._phone_number.country_code_source,
            preferred_domestic_carrier_code=
            self._phone_number.preferred_domestic_carrier_code
        )
        self.national = phonenumbers.format_number(
            self._phone_number,
            phonenumbers.PhoneNumberFormat.NATIONAL
        )
        self.international = phonenumbers.format_number(
            self._phone_number,
            phonenumbers.PhoneNumberFormat.INTERNATIONAL
        )
        self.e164 = phonenumbers.format_number(
            self._phone_number,
            phonenumbers.PhoneNumberFormat.E164
        )
Exemplo n.º 2
0
    def __init__(self, *args, **kwargs):
        if babel is None:
            raise ImproperlyConfigured(
                "'babel' package is required in order to use CurrencyType."
            )

        super(CurrencyType, self).__init__(*args, **kwargs)
Exemplo n.º 3
0
    def __init__(self, max_length=20, *args, **kwargs):
        # Fail if colour is not found.
        if colour is None:
            raise ImproperlyConfigured(
                "'colour' package is required to use 'ColorType'")

        super(ColorType, self).__init__(*args, **kwargs)
        self.impl = types.Unicode(max_length)
Exemplo n.º 4
0
    def __init__(self, max_length=50, *args, **kwargs):
        if not ip_address:
            raise ImproperlyConfigured(
                "'ipaddr' package is required to use 'IPAddressType' "
                "in python 2")

        super(IPAddressType, self).__init__(*args, **kwargs)
        self.impl = types.Unicode(max_length)
Exemplo n.º 5
0
    def __init__(self, country_code='US', max_length=20, *args, **kwargs):
        # Bail if phonenumbers is not found.
        if phonenumbers is None:
            raise ImproperlyConfigured(
                "'phonenumbers' is required to use 'PhoneNumberType'")

        super(PhoneNumberType, self).__init__(*args, **kwargs)
        self.country_code = country_code
        self.impl = types.Unicode(max_length)
Exemplo n.º 6
0
    def __init__(self, current_user_id_factory=None, remote_addr_factory=None):
        self.current_user_id_factory = (fetch_current_user_id
                                        if current_user_id_factory is None else
                                        current_user_id_factory)
        self.remote_addr_factory = (fetch_remote_addr
                                    if remote_addr_factory is None else
                                    remote_addr_factory)

        if not flask:
            raise ImproperlyConfigured(
                'Flask is required with FlaskPlugin. Please install Flask by'
                ' running pip install Flask')
Exemplo n.º 7
0
    def __init__(self, backend='dateutil'):
        """
        :param backend: Whether to use 'dateutil' or 'pytz' for timezones.
        """

        self.backend = backend
        if backend == 'dateutil':
            try:
                from dateutil.tz import tzfile
                from dateutil.zoneinfo import gettz

                self.python_type = tzfile
                self._to = gettz
                self._from = lambda x: x._filename

            except ImportError:
                raise ImproperlyConfigured(
                    "'python-dateutil' is required to use the "
                    "'dateutil' backend for 'TimezoneType'"
                )

        elif backend == 'pytz':
            try:
                from pytz import tzfile, timezone

                self.python_type = tzfile.DstTzInfo
                self._to = timezone
                self._from = six.text_type

            except ImportError:
                raise ImproperlyConfigured(
                    "'pytz' is required to use the 'pytz' backend "
                    "for 'TimezoneType'"
                )

        else:
            raise ImproperlyConfigured(
                "'pytz' or 'dateutil' are the backends supported for "
                "'TimezoneType'"
            )
Exemplo n.º 8
0
    def __init__(self, max_length=None, **kwargs):
        # Fail if passlib is not found.
        if passlib is None:
            raise ImproperlyConfigured(
                "'passlib' is required to use 'PasswordType'")

        # Construct the passlib crypt context.
        self.context = CryptContext(**kwargs)

        if max_length is None:
            max_length = self.calculate_max_length()

        # Set the length to the now-calculated max length.
        self.length = max_length
Exemplo n.º 9
0
 def __init__(self, code):
     if babel is None:
         raise ImproperlyConfigured(
             "'babel' package is required in order to use Currency class.")
     if isinstance(code, Currency):
         self.code = code
     elif isinstance(code, six.string_types):
         self.validate(code)
         self.code = code
     else:
         raise TypeError(
             'First argument given to Currency constructor should be '
             'either an instance of Currency or valid three letter '
             'currency code.')
Exemplo n.º 10
0
    def __init__(self, name, columns):
        if psycopg2 is None:
            raise ImproperlyConfigured(
                "'psycopg2' package is required in order to use CompositeType."
            )
        SchemaType.__init__(self)
        self.name = name
        self.columns = columns
        if name in registered_composites:
            self.type_cls = registered_composites[name].type_cls
        else:
            self.type_cls = namedtuple(
                self.name, [c.name for c in columns]
            )
        registered_composites[name] = self

        class Caster(CompositeCaster):
            def make(obj, values):
                return self.type_cls(*values)

        self.caster = Caster
        attach_composite_listeners()
Exemplo n.º 11
0
 def __init__(self):
     if not flask:
         raise ImproperlyConfigured(
             'Flask is required with FlaskPlugin. Please install Flask by'
             ' running pip install Flask')
Exemplo n.º 12
0
    def __init__(self, *args, **kwargs):
        if not arrow:
            raise ImproperlyConfigured(
                "'arrow' package is required to use 'ArrowType'")

        super(ArrowType, self).__init__(*args, **kwargs)