Beispiel #1
0
 def onCreate(self, msg):
     print msg
     if self.errparams(msg): return
     to = urischemes.parse_uri(msg['to'])
     tok = str(uuid.uuid4())
     if msg.attributes.get('location'):
         key = str(urischemes.parse_uri(msg['location']).path.split('/')[-1])
     else:
         key = tok
     if self.cache.has_key(key): # won't create existing entry
         e = messageutils.InfoElement(
             409, fro=MYURL, to=msg['fro'], corrid=msg['corrid'])
         self.xmlstream.send(e)
         return
     self.posttokens[tok] = msg['fro']
     e = messageutils.InfoElement(
         201, fro=MYURL, to=msg['fro'], corrid=msg['corrid'])
     e['location'] = MYURL + '/' + key
     e['posttoken'] = tok
     self.xmlstream.send(e)
     print "sent %s" % e.toXml()
Beispiel #2
0
    def onDelete(self, msg):
        print msg
        if self.errparams(msg): return
        if not self.has_key(msg): # xxx ???
            self.xmlstream.send(self.my404(msg['fro'], msg['corrid']))
            return
        to = urischemes.parse_uri(msg['to'])
        key = str(to.path.split('/')[-1])

        del self.cache[key]
        self.cache.sync()

        e = messageutils.InfoElement(
            204, fro=(MYURL + '/' + key), to=msg['fro'], corrid=msg['corrid'])
        self.xmlstream.send(e)
        print "sent %s" % e.toXml()
Beispiel #3
0
 def onPost(self, msg):
     print msg # xxx statt location to nehmen!
     if self.errparams(msg, rqheaders=['location', 'posttoken']):
         return
     tok = self.posttokens.get(msg['posttoken'])
     if not tok or tok!=msg['fro']:
         self.xmlstream.send(self.my404(msg['fro'], msg['corrid']))
         return
     loc = urischemes.parse_uri(msg['location'])
     key = str(loc.path.split('/')[-1])
     self.cache[key] = str(msg)
     self.cache.sync()
     e = messageutils.InfoElement(
         204, fro=(MYURL + '/' + key), to=msg['fro'], corrid=msg['corrid'])
     self.xmlstream.send(e)
     print "sent %s" % e.toXml()
Beispiel #4
0
 def onPut(self, msg):
     print msg
     if self.errparams(msg): return
     if not self.has_key(msg):
         self.xmlstream.send(self.my404(msg['fro'], msg['corrid']))
         return
     to = urischemes.parse_uri(msg['to'])
     key = str(to.path.split('/')[-1])
     newval = str(msg) # str(Element) retrieves 1st text node
     self.cache[key] = newval
     self.cache.sync()
     e = messageutils.StateElement(fro=msg['to'], to=msg['fro'],
         corrid=msg['corrid'])
     e['status' ] = 201
     self.xmlstream.send(e)
     print "sent %s" % e.toXml()
Beispiel #5
0
 def getpath(self, uri):
     s = urischemes.parse_uri(uri).path
     l = s.split('/')
     l2 = filter(lambda e: e, l)
     return l2