Created
December 28, 2010 19:56
-
-
Save cklein/757621 to your computer and use it in GitHub Desktop.
Execute Code on GAE dev_server.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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