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


Python Server.quit方法代码示例

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


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

示例1: article_worker

# 需要导入模块: from server import Server [as 别名]
# 或者: from server.Server import quit [as 别名]
def article_worker(host, user, passwd, port, use_ssl, group, start_index,
                   chunk_size, results, lock, min_index):
    signal.signal(signal.SIGINT, signal.SIG_IGN)
    s = Server(host, user, passwd, port, use_ssl)
    s.set_group(group)

    while start_index.value > min_index:
        # increment start_index here so no two processes end up pulling the same data
        with lock:
            if start_index.value < min_index:
                continue

            upper_limit = start_index.value
            lower_limit = start_index.value - chunk_size

            start_index.value = (start_index.value - chunk_size + 1)
            if lower_limit < min_index:
                lower_limit = min_index

        results.append(s.fetch_articles(group, lower_limit, upper_limit))

    # close the connection here so we can process another group
    s.quit()
开发者ID:Islandhitman,项目名称:uidx,代码行数:25,代码来源:__init__.py

示例2: TestWebApi

# 需要导入模块: from server import Server [as 别名]
# 或者: from server.Server import quit [as 别名]
class TestWebApi(unittest.TestCase):

    @property
    def _base_url(self):
        return "http://localhost:8457"

    def setUp(self):
        self._server = Server()
        self._web_api = WebApi(self._server, port=8457)
        self._server.start()
        self._web_api.start()
        self._web_api.wait_ready()

    def tearDown(self):
        self._web_api.quit()
        self._server.quit()
        self._web_api.join()
        self._server.join()

    def _api_call(self, rel_url, method, data=None):
        url = "{}{}".format(self._base_url, rel_url)
        req = urllib.request.Request(url=url, data=data,
                                     headers={'Content-Type': 'application/json'},
                                     method=method)
        with urllib.request.urlopen(req) as f:
            data = None
            json_str = f.read().decode("utf-8")
            if len(json_str) > 0:
                data = json.loads(json_str)
            return data

    def _encode_object(self, object):   # object --> UTF-8 string
        object_str = json.dumps(object)
        object_encoded = object_str.encode('utf-8')
        return object_encoded

    def test_command_list_observers(self):
        # First add 2 mocked observers
        self._server.add_observer(MockObserver("Observer1"))
        self._server.add_observer(MockObserver("Observer2"))

        # Now call the API to see if we get those two
        data = self._api_call("/api/list/observers", "GET")
        self.assertIn("observers", data)
        observer_names = [observer["name"] for observer in data["observers"]]
        self.assertListEqual(observer_names, ["Observer1", "Observer2"])

    def test_command_get_observer(self):
        self._server.add_observer(MockObserver("Observer1"))
        data = self._api_call("/api/observer/Observer1", "GET")
        self.assertDictEqual(data, {"name": "Observer1"})

    def test_command_set_config(self):
        smtp_settings = {"smtp": {"host": "smtp.myhost.com", "port": 587, "auth": True,
                                  "user": "Moatl", "pwd": "geheim123"}}
        # Set all SMTP settings together
        self._api_call("/api/config", "PUT", self._encode_object(smtp_settings))
        self.assertDictEqual(self._server.config.smtp, smtp_settings["smtp"])
        # Set a single string value
        self._api_call("/api/config/smtp/host", "PUT", self._encode_object("say.what.host"))
        self.assertEqual(self._server.config.smtp.host, "say.what.host")
        # Set a single integer value
        self._api_call("/api/config/smtp/port", "PUT", self._encode_object(8123))
        self.assertEqual(self._server.config.smtp.port, 8123)

    def test_command_get_config(self):
        smtp_settings = {"host": "smtp.myhost.com", "port": 587, "auth": True,
                         "user": "Moatl", "pwd": "geheim123"}
        self._server.config.smtp = smtp_settings;
        response_data = self._api_call("/api/config/smtp", "GET")
        self.assertDictEqual(response_data["smtp"], smtp_settings)
        response_data = self._api_call("/api/config/smtp/host", "GET")
        self.assertEqual(response_data["host"], smtp_settings["host"])
        response_data = self._api_call("/api/config/smtp/port", "GET")
        self.assertEqual(response_data["port"], smtp_settings["port"])
        response_data = self._api_call("/api/config", "GET")
        self.assertIn("web", response_data)
        self.assertIn("smtp", response_data)

    def test_command_create_observer(self):
        observer_data = dict(profile="Willhaben",
                             url="that wont work for sure",
                             store=False,
                             interval=30,
                             criteria=[
                                 dict(tag="title",
                                      type="keywords_all",
                                      keywords=["word", "perfect"])])
        observer_data_encoded = self._encode_object(observer_data)
        self._api_call("/api/observer/MyObserver", "PUT", observer_data_encoded)
        self.assertTrue("MyObserver" in self._server.observers())   # Check if the observer is there
        observer_serialized = self._server["MyObserver"].serialize()    # Check if the server has all the correct properties
        observer_data["name"] = observer_serialized["name"]     # not in the original data
        self.assertDictEqual(observer_data, observer_serialized)

    def test_command_add_notification(self):
        observer = MockObserver("MyObserver")
        self._server.add_observer(observer)
        smtp_settings = {"host": "fake", "port": 0, "auth": True,
                         "user": "me", "pwd": "secret"} # Fake SMTP settings
#.........这里部分代码省略.........
开发者ID:kolomanschaft,项目名称:updatejunkie,代码行数:103,代码来源:testwebapi.py


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