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


Python OptionParser.parse_command_line方法代码示例

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


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

示例1: load_config

# 需要导入模块: from tornado.options import OptionParser [as 别名]
# 或者: from tornado.options.OptionParser import parse_command_line [as 别名]
def load_config():
    options = OptionParser()
    options.define('port', default=8888, help='run on the given port', type=int)
    options.define('debug', default=False, help='run in debug mode')
    options.define('api_allowed_host', default='localhost', help='origin host that has access to API')
    options.define('history_size', default=50, help='number of tweets stored in memoty', type=int)
    options.define('config', type=str, help='path to config file',
                   callback=lambda path: options.parse_config_file(path, final=False))
    options.define('logging', default='error', help='logging level')
    options.parse_command_line()
    return options
开发者ID:haxoza,项目名称:tweefee,代码行数:13,代码来源:tweefee.py

示例2: test_help

# 需要导入模块: from tornado.options import OptionParser [as 别名]
# 或者: from tornado.options.OptionParser import parse_command_line [as 别名]
 def test_help(self):
     options = OptionParser()
     try:
         orig_stderr = sys.stderr
         sys.stderr = StringIO()
         with self.assertRaises(SystemExit):
             options.parse_command_line(["main.py", "--help"])
         usage = sys.stderr.getvalue()
     finally:
         sys.stderr = orig_stderr
     self.assertIn("Usage:", usage)
开发者ID:ArthurGarnier,项目名称:SickRage,代码行数:13,代码来源:options_test.py

示例3: test_dash_underscore_cli

# 需要导入模块: from tornado.options import OptionParser [as 别名]
# 或者: from tornado.options.OptionParser import parse_command_line [as 别名]
 def test_dash_underscore_cli(self):
     # Dashes and underscores should be interchangeable.
     for defined_name in ['foo-bar', 'foo_bar']:
         for flag in ['--foo-bar=a', '--foo_bar=a']:
             options = OptionParser()
             options.define(defined_name)
             options.parse_command_line(['main.py', flag])
             # Attr-style access always uses underscores.
             self.assertEqual(options.foo_bar, 'a')
             # Dict-style access allows both.
             self.assertEqual(options['foo-bar'], 'a')
             self.assertEqual(options['foo_bar'], 'a')
开发者ID:ArthurGarnier,项目名称:SickRage,代码行数:14,代码来源:options_test.py

示例4: test_mock_patch

# 需要导入模块: from tornado.options import OptionParser [as 别名]
# 或者: from tornado.options.OptionParser import parse_command_line [as 别名]
    def test_mock_patch(self):
        # ensure that our setattr hooks don't interfere with mock.patch
        options = OptionParser()
        options.define('foo', default=1)
        options.parse_command_line(['main.py', '--foo=2'])
        self.assertEqual(options.foo, 2)

        with mock.patch.object(options.mockable(), 'foo', 3):
            self.assertEqual(options.foo, 3)
        self.assertEqual(options.foo, 2)

        # Try nested patches mixed with explicit sets
        with mock.patch.object(options.mockable(), 'foo', 4):
            self.assertEqual(options.foo, 4)
            options.foo = 5
            self.assertEqual(options.foo, 5)
            with mock.patch.object(options.mockable(), 'foo', 6):
                self.assertEqual(options.foo, 6)
            self.assertEqual(options.foo, 5)
        self.assertEqual(options.foo, 2)
开发者ID:ArthurGarnier,项目名称:SickRage,代码行数:22,代码来源:options_test.py

示例5: test_subcommand

# 需要导入模块: from tornado.options import OptionParser [as 别名]
# 或者: from tornado.options.OptionParser import parse_command_line [as 别名]
    def test_subcommand(self):
        base_options = OptionParser()
        base_options.define("verbose", default=False)
        sub_options = OptionParser()
        sub_options.define("foo", type=str)
        rest = base_options.parse_command_line(
            ["main.py", "--verbose", "subcommand", "--foo=bar"])
        self.assertEqual(rest, ["subcommand", "--foo=bar"])
        self.assertTrue(base_options.verbose)
        rest2 = sub_options.parse_command_line(rest)
        self.assertEqual(rest2, [])
        self.assertEqual(sub_options.foo, "bar")

        # the two option sets are distinct
        try:
            orig_stderr = sys.stderr
            sys.stderr = StringIO()
            with self.assertRaises(Error):
                sub_options.parse_command_line(["subcommand", "--verbose"])
        finally:
            sys.stderr = orig_stderr
开发者ID:ArthurGarnier,项目名称:SickRage,代码行数:23,代码来源:options_test.py

示例6: test_types

# 需要导入模块: from tornado.options import OptionParser [as 别名]
# 或者: from tornado.options.OptionParser import parse_command_line [as 别名]
 def test_types(self):
     options = OptionParser()
     options.define('str', type=str)
     options.define('basestring', type=basestring_type)
     options.define('int', type=int)
     options.define('float', type=float)
     options.define('datetime', type=datetime.datetime)
     options.define('timedelta', type=datetime.timedelta)
     options.parse_command_line(['main.py',
                                 '--str=asdf',
                                 '--basestring=qwer',
                                 '--int=42',
                                 '--float=1.5',
                                 '--datetime=2013-04-28 05:16',
                                 '--timedelta=45s'])
     self.assertEqual(options.str, 'asdf')
     self.assertEqual(options.basestring, 'qwer')
     self.assertEqual(options.int, 42)
     self.assertEqual(options.float, 1.5)
     self.assertEqual(options.datetime,
                      datetime.datetime(2013, 4, 28, 5, 16))
     self.assertEqual(options.timedelta, datetime.timedelta(seconds=45))
开发者ID:ArthurGarnier,项目名称:SickRage,代码行数:24,代码来源:options_test.py

示例7: test_parse_callbacks

# 需要导入模块: from tornado.options import OptionParser [as 别名]
# 或者: from tornado.options.OptionParser import parse_command_line [as 别名]
    def test_parse_callbacks(self):
        options = OptionParser()
        self.called = False
        def callback():
            self.called = True
        options.add_parse_callback(callback)

        # non-final parse doesn't run callbacks
        options.parse_command_line(["main.py"], final=False)
        self.assertFalse(self.called)

        # final parse does
        options.parse_command_line(["main.py"])
        self.assertTrue(self.called)

        # callbacks can be run more than once on the same options
        # object if there are multiple final parses
        self.called = False
        options.parse_command_line(["main.py"])
        self.assertTrue(self.called)
开发者ID:CNCBASHER,项目名称:tornado,代码行数:22,代码来源:options_test.py

示例8: test_parse_command_line

# 需要导入模块: from tornado.options import OptionParser [as 别名]
# 或者: from tornado.options.OptionParser import parse_command_line [as 别名]
 def test_parse_command_line(self):
     options = OptionParser()
     options.define("port", default=80)
     options.parse_command_line(["main.py", "--port=443"])
     self.assertEqual(options.port, 443)
开发者ID:ArthurGarnier,项目名称:SickRage,代码行数:7,代码来源:options_test.py

示例9: test_multiple_int

# 需要导入模块: from tornado.options import OptionParser [as 别名]
# 或者: from tornado.options.OptionParser import parse_command_line [as 别名]
 def test_multiple_int(self):
     options = OptionParser()
     options.define('foo', type=int, multiple=True)
     options.parse_command_line(['main.py', '--foo=1,3,5:7'])
     self.assertEqual(options.foo, [1, 3, 5, 6, 7])
开发者ID:ArthurGarnier,项目名称:SickRage,代码行数:7,代码来源:options_test.py

示例10: test_multiple_string

# 需要导入模块: from tornado.options import OptionParser [as 别名]
# 或者: from tornado.options.OptionParser import parse_command_line [as 别名]
 def test_multiple_string(self):
     options = OptionParser()
     options.define('foo', type=str, multiple=True)
     options.parse_command_line(['main.py', '--foo=a,b,c'])
     self.assertEqual(options.foo, ['a', 'b', 'c'])
开发者ID:ArthurGarnier,项目名称:SickRage,代码行数:7,代码来源:options_test.py

示例11: SockJSRouter

# 需要导入模块: from tornado.options import OptionParser [as 别名]
# 或者: from tornado.options.OptionParser import parse_command_line [as 别名]
    handlers.extend(BodyRouter.urls)

    # Create multiplexer
    router = MultiplexConnection.get(objClass=HijackConnection)

    # Register multiplexer
    HijackRouter = SockJSRouter(router, '/hijack')
    handlers.extend(HijackRouter.urls)

    options = OptionParser()
    options.define("port", default=8002, help="run on the given port", type=int)
    options.define("proxyport", default=8989, help="port the proxy is running on", type=int)
    options.define("proxyhost", default=None, help="host the proxy is running on", type=str)
    options.define("mongourl", default="localhost:27017", help="mongodb url", type=str)

    options.parse_command_line()

    db = motor.MotorClient('mongodb://'+options.mongourl, tz_aware=True)
    
    db.proxyservice['origins'].create_index("origin", background=True)

    ui_methods={'nice_headers': BaseRequestHandler.nice_headers}
    settings = dict(
        handlers=handlers,
        static_path=os.path.join(os.path.dirname(__file__), 'static'),
        db=db,
        template_path=os.path.join(os.path.dirname(__file__), "templates"),
        proxyhost=options.proxyhost,
        proxyport=options.proxyport,
        debug=True,
        ui_methods=ui_methods
开发者ID:leibowitz,项目名称:gianni-proxy-ui,代码行数:33,代码来源:main.py


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