# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

from __future__ import print_function
import sys

from itertools import islice


def chunkify(iterable, n):
    """Split iterable into chunks of length n

    If ``len(iterable) % n != 0``, then the last chunk will have length less than n.

    Example:

    >>> chunkify([1, 2, 3, 4, 5], 2)
    [(1, 2), (3, 4), (5,)]

    :arg iterable: the iterable
    :arg n: the chunk length

    :returns: generator of chunks from the iterable

    """
    iterable = iter(iterable)
    while 1:
        t = tuple(islice(iterable, n))
        if t:
            yield t
        else:
            return


def drop_unicode(text):
    """Takes a text and drops all unicode characters

    :arg str/unicode text: the text to fix

    :returns: text with all unicode characters dropped

    """
    if sys.version_info < (3,):
        if isinstance(text, str):
            # Convert ascii to unicode in python 2
            text = text.decode('unicode_escape')
        # Convert it back to a acsii string and drop any non-ascii characters
        return text.encode('ascii', 'ignore')

    # Python 3 ONLY, python 3 needs unicode string to return
    return text.encode('ascii', 'ignore').decode('unicode_escape')


# utilities

def backoff_seconds_generator():
    seconds = [10, 30, 60, 120, 300]
    for x in seconds:
        yield x
    while True:
        yield seconds[-1]


class DotDict(dict):
    __getattr__ = dict.__getitem__
    __setattr__ = dict.__setitem__
    __delattr__ = dict.__delitem__

@@ -239,18 +239,18 @@
 import s
-ys
+ix
 %0A%0Afrom i
@@ -985,30 +985,14 @@
 if s
-ys.version_info %3C (3,)
+ix.PY2
 :%0A  
@@ -1273,114 +1273,164 @@
 LY, 
-python 3 needs unicode string to return%0A    return text.encode('ascii', 'ignore').decode('unicode_escape')
+strip non ascii characters%0A    ALLOWED_CHARS = %5Bchr(c) for c in range(32, 127)%5D%0A    text = ''.join(%5Bc for c in text if c in ALLOWED_CHARS%5D)%0A%0A    return text
 %0A%0A%0A#

fix bug 1467308 update socorro.lib