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


Python Controller.get_listeners方法代码示例

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


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

示例1: TestControl

# 需要导入模块: from stem.control import Controller [as 别名]
# 或者: from stem.control.Controller import get_listeners [as 别名]

#.........这里部分代码省略.........
        }[param]

        expected = ExitPolicy(
            "reject 0.0.0.0/8:*",  # private entries
            "reject 169.254.0.0/16:*",
            "reject 127.0.0.0/8:*",
            "reject 192.168.0.0/16:*",
            "reject 10.0.0.0/8:*",
            "reject 172.16.0.0/12:*",
            "reject 123.45.67.89:*",  # relay's public address
            "accept *:80",  # finally we get to our ExitPolicy
            "accept *:443",
            "accept 43.5.5.5:*",
            "reject *:22",
            "reject *:25",  # default policy
            "reject *:119",
            "reject *:135-139",
            "reject *:445",
            "reject *:563",
            "reject *:1214",
            "reject *:4661-4666",
            "reject *:6346-6429",
            "reject *:6699",
            "reject *:6881-6999",
            "accept *:*",
        )

        self.assertEqual(expected, self.controller.get_exit_policy())

    @patch("stem.control.Controller.get_info")
    @patch("stem.control.Controller.get_conf")
    def test_get_ports(self, get_conf_mock, get_info_mock):
        """
    Exercises the get_ports() and get_listeners() methods.
    """

        # Exercise as an old version of tor that doesn't support the 'GETINFO
        # net/listeners/*' options.

        get_info_mock.side_effect = InvalidArguments

        get_conf_mock.side_effect = lambda param, **kwargs: {
            "ControlPort": "9050",
            "ControlListenAddress": ["127.0.0.1"],
        }[param]

        self.assertEqual([("127.0.0.1", 9050)], self.controller.get_listeners(Listener.CONTROL))
        self.assertEqual([9050], self.controller.get_ports(Listener.CONTROL))

        # non-local addresss

        get_conf_mock.side_effect = lambda param, **kwargs: {
            "ControlPort": "9050",
            "ControlListenAddress": ["27.4.4.1"],
        }[param]

        self.assertEqual([("27.4.4.1", 9050)], self.controller.get_listeners(Listener.CONTROL))
        self.assertEqual([], self.controller.get_ports(Listener.CONTROL))

        # Exercise via the GETINFO option.

        get_info_mock.side_effect = None
        get_info_mock.return_value = '"127.0.0.1:1112" "127.0.0.1:1114"'

        self.assertEqual([("127.0.0.1", 1112), ("127.0.0.1", 1114)], self.controller.get_listeners(Listener.CONTROL))
开发者ID:Fuzew,项目名称:sharp-stem,代码行数:69,代码来源:controller.py

示例2: TestControl

# 需要导入模块: from stem.control import Controller [as 别名]
# 或者: from stem.control.Controller import get_listeners [as 别名]

#.........这里部分代码省略.........
    }[param]

    expected = ExitPolicy(
      'reject 0.0.0.0/8:*',  # private entries
      'reject 169.254.0.0/16:*',
      'reject 127.0.0.0/8:*',
      'reject 192.168.0.0/16:*',
      'reject 10.0.0.0/8:*',
      'reject 172.16.0.0/12:*',
      'reject 123.45.67.89:*',  # relay's public address
      'accept *:80',  # finally we get to our ExitPolicy
      'accept *:443',
      'accept 43.5.5.5:*',
      'reject *:22',
      'reject *:25',  # default policy
      'reject *:119',
      'reject *:135-139',
      'reject *:445',
      'reject *:563',
      'reject *:1214',
      'reject *:4661-4666',
      'reject *:6346-6429',
      'reject *:6699',
      'reject *:6881-6999',
      'accept *:*',
    )

    self.assertEqual(expected, self.controller.get_exit_policy())

  @patch('stem.control.Controller.get_info')
  @patch('stem.control.Controller.get_conf')
  def test_get_ports(self, get_conf_mock, get_info_mock):
    """
    Exercises the get_ports() and get_listeners() methods.
    """

    # Exercise as an old version of tor that doesn't support the 'GETINFO
    # net/listeners/*' options.

    get_info_mock.side_effect = InvalidArguments

    get_conf_mock.side_effect = lambda param, **kwargs: {
      'ControlPort': '9050',
      'ControlListenAddress': ['127.0.0.1'],
    }[param]

    self.assertEqual([('127.0.0.1', 9050)], self.controller.get_listeners(Listener.CONTROL))
    self.assertEqual([9050], self.controller.get_ports(Listener.CONTROL))

    # non-local addresss

    get_conf_mock.side_effect = lambda param, **kwargs: {
      'ControlPort': '9050',
      'ControlListenAddress': ['27.4.4.1'],
    }[param]

    self.assertEqual([('27.4.4.1', 9050)], self.controller.get_listeners(Listener.CONTROL))
    self.assertEqual([], self.controller.get_ports(Listener.CONTROL))

    # Exercise via the GETINFO option.

    get_info_mock.side_effect = None
    get_info_mock.return_value = '"127.0.0.1:1112" "127.0.0.1:1114"'

    self.assertEqual(
      [('127.0.0.1', 1112), ('127.0.0.1', 1114)],
开发者ID:patrickod,项目名称:stem,代码行数:70,代码来源:controller.py


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