本文整理汇总了Python中server.Server.join方法的典型用法代码示例。如果您正苦于以下问题:Python Server.join方法的具体用法?Python Server.join怎么用?Python Server.join使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类server.Server
的用法示例。
在下文中一共展示了Server.join方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: JOIN
# 需要导入模块: from server import Server [as 别名]
# 或者: from server.Server import join [as 别名]
def JOIN(self, args):
channel = args[0]
# can't join a channel if not logged in
if self.__nickname is None:
ERRMSG(self.__sobj, "Not logged in")
return
try:
Server.join(self.__nickname, channel, self)
ACK(self.__sobj)
except Exception, errmsg:
ERRMSG(self.__sobj, errmsg)
示例2: TestWebApi
# 需要导入模块: from server import Server [as 别名]
# 或者: from server.Server import join [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
#.........这里部分代码省略.........
示例3: server
# 需要导入模块: from server import Server [as 别名]
# 或者: from server.Server import join [as 别名]
def server( parameterFile ):
module = Server( parameterFile )
module.join()