當前位置: 首頁>>代碼示例>>Python>>正文


Python Response.content_type方法代碼示例

本文整理匯總了Python中werkzeug.Response.content_type方法的典型用法代碼示例。如果您正苦於以下問題:Python Response.content_type方法的具體用法?Python Response.content_type怎麽用?Python Response.content_type使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在werkzeug.Response的用法示例。


在下文中一共展示了Response.content_type方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __call__

# 需要導入模塊: from werkzeug import Response [as 別名]
# 或者: from werkzeug.Response import content_type [as 別名]
 def __call__(self, env, start_response):
     Config = ConfigParser()
     Config.read(configfile)
     params = {"host": "", "user": "", "database": "", "port": ""}
     for param in params:
         if not Config.has_option("BlobStore", param):
             print "Malformed configuration file: mission option %s in section %s" % (param, "BlobStore")
             sys.exit(1)
         params[param] = Config.get("BlobStore", param)
     req = Request(env)
     resp = Response(status=200, content_type="text/plain")
     #engine = create_engine("mysql+mysqldb://%s:%[email protected]%s:%s/%s?charset=utf8&use_unicode=0" %
     #    (params["user"], secret.BlobSecret, params["host"], params["port"], params["database"]), pool_recycle=3600)
     Base = declarative_base(bind=engine)
     local.Session = []
     local.FileEntry = []
     Session.append(sessionmaker(bind=engine))
     FileEntry.append(makeFileEntry(Base))
     if req.path.startswith('/fx'):
         if req.method == "GET":
             resp.status_code, filename, resp.content_type, resp.response = self.__download(req)
             if resp.content_type == "application/octet-stream":
                 resp.headers["Content-Disposition"] = "attachment; filename=%s" % filename
             return resp(env, start_response)
         elif req.method == "POST":
             resp.content_type="text/plain"
             resp.response = self.__upload(req)
             return resp(env, start_response)
     else:
         resp.status_code = 404
         resp.content_type="text/plain"
         resp.response = ""
         return resp(env, start_response)
開發者ID:dpq,項目名稱:spooce,代碼行數:35,代碼來源:blob.py

示例2: serve_file

# 需要導入模塊: from werkzeug import Response [as 別名]
# 或者: from werkzeug.Response import content_type [as 別名]
def serve_file(file, content_type=None):
    # Reset the stream
    file.seek(0)
    resp = Response(FileWrapper(file), direct_passthrough=True)

    if content_type is None:
        resp.content_type = file.content_type
    else:
        resp.content_type = content_type

    return resp
開發者ID:smokey42,項目名稱:PhotoBlog,代碼行數:13,代碼來源:images.py

示例3: __call__

# 需要導入模塊: from werkzeug import Response [as 別名]
# 或者: from werkzeug.Response import content_type [as 別名]
 def __call__(self, env, start_response):
     req = Request(env)
     Config = ConfigParser()
     Config.read(configfile)
     params = {"host": "", "user": "", "database": "", "port": ""}
     for param in params:
         if not Config.has_option("MySQL", param):
             print "Malformed configuration file: mission option %s in section MySQL" % (param)
             sys.exit(1)
         params[param] = Config.get("MySQL", param)    
     #engine = create_engine("mysql+mysqldb://%s:%[email protected]%s:%s/%s?charset=utf8&use_unicode=0" %
     #    (params["user"], secret.MySQL, params["host"], params["port"], params["database"]), pool_recycle=3600)
     Base = declarative_base(bind=engine)
     local.Session = []
     local.User = []
     local.MethodEmail = []
     local.Session.append(sessionmaker(bind=engine))
     local.User.append(makeUser(Base))
     local.MethodEmail.append(makeMethodEmail(Base))
     resp = Response(status=200)
     if req.path == '/register':
         resp.content_type = "text/html"
         resp.response = self.__register(req)
         return resp(env, start_response)
     elif req.path == '/regemail1':
         resp.content_type = "text/html"
         resp.response = self.__addEmailAuth1(req)
         return resp(env, start_response)
     elif req.path == '/regemail2':
         resp.content_type = "text/html"
         resp.response = self.__addEmailAuth2(req)
         return resp(env, start_response)
     elif req.path == '/regemail3':
         resp.content_type = "text/html"
         resp.response = self.__addEmailAuth3(req)
         return resp(env, start_response)
     elif req.path == '/regemailkill':
         resp.content_type = "text/html"
         resp.response = self.__removeEmailAuth(req)
         return resp(env, start_response)
     elif req.path == '/regemaillist':
         resp.content_type = "text/plain"
         resp.response = self.__listEmailAuth(req)
         return resp(env, start_response)
     elif req.path == '/auth' and req.values.has_key("email") and req.values.has_key("password"):
         resp.content_type = "text/plain"
         resp.response = [self.__authenticateByEmail(req)]
         return resp(env, start_response)
     elif req.path == '/auth' and req.values.has_key("uid"):
         resp.content_type = "text/plain"
         uid = self.__uid(req)
         if uid == None:
             uid = ""
         resp.response = [uid]
         return resp(env, start_response)
     else:
         resp.status_code = 404
         resp.response = [""]
         return resp(env, start_response)
開發者ID:dpq,項目名稱:spooce,代碼行數:61,代碼來源:warden.py

示例4: __call__

# 需要導入模塊: from werkzeug import Response [as 別名]
# 或者: from werkzeug.Response import content_type [as 別名]
    def __call__(self, environ, start_response):
        local.application = self
        request = MongoRequest(environ)
        local.url_adapter = adapter = url_map.bind_to_environ(environ)
        environ['mongo.db'] = self.db
        environ['mongo.fs'] = self.fs
        try:
            endpoint, values = adapter.match()
            handler = getattr(views, endpoint)
            data = handler(request, **values)

            # WSGI
            if callable(data):
                return data(environ, start_response)

            data = safe_keys(data)

            data['request'] = request

            # Templates
            template = self.env.get_template("%s.html" % endpoint)
            response = Response()
            response.content_type = "text/html"
            response.add_etag()
            # if DEBUG:
            #   response.make_conditional(request)
            data['endpoint'] = endpoint
            response.data = template.render(**data)
        except HTTPException, e:
            response = e
開發者ID:smokey42,項目名稱:PhotoBlog,代碼行數:32,代碼來源:app.py

示例5: miku

# 需要導入模塊: from werkzeug import Response [as 別名]
# 或者: from werkzeug.Response import content_type [as 別名]
def miku(request):
  data = request.files['image'].stream.read()
  img =  HomeImage.split(images.Image(data))[0]
  png = img.execute_transforms(output_encoding=images.PNG)
  r = Response()
  r.content_type = 'image/png'
  r.data = png
  return r
開發者ID:mzp,項目名稱:home-image,代碼行數:10,代碼來源:views.py

示例6: application

# 需要導入模塊: from werkzeug import Response [as 別名]
# 或者: from werkzeug.Response import content_type [as 別名]
def application(req):
    if req.method == 'POST':
        file_in = req.files['myfile']
        buf = convert_doc(file_in)

        filename = file_in.filename.replace('.odt', '-converted.odt')
        resp = Response(buf.getvalue())
        resp.content_type = 'application/x-download'
        resp.headers.add('Content-Disposition', 'attachment', filename=filename)
        return resp
    return Response(HTML, content_type='text/html')
開發者ID:gdamjan,項目名稱:convertor,代碼行數:13,代碼來源:web_app.py

示例7: __call__

# 需要導入模塊: from werkzeug import Response [as 別名]
# 或者: from werkzeug.Response import content_type [as 別名]
 def __call__(self, env, start_response):
     req = Request(env)
     Config = ConfigParser()
     Config.read(configfile)
     params = {"host": "", "user": "", "database": "", "port": ""}
     for param in params:
         if not Config.has_option("MySQL", param):
             print "Malformed configuration file: mission option %s in section MySQL" % (param)
             sys.exit(1)
         params[param] = Config.get("MySQL", param)
     #print params
     #engine = create_engine("mysql+mysqldb://%s:%[email protected]%s:%s/%s?charset=utf8&use_unicode=0" %
     #    (params["user"], secret.MySQL, params["host"], params["port"], params["database"]), pool_recycle=3600)
     Base = declarative_base(bind=engine)
     local.Session = []
     local.Package = []
     local.Session.append(sessionmaker(bind=engine))
     local.Package.append(makePackage(Base))
     resp = Response(status=200, content_type="text/plain")
     if req.path == '/pkg/upload':
         resp.content_type="text/html"
         resp.response = self.__upload(req)
         return resp(env, start_response)
     elif req.path == '/pkg/sdk':
         resp.content_disposition="application/force-download"
         resp.content_type="application/python"
         resp.headers.add("Content-Disposition", "attachment; filename=appcfg.py")
         f = open("appcfg.py").read().replace("__REPO_UPLOAD__", '"%s"' % (req.host_url + 'pkg/upload'))
         resp.headers.add("Content-Length", str(len(f)))
         resp.response = [f]
         return resp(env, start_response)
     elif req.path.startswith('/pkg'):
         resp.status_code, resp.content_encoding, resp.response = self.__download(req)
         return resp(env, start_response)
     else:
         resp.status_code = 404
         resp.response = [""]
         return resp(env, start_response)
開發者ID:dpq,項目名稱:spooce,代碼行數:40,代碼來源:repo.py

示例8: serve_pil

# 需要導入模塊: from werkzeug import Response [as 別名]
# 或者: from werkzeug.Response import content_type [as 別名]
def serve_pil(image, extension):
    resp = Response()
    resp.content_type = mimetypes.guess_type(extension)
    image.save(resp.stream, extension)
    return resp
開發者ID:smokey42,項目名稱:PhotoBlog,代碼行數:7,代碼來源:images.py


注:本文中的werkzeug.Response.content_type方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。