Beispiel #1
0
    def __parse_doc_from_couch(self, result, doc_id,
                               check_for_conflicts=False):
        # restrict to u1db documents
        if 'u1db_rev' not in result:
            return None
        doc = ServerDocument(doc_id, result['u1db_rev'])
        # set contents or make tombstone

        if '_attachments' not in result \
                or 'u1db_content' not in result['_attachments']:
            doc.make_tombstone()
        else:
            doc.content = json.loads(
                result['_attachments']['u1db_content'])
        # determine if there are conflicts
        if check_for_conflicts \
                and '_attachments' in result \
                and 'u1db_conflicts' in result['_attachments']:
            doc.set_conflicts(
                self._build_conflicts(
                    doc.doc_id,
                    result['_attachments']['u1db_conflicts']))
        # store couch revision
        doc.couch_rev = result['_rev']
        # store transactions
        doc.transactions = result['u1db_transactions']
        return doc
Beispiel #2
0
 def __parse_doc_from_couch(self,
                            result,
                            doc_id,
                            check_for_conflicts=False,
                            decode=True):
     # restrict to u1db documents
     if 'u1db_rev' not in result:
         return None
     doc = ServerDocument(doc_id, result['u1db_rev'])
     # set contents or make tombstone
     if '_attachments' not in result \
             or 'u1db_content' not in result['_attachments']:
         doc.make_tombstone()
     elif decode:
         doc.content = json.loads(
             binascii.a2b_base64(
                 result['_attachments']['u1db_content']['data']))
     else:
         doc._json = result['_attachments']['u1db_content']['data']
     # determine if there are conflicts
     if check_for_conflicts \
             and '_attachments' in result \
             and 'u1db_conflicts' in result['_attachments']:
         if decode:
             conflicts = binascii.a2b_base64(
                 result['_attachments']['u1db_conflicts']['data'])
         else:
             conflicts = result['_attachments']['u1db_conflicts']['data']
         conflicts = json.loads(conflicts)
         doc.set_conflicts(self._build_conflicts(doc.doc_id, conflicts))
     # store couch revision
     doc.couch_rev = result['_rev']
     return doc
Beispiel #3
0
 def __parse_doc_from_couch(self, result, doc_id,
                            check_for_conflicts=False, decode=True):
     # restrict to u1db documents
     if 'u1db_rev' not in result:
         return None
     doc = ServerDocument(doc_id, result['u1db_rev'])
     # set contents or make tombstone
     if '_attachments' not in result \
             or 'u1db_content' not in result['_attachments']:
         doc.make_tombstone()
     elif decode:
         doc.content = json.loads(
             binascii.a2b_base64(
                 result['_attachments']['u1db_content']['data']))
     else:
         doc._json = result['_attachments']['u1db_content']['data']
     # determine if there are conflicts
     if check_for_conflicts \
             and '_attachments' in result \
             and 'u1db_conflicts' in result['_attachments']:
         if decode:
             conflicts = binascii.a2b_base64(
                 result['_attachments']['u1db_conflicts']['data'])
         else:
             conflicts = result['_attachments']['u1db_conflicts']['data']
         conflicts = json.loads(conflicts)
         doc.set_conflicts(self._build_conflicts(doc.doc_id, conflicts))
     # store couch revision
     doc.couch_rev = result['_rev']
     return doc
Beispiel #4
0
    def _build_conflicts(self, doc_id, attached_conflicts):
        """
        Build the conflicted documents list from the conflicts attachment
        fetched from a couch document.

        :param attached_conflicts: The document's conflicts as fetched from a
                                   couch document attachment.
        :type attached_conflicts: dict
        """
        conflicts = []
        for doc_rev, content in attached_conflicts:
            doc = ServerDocument(doc_id, doc_rev)
            if content is None:
                doc.make_tombstone()
            else:
                doc.content = content
            conflicts.append(doc)
        return conflicts
Beispiel #5
0
    def _build_conflicts(self, doc_id, attached_conflicts):
        """
        Build the conflicted documents list from the conflicts attachment
        fetched from a couch document.

        :param attached_conflicts: The document's conflicts as fetched from a
                                   couch document attachment.
        :type attached_conflicts: dict
        """
        conflicts = []
        for doc_rev, content in attached_conflicts:
            doc = ServerDocument(doc_id, doc_rev)
            if content is None:
                doc.make_tombstone()
            else:
                doc.content = content
            conflicts.append(doc)
        return conflicts