2
# -*- coding: utf-8 -*-
4
# Copyright (C) 2014 Canonical Ltd
6
# This program is free software: you can redistribute it and/or modify
7
# it under the terms of the GNU Lesser General Public License version 3 as
8
# published by the Free Software Foundation.
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU Lesser General Public License for more details.
15
# You should have received a copy of the GNU Lesser General Public License
16
# along with this program. If not, see <http://www.gnu.org/licenses/>.
18
# Authored by: Pete Woods <pete.woods@canonical.com>
20
import tornado.httpserver
22
import tornado.netutil
26
RESPONSE = '''<Response>
29
<CountryCode>GB</CountryCode>
30
<CountryCode3>GBR</CountryCode3>
31
<CountryName>United Kingdom</CountryName>
32
<RegionCode>H2</RegionCode>
33
<RegionName>Lancashire</RegionName>
34
<City>Accrington</City>
35
<ZipPostalCode>BB5</ZipPostalCode>
36
<Latitude>55.7654</Latitude>
37
<Longitude>-2.7467</Longitude>
38
<AreaCode>0</AreaCode>
39
<TimeZone>Europe/London</TimeZone>
43
class Lookup(tornado.web.RequestHandler):
45
sys.stderr.write('GeoIP location requested\n')
52
application = tornado.web.Application([
55
sockets = tornado.netutil.bind_sockets(0, '127.0.0.1')
56
server = tornado.httpserver.HTTPServer(application)
57
server.add_sockets(sockets)
59
sys.stdout.write('%d\n' % sockets[0].getsockname()[1])
64
if __name__ == "__main__":
65
application = new_app()
66
tornado.ioloop.IOLoop.instance().start()