summaryrefslogtreecommitdiffstats
path: root/jython-tosca-parser/src/main/resources/Lib/site-packages/babel-2.3.4-py2.7.egg/babel/localtime
diff options
context:
space:
mode:
Diffstat (limited to 'jython-tosca-parser/src/main/resources/Lib/site-packages/babel-2.3.4-py2.7.egg/babel/localtime')
-rw-r--r--jython-tosca-parser/src/main/resources/Lib/site-packages/babel-2.3.4-py2.7.egg/babel/localtime/__init__.py76
-rw-r--r--jython-tosca-parser/src/main/resources/Lib/site-packages/babel-2.3.4-py2.7.egg/babel/localtime/_unix.py138
-rw-r--r--jython-tosca-parser/src/main/resources/Lib/site-packages/babel-2.3.4-py2.7.egg/babel/localtime/_win32.py96
3 files changed, 0 insertions, 310 deletions
diff --git a/jython-tosca-parser/src/main/resources/Lib/site-packages/babel-2.3.4-py2.7.egg/babel/localtime/__init__.py b/jython-tosca-parser/src/main/resources/Lib/site-packages/babel-2.3.4-py2.7.egg/babel/localtime/__init__.py
deleted file mode 100644
index 883ff16..0000000
--- a/jython-tosca-parser/src/main/resources/Lib/site-packages/babel-2.3.4-py2.7.egg/babel/localtime/__init__.py
+++ /dev/null
@@ -1,76 +0,0 @@
-# -*- coding: utf-8 -*-
-"""
- babel.localtime
- ~~~~~~~~~~~~~~~
-
- Babel specific fork of tzlocal to determine the local timezone
- of the system.
-
- :copyright: (c) 2013 by the Babel Team.
- :license: BSD, see LICENSE for more details.
-"""
-
-import sys
-import pytz
-import time
-from datetime import timedelta
-from datetime import tzinfo
-from threading import RLock
-
-if sys.platform == 'win32':
- from babel.localtime._win32 import _get_localzone
-else:
- from babel.localtime._unix import _get_localzone
-
-
-_cached_tz = None
-_cache_lock = RLock()
-
-STDOFFSET = timedelta(seconds=-time.timezone)
-if time.daylight:
- DSTOFFSET = timedelta(seconds=-time.altzone)
-else:
- DSTOFFSET = STDOFFSET
-
-DSTDIFF = DSTOFFSET - STDOFFSET
-ZERO = timedelta(0)
-
-
-class _FallbackLocalTimezone(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)]
-
- def _isdst(self, dt):
- tt = (dt.year, dt.month, dt.day,
- dt.hour, dt.minute, dt.second,
- dt.weekday(), 0, -1)
- stamp = time.mktime(tt)
- tt = time.localtime(stamp)
- return tt.tm_isdst > 0
-
-
-def get_localzone():
- """Returns the current underlying local timezone object.
- Generally this function does not need to be used, it's a
- better idea to use the :data:`LOCALTZ` singleton instead.
- """
- return _get_localzone()
-
-
-try:
- LOCALTZ = get_localzone()
-except pytz.UnknownTimeZoneError:
- LOCALTZ = _FallbackLocalTimezone()
diff --git a/jython-tosca-parser/src/main/resources/Lib/site-packages/babel-2.3.4-py2.7.egg/babel/localtime/_unix.py b/jython-tosca-parser/src/main/resources/Lib/site-packages/babel-2.3.4-py2.7.egg/babel/localtime/_unix.py
deleted file mode 100644
index 378a90b..0000000
--- a/jython-tosca-parser/src/main/resources/Lib/site-packages/babel-2.3.4-py2.7.egg/babel/localtime/_unix.py
+++ /dev/null
@@ -1,138 +0,0 @@
-from __future__ import with_statement
-import os
-import re
-import sys
-import pytz
-import subprocess
-
-_systemconfig_tz = re.compile(r'^Time Zone: (.*)$(?m)')
-
-
-def _tz_from_env(tzenv):
- if tzenv[0] == ':':
- tzenv = tzenv[1:]
-
- # TZ specifies a file
- if os.path.exists(tzenv):
- with open(tzenv, 'rb') as tzfile:
- return pytz.tzfile.build_tzinfo('local', tzfile)
-
- # TZ specifies a zoneinfo zone.
- try:
- tz = pytz.timezone(tzenv)
- # That worked, so we return this:
- return tz
- except pytz.UnknownTimeZoneError:
- raise pytz.UnknownTimeZoneError(
- "tzlocal() does not support non-zoneinfo timezones like %s. \n"
- "Please use a timezone in the form of Continent/City")
-
-
-def _get_localzone(_root='/'):
- """Tries to find the local timezone configuration.
- This method prefers finding the timezone name and passing that to pytz,
- over passing in the localtime file, as in the later case the zoneinfo
- name is unknown.
- The parameter _root makes the function look for files like /etc/localtime
- beneath the _root directory. This is primarily used by the tests.
- In normal usage you call the function without parameters.
- """
-
- tzenv = os.environ.get('TZ')
- if tzenv:
- return _tz_from_env(tzenv)
-
- # This is actually a pretty reliable way to test for the local time
- # zone on operating systems like OS X. On OS X especially this is the
- # only one that actually works.
- try:
- link_dst = os.readlink('/etc/localtime')
- except OSError:
- pass
- else:
- pos = link_dst.find('/zoneinfo/')
- if pos >= 0:
- zone_name = link_dst[pos + 10:]
- try:
- return pytz.timezone(zone_name)
- except pytz.UnknownTimeZoneError:
- pass
-
- # If we are on OS X now we are pretty sure that the rest of the
- # code will fail and just fall through until it hits the reading
- # of /etc/localtime and using it without name. At this point we
- # can invoke systemconfig which internally invokes ICU. ICU itself
- # does the same thing we do (readlink + compare file contents) but
- # since it knows where the zone files are that should be a bit
- # better than reimplementing the logic here.
- if sys.platform == 'darwin':
- c = subprocess.Popen(['systemsetup', '-gettimezone'],
- stdout=subprocess.PIPE)
- sys_result = c.communicate()[0]
- c.wait()
- tz_match = _systemconfig_tz.search(sys_result)
- if tz_match is not None:
- zone_name = tz_match.group(1)
- try:
- return pytz.timezone(zone_name)
- except pytz.UnknownTimeZoneError:
- pass
-
- # Now look for distribution specific configuration files
- # that contain the timezone name.
- tzpath = os.path.join(_root, 'etc/timezone')
- if os.path.exists(tzpath):
- with open(tzpath, 'rb') as tzfile:
- data = tzfile.read()
-
- # Issue #3 in tzlocal was that /etc/timezone was a zoneinfo file.
- # That's a misconfiguration, but we need to handle it gracefully:
- if data[:5] != 'TZif2':
- etctz = data.strip().decode()
- # Get rid of host definitions and comments:
- if ' ' in etctz:
- etctz, dummy = etctz.split(' ', 1)
- if '#' in etctz:
- etctz, dummy = etctz.split('#', 1)
- return pytz.timezone(etctz.replace(' ', '_'))
-
- # CentOS has a ZONE setting in /etc/sysconfig/clock,
- # OpenSUSE has a TIMEZONE setting in /etc/sysconfig/clock and
- # Gentoo has a TIMEZONE setting in /etc/conf.d/clock
- # We look through these files for a timezone:
- zone_re = re.compile('\s*ZONE\s*=\s*\"')
- timezone_re = re.compile('\s*TIMEZONE\s*=\s*\"')
- end_re = re.compile('\"')
-
- for filename in ('etc/sysconfig/clock', 'etc/conf.d/clock'):
- tzpath = os.path.join(_root, filename)
- if not os.path.exists(tzpath):
- continue
- with open(tzpath, 'rt') as tzfile:
- data = tzfile.readlines()
-
- for line in data:
- # Look for the ZONE= setting.
- match = zone_re.match(line)
- if match is None:
- # No ZONE= setting. Look for the TIMEZONE= setting.
- match = timezone_re.match(line)
- if match is not None:
- # Some setting existed
- line = line[match.end():]
- etctz = line[:end_re.search(line).start()]
-
- # We found a timezone
- return pytz.timezone(etctz.replace(' ', '_'))
-
- # No explicit setting existed. Use localtime
- for filename in ('etc/localtime', 'usr/local/etc/localtime'):
- tzpath = os.path.join(_root, filename)
-
- if not os.path.exists(tzpath):
- continue
-
- with open(tzpath, 'rb') as tzfile:
- return pytz.tzfile.build_tzinfo('local', tzfile)
-
- raise pytz.UnknownTimeZoneError('Can not find any timezone configuration')
diff --git a/jython-tosca-parser/src/main/resources/Lib/site-packages/babel-2.3.4-py2.7.egg/babel/localtime/_win32.py b/jython-tosca-parser/src/main/resources/Lib/site-packages/babel-2.3.4-py2.7.egg/babel/localtime/_win32.py
deleted file mode 100644
index 3752dff..0000000
--- a/jython-tosca-parser/src/main/resources/Lib/site-packages/babel-2.3.4-py2.7.egg/babel/localtime/_win32.py
+++ /dev/null
@@ -1,96 +0,0 @@
-try:
- import _winreg as winreg
-except ImportError:
- try:
- import winreg
- except ImportError:
- winreg = None
-
-from babel.core import get_global
-import pytz
-
-
-# When building the cldr data on windows this module gets imported.
-# Because at that point there is no global.dat yet this call will
-# fail. We want to catch it down in that case then and just assume
-# the mapping was empty.
-try:
- tz_names = get_global('windows_zone_mapping')
-except RuntimeError:
- tz_names = {}
-
-
-def valuestodict(key):
- """Convert a registry key's values to a dictionary."""
- dict = {}
- size = winreg.QueryInfoKey(key)[1]
- for i in range(size):
- data = winreg.EnumValue(key, i)
- dict[data[0]] = data[1]
- return dict
-
-
-def get_localzone_name():
- # Windows is special. It has unique time zone names (in several
- # meanings of the word) available, but unfortunately, they can be
- # translated to the language of the operating system, so we need to
- # do a backwards lookup, by going through all time zones and see which
- # one matches.
- handle = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE)
-
- TZLOCALKEYNAME = r'SYSTEM\CurrentControlSet\Control\TimeZoneInformation'
- localtz = winreg.OpenKey(handle, TZLOCALKEYNAME)
- keyvalues = valuestodict(localtz)
- localtz.Close()
- if 'TimeZoneKeyName' in keyvalues:
- # Windows 7 (and Vista?)
-
- # For some reason this returns a string with loads of NUL bytes at
- # least on some systems. I don't know if this is a bug somewhere, I
- # just work around it.
- tzkeyname = keyvalues['TimeZoneKeyName'].split('\x00', 1)[0]
- else:
- # Windows 2000 or XP
-
- # This is the localized name:
- tzwin = keyvalues['StandardName']
-
- # Open the list of timezones to look up the real name:
- TZKEYNAME = r'SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones'
- tzkey = winreg.OpenKey(handle, TZKEYNAME)
-
- # Now, match this value to Time Zone information
- tzkeyname = None
- for i in range(winreg.QueryInfoKey(tzkey)[0]):
- subkey = winreg.EnumKey(tzkey, i)
- sub = winreg.OpenKey(tzkey, subkey)
- data = valuestodict(sub)
- sub.Close()
- if data['Std'] == tzwin:
- tzkeyname = subkey
- break
-
- tzkey.Close()
- handle.Close()
-
- if tzkeyname is None:
- raise LookupError('Can not find Windows timezone configuration')
-
- timezone = tz_names.get(tzkeyname)
- if timezone is None:
- # Nope, that didn't work. Try adding 'Standard Time',
- # it seems to work a lot of times:
- timezone = tz_names.get(tzkeyname + ' Standard Time')
-
- # Return what we have.
- if timezone is None:
- raise pytz.UnknownTimeZoneError('Can not find timezone ' + tzkeyname)
-
- return timezone
-
-
-def _get_localzone():
- if winreg is None:
- raise pytz.UnknownTimeZoneError(
- 'Runtime support not available')
- return pytz.timezone(get_localzone_name())