From 034f7f2fd753a69d68172ebc3da74483a5aa8c52 Mon Sep 17 00:00:00 2001 From: plarkin Date: Wed, 16 Jan 2013 19:46:25 -0800 Subject: [PATCH 1/7] Client for Week 1 Assignment: Number Addition Server --- assignments/week01/athome/echo_client.py | 38 ++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100755 assignments/week01/athome/echo_client.py diff --git a/assignments/week01/athome/echo_client.py b/assignments/week01/athome/echo_client.py new file mode 100755 index 00000000..04222cb8 --- /dev/null +++ b/assignments/week01/athome/echo_client.py @@ -0,0 +1,38 @@ +#mostly code from PyMOTW, but the number counting code is mine. +#plarkin week 1 assignment + +import socket +import sys + +# Create a TCP/IP socket +sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM,socket.IPPROTO_IP) + +# Connect the socket to the port where the server is listening +server_address = ('192.168.0.4',50002) +print >>sys.stderr, 'connecting to %s port %s' % server_address +sock.connect(server_address) + +try: + + # Send data + get_num = raw_input("number 1: "),raw_input("number 2: ") + message = get_num[0]+" "+get_num[1] + print >>sys.stderr, 'sending "%s"' % message + sock.sendall(message) + data = sock.recv(3) + print >>sys.stderr, 'received "%s"' % data + # Look for the response +# amount_received = 0 +# amount_expected = len(message) + +# while amount_received < amount_expected: +# data = sock.recv(1) +# amount_received += len(data) +# print >>sys.stderr, 'received "%s"' % data + +finally: + print >>sys.stderr, 'closing socket' + sock.close() + + +#number1 = int(raw_input("number 1: ")) \ No newline at end of file From cedf881bbc03838173376023eb98d1385c86a080 Mon Sep 17 00:00:00 2001 From: plarkin Date: Wed, 16 Jan 2013 19:47:23 -0800 Subject: [PATCH 2/7] Server for Week 1 Addignment: Number Addition Server --- assignments/week01/athome/echo_server.py | 42 ++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100755 assignments/week01/athome/echo_server.py diff --git a/assignments/week01/athome/echo_server.py b/assignments/week01/athome/echo_server.py new file mode 100755 index 00000000..8a546f9c --- /dev/null +++ b/assignments/week01/athome/echo_server.py @@ -0,0 +1,42 @@ +#mostly code from PyMOTW, but the number counting code is mine. +#plarkin week 1 assignment + +import socket +import sys + +# Create a TCP/IP socket +sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + +# Bind the socket to the port +server_address = ('192.168.0.4',50002) +print >>sys.stderr, 'starting up on %s port %s' % server_address + +sock.bind(server_address) + +# Listen for incoming connections +sock.listen(1) + +while True: + # Wait for a connection + print >>sys.stderr, 'waiting for a connection' + connection, client_address = sock.accept() + + try: + print >>sys.stderr, 'connection from', client_address + + # Receive the data in small chunks and retransmit it + while True: + data = connection.recv(3) + print >>sys.stderr, 'received "%s"' % data + if data: + print >>sys.stderr, 'sending data back to the client' + data_tuple = ( tuple( int(i) for i in data.split() ) ) + data_return = str(sum(data_tuple)) + connection.sendall(data_return) + else: + print >>sys.stderr, 'no more data from', client_address + break + + finally: + # Clean up the connection + connection.close() From a75abb703df59ad254cab2430888d9d78107537d Mon Sep 17 00:00:00 2001 From: plarkin Date: Mon, 21 Jan 2013 17:59:04 -0800 Subject: [PATCH 3/7] plarkin - week2 assignment - http_serve1 --- assignments/week02/athome/http_serve1.py | 28 ++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100755 assignments/week02/athome/http_serve1.py diff --git a/assignments/week02/athome/http_serve1.py b/assignments/week02/athome/http_serve1.py new file mode 100755 index 00000000..d4e3718a --- /dev/null +++ b/assignments/week02/athome/http_serve1.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python + +import socket + +host = '' # listen on all connections (WiFi, etc) +port = 50000 +backlog = 5 # how many connections can we stack up +size = 1024 # number of bytes to receive at once + +## create the socket +s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) +# set an option to tell the OS to re-use the socket +s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + +# the bind makes it a server +s.bind( (host,port) ) +s.listen(backlog) + +while True: # keep looking for new connections forever + client, address = s.accept() # look for a connection + data = client.recv(size) + if data: # if the connection was closed there would be no data + print "received: %s, sending it back"%data + f = open("C:/cygwin/home/plarkin/training.python_web/assignments/week02/lab/tiny_html.html", mode="r") + for line in f: + client.send(line) + client.close() + f.close() From a3e740f9906f636b854f5fef5f140152aa138ad7 Mon Sep 17 00:00:00 2001 From: plarkin Date: Mon, 21 Jan 2013 17:59:21 -0800 Subject: [PATCH 4/7] plarkin - week2 assignment - http_serve2 --- assignments/week02/athome/http_serve2.py | 33 ++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100755 assignments/week02/athome/http_serve2.py diff --git a/assignments/week02/athome/http_serve2.py b/assignments/week02/athome/http_serve2.py new file mode 100755 index 00000000..e960f22f --- /dev/null +++ b/assignments/week02/athome/http_serve2.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python + +import socket + +host = '' # listen on all connections (WiFi, etc) +port = 50000 +backlog = 5 # how many connections can we stack up +size = 1024 # number of bytes to receive at once + +## create the socket +s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) +# set an option to tell the OS to re-use the socket +s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + +# the bind makes it a server +s.bind( (host,port) ) +s.listen(backlog) + +f = open('tiny_html.html', 'r') +f_html = f.read() + +def ok_response(body): + return 'HTTP/1.1 200 OK\r\n\r\n' + body + +while True: # keep looking for new connections forever + client, address = s.accept() # look for a connection + data = client.recv(size) + if data: # if the connection was closed there would be no data + print "received: %s, sending it back"%data + send_f_html = ok_response(f_html) + client.send(send_f_html) + client.close() + f.close() From a9a5af429b90b7ef1528c00c70b7bc2638ed82ff Mon Sep 17 00:00:00 2001 From: plarkin Date: Mon, 21 Jan 2013 17:59:31 -0800 Subject: [PATCH 5/7] plarkin - week2 assignment - http_serve3 --- assignments/week02/athome/http_serve3.py | 43 ++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100755 assignments/week02/athome/http_serve3.py diff --git a/assignments/week02/athome/http_serve3.py b/assignments/week02/athome/http_serve3.py new file mode 100755 index 00000000..c2b93bb8 --- /dev/null +++ b/assignments/week02/athome/http_serve3.py @@ -0,0 +1,43 @@ +#!/usr/bin/env python + +import socket + +host = '' # listen on all connections (WiFi, etc) +port = 50000 +backlog = 5 # how many connections can we stack up +size = 1024 # number of bytes to receive at once + +## create the socket +s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) +# set an option to tell the OS to re-use the socket +s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + +# the bind makes it a server +s.bind( (host,port) ) +s.listen(backlog) + +#f = open('tiny_html.html', 'r') +#f_html = f.read() + +#def ok_response(body): +# return 'HTTP/1.1 200 OK\r\n\r\n' + body + +def parse_request(request): + parse = request.split("\r\n") + uri = parse[1].split(' ') + return uri[1] + +while True: # keep looking for new connections forever + client, address = s.accept() # look for a connection + data = client.recv(size) + if data: # if the connection was closed there would be no data + #print "received: %s, sending it back"%data + if "GET" and "HTTP" in data: + findURI = parse_request(data) + client.send(findURI) + else: + raise ValueError("ValueError") + + #send_f_html = ok_response(f_html) + #client.send(send_f_html) + client.close() From bb81f4d44863505138b19012fcdb7247e3a03fba Mon Sep 17 00:00:00 2001 From: plarkin Date: Sun, 10 Feb 2013 13:03:29 -0800 Subject: [PATCH 6/7] Week05 Comments --- assignments/week05/athome/README.txt | 30 ++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100755 assignments/week05/athome/README.txt diff --git a/assignments/week05/athome/README.txt b/assignments/week05/athome/README.txt new file mode 100755 index 00000000..9825bb18 --- /dev/null +++ b/assignments/week05/athome/README.txt @@ -0,0 +1,30 @@ +Thanks to the e-mail collaboration between chris/eric/tyler/austin I was able to get my VM running. Running the db initialize step from my VM seemed to be one solution to my configuration woes. :: https://github.com/cewing/training.python_web/blob/master/source/presentations/week05.rst#initialize-the-db-irl + +In a moment of desperation I installed Flask at root. I know it is taboo, but after 5 hours of +debugging I was willing to try anything. + +You can give flaskr a try here: http://block647060-3is.blueboxgrid.com/ + +I made no modifications to the code offered on git. + + +My flaskr.wsgi (thanks eric!): + +**/var/www/flaskr.wsgi** + +#!/usr/bin/python + +import sys +sys.path.insert(0, '/home/uw/flaskrenv/venv/lib/python2.6/site-packages/flask') +sys.path.insert(0, '/home/uw/flaskrenv/flaskr') +sys.path.insert(0, '/usr/lib/python2.6') +sys.path.insert(0, '/usr/lib/python2.6/plat-linux2') +sys.path.insert(0, '/usr/lib/python2.6/lib-tk') +sys.path.insert(0, '/usr/lib/python2.6/lib-old') +sys.path.insert(0, '/usr/lib/python2.6/lib-dynload') +sys.path.insert(0, '/usr/lib/python2.6/dist-packages') +sys.path.insert(0, '/usr/lib/pymodules/python2.6') +sys.path.insert(0, '/usr/lib/python2.6/dist-packages/wx-2.8-gtk2-unicode') +sys.path.insert(0, '/usr/local/lib/python2.6/dist-packages') + +from flaskr import app as application From 10e5eb9a7a74f68cbec1b55add37dbdf06b3a951 Mon Sep 17 00:00:00 2001 From: plarkin Date: Fri, 15 Feb 2013 23:25:17 -0800 Subject: [PATCH 7/7] rough draft - week 6 team assignment --- assignments/week06/athome/mysite/djangor/models.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100755 assignments/week06/athome/mysite/djangor/models.py diff --git a/assignments/week06/athome/mysite/djangor/models.py b/assignments/week06/athome/mysite/djangor/models.py new file mode 100755 index 00000000..d117b48f --- /dev/null +++ b/assignments/week06/athome/mysite/djangor/models.py @@ -0,0 +1,14 @@ +#ideas: http://lightbird.net/dbe/blog.html, https://github.com/ilblackdragon/django-blogs/blob/master/blog/models.py + +from django.db import models +from django.utils import timezone +from django.contrib.auth.models import User + + +class Entry(models.Model): + publication_date = models.DateTimeField('Date Published') + author = + title = models.CharField(max_length=80) + + def __unicode__(self): + return self.title \ No newline at end of file