Skip to content

Instantly share code, notes, and snippets.

@cklein
Created December 28, 2010 19:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cklein/757621 to your computer and use it in GitHub Desktop.
Save cklein/757621 to your computer and use it in GitHub Desktop.
Execute Code on GAE dev_server.py
#!/usr/bin/env python
# encoding: utf-8
"""
execgae.py
Created by Christian Klein on 2010-12-23.
Copyright (c) 2010 HUDORA. All rights reserved.
"""
import urllib
import urllib2
import urlparse
import xml.etree.ElementTree as ET
class Executor(object):
def __init__(self, addr):
self.addr = addr
def execute(self, commands):
data = {'code': commands}
request = urllib2.Request(urlparse.urljoin(self.addr, "/_ah/admin/interactive/execute"),
urllib.urlencode(data))
response = urllib2.urlopen(request)
if response.code != 200:
raise RuntimeError('status = %s' % response.code)
tree = ET.parse(response)
return tree.findtext('//{http://www.w3.org/1999/xhtml}pre', "")
def execute_file(self, filename):
with open(filename) as inputfile:
return self.execute(inputfile.read())
def main():
e = Executor('http://localhost:8083')
print e.execute('print "hello"')
print e.execute_file('f.py')
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment