import warnings warnings.filterwarnings('ignore', message=r'Module .*? is being added to sys\.path', append=True)
ここに書いてありました:
http://lucumr.pocoo.org/2008/2/19/sick-of-pkg-resources-warnings
import warnings warnings.filterwarnings('ignore', message=r'Module .*? is being added to sys\.path', append=True)
$ tree kay-pyjamas-sample
kay-pyjamas-sample
|-- JSONRPCExample.py
`-- public
`-- JSONRPCExample.html
1 directory, 2 files
import pyjd # dummy in pyjs
from pyjamas.ui.RootPanel import RootPanel
from pyjamas.ui.TextArea import TextArea
from pyjamas.ui.Label import Label
from pyjamas.ui.Button import Button
from pyjamas.ui.HTML import HTML
from pyjamas.ui.VerticalPanel import VerticalPanel
from pyjamas.ui.HorizontalPanel import HorizontalPanel
from pyjamas.ui.ListBox import ListBox
from pyjamas.JSONService import JSONProxy
class JSONRPCExample:
def onModuleLoad(self):
self.TEXT_WAITING = "Waiting for response..."
self.TEXT_ERROR = "Server Error"
self.METHOD_ECHO = "Echo"
self.METHOD_REVERSE = "Reverse"
self.METHOD_UPPERCASE = "UPPERCASE"
self.METHOD_LOWERCASE = "lowercase"
self.methods = [self.METHOD_ECHO, self.METHOD_REVERSE, self.METHOD_UPPERCASE, self.METHOD_LOWERCASE]
self.remote_py = EchoServicePython()
self.status=Label()
self.text_area = TextArea()
self.text_area.setText("""{'Test'} [\"String\"]
\tTest Tab
Test Newline\n
after newline
""" + r"""Literal String:
{'Test'} [\"String\"]
""")
self.text_area.setCharacterWidth(80)
self.text_area.setVisibleLines(8)
self.method_list = ListBox()
self.method_list.setName("hello")
self.method_list.setVisibleItemCount(1)
for method in self.methods:
self.method_list.addItem(method)
self.method_list.setSelectedIndex(0)
method_panel = HorizontalPanel()
method_panel.add(HTML("Remote string method to call: "))
method_panel.add(self.method_list)
method_panel.setSpacing(8)
self.button_py = Button("Send to Python Service", self)
buttons = HorizontalPanel()
buttons.add(self.button_py)
buttons.setSpacing(8)
info = """JSON-RPC Example
This example demonstrates the calling of server services with
JSON-RPC.
Enter some text below, and press a button to send the text
"""
to an Echo service on your server. An echo service simply sends the exact same text back that it receives.
panel = VerticalPanel()
panel.add(HTML(info))
panel.add(self.text_area)
panel.add(method_panel)
panel.add(buttons)
panel.add(self.status)
RootPanel().add(panel)
def onClick(self, sender):
self.status.setText(self.TEXT_WAITING)
method = self.methods[self.method_list.getSelectedIndex()]
text = self.text_area.getText()
id = -1
if method == self.METHOD_ECHO:
id = self.remote_py.echo(text, self)
elif method == self.METHOD_REVERSE:
id = self.remote_py.reverse(text, self)
elif method == self.METHOD_UPPERCASE:
id = self.remote_py.uppercase(text, self)
elif method == self.METHOD_LOWERCASE:
id = self.remote_py.lowercase(text, self)
if id<0:
self.status.setText(self.TEXT_ERROR)
def onRemoteResponse(self, response, request_info):
self.status.setText(response)
def onRemoteError(self, code, message, request_info):
self.status.setText("Server Error or Invalid Response: ERROR %d - %s" %
(code, message))
class EchoServicePython(JSONProxy):
def __init__(self):
JSONProxy.__init__(self, "/json", ["echo", "reverse", "uppercase", "lowercase"])
if __name__ == '__main__':
# for pyjd, set up a web server and load the HTML from there:
# this convinces the browser engine that the AJAX will be loaded
# from the same URI base as the URL, it's all a bit messy...
pyjd.setup("http://127.0.0.1/examples/jsonrpc/public/JSONRPCExample.html")
app = JSONRPCExample()
app.onModuleLoad()
pyjd.run()
$ cd kay-pyjamas-sample
$ ${PYJAMAS_HOME}/bin/pyjsbuild -o ${PROJECT_DIR}/media JSONRPCExample.py
# -*- coding: utf-8 -*-
# myapp.urls
from werkzeug.routing import (
Map, Rule, Submount,
EndpointPrefix, RuleTemplate,
)
import myapp.views
def make_rules():
return [
EndpointPrefix('myapp/', [
Rule('/', endpoint='index'),
Rule('/json', endpoint='json_rpc'),
]),
]
all_views = {
'myapp/index': myapp.views.index,
'myapp/json_rpc': myapp.views.json_rpc,
}
# -*- coding: utf-8 -*-
# myapp.views
# ... 省略
import simplejson
# ... 省略
def json_uppercase(args):
return [args[0].upper()]
def json_echo(args):
return [args[0]]
def json_reverse(args):
return [args[0][::-1]]
def json_lowercase(args):
return [args[0].lower()]
def json_rpc(request):
if request.method:
args = simplejson.loads(request.data)
method_name = 'json_%s' % args[u"method"]
json_func = globals().get(method_name)
json_params = args[u"params"]
json_method_id = args[u"id"]
result = json_func(json_params)
args.pop(u"method")
args["result"] = result[0]
args["error"] = None
return Response(simplejson.dumps(args), content_type="application/json")
else:
return Response('Error')
$ hg clone https://kay-framework.googlecode.com/hg/ kay
$ python kay/manage.py startproject myproject
$ tree myproject
myproject
|-- app.yaml
|-- kay -> /Users/tmatsuo/work/tmp/kay/kay
|-- manage.py -> /Users/tmatsuo/work/tmp/kay/manage.py
|-- settings.py
`-- urls.py
1 directory, 4 files
$ cd myproject
$ python manage.py startapp myapp
$ tree myapp
myapp
|-- __init__.py
|-- models.py
|-- templates
| `-- index.html
|-- urls.py
`-- views.py
1 directory, 5 files
#$/usr/bin/python
#..
#..
INSTALLED_APPS = (
'kay.sessions',
'myapp',
)
APP_MOUNT_POINTS = {
'myapp': '/',
}
$ python manage.py runserver
INFO 2009-08-04 05:48:21,339 appengine_rpc.py:157] Server: appengine.google.com
...
...
INFO 2009-08-04 05:48:21,448 dev_appserver_main.py:465] Running application myproject on port 8080: http://localhost:8080
$ python manage.py appcfg update
_debugged_app = None
app = ... build your wsgi app ...
def main():
# Only run the debugger in development.
import os, sys
if 'SERVER_SOFTWARE' in os.environ and os.environ['SERVER_SOFTWARE'].startswith('Dev'):
# use our debug.utils with Jinja2 templates
import debug.utils
sys.modules['werkzeug.debug.utils'] = debug.utils
# don't use inspect.getsourcefile because the imp module is empty
import inspect
inspect.getsourcefile = inspect.getfile
# wrap the application
from werkzeug import DebuggedApplication
global _debugged_app
if _debugged_app is None:
_debugged_app = app = DebuggedApplication(app, evalex=True)
else:
app = _debugged_app
application: geotest version: 1 runtime: python api_version: 1 handlers: - url: /.* script: main.py
from google.appengine.ext import webapp from google.appengine.ext.webapp.util import run_wsgi_app import os import wsgiref.handlers from google.appengine.ext import db from google.appengine.ext.webapp import template from google.appengine.ext.db import djangoforms import my_geopt class Place(db.Model): name = db.StringProperty() description = db.StringProperty() geopoint = db.GeoPtProperty() date = db.DateTimeProperty(auto_now=True) class PlaceForm(djangoforms.ModelForm): class Meta: model = Place class MainPage(webapp.RequestHandler): def post(self): data = PlaceForm(data=self.request.POST) if data.is_valid(): # Save the data, and redirect to the view page entity = data.save(commit=False) entity.put() self.redirect('/') else: # Reprint the form contents = {'form': data} path = os.path.join(os.path.dirname(__file__), 'index.html') self.response.out.write(template.render(path, contents)) def get(self): contents = {'form': PlaceForm()} path = os.path.join(os.path.dirname(__file__), 'index.html') self.response.out.write(template.render(path, contents)) application = webapp.WSGIApplication( [('/', MainPage),], debug=True) def main(): run_wsgi_app(application) if __name__ == "__main__": main()
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>GeoPtWidgets Example</title> <script src="http://maps.google.com/maps?file=api&v=2&key=YOURAPIKEY" type="text/javascript"></script> <script src="http://www.google.com/uds/api?file=uds.js&v=1.0&key=YOURAPIKEY" type="text/javascript"></script> <script src="http://www.google.com/uds/solutions/localsearch/gmlocalsearch.js" type="text/javascript"></script> <style type="text/css"> @import url("http://www.google.com/uds/css/gsearch.css"); @import url("http://www.google.com/uds/solutions/localsearch/gmlocalsearch.css"); </style> </head> <body onunload="GUnload()"> <h1>GeoPtWidgets Example</h1> <form method="post" action="/"> {{ form.as_p }} <input type="submit" value="register"/> </form> </body> </html>