当前位置: 首页>>代码示例>>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;未经允许,请勿转载。