http.py 文件源码

python
阅读 35 收藏 0 点赞 0 评论 0

项目:dsq 作者: baverman 项目源码 文件源码
def push(self, environ):
        ct = environ.get('CONTENT_TYPE')
        stream = environ['wsgi.input']
        content = stream.read(int(environ['CONTENT_LENGTH']))
        if ct == 'application/json':
            try:
                task = json.loads(content if PY2 else content.decode('utf-8'))
            except:
                return Error('400 BAD REQUEST', 'invalid-encoding', 'Can\'t decode body')
        elif ct == 'application/x-msgpack':
            try:
                task = msgpack.loads(content, encoding='utf-8')
            except:
                return Error('400 BAD REQUEST', 'invalid-encoding', 'Can\'t decode body')
        else:
            return Error('400 BAD REQUEST', 'invalid-content-type',
                         'Content must be json or msgpack')

        if not task.get('queue'):
            return Error('400 BAD REQUEST', 'bad-params', 'queue required')

        if not task.get('name'):
            return Error('400 BAD REQUEST', 'bad-params', 'name required')

        return {'id': self.manager.push(**task).id}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号