コード例 #1
0
ファイル: head.py プロジェクト: lzimm/360io
def http_POST(req):
    type = req.args.get("type", [None])[0]
    param = req.args.get("param", [None])[0]
    body = req.args.get("body", [None])[0]
    body = cgi.escape(body, quote=True).replace(":", "&#58;").replace("\n", "<br />")
    attached = req.args.get("attached", [None])[0]

    time = datetime.now().isoformat()

    if req.user:
        user = simplejson.dumps(req.user)
        uid = req.user["id"]

    else:
        name = req.args.get("name", [None])[0]
        email = req.args.get("email", [None])[0]
        user = simplejson.dumps({"name": name, "email": email})
        uid = None

    title = req.args.get("title", [None])[0]

    if type:
        res = Deferred()

        def resCb(payload):
            id = num_encode(int(payload))

            params = {"param": param}
            if attached:
                params["attached"] = simplejson.loads(attached)

            jsonParams = simplejson.dumps(params)
            safeBody = simplejson.dumps({"body": body})[len("{'body': \"") : -2]

            def headCb(payload):
                req.result = id

                if uid:
                    log.push("%s/head" % uid, simplejson.dumps({"type": type, "params": params, "body": safeBody}))

                res.callback(None)

            d2 = data.putHead(id, title, type, uid, jsonParams, safeBody, time, user)
            d2.addCallback(headCb)

        d1 = sync.getNext("res")
        d1.addCallback(resCb)

        return res

    else:
        req.result = None
        return None
コード例 #2
0
def http_POST(req):
    type = req.args.get('type', [None])[0]
    param = req.args.get('param', [None])[0]
    body = req.args.get('body', [None])[0]
    body = cgi.escape(body,
                      quote=True).replace(':',
                                          '&#58;').replace('\n', '<br />')
    attached = req.args.get('attached', [None])[0]

    time = datetime.now().isoformat()

    if req.user:
        user = simplejson.dumps(req.user)
        uid = req.user['id']

    else:
        name = req.args.get('name', [None])[0]
        email = req.args.get('email', [None])[0]
        user = simplejson.dumps({'name': name, 'email': email})
        uid = None

    title = req.args.get('title', [None])[0]

    if type:
        res = Deferred()

        def resCb(payload):
            id = num_encode(int(payload))

            params = {'param': param}
            if attached:
                params['attached'] = simplejson.loads(attached)

            jsonParams = simplejson.dumps(params)
            safeBody = simplejson.dumps({'body': body})[len("{'body': \""):-2]

            def headCb(payload):
                req.result = id

                if uid:
                    log.push(
                        "%s/head" % uid,
                        simplejson.dumps({
                            'type': type,
                            'params': params,
                            'body': safeBody
                        }))

                res.callback(None)

            d2 = data.putHead(id, title, type, uid, jsonParams, safeBody, time,
                              user)
            d2.addCallback(headCb)

        d1 = sync.getNext('res')
        d1.addCallback(resCb)

        return res

    else:
        req.result = None
        return None
コード例 #3
0
def http_POST(req):
    pid = req.args.get('pid', [None])[0]
    puid = req.args.get('uid', [None])[0]
    lid = req.args.get('lid', [None])[0]

    type = req.args.get('type', [None])[0]
    param = req.args.get('param', [None])[0]
    body = req.args.get('body', [None])[0]
    body = cgi.escape(body,
                      quote=True).replace(':',
                                          '&#58;').replace('\n', '<br />')
    attached = req.args.get('attached', [None])[0]

    time = datetime.now().isoformat()

    if req.user:
        user = simplejson.dumps(req.user)
        uid = req.user['id']

    else:
        name = req.args.get('name', [None])[0]
        email = req.args.get('email', [None])[0]
        user = simplejson.dumps({'name': name, 'email': email})
        uid = None

    if lid:
        res = Deferred()

        def nextCb(payload):
            id = num_encode(int(payload))
            req.result = id

            params = {'param': param}
            if attached:
                params['attached'] = simplejson.loads(attached)

            jsonParams = simplejson.dumps(params)
            safeBody = simplejson.dumps({'body': body})[len("{'body': \""):-2]

            def tailCb(payload):
                if payload:
                    payload = simplejson.loads(payload)

                broadcast = {
                    'tail': [{
                        'id': id,
                        'parent': pid,
                        'uid': uid,
                        'lid': lid,
                        'user': user,
                        'type': type,
                        'params': params,
                        'body': safeBody,
                        'time': time
                    }],
                    'users': [payload]
                }

                def broadcastCb(payload):
                    if puid:

                        def uidCb(payload):
                            res.callback(None)

                        if puid:
                            log.push(
                                "%s/reply" % uid,
                                simplejson.dumps(
                                    {'reply': broadcast['tail'][0]}))

                        d4 = comm.broadcast(
                            '/user/' + puid,
                            simplejson.dumps({'reply': broadcast}))
                        d4.addCallback(uidCb)

                    else:
                        res.callback(None)

                if uid:
                    log.push("%s/tail" % uid,
                             simplejson.dumps({'tail': broadcast['tail'][0]}))

                d3 = comm.broadcast('/chan/tail_' + lid,
                                    simplejson.dumps({'broadcast': broadcast}))
                d3.addCallback(broadcastCb)

            d2 = data.putTail(lid, id, pid, uid, user, type, jsonParams,
                              safeBody, time)
            d2.addCallback(tailCb)

        d1 = sync.getNext('tail_' + lid)
        d1.addCallback(nextCb)

        return res

    else:
        req.result = None
        return None
コード例 #4
0
ファイル: tail.py プロジェクト: lzimm/360io
def http_POST(req):
    pid = req.args.get('pid', [None])[0]
    puid = req.args.get('uid', [None])[0]
    lid = req.args.get('lid', [None])[0]
    
    type = req.args.get('type', [None])[0]
    param = req.args.get('param', [None])[0]
    body = req.args.get('body', [None])[0]
    body = cgi.escape(body, quote=True).replace(':','&#58;').replace('\n', '<br />')
    attached = req.args.get('attached', [None])[0]
        
    time = datetime.now().isoformat()
    
    if req.user:
        user = simplejson.dumps(req.user)
        uid = req.user['id']

    else:
        name = req.args.get('name', [None])[0]
        email = req.args.get('email', [None])[0]
        user = simplejson.dumps({'name': name, 'email': email})
        uid = None

    if lid:
        res = Deferred()
        
        def nextCb(payload):
            id = num_encode(int(payload))
            req.result = id

            params = {'param': param}
            if attached:
                params['attached'] = simplejson.loads(attached)

            jsonParams = simplejson.dumps(params)
            safeBody = simplejson.dumps({'body': body})[len("{'body': \""):-2]

            def tailCb(payload):
                if payload:
                    payload = simplejson.loads(payload)

                broadcast = {
                    'tail' : [{
                        'id' : id,
                        'parent' : pid,
                        'uid' : uid,
                        'lid' : lid,
                        'user' : user,
                        'type' : type,
                        'params' : params,
                        'body' : safeBody,
                        'time' : time
                    }],

                    'users' : [payload]
                }
                
                def broadcastCb(payload):
                    if puid:
                        def uidCb(payload):
                            res.callback(None)

                        if puid:
                            log.push("%s/reply" % uid, simplejson.dumps({'reply': broadcast['tail'][0]}))
                        
                        d4 = comm.broadcast('/user/' + puid, simplejson.dumps({'reply': broadcast}))
                        d4.addCallback(uidCb)
                                    
                    else:
                        res.callback(None)

                if uid:
                    log.push("%s/tail" % uid, simplejson.dumps({'tail': broadcast['tail'][0]}))
                        
                d3 = comm.broadcast('/chan/tail_' + lid, simplejson.dumps({'broadcast': broadcast}))
                d3.addCallback(broadcastCb)
            
            d2 = data.putTail(lid, id, pid, uid, user, type, jsonParams, safeBody, time)
            d2.addCallback(tailCb)
        
        d1 = sync.getNext('tail_' + lid)
        d1.addCallback(nextCb)
        
        return res
        
    else:
        req.result = None
        return None