當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。