Ejemplo n.º 1
0
 def serialize(self):
     from bson import Binary  # by pymongo
     bson = Binary(self._compressed())
     return Serializer().build((Blob.SERIAL_SHA_KEY, self.sha),
                               (Blob.SERIAL_IS_BINARY_KEY, self._is_binary),
                               (Blob.SERIAL_SIZE_KEY, self.size),
                               (Blob.SERIAL_COMPRESSED_BIN_KEY, bson))
Ejemplo n.º 2
0
 def diff(self, base, other):
     data = Serializer().build(("base", base), ("other", other))
     values_deserializer = ResourceDeserializer(
         CellDeserializer(BlockCellName),
         ContentDeserializer(BlockCellName))
     deserializer = ChangesDeserializer(CellName, values_deserializer)
     return self.bson_jwt_call('diff', data=data, deserializer=deserializer)
Ejemplo n.º 3
0
 def serialize(self):
     return Serializer().build(
         (ServerInfo.VERSION, self.version),
         (ServerInfo.COMPATIBLE, self.last_compatible),
         (ServerInfo.URL, self.download_url),
         (ServerInfo.MESSAGES, self.messages),
     )
Ejemplo n.º 4
0
 def serialize(self):
     '''serializer for migration.
     Needs a dict because its directly a mongo collectionS'''
     return Serializer().build(
         (Migration.SERIAL_ID_KEY, self.ID),
         (Migration.SERIAL_TIMESTAMP_KEY, self.applied_timestamp),
     )
Ejemplo n.º 5
0
 def testRecursiveSerialization2(self):
     ''' should call to_dict from DummyA and DummyB '''
     s = Serializer().build(
                           ("a", self.__a),
                           ("b", self.__b)
                          )
     self.assertEqual(s, {"a": {"a": 1, "b": 2}, "b": {"a": {"a": 1, "b": 2}, "b": 2}})
Ejemplo n.º 6
0
 def serialize(self):
     return  Serializer().build(
                 (None, super(VirtualCell, self)),  # Embed here parent
                 (VirtualCell.SERIAL_CODETREE_KEY, self.code),
                 (VirtualCell.SERIAL_LEAVES_KEY, self.leaves),
                 obj=self,
             )
Ejemplo n.º 7
0
 def serialize(self):
     return Serializer().build(
         #(self.SERIAL_PROVIDER, self.provider),
         (self.SERIAL_UID, self.uid),
         (self.SERIAL_LAST_LOGIN, self.last_login),
         (self.SERIAL_DATE_JOINED, self.date_joined),
         (self.SERIAL_TOKENS, self.tokens),
         (self.SERIAL_EXTRA_DATA, self.extra_data))
Ejemplo n.º 8
0
 def serialize(self):
     return Serializer().build(
         (HiveDependencies.SERIAL_DEP_TABLE, self.dep_table),
         (HiveDependencies.SERIAL_REFERENCES, self.references),
         (HiveDependencies.SERIAL_CLOSURE, self.closure),
         (HiveDependencies.SERIAL_SRC_GRAPH, self.src_graph),
         (HiveDependencies.SERIAL_DEP_GRAPH, self.dep_graph),
     )
Ejemplo n.º 9
0
 def serialize(self):
     '''Serialize the object to a 4 element tuple'''
     res = Serializer().build(
         (ElementPermissions.SERIAL_ID, self.ID),  # BRLBlock
         (ElementPermissions.SERIAL_IS_PRIVATE, self.is_private),
         (ElementPermissions.SERIAL_READ, self.read),
         (ElementPermissions.SERIAL_WRITE, self.write))
     return res
Ejemplo n.º 10
0
 def serialize(self):
     ret = Serializer().build(
         (Content.SERIAL_ID_KEY, self.ID),
         (Content.SERIAL_LOAD_KEY, self._load),
         (Content.SERIAL_PARSER_KEY, self.parser),
         (Content.SERIAL_IS_PARSED_KEY, self._is_parsed),
     )
     return ret
Ejemplo n.º 11
0
def smart_serialize(obj):
    args = []
    for field, (key, _, _) in obj.smart_serial.iteritems():
        a = getattr(obj, field)
        #TODO: Check field exist
        if a:
            args.append((key, a))
    ret = Serializer().build(*args)
    return ret
Ejemplo n.º 12
0
 def serialize(self):
     if self:
         resources, versions = zip(*self.values())
     else:
         resources, versions = [], []
     ser = Serializer().build((Closure.SERIAL_NAMES, self.keys()),
                              (Closure.SERIAL_RESOURCES, resources),
                              (Closure.SERIAL_VERSIONS, versions))
     return ser
Ejemplo n.º 13
0
 def serialize(self):
     res = Serializer().build(
         (Cell.SERIAL_ROOT_KEY, self.root),  # CellID
         (Cell.SERIAL_ID_KEY, self.ID),  # CellID or BlockCellName
         (Cell.SERIAL_TYPE_KEY, self.type),
         (Cell.SERIAL_NAME_KEY, self.name),
         (Cell.SERIAL_MAIN_KEY, self.hasMain)
     )
     return res
Ejemplo n.º 14
0
 def serialize(self):
     ret = Serializer().build(
           (Changes.SERIAL_DELETED_KEY,  self.deleted),
           (Changes.SERIAL_CREATED_KEY,  self.created),
           (Changes.SERIAL_MODIFIED_KEY, self.modified),
           (Changes.SERIAL_RENAMES_KEY,  self.renames),
           (Changes.SERIAL_SIMLIMIT_KEY, self.sim_limit),
     )
     return ret
Ejemplo n.º 15
0
 def serialize(self):
     if self.serialize_bytes:
         from bson import Binary  # by pymongo
         if self._compressed_bin is None:
             try:
                 self._compressed_bin = zlib.compress(self._binary)
             except IOError:
                 raise BiiException("Error compressing load text string")
         bson = Binary(self._compressed_bin)
         return Serializer().build(
             (Blob.SERIAL_SHA_KEY, self.sha),
             (Blob.SERIAL_IS_BINARY_KEY, self._is_binary),
             (Blob.SERIAL_SIZE_KEY, self.size),
             (Blob.SERIAL_COMPRESSED_BIN_KEY, bson))
     else:
         return Serializer().build(
             (Blob.SERIAL_SHA_KEY, self.sha),
             (Blob.SERIAL_IS_BINARY_KEY, self._is_binary))
Ejemplo n.º 16
0
 def serialize(self):
     #res = super(SimpleCell, self).serialize()
     ret = Serializer().build(
               (None, super(SimpleCell, self)),  # Embed here parent
               (SimpleCell.SERIAL_DEPENDENCES_KEY, self.dependencies),
               (SimpleCell.SERIAL_CONTAINER_KEY, self.container),
               obj=self,
     )
     return ret
Ejemplo n.º 17
0
 def serialize(self):
     return Serializer().build((FinderRequest.SERIAL_UNRESOLVED_KEY, self.unresolved),
                               (FinderRequest.SERIAL_TRACKING_KEY, self.block_names),
                               (FinderRequest.SERIAL_EXISTING_KEY, self.existing),
                               (FinderRequest.SERIAL_POLICY, self.policy),
                               (FinderRequest.SERIAL_DEP_COMMON_TABLE, self.existing_common_table),
                               (FinderRequest.SERIAL_CRITERIA, (self.find,
                                                                self.update,
                                                                self.downgrade,
                                                                self.modify)))
Ejemplo n.º 18
0
 def serialize(self):
     return Serializer().build(
         (DependencySet.SERIAL_EXPLICIT, self.explicit),
         (DependencySet.SERIAL_IMPLICIT, self.implicit),
         (DependencySet.SERIAL_PROPERTIES, self.properties),
         (DependencySet.SERIAL_SYSTEM, self.system),
         (DependencySet.SERIAL_RESOLVED, self.resolved),
         (DependencySet.SERIAL_UNRESOLVED, self.unresolved),
         (DependencySet.SERIAL_PATHS, self.paths),
     )
Ejemplo n.º 19
0
 def serialize(self):
     ret = Serializer().build(
           (SystemID.SERIAL_NAME_ID_KEY, self.name_id),
           (SystemID.SERIAL_VERSION_ID_KEY, self.version_id),
           (SystemID.SERIAL_BIITYPE_KEY, self.biiType),
           (SystemID.SERIAL_LANGUAGE_VERSION_KEY, self.language_version),
           (SystemID.SERIAL_OS_INFO_KEY, self.os_info),
           (SystemID.SERIAL_TOOL_INFO_KEY, self.tool_info),
           (SystemID.SERIAL_PATH_KEY, self.path)
           )
     return ret
Ejemplo n.º 20
0
 def get_server_info(self):
     """Gets a ServerInfo and sends os_info + client version to server"""
     os_info = OSInfo.capture()
     from biicode.common import __version__
     data = (os_info, str(__version__))
     serialized_data = Serializer().build(("data", data))
     info = self.bson_jwt_call('get_server_info',
                               data=serialized_data,
                               deserializer=ServerInfo,
                               timeout=1)
     return info
Ejemplo n.º 21
0
 def serialize(self):
     # TODO Add the rest of attributes
     assert isinstance(self._numeric_id, ID), self._numeric_id.__class__
     return Serializer().build(
         (self.SERIAL_ID_KEY, self._id),
         (self.SERIAL_NUMERIC_ID_KEY, self._numeric_id),
         (self.SERIAL_CELL_TABLE, self._cells_table),
         (self.SERIAL_CONTENT_TABLE, self._contents_table),
         (self.SERIAL_DEPS_TABLE, self._deps_table),
         (self.SERIAL_RENAMES, self._renames),
         (self.SERIAL_DELTAS, self._deltas),
         (self.SERIAL_CELLS_COUNTER, self._cell_count),
         (self.SERIAL_CONTENT_COUNTER, self._content_count))
Ejemplo n.º 22
0
 def serialize(self):
     ret = Serializer().build(
         (PublishRequest.SERIAL_TRACKED_KEY, self.parent),
         (PublishRequest.SERIAL_PARENT_DATETIME, self.parent_time),
         (PublishRequest.SERIAL_TAG_KEY, self.tag),
         (PublishRequest.SERIAL_MSG_KEY, self.msg),
         (PublishRequest.SERIAL_VTAG_KEY, self.versiontag),
         (PublishRequest.SERIAL_CELLS_KEY, self.cells),
         (PublishRequest.SERIAL_CONTENTS_KEY, self.contents),
         (PublishRequest.SERIAL_DELETED_KEY, self.deleted),
         (PublishRequest.SERIAL_RENAMES_KEY, self.renames),
         (PublishRequest.SERIAL_DEP_TABLE, self.deptable),
         (PublishRequest.SERIAL_CONTENTS_ID_KEY, self.contents_ids),
         (PublishRequest.SERIAL_ORIGIN_INFO, self.origin),
     )
     return ret
Ejemplo n.º 23
0
 def serialize(self):
     return Serializer().build(
         (self.SERIAL_ID_KEY, self.ID),
         (self.SERIAL_NUMERIC_ID, self.numeric_id),
         (self.SERIAL_ENCRYPTED_PASSWORD, self._encrypted_password),
         (self.SERIAL_PASSWORD_TIMESTAMP, self.password_timestamp),
         (self.SERIAL_FIRSTNAME, self.firstname),
         (self.SERIAL_LASTNAME, self.lastname),
         (self.SERIAL_COUNTRY, self.country),
         (self.SERIAL_DESCRIPTION, self.description),
         (self.SERIAL_EMAIL, self.email),
         (self.SERIAL_VISIBLE_EMAIL, self.visible_email),
         (self.SERIAL_ALLOW_MAILING, self.allow_mailing),
         (self.SERIAL_ACTIVE, self.active),
         (self.SERIAL_STAFF, self.staff),
         (self.SERIAL_JOINED_DATE, self.joined_date),
         (self.SERIAL_CONFIRMATION_DATE, self.confirmation_date),
         (self.SERIAL_CONFIRMATION_TOKEN, self.confirmation_token),
         # old workspace fields
         (self.SERIAL_MOD_COUNTER, self.block_counter),
         (self.SERIAL_BLOCKS, self.blocks),
         (self.SERIAL_ADMINISTRATORS, self.administrators),
         (self.SERIAL_SOCIAL_ACCOUNTS, self.social_accounts),
         (self.SERIAL_READ_API_COUNTER, self.read_api_counter),
         (self.SERIAL_PUBLISH_COUNTER, self.publish_counter),
         (self.SERIAL_REUSE_COUNTER, self.reuse_counter),
         # Additional profile fields
         (self.SERIAL_STREET1, self.street_1),
         (self.SERIAL_STREET2, self.street_2),
         (self.SERIAL_CITY, self.city),
         (self.SERIAL_POSTAL_CODE, self.postal_code),
         (self.SERIAL_REGION, self.region),
         (self.SERIAL_TAX_ID, self.tax_id),
         (self.SERIAL_VAT, self.vat),
         (self.SERIAL_OAUTH_GITHUB_TOKEN, self.oauth_github_token),
         (self.SERIAL_OAUTH_GOOGLE_TOKEN, self.oauth_google_token),
         (self.SERIAL_MAX_WORKSPACE_SIZE, self.max_workspace_size),
         # Invited by
         (self.SERIAL_INVITED_BY, self.invited_by),
     )
Ejemplo n.º 24
0
 def testObjectWithList(self):
     s = Serializer().build(
                       (None, self.__a),
                       ("d", self.__d)
                     )
     self.assertEqual(s, {'a': 1, 'b': 2, 'd': {'list': ["uno", "dos"]}})
Ejemplo n.º 25
0
 def testEmbed(self):
     s = Serializer().build(
                       (None, self.__a),
                       ("c", self.__c)
                     )
     self.assertEqual(s, {'a': 1, 'b': 2, 'c': {'a': {'a': 1, 'b': 2}, 'b': 2}})
Ejemplo n.º 26
0
 def testKeyRepeatedEmbedding(self):
     self.assertRaises(ValueError,
                        Serializer().build,
                           (None, self.__a),  # Embed DummyA here, "b" key repeated
                           ("b", self.__b)
                          )
Ejemplo n.º 27
0
 def testKeyRepeated(self):
     ''' should raise an exception for a repeated key '''
     self.assertRaises(ValueError,
                       Serializer().build,
                       ("k2", "value2"), ("k", "value3"), ("k2", "value4")
                       )
Ejemplo n.º 28
0
 def serialize(self):
     return  Serializer().build(("list", (self.a, "dos")))
Ejemplo n.º 29
0
 def serialize(self):
     return  Serializer().build(("a", self.a), ("b", self.b))
Ejemplo n.º 30
0
 def testObjectWithComplexList(self):
     s = Serializer().build(
                       (None, self.__a),
                       ("e", self.__e)
                     )
     self.assertEqual(s, {'a': 1, 'b': 2, 'e': {'list': [{'a': 1, 'b': 2}, "dos"]}})