def __init__(self, source, query, values, room, count=None):
        Peer.__init__(self, room)
        QueryResult.__init__(self, source, query)

        from documentChanger import DocumentChanger
        DocumentChanger.reregisterToken(room + "NextOrder", self.nextOrderToken)

        self._values = values

        from uuid import uuid4
        self._ident  = uuid4().hex
        self._count  = count
        self._limit  = -1
        self._serial = unicode(ValueQueryResult.SERIAL)
        self._orderPath = None
        ValueQueryResult.SERIAL += 1

        if query != None:
            limit = query.get('args.limit')
            if limit != None:
                self._limit = int(limit)

        self._catch(ValueQueryResult.In.RequestedDocument, self._requestedDocument)
        self._defers = {}
        self._deferredDocs = {}
    def _createAndSaveDocument(self, pillow, doc):
        if isinstance(doc, str) or isinstance(doc, unicode):
            try:
                doc = yield DocumentChanger.transform(None, doc)
            except Exception as e:
                doc = None
                print "ERROR - Exception: " + str(e)

        if type(doc) is dict:
            self._throw(DocumentCache.Out.CreateAndSaveDocument, doc)
        else:
            self._throw(DocumentCache.Out.CreateAndSaveDocument, None)
    def __create(self, pillow, feathers):
        if isinstance(feathers, str) or isinstance(feathers, unicode):
            try:
                feathers = yield DocumentChanger.transform(None, feathers)
            except Exception as e:
                feathers = None
                print "ERROR - Exception: " + str(e)

        if type(feathers) is dict:
            self._throw(Database.In.CreateDocument, feathers)
        else:
            self._throw(Database.In.CreateDocument, None)