用法:
wsgiref.validate.validator(application)
裹
application
並返回一個新的 WSGI 應用程序對象。返回的應用程序會將所有請求轉發給原始應用程序application
, 並將檢查兩者application
並且調用它的服務器符合 WSGI 規範和RFC 2616.任何檢測到的不符合項都會引發
AssertionError
;但是請注意,如何處理這些錯誤是server-dependent。例如,wsgiref.simple_server
和其他基於wsgiref.handlers
的服務器(不覆蓋錯誤處理方法來做其他事情)將簡單地輸出一條錯誤發生的消息,並將回溯轉儲到sys.stderr
或一些其他錯誤流。這個包裝器也可以使用
warnings
模塊來指示有問題但實際上可能未被禁止的行為 PEP 3333.除非使用 Python 命令行 選項或warnings
API,任何此類警告都將寫入sys.stderr
(not
wsgi.errors
,除非它們碰巧是同一個對象)。示例用法:
from wsgiref.validate import validator from wsgiref.simple_server import make_server # Our callable object which is intentionally not compliant to the # standard, so the validator is going to break def simple_app(environ, start_response): status = '200 OK' # HTTP Status headers = [('Content-type', 'text/plain')] # HTTP Headers start_response(status, headers) # This is going to break because we need to return a list, and # the validator is going to inform us return b"Hello World" # This is the application wrapped in a validator validator_app = validator(simple_app) with make_server('', 8000, validator_app) as httpd: print("Listening on port 8000....") httpd.serve_forever()
相關用法
- Python wsgiref.simple_server.make_server用法及代碼示例
- Python wsgiref.util.FileWrapper用法及代碼示例
- Python wsgiref.util.setup_testing_defaults用法及代碼示例
- Python OpenCV waitKeyEx()用法及代碼示例
- Python winsound.SND_ALIAS用法及代碼示例
- Python weakref.WeakMethod用法及代碼示例
- Python OpenCV waitKey()用法及代碼示例
- Python cudf.core.column.string.StringMethods.is_vowel用法及代碼示例
- Python torch.distributed.rpc.rpc_async用法及代碼示例
- Python torch.nn.InstanceNorm3d用法及代碼示例
- Python sklearn.cluster.MiniBatchKMeans用法及代碼示例
- Python pandas.arrays.IntervalArray.is_empty用法及代碼示例
- Python tf.compat.v1.distributions.Multinomial.stddev用法及代碼示例
- Python numpy.less()用法及代碼示例
- Python tf.compat.v1.distribute.MirroredStrategy.experimental_distribute_dataset用法及代碼示例
- Python Sympy Permutation.list()用法及代碼示例
- Python dask.dataframe.Series.apply用法及代碼示例
- Python networkx.algorithms.shortest_paths.weighted.all_pairs_dijkstra_path用法及代碼示例
- Python scipy.ndimage.binary_opening用法及代碼示例
- Python pyspark.pandas.Series.dropna用法及代碼示例
注:本文由純淨天空篩選整理自python.org大神的英文原創作品 wsgiref.validate.validator。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。