Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import six
from faker import Faker
from faker.providers.date_time import Provider as DatetimeProvider
from faker.providers.date_time.pl_PL import Provider as PlProvider
from faker.providers.date_time.ar_AA import Provider as ArProvider
from faker.providers.date_time.ar_EG import Provider as EgProvider
from faker.providers.date_time.hy_AM import Provider as HyAmProvider
from faker.providers.date_time.ta_IN import Provider as TaInProvider
def is64bit():
return sys.maxsize > 2**32
class UTC(tzinfo):
"""
UTC implementation taken from Python's docs.
"""
def __repr__(self):
return ""
def utcoffset(self, dt):
return timedelta(0)
def tzname(self, dt):
return "UTC"
def dst(self, dt):
return timedelta(0)
def test_get_tzinfo_options(self):
options = get_tzinfo_options()
self.assertTrue(len(options) > 0)
for tzinfo in options:
self.assertIsInstance(tzinfo(), datetime.tzinfo)
:return: the relative path
:rtype: `basestring`
"""
start_list = os.path.abspath(start).split(os.sep)
path_list = os.path.abspath(path).split(os.sep)
# Work out how much of the filepath is shared by start and path.
i = len(os.path.commonprefix([start_list, path_list]))
rel_list = [os.path.pardir] * (len(start_list) - i) + path_list[i:]
return os.path.join(*rel_list)
ZERO = timedelta(0)
class FixedOffsetTimezone(tzinfo):
"""Fixed offset in minutes east from UTC."""
def __init__(self, offset, name=None):
self._offset = timedelta(minutes=offset)
if name is None:
name = 'Etc/GMT+%d' % offset
self.zone = name
def __str__(self):
return self.zone
def __repr__(self):
return '' % (self.zone, self._offset)
def utcoffset(self, dt):
return self._offset
try:
from functools import reduce
except ImportError:
# reduce is available in functools starting with Python 2.6
pass
try:
from pytz import UTC
except ImportError:
# pytz is optional, define own "UTC" timestamp
# reference implementation from Python documentation
from datetime import timedelta, tzinfo
ZERO = timedelta(0)
class UTC(tzinfo):
"""UTC"""
def utcoffset(self, dt):
return ZERO
def tzname(self, dt):
return "UTC"
def dst(self, dt):
return ZERO
def _call__(self):
return self
UTC = UTC()
import sys
import os
relativedelta = None
parser = None
rrule = None
__all__ = ["tzutc", "tzoffset", "tzlocal", "tzfile", "tzrange",
"tzstr", "tzical", "tzwin", "tzwinlocal", "gettz"]
tzwin, tzwinlocal = None, None
ZERO = datetime.timedelta(0)
EPOCHORDINAL = datetime.datetime.utcfromtimestamp(0).toordinal()
class tzutc(datetime.tzinfo):
def utcoffset(self, dt):
return ZERO
def dst(self, dt):
return ZERO
def tzname(self, dt):
return "UTC"
def __eq__(self, other):
return (isinstance(other, tzutc) or
(isinstance(other, tzoffset) and other._offset == ZERO))
def __ne__(self, other):
return not self.__eq__(other)
def _build_tzinfo(self, tzinfos, tzname, tzoffset):
if callable(tzinfos):
tzdata = tzinfos(tzname, tzoffset)
else:
tzdata = tzinfos.get(tzname)
# handle case where tzinfo is paased an options that returns None
# eg tzinfos = {'BRST' : None}
if isinstance(tzdata, datetime.tzinfo) or tzdata is None:
tzinfo = tzdata
elif isinstance(tzdata, text_type):
tzinfo = tz.tzstr(tzdata)
elif isinstance(tzdata, integer_types):
tzinfo = tz.tzoffset(tzname, tzdata)
return tzinfo
from datetime import datetime as DT
from datetime import timedelta
from datetime import tzinfo
def first_sunday_on_or_after(dt):
days_to_go = 6 - dt.weekday()
if days_to_go:
dt += timedelta(days_to_go)
return dt
DSTSTART_2007 = DT(1, 3, 8, 2)
DSTEND_2007 = DT(1, 11, 1, 1)
ZERO = timedelta(0)
HOUR = timedelta(hours=1)
class USTimeZone(tzinfo):
def __init__(self, hours, reprname, stdname, dstname):
self.stdoffset = timedelta(hours=hours)
self.reprname = reprname
self.stdname = stdname
self.dstname = dstname
def __repr__(self):
return self.reprname
def tzname(self, dt):
if self.dst(dt):
return self.dstname
else:
return self.stdname
location_el = p["location"]
location = g15pythonlang.append_if_exists(location_el, "city", "")
location = g15pythonlang.append_if_exists(location_el, "region", location)
location = g15pythonlang.append_if_exists(location_el, "country", location)
# Get current condition
condition_el = p["condition"]
wind_el = p["wind"] if "wind" in p else None
# Observed date
try:
observed_datetime = datetime.datetime.strptime(condition_el["date"], "%a, %d %b %Y %H:%M %p %Z")
except ValueError as v:
import email.utils
dxt = email.utils.parsedate_tz(condition_el["date"])
class TZ(datetime.tzinfo):
def dst(self, dt):
return datetime.timedelta(0)
def tzname(self, dt):
return dxt[9]
def utcoffset(self, dt): return datetime.timedelta(seconds=dxt[9])
observed_datetime = datetime.datetime(*dxt[:7], tzinfo=TZ())
# Forecasts (we only get 2 from yahoo)
forecasts_el = p["forecasts"]
forecasts = []
today_low = None
today_high = None
for f in forecasts_el:
condition_code = g15pythonlang.to_int_or_none(f["code"])
def _safe_timezone(obj):
# type: (Union[str, int, float, _datetime.tzinfo]) -> _Timezone
"""
Creates a timezone instance
from a string, Timezone, TimezoneInfo or integer offset.
"""
if isinstance(obj, _Timezone):
return obj
if obj is None or obj == "local":
return local_timezone()
if isinstance(obj, (int, float)):
obj = int(obj * 60 * 60)
elif isinstance(obj, _datetime.tzinfo):
# pytz
if hasattr(obj, "localize"):
obj = obj.zone
else:
offset = obj.utcoffset(None)
if offset is None:
offset = _datetime.timedelta(0)
obj = int(offset.total_seconds())
return timezone(obj)
def dst(self, dt):
return ZERO
# A class capturing the platform's idea of local time.
import time as _time
STDOFFSET = timedelta(seconds = -_time.timezone)
if _time.daylight:
DSTOFFSET = timedelta(seconds = -_time.altzone)
else:
DSTOFFSET = STDOFFSET
DSTDIFF = DSTOFFSET - STDOFFSET
class LocalTimezone(tzinfo):
def utcoffset(self, dt):
if self._isdst(dt):
return DSTOFFSET
else:
return STDOFFSET
def dst(self, dt):
if self._isdst(dt):
return DSTDIFF
else:
return ZERO
def tzname(self, dt):
return _time.tzname[self._isdst(dt)]