summaryrefslogtreecommitdiff
path: root/tools/web
diff options
context:
space:
mode:
authorBen Longbons <b.r.longbons@gmail.com>2013-05-17 12:41:41 -0700
committerBen Longbons <b.r.longbons@gmail.com>2013-05-17 12:44:59 -0700
commitf142608716e8e5c0411715eb7bb0b88f65de0ee1 (patch)
treeb30a65550fef201c5116b52d139e63b3fa7d2b53 /tools/web
parentcf071d9846890a24d8d462f82da9b6d0f96d8fd2 (diff)
downloadserverdata-f142608716e8e5c0411715eb7bb0b88f65de0ee1.tar.gz
serverdata-f142608716e8e5c0411715eb7bb0b88f65de0ee1.tar.bz2
serverdata-f142608716e8e5c0411715eb7bb0b88f65de0ee1.tar.xz
serverdata-f142608716e8e5c0411715eb7bb0b88f65de0ee1.zip
Make the tmx converter update resnametable.txt
If/when we use static instancing, we'll have to change this.
Diffstat (limited to 'tools/web')
-rw-r--r--tools/web/README3
-rwxr-xr-xtools/web/main.py28
-rw-r--r--tools/web/with_xml.py71
3 files changed, 102 insertions, 0 deletions
diff --git a/tools/web/README b/tools/web/README
new file mode 100644
index 00000000..dc7bc55b
--- /dev/null
+++ b/tools/web/README
@@ -0,0 +1,3 @@
+This is a flask app to manage accounts.
+
+It implements a full-featured webserver, but is usually proxied by nginx.
diff --git a/tools/web/main.py b/tools/web/main.py
new file mode 100755
index 00000000..b7501c5c
--- /dev/null
+++ b/tools/web/main.py
@@ -0,0 +1,28 @@
+#!/usr/bin/env python2.6
+
+from flask import Flask
+
+from with_xml import Node
+
+app = Flask(__name__)
+
+@app.route('/')
+def index():
+ content = Node()
+ tag = content.tag
+ put = content.put
+ a = tag('a')
+ with tag('html'):
+ with tag('head'):
+ with tag('title'):
+ put('Title')
+ with tag('body'):
+ with tag('h1'):
+ put('Header')
+ put('This is ')
+ with a(href='http://google.com/'):
+ put('a link to Google.')
+ return str(content)
+
+if __name__ == '__main__':
+ app.run(debug=True)
diff --git a/tools/web/with_xml.py b/tools/web/with_xml.py
new file mode 100644
index 00000000..bc49a94e
--- /dev/null
+++ b/tools/web/with_xml.py
@@ -0,0 +1,71 @@
+''' A stupid little way of generating xml
+'''
+
+import re
+
+from flask import escape
+
+PRETTY = True
+
+class Context(object):
+ __slots__ = ('_node', '_name', '_kwargs')
+ pattern = re.compile(r'[A-Za-z]\w*')
+
+ def __init__(self, node, name, kwargs):
+ self._node = node
+ self._name = name
+ self._kwargs = kwargs
+
+ def __enter__(self):
+ _node = self._node
+ _buffer = _node._buffer
+ _node.nl()
+ _buffer.extend(['<', escape(self._name)])
+ for k, v in self._kwargs.iteritems():
+ assert Context.pattern.match(k)
+ _buffer.extend([' ', k, '="', escape(v), '"'])
+ _buffer.append('>')
+ _node._indent += 1
+ _node.nl()
+
+ def __exit__(self, exc_type, exc_value, traceback):
+ _node = self._node
+ _buffer = _node._buffer
+ _node._indent -= 1
+ _node.nl()
+ if _buffer[-1] == '>' and _buffer[-3] != '</':
+ _buffer[-1] = '/>'
+ else:
+ _buffer.extend(['</', escape(self._name), '>'])
+ _node.nl()
+
+ def __call__(_self, **kwargs):
+ new_kwargs = dict(_self._kwargs)
+ new_kwargs.update(kwargs)
+ return Context(_self._node, _self._name, new_kwargs)
+
+class Node(object):
+ __slots__ = ('_buffer', '_indent')
+
+ def __init__(self):
+ self._buffer = ['<?xml version="1.0" encoding="utf-8"?>', '\n', '']
+ self._indent = 0
+
+ def tag(_self, _name, **kwargs):
+ return Context(_self, _name, kwargs)
+
+
+ def put(self, text):
+ self._buffer.append(escape(text))
+
+ def __str__(self):
+ return ''.join(self._buffer)
+
+ def nl(self):
+ if PRETTY:
+ _buffer = self._buffer
+ if _buffer[-2] == '\n':
+ _buffer.pop()
+ else:
+ _buffer.append('\n')
+ _buffer.extend([' ' * self._indent])