Пример #1
0
    def deserialize(doc):
        brl = BRLUser(doc[User.SERIAL_ID_KEY])
        user = User(brl)
        user._encrypted_password = doc[User.SERIAL_ENCRYPTED_PASSWORD]
        user.password_timestamp = doc.get(User.SERIAL_PASSWORD_TIMESTAMP, None)

        if User.SERIAL_NUMERIC_ID in doc:
            user.numeric_id = ID.deserialize(doc[User.SERIAL_NUMERIC_ID])

        # Profile fields
        user.firstname = doc.get(User.SERIAL_FIRSTNAME, None)
        user.lastname = doc.get(User.SERIAL_LASTNAME, None)
        user.country = doc.get(User.SERIAL_COUNTRY, None)
        user.description = doc.get(User.SERIAL_DESCRIPTION, None)
        user.email = doc.get(User.SERIAL_EMAIL, None)
        user.visible_email = doc.get(User.SERIAL_VISIBLE_EMAIL, 0) == 1
        user.allow_mailing = doc.get(User.SERIAL_ALLOW_MAILING, 0) == 1
        user.active = doc.get(User.SERIAL_ACTIVE, 0) == 1
        user.staff = doc.get(User.SERIAL_STAFF, 0) == 1
        user.joined_date = UtcDatetime.deserialize(
            doc.get(User.SERIAL_JOINED_DATE, None))
        user.confirmation_date = UtcDatetime.deserialize(
            doc.get(User.SERIAL_CONFIRMATION_DATE, None))
        user.confirmation_token = doc.get(User.SERIAL_CONFIRMATION_TOKEN, None)
        # Old workspace methods
        user.block_counter = doc.get(User.SERIAL_MOD_COUNTER, 0)
        blocks_data = doc.get(User.SERIAL_BLOCKS, {})
        user.blocks = DictDeserializer(
            BRLBlock, BlockMetaInfoDeserializer).deserialize(blocks_data)
        user.administrators = Permissions.deserialize(
            doc.get(User.SERIAL_ADMINISTRATORS, {}))
        social_accounts_doc = doc.get(User.SERIAL_SOCIAL_ACCOUNTS)
        user.social_accounts = DictDeserializer(
            str, SocialAccount).deserialize(social_accounts_doc)

        # Achievements
        user.read_api_counter = doc.get(User.SERIAL_READ_API_COUNTER, 0)
        user.publish_counter = doc.get(User.SERIAL_PUBLISH_COUNTER, 0)
        user.reuse_counter = doc.get(User.SERIAL_REUSE_COUNTER, 0)

        # Additional profile fields
        user.street_1 = doc.get(User.SERIAL_STREET1, "")
        user.street_2 = doc.get(User.SERIAL_STREET2, "")
        user.city = doc.get(User.SERIAL_CITY, "")
        user.postal_code = doc.get(User.SERIAL_POSTAL_CODE, "")
        user.region = doc.get(User.SERIAL_REGION, "")
        user.tax_id = doc.get(User.SERIAL_TAX_ID, "")
        user.vat = doc.get(User.SERIAL_VAT, "")

        # OAuth
        user.oauth_github_token = doc.get(User.SERIAL_OAUTH_GITHUB_TOKEN, None)
        user.oauth_google_token = doc.get(User.SERIAL_OAUTH_GOOGLE_TOKEN, None)

        # Max workspace size, default BII_MAX_USER_WORKSPACE_SIZE
        user.max_workspace_size = doc.get(User.SERIAL_MAX_WORKSPACE_SIZE,
                                          BII_MAX_USER_WORKSPACE_SIZE)

        # Invited by
        user.invited_by = doc.get(User.SERIAL_INVITED_BY, None)
        return user
Пример #2
0
    def read_content_sizes(self, content_ids):
        dbcol = self.db[GenericServerStore.PUBLISHED_CONTENT_ST]
        ids = [a.serialize() for a in content_ids]
        projection = {"l.sz": 1}
        cursor = dbcol.find({"_id": {"$in": ids}}, projection)
        result = {ID.deserialize(doc["_id"]): doc["l"]["sz"] for doc in cursor}

        return result
Пример #3
0
    def read_content_sizes(self, content_ids):
        dbcol = self.db[GenericServerStore.PUBLISHED_CONTENT_ST]
        ids = [a.serialize() for a in content_ids]
        projection = {"l.sz": 1}
        cursor = dbcol.find({"_id": {"$in": ids}}, projection)
        result = {ID.deserialize(doc["_id"]): doc["l"]["sz"] for doc in cursor}

        return result
    def test_id(self):
        rf = UserID(13)
        s = rf.serialize()
        rf2 = ID.deserialize(s)

        #print(str(rf.__class__))
        #print(str(rf2.__class__))

        self.assertEqual(rf, rf2)
Пример #5
0
    def test_id(self):
        rf = UserID(13)
        s = rf.serialize()
        rf2 = ID.deserialize(s)

        #print(str(rf.__class__))
        #print(str(rf2.__class__))

        self.assertEqual(rf, rf2)
Пример #6
0
    def deserialize(doc):
        brl = BRLUser(doc[User.SERIAL_ID_KEY])
        user = User(brl)
        user._encrypted_password = doc[User.SERIAL_ENCRYPTED_PASSWORD]
        user.password_timestamp = doc.get(User.SERIAL_PASSWORD_TIMESTAMP, None)

        if User.SERIAL_NUMERIC_ID in doc:
            user.numeric_id = ID.deserialize(doc[User.SERIAL_NUMERIC_ID])

        # Profile fields
        user.firstname = doc.get(User.SERIAL_FIRSTNAME, None)
        user.lastname = doc.get(User.SERIAL_LASTNAME, None)
        user.country = doc.get(User.SERIAL_COUNTRY, None)
        user.description = doc.get(User.SERIAL_DESCRIPTION, None)
        user.email = doc.get(User.SERIAL_EMAIL, None)
        user.visible_email = doc.get(User.SERIAL_VISIBLE_EMAIL, 0) == 1
        user.allow_mailing = doc.get(User.SERIAL_ALLOW_MAILING, 0) == 1
        user.active = doc.get(User.SERIAL_ACTIVE, 0) == 1
        user.staff = doc.get(User.SERIAL_STAFF, 0) == 1
        user.joined_date = UtcDatetime.deserialize(doc.get(User.SERIAL_JOINED_DATE, None))
        user.confirmation_date = UtcDatetime.deserialize(doc.get(User.SERIAL_CONFIRMATION_DATE,
                                                                 None))
        user.confirmation_token = doc.get(User.SERIAL_CONFIRMATION_TOKEN, None)
        # Old workspace methods
        user.block_counter = doc.get(User.SERIAL_MOD_COUNTER, 0)
        blocks_data = doc.get(User.SERIAL_BLOCKS, {})
        user.blocks = DictDeserializer(BRLBlock, BlockMetaInfoDeserializer).deserialize(blocks_data)
        user.administrators = Permissions.deserialize(doc.get(User.SERIAL_ADMINISTRATORS, {}))
        social_accounts_doc = doc.get(User.SERIAL_SOCIAL_ACCOUNTS)
        user.social_accounts = DictDeserializer(str, SocialAccount).deserialize(social_accounts_doc)

        # Achievements
        user.read_api_counter = doc.get(User.SERIAL_READ_API_COUNTER, 0)
        user.publish_counter = doc.get(User.SERIAL_PUBLISH_COUNTER, 0)
        user.reuse_counter = doc.get(User.SERIAL_REUSE_COUNTER, 0)

        # Additional profile fields
        user.street_1 = doc.get(User.SERIAL_STREET1, "")
        user.street_2 = doc.get(User.SERIAL_STREET2, "")
        user.city = doc.get(User.SERIAL_CITY, "")
        user.postal_code = doc.get(User.SERIAL_POSTAL_CODE, "")
        user.region = doc.get(User.SERIAL_REGION, "")
        user.tax_id = doc.get(User.SERIAL_TAX_ID, "")
        user.vat = doc.get(User.SERIAL_VAT, "")

        # OAuth
        user.oauth_github_token = doc.get(User.SERIAL_OAUTH_GITHUB_TOKEN, None)
        user.oauth_google_token = doc.get(User.SERIAL_OAUTH_GOOGLE_TOKEN, None)

        # Max workspace size, default BII_MAX_USER_WORKSPACE_SIZE
        user.max_workspace_size = doc.get(User.SERIAL_MAX_WORKSPACE_SIZE,
                                          BII_MAX_USER_WORKSPACE_SIZE)

        # Invited by
        user.invited_by = doc.get(User.SERIAL_INVITED_BY, None)
        return user
Пример #7
0
 def deserialize(doc):
     numeric_id = ID.deserialize(doc[Block.SERIAL_NUMERIC_ID_KEY])
     m = Block(brl_id=BRLBlock(doc[Block.SERIAL_ID_KEY]), numeric_id=numeric_id)
     m._cells_table = AddressTable.deserialize(doc[Block.SERIAL_CELL_TABLE], numeric_id)
     m._contents_table = AddressTable.deserialize(doc[Block.SERIAL_CONTENT_TABLE], numeric_id)
     m._deps_table = TimeBaseMapDeserializer(BlockVersionTable).deserialize(doc[Block.SERIAL_DEPS_TABLE])
     m._renames = TimeBaseMapDeserializer(Renames).deserialize(doc[Block.SERIAL_RENAMES])
     m._deltas = ListDeserializer(BlockDelta).deserialize(doc[Block.SERIAL_DELTAS])
     m._cell_count = int(doc[Block.SERIAL_CELLS_COUNTER])
     m._content_count = int(doc[Block.SERIAL_CONTENT_COUNTER])
     return m
Пример #8
0
 def deserialize(doc):
     numeric_id = ID.deserialize(doc[Block.SERIAL_NUMERIC_ID_KEY])
     m = Block(brl_id=BRLBlock(doc[Block.SERIAL_ID_KEY]),
               numeric_id=numeric_id)
     m._cells_table = AddressTable.deserialize(doc[Block.SERIAL_CELL_TABLE],
                                               numeric_id)
     m._contents_table = AddressTable.deserialize(
         doc[Block.SERIAL_CONTENT_TABLE], numeric_id)
     m._deps_table = TimeBaseMapDeserializer(BlockVersionTable).deserialize(
         doc[Block.SERIAL_DEPS_TABLE])
     m._renames = TimeBaseMapDeserializer(Renames).deserialize(
         doc[Block.SERIAL_RENAMES])
     m._deltas = ListDeserializer(BlockDelta).deserialize(
         doc[Block.SERIAL_DELTAS])
     m._cell_count = int(doc[Block.SERIAL_CELLS_COUNTER])
     m._content_count = int(doc[Block.SERIAL_CONTENT_COUNTER])
     return m
Пример #9
0
 def deserialize(self, data):
     if data is None:
         return None
     try:
         kls = Deserializer.get_polymorphic_class(data)
         r = kls.deserialize(data)
         r.name = BlockCellName(data[Cell.SERIAL_NAME_KEY])
         r.root = ID.deserialize(data[Cell.SERIAL_ROOT_KEY])
         r.ID = self.id_type.deserialize(data[Cell.SERIAL_ID_KEY])
         r.type = BiiType(data[Cell.SERIAL_TYPE_KEY])
         r.hasMain = data[Cell.SERIAL_MAIN_KEY]
         try:
             r.dependencies.cell_name = r.name
         except AttributeError:
             pass
         return r
     except Exception as e:
         tb = traceback.format_exc()
         logger.warning(tb)
         raise BiiSerializationException(e)