def add(self, *args, **kwargs):
    """ Accumulate datums for the transaction

    Start a transaction on an existing db connection
    >>> tx = TX(db)

    Get get an entity object with a tempid
    >>> ref = add()
    >>> ref = add(0)
    >>> ref = add(None)
    >>> ref = add(False)

    Entity id passed as first argument (int|long)
    >>> tx.add(1, 'thing/name', 'value')

    Shorthand form for multiple attributes sharing a root namespace
    >>> tx.add(':thing/', {'name':'value', 'tag':'value'})

    Attributes with a value of None are ignored
    >>> tx.add(':thing/ignored', None)

    Add multiple datums for an attribute with carinality:many
    >>> tx.add(':thing/color', ['red','white','blue'])

    """

    assert self.resp is None, "Transaction already committed"
    entity, av_pairs, args = None, [], list(args)
    if len(args):
      if isinstance(args[0], (int, long)): 
        " first arg is an entity or tempid"
        entity = E(args[0], tx=self)
      elif isinstance(args[0], E):
        " dont resuse entity from another tx"
        if args[0]._tx is self:
          entity  = args[0]
        else:
          if int(args[0]) > 0:
            " use the entity id on a new obj"
            entity = E(int(args[0]), tx=self)
          args[0] = None
      " drop the first arg"
      if entity is not None or args[0] in (None, False, 0):
        v = args.pop(0)
    " auto generate a temp id?"
    if entity is None:
      entity       = E(self.ctmpid, tx=self)
      self.ctmpid -= 1
    " a,v from kwargs"
    if len(args) == 0 and kwargs: 
      for a,v in kwargs.iteritems():
        self.addeav(entity, a, v)
    " a,v from args "
    if len(args):
      assert len(args) % 2 == 0, "imbalanced a,v in args: " % args
      for first, second in pairwise(args):
        if not first.startswith(':'): 
          first = ':' + first
        if not first.endswith('/'):
          " longhand used: blah/blah "
          if isinstance(second, list):
            for v in second:
              self.addeav(entity, first, v)
          else:
            self.addeav(entity, first, second)
          continue
        elif isinstance(second, dict):
          " shorthand used: blah/, dict "
          for a,v in second.iteritems():
            self.addeav(entity, "%s%s" % (first, a), v)
            continue
        elif isinstance(second, (list, tuple)):
          " shorthand used: blah/, list|tuple "
          for a,v in pairwise(second):
            self.addeav(entity, "%s%s" % (first, a), v)
            continue
        else:
          raise Exception, "invalid pair: %s : %s" % (first,second)
    "pass back the entity so it can be resolved after tx()"
    return entity
def add ( self , * args , ** kwargs ) : assert self . resp is None , "Transaction already committed" entity , av_pairs , args = None , [ ] , list ( args ) if len ( args ) : if isinstance ( args [ 0 ] , ( int , long ) ) : entity = E ( args [ 0 ] , tx = self ) elif isinstance ( args [ 0 ] , E ) : if args [ 0 ] . _tx is self : entity = args [ 0 ] else : if int ( args [ 0 ] ) > 0 : entity = E ( int ( args [ 0 ] ) , tx = self ) args [ 0 ] = None " drop the first arg" if entity is not None or args [ 0 ] in ( None , False , 0 ) : v = args . pop ( 0 ) " auto generate a temp id?" if entity is None : entity = E ( self . ctmpid , tx = self ) self . ctmpid -= 1 " a,v from kwargs" if len ( args ) == 0 and kwargs : for a , v in kwargs . iteritems ( ) : self . addeav ( entity , a , v ) " a,v from args " if len ( args ) : assert len ( args ) % 2 == 0 , "imbalanced a,v in args: " % args for first , second in pairwise ( args ) : if not first . startswith ( ':' ) : first = ':' + first if not first . endswith ( '/' ) : if isinstance ( second , list ) : for v in second : self . addeav ( entity , first , v ) else : self . addeav ( entity , first , second ) continue elif isinstance ( second , dict ) : for a , v in second . iteritems ( ) : self . addeav ( entity , "%s%s" % ( first , a ) , v ) continue elif isinstance ( second , ( list , tuple ) ) : for a , v in pairwise ( second ) : self . addeav ( entity , "%s%s" % ( first , a ) , v ) continue else : raise Exception , "invalid pair: %s : %s" % ( first , second ) "pass back the entity so it can be resolved after tx()" return entity
Accumulate datums for the transaction

    Start a transaction on an existing db connection
    >>> tx = TX(db)

    Get get an entity object with a tempid
    >>> ref = add()
    >>> ref = add(0)
    >>> ref = add(None)
    >>> ref = add(False)

    Entity id passed as first argument (int|long)
    >>> tx.add(1, 'thing/name', 'value')

    Shorthand form for multiple attributes sharing a root namespace
    >>> tx.add(':thing/', {'name':'value', 'tag':'value'})

    Attributes with a value of None are ignored
    >>> tx.add(':thing/ignored', None)

    Add multiple datums for an attribute with carinality:many
    >>> tx.add(':thing/color', ['red','white','blue'])