Commits

Benoit Boissinot committed 70c48af

add welcome tile, normalize unicode

Comments (0)

Files changed (1)

 
 from google.appengine.ext import db
 
+maxrange = 2**27
+tilelength = 32*32
+
+#welcome = u'Bienvenue dans lemur2.0'+u' '*1001
+welcome_tile = 'x\x9cs\xcaL\xcd+K\xcd+MUHI\xcc+V\xc8I\xcd--2\xd23P\x18\x05\xa3`\x14\x0c\x7f\x00\x00\x8eM\x85]'
 #empty_tile = zlib.compress(' '*(32*32))
 empty_tile = 'x\x9cSP\x18\x05\xa3`\x14\x8cT\x00\x00S\x00\x80\x01'
-maxrange = 2**27
-tilelength = 32*32
 
 import unicodedata, re
 # TODO: check wide characters?
 
 class Tiles(webapp.RequestHandler):
     def get(self, *args):
-        if args[0] is None:
+        if args[1] is None or args[2] is None:
             x, y = 0, 0
         else:
             x = long(args[1]) % maxrange
             y = long(args[2]) % maxrange
 
         t = get_tile(x, y)
-        if t is None:
+        if (x, y) == (0, 0) and (t is None or t.content != welcome_tile):
+            content = welcome_tile
+            tile = Tile(x=x, y=y, content=content)
+            tile.put()
+        elif t is None:
             content = empty_tile
         else:
             content = t.content
 
         content = zlib.decompress(content)
+
         tile = {
             'coord': (x, y),
             'content': content, #list(split32(content)),
             content = self.request.body.decode('utf8')
 
         content = remove_control_chars(content)
+        content = unicodedata.normalize('NFKC', content)
 
         if len(content) != tilelength or (x, y) == (0, 0):
             raise Exception("Invalid input")