mirror of
https://github.com/kennethreitz/maya.git
synced 2026-06-05 23:00:18 +00:00
adapt compat.py style to the one from requests
This commit is contained in:
@@ -6,16 +6,30 @@ maya.compat
|
||||
This module handles import compatibility issues between Python 2 and
|
||||
Python 3.
|
||||
"""
|
||||
|
||||
import sys
|
||||
|
||||
if sys.version_info < (3, 0):
|
||||
_PY3 = False
|
||||
else:
|
||||
_PY3 = True
|
||||
# -------
|
||||
# Pythons
|
||||
# -------
|
||||
|
||||
try:
|
||||
# Syntax sugar.
|
||||
_ver = sys.version_info
|
||||
|
||||
#: Python 2.x?
|
||||
is_py2 = (_ver[0] == 2)
|
||||
|
||||
#: Python 3.x?
|
||||
is_py3 = (_ver[0] == 3)
|
||||
|
||||
# ---------
|
||||
# Specifics
|
||||
# ---------
|
||||
|
||||
if is_py2:
|
||||
cmp = cmp
|
||||
except NameError:
|
||||
|
||||
elif is_py3:
|
||||
def cmp(a, b):
|
||||
"""
|
||||
Compare two objects.
|
||||
@@ -38,7 +52,7 @@ def comparable(klass):
|
||||
relying on C{__cmp__} to implement their comparisons.
|
||||
"""
|
||||
# On Python 2, __cmp__ will just work, so no need to add extra methods:
|
||||
if not _PY3:
|
||||
if not is_py3:
|
||||
return klass
|
||||
|
||||
def __eq__(self, other):
|
||||
|
||||
@@ -12,6 +12,7 @@ import email.utils
|
||||
import time
|
||||
from datetime import timedelta, datetime as Datetime
|
||||
|
||||
import functools
|
||||
import pytz
|
||||
import humanize
|
||||
import dateparser
|
||||
@@ -506,7 +507,7 @@ class MayaInterval(object):
|
||||
|
||||
@staticmethod
|
||||
def flatten(ii):
|
||||
return reduce(lambda reduced, i: (
|
||||
return functools.reduce(lambda reduced, i: (
|
||||
(reduced[:-1] + i.combine(reduced[-1]))
|
||||
if reduced else [i]
|
||||
), sorted(ii), [])
|
||||
|
||||
Reference in New Issue
Block a user