コード例 #1
0
ファイル: tests.py プロジェクト: AHAPX/websocket
 def test_server(self):
     server = WebSocketServer()
     # test run
     with patch("asyncio.async") as mock, patch(
         "asyncio.base_events.BaseEventLoop.run_until_complete"
     ) as mock1, patch("asyncio.base_events.BaseEventLoop.run_forever") as mock2:
         run(MagicMock, MagicMock, "localhost", 999, "localhost", 6379, 0, "ws-channel")
         mock.assert_called_once()
         mock1.assert_called_once()
         mock2.assert_called_once()
     # test receiver
     client = Client(MockSocket(True))
     server.receiver(client, "msg")
     self.assertEqual(client.name, "unknown")
     server.receiver(client, '{"message": "msg", "tags": ["tag1", "tag2"]}')
     server.receiver(client, "msg")
     self.assertEqual(client.name, "tag1, tag2")
コード例 #2
0
ファイル: api.py プロジェクト: cream/melange-experiments
import urllib
from contextlib import closing
from lxml.etree import parse as parse_xml


CURRENT_URL = 'http://api.wunderground.com/auto/wui/geo/WXCurrentObXML/index.xml?query={0}'


@Api.register('weather')
class Weather(Api):


    @Api.expose
    def get_temperature(self, location):

        print
        print location
        print

        current_url = CURRENT_URL.format(location)
        with closing(urllib.urlopen(current_url)) as file_handle:
            current_data = parse_xml(file_handle)

        return {'temperature': current_data.find('temp_c').text, 'location': location}



if __name__ == '__main__':
    run(ApiWebSocket)
コード例 #3
0
def main():
    run(8000, False)