コード例 #1
0
    def novabase_to_dict(ref):
        request_uuid = uuid.uuid1()
        encoder = Encoder(request_uuid=request_uuid)
        decoder = Decoder(request_uuid=request_uuid)

        json_object = encoder.simplify(ref)
        json_object.pop("_metadata_novabase_classname")

        return decoder.desimplify(json_object)
コード例 #2
0
    def novabase_to_dict(ref):
        request_uuid = uuid.uuid1()
        encoder = Encoder(request_uuid=request_uuid)
        decoder = Decoder(request_uuid=request_uuid)

        json_object = encoder.simplify(ref)
        json_object.pop("_metadata_novabase_classname")

        return decoder.desimplify(json_object)
コード例 #3
0
ファイル: string.py プロジェクト: Gayout/rome
class Decoder(object):
    """Class that translate an object containing values taken from database
    into an object containing values understandable by services composing
    Nova."""

    def __init__(self, request_uuid=uuid.uuid1()):
        self.json_decoder = JsonDecoder(request_uuid)
        self.cache = self.json_decoder.cache

    def desimplify(self, obj):
        is_dict = isinstance(obj, dict)
        is_list = isinstance(obj, list)
        is_tuple = isinstance(obj, tuple)
        if is_list:
            result = []
            for item in obj:
                result += [self.desimplify(item)]
        elif is_tuple:
            result = map(lambda x: self.desimplify(x), obj)
        elif is_dict and obj.has_key("novabase_classname"):
            result = self.json_decoder.novabase_desimplify(obj)
        elif is_dict and obj.has_key("metadata_novabase_classname"):
            result = self.json_decoder.novabase_desimplify(obj)
        elif is_dict:
            result = {}
            for item in obj:
                result[item] = self.desimplify(obj[item])
        else:
            if (isinstance(obj, str) or isinstance(obj, unicode) )and "{separator}" in obj:
                tabs = obj.split("{separator}")
                if len(tabs) == 2:
                    string_strategy = tabs[0]
                    value = tabs[1]
                    obj = eval(value)
                    if "datetime" in string_strategy:
                        result = self.json_decoder.datetime_desimplify(obj)
                    elif "ipnetwork" in string_strategy:
                        result = self.json_decoder.ipnetwork_desimplify(obj)
                    elif "novabase" in string_strategy:
                        result = self.json_decoder.novabase_desimplify(obj)
                    elif "list" in string_strategy:
                        result = self.json_decoder.desimplify(obj)
                    elif "dict" in string_strategy:
                        result = self.json_decoder.desimplify(obj)
                    else:
                        result = self.json_decoder.desimplify(obj)
            else:
                result = self.json_decoder.desimplify(obj)
        return result
コード例 #4
0
class Decoder(object):
    """Class that translate an object containing values taken from database
    into an object containing values understandable by services composing
    Nova."""

    def __init__(self, request_uuid=uuid.uuid1()):
        self.json_decoder = JsonDecoder(request_uuid)
        self.cache = self.json_decoder.cache

    def desimplify(self, obj):
        is_dict = isinstance(obj, dict)
        is_list = isinstance(obj, list)
        is_tuple = isinstance(obj, tuple)
        if is_list:
            result = []
            for item in obj:
                result += [self.desimplify(item)]
        elif is_tuple:
            result = map(lambda x: self.desimplify(x), obj)
        elif is_dict and obj.has_key("novabase_classname"):
            result = self.json_decoder.novabase_desimplify(obj)
        elif is_dict and obj.has_key("_metadata_novabase_classname"):
            result = self.json_decoder.novabase_desimplify(obj)
        elif is_dict:
            result = {}
            for item in obj:
                result[item] = self.desimplify(obj[item])
        else:
            if (isinstance(obj, str) or isinstance(obj, unicode) )and "{separator}" in obj:
                tabs = obj.split("{separator}")
                if len(tabs) == 2:
                    string_strategy = tabs[0]
                    value = tabs[1]
                    obj = eval(value)
                    if "datetime" in string_strategy:
                        result = self.json_decoder.datetime_desimplify(obj)
                    elif "ipnetwork" in string_strategy:
                        result = self.json_decoder.ipnetwork_desimplify(obj)
                    elif "novabase" in string_strategy:
                        result = self.json_decoder.novabase_desimplify(obj)
                    elif "list" in string_strategy:
                        result = self.json_decoder.desimplify(obj)
                    elif "dict" in string_strategy:
                        result = self.json_decoder.desimplify(obj)
                    else:
                        result = self.json_decoder.desimplify(obj)
            else:
                result = self.json_decoder.desimplify(obj)
        return result
コード例 #5
0
ファイル: string.py プロジェクト: Gayout/rome
 def __init__(self, request_uuid=uuid.uuid1()):
     self.json_decoder = JsonDecoder(request_uuid)
     self.cache = self.json_decoder.cache
コード例 #6
0
 def __init__(self, request_uuid=uuid.uuid1()):
     self.json_decoder = JsonDecoder(request_uuid)
     self.cache = self.json_decoder.cache
コード例 #7
0
ファイル: __init__.py プロジェクト: msimonin/rome
def get_decoder(request_uuid=uuid.uuid1()):
    # if get_config().backend() == "cassandra":
    #     from lib.rome.core.dataformat.string import Decoder
    # else:
    from lib.rome.core.dataformat.json import Decoder
    return Decoder(request_uuid)