/usr/share/pyshared/jsb/lib/container.py is in jsonbot 0.84.4-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | # jsb/container.py
#
#
""" container for bot to bot communication. """
__version__ = "1"
## jsb imports
from jsb.lib.persist import Persist
from jsb.utils.name import stripname
from jsb.lib.gozerevent import GozerEvent
from jsb.imports import getjson
## xmpp import
from jsb.contrib.xmlstream import NodeBuilder, XMLescape, XMLunescape
## basic imports
import hmac
import uuid
import time
import hashlib
## defines
idattributes = ['createtime', 'origin', 'type', 'idtime', 'payload']
## functions
def getid(container):
name = ""
for attr in idattributes:
try: name += str(container[attr])
except KeyError: pass
return uuid.uuid3(uuid.NAMESPACE_URL, name).hex
## classes
class Container(GozerEvent):
""" Container for bot to bot communication. Provides a hmac id that can be checked. """
def __init__(self, origin=None, payload=None, type="event", key=None, how="direct"):
GozerEvent.__init__(self)
self.createtime = time.time()
self.origin = origin
self.type = str(type)
self.payload = payload
self.makeid()
if key: self.makehmac(key)
else: self.makehmac(self.id)
def makeid(self):
self.idtime = time.time()
self.id = getid(self)
def makehmac(self, key):
self.hash = "sha512"
self.hashkey = key
self.digest = hmac.new(key, self.payload, hashlib.sha512).hexdigest()
def save(self, attributes=[]):
target = {}
if attributes:
for key in attributes: target[key] = self[key]
else: target = cpy(self)
targetfile = getdatadir() + os.sep + "containers" + os.sep + str(self.createtime) + "_" + stripname(self.origin)
p = Persist(targetfile)
p.data = getjson().dumps(target)
p.save()
|