[pypy-svn] r28478 - in pypy/dist/pypy/translator/js2/proxy: . testme testme.egg-info testme/sqlobject-history testme/static testme/static/css testme/static/images testme/static/javascript testme/templates

ericvrp at codespeak.net ericvrp at codespeak.net
Wed Jun 7 19:57:10 CEST 2006


Author: ericvrp
Date: Wed Jun  7 19:57:09 2006
New Revision: 28478

Added:
   pypy/dist/pypy/translator/js2/proxy/
   pypy/dist/pypy/translator/js2/proxy/README.txt   (contents, props changed)
   pypy/dist/pypy/translator/js2/proxy/dev.cfg
   pypy/dist/pypy/translator/js2/proxy/prod.cfg
   pypy/dist/pypy/translator/js2/proxy/setup.py   (contents, props changed)
   pypy/dist/pypy/translator/js2/proxy/testme/
   pypy/dist/pypy/translator/js2/proxy/testme-start.py   (contents, props changed)
   pypy/dist/pypy/translator/js2/proxy/testme.egg-info/
   pypy/dist/pypy/translator/js2/proxy/testme.egg-info/PKG-INFO
   pypy/dist/pypy/translator/js2/proxy/testme.egg-info/SOURCES.txt   (contents, props changed)
   pypy/dist/pypy/translator/js2/proxy/testme.egg-info/not-zip-safe
   pypy/dist/pypy/translator/js2/proxy/testme.egg-info/requires.txt   (contents, props changed)
   pypy/dist/pypy/translator/js2/proxy/testme.egg-info/sqlobject.txt   (contents, props changed)
   pypy/dist/pypy/translator/js2/proxy/testme.egg-info/top_level.txt   (contents, props changed)
   pypy/dist/pypy/translator/js2/proxy/testme/__init__.py   (contents, props changed)
   pypy/dist/pypy/translator/js2/proxy/testme/controllers.py   (contents, props changed)
   pypy/dist/pypy/translator/js2/proxy/testme/model.py   (contents, props changed)
   pypy/dist/pypy/translator/js2/proxy/testme/msgstruct.py   (contents, props changed)
   pypy/dist/pypy/translator/js2/proxy/testme/sqlobject-history/
   pypy/dist/pypy/translator/js2/proxy/testme/static/
   pypy/dist/pypy/translator/js2/proxy/testme/static/css/
   pypy/dist/pypy/translator/js2/proxy/testme/static/images/
   pypy/dist/pypy/translator/js2/proxy/testme/static/javascript/
   pypy/dist/pypy/translator/js2/proxy/testme/templates/
   pypy/dist/pypy/translator/js2/proxy/testme/templates/__init__.py   (contents, props changed)
   pypy/dist/pypy/translator/js2/proxy/testme/templates/master.kid
   pypy/dist/pypy/translator/js2/proxy/testme/templates/welcome.kid
Log:
Temporary location for proxy-kind-of-code that will allow javascript to connect
(over http) to a socket server (of a not yet to be disclosed piece of
entertainment software)


Added: pypy/dist/pypy/translator/js2/proxy/README.txt
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/js2/proxy/README.txt	Wed Jun  7 19:57:09 2006
@@ -0,0 +1,4 @@
+testme
+
+This is a TurboGears (http://www.turbogears.org) project. It can be
+started by running the start-testme.py script.
\ No newline at end of file

Added: pypy/dist/pypy/translator/js2/proxy/dev.cfg
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/js2/proxy/dev.cfg	Wed Jun  7 19:57:09 2006
@@ -0,0 +1,43 @@
+# This is where all of your settings go for your development environment
+
+[global]
+
+# DATABASE
+
+# pick the form for your database
+# sqlobject.dburi="postgres://username@hostname/databasename"
+# sqlobject.dburi="mysql://username:password@hostname:port/databasename"
+# sqlobject.dburi="sqlite:///file_name_and_path"
+
+# for Windows users, sqlite URIs look like:
+# sqlobject.dburi="sqlite:///drive_letter|/path/to/file"
+
+
+# VIEW
+
+# kid.outputformat="html"
+
+# The sitetemplate is used for overall styling of a site that
+# includes multiple TurboGears applications
+# tg.sitetemplate="<packagename.templates.templatename>"
+
+
+# SERVER
+
+# Some server parameters that you may want to tweak
+# server.socketPort=8080
+
+# Disable the debug output at the end on pages.
+# logDebugInfoFilter.on = False
+
+server.environment="production" #"development"
+autoreload.package="testme"
+autoreload.on = False
+
+sessionFilter.on = True
+sessionFilter.storageType = "Ram"
+sessionFilter.cookieName = "BnB"
+
+[/static]
+staticFilter.on = True
+staticFilter.dir = "static"

Added: pypy/dist/pypy/translator/js2/proxy/prod.cfg
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/js2/proxy/prod.cfg	Wed Jun  7 19:57:09 2006
@@ -0,0 +1,40 @@
+# This is where all of your settings go for your development environment
+
+[global]
+
+# DATABASE
+
+# pick the form for your database
+# sqlobject.dburi="postgres://username@hostname/databasename"
+# sqlobject.dburi="mysql://username:password@hostname:port/databasename"
+# sqlobject.dburi="sqlite:///file_name_and_path"
+
+# for Windows users, sqlite URIs look like:
+# sqlobject.dburi="sqlite:///drive_letter|/path/to/file"
+
+
+# VIEW
+
+# kid.outputformat="html"
+
+# The sitetemplate is used for overall styling of a site that
+# includes multiple TurboGears applications
+# tg.sitetemplate="<packagename.templates.templatename>"
+
+
+# SERVER
+
+# Some server parameters that you may want to tweak
+# server.socketPort=8080
+
+server.environment="production"
+server.logFile="server.log"
+server.logToScreen=False
+
+# if this is part of a larger site, you can set the path
+# to the TurboGears instance here
+# server.webpath=""
+
+[/static]
+staticFilter.on = True
+staticFilter.dir = "static"

Added: pypy/dist/pypy/translator/js2/proxy/setup.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/js2/proxy/setup.py	Wed Jun  7 19:57:09 2006
@@ -0,0 +1,18 @@
+from setuptools import setup, find_packages
+from turbogears.finddata import find_package_data
+
+setup(
+    name="testme",
+    version="1.0",
+    #description="",
+    #author="",
+    #author_email="",
+    #url="",
+    install_requires = ["TurboGears >= 0.8.9"],
+    scripts = ["testme-start.py"],
+    zip_safe=False,
+    packages=find_packages(),
+    package_data = find_package_data(where='testme',
+                                     package='testme'),
+    )
+    

Added: pypy/dist/pypy/translator/js2/proxy/testme-start.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/js2/proxy/testme-start.py	Wed Jun  7 19:57:09 2006
@@ -0,0 +1,23 @@
+#!/usr/bin/python
+import pkg_resources
+pkg_resources.require("TurboGears")
+
+import cherrypy
+from os.path import *
+import sys
+
+# first look on the command line for a desired config file,
+# if it's not on the command line, then
+# look for setup.py in this directory. If it's not there, this script is
+# probably installed
+if len(sys.argv) > 1:
+    cherrypy.config.update(file=sys.argv[1])
+elif exists(join(dirname(__file__), "setup.py")):
+    cherrypy.config.update(file="dev.cfg")
+else:
+    cherrypy.config.update(file="prod.cfg")
+
+from testme.controllers import Root
+
+cherrypy.root = Root()
+cherrypy.server.start()

Added: pypy/dist/pypy/translator/js2/proxy/testme.egg-info/PKG-INFO
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/js2/proxy/testme.egg-info/PKG-INFO	Wed Jun  7 19:57:09 2006
@@ -0,0 +1,10 @@
+Metadata-Version: 1.0
+Name: testme
+Version: 1.0
+Summary: UNKNOWN
+Home-page: UNKNOWN
+Author: UNKNOWN
+Author-email: UNKNOWN
+License: UNKNOWN
+Description: UNKNOWN
+Platform: UNKNOWN

Added: pypy/dist/pypy/translator/js2/proxy/testme.egg-info/SOURCES.txt
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/js2/proxy/testme.egg-info/SOURCES.txt	Wed Jun  7 19:57:09 2006
@@ -0,0 +1,13 @@
+README.txt
+setup.py
+testme-start.py
+testme/__init__.py
+testme/controllers.py
+testme/model.py
+testme.egg-info/PKG-INFO
+testme.egg-info/SOURCES.txt
+testme.egg-info/not-zip-safe
+testme.egg-info/requires.txt
+testme.egg-info/sqlobject.txt
+testme.egg-info/top_level.txt
+testme/templates/__init__.py

Added: pypy/dist/pypy/translator/js2/proxy/testme.egg-info/not-zip-safe
==============================================================================

Added: pypy/dist/pypy/translator/js2/proxy/testme.egg-info/requires.txt
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/js2/proxy/testme.egg-info/requires.txt	Wed Jun  7 19:57:09 2006
@@ -0,0 +1 @@
+TurboGears >= 0.8.9
\ No newline at end of file

Added: pypy/dist/pypy/translator/js2/proxy/testme.egg-info/sqlobject.txt
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/js2/proxy/testme.egg-info/sqlobject.txt	Wed Jun  7 19:57:09 2006
@@ -0,0 +1,2 @@
+db_module=testme.model
+history_dir=$base/testme/sqlobject-history

Added: pypy/dist/pypy/translator/js2/proxy/testme.egg-info/top_level.txt
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/js2/proxy/testme.egg-info/top_level.txt	Wed Jun  7 19:57:09 2006
@@ -0,0 +1 @@
+testme

Added: pypy/dist/pypy/translator/js2/proxy/testme/__init__.py
==============================================================================

Added: pypy/dist/pypy/translator/js2/proxy/testme/controllers.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/js2/proxy/testme/controllers.py	Wed Jun  7 19:57:09 2006
@@ -0,0 +1,129 @@
+import turbogears
+from turbogears import controllers
+import cherrypy
+from msgstruct import *
+import PIL.Image
+import zlib
+import socket
+
+
+class SessionData:
+
+    def broadcast_port(self, *values):
+        print 'MESSAGE (IGNORE):broadcast_port', values
+
+    def ping(self):
+        print 'MESSAGE:ping'
+
+    def def_playfield(self, width, height, backcolor, FnDesc):
+        print 'MESSAGE:def_playfield width=%s, height=%s, backcolor=%s, FnDesc=%s' %\
+            (width, height, backcolor, FnDesc)
+
+    def def_bitmap(self, code, data, *rest):
+        print 'MESSAGE:def_bitmap code=%s, data=%d bytes, colorkey=%s' %\
+            (code, len(data), rest)
+        bitmap_filename = 'testme/static/images/bitmap%d.ppm' % code
+        f = open(bitmap_filename, 'wb')
+        f.write(zlib.decompress(data))
+        f.close()
+
+        #TODO: use in memory (don't save ppm first)
+        bitmap = PIL.Image.open(bitmap_filename)
+        gif_bitmap_filename = 'testme/static/images/bitmap%d.gif' % code
+        bitmap.save(gif_bitmap_filename)
+
+    def def_icon(self, bitmap_code, code, x,y,w,h, *rest):
+        print 'MESSAGE:def_icon bitmap_code=%s, code=%s, x=%s, y=%s, w=%s, h=%s, alpha=%s' %\
+            (bitmap_code, code, x,y,w,h, rest)
+
+        #TODO: use in memory (don't save ppm first)
+        bitmap_filename = 'testme/static/images/bitmap%d.gif' % bitmap_code
+        icon_filename = 'testme/static/images/icon%d.gif' % code
+        icon    = PIL.Image.open(bitmap_filename)
+        box     = (x, y, x+w, y+h)
+        region  = icon.crop(box)
+        region.save(icon_filename)
+        print 'SAVED:', icon_filename
+
+    MESSAGES = {
+        MSG_BROADCAST_PORT : broadcast_port,
+        MSG_PING           : ping,
+        MSG_DEF_PLAYFIELD  : def_playfield,
+        MSG_DEF_BITMAP     : def_bitmap,
+        MSG_DEF_ICON       : def_icon,
+        }
+
+    def __init__(self):
+        self.socket = None
+        self.data   = ''
+
+    def handleServerMessage(self, *values):
+        #print 'RECEIVED MESSAGE:%s(%d)' % (values[0], len(values[1:]))
+        fn = self.MESSAGES.get(values[0])
+        if fn:
+            fn(self, *values[1:])
+        else:
+            print "UNKNOWN MESSAGE:", values
+
+
+class Root(controllers.Root):
+
+    host = 'localhost'
+    port = 32819    #XXX automate this
+    size = 1024
+
+    #data
+    _sessionData = {}
+    n_header_lines = 2
+
+    def sessionData(self):
+        session = cherrypy.session
+        sessionid = session['_id']
+        if sessionid not in self._sessionData:
+            self._sessionData[sessionid] = SessionData()
+        return self._sessionData[sessionid]
+
+    def sessionSocket(self, close=False):
+        d = self.sessionData()
+        if d.socket is None:
+            d.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+            d.socket.connect((self.host, self.port))
+            #XXX todo: session.socket.close() after a timeout
+        return d.socket
+
+    @turbogears.expose()
+    def send(self, data=message(CMSG_PING)):
+        self.sessionSocket().send(data)
+        print 'SENT:' + repr(data)
+        return self.recv()
+
+    @turbogears.expose()
+    def recv(self):
+        #XXX hangs if not first sending a ping!
+        d = self.sessionData()
+        data = d.data + self.sessionSocket().recv(self.size)
+        while self.n_header_lines > 0 and '\n' in data:
+            self.n_header_lines -= 1
+            header_line, data = data.split('\n',1)
+            print 'RECEIVED HEADER LINE: %s' % header_line
+        
+        #print 'RECEIVED DATA CONTAINS %d BYTES' % len(data)
+        while data:
+            values, data = decodemessage(data)
+            if not values:
+                break  # incomplete message
+            d.handleServerMessage(*values)
+        d.data = data
+        #print 'RECEIVED DATA REMAINING CONTAINS %d BYTES' % len(data)
+
+        return dict(data=data)
+
+    @turbogears.expose()
+    def close(self):
+        session = cherrypy.session
+        sessionid = session['_id']
+        d = self.sessionData()
+        if d.socket is not None:
+            d.socket.close()
+        del self._sessionData[sessionid]
+

Added: pypy/dist/pypy/translator/js2/proxy/testme/model.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/js2/proxy/testme/model.py	Wed Jun  7 19:57:09 2006
@@ -0,0 +1,8 @@
+from sqlobject import *
+from turbogears.database import PackageHub
+
+hub = PackageHub("testme")
+__connection__ = hub
+
+# class YourDataClass(SQLObject):
+#     pass

Added: pypy/dist/pypy/translator/js2/proxy/testme/msgstruct.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/js2/proxy/testme/msgstruct.py	Wed Jun  7 19:57:09 2006
@@ -0,0 +1,75 @@
+from struct import pack, unpack, calcsize
+
+try:
+    from localmsg import PORTS
+except ImportError:
+    PORTS = {}
+try:
+    from localmsg import HOSTNAME
+except ImportError:
+    from socket import gethostname
+    HOSTNAME = gethostname()
+
+
+MSG_WELCOME = "Welcome to gamesrv.py(3) !\n"
+MSG_BROADCAST_PORT= "*"
+MSG_DEF_PLAYFIELD = "p"
+MSG_DEF_KEY       = "k"
+MSG_DEF_ICON      = "r"
+MSG_DEF_BITMAP    = "m"
+MSG_DEF_SAMPLE    = "w"
+MSG_DEF_MUSIC     = "z"
+MSG_PLAY_MUSIC    = "Z"
+MSG_FADEOUT       = "f"
+MSG_PLAYER_JOIN   = "+"
+MSG_PLAYER_KILL   = "-"
+MSG_PLAYER_ICON   = "i"
+MSG_PING          = "g"
+MSG_PONG          = "G"
+MSG_INLINE_FRAME  = "\\"
+MSG_PATCH_FILE    = MSG_DEF_MUSIC
+MSG_ZPATCH_FILE   = "P"
+MSG_MD5_FILE      = "M"
+MSG_RECORDED      = "\x00"
+
+CMSG_PROTO_VERSION= "v"
+CMSG_KEY          = "k"
+CMSG_ADD_PLAYER   = "+"
+CMSG_REMOVE_PLAYER= "-"
+CMSG_UDP_PORT     = "<"
+CMSG_ENABLE_SOUND = "s"
+CMSG_ENABLE_MUSIC = "m"
+CMSG_PING         = "g"
+CMSG_PONG         = "G"
+CMSG_DATA_REQUEST = "M"
+CMSG_PLAYER_NAME  = "n"
+
+BROADCAST_MESSAGE = "game!"   # less than 6 bytes
+
+
+def message(tp, *values):
+    strtype = type('')
+    typecodes = ['']
+    for v in values:
+        if type(v) is strtype:
+            typecodes.append('%ds' % len(v))
+        elif 0 <= v < 256:
+            typecodes.append('B')
+        else:
+            typecodes.append('l')
+    typecodes = ''.join(typecodes)
+    assert len(typecodes) < 256
+    return pack(("!B%dsc" % len(typecodes)) + typecodes,
+                len(typecodes), typecodes, tp, *values)
+
+def decodemessage(data):
+    if data:
+        limit = ord(data[0]) + 1
+        if len(data) >= limit:
+            typecodes = "!c" + data[1:limit]
+            end = limit + calcsize(typecodes)
+            if len(data) >= end:
+                return unpack(typecodes, data[limit:end]), data[end:]
+            elif end > 1000000:
+                raise OverflowError
+    return None, data

Added: pypy/dist/pypy/translator/js2/proxy/testme/templates/__init__.py
==============================================================================

Added: pypy/dist/pypy/translator/js2/proxy/testme/templates/master.kid
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/js2/proxy/testme/templates/master.kid	Wed Jun  7 19:57:09 2006
@@ -0,0 +1,17 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<?python import sitetemplate ?>
+<html xmlns="http://www.w3.org/1999/xhtml" xmlns:py="http://purl.org/kid/ns#" py:extends="sitetemplate">
+
+<head>
+    <meta content="text/html; charset=UTF-8" http-equiv="content-type" py:replace="''"/>
+    <title>Your title goes here</title>
+</head>
+
+<body py:match="item.tag=='{http://www.w3.org/1999/xhtml}body'">
+    <!-- p align="center"><img src="http://www.turbogears.org/tgheader.png"/></p -->
+    
+    <div py:if="tg_flash" class="flash" py:content="tg_flash"></div>
+    
+    <div py:replace="item[:]"/>
+</body>
+</html>

Added: pypy/dist/pypy/translator/js2/proxy/testme/templates/welcome.kid
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/js2/proxy/testme/templates/welcome.kid	Wed Jun  7 19:57:09 2006
@@ -0,0 +1,13 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xmlns:py="http://purl.org/kid/ns#"
+    py:extends="'master.kid'">
+
+<head>
+    <meta content="text/html; charset=UTF-8" http-equiv="content-type" py:replace="''"/>
+    <title>BnB</title>
+</head>
+
+<body>
+    <p>sessionid: ${sessionid}</p>
+</body>
+</html>



More information about the Pypy-commit mailing list