Commits

Lynn Rees committed d27ad5a

- fix mro

Comments (0)

Files changed (8)

twoq/active/mixins.py

         try:
             incoming = deque(things[0]) if len(things) == 1 else deque(things)
         except TypeError:
-            incoming = deque(iter([things]))
+            incoming = deque()
+            incoming.extend(things)
         super(BaseMixin, self).__init__(incoming, deque())
         # set iterator
         self._iterator = self._iterexcept
         length = len(dq)
         call = dq.popleft
         for i in repeat(None, length):  # @UnusedVariable
-            try:
-                yield call()
-            except IndexError:
-                pass
+            yield call()
 
     def _iterexcept(self, attr='_UTILQ'):
         '''
 from contextlib import contextmanager
 
 from stuf.utils import OrderedDict
-from stuf.six import binaries, texts, b, u
 from stuf.core import stuf, frozenstuf, orderedstuf
 
-from twoq.support import n2u, n2b
-
 SLOTS = [
     '_work', 'outgoing', '_util', 'incoming', '_call', '_alt', '_wrapper',
     '_args', '_kw', '_clearout', '_context', '_CONFIG', '_INQ', '_WORKQ',
         if not index:
             self.incoming = self._savepoints.pop()
         else:
-            self._savepoints.reverse()
-            self.incoming = self._savepoints[index]
-            self._savepoints.reverse()
+            self.incoming = deque(reversed(self._savepoints))[index]
         return self._savepoint()
 
     ###########################################################################
         '''set wrapper to `set`'''
         return self.wrap(set)
 
-    def byte_wrap(self, encoding='ISO-8859-1', join=b('')):
-        '''set wrapper to `bytes` with given `encoding`'''
-        return self.wrap(lambda x: n2b(
-            join.join(binaries(i) for i in x), encoding)
-        )
-
     def deque_wrap(self):
         '''set wrapper to `deque`'''
         return self.wrap(deque)
         '''set wrapper to `stuf`'''
         return self.wrap(stuf)
 
-    def unicode_wrap(self, encoding='utf-8', join=u('')):
-        '''set wrapper to `unicode` with given `encoding`'''
-        return self.wrap(
-            lambda x: n2u(join.join(texts(i) for i in x), encoding)
-        )
-
     def list_wrap(self):
         '''clear current wrapper'''
         return self.wrap(list)

twoq/filtering.py

     def mro(self):
         '''extract ancestors of things by method resolution order'''
         with self._context():
-            return self._xtend(getmro(i) for i in self._iterable)
+            return self._xtend(ichain(getmro(i) for i in self._iterable))
 
     def pick(self, *names):
         '''collect object attributes from incoming things by their `*names`'''
     map, filterfalse, filter, zip, zip_longest, xrange)  # @UnresolvedImport @UnusedImport @IgnorePep8
 # pylint: enable-msg=f0401
 
-__all__ = ['port']
 items = six.items
 ichain = chain.from_iterable
 range = xrange
                 self_get = self.get
                 for elem in iterable:
                     self[elem] = self_get(elem, 0) + 1
-
-
-if six.PY3:
-
-    def n2b(n, encoding='ISO-8859-1'):
-        '''
-        the given native string as a byte string in the given encoding
-        '''
-        # In Python 3, the native string type is unicode
-        return n.encode(encoding)
-
-    def n2u(n, encoding='ISO-8859-1'):
-        '''
-        the given native string as a unicode string with the given encoding
-        '''
-        # In Python 3, the native string type is unicode
-        return n
-
-    def ton(n, encoding='ISO-8859-1'):
-        '''
-        the given string as a native string in the given encoding
-        '''
-        # In Python 3, the native string type is unicode
-        if isinstance(n, bytes):
-            return n.decode(encoding)
-        return n
-else:
-    import re
-
-    def n2b(n, encoding='ISO-8859-1'):
-        '''the given native string as a byte string in the given encoding'''
-        # In Python 2, the native string type is bytes. Assume it's already
-        # in the given encoding, which for ISO-8859-1 is almost always what
-        # was intended.
-        return n
-
-    def n2u(n, encoding='ISO-8859-1'):
-        '''
-        the given native string as a unicode string with the given encoding
-        '''
-        # In Python 2, the native string type is bytes.
-        # First, check for the special encoding 'escape'. The test suite uses
-        # this
-        # to signal that it wants to pass a string with embedded \unnnn
-        # escapes, but without having to prefix it with u'' for Python 2, but
-        # no prefix for Python 3.
-        if encoding == 'escape':
-            return unicode(re.sub(
-                r'\\u([0-9a-zA-Z]{4})',
-               lambda m: unichr(int(m.group(1), 16)),
-               n.decode('ISO-8859-1')
-            ))
-        # assume it's already in the given encoding, which for ISO-8859-1 is
-        # almost always what was intended.
-        return n.decode(encoding)
-
-    def ton(n, encoding='ISO-8859-1'):
-        '''return the given string as a native string in the given encoding'''
-        # in Python 2, the native string type is bytes.
-        if isinstance(n, unicode):
-            return n.encode(encoding)
-        return n

twoq/tests/auto/filtering.py

         test = lambda x: not x[0].startswith('__')
         value = self.qclass(
             stoog3
-        ).tap(test, isclass).tuple_wrap().mro().members().untap().end(),
+        ).tap(test, isclass).tuple_wrap().mro().members().untap().end()
         self.assertEqual(
             value,
-            ((('age', 40), ('name', 'moe'), ('age', 50), ('name', 'larry'),
-            ('age', 60), ('name', 'curly'), ('stoog4', (('age', 969),
-            ('name', 'beastly')))),),
+            (('age', 60), ('name', 'curly'), ('age', 50), ('name', 'larry'),
+            ('age', 40), ('name', 'moe')),
             value,
         )
 

twoq/tests/auto/queuing.py

             [1, 2, 3, 4, 5, 6],
         )
 
-    def test_unicode_wrap(self):
-        from stuf.six import texts, u
-        self.assertIsInstance(
-            self.qclass(1, 2, 3, 4, 5, 6).unicode_wrap().syncout().value(),
-            texts,
-        )
-        self.assertEqual(
-            self.qclass(1, 2, 3, 4, 5, 6).unicode_wrap().syncout().value(),
-            u('123456'),
-        )
-
-    def test_byte_wrap(self):
-        from stuf.six import binaries, b
-        self.assertIsInstance(
-            self.qclass(1, 2, 3, 4, 5, 6).byte_wrap().syncout().value(),
-            binaries,
-        )
-        self.assertEqual(
-            self.qclass(1, 2, 3, 4, 5, 6).byte_wrap().syncout().value(),
-            b('123456'),
-        )
-
     def test_tuple_wrap(self):
         self.assertIsInstance(
             self.qclass(1, 2, 3, 4, 5, 6).tuple_wrap().syncout().value(),

twoq/tests/man/filtering.py

         self._true_true_false(
             self.qclass(stoog3).tap(
                 lambda x: x, isclass
-            ).tuple_wrap().mro().members().untap().sync(),
+            ).tuple_wrap().mro().sync().members().untap().sync(),
             self.assertEqual,
-            (('age', 60), ('name', 'curly'))
+            (('age', 60), ('name', 'curly'), ('age', 50), ('name', 'larry'),
+            ('age', 40), ('name', 'moe'))
         )
 
     def test_pick(self):

twoq/tests/man/queuing.py

             [1, 2, 3, 4, 5, 6]
         )
 
-    def test_unicode_wrap(self):
-        from stuf.six import texts, u
-        self.assertIsInstance(
-            self.qclass(1, 2, 3, 4, 5, 6).unicode_wrap().syncout().value(),
-            texts,
-        )
-        self.assertEqual(
-            self.qclass(1, 2, 3, 4, 5, 6).unicode_wrap().syncout().value(),
-            u('123456'),
-        )
-
-    def test_byte_wrap(self):
-        from stuf.six import binaries, b
-        self.assertIsInstance(
-            self.qclass(1, 2, 3, 4, 5, 6).byte_wrap().syncout().value(),
-            binaries,
-        )
-        self.assertEqual(
-            self.qclass(1, 2, 3, 4, 5, 6).byte_wrap().syncout().value(),
-            b('123456'),
-        )
-
     def test_tuple_wrap(self):
         self.assertIsInstance(
             self.qclass(1, 2, 3, 4, 5, 6).tuple_wrap().syncout().value(),