Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Cloudflare requests #3742

Merged
merged 3 commits into from
Feb 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
414 changes: 0 additions & 414 deletions ext/certifi/old_root.pem

This file was deleted.

5,019 changes: 0 additions & 5,019 deletions ext/certifi/weak.pem

This file was deleted.

2 changes: 1 addition & 1 deletion ext/msgpack/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version = (0, 5, 1)
version = (0, 5, 4)
58 changes: 51 additions & 7 deletions ext/msgpack/fallback.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,16 @@ class Unpacker(object):
If true, unpack msgpack array to Python list.
Otherwise, unpack to Python tuple. (default: True)

:param bool raw:
If true, unpack msgpack raw to Python bytes (default).
Otherwise, unpack to Python str (or unicode on Python 2) by decoding
with UTF-8 encoding (recommended).
Currently, the default is true, but it will be changed to false in
near future. So you must specify it explicitly for keeping backward
compatibility.

*encoding* option which is deprecated overrides this option.

:param callable object_hook:
When specified, it should be callable.
Unpacker calls it with a dict argument after unpacking msgpack map.
Expand Down Expand Up @@ -183,13 +193,13 @@ class Unpacker(object):

example of streaming deserialize from file-like object::

unpacker = Unpacker(file_like)
unpacker = Unpacker(file_like, raw=False)
for o in unpacker:
process(o)

example of streaming deserialize from socket::

unpacker = Unpacker()
unpacker = Unpacker(raw=False)
while True:
buf = sock.recv(1024**2)
if not buf:
Expand All @@ -199,15 +209,28 @@ class Unpacker(object):
process(o)
"""

def __init__(self, file_like=None, read_size=0, use_list=True,
def __init__(self, file_like=None, read_size=0, use_list=True, raw=True,
object_hook=None, object_pairs_hook=None, list_hook=None,
encoding=None, unicode_errors='strict', max_buffer_size=0,
encoding=None, unicode_errors=None, max_buffer_size=0,
ext_hook=ExtType,
max_str_len=2147483647, # 2**32-1
max_bin_len=2147483647,
max_array_len=2147483647,
max_map_len=2147483647,
max_ext_len=2147483647):

if encoding is not None:
warnings.warn(
"encoding is deprecated, Use raw=False instead.",
PendingDeprecationWarning)

if unicode_errors is not None:
warnings.warn(
"unicode_errors is deprecated.",
PendingDeprecationWarning)
else:
unicode_errors = 'strict'

if file_like is None:
self._feeding = True
else:
Expand All @@ -234,6 +257,7 @@ def __init__(self, file_like=None, read_size=0, use_list=True,
if read_size > self._max_buffer_size:
raise ValueError("read_size must be smaller than max_buffer_size")
self._read_size = read_size or min(self._max_buffer_size, 16*1024)
self._raw = bool(raw)
self._encoding = encoding
self._unicode_errors = unicode_errors
self._use_list = use_list
Expand Down Expand Up @@ -582,8 +606,10 @@ def _unpack(self, execute=EX_CONSTRUCT):
if typ == TYPE_RAW:
if self._encoding is not None:
obj = obj.decode(self._encoding, self._unicode_errors)
else:
elif self._raw:
obj = bytes(obj)
else:
obj = obj.decode('utf_8')
return obj
if typ == TYPE_EXT:
return self._ext_hook(n, bytes(obj))
Expand Down Expand Up @@ -682,9 +708,23 @@ class Packer(object):
:param str unicode_errors:
(deprecated) Error handler for encoding unicode. (default: 'strict')
"""
def __init__(self, default=None, encoding='utf-8', unicode_errors='strict',
def __init__(self, default=None, encoding=None, unicode_errors=None,
use_single_float=False, autoreset=True, use_bin_type=False,
strict_types=False):
if encoding is None:
encoding = 'utf_8'
else:
warnings.warn(
"encoding is deprecated, Use raw=False instead.",
PendingDeprecationWarning)

if unicode_errors is None:
unicode_errors = 'strict'
else:
warnings.warn(
"unicode_errors is deprecated.",
PendingDeprecationWarning)

self._strict_types = strict_types
self._use_float = use_single_float
self._autoreset = autoreset
Expand Down Expand Up @@ -808,7 +848,11 @@ def _pack(self, obj, nest_limit=DEFAULT_RECURSE_LIMIT,
raise TypeError("Cannot serialize %r" % (obj, ))

def pack(self, obj):
self._pack(obj)
try:
self._pack(obj)
except:
self._buffer = StringIO() # force reset
raise
ret = self._buffer.getvalue()
if self._autoreset:
self._buffer = StringIO()
Expand Down
66 changes: 26 additions & 40 deletions ext/pytz/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,39 @@
on how to use these modules.
'''

import sys
import datetime
import os.path

from pytz.exceptions import AmbiguousTimeError
from pytz.exceptions import InvalidTimeError
from pytz.exceptions import NonExistentTimeError
from pytz.exceptions import UnknownTimeZoneError
from pytz.lazy import LazyDict, LazyList, LazySet
from pytz.tzinfo import unpickler
from pytz.tzfile import build_tzinfo


# The IANA (nee Olson) database is updated several times a year.
OLSON_VERSION = '2017c'
VERSION = '2017.3' # Switching to pip compatible version numbering.
OLSON_VERSION = '2018c'
VERSION = '2018.3' # Switching to pip compatible version numbering.
__version__ = VERSION

OLSEN_VERSION = OLSON_VERSION # Old releases had this misspelling
OLSEN_VERSION = OLSON_VERSION # Old releases had this misspelling

__all__ = [
'timezone', 'utc', 'country_timezones', 'country_names',
'AmbiguousTimeError', 'InvalidTimeError',
'NonExistentTimeError', 'UnknownTimeZoneError',
'all_timezones', 'all_timezones_set',
'common_timezones', 'common_timezones_set',
]

import sys, datetime, os.path, gettext

from pytz.exceptions import AmbiguousTimeError
from pytz.exceptions import InvalidTimeError
from pytz.exceptions import NonExistentTimeError
from pytz.exceptions import UnknownTimeZoneError
from pytz.lazy import LazyDict, LazyList, LazySet
from pytz.tzinfo import unpickler
from pytz.tzfile import build_tzinfo, _byte_string
]


try:
unicode

except NameError: # Python 3.x
except NameError: # Python 3.x

# Python 3.x doesn't have unicode(), making writing code
# for Python 2.3 and Python 3.x a pain.
Expand All @@ -55,10 +58,10 @@ def ascii(s):
if type(s) == bytes:
s = s.decode('ASCII')
else:
s.encode('ASCII') # Raise an exception if not ASCII
return s # But the string - not a byte string.
s.encode('ASCII') # Raise an exception if not ASCII
return s # But the string - not a byte string.

else: # Python 2.x
else: # Python 2.x

def ascii(s):
r"""
Expand Down Expand Up @@ -88,7 +91,7 @@ def open_resource(name):
if part == os.path.pardir or os.path.sep in part:
raise ValueError('Bad path segment: %r' % part)
zoneinfo_dir = os.environ.get('PYTZ_TZDATADIR', None)
if zoneinfo_dir != None:
if zoneinfo_dir is not None:
filename = os.path.join(zoneinfo_dir, *name_parts)
else:
filename = os.path.join(os.path.dirname(__file__),
Expand Down Expand Up @@ -116,23 +119,9 @@ def resource_exists(name):
return False


# Enable this when we get some translations?
# We want an i18n API that is useful to programs using Python's gettext
# module, as well as the Zope3 i18n package. Perhaps we should just provide
# the POT file and translations, and leave it up to callers to make use
# of them.
#
# t = gettext.translation(
# 'pytz', os.path.join(os.path.dirname(__file__), 'locales'),
# fallback=True
# )
# def _(timezone_name):
# """Translate a timezone name using the current locale, returning Unicode"""
# return t.ugettext(timezone_name)


_tzinfo_cache = {}


def timezone(zone):
r''' Return a datetime.tzinfo implementation for the given timezone

Expand Down Expand Up @@ -298,7 +287,6 @@ def _p(*args):
_p.__safe_for_unpickling__ = True



class _CountryTimezoneDict(LazyDict):
"""Map ISO 3166 country code to a list of timezone names commonly used
in that country.
Expand Down Expand Up @@ -384,7 +372,7 @@ def _fill(self):

class _FixedOffset(datetime.tzinfo):

zone = None # to match the standard pytz API
zone = None # to match the standard pytz API

def __init__(self, minutes):
if abs(minutes) >= 1440:
Expand Down Expand Up @@ -422,7 +410,7 @@ def normalize(self, dt, is_dst=False):
return dt.astimezone(self)


def FixedOffset(offset, _tzinfos = {}):
def FixedOffset(offset, _tzinfos={}):
"""return a fixed-offset timezone based off a number of minutes.

>>> one = FixedOffset(-330)
Expand Down Expand Up @@ -492,14 +480,13 @@ def FixedOffset(offset, _tzinfos = {}):


def _test():
import doctest, os, sys
import doctest
sys.path.insert(0, os.pardir)
import pytz
return doctest.testmod(pytz)

if __name__ == '__main__':
_test()

all_timezones = \
['Africa/Abidjan',
'Africa/Accra',
Expand Down Expand Up @@ -1086,7 +1073,6 @@ def _test():
'US/Michigan',
'US/Mountain',
'US/Pacific',
'US/Pacific-New',
'US/Samoa',
'UTC',
'Universal',
Expand Down
2 changes: 1 addition & 1 deletion ext/pytz/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
__all__ = [
'UnknownTimeZoneError', 'InvalidTimeError', 'AmbiguousTimeError',
'NonExistentTimeError',
]
]


class UnknownTimeZoneError(KeyError):
Expand Down
1 change: 1 addition & 0 deletions ext/pytz/lazy.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
class LazyDict(DictMixin):
"""Dictionary populated on first use."""
data = None

def __getitem__(self, key):
if self.data is None:
_fill_lock.acquire()
Expand Down
35 changes: 24 additions & 11 deletions ext/pytz/reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,28 @@
'''

from datetime import tzinfo, timedelta, datetime
from pytz import utc, UTC, HOUR, ZERO
from pytz import HOUR, ZERO, UTC

__all__ = [
'FixedOffset',
'LocalTimezone',
'USTimeZone',
'Eastern',
'Central',
'Mountain',
'Pacific',
'UTC'
]


# A class building tzinfo objects for fixed-offset time zones.
# Note that FixedOffset(0, "UTC") is a different way to build a
# UTC tzinfo object.

class FixedOffset(tzinfo):
"""Fixed offset in minutes east from UTC."""

def __init__(self, offset, name):
self.__offset = timedelta(minutes = offset)
self.__offset = timedelta(minutes=offset)
self.__name = name

def utcoffset(self, dt):
Expand All @@ -27,18 +38,19 @@ def tzname(self, dt):
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)
STDOFFSET = timedelta(seconds=-_time.timezone)
if _time.daylight:
DSTOFFSET = timedelta(seconds = -_time.altzone)
DSTOFFSET = timedelta(seconds=-_time.altzone)
else:
DSTOFFSET = STDOFFSET

DSTDIFF = DSTOFFSET - STDOFFSET


# A class capturing the platform's idea of local time.
class LocalTimezone(tzinfo):

def utcoffset(self, dt):
Expand Down Expand Up @@ -66,20 +78,22 @@ def _isdst(self, dt):

Local = LocalTimezone()

# A complete implementation of current DST rules for major US time zones.

def first_sunday_on_or_after(dt):
days_to_go = 6 - dt.weekday()
if days_to_go:
dt += timedelta(days_to_go)
return dt


# In the US, DST starts at 2am (standard time) on the first Sunday in April.
DSTSTART = datetime(1, 4, 1, 2)
# and ends at 2am (DST time; 1am standard time) on the last Sunday of Oct.
# which is the first Sunday on or after Oct 25.
DSTEND = datetime(1, 10, 25, 1)


# A complete implementation of current DST rules for major US time zones.
class USTimeZone(tzinfo):

def __init__(self, hours, reprname, stdname, dstname):
Expand Down Expand Up @@ -120,8 +134,7 @@ def dst(self, dt):
else:
return ZERO

Eastern = USTimeZone(-5, "Eastern", "EST", "EDT")
Central = USTimeZone(-6, "Central", "CST", "CDT")
Eastern = USTimeZone(-5, "Eastern", "EST", "EDT")
Central = USTimeZone(-6, "Central", "CST", "CDT")
Mountain = USTimeZone(-7, "Mountain", "MST", "MDT")
Pacific = USTimeZone(-8, "Pacific", "PST", "PDT")

Pacific = USTimeZone(-8, "Pacific", "PST", "PDT")
Loading