File: twms.py

package info (click to toggle)
twms 0.03e-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 424 kB
  • sloc: python: 1,527; sh: 111; makefile: 9
file content (71 lines) | stat: -rwxr-xr-x 1,732 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/python
# -*- coding: utf-8 -*-
#    This file is part of tWMS.

#   tWMS is free software: you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation, either version 3 of the License, or
#   (at your option) any later version.

#   tWMS is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.

#   You should have received a copy of the GNU General Public License
#   along with tWMS.  If not, see <http://www.gnu.org/licenses/>.

import web
import sys
from twms.twms import *

try:
        import psyco
        psyco.full()
except ImportError:
        pass

OK = 200
ERROR = 500


def handler():
    """
    A handler for web.py.
    """
    data = web.input()
    resp, ctype, content = twms_main(data)
    web.header('Content-type', ctype)
    return content



urls = (
      '/(.*)', 'mainhandler'
)
class mainhandler:
   def GET(self, crap):
       return handler()



if __name__ == "__main__":
    try:
     if sys.argv[1] == "josm":                                  # josm mode 
      import cgi
      url, params = sys.argv[2].split("/?", 1)
      data = cgi.parse_qs(params)
      for t in data.keys():
        data[t] = data[t][0]
      resp, ctype, content = twms_main(data)
      print content
      exit()
    except IndexError:
      pass


    app = web.application(urls, globals())
    app.run()                                                    # standalone run


application = web.application(urls, globals()).wsgifunc()        # mod_wsgi