summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/__init__.py0
-rw-r--r--python/hello.py7
-rw-r--r--python/interp.py7
-rw-r--r--python/server.py33
4 files changed, 47 insertions, 0 deletions
diff --git a/python/__init__.py b/python/__init__.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/python/__init__.py
diff --git a/python/hello.py b/python/hello.py
new file mode 100644
index 00000000..b5b072bb
--- /dev/null
+++ b/python/hello.py
@@ -0,0 +1,7 @@
+import ledger
+
+def precmd_hello():
+ hello = ledger.Value()
+ hello.set_string("Well, hello yourself! This is Ledger, coming to you from Python Land.")
+ print hello
+ return hello
diff --git a/python/interp.py b/python/interp.py
new file mode 100644
index 00000000..afc62ba4
--- /dev/null
+++ b/python/interp.py
@@ -0,0 +1,7 @@
+from code import InteractiveConsole
+
+def cmd_python():
+ interpreter = InteractiveConsole()
+ interpreter.push("from ledger import *")
+ interpreter.interact("Welcome to Ledger")
+ return True
diff --git a/python/server.py b/python/server.py
new file mode 100644
index 00000000..64a91ca3
--- /dev/null
+++ b/python/server.py
@@ -0,0 +1,33 @@
+import ledger
+import cgi
+import sys
+
+from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
+
+class LedgerHandler(BaseHTTPRequestHandler):
+ def do_GET(self):
+ print "Saw a GET request!"
+ sys.exit(0)
+
+ def do_POST(self):
+ print "Saw a POST request!"
+ try:
+ ctype, pdict = cgi.parse_header(self.headers.getheader('content-type'))
+ if ctype == 'multipart/form-data':
+ query = cgi.parse_multipart(self.rfile, pdict)
+ self.send_response(301)
+ self.end_headers()
+ except Exception:
+ print "Saw exception in POST handler"
+
+def cmd_server():
+ try:
+ port = 9000
+ server = HTTPServer(('', port), LedgerHandler)
+ print "Local HTTP server listening on port %d... (Control-C to exit)" \
+ % port
+ server.serve_forever()
+ except KeyboardInterrupt:
+ print "Shutting down server"
+ server.socket.close()
+