1212
1313import sys
1414import subprocess
15- from math import ceil
15+ from math import ceil as oldceil
1616from collections import MutableMapping
1717
1818from future .utils import iteritems , itervalues , PY26 , PY3
1919
2020
21- def _ceil (x ):
21+ def ceil (x ):
2222 """
2323 Return the ceiling of x as an int.
2424 This is the smallest integral value >= x.
2525 """
26- return int (ceil (x ))
26+ return int (oldceil (x ))
2727
2828
2929# OrderedDict Shim from Raymond Hettinger, python core dev
@@ -43,7 +43,7 @@ def _ceil(x):
4343 pass
4444
4545
46- class _OrderedDict (dict ):
46+ class OrderedDict (dict ):
4747
4848 'Dictionary that remembers insertion order'
4949 # An inherited dict maps keys to values.
@@ -305,13 +305,13 @@ def viewitems(self):
305305### Counter
306306########################################################################
307307
308- def __count_elements (mapping , iterable ):
308+ def _count_elements (mapping , iterable ):
309309 'Tally elements from the iterable.'
310310 mapping_get = mapping .get
311311 for elem in iterable :
312312 mapping [elem ] = mapping_get (elem , 0 ) + 1
313313
314- class _Counter (dict ):
314+ class Counter (dict ):
315315
316316 '''Dict subclass for counting hashable objects. Sometimes called a bag
317317 or multiset. Elements are stored as dictionary keys and their counts
@@ -496,7 +496,7 @@ def __and__(self, other):
496496 return result
497497
498498
499- def _check_output (* popenargs , ** kwargs ):
499+ def check_output (* popenargs , ** kwargs ):
500500 """
501501 For Python 2.6 compatibility: see
502502 http://stackoverflow.com/questions/4814970/
@@ -515,7 +515,7 @@ def _check_output(*popenargs, **kwargs):
515515 return output
516516
517517
518- def _count (start = 0 , step = 1 ):
518+ def count (start = 0 , step = 1 ):
519519 """
520520 ``itertools.count`` in Py 2.6 doesn't accept a step
521521 parameter. This is an enhanced version of ``itertools.count``
@@ -536,7 +536,7 @@ def _count(start=0, step=1):
536536except ImportError :
537537 from _dummy_thread import get_ident
538538
539- def _recursive_repr (fillvalue = '...' ):
539+ def recursive_repr (fillvalue = '...' ):
540540 'Decorator to make a repr function return fillvalue for a recursive call'
541541
542542 def decorating_function (user_function ):
@@ -569,7 +569,7 @@ def wrapper(self):
569569### https://github.com/kkxue/Py2ChainMap/blob/master/py2chainmap.py
570570########################################################################
571571
572- class _ChainMap (MutableMapping ):
572+ class ChainMap (MutableMapping ):
573573 ''' A ChainMap groups multiple dicts (or other mappings) together
574574 to create a single, updateable view.
575575
@@ -618,7 +618,7 @@ def __bool__(self):
618618 # Py2 compatibility:
619619 __nonzero__ = __bool__
620620
621- @_recursive_repr ()
621+ @recursive_repr ()
622622 def __repr__ (self ):
623623 return '{0.__class__.__name__}({1})' .format (
624624 self , ', ' .join (map (repr , self .maps )))
@@ -676,26 +676,27 @@ def clear(self):
676676 self .maps [0 ].clear ()
677677
678678
679- if sys .version_info < (2 , 7 ):
680- OrderedDict = _OrderedDict
681- Counter = _Counter
682- check_output = _check_output
683- count = _count
684- else :
679+ # Back up our definitions above in case they're useful
680+ _OrderedDict = OrderedDict
681+ _Counter = Counter
682+ _check_output = check_output
683+ _count = count
684+ _ceil = ceil
685+ __count_elements = _count_elements
686+ _recursive_repr = recursive_repr
687+ _ChainMap = ChainMap
688+
689+ # Overwrite the definitions above with the usual ones
690+ # from the standard library:
691+ if sys .version_info >= (2 , 7 ):
685692 from collections import OrderedDict , Counter
686693 from subprocess import check_output
687694 from itertools import count
688695
689- if sys .version_info < (3 , 0 ):
690- ceil = _ceil
691- _count_elements = __count_elements
692- else :
696+ if sys .version_info >= (3 , 0 ):
693697 from math import ceil
694698 from collections import _count_elements
695699
696- if sys .version_info < (3 , 3 ):
697- recursive_repr = _recursive_repr
698- ChainMap = _ChainMap
699- else :
700+ if sys .version_info >= (3 , 3 ):
700701 from reprlib import recursive_repr
701702 from collections import ChainMap
0 commit comments