Lynn Rees avatar Lynn Rees committed fe5c2f2

- refactoring

Comments (0)

Files changed (25)

-twoq
-twoq.active
-twoq.lazy
+thingq
+thingq.active
+thingq.lazy

thingq/active/core.py

 # -*- coding: utf-8 -*-
 '''thingq active queues'''
 
-from thingq.core import SLOTS
+from thingq.mixins import SLOTS
 from thingq.mapping import MappingMixin as MapMixin
 from thingq.ordering import OrderingMixin as OrderMixin
 from thingq.reducing import ReducingMixin as ReduceMixin

thingq/active/filtering.py

 # -*- coding: utf-8 -*-
 '''thingq active filtering queues'''
 
-from thingq.core import SLOTS
+from thingq.mixins import SLOTS
 from thingq.filtering import (
     FilteringMixin, CollectMixin, SetMixin, SliceMixin)
 

thingq/active/mapping.py

 # -*- coding: utf-8 -*-
 '''thingq active mapping queues'''
 
-from thingq.core import SLOTS
+from thingq.mixins import SLOTS
 from thingq.mapping import DelayMixin, RepeatMixin, MappingMixin
 
 from thingq.active.mixins import AutoResultMixin, ManResultMixin

thingq/active/mixins.py

 
 from stuf.utils import clsname
 
-from thingq.core import ThingsMixin, ResultsMixin
+from thingq.mixins import ThingsMixin, ResultsMixin
 
 
 class BaseMixin(ThingsMixin):
     ## know things ############################################################
     ###########################################################################
 
-    def __len__(self):
-        '''number of incoming things'''
-        return len(self.incoming)
-
     def __repr__(self):
         getr_, list_ = lambda x: getattr(self, x), list
         return self._repr(
             id(self),
         )
 
+    def __len__(self):
+        '''number of incoming things'''
+        return len(self.incoming)
+    
+    count = __len__
+
     def countout(self):
         '''number of outgoing things'''
         return len(self.outgoing)
     '''result things mixin'''
 
     def end(self):
-        '''return outgoing things then clear out everything'''
+        '''return outgoing things then clear wrap everything'''
         # return to default context
         self.unswap()
         wrap, outgoing = self._wrapper, self.outgoing
-        out = self.outgoing.pop() if len(outgoing) == 1 else wrap(outgoing)
+        wrap = self.outgoing.pop() if len(outgoing) == 1 else wrap(outgoing)
         # clear every last thing
         self.clear()._clearsp()
-        return out
+        return wrap
 
     def snapshot(self):
         '''snapshot of current outgoing things'''
-        out = copy(getattr(self, self._OUTQ))
-        return out.pop() if len(out) == 1 else self._wrapper(out)
+        wrap = copy(getattr(self, self._OUTQ))
+        return wrap.pop() if len(wrap) == 1 else self._wrapper(wrap)
 
-    def value(self):
+    def out(self):
         '''return outgoing things and clear outgoing things'''
         # return to default context
         self.unswap()
         wrap, outgoing = self._wrapper, self.outgoing
-        out = self.outgoing.pop() if len(outgoing) == 1 else wrap(outgoing)
+        wrap = self.outgoing.pop() if len(outgoing) == 1 else wrap(outgoing)
         # clear outgoing things
         self.clearout()
-        return out
+        return wrap
 
 
 class AutoResultMixin(AutoMixin, EndMixin):

thingq/active/ordering.py

 # -*- coding: utf-8 -*-
 '''thingq active ordering queues'''
 
-from thingq.core import SLOTS
+from thingq.mixins import SLOTS
 from thingq.ordering import RandomMixin, OrderingMixin
 
 from thingq.active.mixins import AutoResultMixin, ManResultMixin

thingq/active/reducing.py

 # -*- coding: utf-8 -*-
 '''thingq active reducing queues'''
 
-from thingq.core import SLOTS
+from thingq.mixins import SLOTS
 from thingq.reducing import MathMixin, TruthMixin, ReducingMixin
 
 from thingq.active.mixins import AutoResultMixin, ManResultMixin

thingq/core.py

-# -*- coding: utf-8 -*-
-'''thingq queuing mixins'''
-
-from threading import local
-from collections import deque
-from contextlib import contextmanager
-
-from stuf.utils import OrderedDict
-from stuf.core import stuf, frozenstuf, orderedstuf
-
-SLOTS = [
-    '_work', 'outgoing', '_util', 'incoming', '_call', '_alt', '_wrapper',
-    '_args', '_kw', '_clearout', '_context', '_CONFIG', '_INQ', '_WORKQ',
-    '_UTILQ', '_OUTQ', '_iterator', 'current_mode', '_savepoints', '_start',
-]
-
-
-class ThingsMixin(local):
-
-    '''things management mixin'''
-
-    def __init__(self, incoming, outgoing, **kw):
-        '''
-        init
-
-        @param incoming: incoming things
-        @param outgoing: outgoing things
-        '''
-        super(ThingsMixin, self).__init__()
-        # incoming things
-        self.incoming = incoming
-        # outgoing things
-        self.outgoing = outgoing
-        # preferred mode
-        self.current_mode = self._RW
-        #######################################################################
-        ## context defaults ###################################################
-        #######################################################################
-        # preferred context
-        self._context = getattr(self, self._DEFAULT_CONTEXT)
-        # default context settings
-        self._CONFIG = {}
-        # 1. default incoming things
-        self._INQ = self._INVAR
-        # 2. default work things
-        self._WORKQ = self._WORKVAR
-        # 3. default utility things
-        self._UTILQ = self._UTILVAR
-        # 4. default outgoing things
-        self._OUTQ = self._OUTVAR
-        # clear outgoing things before extending/appending to them?
-        self._clearout = True
-        #######################################################################
-        ## snapshotting defaults ##############################################
-        #######################################################################
-        # number of savepoints to keep (default: 5)
-        maxlen = kw.pop('savepoints', 5)
-        # create stack for savepoint things
-        self._savepoints = deque(maxlen=maxlen) if maxlen is not None else None
-        # savepoint of original incoming things
-        if self._savepoints is not None:
-            self._original()
-        #######################################################################
-        ## callable defaults ##################################################
-        #######################################################################
-        # current callable (default: identity)
-        self._call = lambda x: x
-        # current alternate callable (default: identity)
-        self._alt = lambda x: x
-        # iterable export wrapper (default: `list`)
-        self._wrapper = list
-        # postition arguments (default: `tuple`)
-        self._args = ()
-        # keyword arguments (default: `dict`)
-        self._kw = {}
-
-    ###########################################################################
-    ## mode things ############################################################
-    ###########################################################################
-
-    # read/write mode
-    _RW = 'read/write'
-    # read-only mode
-    _RO = 'read-only'
-
-    def rw(self):
-        '''switch to read/write mode'''
-        self.current_mode = self._RW
-        return self._clearu().unswap()
-
-    ###########################################################################
-    ## context things #EE######################################################
-    ###########################################################################
-
-    # 1. incoming things
-    _INCFG = 'inq'
-    _INVAR = 'incoming'
-    # 2. utility things
-    _UTILCFG = 'utilq'
-    _UTILVAR = '_util'
-    # 3. work things
-    _WORKCFG = 'workq'
-    _WORKVAR = '_work'
-    # 4. outgoing things
-    _OUTCFG = 'outq'
-    _OUTVAR = 'outgoing'
-
-    def swap(self, **kw):
-        '''swap context'''
-        # savepoint
-        savepoint = kw.pop('savepoint', True)
-        if savepoint:
-            self._savepoint()
-        # keep context-specific settings between context swaps
-        self._CONFIG = kw if kw.get('hard', False) else {}
-        # set context
-        self._context = kw.get('context', getattr(self, self._DEFAULT_CONTEXT))
-        # clear out outgoing things before extending them?
-        self._clearout = kw.get('clearout', True)
-        # 1. incoming things
-        self._INQ = kw.get(self._INCFG, self._INVAR)
-        # 2. work things
-        self._WORKQ = kw.get(self._WORKCFG, self._WORKVAR)
-        # 3. utility things
-        self._UTILQ = kw.get(self._UTILCFG, self._UTILVAR)
-        # 4. outgoing things
-        self._OUTQ = kw.get(self._OUTCFG, self._OUTVAR)
-        return self
-
-    def reswap(self):
-        '''swap for preferred context'''
-        return self.swap(savepoint=False, **self._CONFIG)
-
-    def unswap(self):
-        '''swap for current default context'''
-        return self.swap(savepoint=False)
-
-    @contextmanager
-    def ctx1(self, **kw):
-        '''swap for one-armed context'''
-        q = kw.pop(self._WORKCFG, self._INVAR)
-        self.swap(workq=q, utilq=q, context=self.ctx1, **kw)
-        yield
-        self.reswap()
-
-    ###########################################################################
-    ## savepoint for things ##################################################
-    ###########################################################################
-
-    def _original(self):
-        '''preserve original incoming things'''
-        self._savepoint()
-        # preserve from savepoint stack
-        self._start = self._savepoints.pop()
-        return self
-
-    def undo(self, index=0, everything=False):
-        '''
-        revert to previous savepoint
-
-        @param index: index of savepoint (default: 0)
-        @param everything: undo everything and return things to original state
-        '''
-        if everything:
-            self.clear()._clearsp()
-            self.incoming = self._start
-            self._original()
-            return self
-        self.clear()
-        if not index:
-            self.incoming = self._savepoints.pop()
-        else:
-            self.incoming = deque(reversed(self._savepoints))[index]
-        return self._savepoint()
-
-    ###########################################################################
-    ## rotate things ##########################################################
-    ###########################################################################
-
-    def reup(self):
-        '''put incoming things in incoming things as one incoming thing'''
-        with self.ctx2(savepoint=False):
-            return self._append(list(self._iterable))
-
-    def sync(self):
-        '''shift outgoing things to incoming things'''
-        with self.autoctx(inq=self._OUTVAR, outq=self._INVAR, savepoint=False):
-            return self._xtend(self._iterable)
-
-    def syncout(self):
-        '''shift incoming things to outgoing things'''
-        with self.autoctx(savepoint=False):
-            return self._xtend(self._iterable)
-
-    ###########################################################################
-    ## extend incoming things #################################################
-    ###########################################################################
-
-    def extend(self, things):
-        '''
-        extend after incoming things
-
-        @param thing: some things
-        '''
-        with self.ctx1():
-            return self._xtend(things)
-
-    def extendleft(self, things):
-        '''
-        extend before incoming things
-
-        @param thing: some things
-        '''
-        with self.ctx1():
-            return self._xtendleft(things)
-
-    def outextend(self, things):
-        '''
-        extend right side of outgoing things
-
-        @param thing: some things
-        '''
-        with self.ctx1(workq=self._OUTVAR):
-            return self._xtend(things)
-
-    ###########################################################################
-    ## append incoming things #################################################
-    ###########################################################################
-
-    def append(self, thing):
-        '''
-        append after incoming things
-
-        @param thing: some thing
-        '''
-        with self.ctx1():
-            return self._append(thing)
-
-    def prepend(self, thing):
-        '''
-        append before incoming things
-
-        @param thing: some thing
-        '''
-        with self.ctx1():
-            return self._appendleft(thing)
-
-    ###########################################################################
-    ## call things ############################################################
-    ###########################################################################
-
-    def args(self, *args, **kw):
-        '''set arguments for current or alternative callable'''
-        # set position arguments
-        self._args = args
-        # set keyword arguemnts
-        self._kw = kw
-        return self
-
-    def tap(self, call, alt=None, factory=False):
-        '''
-        set current callable
-
-        @param call: a callable
-        @param alt: an alternative callable (default: None)
-        @param factor: call is a factory? (default: False)
-        '''
-        # reset postition arguments
-        self._args = ()
-        # reset keyword arguments
-        self._kw = {}
-        # set factory for building current callable
-        if factory:
-            def factory(*args, **kw):
-                return call(*args, **kw)
-            self._call = factory
-        else:
-            # set current callable
-            self._call = call
-        # set alternative callable
-        self._alt = alt if alt is not None else lambda x: x
-        return self
-
-    def untap(self):
-        '''clear current callable'''
-        # reset postition arguments
-        self._args = ()
-        # reset keyword arguments
-        self._kw = {}
-        # reset current callable (default is identity)
-        self._call = lambda x: x
-        # reset alternative callable
-        self._alt = lambda x: x
-        return self
-
-    ###########################################################################
-    ## know things ############################################################
-    ###########################################################################
-
-    @staticmethod
-    def _repr(*args):
-        '''queue representation'''
-        return (
-            '<{0}.{1}<<{2}>>([IN: {3}({4}) => WORK: {5}({6}) => UTIL: {7}({8})'
-            ' => OUT: {9}: ({10})]) at {11}>'
-        ).format(*args)
-
-    @property
-    def balanced(self):
-        '''queues are balanced?'''
-        return self.countout() == self.__len__()
-
-    ###########################################################################
-    ## clear things ###########################################################
-    ###########################################################################
-
-    def _clearsp(self):
-        '''clear savepoints'''
-        self._savepoints.clear()
-        return self
-
-    def clear(self):
-        '''clear anything'''
-        return self.untap().unwrap().clearout().clearin()._clearw()._clearu()
-
-
-class ResultsMixin(local):
-
-    '''result of things mixin'''
-
-    ###########################################################################
-    ## outgoing things export #################################################
-    ###########################################################################
-
-    def peek(self):
-        '''results from read-only context'''
-        self.ro()
-        out = self._wrapper(self._util)
-        results = out[0] if len(out) == 1 else out
-        self.rw()
-        return results
-
-    def results(self):
-        '''yield outgoing things, clearing outgoing things as it iterates'''
-        return self.__iter__()
-
-    ###########################################################################
-    ## wrap outgoing things ###################################################
-    ###########################################################################
-
-    def wrap(self, wrapper):
-        '''
-        wrapper for outgoing things
-
-        @param wrapper: an iterator class
-        '''
-        self._wrapper = wrapper
-        return self
-
-    def tuple_wrap(self):
-        '''set wrapper to `tuple`'''
-        return self.wrap(tuple)
-
-    def set_wrap(self):
-        '''set wrapper to `set`'''
-        return self.wrap(set)
-
-    def deque_wrap(self):
-        '''set wrapper to `deque`'''
-        return self.wrap(deque)
-
-    def dict_wrap(self):
-        '''set wrapper to `dict`'''
-        return self.wrap(dict)
-
-    def frozenset_wrap(self):
-        '''set wrapper to `frozenset`'''
-        return self.wrap(frozenset)
-
-    def frozenstuf_wrap(self):
-        '''set wrapper to `frozenstuf`'''
-        return self.wrap(frozenstuf)
-
-    def ordereddict_wrap(self):
-        '''set wrapper to `OrderedDict`'''
-        return self.wrap(OrderedDict)
-
-    def orderedstuf_wrap(self):
-        '''set wrapper to `orderedstuf`'''
-        return self.wrap(orderedstuf)
-
-    def stuf_wrap(self):
-        '''set wrapper to `stuf`'''
-        return self.wrap(stuf)
-
-    def list_wrap(self):
-        '''clear current wrapper'''
-        return self.wrap(list)
-
-    unwrap = list_wrap

thingq/lazy/core.py

 # -*- coding: utf-8 -*-
 '''thingq lazy queues'''
 
-from thingq.core import SLOTS
+from thingq.mixins import SLOTS
 from thingq.mapping import MappingMixin as MapMixin
 from thingq.ordering import OrderingMixin as OrderMixin
 from thingq.reducing import ReducingMixin as ReduceMixin

thingq/lazy/filtering.py

 # -*- coding: utf-8 -*-
 '''thingq lazy filtering queues'''
 
-from thingq.core import SLOTS
+from thingq.mixins import SLOTS
 from thingq.filtering import (
     FilteringMixin, CollectMixin, SetMixin, SliceMixin)
 

thingq/lazy/mapping.py

 # -*- coding: utf-8 -*-
 '''thingq lazy mapping queues'''
 
-from thingq.core import SLOTS
+from thingq.mixins import SLOTS
 from thingq.mapping import DelayMixin, RepeatMixin, MappingMixin
 
 from thingq.lazy.mixins import AutoResultMixin, ManResultMixin

thingq/lazy/mixins.py

 
 from stuf.utils import clsname
 
-from thingq.core import ResultsMixin, ThingsMixin
+from thingq.mixins import ResultsMixin, ThingsMixin
 
 
 class BaseMixin(ThingsMixin):
         getr_ = lambda x: getattr(self, x)
         OUTQ = self._OUTQ
         # extend work things with outgoing things
-        work, out = tee(getr_(OUTQ))
+        work, wrap = tee(getr_(OUTQ))
         setr_(self._WORKQ, work)
-        setr_(OUTQ, out)
+        setr_(OUTQ, wrap)
         yield
         # extend outgoing things with utility things
         util = getr_(self._UTILQ)
         setr_(INQ, inq)
         yield
         # extend incoming things and outgoing things with utility things
-        inq, out = tee(getr_(self._UTILQ))
+        inq, wrap = tee(getr_(self._UTILQ))
         setr_(
             self._OUTQ,
-            out if self._clearout else chain(out, getr_(self._OUTQ)),
+            wrap if self._clearout else chain(wrap, getr_(self._OUTQ)),
         )
         setr_(INQ, inq)
         self._clearworking()
         '''number of incoming things'''
         self.incoming, incoming = tee(self.incoming)
         return len(list(incoming))
+    
+    count = __len__
 
     def countout(self):
         '''number of outgoing things'''
         self.unswap()
         out, tell = tee(self.outgoing)
         wrap = self._wrapper
-        out = next(out) if len(wrap(tell)) == 1 else wrap(out)
+        wrap = next(out) if len(wrap(tell)) == 1 else wrap(out)
         # clear every last thing
         self.clear()
-        return out
+        return wrap
 
     def snapshot(self):
-        '''snapshot of current outgoing things'''
+        '''snapshot of outgoing things'''
         out, tell, self.outgoing = tee(getattr(self, self._OUTQ), 3)
         wrap = self._wrapper
         return out.pop() if len(wrap(tell)) == 1 else wrap(out)
 
-    def value(self):
+    def out(self):
         '''return outgoing things and clear outgoing things'''
         # swap for default context
         self.unswap()
         out, tell = tee(self.outgoing)
         wrap = self._wrapper
-        out = next(out) if len(wrap(tell)) == 1 else wrap(out)
+        wrap = next(out) if len(wrap(tell)) == 1 else wrap(out)
         # clear outgoing things
         self.clearout()
-        return out
+        return wrap
 
 
 class AutoResultMixin(EndMixin, AutoMixin):

thingq/lazy/ordering.py

 # -*- coding: utf-8 -*-
 '''thingq lazy ordering queues'''
 
-from thingq.core import SLOTS
+from thingq.mixins import SLOTS
 from thingq.ordering import RandomMixin, OrderingMixin
 
 from thingq.lazy.mixins import AutoResultMixin, ManResultMixin

thingq/lazy/reducing.py

 # -*- coding: utf-8 -*-
 '''thingq lazy reducing queues'''
 
-from thingq.core import SLOTS
+from thingq.mixins import SLOTS
 from thingq.reducing import MathMixin, TruthMixin, ReducingMixin
 
 from thingq.lazy.mixins import AutoResultMixin, ManResultMixin
+# -*- coding: utf-8 -*-
+'''thingq queuing mixins'''
+
+from threading import local
+from collections import deque
+from contextlib import contextmanager
+
+from stuf.utils import OrderedDict
+from stuf.core import stuf, frozenstuf, orderedstuf
+
+SLOTS = [
+    '_work', 'outgoing', '_util', 'incoming', '_call', '_alt', '_wrapper',
+    '_args', '_kw', '_clearout', '_context', '_CONFIG', '_INQ', '_WORKQ',
+    '_UTILQ', '_OUTQ', '_iterator', 'current_mode', '_savepoints', '_start',
+]
+
+
+class ThingsMixin(local):
+
+    '''things management mixin'''
+
+    def __init__(self, incoming, outgoing, **kw):
+        '''
+        init
+
+        @param incoming: incoming things
+        @param outgoing: outgoing things
+        '''
+        super(ThingsMixin, self).__init__()
+        # incoming things
+        self.incoming = incoming
+        # outgoing things
+        self.outgoing = outgoing
+        # preferred mode
+        self.current_mode = self._RW
+        #######################################################################
+        ## context defaults ###################################################
+        #######################################################################
+        # preferred context
+        self._context = getattr(self, self._DEFAULT_CONTEXT)
+        # default context settings
+        self._CONFIG = {}
+        # 1. default incoming things
+        self._INQ = self._INVAR
+        # 2. default work things
+        self._WORKQ = self._WORKVAR
+        # 3. default utility things
+        self._UTILQ = self._UTILVAR
+        # 4. default outgoing things
+        self._OUTQ = self._OUTVAR
+        # clear outgoing things before extending/appending to them?
+        self._clearout = True
+        #######################################################################
+        ## snapshotting defaults ##############################################
+        #######################################################################
+        # number of savepoints to keep (default: 5)
+        maxlen = kw.pop('savepoints', 5)
+        # create stack for savepoint things
+        self._savepoints = deque(maxlen=maxlen) if maxlen is not None else None
+        # savepoint of original incoming things
+        if self._savepoints is not None:
+            self._original()
+        #######################################################################
+        ## callable defaults ##################################################
+        #######################################################################
+        # current callable (default: identity)
+        self._call = lambda x: x
+        # current alternate callable (default: identity)
+        self._alt = lambda x: x
+        # iterable export wrapper (default: `list`)
+        self._wrapper = list
+        # postition arguments (default: `tuple`)
+        self._args = ()
+        # keyword arguments (default: `dict`)
+        self._kw = {}
+
+    ###########################################################################
+    ## mode things ############################################################
+    ###########################################################################
+
+    # read/write mode
+    _RW = 'read/write'
+    # read-only mode
+    _RO = 'read-only'
+
+    def rw(self):
+        '''switch to read/write mode'''
+        self.current_mode = self._RW
+        return self._clearu().unswap()
+
+    ###########################################################################
+    ## context things #EE######################################################
+    ###########################################################################
+
+    # 1. incoming things
+    _INCFG = 'inq'
+    _INVAR = 'incoming'
+    # 2. utility things
+    _UTILCFG = 'utilq'
+    _UTILVAR = '_util'
+    # 3. work things
+    _WORKCFG = 'workq'
+    _WORKVAR = '_work'
+    # 4. outgoing things
+    _OUTCFG = 'outq'
+    _OUTVAR = 'outgoing'
+
+    def swap(self, **kw):
+        '''swap context'''
+        # savepoint
+        savepoint = kw.pop('savepoint', True)
+        if savepoint:
+            self._savepoint()
+        # keep context-specific settings between context swaps
+        self._CONFIG = kw if kw.get('hard', False) else {}
+        # set context
+        self._context = kw.get('context', getattr(self, self._DEFAULT_CONTEXT))
+        # clear wrap outgoing things before extending them?
+        self._clearout = kw.get('clearout', True)
+        # 1. incoming things
+        self._INQ = kw.get(self._INCFG, self._INVAR)
+        # 2. work things
+        self._WORKQ = kw.get(self._WORKCFG, self._WORKVAR)
+        # 3. utility things
+        self._UTILQ = kw.get(self._UTILCFG, self._UTILVAR)
+        # 4. outgoing things
+        self._OUTQ = kw.get(self._OUTCFG, self._OUTVAR)
+        return self
+
+    def reswap(self):
+        '''swap for preferred context'''
+        return self.swap(savepoint=False, **self._CONFIG)
+
+    def unswap(self):
+        '''swap for current default context'''
+        return self.swap(savepoint=False)
+
+    @contextmanager
+    def ctx1(self, **kw):
+        '''swap for one-armed context'''
+        q = kw.pop(self._WORKCFG, self._INVAR)
+        self.swap(workq=q, utilq=q, context=self.ctx1, **kw)
+        yield
+        self.reswap()
+
+    ###########################################################################
+    ## savepoint for things ##################################################
+    ###########################################################################
+
+    def _original(self):
+        '''preserve original incoming things'''
+        self._savepoint()
+        # preserve from savepoint stack
+        self._start = self._savepoints.pop()
+        return self
+
+    def undo(self, index=0, everything=False):
+        '''
+        revert to previous savepoint
+
+        @param index: index of savepoint (default: 0)
+        @param everything: undo everything and return things to original state
+        '''
+        if everything:
+            self.clear()._clearsp()
+            self.incoming = self._start
+            self._original()
+            return self
+        self.clear()
+        if not index:
+            self.incoming = self._savepoints.pop()
+        else:
+            self.incoming = deque(reversed(self._savepoints))[index]
+        return self._savepoint()
+
+    ###########################################################################
+    ## rotate things ##########################################################
+    ###########################################################################
+
+    def reup(self):
+        '''put incoming things in incoming things as one incoming thing'''
+        with self.ctx2(savepoint=False):
+            return self._append(list(self._iterable))
+
+    def sync(self):
+        '''shift outgoing things to incoming things'''
+        with self.autoctx(inq=self._OUTVAR, outq=self._INVAR, savepoint=False):
+            return self._xtend(self._iterable)
+
+    def syncout(self):
+        '''shift incoming things to outgoing things'''
+        with self.autoctx(savepoint=False):
+            return self._xtend(self._iterable)
+
+    ###########################################################################
+    ## extend incoming things #################################################
+    ###########################################################################
+
+    def extend(self, things):
+        '''
+        extend after incoming things
+
+        @param thing: some things
+        '''
+        with self.ctx1():
+            return self._xtend(things)
+
+    def extendleft(self, things):
+        '''
+        extend before incoming things
+
+        @param thing: some things
+        '''
+        with self.ctx1():
+            return self._xtendleft(things)
+
+    def extendout(self, things):
+        '''
+        extend right side of outgoing things
+
+        @param thing: some things
+        '''
+        with self.ctx1(workq=self._OUTVAR):
+            return self._xtend(things)
+
+    ###########################################################################
+    ## append incoming things #################################################
+    ###########################################################################
+
+    def append(self, thing):
+        '''
+        append after incoming things
+
+        @param thing: some thing
+        '''
+        with self.ctx1():
+            return self._append(thing)
+
+    def prepend(self, thing):
+        '''
+        append before incoming things
+
+        @param thing: some thing
+        '''
+        with self.ctx1():
+            return self._appendleft(thing)
+
+    ###########################################################################
+    ## call things ############################################################
+    ###########################################################################
+
+    def args(self, *args, **kw):
+        '''set arguments for current or alternative callable'''
+        # set position arguments
+        self._args = args
+        # set keyword arguemnts
+        self._kw = kw
+        return self
+
+    def tap(self, call, alt=None, factory=False):
+        '''
+        set current callable
+
+        @param call: a callable
+        @param alt: an alternative callable (default: None)
+        @param factor: call is a factory? (default: False)
+        '''
+        # reset postition arguments
+        self._args = ()
+        # reset keyword arguments
+        self._kw = {}
+        # set factory for building current callable
+        if factory:
+            def factory(*args, **kw):
+                return call(*args, **kw)
+            self._call = factory
+        else:
+            # set current callable
+            self._call = call
+        # set alternative callable
+        self._alt = alt if alt is not None else lambda x: x
+        return self
+
+    def untap(self):
+        '''clear current callable'''
+        # reset postition arguments
+        self._args = ()
+        # reset keyword arguments
+        self._kw = {}
+        # reset current callable (default is identity)
+        self._call = lambda x: x
+        # reset alternative callable
+        self._alt = lambda x: x
+        return self
+
+    ###########################################################################
+    ## know things ############################################################
+    ###########################################################################
+
+    @staticmethod
+    def _repr(*args):
+        '''queue representation'''
+        return (
+            '<{0}.{1}<<{2}>>([IN: {3}({4}) => WORK: {5}({6}) => UTIL: {7}({8})'
+            ' => OUT: {9}: ({10})]) at {11}>'
+        ).format(*args)
+
+    @property
+    def balanced(self):
+        '''queues are balanced?'''
+        return self.countout() == self.__len__()
+
+    ###########################################################################
+    ## clear things ###########################################################
+    ###########################################################################
+
+    def _clearsp(self):
+        '''clear savepoints'''
+        self._savepoints.clear()
+        return self
+
+    def clear(self):
+        '''clear anything'''
+        return self.untap().unwrap().clearout().clearin()._clearw()._clearu()
+
+
+class ResultsMixin(local):
+
+    '''result of things mixin'''
+
+    ###########################################################################
+    ## outgoing things export #################################################
+    ###########################################################################
+
+    def peek(self):
+        '''results from read-only context'''
+        self.ro()
+        out = self._wrapper(self._util)
+        results = out[0] if len(out) == 1 else out
+        self.rw()
+        return results
+
+    def results(self):
+        '''yield outgoing things, clearing outgoing things as it iterates'''
+        return self.__iter__()
+
+    ###########################################################################
+    ## wrap outgoing things ###################################################
+    ###########################################################################
+
+    def wrap(self, wrapper):
+        '''
+        wrapper for outgoing things
+
+        @param wrapper: an iterator class
+        '''
+        self._wrapper = wrapper
+        return self
+
+    def tupleout(self):
+        '''set wrapper to `tuple`'''
+        return self.wrap(tuple)
+
+    def setout(self):
+        '''set wrapper to `set`'''
+        return self.wrap(set)
+
+    def dequeout(self):
+        '''set wrapper to `deque`'''
+        return self.wrap(deque)
+
+    def dictout(self):
+        '''set wrapper to `dict`'''
+        return self.wrap(dict)
+
+    def fsetout(self):
+        '''set wrapper to `frozenset`'''
+        return self.wrap(frozenset)
+
+    def fstufout(self):
+        '''set wrapper to `frozenstuf`'''
+        return self.wrap(frozenstuf)
+
+    def odictout(self):
+        '''set wrapper to `OrderedDict`'''
+        return self.wrap(OrderedDict)
+
+    def ostufout(self):
+        '''set wrapper to `orderedstuf`'''
+        return self.wrap(orderedstuf)
+
+    def stufout(self):
+        '''set wrapper to `stuf`'''
+        return self.wrap(stuf)
+
+    def listout(self):
+        '''clear current wrapper'''
+        return self.wrap(list)
+
+    unwrap = listout

thingq/ordering.py

 
     '''order mixin'''
 
-    def group(self):
+    def groupby(self):
         '''
         group incoming things, optionally using current call for key function
         '''

thingq/support.py

     reraise = staticmethod(six.reraise)
 
     @classmethod
-    def isbinary(cls, value):
+    def isbinary(cls, out):
         '''is binary?'''
-        return isinstance(value, cls.BINARY)
+        return isinstance(out, cls.BINARY)
 
     @classmethod
-    def isclass(cls, value):
+    def isclass(cls, out):
         '''is class?'''
-        return isinstance(value, cls.CLASS)
+        return isinstance(out, cls.CLASS)
 
     @classmethod
-    def iscall(cls, value):
+    def iscall(cls, out):
         '''is callable?'''
-        return six.callable(value)
+        return six.callable(out)
 
     @classmethod
-    def isgtemax(cls, value):
+    def isgtemax(cls, out):
         '''greater than max size?'''
-        return value > cls.MAXSIZE
+        return out > cls.MAXSIZE
 
     @classmethod
-    def isinteger(cls, value):
+    def isinteger(cls, out):
         '''is integer?'''
-        return isinstance(value, cls.INTEGER)
+        return isinstance(out, cls.INTEGER)
 
     @classmethod
-    def isltemax(cls, value):
+    def isltemax(cls, out):
         '''less than max size?'''
-        return value < cls.MAXSIZE
+        return out < cls.MAXSIZE
 
     @classmethod
-    def isstring(cls, value):
+    def isstring(cls, out):
         '''is string'''
-        return isinstance(value, cls.STRING)
+        return isinstance(out, cls.STRING)
 
     @classmethod
-    def isunicode(cls, value):
+    def isunicode(cls, out):
         '''is text?'''
-        return isinstance(value, cls.UNICODE)
+        return isinstance(out, cls.UNICODE)
 
     @staticmethod
     def printf(*args, **kw):

thingq/tests/auto/filtering.py

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

thingq/tests/auto/ordering.py

     def test_group(self,):
         from math import floor
         self.assertEqual(
-        self.qclass(1.3, 2.1, 2.4).tap(lambda x: floor(x)).group().end(),
+        self.qclass(1.3, 2.1, 2.4).tap(lambda x: floor(x)).groupby().end(),
             [[1.0, [1.3]], [2.0, [2.1, 2.4]]]
         )
         self.assertEqual(
-            self.qclass(1.3, 2.1, 2.4).group().end(),
+            self.qclass(1.3, 2.1, 2.4).groupby().end(),
             [[1.3, [1.3]], [2.1, [2.1]], [2.4, [2.4]]],
         )
 
         )
 
     def test_product(self):
-        foo = self.qclass('ABCD', 'xy').product().value()
+        foo = self.qclass('ABCD', 'xy').product().out()
         self.assertEqual(
             foo,
             [('A', 'x'), ('A', 'y'), ('B', 'x'), ('B', 'y'), ('C', 'x'),

thingq/tests/auto/queuing.py

 
     def test_outextend(self):
         self.assertListEqual(
-            self.qclass().outextend([1, 2, 3, 4, 5, 6]).end(),
+            self.qclass().extendout([1, 2, 3, 4, 5, 6]).end(),
             [1, 2, 3, 4, 5, 6],
         )
 
 
     def test_tuple_wrap(self):
         self.assertIsInstance(
-            self.qclass(1, 2, 3, 4, 5, 6).tuple_wrap().syncout().value(),
+            self.qclass(1, 2, 3, 4, 5, 6).tupleout().syncout().out(),
             tuple,
         )
         self.assertTupleEqual(
-            self.qclass(1, 2, 3, 4, 5, 6).tuple_wrap().syncout().value(),
+            self.qclass(1, 2, 3, 4, 5, 6).tupleout().syncout().out(),
             (1, 2, 3, 4, 5, 6),
         )
 
     def test_set_wrap(self):
         self.assertIsInstance(
-            self.qclass(1, 2, 3, 4, 5, 6).set_wrap().syncout().value(),
+            self.qclass(1, 2, 3, 4, 5, 6).setout().syncout().out(),
             set,
         )
         self.assertSetEqual(
-            self.qclass(1, 2, 3, 4, 5, 6).set_wrap().syncout().value(),
+            self.qclass(1, 2, 3, 4, 5, 6).setout().syncout().out(),
             set([1, 2, 3, 4, 5, 6]),
         )
 
     def test_deque_wrap(self):
         from collections import deque
         self.assertIsInstance(
-            self.qclass(1, 2, 3, 4, 5, 6).deque_wrap().syncout().value(),
+            self.qclass(1, 2, 3, 4, 5, 6).dequeout().syncout().out(),
             deque,
         )
         self.assertEqual(
-            self.qclass(1, 2, 3, 4, 5, 6).deque_wrap().syncout().value(),
+            self.qclass(1, 2, 3, 4, 5, 6).dequeout().syncout().out(),
             deque([1, 2, 3, 4, 5, 6]),
         )
 
     def test_frozenset_wrap(self):
         self.assertIsInstance(
-            self.qclass(1, 2, 3, 4, 5, 6).frozenset_wrap().syncout().value(),
+            self.qclass(1, 2, 3, 4, 5, 6).fsetout().syncout().out(),
             frozenset,
         )
         self.assertSetEqual(
-            self.qclass(1, 2, 3, 4, 5, 6).frozenset_wrap().syncout().value(),
+            self.qclass(1, 2, 3, 4, 5, 6).fsetout().syncout().out(),
             frozenset([1, 2, 3, 4, 5, 6]),
         )
 
         self.assertIsInstance(
             self.qclass(
                 (1, 2), (3, 4), (5, 6)
-            ).dict_wrap().syncout().value(),
+            ).dictout().syncout().out(),
             dict,
         )
         self.assertDictEqual(
             self.qclass(
                 (1, 2), (3, 4), (5, 6)
-            ).dict_wrap().syncout().value(),
+            ).dictout().syncout().out(),
             {1: 2, 3: 4, 5: 6},
         )
 
         self.assertIsInstance(
             self.qclass(
                 ('a1', 2), ('a3', 4), ('a5', 6)
-            ).frozenstuf_wrap().syncout().value(),
+            ).fstufout().syncout().out(),
             frozenstuf,
         )
         self.assertEqual(
             self.qclass(
                 ('a1', 2), ('a3', 4), ('a5', 6)
-            ).frozenstuf_wrap().syncout().value(),
+            ).fstufout().syncout().out(),
            frozenstuf({'a1': 2, 'a3': 4, 'a5': 6}),
         )
 
         self.assertIsInstance(
             self.qclass(
                 (1, 2), (3, 4), (5, 6)
-            ).ordereddict_wrap().syncout().value(),
+            ).odictout().syncout().out(),
             OrderedDict,
         )
         self.assertDictEqual(
             self.qclass(
                 (1, 2), (3, 4), (5, 6)
-            ).ordereddict_wrap().syncout().value(),
+            ).odictout().syncout().out(),
             OrderedDict({1: 2, 3: 4, 5: 6}),
         )
 
         self.assertIsInstance(
             self.qclass(
                 (1, 2), (3, 4), (5, 6)
-            ).orderedstuf_wrap().syncout().value(),
+            ).ostufout().syncout().out(),
             orderedstuf,
         )
         self.assertEqual(
             self.qclass(
                 (1, 2), (3, 4), (5, 6)
-            ).orderedstuf_wrap().syncout().value(),
+            ).ostufout().syncout().out(),
            orderedstuf({1: 2, 3: 4, 5: 6}),
         )
 
         self.assertIsInstance(
             self.qclass(
                 (1, 2), (3, 4), (5, 6)
-            ).stuf_wrap().syncout().value(),
+            ).stufout().syncout().out(),
             stuf,
         )
         self.assertDictEqual(
             self.qclass(
                 (1, 2), (3, 4), (5, 6)
-            ).stuf_wrap().syncout().value(),
+            ).stufout().syncout().out(),
            stuf({1: 2, 3: 4, 5: 6}),
         )

thingq/tests/man/filtering.py

         self.assertFalse(manq.balanced)
         manq.sync()
         self.assertTrue(manq.balanced)
-        self.assertEqual(manq.value(), 5)
+        self.assertEqual(manq.out(), 5)
         self.assertFalse(manq.balanced)
 
     def test_nth(self):
         self.assertFalse(manq.balanced)
         manq.sync()
         self.assertTrue(manq.balanced)
-        self.assertEqual(manq.value(), 1)
+        self.assertEqual(manq.out(), 1)
         self.assertFalse(manq.balanced)
 
     def test_initial(self):
                 stooges, stoog2, stoog3
             ).tap(
                 lambda x: not x[0].startswith('__'), isclass
-            ).tuple_wrap().members().untap().sync(),
+            ).tupleout().members().untap().sync(),
             self.assertEqual,
             (('age', 40), ('name', 'moe'), ('age', 50), ('name', 'larry'),
             ('age', 60), ('name', 'curly'), ('stoog4', (('age', 969),
         self._true_true_false(
             self.qclass(stoog3).tap(
                 lambda x: x, isclass
-            ).tuple_wrap().mro().sync().members().untap().sync(),
+            ).tupleout().mro().sync().members().untap().sync(),
             self.assertEqual,
             (('age', 60), ('name', 'curly'), ('age', 50), ('name', 'larry'),
             ('age', 40), ('name', 'moe'))

thingq/tests/man/manning.py

         manq.sync()
         self.assertTrue(manq.balanced)
         if comp is not None:
-            expr(manq.value(), comp)
+            expr(manq.out(), comp)
         else:
-            expr(manq.value())
+            expr(manq.out())
         self.assertFalse(manq.balanced)
 
     def _true_true_false(self, manq, expr, comp=None):
         manq.sync()
         self.assertTrue(manq.balanced)
         if comp is not None:
-            value = manq.value()
-            expr(value, comp, value)
+            out = manq.out()
+            expr(out, comp, out)
         else:
-            expr(manq.value())
+            expr(manq.out())
         self.assertFalse(manq.balanced)
 
     def _false_true_true(self, manq, expr, comp=None):
         manq.sync()
         self.assertTrue(manq.balanced)
         if comp is not None:
-            expr(manq.value(), comp)
+            expr(manq.out(), comp)
         else:
-            expr(manq.value())
+            expr(manq.out())
         self.assertTrue(manq.balanced)

thingq/tests/man/ordering.py

     def test_group(self,):
         from math import floor
         self._false_true_false(
-            self.qclass(1.3, 2.1, 2.4).tap(lambda x: floor(x)).group(),
+            self.qclass(1.3, 2.1, 2.4).tap(lambda x: floor(x)).groupby(),
             self.assertListEqual,
             [[1.0, [1.3]], [2.0, [2.1, 2.4]]]
         )
         self._true_true_false(
-            self.qclass(1.3, 2.1, 2.4).group(),
+            self.qclass(1.3, 2.1, 2.4).groupby(),
             self.assertListEqual,
             [[1.3, [1.3]], [2.1, [2.1]], [2.4, [2.4]]],
         )

thingq/tests/man/queuing.py

 
     def test_outextend(self):
         self.assertListEqual(
-            self.qclass().outextend([1, 2, 3, 4, 5, 6]).end(),
+            self.qclass().extendout([1, 2, 3, 4, 5, 6]).end(),
             [1, 2, 3, 4, 5, 6],
         )
 
 
     def test_tuple_wrap(self):
         self.assertIsInstance(
-            self.qclass(1, 2, 3, 4, 5, 6).tuple_wrap().syncout().value(),
+            self.qclass(1, 2, 3, 4, 5, 6).tupleout().syncout().out(),
             tuple,
         )
         self.assertTupleEqual(
-            self.qclass(1, 2, 3, 4, 5, 6).tuple_wrap().syncout().value(),
+            self.qclass(1, 2, 3, 4, 5, 6).tupleout().syncout().out(),
             (1, 2, 3, 4, 5, 6),
         )
 
     def test_set_wrap(self):
         self.assertIsInstance(
-            self.qclass(1, 2, 3, 4, 5, 6).set_wrap().syncout().value(),
+            self.qclass(1, 2, 3, 4, 5, 6).setout().syncout().out(),
             set,
         )
         self.assertSetEqual(
-            self.qclass(1, 2, 3, 4, 5, 6).set_wrap().syncout().value(),
+            self.qclass(1, 2, 3, 4, 5, 6).setout().syncout().out(),
             set([1, 2, 3, 4, 5, 6]),
         )
 
     def test_deque_wrap(self):
         from collections import deque
         self.assertIsInstance(
-            self.qclass(1, 2, 3, 4, 5, 6).deque_wrap().syncout().value(),
+            self.qclass(1, 2, 3, 4, 5, 6).dequeout().syncout().out(),
             deque,
         )
         self.assertEqual(
-            self.qclass(1, 2, 3, 4, 5, 6).deque_wrap().syncout().value(),
+            self.qclass(1, 2, 3, 4, 5, 6).dequeout().syncout().out(),
             deque([1, 2, 3, 4, 5, 6]),
         )
 
     def test_frozenset_wrap(self):
         self.assertIsInstance(
-            self.qclass(1, 2, 3, 4, 5, 6).frozenset_wrap().syncout().value(),
+            self.qclass(1, 2, 3, 4, 5, 6).fsetout().syncout().out(),
             frozenset,
         )
         self.assertSetEqual(
-            self.qclass(1, 2, 3, 4, 5, 6).frozenset_wrap().syncout().value(),
+            self.qclass(1, 2, 3, 4, 5, 6).fsetout().syncout().out(),
             frozenset([1, 2, 3, 4, 5, 6]),
         )
 
         self.assertIsInstance(
             self.qclass(
                 (1, 2), (3, 4), (5, 6)
-            ).dict_wrap().syncout().value(),
+            ).dictout().syncout().out(),
             dict,
         )
         self.assertDictEqual(
             self.qclass(
                 (1, 2), (3, 4), (5, 6)
-            ).dict_wrap().syncout().value(),
+            ).dictout().syncout().out(),
             {1: 2, 3: 4, 5: 6},
         )
 
         self.assertIsInstance(
             self.qclass(
                 ('a1', 2), ('a3', 4), ('a5', 6)
-            ).frozenstuf_wrap().syncout().value(),
+            ).fstufout().syncout().out(),
             frozenstuf,
         )
         self.assertEqual(
             self.qclass(
                 ('a1', 2), ('a3', 4), ('a5', 6)
-            ).frozenstuf_wrap().syncout().value(),
+            ).fstufout().syncout().out(),
            frozenstuf({'a1': 2, 'a3': 4, 'a5': 6}),
         )
 
         self.assertIsInstance(
             self.qclass(
                 (1, 2), (3, 4), (5, 6)
-            ).ordereddict_wrap().syncout().value(),
+            ).odictout().syncout().out(),
             OrderedDict,
         )
         self.assertDictEqual(
             self.qclass(
                 (1, 2), (3, 4), (5, 6)
-            ).ordereddict_wrap().syncout().value(),
+            ).odictout().syncout().out(),
             OrderedDict({1: 2, 3: 4, 5: 6}),
         )
 
         self.assertIsInstance(
             self.qclass(
                 (1, 2), (3, 4), (5, 6)
-            ).orderedstuf_wrap().syncout().value(),
+            ).ostufout().syncout().out(),
             orderedstuf,
         )
         self.assertEqual(
             self.qclass(
                 (1, 2), (3, 4), (5, 6)
-            ).orderedstuf_wrap().syncout().value(),
+            ).ostufout().syncout().out(),
            orderedstuf({1: 2, 3: 4, 5: 6}),
         )
 
         self.assertIsInstance(
             self.qclass(
                 (1, 2), (3, 4), (5, 6)
-            ).stuf_wrap().syncout().value(),
+            ).stufout().syncout().out(),
             stuf,
         )
         self.assertDictEqual(
             self.qclass(
                 (1, 2), (3, 4), (5, 6)
-            ).stuf_wrap().syncout().value(),
+            ).stufout().syncout().out(),
            stuf({1: 2, 3: 4, 5: 6}),
         )
 deps=
   nose
   coverage
-  bpython
-  ipython
 commands=
   nosetests {posargs:--with-coverage --cover-package=thingq}
   
   unittest2
   nose
   coverage
-  bpython
-  ipython
 commands=
   nosetests {posargs:--with-coverage  --cover-package=thingq}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.