From 8b507d38b1fc518843d63216f77d6ab042c646fc Mon Sep 17 00:00:00 2001 From: Steve Date: Fri, 10 Jan 2014 19:51:18 -0800 Subject: [PATCH 1/2] incomplete --- assignments/session01/echo_client.py | 17 ++++++++++------- assignments/session01/echo_server.py | 25 ++++++++++++++++--------- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/assignments/session01/echo_client.py b/assignments/session01/echo_client.py index 61616c36..7c052020 100644 --- a/assignments/session01/echo_client.py +++ b/assignments/session01/echo_client.py @@ -6,16 +6,16 @@ def client(msg, log_buffer=sys.stderr): server_address = ('localhost', 10000) # TODO: Replace the following line with your code which will instantiate # a TCP socket with IPv4 Addressing, call the socket you make 'sock' - sock = None + sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_TCP) print >>log_buffer, 'connecting to {0} port {1}'.format(*server_address) # TODO: connect your socket to the server here. - + sock.connect(server_address) # this try/finally block exists purely to allow us to close the socket # when we are finished with it try: print >>log_buffer, 'sending "{0}"'.format(msg) # TODO: send your message to the server here. - + sock.sendall(msg) # TODO: the server should be sending you back your message as a series # of 16-byte chunks. You will want to log them as you receive # each one. You will also need to check to make sure that @@ -24,13 +24,16 @@ def client(msg, log_buffer=sys.stderr): # # Make sure that you log each chunk you receive. Use the print # statement below to do it. (The tests expect this log format) - chunk = '' - print >>log_buffer, 'received "{0}"'.format(chunk) + chunk = sock.recv(16) + if chunk: + print >>log_buffer, 'received "{0}"'.format(chunk) + else: + return finally: # TODO: after you break out of the loop receiving echoed chunks from # the server you will want to close your client socket. print >>log_buffer, 'closing socket' - + sock.close() if __name__ == '__main__': if len(sys.argv) != 2: @@ -39,4 +42,4 @@ def client(msg, log_buffer=sys.stderr): sys.exit(1) msg = sys.argv[1] - client(msg) \ No newline at end of file + client(msg) diff --git a/assignments/session01/echo_server.py b/assignments/session01/echo_server.py index 217380fb..f68bb943 100644 --- a/assignments/session01/echo_server.py +++ b/assignments/session01/echo_server.py @@ -7,16 +7,17 @@ def server(log_buffer=sys.stderr): address = ('127.0.0.1', 10000) # TODO: Replace the following line with your code which will instantiate # a TCP socket with IPv4 Addressing, call the socket you make 'sock' - sock = None + sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_TCP) # TODO: Set an option to allow the socket address to be reused immediately # see the end of http://docs.python.org/2/library/socket.html - + sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) # log that we are building a server print >>log_buffer, "making a server on {0}:{1}".format(*address) # TODO: bind your new sock 'sock' to the address above and begin to listen # for incoming connections - + sock.bind(address) + sock.listen(1) try: # the outer loop controls the creation of new connection sockets. The # server will handle each incoming connection one at a time. @@ -28,7 +29,7 @@ def server(log_buffer=sys.stderr): # the client so we can report it below. Replace the # following line with your code. It is only here to prevent # syntax errors - addr = ('bar', 'baz') + conn, addr = sock.accept() try: print >>log_buffer, 'connection - {0}:{1}'.format(*addr) @@ -41,29 +42,35 @@ def server(log_buffer=sys.stderr): # following line with your code. It's only here as # a placeholder to prevent an error in string # formatting - data = '' + data = conn.recv(16) + print >>log_buffer, 'received "{0}"'.format(data) + # TODO: you will need to check here to see if any data was # received. If so, send the data you got back to # the client. If not, exit the inner loop and wait # for a new connection from a client - + if data: + conn.sendall(data) + else: + return finally: # TODO: When the inner loop exits, this 'finally' clause will # be hit. Use that opportunity to close the socket you # created above when a client connected. Replace the # call to `pass` below, which is only there to prevent # syntax problems - pass + conn.close() except KeyboardInterrupt: # TODO: Use the python KeyboardIntterupt exception as a signal to # close the server socket and exit from the server function. # Replace the call to `pass` below, which is only there to # prevent syntax problems - pass + sock.close() + return if __name__ == '__main__': server() - sys.exit(0) \ No newline at end of file + sys.exit(0) From d916c1d457b9d9a90a888a9b53b3c8bbfc84f282 Mon Sep 17 00:00:00 2001 From: Steve Date: Mon, 24 Feb 2014 22:52:31 -0800 Subject: [PATCH 2/2] Assignment 07 --- assignments/session07/mysite/myblog/admin.py | 14 ++- assignments/session07/mysite/mysite.db | Bin 155648 -> 155648 bytes ebaq0uai.ytv.txt | 105 +++++++++++++++++++ 3 files changed, 117 insertions(+), 2 deletions(-) create mode 100644 ebaq0uai.ytv.txt diff --git a/assignments/session07/mysite/myblog/admin.py b/assignments/session07/mysite/myblog/admin.py index 67aec2d6..bf2f42d8 100644 --- a/assignments/session07/mysite/myblog/admin.py +++ b/assignments/session07/mysite/myblog/admin.py @@ -2,5 +2,15 @@ from myblog.models import Post from myblog.models import Category -admin.site.register(Post) -admin.site.register(Category) +class CategoryInline(admin.TabularInline): + model = Category.posts.through + +class PostAdmin(admin.ModelAdmin): + inlines = [CategoryInline,] + + +class CategoryAdmin(admin.ModelAdmin): + exclude = ('posts',) + +admin.site.register(Post, PostAdmin) +admin.site.register(Category, CategoryAdmin) diff --git a/assignments/session07/mysite/mysite.db b/assignments/session07/mysite/mysite.db index 63c9e9a57dbf40bdfacafb2a0d046cc8f04f22df..b1d4ed8630123bad886c972a94d3a6611ff2c5e5 100644 GIT binary patch delta 476 zcmZoTz}awsbAmLZ_ePm{=LJm_49u*IfyhG7%)s2hz+m&~^Ogb1OH$MGiz;;s@{3Cpic)hDOEUBGiZe0` zax0T^^3!4R@gVu)&EMYfF-map8!_;|<3G)Ri+?Zw0)8KUBmQdsZvF(I!D9SUk}Q&% zjMy}DP4@Y}gNunzhk;*=Plrzis9ccG^j9ORqorYTW{O#rX;ou73#)HaEJ7fuyu{GF z)FQ8_qO`ayDXXNgqA8PdGQusvVI~Xz9R}6RBFk(8%krF5qm=SAv-F(u)XK8d(#))K!&F1FlB9BG zkV(_!_!$+p-g|4Cpu(Ic7&j RY|>_6x3g@2c%M!(Ywc&7S~NV8lP! z=l>24Mt(5{eldPFpvYf7-d~NZj#b806-DW#B^lGj_!-}D-CtjML@#85OqQmS@!505sqs1OG$*!$8?x{L;2Y28JfO2FAJuX2=dUurxQ={_sAd Gd; assignments/session04/sql/createdb.py +# renamed: resources/session05/sql/ddl.sql -> assignments/session04/sql/ddl.sql +# renamed: resources/session05/sql/populatedb.py -> assignments/session04/sql/populatedb.py +# renamed: resources/session05/sql/utils.py -> assignments/session04/sql/utils.py +# new file: assignments/session04/sql_persistence_tutorial-plain.rst +# modified: assignments/session04/tasks.txt +# new file: assignments/session04/template_tutorial-plain.html +# modified: assignments/session05/microblog/microblog.py +# deleted: assignments/session05/microblog/microblog/microblog.cfg +# deleted: assignments/session05/microblog/microblog/microblog.db +# deleted: assignments/session05/microblog/microblog/microblog.py +# deleted: assignments/session05/microblog/microblog/microblog_tests.py +# deleted: assignments/session05/microblog/microblog/schema.sql +# deleted: assignments/session05/microblog/microblog/templates/layout.html +# deleted: assignments/session05/microblog/microblog/templates/login.html +# deleted: assignments/session05/microblog/microblog/templates/show_entries.html +# new file: assignments/session06/django_intro-plain.html +# new file: assignments/session06/img/admin_index.png +# new file: assignments/session06/img/django-admin-login.png +# new file: assignments/session06/img/django-start.png +# new file: assignments/session06/tasks.txt +# new file: assignments/session07/mysite/manage.py +# new file: assignments/session07/mysite/myblog/__init__.py +# new file: assignments/session07/mysite/myblog/admin.py +# new file: assignments/session07/mysite/myblog/fixtures/myblog_test_fixture.json +# new file: assignments/session07/mysite/myblog/migrations/0001_initial.py +# new file: assignments/session07/mysite/myblog/migrations/0002_auto__add_category.py +# new file: assignments/session07/mysite/myblog/migrations/__init__.py +# new file: assignments/session07/mysite/myblog/models.py +# renamed: resources/session08/django_blog.css -> assignments/session07/mysite/myblog/static/django_blog.css +# new file: assignments/session07/mysite/myblog/templates/detail.html +# new file: assignments/session07/mysite/myblog/templates/list.html +# new file: assignments/session07/mysite/myblog/tests.py +# new file: assignments/session07/mysite/myblog/urls.py +# new file: assignments/session07/mysite/myblog/views.py +# new file: assignments/session07/mysite/mysite.db +# new file: assignments/session07/mysite/mysite/__init__.py +# new file: assignments/session07/mysite/mysite/settings.py +# new file: assignments/session07/mysite/mysite/templates/base.html +# new file: assignments/session07/mysite/mysite/templates/login.html +# new file: assignments/session07/mysite/mysite/urls.py +# new file: assignments/session07/mysite/mysite/wsgi.py +# new file: assignments/session07/tasks.txt +# modified: buildout.cfg +# modified: docutils.conf +# modified: resources/session04/wsgi/bookapp.py +# renamed: assignments/session05/microblog/microblog/static/style.css -> resources/session05/microblog/static/style.css +# modified: resources/session06/microblog/microblog_tests.py +# new file: resources/session07/django_blog.css +# modified: resources/session08/mysite/myblog/admin.py +# new file: resources/session08/mysite/myblog/migrations/0001_initial.py +# new file: resources/session08/mysite/myblog/migrations/0002_auto__add_category.py +# new file: resources/session08/mysite/myblog/migrations/__init__.py +# modified: resources/session08/mysite/myblog/models.py +# modified: resources/session08/mysite/myblog/static/django_blog.css +# modified: resources/session08/mysite/myblog/templates/detail.html +# modified: resources/session08/mysite/myblog/templates/list.html +# modified: resources/session08/mysite/myblog/tests.py +# modified: resources/session08/mysite/myblog/urls.py +# modified: resources/session08/mysite/myblog/views.py +# modified: resources/session08/mysite/mysite/settings.py +# modified: resources/session08/mysite/mysite/templates/base.html +# modified: resources/session08/mysite/mysite/templates/login.html +# modified: resources/session08/mysite/mysite/urls.py +# modified: resources/session08/mysite/mysite/wsgi.py +# new file: source/additional/flask_walkthrough.rst +# new file: source/additional/git_cleanup.rst +# new file: source/additional/sql_persistence_tutorial.rst +# new file: source/additional/template_tutorial.rst +# modified: source/img/admin_index.png +# new file: source/img/flask_hello.png +# modified: source/main/outline.rst +# modified: source/main/readings.rst +# renamed: source/presentations/session07.rst -> source/presentations/django_intro.rst +# modified: source/presentations/session02.rst +# modified: source/presentations/session03.rst +# modified: source/presentations/session04.rst +# renamed: source/presentations/session06.rst -> source/presentations/session05.rst +# modified: source/presentations/session06.rst +# renamed: source/presentations/session08.rst -> source/presentations/session07.rst +# modified: source/presentations/session08.rst +# +