Example #1
0
    def __init__(self, sd_id, sd_params):
        """
        **arguments**
            *sd_id*
                SD-IDs are case-sensitive and uniquely identify the type and purpose
                of the SD-ELEMENT.

            *sd_params*
                Key/value pairs attached to this SD-ELEMENT. This can be any iterable
                that yields tuples, a dict or a :class:`~loggerglue.utils.multidict.OrderedMultiDict`
                (An SD-PARAM key may be repeated multiple times inside an SD-ELEMENT)

        **attributes**
            *id*
                SD-ID for this structured data element.

            *sd_params*
                Key/value pairs attached to this SD-ELEMENT, represented as
                a OrderedMultiDict.

            *params*
                Key/value pairs attached to this SD-ELEMENT, represented as
                a class instance (for convenience, so that parameters can
                be addressed with `elmt.params.origin`). If there are multiple
                values for a key, the *last* element is returned.

        """
        self.id = sd_id
        self.sd_params = OrderedMultiDict(sd_params)
        self.params = Params(self.sd_params)
Example #2
0
    def __init__(self, sd_id, sd_params):
        """
        **arguments**
            *sd_id*
                SD-IDs are case-sensitive and uniquely identify the type and purpose
                of the SD-ELEMENT.

            *sd_params*
                Key/value pairs attached to this SD-ELEMENT. This can be any iterable
                that yields tuples, a dict or a :class:`~loggerglue.utils.multidict.OrderedMultiDict`
                (An SD-PARAM key may be repeated multiple times inside an SD-ELEMENT)

        **attributes**
            *id*
                SD-ID for this structured data element.

            *sd_params*
                Key/value pairs attached to this SD-ELEMENT, represented as
                a OrderedMultiDict.

            *params*
                Key/value pairs attached to this SD-ELEMENT, represented as
                a class instance (for convenience, so that parameters can
                be addressed with `elmt.params.origin`). If there are multiple
                values for a key, the *last* element is returned.

        """
        self.id = sd_id
        self.sd_params = OrderedMultiDict(sd_params)
        self.params = Params(self.sd_params)
Example #3
0
 def test_init_with_dict(self):
     e = SDElement('exampleSDID@32473', {'param1': 1, 'param2': 2})
     self.assertEqual('exampleSDID@32473', e.id)
     self.assertEqual(OrderedMultiDict({
         'param1': 1,
         'param2': 2
     }), e.sd_params)
Example #4
0
 def parse(cls, parsed):
     sd = getattr(parsed, 'STRUCTURED_DATA', None)
     if sd is None or sd == '-':
         return None
     sd_id = parsed.STRUCTURED_DATA.SD_ID
     params = OrderedMultiDict()
     for i in parsed.STRUCTURED_DATA.SD_PARAMS:
         params[i.SD_PARAM.SD_PARAM_NAME] = \
                 i.SD_PARAM.SD_PARAM_VALUE.decode('utf-8')
     return StructuredData(sd_id, params)
Example #5
0
class SDElement(object):
    """
    An SD-ELEMENT consists of a name and parameter name-value pairs.
    """

    def __init__(self, sd_id, sd_params):
        """
        **arguments**
            *sd_id*
                SD-IDs are case-sensitive and uniquely identify the type and purpose
                of the SD-ELEMENT.

            *sd_params*
                Key/value pairs attached to this SD-ELEMENT. This can be any iterable
                that yields tuples, a dict or a :class:`~loggerglue.utils.multidict.OrderedMultiDict`
                (An SD-PARAM key may be repeated multiple times inside an SD-ELEMENT)

        **attributes**
            *id*
                SD-ID for this structured data element.

            *sd_params*
                Key/value pairs attached to this SD-ELEMENT, represented as
                a OrderedMultiDict.

            *params*
                Key/value pairs attached to this SD-ELEMENT, represented as
                a class instance (for convenience, so that parameters can
                be addressed with `elmt.params.origin`). If there are multiple
                values for a key, the *last* element is returned.

        """
        self.id = sd_id
        self.sd_params = OrderedMultiDict(sd_params)
        self.params = Params(self.sd_params)

    def __str__(self):
        """Convert SDElement to formatted string"""
        rv = ["[", self.id]
        for (k, v) in self.sd_params.allitems():
            rv += [" ", k, '="', escape_param_value(unicode(v)), '"']
        rv += ["]"]
        return "".join(rv)

    @classmethod
    def parse(cls, parsed):
        sd = getattr(parsed, "STRUCTURED_DATA", None)
        if sd is None or sd == "-":
            return None
        sd_id = parsed.STRUCTURED_DATA.SD_ID
        params = OrderedMultiDict()
        for i in parsed.STRUCTURED_DATA.SD_PARAMS:
            params[i.SD_PARAM.SD_PARAM_NAME] = i.SD_PARAM.SD_PARAM_VALUE.decode("utf-8")
        return StructuredData(sd_id, params)
Example #6
0
class SDElement(object):
    """
    An SD-ELEMENT consists of a name and parameter name-value pairs.
    """
    def __init__(self, sd_id, sd_params):
        """
        **arguments**
            *sd_id*
                SD-IDs are case-sensitive and uniquely identify the type and purpose
                of the SD-ELEMENT.

            *sd_params*
                Key/value pairs attached to this SD-ELEMENT. This can be any iterable
                that yields tuples, a dict or a :class:`~loggerglue.utils.multidict.OrderedMultiDict`
                (An SD-PARAM key may be repeated multiple times inside an SD-ELEMENT)

        **attributes**
            *id*
                SD-ID for this structured data element.

            *sd_params*
                Key/value pairs attached to this SD-ELEMENT, represented as
                a OrderedMultiDict.

            *params*
                Key/value pairs attached to this SD-ELEMENT, represented as
                a class instance (for convenience, so that parameters can
                be addressed with `elmt.params.origin`). If there are multiple
                values for a key, the *last* element is returned.

        """
        self.id = sd_id
        self.sd_params = OrderedMultiDict(sd_params)
        self.params = Params(self.sd_params)

    def __str__(self):
        """Convert SDElement to formatted string"""
        rv = ['[', self.id]
        for (k,v) in self.sd_params.allitems():
            rv += [' ',k,'="',escape_param_value(unicode(v)),'"']
        rv += [']']
        return ''.join(rv)

    @classmethod
    def parse(cls, parsed):
        sd = getattr(parsed, 'STRUCTURED_DATA', None)
        if sd is None or sd == '-':
            return None
        sd_id = parsed.STRUCTURED_DATA.SD_ID
        params = OrderedMultiDict()
        for i in parsed.STRUCTURED_DATA.SD_PARAMS:
            params[i.SD_PARAM.SD_PARAM_NAME] = \
                    i.SD_PARAM.SD_PARAM_VALUE.decode('utf-8')
        return StructuredData(sd_id, params)
Example #7
0
 def parse(cls, parsed):
     sd = getattr(parsed, 'STRUCTURED_DATA', None)
     if sd is None or sd == '-':
         return None
     elements = []
     for se in parsed.SD_ELEMENTS:
         sd_id = se.SD_ID
         params = OrderedMultiDict()
         for i in se.SD_PARAMS:
             params[i.SD_PARAM.SD_PARAM_NAME] = \
                     i.SD_PARAM.SD_PARAM_VALUE.decode('utf-8')
         elements.append(SDElement(sd_id, params))
     return StructuredData(elements)
Example #8
0
    def parse(cls, parsed):
        sd = getattr(parsed, 'STRUCTURED_DATA', None)
        if sd is None or sd == '-':
            return None

        # Don't know what is changed in py3 version, but according to unittest
        # it returns non-string value.
        if list(sd) == ['-']:
            return None

        sd_id = parsed.STRUCTURED_DATA.SD_ID
        params = OrderedMultiDict()
        for i in parsed.STRUCTURED_DATA.SD_PARAMS:
            value = i.SD_PARAM.SD_PARAM_VALUE
            if isinstance(value, bytes):
                value = value.decode('utf-8')
            params[i.SD_PARAM.SD_PARAM_NAME] = value
        return StructuredData(sd_id, params)
Example #9
0
 def test_init_with_tuples(self):
     e = SDElement('exampleSDID@32473', [('param1', 1), ('param2', 2)])
     self.assertEqual('exampleSDID@32473', e.id)
     self.assertEqual(OrderedMultiDict([('param1', 1), ('param2', 2)]),
                      e.sd_params)
     self.assertEqual('[exampleSDID@32473 param1="1" param2="2"]', str(e))