How to use the pytz.exceptions.UnknownTimeZoneError function in pytz

To help you get started, we’ve selected a few pytz examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github openbmc / openbmc / yocto-poky / bitbake / lib / toaster / toastermain / settings.py View on Github external
# since the timezone may match any number of identical timezone definitions,

    zonefilelist = {}
    ZONEINFOPATH = '/usr/share/zoneinfo/'
    for dirpath, dirnames, filenames in os.walk(ZONEINFOPATH):
        for fn in filenames:
            filepath = os.path.join(dirpath, fn)
            zonename = filepath.lstrip(ZONEINFOPATH).strip()
            try:
                import pytz
                from pytz.exceptions import UnknownTimeZoneError
                pass
                try:
                    if pytz.timezone(zonename) is not None:
                        zonefilelist[hashlib.md5(open(filepath).read()).hexdigest()] = zonename
                except UnknownTimeZoneError, ValueError:
                    # we expect timezone failures here, just move over
                    pass
            except ImportError:
                zonefilelist[hashlib.md5(open(filepath).read()).hexdigest()] = zonename

    TIME_ZONE = zonefilelist[hashlib.md5(open('/etc/localtime').read()).hexdigest()]

# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en-us'

SITE_ID = 1

# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True
github the-blue-alliance / the-blue-alliance / controllers / nightbot_controller.py View on Github external
def _render(self, team_number, tz_str=None):
        import pytz
        from pytz.exceptions import UnknownTimeZoneError

        user = self.request.get('user')
        if user:
            user_str = '@{}, '.format(user)
        else:
            user_str = ''

        try:
            arg_tz = pytz.timezone(tz_str) if tz_str else None
        except UnknownTimeZoneError:
            arg_tz = None

        team_event_or_error = validate_team(user_str, team_number)
        if type(team_event_or_error) == str:
            return team_event_or_error

        _, event = team_event_or_error
        event_code_upper = event.event_short.upper()

        matches_future = TeamEventMatchesQuery('frc{}'.format(team_number), event.key.id()).fetch_async()
        matches = MatchHelper.play_order_sort_matches(matches_future.get_result())

        # No match schedule yet
        if not matches:
            return "{}[{}] Team {} has no scheduled matches yet.".format(user_str, event_code_upper, team_number)
github jas14 / gcal2text / gcal2text.py View on Github external
# get timezone
    if args.tz:
        timezone = pytz.timezone(args.tz)
    else:
        timezone = tzlocal()
        while True:
            tzstr = raw_input('Enter a timezone (e.g. US/Pacific) '
                              '[{0}]: '.format(
                                  timezone.tzname(datetime.datetime.now())))
            if tzstr == "":
                break
            try:
                timezone = pytz.timezone(tzstr)
                break
            except pytz.exceptions.UnknownTimeZoneError:
                print("That is not a recognized timezone. See "
                      "https://en.wikipedia.org/wiki/"
                      "List_of_tz_database_time_zones "
                      "for timezone names.")
                pass

    # done getting arguments!!
    # convert clamps to desired timezone
    clamp_end = clamp_end.replace(tzinfo=tzlocal()).astimezone(timezone)
    clamp_start = clamp_start.replace(tzinfo=tzlocal()).astimezone(timezone)

    calendarList = service.calendarList().list().execute()
    calendars = {cal['id']: cal['summary']
                 for cal in calendarList.get('items')}
    print("Fetching events from:")
    for name in calendars.values():
github Tautulli / Tautulli / lib / pytz / __init__.py View on Github external
try:
        zone = ascii(zone)
    except UnicodeEncodeError:
        # All valid timezones are ASCII
        raise UnknownTimeZoneError(zone)

    zone = _case_insensitive_zone_lookup(_unmunge_zone(zone))
    if zone not in _tzinfo_cache:
        if zone in all_timezones_set:  # noqa
            fp = open_resource(zone)
            try:
                _tzinfo_cache[zone] = build_tzinfo(zone, fp)
            finally:
                fp.close()
        else:
            raise UnknownTimeZoneError(zone)

    return _tzinfo_cache[zone]
github fossasia / open-event-server / app / api / schema / events.py View on Github external
def validate_timezone(self, data, original_data):
        if 'id' in original_data['data']:
            try:
                event = Event.query.filter_by(id=original_data['data']['id']).one()
            except NoResultFound:
                raise ObjectNotFound({'source': 'data/id'}, "Event id not found")

            if 'timezone' not in data:
                data['timezone'] = event.timezone
        try:
            timezone(data['timezone'])
        except pytz.exceptions.UnknownTimeZoneError:
            raise UnprocessableEntity({'pointer': '/data/attributes/timezone'},
                                      "Unknown timezone: '{}'".
                                      format(data['timezone']))
github ryfeus / lambda-packs / Pandas_numpy / source / pytz / __init__.py View on Github external
try:
        zone = ascii(zone)
    except UnicodeEncodeError:
        # All valid timezones are ASCII
        raise UnknownTimeZoneError(zone)

    zone = _unmunge_zone(zone)
    if zone not in _tzinfo_cache:
        if zone in all_timezones_set:
            fp = open_resource(zone)
            try:
                _tzinfo_cache[zone] = build_tzinfo(zone, fp)
            finally:
                fp.close()
        else:
            raise UnknownTimeZoneError(zone)

    return _tzinfo_cache[zone]
github mdn / kuma / vendor / packages / pytz / __init__.py View on Github external
>>> try:
    ...     timezone(unicode('\N{TRADE MARK SIGN}'))
    ... except UnknownTimeZoneError:
    ...     print('Unknown')
    Unknown

    '''
    if zone.upper() == 'UTC':
        return utc

    try:
        zone = ascii(zone)
    except UnicodeEncodeError:
        # All valid timezones are ASCII
        raise UnknownTimeZoneError(zone)

    zone = _unmunge_zone(zone)
    if zone not in _tzinfo_cache:
        if zone in all_timezones_set:
            fp = open_resource(zone)
            try:
                _tzinfo_cache[zone] = build_tzinfo(zone, fp)
            finally:
                fp.close()
        else:
            raise UnknownTimeZoneError(zone)

    return _tzinfo_cache[zone]
github dheerajchand / ubuntu-django-nginx-ansible / projectenv / lib / python2.7 / site-packages / pytz / __init__.py View on Github external
try:
        zone = ascii(zone)
    except UnicodeEncodeError:
        # All valid timezones are ASCII
        raise UnknownTimeZoneError(zone)

    zone = _unmunge_zone(zone)
    if zone not in _tzinfo_cache:
        if zone in all_timezones_set:
            fp = open_resource(zone)
            try:
                _tzinfo_cache[zone] = build_tzinfo(zone, fp)
            finally:
                fp.close()
        else:
            raise UnknownTimeZoneError(zone)

    return _tzinfo_cache[zone]
github FichteFoll / InsertDate / format_date / __init__.py View on Github external
def check_tzparam(self, tz, name):
        if isinstance(tz, basestring):
            try:
                tz = str(tz)  # convert to ansi for ST2
                return pytz.timezone(tz)
            except UnknownTimeZoneError:
                raise UnknownTimeZoneError("Parameter %r = %r is not a valid timezone name"
                                           % (name, tz))

        if tz is not None and not isinstance(tz, tzinfo):
            raise TypeError("Parameter %r = %r is not an instance of datetime.tzinfo"
                            % (name, tz))

        # Nothing else to be done
        return tz