本文整理匯總了Python中twisted.web.tap.Options.parseOptions方法的典型用法代碼示例。如果您正苦於以下問題:Python Options.parseOptions方法的具體用法?Python Options.parseOptions怎麽用?Python Options.parseOptions使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類twisted.web.tap.Options
的用法示例。
在下文中一共展示了Options.parseOptions方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_defaultPort
# 需要導入模塊: from twisted.web.tap import Options [as 別名]
# 或者: from twisted.web.tap.Options import parseOptions [as 別名]
def test_defaultPort(self):
"""
If the I{--port} option is not specified, L{Options} defaults the port
to C{8080}.
"""
options = Options()
options.parseOptions([])
self.assertEqual(strports.parse(options["port"], None)[:2], ("TCP", (8080, None)))
示例2: test_HTTPSAcceptedOnAvailableSSL
# 需要導入模塊: from twisted.web.tap import Options [as 別名]
# 或者: from twisted.web.tap.Options import parseOptions [as 別名]
def test_HTTPSAcceptedOnAvailableSSL(self):
"""
When SSL support is present, it accepts the --https option.
"""
options = Options()
options.parseOptions(['--https=443'])
self.assertEqual('443', options['https'])
示例3: test_add_header_parsing
# 需要導入模塊: from twisted.web.tap import Options [as 別名]
# 或者: from twisted.web.tap.Options import parseOptions [as 別名]
def test_add_header_parsing(self):
"""
When --add-header is specific, the value is parsed.
"""
options = Options()
options.parseOptions(
['--add-header', 'K1: V1', '--add-header', 'K2: V2']
)
self.assertEqual(options['extraHeaders'], [('K1', 'V1'), ('K2', 'V2')])
示例4: test_defaultPort
# 需要導入模塊: from twisted.web.tap import Options [as 別名]
# 或者: from twisted.web.tap.Options import parseOptions [as 別名]
def test_defaultPort(self):
"""
If the I{--port} option is not specified, L{Options} defaults the port
to C{8080}.
"""
options = Options()
options.parseOptions([])
self.assertEqual(
endpoints._parseServer(options['port'], None)[:2],
('TCP', (8080, None)))
示例5: test_defaultPersonalPath
# 需要導入模塊: from twisted.web.tap import Options [as 別名]
# 或者: from twisted.web.tap.Options import parseOptions [as 別名]
def test_defaultPersonalPath(self):
"""
If the I{--port} option not specified but the I{--personal} option is,
L{Options} defaults the port to C{UserDirectory.userSocketName} in the
user's home directory.
"""
options = Options()
options.parseOptions(["--personal"])
path = os.path.expanduser(os.path.join("~", UserDirectory.userSocketName))
self.assertEqual(strports.parse(options["port"], None)[:2], ("UNIX", (path, None)))
示例6: test_defaultPersonalPath
# 需要導入模塊: from twisted.web.tap import Options [as 別名]
# 或者: from twisted.web.tap.Options import parseOptions [as 別名]
def test_defaultPersonalPath(self):
"""
If the I{--port} option not specified but the I{--personal} option is,
L{Options} defaults the port to C{UserDirectory.userSocketName} in the
user's home directory.
"""
options = Options()
options.parseOptions(['--personal'])
path = os.path.expanduser(
os.path.join('~', UserDirectory.userSocketName))
self.assertEqual(
endpoints._parseServer(options['port'], None)[:2],
('UNIX', (path, None)))
示例7: test_personalServer
# 需要導入模塊: from twisted.web.tap import Options [as 別名]
# 或者: from twisted.web.tap.Options import parseOptions [as 別名]
def test_personalServer(self):
"""
The I{--personal} option to L{makeService} causes it to return a
service which will listen on the server address given by the I{--port}
option.
"""
port = self.mktemp()
options = Options()
options.parseOptions(['--port', 'unix:' + port, '--personal'])
service = makeService(options)
service.startService()
self.addCleanup(service.stopService)
self.assertTrue(os.path.exists(port))
self.assertTrue(stat.S_ISSOCK(os.stat(port).st_mode))
示例8: test_add_header_resource
# 需要導入模塊: from twisted.web.tap import Options [as 別名]
# 或者: from twisted.web.tap.Options import parseOptions [as 別名]
def test_add_header_resource(self):
"""
When --add-header is specified, the resource is a composition that adds
headers.
"""
options = Options()
options.parseOptions(
['--add-header', 'K1: V1', '--add-header', 'K2: V2']
)
service = makeService(options)
resource = service.services[0].factory.resource
self.assertIsInstance(resource, _AddHeadersResource)
self.assertEqual(resource._headers, [('K1', 'V1'), ('K2', 'V2')])
self.assertIsInstance(resource._originalResource, demo.Test)
示例9: _pathOption
# 需要導入模塊: from twisted.web.tap import Options [as 別名]
# 或者: from twisted.web.tap.Options import parseOptions [as 別名]
def _pathOption(self):
"""
Helper for the I{--path} tests which creates a directory and creates
an L{Options} object which uses that directory as its static
filesystem root.
@return: A two-tuple of a L{FilePath} referring to the directory and
the value associated with the C{'root'} key in the L{Options}
instance after parsing a I{--path} option.
"""
path = FilePath(self.mktemp())
path.makedirs()
options = Options()
options.parseOptions(['--path', path.path])
root = options['root']
return path, root
示例10: test_pathServer
# 需要導入模塊: from twisted.web.tap import Options [as 別名]
# 或者: from twisted.web.tap.Options import parseOptions [as 別名]
def test_pathServer(self):
"""
The I{--path} option to L{makeService} causes it to return a service
which will listen on the server address given by the I{--port} option.
"""
path = FilePath(self.mktemp())
path.makedirs()
port = self.mktemp()
options = Options()
options.parseOptions(['--port', 'unix:' + port, '--path', path.path])
service = makeService(options)
service.startService()
self.addCleanup(service.stopService)
self.assertIsInstance(service.services[0].factory.resource, File)
self.assertEqual(service.services[0].factory.resource.path, path.path)
self.assertTrue(os.path.exists(port))
self.assertTrue(stat.S_ISSOCK(os.stat(port).st_mode))
示例11: test_wsgi
# 需要導入模塊: from twisted.web.tap import Options [as 別名]
# 或者: from twisted.web.tap.Options import parseOptions [as 別名]
def test_wsgi(self):
"""
The I{--wsgi} option takes the fully-qualifed Python name of a WSGI
application object and creates a L{WSGIResource} at the root which
serves that application.
"""
options = Options()
options.parseOptions(['--wsgi', __name__ + '.application'])
root = options['root']
self.assertTrue(root, WSGIResource)
self.assertIdentical(root._reactor, reactor)
self.assertTrue(isinstance(root._threadpool, ThreadPool))
self.assertIdentical(root._application, application)
# The threadpool should start and stop with the reactor.
self.assertFalse(root._threadpool.started)
reactor.fireSystemEvent('startup')
self.assertTrue(root._threadpool.started)
self.assertFalse(root._threadpool.joined)
reactor.fireSystemEvent('shutdown')
self.assertTrue(root._threadpool.joined)