当前位置: 首页>>代码示例>>Python>>正文


Python cherrypy.request方法代码示例

本文整理汇总了Python中cherrypy.request方法的典型用法代码示例。如果您正苦于以下问题:Python cherrypy.request方法的具体用法?Python cherrypy.request怎么用?Python cherrypy.request使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cherrypy的用法示例。


在下文中一共展示了cherrypy.request方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import request [as 别名]
def __init__(self, path, query_string=''):
        self.request = cherrypy.serving.request

        self.query_string = query_string
        if '?' in path:
            # Separate any params included in the path
            path, self.query_string = path.split('?', 1)

        # Note that urljoin will "do the right thing" whether url is:
        #  1. a URL relative to root (e.g. "/dummy")
        #  2. a URL relative to the current path
        # Note that any query string will be discarded.
        path = urllib.parse.urljoin(self.request.path_info, path)

        # Set a 'path' member attribute so that code which traps this
        # error can have access to it.
        self.path = path

        CherryPyException.__init__(self, path, self.query_string) 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:21,代码来源:_cperror.py

示例2: set_response

# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import request [as 别名]
def set_response(self):
        """Modify cherrypy.response status, headers, and body to represent
        self.

        CherryPy uses this internally, but you can also use it to create an
        HTTPError object and set its output without *raising* the exception.
        """
        response = cherrypy.serving.response

        clean_headers(self.code)

        # In all cases, finalize will be called after this method,
        # so don't bother cleaning up response values here.
        response.status = self.status
        tb = None
        if cherrypy.serving.request.show_tracebacks:
            tb = format_exc()

        response.headers.pop('Content-Length', None)

        content = self.get_error_page(self.status, traceback=tb,
                                      message=self._message)
        response.body = content

        _be_ie_unfriendly(self.code) 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:27,代码来源:_cperror.py

示例3: script_name

# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import request [as 别名]
def script_name(self):  # noqa: D401; irrelevant for properties
        """The URI "mount point" for this app.

        A mount point is that portion of the URI which is constant for all URIs
        that are serviced by this application; it does not include scheme,
        host, or proxy ("virtual host") portions of the URI.

        For example, if script_name is "/my/cool/app", then the URL
        "http://www.example.com/my/cool/app/page1" might be handled by a
        "page1" method on the root object.

        The value of script_name MUST NOT end in a slash. If the script_name
        refers to the root of the URI, it MUST be an empty string (not "/").

        If script_name is explicitly set to None, then the script_name will be
        provided for each call from request.wsgi_environ['SCRIPT_NAME'].
        """
        if self._script_name is not None:
            return self._script_name

        # A `_script_name` with a value of None signals that the script name
        # should be pulled from WSGI environ.
        return cherrypy.serving.request.wsgi_environ['SCRIPT_NAME'].rstrip('/') 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:25,代码来源:_cptree.py

示例4: _populate_known_types

# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import request [as 别名]
def _populate_known_types(self):
        b = [x for x in vars(builtins).values()
             if type(x) is type(str)]

        def traverse(obj, namespace):
            for name in dir(obj):
                # Hack for 3.2's warning about body_params
                if name == 'body_params':
                    continue
                vtype = type(getattr(obj, name, None))
                if vtype in b:
                    self.known_config_types[namespace + '.' + name] = vtype

        traverse(cherrypy.request, 'request')
        traverse(cherrypy.response, 'response')
        traverse(cherrypy.server, 'server')
        traverse(cherrypy.engine, 'engine')
        traverse(cherrypy.log, 'log') 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:20,代码来源:_cpchecker.py

示例5: test_CONNECT_method

# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import request [as 别名]
def test_CONNECT_method(self):
        self.persistent = True
        try:
            conn = self.HTTP_CONN
            conn.request('CONNECT', 'created.example.com:3128')
            response = conn.response_class(conn.sock, method='CONNECT')
            response.begin()
            self.assertEqual(response.status, 204)
        finally:
            self.persistent = False

        self.persistent = True
        try:
            conn = self.HTTP_CONN
            conn.request('CONNECT', 'body.example.com:3128')
            response = conn.response_class(conn.sock, method='CONNECT')
            response.begin()
            self.assertEqual(response.status, 200)
            self.body = response.read()
            self.assertBody(b'CONNECTed to /body.example.com:3128')
        finally:
            self.persistent = False 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:24,代码来源:test_request_obj.py

示例6: __init__

# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import request [as 别名]
def __init__(self):
		cherrypy.log("Initializing Webserver")
		
		cherrypy.config.update({'request.error_response': self.handle_error})
		cherrypy.config.update({'error_page.404': self.error_404})
		cherrypy.config.update({'error_page.401': self.error_401})
		
		self.sensors = SensorsPage()
		self.zones = ZonesPage()
		self.setups = SetupsPage()
		self.alarms = AlarmsPage()
		self.workers = WorkersPage()
		self.actions = ActionsPage()
		self.notifiers = NotifiersPage()
		self.sensorparams = SensorParamsPage()
		self.actionparams = ActionParamsPage()
		self.notifierparams = NotifierParamsPage()
		self.logs = LogEntriesPage()
		self.setupszones = SetupsZonesPage()
		self.workersactions = WorkersActionsPage()
		
		self.alarmdata = AlarmDataPage()
		
		self.connect()
		cherrypy.log("Finished initialization") 
开发者ID:SecPi,项目名称:SecPi,代码行数:27,代码来源:main.py

示例7: list

# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import request [as 别名]
def list(self):
		if(hasattr(cherrypy.request, 'json')):
			qry = self.db.query(self.baseclass)
			
			if('filter' in cherrypy.request.json and cherrypy.request.json['filter']!=''):
				qry = qry.filter(text(cherrypy.request.json['filter']))
			
			if('sort' in cherrypy.request.json and cherrypy.request.json['sort']!=''):
				qry = qry.order_by(text(cherrypy.request.json['sort']))
			
			objects = qry.all()
			
		else:	
			objects = self.db.query(self.baseclass).all()
		
		return {'status': 'success', 'data': self.objectsToList(objects)} 
开发者ID:SecPi,项目名称:SecPi,代码行数:18,代码来源:base_webpage.py

示例8: update

# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import request [as 别名]
def update(self):
		if(hasattr(cherrypy.request, 'json')):
			data = cherrypy.request.json
			
			id = data['id']
			
			# check for valid id
			if(id and id > 0):
				
				if(data and len(data)>0):
					cherrypy.log("update something %s"%data)
					obj = self.db.query(self.baseclass).get(id)
					
					for k, v in data.iteritems():
						if(not k == "id"): # and v is not None --> can be null!?
							setattr(obj, k, utils.str_to_value(v))
					
					self.db.commit()
					
					return {'status': 'success', 'message': "Updated object with id %i"%obj.id}
					
			else:
				return {'status':'error', 'message': "Invalid ID!" }
		
		return {'status': 'error', 'message': 'No data recieved!'} 
开发者ID:SecPi,项目名称:SecPi,代码行数:27,代码来源:base_webpage.py

示例9: extract

# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import request [as 别名]
def extract(self):
		if(hasattr(cherrypy.request, 'json')):
			if('dir' in cherrypy.request.json and cherrypy.request.json['dir']!='' and 'name' in cherrypy.request.json and cherrypy.request.json['name']!=''):
				dir = cherrypy.request.json['dir']
				name = cherrypy.request.json['name']
				
				fdir = path.join(self.datapath, dir)
				fp = path.join(fdir, name)
				if(path.exists(fp)):
					with zipfile.ZipFile(fp, "r") as z:
						z.extractall(fdir)
						return {'status': 'success', 'message': "File %s/%s extracted!"%(dir, name)}
				else:
					return {'status': 'error', 'message': "File doesn't exist!"}
			else:
				return {'status': 'error', 'message': "Invalid filename!"}
		else:
			return {'status': 'error', 'message': "No filename given!"} 
开发者ID:SecPi,项目名称:SecPi,代码行数:20,代码来源:alarmdata.py

示例10: __init__

# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import request [as 别名]
def __init__(self, path, query_string=""):
        import cherrypy
        self.request = cherrypy.serving.request

        self.query_string = query_string
        if "?" in path:
            # Separate any params included in the path
            path, self.query_string = path.split("?", 1)

        # Note that urljoin will "do the right thing" whether url is:
        #  1. a URL relative to root (e.g. "/dummy")
        #  2. a URL relative to the current path
        # Note that any query string will be discarded.
        path = _urljoin(self.request.path_info, path)

        # Set a 'path' member attribute so that code which traps this
        # error can have access to it.
        self.path = path

        CherryPyException.__init__(self, path, self.query_string) 
开发者ID:naparuba,项目名称:opsbro,代码行数:22,代码来源:_cperror.py

示例11: _populate_known_types

# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import request [as 别名]
def _populate_known_types(self):
        b = [x for x in vars(builtins).values()
             if type(x) is type(str)]

        def traverse(obj, namespace):
            for name in dir(obj):
                # Hack for 3.2's warning about body_params
                if name == 'body_params':
                    continue
                vtype = type(getattr(obj, name, None))
                if vtype in b:
                    self.known_config_types[namespace + "." + name] = vtype

        traverse(cherrypy.request, "request")
        traverse(cherrypy.response, "response")
        traverse(cherrypy.server, "server")
        traverse(cherrypy.engine, "engine")
        traverse(cherrypy.log, "log") 
开发者ID:naparuba,项目名称:opsbro,代码行数:20,代码来源:_cpchecker.py

示例12: emit

# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import request [as 别名]
def emit(self, record):
        """Emit a record."""
        try:
            stream = cherrypy.serving.request.wsgi_environ.get('wsgi.errors')
        except (AttributeError, KeyError):
            pass
        else:
            try:
                msg = self.format(record)
                fs = "%s\n"
                import types
                # if no unicode support...
                if not hasattr(types, "UnicodeType"):
                    stream.write(fs % msg)
                else:
                    try:
                        stream.write(fs % msg)
                    except UnicodeError:
                        stream.write(fs % msg.encode("UTF-8"))
                self.flush()
            except:
                self.handleError(record) 
开发者ID:naparuba,项目名称:opsbro,代码行数:24,代码来源:_cplogging.py

示例13: __init__

# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import request [as 别名]
def __init__(self, path, query_string=''):
        import cherrypy
        self.request = cherrypy.serving.request

        self.query_string = query_string
        if '?' in path:
            # Separate any params included in the path
            path, self.query_string = path.split('?', 1)

        # Note that urljoin will "do the right thing" whether url is:
        #  1. a URL relative to root (e.g. "/dummy")
        #  2. a URL relative to the current path
        # Note that any query string will be discarded.
        path = _urljoin(self.request.path_info, path)

        # Set a 'path' member attribute so that code which traps this
        # error can have access to it.
        self.path = path

        CherryPyException.__init__(self, path, self.query_string) 
开发者ID:morpheus65535,项目名称:bazarr,代码行数:22,代码来源:_cperror.py

示例14: emit

# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import request [as 别名]
def emit(self, record):
        """Emit a record."""
        try:
            stream = cherrypy.serving.request.wsgi_environ.get('wsgi.errors')
        except (AttributeError, KeyError):
            pass
        else:
            try:
                msg = self.format(record)
                fs = '%s\n'
                import types
                # if no unicode support...
                if not hasattr(types, 'UnicodeType'):
                    stream.write(fs % msg)
                else:
                    try:
                        stream.write(fs % msg)
                    except UnicodeError:
                        stream.write(fs % msg.encode('UTF-8'))
                self.flush()
            except:
                self.handleError(record) 
开发者ID:morpheus65535,项目名称:bazarr,代码行数:24,代码来源:_cplogging.py

示例15: default_status

# 需要导入模块: import cherrypy [as 别名]
# 或者: from cherrypy import request [as 别名]
def default_status(cls):
        """
        The default redirect status for the request.

        RFC 2616 indicates a 301 response code fits our goal; however,
        browser support for 301 is quite messy. Use 302/303 instead. See
        http://www.alanflavell.org.uk/www/post-redirect.html
        """
        return 303 if cherrypy.serving.request.protocol >= (1, 1) else 302 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:11,代码来源:_cperror.py


注:本文中的cherrypy.request方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。