python类exceptions()的实例源码

ewsdatetime.py 文件源码 项目:exchangelib 作者: ecederstrand 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def localzone(cls):
        try:
            tz = tzlocal.get_localzone()
        except pytz.exceptions.UnknownTimeZoneError:
            raise UnknownTimeZone("Failed to guess local timezone")
        return cls.from_pytz(tz)
ewsdatetime.py 文件源码 项目:exchangelib 作者: ecederstrand 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
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)
ewsdatetime.py 文件源码 项目:exchangelib 作者: ecederstrand 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
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
ewsdatetime.py 文件源码 项目:exchangelib 作者: ecederstrand 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
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


问题


面经


文章

微信
公众号

扫码关注公众号