本文整理汇总了Python中paste.httpserver.serve方法的典型用法代码示例。如果您正苦于以下问题:Python httpserver.serve方法的具体用法?Python httpserver.serve怎么用?Python httpserver.serve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类paste.httpserver
的用法示例。
在下文中一共展示了httpserver.serve方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test
# 需要导入模块: from paste import httpserver [as 别名]
# 或者: from paste.httpserver import serve [as 别名]
def test():
# this requires python-paste package
import logging
from paste import httpserver
d=fromFs(os.path.dirname(sys.argv[0]))
LOG_FILENAME = os.path.join(d,u'tmp','logging_example.out')
logging.basicConfig(filename=LOG_FILENAME,level=logging.INFO,)
myLogger=logging.getLogger('MyTestWebApp')
h=logging.StreamHandler() # in production use WatchedFileHandler or RotatingFileHandler
h.setFormatter(logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s"))
myLogger.addHandler(h)
myLogger.setLevel(logging.INFO) # in production use logging.INFO
d=fromFs(os.path.dirname(sys.argv[0]))
app=webApp(
os.path.join(d,u'resources/templates'),
staticBaseDir={u'/_files/':os.path.join(d,u'resources/files')},
logger=myLogger
);
# for options see http://pythonpaste.org/modules/httpserver.html
try:
httpserver.serve(app, host='0.0.0.0', port='8080')
except:
httpserver.serve(app, host='0.0.0.0', port='8081')
示例2: main
# 需要导入模块: from paste import httpserver [as 别名]
# 或者: from paste.httpserver import serve [as 别名]
def main():
# setup opts
config.parse_args(args=sys.argv[1:])
config.setup_logging()
paste_conf = config.find_paste_config()
# quick simple server for testing purposes or simple scenarios
ip = CONF.get('bind_host', '0.0.0.0')
port = CONF.get('bind_port', 9090)
try:
httpserver.serve(
application=deploy.loadapp('config:%s' % paste_conf, name='main'),
host=ip,
port=port)
message = (_i18n._('Server listening on %(ip)s:%(port)s') %
{'ip': ip, 'port': port})
_LOG.info(message)
print(message)
except KeyboardInterrupt:
print(_i18n._("Thank You ! \nBye."))
sys.exit(0)
示例3: main
# 需要导入模块: from paste import httpserver [as 别名]
# 或者: from paste.httpserver import serve [as 别名]
def main():
parser = argparse.ArgumentParser()
parser.add_argument('--listen',
help='host:port to listen on',
default='127.0.0.1:8083')
args = parser.parse_args()
initialise_app()
host, port = args.listen.split(':')
httpserver.serve(
app,
host=host,
port=port,
request_queue_size=128,
use_threadpool=True,
threadpool_workers=32,
)
示例4: main
# 需要导入模块: from paste import httpserver [as 别名]
# 或者: from paste.httpserver import serve [as 别名]
def main():
# Parse command line arguments into `args` dictionary:
parser = argparse.ArgumentParser()
parser.add_argument('--listen',
help='host:port to listen on',
default='127.0.0.1:8082')
args = parser.parse_args()
# Initialise the application:
initialise_app()
# Start serving requests:
host, port = args.listen.split(':')
httpserver.serve(
app,
host=host,
port=port,
request_queue_size=128,
use_threadpool=True,
threadpool_workers=32,
)
示例5: main
# 需要导入模块: from paste import httpserver [as 别名]
# 或者: from paste.httpserver import serve [as 别名]
def main():
parser = argparse.ArgumentParser()
parser.add_argument('--listen',
help='host:port to listen on',
default='127.0.0.1:8084')
args = parser.parse_args()
host, port = args.listen.split(':')
httpserver.serve(
app,
host=host,
port=port,
request_queue_size=128,
use_threadpool=True,
threadpool_workers=32,
)
示例6: __init__
# 需要导入模块: from paste import httpserver [as 别名]
# 或者: from paste.httpserver import serve [as 别名]
def __init__(self, catchall=True, autojson=True, config=None):
""" Create a new bottle instance.
You usually don't do that. Use `bottle.app.push()` instead.
"""
self.routes = [] # List of installed routes including metadata.
self.callbacks = {} # Cache for wrapped callbacks.
self.router = Router() # Maps to self.routes indices.
self.mounts = {}
self.error_handler = {}
self.catchall = catchall
self.config = config or {}
self.serve = True
self.castfilter = []
if autojson and json_dumps:
self.add_filter(dict, dict2json)
self.hooks = {'before_request': [], 'after_request': []}
示例7: __serveStatic
# 需要导入模块: from paste import httpserver [as 别名]
# 或者: from paste.httpserver import serve [as 别名]
def __serveStatic(self, rq, fn):
"""
internal method to serve static files like png, css,js ...etc.
"""
if not os.path.exists(fn): raise fileNotFoundException()
try: f=open(fn,'rb')
except IOError: raise fileNotFoundException()
ext=fn[fn.rfind('.'):][1:].lower()
rq.start_response("200 OK", [('content-type', self._mimeByExtension.get(ext,"application/octet-stream"))])
# NOTE: since the file object is iteratable then no need for returning [r.read()]
return f
示例8: __call__
# 需要导入模块: from paste import httpserver [as 别名]
# 或者: from paste.httpserver import serve [as 别名]
def __call__(self, environ, start_response):
rq=Request(self, environ, start_response)
if rq.uri==None:
# handle malformed uri
return self._handleException(rq, webAppBaseException(500))
if ALLOW_DEBUG: self._logger.info('got uri=[%s]' % rq.uri)
if ALLOW_DEBUG: self._logger.debug('got env=[%s]' % rq.environ)
rq.q._ok_max_files_count=self._max_files_count
# check if we need to serve static content
for k in self._staticBaseDirKeys:
if rq.uri.startswith(k):
# SECURITY CHECK: that filename is really in side base filename ie. no ".." trick
# NOTE: no need for this check as it seems to be done by paste
bfn=self._staticBaseDir[k]
if os.sep!='/': fn=bfn+rq.uri[len(k):].replace('/',os.sep)
else: fn=bfn+rq.uri[len(k):]
if not os.path.abspath(fn).startswith(bfn):
return self._handleException(rq, forbiddenException())
try: return self.__serveStatic(rq, fn)
except webAppBaseException as e:
return self._handleException(rq, e)
# check if we need to serve redirect
for k in self._redirectBaseUrlsKeys:
if rq.uri.startswith(k):
u=self._redirectBaseUrls[k]+rq.uri[len(k):]
# FIXME: should we escape Location in start_response
start_response("302 Temporary Redirect", [('Location',u),('content-type', 'text/html')])
return [('<html><body><a href="%s">moved</a></body></html>' % escape(u))]
# pass control to the right method
if rq.uriList and not rq.uriList[0].startswith('_') and hasattr(self, rq.uriList[0]):
f=getattr(self, rq.uriList[0])
a=rq.uriList[1:]
else:
f=self._root
a=rq.uriList
try: r=f(rq, *a)
except webAppBaseException as e:
return self._handleException(rq, e)
return r
示例9: run
# 需要导入模块: from paste import httpserver [as 别名]
# 或者: from paste.httpserver import serve [as 别名]
def run(self, handler):
from waitress import serve
serve(handler, host=self.host, port=self.port)
示例10: run
# 需要导入模块: from paste import httpserver [as 别名]
# 或者: from paste.httpserver import serve [as 别名]
def run(self, handler): # pragma: no cover
from paste import httpserver
if not self.quiet:
from paste.translogger import TransLogger
handler = TransLogger(handler)
httpserver.serve(handler, host=self.host, port=str(self.port),
**self.options)
示例11: main
# 需要导入模块: from paste import httpserver [as 别名]
# 或者: from paste.httpserver import serve [as 别名]
def main(args):
# Initialise the app by precomputing values:
initialise_app(args.max_relations_to_load)
# Start the server:
host, port = args.listen.split(':')
httpserver.serve(
app,
host=host,
port=port,
request_queue_size=128,
use_threadpool=True,
threadpool_workers=32,
)
示例12: main
# 需要导入模块: from paste import httpserver [as 别名]
# 或者: from paste.httpserver import serve [as 别名]
def main(args_dict):
initialise_app()
host, port = args_dict['listen'].split(':')
httpserver.serve(
app,
host=host,
port=port,
request_queue_size=128,
use_threadpool=True,
threadpool_workers=32,
)
示例13: run
# 需要导入模块: from paste import httpserver [as 别名]
# 或者: from paste.httpserver import serve [as 别名]
def run(self, handler):
from waitress import serve
serve(handler, host=self.host, port=self.port, _quiet=self.quiet, **self.options)
示例14: run
# 需要导入模块: from paste import httpserver [as 别名]
# 或者: from paste.httpserver import serve [as 别名]
def run(self, handler): # 重写 run() 函数.
from paste import httpserver
from paste.translogger import TransLogger
app = TransLogger(handler)
httpserver.serve(app, host=self.host, port=str(self.port))
示例15: __init__
# 需要导入模块: from paste import httpserver [as 别名]
# 或者: from paste.httpserver import serve [as 别名]
def __init__(self, catchall=True, autojson=True, path = ''):
""" Create a new bottle instance.
You usually don't do that. Use `bottle.app.push()` instead.
"""
self.routes = Router()
self.mounts = {}
self.error_handler = {}
self.catchall = catchall
self.config = dict()
self.serve = True
self.castfilter = []
if autojson and json_dumps:
self.add_filter(dict, dict2json)