# Path: tooz/utils.py
# class Base64LockEncoder(object):
# class ProxyExecutor(object):
# class SerializationError(tooz.ToozError):
#     def __init__(self, keyspace_url, prefix=''):
#     def check_and_encode(self, name):
#     def encode(self, name):
#     def __init__(self, driver_name, default_executor_factory):
#     def build(cls, driver_name, options):
#     def start(self):
#     def stop(self):
#     def submit(self, cb, *args, **kwargs):
# def safe_abs_path(rooted_at, *pieces):
# def convert_blocking(blocking):
# def collapse(config, exclude=None, item_selector=operator.itemgetter(-1)):
# def to_binary(text, encoding='ascii'):
# def dumps(data, excp_cls=SerializationError):
# def loads(blob, excp_cls=SerializationError):
# def millis_to_datetime(milliseconds):
# def raise_with_cause(exc_cls, message, *args, **kwargs):
#     KIND_TO_FACTORY = {
#         'threaded': (lambda:
#                      futurist.ThreadPoolExecutor(max_workers=1)),
#         'synchronous': lambda: futurist.SynchronousExecutor(),
#     }
#     DEFAULT_KIND = 'threaded'


import os
import tempfile
import futurist
import tooz
from testtools import testcase
from tooz import utils

    def test_unsafe_join(self):
        self.assertRaises(ValueError, utils.safe_abs_path,
                          self.base, "../b")
        self.assertRaises(ValueError, utils.safe_abs_path,
                          self.base, "b", 'c', '../../../')


class TestUtilsCollapse(testcase.TestCase):

    def test_bad_type(self):
        self.assertRaises(TypeError, utils.collapse, "")
        self.assertRaises(TypeError, utils.collapse, [])
        self.assertRaises(TypeError, utils.collapse, 2)

    def test_collapse_simple(self):
        ex = {
            'a': [1],
            'b': 2,
            'c': (1, 2, 3),
        }
        c_ex = utils.collapse(ex)
        self.assertEqual({'a': 1, 'c': 3, 'b': 2}, c_ex)

    def test_collapse_exclusions(self):
        ex = {
            'a': [1],
            'b': 2,
            'c': (1, 2, 3),
        }

# Path: tooz/utils.py
# class Base64LockEncoder(object):
# class ProxyExecutor(object):
# class SerializationError(tooz.ToozError):
#     def __init__(self, keyspace_url, prefix=''):
#     def check_and_encode(self, name):
#     def encode(self, name):
#     def __init__(self, driver_name, default_executor_factory):
#     def build(cls, driver_name, options):
#     def start(self):
#     def stop(self):
#     def submit(self, cb, *args, **kwargs):
# def safe_abs_path(rooted_at, *pieces):
# def convert_blocking(blocking):
# def collapse(config, exclude=None, item_selector=operator.itemgetter(-1)):
# def to_binary(text, encoding='ascii'):
# def dumps(data, excp_cls=SerializationError):
# def loads(blob, excp_cls=SerializationError):
# def millis_to_datetime(milliseconds):
# def raise_with_cause(exc_cls, message, *args, **kwargs):
#     KIND_TO_FACTORY = {
#         'threaded': (lambda:
#                      futurist.ThreadPoolExecutor(max_workers=1)),
#         'synchronous': lambda: futurist.SynchronousExecutor(),
#     }
#     DEFAULT_KIND = 'threaded'


# Path: tooz/tests/test_utils.py
import os
import tempfile
import futurist
import tooz
from testtools import testcase
from tooz import utils


    def test_unsafe_join(self):
        self.assertRaises(ValueError, utils.safe_abs_path,
                          self.base, "../b")
        self.assertRaises(ValueError, utils.safe_abs_path,
                          self.base, "b", 'c', '../../../')


class TestUtilsCollapse(testcase.TestCase):

    def test_bad_type(self):
        self.assertRaises(TypeError, utils.collapse, "")
        self.assertRaises(TypeError, utils.collapse, [])
        self.assertRaises(TypeError, utils.collapse, 2)

    def test_collapse_simple(self):
        ex = {
            'a': [1],
            'b': 2,
            'c': (1, 2, 3),
        }
        c_ex = utils.collapse(ex)
        self.assertEqual({'a': 1, 'c': 3, 'b': 2}, c_ex)

    def test_collapse_exclusions(self):
        ex = {
            'a': [1],
            'b': 2,
            'c': (1, 2, 3),
        }

        c_ex = utils.collapse(ex, exclude=['a'])