Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add fallback function for itertools.izip_longest for python 2.5 compat

  • Loading branch information...
commit 2f755996cc4b6baf2fd1eeb639a7655f0741bb8f 1 parent 4388b57
@olt olt authored
View
6 COPYING.txt
@@ -49,6 +49,12 @@ mapproxy/util/ext/dictspec/*.py
(c) 2011 by Oliver Tonnhofer, Omniscale.
MIT license.
+mapproxy/util/ext/itertools.py
+------------------------------
+# Copyright © 2001-2012 Python Software Foundation; All Rights Reserved
+# http://docs.python.org/library/itertools.html#itertools.izip_longest
+PSF license.
+
mapproxy/test/schemas/*
-----------------------
Copyright (c) 1994 - 2010 Open Geospatial Consortium, Inc
View
2  mapproxy/seed/seeder.py
@@ -16,12 +16,12 @@
from __future__ import with_statement, division
import sys
from contextlib import contextmanager
-from itertools import izip_longest
from mapproxy.config import base_config
from mapproxy.grid import MetaGrid
from mapproxy.source import SourceError
from mapproxy.util import local_base_config
+from mapproxy.util.ext.itertools import izip_longest
from mapproxy.util.lock import LockTimeout
from mapproxy.seed.util import format_seed_task
from mapproxy.seed.cachelock import DummyCacheLocker, CacheLockedError
View
29 mapproxy/util/ext/itertools.py
@@ -0,0 +1,29 @@
+# missing izip_longest function for Python 2.5 compatibility
+# http://docs.python.org/library/itertools.html#itertools.izip_longest
+# Copyright 2001-2012 Python Software Foundation; All Rights Reserved
+
+from __future__ import absolute_import
+import itertools
+
+if hasattr(itertools, 'izip_longest'):
+ izip_longest = itertools.izip_longest
+else:
+ class ZipExhausted(Exception):
+ pass
+
+ def izip_longest(*args, **kwds):
+ # izip_longest('ABCD', 'xy', fillvalue='-') --> Ax By C- D-
+ fillvalue = kwds.get('fillvalue')
+ counter = [len(args) - 1]
+ def sentinel():
+ if not counter[0]:
+ raise ZipExhausted
+ counter[0] -= 1
+ yield fillvalue
+ fillers = itertools.repeat(fillvalue)
+ iterators = [itertools.chain(it, sentinel(), fillers) for it in args]
+ try:
+ while iterators:
+ yield tuple(i.next() for i in iterators)
+ except ZipExhausted:
+ pass
View
5 mapproxy/util/ext/odict.py
@@ -106,6 +106,7 @@ def __setitem__(self, key, value):
:copyright: (c) 2008 by Armin Ronacher and PEP 273 authors.
:license: modified BSD license.
"""
+from __future__ import absolute_import
from itertools import izip, imap
from copy import deepcopy
@@ -130,7 +131,7 @@ class odict(dict):
>>> d.update({'foo': 'bar'})
>>> d
odict.odict([('a', 'b'), ('c', 'd'), ('foo', 'bar')])
-
+
Keep in mind that when updating from dict-literals the order is not
preserved as these dicts are unsorted!
@@ -179,7 +180,7 @@ class odict(dict):
>>> d.reverse()
>>> d
odict.odict([('spam', []), ('foo', 'bar'), ('c', 'd'), ('a', 'b')])
-
+
And sort it like a list:
>>> d.sort(key=lambda x: x[0].lower())
Please sign in to comment.
Something went wrong with that request. Please try again.