python类header()的实例源码

certifier.py 文件源码 项目:CommunityCellularManager 作者: facebookincubator 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def POST(self):
        data = web.input()
        if not ("ident" in data and "csr" in data):
            raise web.BadRequest()

        crt = sign_csr(data.csr, data.ident)
        web.header('Content-Type', "application/json")
        return json.dumps({'certificate': crt})
prediction_api.py 文件源码 项目:tensorflow_recommendation_engine 作者: goodrahstar 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def GET(self):
        web.header('Content-Type','application/json') 

        topic = web.input(value=' ')

        try:
            output = run_model.model(requirement = [topic.value])
        except:
            output = 'Invalid query'
            pass

        return output
webserver.py 文件源码 项目:nupic-history-server 作者: htm-community 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def POST(self):
    global modelCache
    params = json.loads(web.data())
    requestInput = web.input()
    id = requestInput["id"]
    # We will always return the active cells because they are cheap.
    returnSnapshots = [TM_SNAPS.ACT_CELLS]
    from pprint import pprint; pprint(params)
    tm = TM(**params)

    tmFacade = TmFacade(tm, ioClient, modelId=id)

    modelId = tmFacade.getId()
    modelCache[modelId]["tm"] = tmFacade
    modelCache[modelId]["classifier"] = SDRClassifierFactory.create(implementation="py")
    modelCache[modelId]["recordsSeen"] = 0

    print "Created TM {}".format(modelId)

    payload = {
      "meta": {
        "id": modelId,
        "saving": returnSnapshots
      }
    }

    tmState = tmFacade.getState(*returnSnapshots)

    for key in tmState:
      payload[key] = tmState[key]

    web.header("Content-Type", "application/json")
    return json.dumps(payload)
__init__.py 文件源码 项目:layman 作者: CCSS-CZ 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def getFile(self,fileName):
        """Return file itself
        """

        # TODO: set propper Content/type
        try:
            if fileName.find(".shp") or fileName.find(".tab"):
                (path,fn) = os.path.split(fileName)
                old_path = os.path.abspath(os.path.curdir)
                os.chdir(path)
                fn_noext = os.path.splitext(fn)[0]
                from zipfile import ZipFile
                from io import BytesIO
                filelike = BytesIO()
                zipout = ZipFile(filelike,"w")
                for f in os.listdir(os.path.curdir):
                    if f.find(fn_noext) > -1:
                        zipout.write(f)

                zipout.close()
                web.header('Content-Disposition','attachment; filename="%s.zip"'% fn_noext)
                os.chdir(old_path)
                fn_noext = os.path.splitext(fn)[0]
                return (200, filelike.getvalue())
            else:
                return (200, open(fileName).read())

        except Exception as e:
            message = "LayEd: getFile(): Unable to read from the file named '" + fileName + "'. Exception received: " + str(e)
            raise LaymanError(500, message)
website.py 文件源码 项目:Chinese-ChatBot-AIML-Web.py 作者: JingLuo05 项目源码 文件源码 阅读 14 收藏 0 点赞 0 评论 0
def POST(self):
        form = formA()
        self.new_question = question
        if not form.validates():
            return render.add(question, form)
        else:
            new_answer = form['Answer'].value
            web.header('Content-Type','text/html; charset=utf-8', unique=True)
            print self.new_question
            global after_question
            robot.addAnswer(after_question, new_answer)
            raise web.seeother('/')
objectstore.py 文件源码 项目:rucio 作者: rucio01 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def GET(self, url, rse, operation):
        """
        GET redirect URL.

        HTTP Success:
            200 OK

        HTTP Error:
            401 Unauthorized
            500 InternalError

        :returns: A URL refering to the file.
        """

        # header('Access-Control-Allow-Origin', ctx.env.get('HTTP_ORIGIN'))
        # header('Access-Control-Allow-Headers', ctx.env.get('HTTP_ACCESS_CONTROL_REQUEST_HEADERS'))
        # header('Access-Control-Allow-Methods', '*')
        # header('Access-Control-Allow-Credentials', 'true')

        try:
            pos = url.index('/')
            url = ''.join([url[:pos], '/', url[pos:]])

            if operation == 'connect':
                objectstore.connect(rse, url)
            else:
                result = objectstore.get_signed_urls([url], rse=rse, operation=operation)
                if isinstance(result[url], Exception):
                    raise result[url]
                return result[url]
        except RucioException, e:
            raise generate_http_error(500, e.__class__.__name__, e.args[0])
        except Exception, e:
            print traceback.format_exc()
            raise InternalError(e)
        raise OK()
objectstore.py 文件源码 项目:rucio 作者: rucio01 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def POST(self, rse, operation):
        """
        Get URLs for files at a given RSE.

        HTTP Success:
            200 OK

        HTTP Error:
            401 Unauthorized
            500 Internal Error
        """
        header('Content-Type', 'application/json')
        json_data = data()
        try:
            parameters = parse_response(json_data)
        except ValueError:
            raise generate_http_error(400, 'ValueError', 'Cannot decode json parameter list')

        try:
            result = objectstore.get_signed_urls(parameters, rse=rse, operation=operation)
            for url in result:
                if isinstance(result[url], Exception):
                    raise result[url]
            return render_json(**result)
        except RucioException, e:
            raise generate_http_error(500, e.__class__.__name__, e.args[0][0])
        except Exception, e:
            print traceback.format_exc()
            raise InternalError(e)
objectstore.py 文件源码 项目:rucio 作者: rucio01 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def POST(self, rse):
        """
        Get files metadata at a given RSE.

        HTTP Success:
            200 OK

        HTTP Error:
            401 Unauthorized
            500 Internal Error
        """
        header('Content-Type', 'application/json')
        json_data = data()
        try:
            parameters = parse_response(json_data)
        except ValueError:
            raise generate_http_error(400, 'ValueError', 'Cannot decode json parameter list')

        try:
            result = objectstore.get_metadata(parameters, rse=rse)
            for url in result:
                if isinstance(result[url], Exception):
                    raise result[url]
            return render_json(**result)
        except RucioException, e:
            raise generate_http_error(500, e.__class__.__name__, e.args[0][0])
        except Exception, e:
            print traceback.format_exc()
            raise InternalError(e)
objectstore.py 文件源码 项目:rucio 作者: rucio01 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def POST(self, rse):
        """
        Get files metadata at a given RSE.

        HTTP Success:
            200 OK

        HTTP Error:
            401 Unauthorized
            500 Internal Error
        """
        header('Content-Type', 'application/json')
        json_data = data()
        try:
            parameters = parse_response(json_data)
        except ValueError:
            raise generate_http_error(400, 'ValueError', 'Cannot decode json parameter list')

        try:
            url = parameters['url']
            new_url = parameters['new_url']
            objectstore.rename(url, new_url, rse=rse)
        except RucioException, e:
            raise generate_http_error(500, e.__class__.__name__, e.args[0][0])
        except Exception, e:
            print traceback.format_exc()
            raise InternalError(e)

        raise OK()


# ----------------------
#   Web service startup
# ----------------------
server.py 文件源码 项目:CloudPrint 作者: William-An 项目源码 文件源码 阅读 15 收藏 0 点赞 0 评论 0
def GET(self):
        web.header("Content-Type","text/html; charset=utf-8")
        render = web.template.render('static/')
        return render.index()
pwt.py 文件源码 项目:py-script 作者: xiaoxiamin 项目源码 文件源码 阅读 15 收藏 0 点赞 0 评论 0
def GET(self):
        web.header('Content-Type', 'text/html')
        print self.page % self.form()
pwt.py 文件源码 项目:py-script 作者: xiaoxiamin 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def POST(self):
        i = web.input()
        if '_' in i: del i['_']
        #for k, v in i.iteritems(): setattr(self, k, v)

        self._inFunc = True
        self.work(**i)
        self._inFunc = False

        web.header('Content-Type', 'text/javascript')
        print 'receive('+simplejson.dumps(self.updated)+');'
app.py 文件源码 项目:lc_cloud 作者: refractionPOINT 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def jsonApi( f ):
    ''' Decorator to basic exception handling on function. '''
    @wraps( f )
    def wrapped( *args, **kwargs ):
        web.header( 'Content-Type', 'application/json' )
        r = f( *args, **kwargs )
        try:
            return dumpJson( r )
        except:
            return dumpJson( { 'error' : str( r ) } )
    return wrapped
app.py 文件源码 项目:lc_cloud 作者: refractionPOINT 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def msgpackApi( f ):
    ''' Decorator to basic exception handling on function. '''
    @wraps( f )
    def wrapped( *args, **kwargs ):
        web.header( 'Content-Type', 'application/msgpack' )
        r = f( *args, **kwargs )
        try:
            return msgpack.packb( r )
        except:
            return msgpack.packb( { 'error' : str( r ) } )
    return wrapped
app.py 文件源码 项目:lc_cloud 作者: refractionPOINT 项目源码 文件源码 阅读 15 收藏 0 点赞 0 评论 0
def jsonData( data ):
    web.header( 'Content-Type', 'application/json' )
    return dumpJson( data )
app.py 文件源码 项目:lc_cloud 作者: refractionPOINT 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def msgpackData( data ):
    web.header( 'Content-Type', 'application/msgpack' )
    return msgpack.packb( data )
app.py 文件源码 项目:lc_cloud 作者: refractionPOINT 项目源码 文件源码 阅读 15 收藏 0 点赞 0 评论 0
def GET( self ):
        web.header( 'Content-Type', 'application/json' )
        params = web.input( sid = None )

        sensorInfo = getSiteFor( params.sid )
        if sensorInfo is None:
            raise web.HTTPError( '404 Not Found: sensor not found' )

        sensorInfo, site = sensorInfo

        after = int( time.time() - 5 )
        eventCache = RingCache( maxEntries = 100, isAutoAdd = True )

        while True:
            now = int( time.time() )
            newest = 0
            res = querySite( 'models', 'get_timeline', 
                             { 'id' : sensorInfo[ 'id' ],
                               'is_include_content' : True,
                               'after' : after }, defaultSiteProc, site, {} )

            for r in res[ 'events' ]:
                if r[ 2 ] not in eventCache:
                    yield dumpJson( sanitizeJson( r[ 3 ] ) )
                eventTime = int( r[ 0 ] / 1000 )
                if eventTime < now + 30 and eventTime > newest:
                    newest = eventTime

            if 0 != newest:
                after = newest - 1
            gevent.sleep( 2 )
app.py 文件源码 项目:lc_cloud 作者: refractionPOINT 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def setDownloadFileName( name ):
    web.header( 'Content-Disposition', 'attachment;filename="%s"' % name )
app.py 文件源码 项目:lc_cloud 作者: refractionPOINT 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def fileDownload( f ):
    ''' Decorator to basic exception handling on function. '''
    @wraps( f )
    def wrapped( *args, **kwargs ):
        web.header( 'Content-Type', 'application/octet-stream' )
        return f( *args, **kwargs )
    return wrapped

#==============================================================================
#   PAGES
#==============================================================================
pwt.py 文件源码 项目:lantern-detection 作者: gongxijun 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def GET(self):
        web.header('Content-Type', 'text/html')
        print self.page % self.form()


问题


面经


文章

微信
公众号

扫码关注公众号