Python pytz 模块,exceptions() 实例源码

我们从Python开源项目中,提取了以下4个代码示例,用于说明如何使用pytz.exceptions()

项目:exchangelib    作者:ecederstrand    | 项目源码 | 文件源码
def localzone(cls):
        try:
            tz = tzlocal.get_localzone()
        except pytz.exceptions.UnknownTimeZoneError:
            raise UnknownTimeZone("Failed to guess local timezone")
        return cls.from_pytz(tz)
项目:exchangelib    作者:ecederstrand    | 项目源码 | 文件源码
def timezone(cls, location):
        # Like pytz.timezone() but returning EWSTimeZone instances
        try:
            tz = pytz.timezone(location)
        except pytz.exceptions.UnknownTimeZoneError:
            raise UnknownTimeZone("Timezone '%s' is unknown by pytz" % location)
        return cls.from_pytz(tz)
项目:exchangelib    作者:ecederstrand    | 项目源码 | 文件源码
def normalize(self, dt, is_dst=False):
        # super() returns a dt.tzinfo of class pytz.tzinfo.FooBar. We need to return type EWSTimeZone
        if is_dst is not False:
            # Not all pytz timezones support 'is_dst' argument. Only pass it on if it's set explicitly.
            try:
                res = super(EWSTimeZone, self).normalize(dt, is_dst=is_dst)
            except pytz.exceptions.AmbiguousTimeError:
                raise AmbiguousTimeError(str(dt))
            except pytz.exceptions.NonExistentTimeError:
                raise NonExistentTimeError(str(dt))
        else:
            res = super(EWSTimeZone, self).normalize(dt)
        if not isinstance(res.tzinfo, EWSTimeZone):
            return res.replace(tzinfo=self.from_pytz(res.tzinfo))
        return res
项目:exchangelib    作者:ecederstrand    | 项目源码 | 文件源码
def localize(self, dt, is_dst=False):
        # super() returns a dt.tzinfo of class pytz.tzinfo.FooBar. We need to return type EWSTimeZone
        if is_dst is not False:
            # Not all pytz timezones support 'is_dst' argument. Only pass it on if it's set explicitly.
            try:
                res = super(EWSTimeZone, self).localize(dt, is_dst=is_dst)
            except pytz.exceptions.AmbiguousTimeError:
                raise AmbiguousTimeError(str(dt))
            except pytz.exceptions.NonExistentTimeError:
                raise NonExistentTimeError(str(dt))
        else:
            res = super(EWSTimeZone, self).localize(dt)
        if not isinstance(res.tzinfo, EWSTimeZone):
            return res.replace(tzinfo=self.from_pytz(res.tzinfo))
        return res