Beispiel #1
0
 def default(self, obj):
     if isinstance(obj, timedelta):
         return timedeltaformat(obj)
     if isinstance(obj, datetime):
         return datetimeformat(obj)
     if isinstance(obj, bool):
         return booleanformat(obj)
     return json.JSONEncoder.default(self, obj)
Beispiel #2
0
def _create_replay_protect():
    dt_element = Element("{http://openadr.org/oadr-2.0b/2012/07/xmldsig-properties}timestamp")
    dt_element.text = utils.datetimeformat(datetime.now(timezone.utc))

    nonce_element = Element("{http://openadr.org/oadr-2.0b/2012/07/xmldsig-properties}nonce")
    nonce_element.text = uuid4().hex

    el = Element("{http://openadr.org/oadr-2.0b/2012/07/xmldsig-properties}ReplayProtect",
                 nsmap={'dsp': 'http://openadr.org/oadr-2.0b/2012/07/xmldsig-properties'},
                 attrib={'Id': 'myid', 'Target': '#mytarget'})
    el.append(dt_element)
    el.append(nonce_element)
    return el