Exemplo n.º 1
0
 def _isdst(self, dt):
     try:
         return super(LocalTimezone, self)._isdst(dt)
     except (OverflowError, ValueError) as exc:
         exc_type = type(exc)
         exc_value = exc_type(
             "Unsupported value: %r. You should install pytz." % dt)
         exc_value.__cause__ = exc
         if not hasattr(exc, '__traceback__'):
             exc.__traceback__ = sys.exc_info()[2]
         six.reraise(exc_type, exc_value, sys.exc_info()[2])
Exemplo n.º 2
0
 def _isdst(self, dt):
     try:
         return super(LocalTimezone, self)._isdst(dt)
     except (OverflowError, ValueError) as exc:
         exc_type = type(exc)
         exc_value = exc_type(
             "Unsupported value: %r. You should install pytz." % dt)
         exc_value.__cause__ = exc
         if not hasattr(exc, '__traceback__'):
             exc.__traceback__ = sys.exc_info()[2]
         six.reraise(exc_type, exc_value, sys.exc_info()[2])
Exemplo n.º 3
0
def import_by_path(dotted_path, error_prefix=''):
    """
    Import a dotted module path and return the attribute/class designated by the
    last name in the path. Raise ImproperlyConfigured if something goes wrong.
    """
    try:
        module_path, class_name = dotted_path.rsplit('.', 1)
    except ValueError:
        raise ImproperlyConfigured("%s%s doesn't look like a module path" % (
            error_prefix, dotted_path))
    try:
        module = import_module(module_path)
    except ImportError as e:
        msg = '%sError importing module %s: "%s"' % (
            error_prefix, module_path, e)
        six.reraise(ImproperlyConfigured, ImproperlyConfigured(msg),
                    sys.exc_info()[2])
    try:
        attr = getattr(module, class_name)
    except AttributeError:
        raise ImproperlyConfigured('%sModule "%s" does not define a "%s" attribute/class' % (
            error_prefix, module_path, class_name))
    return attr