├── .gitignore ├── Examples ├── Readme.rst ├── advancedOO │ ├── constrained_int │ │ ├── constrained_int.py │ │ ├── readme.rst │ │ └── test_constrained_int.py │ ├── diamond.py │ ├── even_int.py │ ├── even_int_solution.py │ ├── invalid_mro.py │ ├── kwargs.py │ ├── logging_dict.py │ ├── mixins.py │ ├── mro.py │ ├── new_example.py │ ├── shapes.py │ ├── super_test.ipynb │ ├── test_even_int.py │ └── unpickle.py ├── capitalize │ ├── cap_script.py │ ├── capital_mod.py │ ├── sample_text_file.txt │ ├── sample_text_file_cap.txt │ └── test_capital_mod.py ├── datetime_example.py ├── debugging │ ├── long_loop.py │ └── wikidef │ │ ├── api.py │ │ ├── define.py │ │ ├── definitions.py │ │ ├── html2text.py │ │ ├── test_wikidef.py │ │ └── test_wikidef_with_mock.py ├── documentation │ └── Capitalize │ │ ├── CHANGES.txt │ │ ├── LICENSE.txt │ │ ├── MANIFEST.txt │ │ ├── README.txt │ │ ├── bin │ │ └── cap_script.py │ │ ├── capitalize │ │ ├── __init__.py │ │ ├── capital_mod.py │ │ └── test │ │ │ ├── __init__.py │ │ │ ├── sample_text_file.txt │ │ │ └── test_capital_mod.py │ │ ├── doc │ │ ├── Makefile │ │ ├── make.bat │ │ └── source │ │ │ ├── conf.py │ │ │ ├── index.rst │ │ │ ├── reference.rst │ │ │ └── tutorial.rst │ │ ├── setup.cfg │ │ └── setup.py ├── extensions │ ├── c-api │ │ ├── add.c │ │ ├── divide │ │ │ ├── divide.c │ │ │ ├── setup.py │ │ │ └── test_divide.py │ │ ├── setup.py │ │ └── test_add.py │ ├── ctypes │ │ ├── Makefile │ │ ├── add.c │ │ ├── add.dll │ │ ├── pointers.py │ │ ├── qsort_test.py │ │ └── test_add.py │ ├── cython │ │ ├── AGC_example │ │ │ ├── README.rst │ │ │ ├── agc_c.c │ │ │ ├── agc_c_cy.pyx │ │ │ ├── agc_cython.pyx │ │ │ ├── agc_program.f │ │ │ ├── agc_python.py │ │ │ ├── agc_subroutine.f │ │ │ ├── agc_subroutine.pyf │ │ │ ├── plot_agc.py │ │ │ ├── setup.py │ │ │ └── test_agc.py │ │ ├── NotesAboutCythonExample.txt │ │ ├── add.c │ │ ├── add.h │ │ ├── cy_add1.pyx │ │ ├── cy_add2.pyx │ │ ├── cy_add_c.pyx │ │ ├── integrate │ │ │ ├── cy_integrate1.pyx │ │ │ ├── cy_integrate2.pyx │ │ │ ├── cy_integrate3.pyx │ │ │ ├── cy_integrate4.pyx │ │ │ ├── cy_integrate5.pyx │ │ │ ├── cy_integrate6.pyx │ │ │ ├── cy_integrate7.pyx │ │ │ ├── integrate.py │ │ │ ├── setup.py │ │ │ ├── test_integrate.py │ │ │ └── timer_context.py │ │ ├── setup.py │ │ ├── test_cy_add1.py │ │ ├── test_cy_add2.py │ │ └── test_cy_add_c.py │ ├── distutils │ │ ├── add.py │ │ └── setup.py │ ├── pure-c │ │ ├── Makefile │ │ └── add.c │ └── swig │ │ ├── README.rst │ │ ├── add.c │ │ ├── add.i │ │ ├── add.py │ │ ├── ruby │ │ ├── add.c │ │ ├── add.i │ │ └── extconf.rb │ │ ├── setup.py │ │ └── test_add.py ├── logging │ ├── example.py │ └── worker.py ├── matplotlib │ ├── lena.png │ ├── matplotlib-instructor.ipynb │ └── matplotlib-learner.ipynb ├── metaclasses │ ├── cool_meta.py │ ├── mangler.py │ ├── my_solution.py │ ├── singleton.py │ └── start_class.py ├── nosql │ ├── address_book_model.py │ ├── address_book_mongo.py │ ├── address_book_zodb.py │ ├── mongo_test.py │ ├── test_address_book_model.py │ └── test_address_book_mongo.py ├── numpy │ ├── README.rst │ ├── broadcasting.ipynb │ ├── constructors.ipynb │ ├── dtypes.ipynb │ ├── fancy_indexing.ipynb │ ├── filter_example.py │ ├── memory_structure.ipynb │ ├── object.ipynb │ ├── reshaping.ipynb │ ├── slice.ipynb │ ├── start.py │ ├── stride_tricks.ipynb │ ├── striding_examples.txt │ └── sudoku-chb.py ├── packaging │ └── Capitalize │ │ ├── CHANGES.txt │ │ ├── LICENSE.txt │ │ ├── MANIFEST.txt │ │ ├── README.txt │ │ ├── bin │ │ └── cap_script │ │ ├── capitalize │ │ ├── __init__.py │ │ ├── capital_mod.py │ │ └── test │ │ │ ├── __init__.py │ │ │ ├── sample_text_file.txt │ │ │ └── test_capital_mod.py │ │ └── setup.py ├── pandas │ ├── IntroductionToPandas.html │ ├── IntroductionToPandas_files │ │ ├── 88x31.png │ │ ├── alfie.f51946af45e0b561c60f768335c9eb79.js │ │ ├── all-nocdn.css │ │ ├── all-nocdn.js │ │ ├── common.bundle.a8371d2f5c54e47dba1b471e1a96a2f8.js │ │ ├── config.js │ │ ├── count-data.js │ │ ├── count.js │ │ ├── discovery.bundle.0b2b44b6bfbbdf79338f10a546d5b492.js │ │ ├── embed.js │ │ ├── event.js │ │ ├── ga.js │ │ ├── lounge.bundle.04998cf95d03a1f4b8b137eaf58a9cad.js │ │ ├── lounge.load.8e73082f9192426c928801477056b9da.js │ │ ├── mike_head.png │ │ ├── noavatar92.b677f9ddbee6f4bb22f473ae3bd61b85.png │ │ ├── noavatar92.png │ │ └── saved_resource.html │ ├── README.rst │ ├── pandas_tutorial.ipynb │ └── weather_year.csv ├── pep8 │ ├── Listing1.py │ ├── encoding.py │ └── pep8_fail.py ├── persistence │ ├── Solutions │ │ ├── add_book_data.py │ │ ├── add_book_data_flat.py │ │ ├── circle.py │ │ ├── csv_example.py │ │ ├── dbm_example.py │ │ ├── indent_etree.py │ │ ├── ini_file_example.py │ │ ├── json_example.py │ │ ├── pickle_example.py │ │ ├── pickle_example2.py │ │ ├── python_literal.py │ │ ├── shelve_example.py │ │ ├── sqlite_example.py │ │ ├── xml_example.py │ │ └── xml_example2.py │ ├── add_book_data.py │ ├── add_book_data_flat.py │ └── eggs.csv ├── profiling │ ├── bna_reader │ │ ├── ChesapeakeBay.bna │ │ ├── filescanner.pyx │ │ ├── polygons.py │ │ ├── read_bna.py │ │ ├── setup.py │ │ └── small.bna │ ├── data_aggregation │ │ ├── agg.py │ │ ├── containers.py │ │ ├── loops.py │ │ ├── pycallgraph.png │ │ └── timer.py │ ├── django │ │ └── benchmark │ │ │ ├── benchmark │ │ │ ├── __init__.py │ │ │ ├── settings.py │ │ │ ├── templates │ │ │ │ └── index.html │ │ │ ├── urls.py │ │ │ └── wsgi.py │ │ │ ├── benchmarkapp │ │ │ ├── __init__.py │ │ │ ├── index.html │ │ │ ├── models.py │ │ │ ├── tests.py │ │ │ └── views.py │ │ │ └── manage.py │ ├── integrate │ │ ├── integrate.py │ │ ├── integrate_main.py │ │ └── pycallgraph.png │ ├── json │ │ ├── js.py │ │ └── pycallgraph.png │ ├── line_profiler │ │ ├── integrate.py │ │ ├── integrate_main.py │ │ ├── integrate_main.py.lprof │ │ └── pycallgraph.png │ ├── notebook │ │ └── Big_O.ipynb │ ├── numpy │ │ ├── decorators.py │ │ ├── image_array.png │ │ ├── images.py │ │ ├── images2.py │ │ ├── matrix.py │ │ ├── out.png │ │ ├── shift.py │ │ ├── str.py │ │ ├── test_image.jpg │ │ ├── timer.py │ │ └── xion.jpg │ ├── pygame │ │ ├── ball.gif │ │ ├── bounce.py │ │ ├── out.prof │ │ ├── pycallgraph.png │ │ ├── sun.gif │ │ └── swarm.py │ ├── strings │ │ ├── str_comprehensions.py │ │ ├── str_concat.py │ │ └── timer.py │ ├── timer │ │ └── timer_test.py │ └── wikidef │ │ ├── api.py │ │ ├── define.py │ │ ├── define.py.lprof │ │ ├── definitions.py │ │ ├── dump.callgrind │ │ ├── dump.profile │ │ ├── html2text.py │ │ ├── output.callgrind │ │ ├── print_stats.py │ │ ├── pycallgraph.png │ │ └── tests │ │ ├── wikidef_tests.py │ │ └── wikidef_tests_with_mock.py ├── ref_counting │ ├── CircularReferenceExample.ipynb │ ├── circular.py │ ├── mem_check.py │ ├── memcount.py │ ├── simple_circular.py │ └── simple_circular_di.py ├── sql │ ├── address_book_ddl.sql │ ├── address_book_model.py │ ├── address_book_sql.py │ ├── createdb.py │ ├── ddl.sql │ ├── little_bobby_tables.py │ ├── placeholders.py │ ├── populatedb.py │ ├── postgres.py │ ├── sqlite3_psycopg2_exceptions.py │ ├── threaded.py │ └── utils.py ├── testing │ ├── calculator │ │ ├── calculator.py │ │ ├── calculator_functions.py │ │ ├── calculator_test.sh │ │ ├── calculator_test_suite.py │ │ ├── solution │ │ │ ├── calculator.py │ │ │ ├── calculator_functions.py │ │ │ ├── calculator_test_suite.py │ │ │ └── test_calculator.py │ │ └── test_calculator.py │ ├── context_manager │ │ ├── context_manager.py │ │ └── exercise1.py │ ├── coverage │ │ ├── calculator.py │ │ ├── calculator_functions.py │ │ ├── calculator_test.sh │ │ ├── calculator_test_suite.py │ │ ├── doctests.py │ │ ├── myprog.py │ │ └── test_calculator.py │ ├── decorators │ │ ├── decorators.py │ │ └── my_solution.py │ ├── doctests │ │ └── square.py │ ├── selenium │ │ └── selenium_test.py │ ├── solutions │ │ ├── calculator_functions.py │ │ ├── context_manager_exception_swallower.py │ │ └── test_calculator.py │ ├── test_float.py │ └── wikidef │ │ ├── api.py │ │ ├── define.py │ │ ├── definitions.py │ │ ├── solution │ │ ├── api.py │ │ ├── define.py │ │ ├── definitions.py │ │ ├── solution.rst │ │ └── test_wikidef_with_mock.py │ │ ├── test_wikidef.py │ │ └── test_wikidef_with_mock.py ├── threading-multiprocessing │ ├── celery │ │ ├── master.py │ │ └── tasks.py │ ├── decorators │ │ ├── __init__.py │ │ └── decorators.py │ ├── integrate │ │ ├── __init__.py │ │ ├── decorators.py │ │ ├── integrate.py │ │ ├── integrate_main.py │ │ ├── integrate_main_profiler.py │ │ └── sequential │ │ │ └── integrate_main.py │ ├── lock │ │ ├── simple_locks.py │ │ ├── stdout_writer.py │ │ ├── stdout_writer_semaphore.py │ │ └── stdout_writer_solution.py │ ├── multiprocessing │ │ └── integrate_main.py │ ├── race_condition.py │ ├── server │ │ ├── app.py │ │ ├── client-asyncio.py │ │ ├── client-mp.py │ │ ├── client-pooled-solution.py │ │ ├── client-pooled.py │ │ ├── client-threading.py │ │ └── serve.py │ ├── simple-threading.py │ ├── sqlite_threaded.py │ ├── test.db │ └── threading │ │ └── integrate_main.py └── wxpython │ ├── CalculatorDemo.py │ ├── address_book │ ├── a_book.json │ ├── address_book_app.py │ ├── address_book_data.py │ ├── entry_form.py │ └── switcher.py │ ├── address_book_solution │ ├── a_book.json │ ├── address_book_app.py │ ├── address_book_data.py │ ├── entry_form.py │ └── switcher.py │ ├── basic_app_1.py │ ├── basic_app_2.py │ ├── basic_app_3.py │ ├── basic_app_4.py │ ├── basic_app_5.py │ ├── basic_app_6.py │ ├── basic_app_7.py │ └── basic_app_8.py ├── LICENSE ├── Python 3 Topic Options (Responses) - Form Responses 1.tsv ├── README.rst ├── Syllabus.md ├── possible_topics.txt ├── process_survey.py ├── slides_sources ├── Makefile ├── Readme.rst ├── build_gh_pages.sh ├── html_slides │ ├── 03-debugging.html │ ├── 04-db.html │ ├── 04-db.rst │ ├── 06-datetime.html │ ├── 06-metaclasses.html │ ├── 06-metaclasses.rst │ ├── 07-threading-and-multiprocessing.html │ ├── 09-profiling.html │ ├── 09-profiling.rst │ ├── deckjs │ │ ├── CHANGELOG.md │ │ ├── MIT-license.txt │ │ ├── Makefile │ │ ├── README.md │ │ ├── core │ │ │ ├── deck.core.css │ │ │ ├── deck.core.js │ │ │ ├── deck.core.scss │ │ │ ├── print.css │ │ │ └── print.scss │ │ ├── extensions │ │ │ ├── goto │ │ │ │ ├── deck.goto.css │ │ │ │ ├── deck.goto.html │ │ │ │ ├── deck.goto.js │ │ │ │ └── deck.goto.scss │ │ │ ├── hash │ │ │ │ ├── deck.hash.css │ │ │ │ ├── deck.hash.html │ │ │ │ ├── deck.hash.js │ │ │ │ └── deck.hash.scss │ │ │ ├── menu │ │ │ │ ├── deck.menu.css │ │ │ │ ├── deck.menu.js │ │ │ │ └── deck.menu.scss │ │ │ ├── navigation │ │ │ │ ├── deck.navigation.css │ │ │ │ ├── deck.navigation.html │ │ │ │ ├── deck.navigation.js │ │ │ │ └── deck.navigation.scss │ │ │ ├── scale │ │ │ │ ├── deck.scale.css │ │ │ │ ├── deck.scale.js │ │ │ │ └── deck.scale.scss │ │ │ └── status │ │ │ │ ├── deck.status.css │ │ │ │ ├── deck.status.html │ │ │ │ ├── deck.status.js │ │ │ │ └── deck.status.scss │ │ ├── introduction │ │ │ └── index.html │ │ ├── jquery.min.js │ │ ├── modernizr.custom.js │ │ ├── proposals.html │ │ ├── test │ │ │ ├── fixtures │ │ │ │ ├── empty.html │ │ │ │ ├── nesteds.html │ │ │ │ └── standard.html │ │ │ ├── index.html │ │ │ ├── settings.js │ │ │ ├── spec.core.js │ │ │ ├── spec.goto.js │ │ │ ├── spec.menu.js │ │ │ ├── spec.navigation.js │ │ │ ├── spec.scale.js │ │ │ └── spec.status.js │ │ └── themes │ │ │ ├── style │ │ │ ├── _reset.scss │ │ │ ├── neon.css │ │ │ ├── neon.scss │ │ │ ├── swiss.css │ │ │ ├── swiss.scss │ │ │ ├── web-2.0.css │ │ │ └── web-2.0.scss │ │ │ └── transition │ │ │ ├── fade.css │ │ │ ├── fade.scss │ │ │ ├── horizontal-slide.css │ │ │ ├── horizontal-slide.scss │ │ │ ├── vertical-slide.css │ │ │ └── vertical-slide.scss │ ├── images │ │ ├── 200px-SQLite.png │ │ ├── 3vl.png │ │ ├── 6libU.png │ │ ├── Diamond_inheritance.png │ │ ├── FfBuN.png │ │ ├── Greenwich_clock.jpg │ │ ├── OPP.0108.gif │ │ ├── big_o.png │ │ ├── closures.jpg │ │ ├── database.gif │ │ ├── flags.jpg │ │ ├── gil.png │ │ ├── image.png │ │ ├── killGIL.jpg │ │ ├── mysql_100x58.gif │ │ ├── mysql_large.png │ │ ├── pgsql_100x58.gif │ │ ├── pgsql_large.png │ │ ├── pycallgraph.png │ │ ├── python_comrades1.png │ │ ├── runsnake.png │ │ ├── sql_anatomy.png │ │ ├── sql_dbs.png │ │ ├── state_of_packaging.jpg │ │ └── x2.png │ └── pep8 │ │ ├── CHANGELOG.md │ │ ├── MIT-license.txt │ │ ├── Makefile │ │ ├── README.md │ │ ├── core │ │ ├── deck.core.css │ │ ├── deck.core.js │ │ ├── deck.core.scss │ │ ├── print.css │ │ └── print.scss │ │ ├── extensions │ │ ├── goto │ │ │ ├── deck.goto.css │ │ │ ├── deck.goto.html │ │ │ ├── deck.goto.js │ │ │ └── deck.goto.scss │ │ ├── menu │ │ │ ├── deck.menu.css │ │ │ ├── deck.menu.js │ │ │ └── deck.menu.scss │ │ ├── navigation │ │ │ ├── deck.navigation.css │ │ │ ├── deck.navigation.html │ │ │ ├── deck.navigation.js │ │ │ └── deck.navigation.scss │ │ ├── scale │ │ │ ├── deck.scale.css │ │ │ ├── deck.scale.js │ │ │ └── deck.scale.scss │ │ └── status │ │ │ ├── deck.status.css │ │ │ ├── deck.status.html │ │ │ ├── deck.status.js │ │ │ └── deck.status.scss │ │ ├── index.html │ │ ├── introduction │ │ └── index.html │ │ ├── jquery.min.js │ │ ├── modernizr.custom.js │ │ ├── test │ │ ├── fixtures │ │ │ ├── empty.html │ │ │ ├── nesteds.html │ │ │ └── standard.html │ │ ├── index.html │ │ ├── settings.js │ │ ├── spec.core.js │ │ ├── spec.goto.js │ │ ├── spec.menu.js │ │ ├── spec.navigation.js │ │ ├── spec.scale.js │ │ └── spec.status.js │ │ └── themes │ │ ├── style │ │ ├── _reset.scss │ │ ├── neon.css │ │ ├── neon.scss │ │ ├── swiss.css │ │ ├── swiss.scss │ │ ├── web-2.0.css │ │ └── web-2.0.scss │ │ └── transition │ │ ├── fade.css │ │ ├── fade.scss │ │ ├── horizontal-slide.css │ │ ├── horizontal-slide.scss │ │ ├── vertical-slide.css │ │ └── vertical-slide.scss ├── requirements.txt ├── scss_sources │ └── slides_custom.scss └── source │ ├── _static │ ├── Diamond_inheritance.png │ ├── Greenwich_clock.jpg │ ├── color_git_prompt.png │ ├── dst_fb_graph.png │ ├── dst_sf_graph.png │ ├── flake8_output.png │ ├── git_another_commit_on_branch.png │ ├── git_checkout_branch.png │ ├── git_checkout_master.png │ ├── git_commit_on_branch.png │ ├── git_head.png │ ├── git_master_branch.png │ ├── git_merge_commit.png │ ├── git_new_branch.png │ ├── git_new_commit.png │ ├── git_new_commit_on_master.png │ ├── git_simple_timeline.png │ ├── pc_menu.png │ ├── plugin_list.png │ ├── program_callstack.png │ ├── python.png │ ├── remotes_clone.png │ ├── remotes_fork.png │ ├── remotes_start.png │ ├── remotes_upstream.png │ ├── simple_prompt.png │ ├── tab_completion.png │ ├── test_v_model.png │ ├── transmogrifier.jpg │ ├── two_line_prompt.png │ └── virtualenv_prompt.png │ ├── _templates │ ├── end_slide.html │ └── title_slide.html │ ├── advanced_oo.rst │ ├── code_review.rst │ ├── conf.py │ ├── datetime.rst │ ├── debugging.rst │ ├── documentation.rst │ ├── extensions.rst │ ├── homework │ └── index.rst │ ├── images │ ├── OPP.0108.gif │ ├── big_o.png │ ├── flags.jpg │ ├── gil.png │ ├── killGIL.jpg │ ├── pycallgraph.png │ ├── snakeviz.png │ └── x2.png │ ├── index.rst │ ├── logging.rst │ ├── metaclasses.rst │ ├── nosql.rst │ ├── notes │ ├── BuildingExtensions.rst │ ├── InstallingTheScipyStack.rst │ ├── Installing_wxPython.rst │ └── Installing_wxPython_demo.rst │ ├── packaging.rst │ ├── persistance_serialization.rst │ ├── profiling.rst │ ├── resources │ ├── ICanEatGlass.utf16.txt │ ├── ICanEatGlass.utf8.txt │ ├── exception_test.py │ ├── hello_unicode.py │ ├── latin1_test.py │ ├── text.utf16 │ ├── text.utf32 │ ├── text.utf8 │ └── unicodify.py │ ├── scipy.rst │ ├── syllabus.rst │ ├── testing.rst │ ├── threading-multiprocessing.rst │ ├── unicode.rst │ ├── weak_references.rst │ └── wxpython.rst └── survey_results.txt /.gitignore: -------------------------------------------------------------------------------- 1 | slides_sources/build 2 | .idea 3 | .DS_Store 4 | .cache* 5 | #ignore compiled files, sublime workspace and project files 6 | *.pyc 7 | *junk* 8 | 9 | #ignore sublime workspace files 10 | *.sublime* 11 | 12 | # emacs 13 | *.*~ 14 | 15 | .project 16 | .pydevproject 17 | # ignore .gitignore, so we can each have our own. 18 | .gitignore 19 | 20 | build/ 21 | 22 | .ipynb_checkpoints 23 | .coverage 24 | -------------------------------------------------------------------------------- /Examples/Readme.rst: -------------------------------------------------------------------------------- 1 | PLce to put various example code, files, etc. 2 | -------------------------------------------------------------------------------- /Examples/advancedOO/constrained_int/constrained_int.py: -------------------------------------------------------------------------------- 1 | class ConstrainedInt(int): 2 | """keeps value between 0 and 255""" 3 | def __new__(cls, value): 4 | value = value % 256 5 | self = int.__new__(cls, value) 6 | return self 7 | 8 | def __add__(self, other): 9 | return int(self) + int(other) 10 | -------------------------------------------------------------------------------- /Examples/advancedOO/constrained_int/test_constrained_int.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | from constrained_int import ConstrainedInt 4 | 5 | 6 | class TestConstrainedInt(unittest.TestCase): 7 | 8 | def test_constrainedint(self): 9 | x = ConstrainedInt(10) 10 | self.assertEqual(x, 10) 11 | 12 | def test_constrainedint_mods_correctly(self): 13 | x = ConstrainedInt(256) 14 | self.assertEqual(x, 0) 15 | 16 | def test_constrainedint_handles_addition(self): 17 | x = ConstrainedInt(10) 18 | x += 246 19 | self.assertEqual(x, 0) 20 | -------------------------------------------------------------------------------- /Examples/advancedOO/diamond.py: -------------------------------------------------------------------------------- 1 | class A(object): 2 | def do_your_stuff(self): 3 | print("doing A's stuff") 4 | 5 | 6 | class B(A): 7 | def do_your_stuff(self): 8 | A.do_your_stuff(self) 9 | print("doing B's stuff") 10 | 11 | 12 | class C(A): 13 | def do_your_stuff(self): 14 | A.do_your_stuff(self) 15 | print("doing C's stuff") 16 | 17 | 18 | class D(B, C): 19 | def do_your_stuff(self): 20 | B.do_your_stuff(self) 21 | C.do_your_stuff(self) 22 | print("doing D's stuff") 23 | 24 | 25 | if __name__ == '__main__': 26 | a = A() 27 | print("\ncalling A's method") 28 | a.do_your_stuff() 29 | 30 | print("\ncalling B's method") 31 | b = B() 32 | b.do_your_stuff() 33 | 34 | print("\ncalling C's method") 35 | c = C() 36 | c.do_your_stuff() 37 | 38 | print("\ncalling D's method") 39 | d = D() 40 | d.do_your_stuff() 41 | -------------------------------------------------------------------------------- /Examples/advancedOO/even_int.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | Using new to create an even integer 5 | 6 | rounds the input to the nearest even integer. 7 | 8 | will even convert a string to an int... 9 | 10 | """ 11 | 12 | 13 | class EvenInt(int): 14 | """ 15 | An integer that is always even 16 | """ 17 | pass 18 | -------------------------------------------------------------------------------- /Examples/advancedOO/even_int_solution.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | Using new to create an even integer 5 | 6 | rounds the input to the nearest even integer. 7 | 8 | will even convert a string to an int... 9 | 10 | """ 11 | 12 | 13 | class EvenInt(int): 14 | """ 15 | An integer that is always even 16 | """ 17 | def __new__(cls, number): 18 | num = round(float(number) / 2) * 2 19 | 20 | return int.__new__(cls, num) 21 | 22 | -------------------------------------------------------------------------------- /Examples/advancedOO/invalid_mro.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | 4 | class X(): 5 | pass 6 | 7 | 8 | class Y(): 9 | pass 10 | 11 | 12 | class A(X, Y): 13 | pass 14 | 15 | 16 | class B(Y, X): 17 | pass 18 | 19 | 20 | class C(A, B): 21 | pass 22 | -------------------------------------------------------------------------------- /Examples/advancedOO/kwargs.py: -------------------------------------------------------------------------------- 1 | def foo(bar, **kwargs): 2 | print(bar) 3 | 4 | foo("lion") 5 | foo(bar="lion") 6 | -------------------------------------------------------------------------------- /Examples/advancedOO/logging_dict.py: -------------------------------------------------------------------------------- 1 | import collections 2 | import logging 3 | 4 | logger = logging.getLogger() 5 | logger.setLevel(logging.INFO) 6 | 7 | 8 | class Base(): 9 | def __str__(self): 10 | return "\n".join(['%s : %s' % (key, self[key]) for key in self.keys()]) 11 | 12 | 13 | class LoggingDict(Base, dict): 14 | def __setitem__(self, key, value): 15 | logging.info('Setting %s to %s' % (key, value)) 16 | super(LoggingDict, self).__setitem__(key, value) 17 | 18 | def __getitem__(self, key): 19 | value = super(LoggingDict, self).__getitem__(key) 20 | logging.info('Getting %s (%s)' % (key, value)) 21 | return value 22 | 23 | 24 | class UpperCaseDict(Base, dict): 25 | def __setitem__(self, key, value): 26 | super(UpperCaseDict, self).__setitem__(key.upper(), value.upper()) 27 | 28 | 29 | class LoggingOrderedDict(UpperCaseDict, LoggingDict, collections.OrderedDict): 30 | pass 31 | 32 | d = logging_dict = LoggingDict() 33 | d = upper_case_dict = UpperCaseDict() 34 | d = logging_ordered_dict = LoggingOrderedDict() 35 | 36 | d['a_key'] = 'my_value' 37 | d['b_key'] = 'my_value' 38 | d['c_key'] = 'my_value' 39 | 40 | print(d) 41 | -------------------------------------------------------------------------------- /Examples/advancedOO/mixins.py: -------------------------------------------------------------------------------- 1 | import time 2 | 3 | 4 | class Base(): 5 | def log(self): 6 | pass 7 | 8 | 9 | class LoggingMixin(Base): 10 | def log(self): 11 | print("time is: %s" % time.time()) 12 | # print("this is:", self) 13 | super().log() 14 | 15 | 16 | class Vehicle(Base): 17 | def log(self): 18 | print("this is:", self.__repr__()) 19 | super().log() 20 | 21 | 22 | class TwoWheeledVehicle(Vehicle): 23 | pass 24 | 25 | 26 | class LightVehicle(Vehicle): 27 | pass 28 | 29 | 30 | class HeavyVehicle(Vehicle): 31 | pass 32 | 33 | 34 | class Bike(LoggingMixin, TwoWheeledVehicle, LightVehicle): 35 | pass 36 | 37 | 38 | class MotorCycle(TwoWheeledVehicle, HeavyVehicle): 39 | pass 40 | 41 | 42 | class Tank(HeavyVehicle): 43 | pass 44 | 45 | 46 | bike = Bike() 47 | tank = Tank() 48 | 49 | bike.log() 50 | tank.log() 51 | -------------------------------------------------------------------------------- /Examples/advancedOO/mro.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | 4 | class A(object): 5 | def my_method(self): 6 | print("called A") 7 | 8 | 9 | class B(A): 10 | def my_method(self): 11 | print("called B") 12 | super(B, self).my_method() 13 | 14 | 15 | class C(A): 16 | def my_method(self): 17 | print("called C") 18 | super(C, self).my_method() 19 | 20 | 21 | class B1(B): 22 | def my_method(self): 23 | print("called B1") 24 | super(B1, self).my_method() 25 | 26 | 27 | class C1(C): 28 | def my_method(self): 29 | print("called C1") 30 | super(C1, self).my_method() 31 | 32 | 33 | class D(B1, C1): 34 | def my_method(self): 35 | print("called D") 36 | super(D, self).my_method() 37 | 38 | print(D.mro()) 39 | d = D() 40 | print(d.my_method()) 41 | -------------------------------------------------------------------------------- /Examples/advancedOO/new_example.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | example of __new__ 5 | """ 6 | 7 | 8 | # the general case: 9 | class Test(): 10 | def __new__(cls, arg): 11 | print("in __new__:") 12 | print(arg) 13 | obj = super().__new__(cls) 14 | # you _could_ do something with arg here: 15 | obj.arg = arg 16 | # but it's usally better to save that for the __init__ 17 | return obj 18 | 19 | def __init__(self, arg): 20 | print("in __init__") 21 | print(arg) 22 | self.that = arg 23 | 24 | 25 | # subclassing a string 26 | 27 | class CapitalString(str): 28 | """ 29 | A string class that is always capitalized... 30 | """ 31 | def __new__(cls, in_string): 32 | print("in CapitalString.__new__") 33 | print(cls) 34 | # return str.__new__(cls, in_string.title()) 35 | return super().__new__(cls, in_string.title()) 36 | 37 | if __name__ == "__main__": 38 | print(CapitalString("this is a string")) 39 | -------------------------------------------------------------------------------- /Examples/advancedOO/shapes.py: -------------------------------------------------------------------------------- 1 | class Shape: 2 | def __str__(self): 3 | return "Shape:{}".format(self.__class__.__name__) 4 | 5 | 6 | class Rectangle(Shape): 7 | def __init__(self, width, height): 8 | # validate inputs: 9 | assert(width > 0) 10 | assert(height > 0) 11 | 12 | self.width = width 13 | self.height = height 14 | 15 | def area(self): 16 | """returns the area of this Rectangle""" 17 | return self.width * self.height 18 | 19 | 20 | class Square(Rectangle): 21 | def __init__(self, length): 22 | self.width = length 23 | self.height = length 24 | 25 | print(Square(10).area()) 26 | -------------------------------------------------------------------------------- /Examples/advancedOO/test_even_int.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | tests for an even integer class 5 | """ 6 | 7 | from even_int import EvenInt 8 | # from even_int_solution import EvenInt 9 | 10 | 11 | # And some tests -- try with py.test or nosetests... 12 | def test_subclass(): 13 | assert issubclass(EvenInt, int) 14 | 15 | 16 | def test_instance(): 17 | i = EvenInt(3) 18 | assert isinstance(i, int) 19 | 20 | 21 | def test_isinstance(): 22 | i = EvenInt(2) 23 | assert isinstance(i, EvenInt) 24 | 25 | 26 | def test_even(): 27 | assert EvenInt(4) == 4 28 | 29 | 30 | def test_odd1(): 31 | assert EvenInt(3) == 4 32 | 33 | 34 | def test_odd2(): 35 | assert EvenInt(2.99) == 2 36 | 37 | 38 | def test_negative(): 39 | assert EvenInt(-2) == -2 40 | 41 | 42 | def test_negative_odd(): 43 | assert EvenInt(-1) == 0 44 | 45 | 46 | def test_negative_odd2(): 47 | assert EvenInt(-1.1) == -2 48 | 49 | 50 | def test_string_odd(): 51 | assert EvenInt("3") == 4 52 | 53 | 54 | def test_string_even(): 55 | assert EvenInt("12") == 12 56 | 57 | 58 | def test_string_float(): 59 | assert EvenInt("4.45") == 4 60 | -------------------------------------------------------------------------------- /Examples/advancedOO/unpickle.py: -------------------------------------------------------------------------------- 1 | import pickle 2 | 3 | 4 | class Foo: 5 | def __init__(self): 6 | print("init called") 7 | 8 | foo = Foo() 9 | 10 | foo_pickle = pickle.dumps(foo) 11 | 12 | new_foo = pickle.loads(foo_pickle) 13 | -------------------------------------------------------------------------------- /Examples/capitalize/cap_script.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | A really simple script just to demonstrate disutils 5 | """ 6 | 7 | import sys, os 8 | import capital_mod 9 | 10 | 11 | if __name__ == "__main__": 12 | try: 13 | infilename = sys.argv[1] 14 | except IndexError: 15 | print("you need to pass in a file to process") 16 | 17 | root, ext = os.path.splitext(infilename) 18 | outfilename = root + "_cap" + ext 19 | 20 | # do the real work: 21 | print("Capitalizing: %s and storing it in %s"%(infilename, outfilename)) 22 | capital_mod.capitalize(infilename, outfilename) 23 | 24 | print("I'm done") 25 | 26 | -------------------------------------------------------------------------------- /Examples/capitalize/sample_text_file.txt: -------------------------------------------------------------------------------- 1 | This is a really simple Text file. 2 | It is here so that I can test the capitalize script. 3 | 4 | And that's only there to try out distutils. 5 | 6 | So there. 7 | -------------------------------------------------------------------------------- /Examples/capitalize/sample_text_file_cap.txt: -------------------------------------------------------------------------------- 1 | This Is A Really Simple Text File. 2 | It Is Here So That I Can Test The Capitalize Script. 3 | 4 | And That's Only There To Try Out Distutils. 5 | 6 | So There. 7 | 8 | -------------------------------------------------------------------------------- /Examples/capitalize/test_capital_mod.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | test code for capitalize module 5 | 6 | can be run with py.test or nosetests 7 | """ 8 | 9 | import capital_mod 10 | 11 | #print(capitalize.__file__) 12 | 13 | def test_capitalize_line(): 14 | line = "this is a Line to capitalize" 15 | expected = "This Is A Line To Capitalize" 16 | 17 | assert capital_mod.capitalize_line(line) == expected 18 | 19 | def test_capitalize(): 20 | """ test an actual string """ 21 | capital_mod.capitalize("sample_text_file.txt", "sample_text_file_cap.txt") 22 | contents = open("sample_text_file_cap.txt", 'U').read() 23 | expected = """This Is A Really Simple Text File. 24 | It Is Here So That I Can Test The Capitalize Script. 25 | 26 | And That's Only There To Try Out Distutils. 27 | 28 | So There.""" 29 | assert contents.strip() == expected 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /Examples/datetime_example.py: -------------------------------------------------------------------------------- 1 | import datetime 2 | 3 | today = datetime.date.today() 4 | print(today) 5 | print('ctime :', today.ctime()) 6 | tt = today.timetuple() 7 | print('tuple : tm_year =', tt.tm_year) 8 | print(' tm_mon =', tt.tm_mon) 9 | print(' tm_mday =', tt.tm_mday) 10 | print(' tm_hour =', tt.tm_hour) 11 | print(' tm_min =', tt.tm_min) 12 | print(' tm_sec =', tt.tm_sec) 13 | print(' tm_wday =', tt.tm_wday) 14 | print(' tm_yday =', tt.tm_yday) 15 | print(' tm_isdst =', tt.tm_isdst) 16 | print('ordinal:', today.toordinal()) 17 | print('Year :', today.year) 18 | print('Mon :', today.month) 19 | print('Day :', today.day) 20 | 21 | d1 = datetime.date(2008, 3, 29) 22 | print('d1:', d1.ctime()) 23 | 24 | d2 = d1.replace(year=2009) 25 | print('d2:', d2.ctime()) 26 | 27 | today = datetime.date.today() 28 | print('Today :', today) 29 | 30 | one_day = datetime.timedelta(days=1) 31 | print('One day :', one_day) 32 | 33 | yesterday = today - one_day 34 | print('Yesterday:', yesterday) 35 | 36 | tomorrow = today + one_day 37 | print('Tomorrow :', tomorrow) 38 | 39 | print() 40 | print('tomorrow - yesterday:', tomorrow - yesterday) 41 | print('yesterday - tomorrow:', yesterday - tomorrow) 42 | -------------------------------------------------------------------------------- /Examples/debugging/long_loop.py: -------------------------------------------------------------------------------- 1 | 2 | def long_loop(): 3 | for i in range(int(1e04)): 4 | i+1 5 | if i == 777: 6 | raise Exception("terrible bug") 7 | result = 1 + 1 8 | return result 9 | 10 | print(long_loop()) 11 | 12 | s = "next statement" 13 | print(s) 14 | -------------------------------------------------------------------------------- /Examples/debugging/wikidef/api.py: -------------------------------------------------------------------------------- 1 | import requests 2 | 3 | 4 | class ParseError(Exception): 5 | pass 6 | 7 | 8 | class Wikipedia(object): 9 | """Wikipedia API interface""" 10 | 11 | api_endpoint = "http://en.wikipedia.org/w/api.php?" 12 | 13 | @classmethod 14 | def article(cls, title): 15 | """Return contents of article 16 | 17 | arguments: 18 | 19 | title -- title of article 20 | """ 21 | data = {'action': 'parse', 'format': 'json', 'prop':'text', 'page': title} 22 | response = requests.get(cls.api_endpoint, params=data) 23 | json_response = response.json() 24 | 25 | try: 26 | contents = json_response['parse']['text']['*'] 27 | except KeyError: 28 | raise ParseError(json_response) 29 | 30 | return contents 31 | -------------------------------------------------------------------------------- /Examples/debugging/wikidef/define.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | """ 4 | Script to contact Wikipedia and get articles on a specified topic. 5 | python define.py interesting_topic 6 | """ 7 | 8 | import sys 9 | 10 | from definitions import Definitions 11 | from html2text import html2text 12 | 13 | title = len(sys.argv) == 2 and sys.argv[1] or "" 14 | 15 | definition = Definitions.article(title) 16 | txt = html2text(definition) 17 | print(txt.encode('utf-8')) 18 | 19 | -------------------------------------------------------------------------------- /Examples/debugging/wikidef/definitions.py: -------------------------------------------------------------------------------- 1 | from api import Wikipedia 2 | 3 | class Definitions(object): 4 | 5 | @classmethod 6 | def article(cls, title): 7 | return Wikipedia.article(title) 8 | -------------------------------------------------------------------------------- /Examples/debugging/wikidef/test_wikidef.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | from api import Wikipedia, ParseError 4 | from definitions import Definitions 5 | 6 | class WikiDefTest(unittest.TestCase): 7 | 8 | def setUp(self): 9 | pass 10 | 11 | def tearDown(self): 12 | pass 13 | 14 | def test_article_success(self): 15 | article = Definitions.article("Robot") 16 | self.assertIn("mechanical", article) 17 | 18 | def test_missing_article_failure(self): 19 | missing_article_title = "!!!!!-NonExistentArticle" 20 | self.assertRaises(ParseError, Definitions.article, missing_article_title) 21 | 22 | -------------------------------------------------------------------------------- /Examples/documentation/Capitalize/CHANGES.txt: -------------------------------------------------------------------------------- 1 | v 0.0.1, 2014:03:23 -- Initial release. 2 | 3 | -------------------------------------------------------------------------------- /Examples/documentation/Capitalize/LICENSE.txt: -------------------------------------------------------------------------------- 1 | The license for the capitalize package 2 | 3 | Public Domain: do with it what you will. 4 | 5 | -------------------------------------------------------------------------------- /Examples/documentation/Capitalize/MANIFEST.txt: -------------------------------------------------------------------------------- 1 | include *.txt -------------------------------------------------------------------------------- /Examples/documentation/Capitalize/README.txt: -------------------------------------------------------------------------------- 1 | =================== 2 | Capitalize Package 3 | =================== 4 | 5 | A basic pacakge for Capitalizing text in files 6 | 7 | Purpose 8 | ======== 9 | 10 | Nothing useful, just something to demonstrate packaging with. 11 | 12 | -------------------------------------------------------------------------------- /Examples/documentation/Capitalize/bin/cap_script.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | A really simple script just to demonstrate disutils 5 | """ 6 | 7 | import sys, os 8 | from capitalize import capital_mod 9 | 10 | 11 | if __name__ == "__main__": 12 | try: 13 | infilename = sys.argv[1] 14 | except IndexError: 15 | print "you need to pass in a file to process" 16 | 17 | root, ext = os.path.splitext(infilename) 18 | outfilename = root + "_cap" + ext 19 | 20 | # do the real work: 21 | print "Capitalizing: %s and storing it in %s"%(infilename, outfilename) 22 | capital_mod.capitalize(infilename, outfilename) 23 | 24 | print "I'm done" 25 | -------------------------------------------------------------------------------- /Examples/documentation/Capitalize/capitalize/__init__.py: -------------------------------------------------------------------------------- 1 | # init for Capitalize package 2 | 3 | """ 4 | A little package to make it easy to Capitalize things. 5 | 6 | Really useless -- but here to demostrate packaging and documentation 7 | """ 8 | 9 | __version__ = "0.1.1" 10 | -------------------------------------------------------------------------------- /Examples/documentation/Capitalize/capitalize/test/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | Test package for capitalize module 3 | """ 4 | 5 | import os 6 | 7 | 8 | def runall(): 9 | import pytest 10 | pytest.main(os.path.split(__file__)[0]) 11 | -------------------------------------------------------------------------------- /Examples/documentation/Capitalize/capitalize/test/sample_text_file.txt: -------------------------------------------------------------------------------- 1 | This is a really simple Text file. 2 | It is here so that I can test the capitalize script. 3 | 4 | And that's only there to try out packaging and documentation. 5 | 6 | So there. 7 | -------------------------------------------------------------------------------- /Examples/documentation/Capitalize/doc/source/index.rst: -------------------------------------------------------------------------------- 1 | .. capitalize documentation master file, created by 2 | sphinx-quickstart on Tue Apr 19 19:51:59 2016. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | Welcome to capitalize's documentation! 7 | ====================================== 8 | 9 | Capitalize is a small packge that helps you capitilze text files. 10 | 11 | Contents: 12 | 13 | .. toctree:: 14 | :maxdepth: 2 15 | 16 | tutorial.rst 17 | reference.rst 18 | 19 | 20 | 21 | Indices and tables 22 | ================== 23 | 24 | * :ref:`genindex` 25 | * :ref:`modindex` 26 | * :ref:`search` 27 | 28 | -------------------------------------------------------------------------------- /Examples/documentation/Capitalize/doc/source/reference.rst: -------------------------------------------------------------------------------- 1 | ============= 2 | Lib Reference 3 | ============= 4 | 5 | the reference docs 6 | 7 | The capitalize packge 8 | ===================== 9 | 10 | .. automodule:: capitalize 11 | 12 | capital_mod module 13 | ------------------- 14 | 15 | .. automodule:: capitalize.capital_mod 16 | :members: 17 | 18 | -------------------------------------------------------------------------------- /Examples/documentation/Capitalize/doc/source/tutorial.rst: -------------------------------------------------------------------------------- 1 | ======== 2 | Tutorial 3 | ======== 4 | 5 | A short tutorial for capitalize 6 | 7 | Easy Start 8 | ========== 9 | 10 | just do: 11 | 12 | .. code-block:: bash 13 | 14 | $ capitalize.py a_text_file 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /Examples/documentation/Capitalize/setup.cfg: -------------------------------------------------------------------------------- 1 | [aliases] 2 | test=pytest -------------------------------------------------------------------------------- /Examples/documentation/Capitalize/setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | This is about as simple a setup.py as you can have 5 | 6 | It installs the capitalize module and script 7 | 8 | """ 9 | 10 | from setuptools import setup 11 | 12 | import capitalize # to get __version__ 13 | 14 | setup( 15 | name='Capitalize', 16 | version=capitalize.__version__, 17 | author='Chris Barker', 18 | author_email='PythonCHB@gmail.com', 19 | packages=['capitalize', 20 | 'capitalize/test'], 21 | scripts=['bin/cap_script.py', ], 22 | setup_requires=['pytest-runner'], 23 | tests_require=['pytest'], 24 | license='LICENSE.txt', 25 | description='Not very useful capitalizing module and script', 26 | long_description=open('README.txt').read(), 27 | ) 28 | -------------------------------------------------------------------------------- /Examples/extensions/c-api/add.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static PyObject * 4 | add(PyObject *self, PyObject *args) 5 | { 6 | int x; 7 | int y; 8 | int sts; 9 | 10 | if (!PyArg_ParseTuple(args, "ii", &x, &y)) 11 | return NULL; 12 | sts = x+y; 13 | return Py_BuildValue("i", sts); 14 | } 15 | 16 | // Module's method table and initialization function 17 | // see: https://docs.python.org/2/extending/extending.html#the-module-s-method-table-and-initialization-function 18 | static PyMethodDef AddMethods[] = { 19 | {"add", add, METH_VARARGS, "add two numbers"}, 20 | {NULL, NULL, 0, NULL} // sentinel 21 | }; 22 | 23 | 24 | PyMODINIT_FUNC 25 | initadd(void) { 26 | // Module's initialization function 27 | // Will be called again if you use Python's reload() 28 | (void) Py_InitModule("add", AddMethods); 29 | } 30 | -------------------------------------------------------------------------------- /Examples/extensions/c-api/divide/divide.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static PyObject * 4 | divide(PyObject *self, PyObject *args) 5 | { 6 | double x; 7 | double y; 8 | double sts; 9 | 10 | if (!PyArg_ParseTuple(args, "dd", &x, &y)) 11 | return NULL; 12 | sts = x/y; 13 | return Py_BuildValue("d", sts); 14 | } 15 | 16 | // Module's method table and initialization function 17 | // See: http://docs.python.org/extending/extending.html#the-module-s-method-table-and-initialization-function 18 | static PyMethodDef DivideMethods[] = { 19 | {"divide", divide, METH_VARARGS, "divide two numbers"}, 20 | {NULL, NULL, 0, NULL} 21 | }; 22 | 23 | PyMODINIT_FUNC // does the right thing on Windows, Linux, etc. 24 | initdivide(void) { 25 | // Module's initialization function 26 | // Will be called again if you use Python's reload() 27 | 28 | Py_InitModule("divide", DivideMethods); 29 | } 30 | -------------------------------------------------------------------------------- /Examples/extensions/c-api/divide/setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from setuptools import setup, Extension 4 | 5 | setup( 6 | name='Cdiv', 7 | version='1.0', 8 | description='sample method that does exceptions', 9 | ext_modules=[Extension('divide', sources=['divide.c'])], 10 | ) 11 | -------------------------------------------------------------------------------- /Examples/extensions/c-api/divide/test_divide.py: -------------------------------------------------------------------------------- 1 | """ 2 | test file for the divide function 3 | """ 4 | 5 | import pytest 6 | 7 | from divide import divide 8 | 9 | 10 | def test_divide(): 11 | assert divide(3, 4) == 0.75 12 | 13 | 14 | def test_divide_zero(): 15 | # if it acts like python, it should raise an exception 16 | with pytest.raises(ZeroDivisionError): 17 | divide(3, 0) 18 | -------------------------------------------------------------------------------- /Examples/extensions/c-api/setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from setuptools import setup, Extension 4 | 5 | setup( 6 | name='Cadd', 7 | version='1.0', 8 | description='simple c extension for an example', 9 | ext_modules=[Extension('add', sources=['add.c'])], 10 | ) 11 | -------------------------------------------------------------------------------- /Examples/extensions/c-api/test_add.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | simple test for the add C extension 5 | """ 6 | 7 | import pytest 8 | 9 | import add 10 | 11 | def test_basic(): 12 | assert add.add(3,4) == 7 13 | 14 | def test_negative(): 15 | assert add.add(-12, 5) == -7 16 | 17 | def test_float(): 18 | with pytest.raises(TypeError): 19 | add.add(3, 4.0) 20 | 21 | 22 | -------------------------------------------------------------------------------- /Examples/extensions/ctypes/Makefile: -------------------------------------------------------------------------------- 1 | all: add; gcc -shared -o add.so add.c 2 | -------------------------------------------------------------------------------- /Examples/extensions/ctypes/add.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int add(int x, int y) { 4 | return x+y; 5 | } 6 | int main(void) { 7 | int w = 3; 8 | int q = 2; 9 | printf("%d + %d = %d\n\n", w, q, add(w,q)); 10 | } 11 | -------------------------------------------------------------------------------- /Examples/extensions/ctypes/add.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/Examples/extensions/ctypes/add.dll -------------------------------------------------------------------------------- /Examples/extensions/ctypes/pointers.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from ctypes import * 4 | 5 | libc = CDLL("libc.dylib") 6 | 7 | i = c_int() 8 | f = c_float() 9 | s = create_string_buffer('\000' * 32) 10 | print i.value, f.value, repr(s.value) 11 | libc.sscanf("1 3.14 Hello", "%d %f %s",byref(i), byref(f), s) 12 | print i.value, f.value, repr(s.value) 13 | -------------------------------------------------------------------------------- /Examples/extensions/ctypes/qsort_test.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from ctypes import * 4 | 5 | libc = CDLL("libc.dylib") 6 | 7 | TenInts = c_int * 10 8 | data = TenInts(*range(10,0,-1)) 9 | 10 | # http://www.gnu.org/software/libc/manual/html_node/Array-Sort-Function.html 11 | # void qsort (void *array, size_t count, size_t size, comparison_fn_t compare) 12 | 13 | # http://docs.python.org/2/library/ctypes.html#ctypes.CFUNCTYPE 14 | CMPFUNC = CFUNCTYPE(c_int, POINTER(c_int), POINTER(c_int)) 15 | 16 | def py_cmp_func(a, b): 17 | # print "py_cmp_func", a[0], b[0] 18 | return a[0] - b[0] 19 | 20 | for i in data: 21 | print i 22 | 23 | libc.qsort(data, len(data), sizeof(c_int), CMPFUNC(py_cmp_func)) 24 | 25 | for i in data: 26 | print i 27 | -------------------------------------------------------------------------------- /Examples/extensions/cython/AGC_example/README.rst: -------------------------------------------------------------------------------- 1 | Automatic Gain Control Example 2 | ============================== 3 | 4 | Automatic Gain Control is a signal processing procedure: 5 | 6 | http://seismicreflections.globeclaritas.com/2013/04/agc-equaliser.html 7 | 8 | This is an example of using fortran, C, and Cython to produce a fast AGC 9 | filter for Python/numpy. 10 | 11 | Thanks for the folks at IRIS (http://www.iris.edu) for this example and 12 | the Fortran code. 13 | 14 | Using these examples: 15 | ===================== 16 | 17 | The c and cython versions should be usable with any pyton set up to 18 | compile extensions. They use setuptools to call the compiler. 19 | 20 | The Fortran / f2c version requires a compatible Fortran compiler. g77 21 | should work fine, but getting a compatible build on anything but Linux 22 | is a trick, and out of scope for this README (sorry). Google for it -- 23 | you should find what you need. 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /Examples/extensions/cython/AGC_example/agc_c.c: -------------------------------------------------------------------------------- 1 | /* C version of AGC code */ 2 | 3 | #include 4 | #include 5 | 6 | void AGC(int nAGC, int npts, float *amp, float *ampAGC); 7 | 8 | void AGC(int nAGC, int npts, float *amp, float *ampAGC) { 9 | 10 | float fmax; 11 | float absamp[npts]; 12 | int i, j, nAGC2; 13 | 14 | 15 | for (i = 0; i < npts; i++){ 16 | ampAGC[i] = 0.0; 17 | absamp[i] = fabs(amp[i]); 18 | } 19 | nAGC2 = nAGC / 2; 20 | 21 | for (i = nAGC2; i < npts-nAGC2; i++){ 22 | fmax = 0.0; 23 | for ( j=(i-nAGC2); j < i+nAGC2+1; j++ ){ 24 | if ( absamp[j] > fmax ) { 25 | fmax = absamp[j]; 26 | } 27 | } 28 | ampAGC[i] = amp[i] / fmax; 29 | } 30 | return; 31 | } 32 | 33 | -------------------------------------------------------------------------------- /Examples/extensions/cython/AGC_example/agc_c_cy.pyx: -------------------------------------------------------------------------------- 1 | """ 2 | Cython file to call the C routine 3 | """ 4 | 5 | import numpy as np 6 | cimport numpy as cnp 7 | 8 | cdef extern: 9 | void AGC(int nAGC, int npts, float *amp, float *ampAGC) 10 | 11 | 12 | def agc (int nAGC, float[:] amp): 13 | 14 | # create the output array 15 | cdef cnp.ndarray[float, ndim=1] ampAGC = np.zeros_like(amp) 16 | 17 | npts = amp.shape[0] 18 | 19 | # call the C function 20 | AGC(nAGC, npts, &[0], &AGC[0]) 21 | 22 | return ampAGC 23 | -------------------------------------------------------------------------------- /Examples/extensions/cython/AGC_example/agc_python.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | Pure python (and not very numpy smart) version of the 5 | Automatic Gain Control function 6 | """ 7 | 8 | import numpy as np 9 | 10 | 11 | def agc(nAGC, amp): 12 | """ 13 | run an automatic gain control filter onver the input array 14 | 15 | :param nAGC: width of window, number of elements. 16 | :type nAGC: integer 17 | 18 | :param amp: input amplitude data 19 | :type amp: 1-d numpy array of float32 20 | 21 | :returns ampAGC: a numpy array of the filtered data. 22 | 23 | """ 24 | 25 | # make sure input array is as expected: 26 | amp = np.asarray(amp, dtype=np.float32) 27 | 28 | if len(amp.shape) != 1: 29 | raise ValueError("amp must be a rank-1 array") 30 | 31 | npts = amp.shape[0] 32 | 33 | nAGC2 = nAGC / 2 34 | ampAGC = np.zeros_like(amp) 35 | absamp = np.zeros_like(amp) 36 | 37 | absamp = np.abs(amp) 38 | 39 | for i in xrange(nAGC2, npts - nAGC2): 40 | fmax = 0.0 41 | for j in range(i - nAGC2, i + nAGC2 + 1): 42 | if absamp[j] > fmax: 43 | fmax = absamp[j] 44 | ampAGC[i] = amp[i] / fmax 45 | 46 | return ampAGC 47 | -------------------------------------------------------------------------------- /Examples/extensions/cython/AGC_example/agc_subroutine.f: -------------------------------------------------------------------------------- 1 | c 2 | c Subrooutine to compute an automatic gain control filter. 3 | c 4 | c 5 | subroutine AGC(nAGC,npts,amp,ampAGC) 6 | 7 | CF2PY INTENT(OUT) :: ampAGC 8 | CF2PY INTENT(HIDE) :: npts 9 | 10 | real fmax,amp(npts),absamp(npts),ampAGC(npts) 11 | integer i,j,npts,nAGC,nAGC2 12 | 13 | do i=1,npts 14 | ampAGC(i)=0. 15 | absamp(i)=abs(amp(i)) 16 | enddo 17 | 18 | nAGC2=nAGC/2 19 | 20 | do i=nAGC2+1,npts-nAGC2 21 | fmax=0. 22 | do j=i-nAGC2,i+nAGC2 23 | if (absamp(j).gt.fmax) fmax=absamp(j) 24 | enddo 25 | ampAGC(i)=amp(i)/fmax 26 | enddo 27 | 28 | return 29 | 30 | end 31 | 32 | -------------------------------------------------------------------------------- /Examples/extensions/cython/AGC_example/agc_subroutine.pyf: -------------------------------------------------------------------------------- 1 | ! -*- f90 -*- 2 | ! Note: the context of this file is case sensitive. 3 | 4 | python module agc_subroutine ! in 5 | interface ! in :agc_subroutine 6 | subroutine agc(nagc,npts,amp,ampagc) ! in :agc_subroutine:agc_subroutine.f 7 | integer :: nagc 8 | integer, optional,intent(hide),check(len(amp)>=npts),depend(amp) :: npts=len(amp) 9 | real dimension(npts) :: amp 10 | real dimension(npts),intent(out),depend(npts) :: ampagc 11 | end subroutine agc 12 | end interface 13 | end python module agc_subroutine 14 | 15 | ! This file was auto-generated with f2py (version:2). 16 | ! See http://cens.ioc.ee/projects/f2py2e/ 17 | -------------------------------------------------------------------------------- /Examples/extensions/cython/AGC_example/plot_agc.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | test code for the "agc_subroutine" extension, generated from fortran by f2py 5 | """ 6 | import numpy as np 7 | import matplotlib.pyplot as plt 8 | 9 | import agc_subroutine 10 | import agc_python 11 | 12 | print "the doctring for agc:" 13 | print agc_subroutine.agc.__doc__ 14 | 15 | # to call it: 16 | # create a noisy array: 17 | 18 | t = np.linspace(0,20,100).astype(np.float32) 19 | 20 | signal = np.sin(t) 21 | 22 | # add some noise 23 | signal += (np.random.random(signal.shape)-0.5) * 0.3 24 | 25 | # create an array for the result: 26 | #filtered = np.zeros_like(signal) 27 | 28 | # run it through the AGC filter: 29 | filtered = agc_subroutine.agc(10, signal) 30 | 31 | # try the python version 32 | filtered2 = agc_python.agc(10, signal) 33 | 34 | if np.allclose(filtered2, filtered2): 35 | print "the same" 36 | else: 37 | print "not the same" 38 | 39 | ## plot the results 40 | 41 | fig = plt.figure(figsize=(10,5)) 42 | ax = fig.add_subplot(1,1,1) 43 | ax.plot(t, signal, t, filtered, t, filtered2) 44 | 45 | plt.show() 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /Examples/extensions/cython/AGC_example/setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from setuptools import setup, Extension 4 | from Cython.Build import cythonize 5 | 6 | import numpy 7 | 8 | cy = Extension("agc_cython", 9 | ["agc_cython.pyx"], 10 | include_dirs=[numpy.get_include()], 11 | ) 12 | c_wrap = Extension("agc_c_cy", 13 | ["agc_c_cy.pyx", "agc_c.c"], 14 | include_dirs=[numpy.get_include()] 15 | ) 16 | 17 | setup(ext_modules=cythonize([cy, c_wrap])) 18 | -------------------------------------------------------------------------------- /Examples/extensions/cython/NotesAboutCythonExample.txt: -------------------------------------------------------------------------------- 1 | # Notes about Cython examples: 2 | 3 | ## Installing Cython: 4 | 5 | $ pip install Cython 6 | 7 | Cython files are named with the "pyx" extension (Pyrex legacy) 8 | 9 | Note: Python syntax highlighting works pretty well in most editors. 10 | 11 | 12 | ## For simple functions: 13 | 14 | def is callable from Python 15 | 16 | cdef is only callable from Cython (or C) 17 | 18 | 19 | ## generating C code: 20 | 21 | $ cython cy_add.pyx 22 | 23 | generating "annotated" C code (HTML): 24 | 25 | $ cython -a cy_add.pyx 26 | 27 | Look at the html -- the yellow highlights are places where calls into the Python runtime are used. 28 | 29 | ## To build extension: 30 | 31 | python cy_setup.py build_ext --inplace 32 | 33 | (or develop or install....) 34 | 35 | running nose or py.test should run all the tests. Or you can run each one on it's own. 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /Examples/extensions/cython/add.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "add.h" 3 | 4 | int add(int x, int y) { 5 | return x+y; 6 | } 7 | -------------------------------------------------------------------------------- /Examples/extensions/cython/add.h: -------------------------------------------------------------------------------- 1 | 2 | int add(int x, int y); 3 | 4 | 5 | -------------------------------------------------------------------------------- /Examples/extensions/cython/cy_add1.pyx: -------------------------------------------------------------------------------- 1 | """ 2 | Cython implementation of the add.c example 3 | 4 | This one pure python 5 | 6 | """ 7 | 8 | def add(x, y): 9 | 10 | result = x + y 11 | 12 | return result 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /Examples/extensions/cython/cy_add2.pyx: -------------------------------------------------------------------------------- 1 | """ 2 | Cython implementation of the add.c example 3 | 4 | This one with type defs 5 | 6 | """ 7 | 8 | def add(int x, int y): 9 | 10 | cdef int result=0 11 | result = x + y 12 | 13 | return result 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /Examples/extensions/cython/cy_add_c.pyx: -------------------------------------------------------------------------------- 1 | # distutils: sources = add.c 2 | 3 | """ 4 | Cython implementation of the add.c example 5 | 6 | This one calls an actual C function to do the work 7 | 8 | creates a cython function to call the C function. 9 | 10 | """ 11 | 12 | 13 | # telling cython what the function we want to call looks like. 14 | cdef extern from "add.h": 15 | # pull in C add function, renaming to c_add for Cython 16 | int c_add "add" (int x, int y) 17 | 18 | 19 | def add(x, y): 20 | return c_add(x, y) 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /Examples/extensions/cython/integrate/cy_integrate1.pyx: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # a cython version with no changes -- pure python! 4 | 5 | import cython 6 | 7 | cdef double f(double x): 8 | """simple objective function to integrate""" 9 | 10 | return x**2.0 - x 11 | 12 | @cython.cdivision(True) 13 | def double integrate_f(double a, double b, int N): 14 | """ 15 | integrates the function: 16 | 17 | f(x) = x**2 - x 18 | 19 | from a to b, using N steps, using the simple rectangle rule approach. 20 | """ 21 | 22 | cdef double s = 0.0 23 | cdef double dx = 0.0 24 | cdef int i = 0 25 | 26 | dx = (b - a) / N 27 | 28 | for i in range(N): 29 | s += f(a + i * dx) 30 | return s * dx 31 | -------------------------------------------------------------------------------- /Examples/extensions/cython/integrate/cy_integrate2.pyx: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # a cython version with some static typing 4 | 5 | 6 | # The objective function is only called from within Cython, 7 | # so we can make it a cdef function: 8 | 9 | cdef f(x): 10 | """simple objective function to integrate""" 11 | return x**2-x 12 | 13 | def integrate_f(a, b, N): 14 | """ 15 | integrates the function: 16 | 17 | f(x) = x**2 - x 18 | 19 | from a to b, using N steps, using the simple recatngle rule approach. 20 | """ 21 | 22 | s = 0 23 | dx = (b-a)/N 24 | for i in range(N): 25 | s += f(a+i*dx) 26 | return s * dx 27 | 28 | 29 | -------------------------------------------------------------------------------- /Examples/extensions/cython/integrate/cy_integrate3.pyx: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # a cython version with some static typing 4 | 5 | 6 | # The objective function is only called from within Cython, 7 | # so we can make it a cdef function: 8 | 9 | # but a non-typed cdef isn't any faster -- so add the type defs: 10 | 11 | cdef double f(double x): 12 | """simple objective function to integrate""" 13 | return x**2 - x 14 | 15 | def integrate_f(a, b, N): 16 | """ 17 | integrates the function: 18 | 19 | f(x) = x**2 - x 20 | 21 | from a to b, using N steps, using the simple recatngle rule approach. 22 | """ 23 | 24 | s = 0 25 | dx = (b-a)/N 26 | for i in range(N): 27 | s += f(a+i*dx) 28 | return s * dx 29 | 30 | 31 | -------------------------------------------------------------------------------- /Examples/extensions/cython/integrate/cy_integrate4.pyx: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # a cython version with some static typing 4 | 5 | 6 | # The objective function is only called from within Cython, 7 | # so we can make it a cdef function: 8 | 9 | # but a non-typed cdef isn't any faster -- so add the type defs: 10 | 11 | cdef double f(double x): 12 | """simple objective function to integrate""" 13 | return x**2 - x 14 | 15 | # But this function isn't typed, so it still needs 16 | # to convert py_objects to/from the f() 17 | # so add some more type definitions: 18 | 19 | def integrate_f(a, b, N): 20 | """ 21 | integrates the function: 22 | 23 | f(x) = x**2 - x 24 | 25 | from a to b, using N steps, using the simple recatngle rule approach. 26 | """ 27 | cdef double s, dx 28 | 29 | s = 0 30 | dx = (b-a)/N 31 | for i in range(N): 32 | s += f(a+i*dx) 33 | return s * dx 34 | 35 | 36 | -------------------------------------------------------------------------------- /Examples/extensions/cython/integrate/cy_integrate5.pyx: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # a cython version with some static typing 4 | 5 | 6 | # The objective function is only called from within Cython, 7 | # so we can make it a cdef function: 8 | 9 | # but a non-typed cdef isn't any faster -- so add the type defs: 10 | 11 | cdef double f(double x): 12 | """simple objective function to integrate""" 13 | return x**2 - x 14 | 15 | # But this function isn't typed, so it still needs 16 | # to convert py_objects to/from the f() 17 | # so add some more type definitions: 18 | 19 | # typeeverythign passed in to the funciton, 20 | # should be pure C speed from there: 21 | 22 | def integrate_f(double a, double b, int N): 23 | """ 24 | integrates the function: 25 | 26 | f(x) = x**2 - x 27 | 28 | from a to b, using N steps, using the simple recatngle rule approach. 29 | """ 30 | cdef double s, dx 31 | 32 | s = 0 33 | dx = (b-a) / N 34 | for i in range(N): 35 | s += f(a+i*dx) 36 | return s * dx 37 | 38 | 39 | -------------------------------------------------------------------------------- /Examples/extensions/cython/integrate/cy_integrate6.pyx: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # a cython version with some static typing 4 | 5 | 6 | # The objective function is only called from within Cython, 7 | # so we can make it a cdef function: 8 | 9 | # but a non-typed cdef isn't any faster -- so add the type defs: 10 | 11 | cdef double f(double x): 12 | """simple objective function to integrate""" 13 | return x**2 - x 14 | 15 | # But this function isn't typed, so it still needs 16 | # to convert py_objects to/from the f() 17 | # so add some more type definitions: 18 | 19 | # type everythign passed in to the funciton, 20 | # should be pure C speed from there: 21 | 22 | # not much help -- what did we miss? 23 | # check out the annotated version: 24 | # cython -a cy_integrate5.pyx 25 | # still a lot of yellow in that loop! 26 | # 27 | # oops! didn't type def the counter, i! 28 | 29 | def integrate_f(double a, double b, int N): 30 | """ 31 | integrates the function: 32 | 33 | f(x) = x**2 - x 34 | 35 | from a to b, using N steps, using the simple recatngle rule approach. 36 | """ 37 | cdef double s, dx 38 | cdef int i 39 | 40 | s = 0 41 | dx = (b-a) / N 42 | for i in range(N): 43 | s += f(a + i*dx) 44 | return s * dx 45 | 46 | 47 | -------------------------------------------------------------------------------- /Examples/extensions/cython/integrate/integrate.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | cdef f(double x): 4 | """simple objective function to integrate""" 5 | 6 | return x**2.0 - x 7 | 8 | def integrate_f(a, b, N): 9 | """ 10 | integrates the function: 11 | 12 | f(x) = x**2 - x 13 | 14 | from a to b, using N steps, using the simple recatngle rule approach. 15 | """ 16 | 17 | s = 0 18 | dx = (b-a)/N 19 | for i in range(N): 20 | s += f(a+i*dx) 21 | return s * dx 22 | -------------------------------------------------------------------------------- /Examples/extensions/cython/integrate/setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from setuptools import setup 4 | from Cython.Build import cythonize 5 | 6 | setup(name="cython_example", 7 | ext_modules=cythonize(['cy_integrate1.pyx', 8 | # 'cy_integrate2.pyx', 9 | # 'cy_integrate3.pyx', 10 | # 'cy_integrate4.pyx', 11 | # 'cy_integrate5.pyx', 12 | # 'cy_integrate6.pyx', 13 | # 'cy_integrate7.pyx', 14 | ]) 15 | ) 16 | -------------------------------------------------------------------------------- /Examples/extensions/cython/integrate/test_integrate.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | Simple test script to get gross timings 5 | 6 | Not unit tests 7 | """ 8 | 9 | from timer_context import Timer 10 | 11 | 12 | def run_test(msg): 13 | print msg 14 | with Timer(): 15 | result = integrate_f(0.0, 10.0, 1000000) 16 | print "result:", result 17 | print 18 | 19 | from integrate import integrate_f 20 | run_test("Pure Python version:") 21 | 22 | from cy_integrate1 import integrate_f 23 | run_test("First Cython version:") 24 | 25 | from cy_integrate2 import integrate_f 26 | run_test("Second Cython version:") 27 | 28 | from cy_integrate3 import integrate_f 29 | run_test("Third Cython version:") 30 | 31 | from cy_integrate4 import integrate_f 32 | run_test("Fourth Cython version:") 33 | 34 | from cy_integrate5 import integrate_f 35 | run_test("Fifth Cython version:") 36 | 37 | from cy_integrate6 import integrate_f 38 | run_test("Sixth Cython version:") 39 | 40 | from cy_integrate7 import integrate_f 41 | run_test("Seventh Cython version:") 42 | 43 | -------------------------------------------------------------------------------- /Examples/extensions/cython/integrate/timer_context.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | timer_context 5 | 6 | A context manager that does simple code timing 7 | 8 | Adapted from: 9 | 10 | http://preshing.com/20110924/timing-your-code-using-pythons-with-statement/ 11 | 12 | NOTE: this is only good for crude timing -- use the timeit module to do it better. 13 | """ 14 | 15 | import time 16 | 17 | class Timer(object): 18 | def __enter__(self): 19 | self.start = time.clock() 20 | return self 21 | 22 | def __exit__(self, *args): 23 | self.end = time.clock() 24 | self.interval = self.end - self.start 25 | print "this code took %f seconds"%self.interval 26 | -------------------------------------------------------------------------------- /Examples/extensions/cython/setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from setuptools import setup 4 | from Cython.Build import cythonize 5 | 6 | setup(name="cython_example", 7 | ext_modules=cythonize(['cy_add_c.pyx', 8 | 'cy_add1.pyx', 9 | 'cy_add2.pyx', 10 | ]) 11 | 12 | ) 13 | -------------------------------------------------------------------------------- /Examples/extensions/cython/test_cy_add1.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | simple test code for cy_add1 5 | 6 | can be run by itself, or with nose or pytest 7 | """ 8 | 9 | import cy_add1 10 | 11 | 12 | def test_1(): 13 | assert cy_add1.add(3, 4) == 7 14 | 15 | def test_2(): 16 | assert cy_add1.add(5, 6) == 11 17 | 18 | def test_error(): 19 | """ 20 | you should get an TypeError if you try to add something other than numbers 21 | """ 22 | try: 23 | print cy_add1.add('this', 5) 24 | assert False # shouldn't get here! 25 | except TypeError: 26 | # should have gotten an exception 27 | pass 28 | 29 | if __name__ == "__main__": 30 | test_1() 31 | test_2() 32 | test_error() 33 | 34 | print "if you didn't get an assertion, it worked" 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /Examples/extensions/cython/test_cy_add2.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | simple test code for cy_add1 5 | 6 | can be run by itself, or with nose or pytest 7 | """ 8 | 9 | import cy_add2 10 | 11 | 12 | def test_1(): 13 | assert cy_add2.add(3, 4) == 7 14 | 15 | def test_2(): 16 | assert cy_add2.add(5, 6) == 11 17 | 18 | def test_error(): 19 | """ 20 | you should get an TypeError if you try to add something other than numbers 21 | """ 22 | try: 23 | print cy_add2.add('this', 5) 24 | assert False # shouldn't get here! 25 | except TypeError: 26 | # should have gotten an exception 27 | pass 28 | 29 | if __name__ == "__main__": 30 | test_1() 31 | test_2() 32 | test_error() 33 | 34 | print "if you didn't get an assertion, it worked" 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /Examples/extensions/cython/test_cy_add_c.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | simple test code for cy_add1 5 | 6 | can be run by itself, or with nose or pytest 7 | """ 8 | 9 | import cy_add_c 10 | 11 | 12 | def test_1(): 13 | assert cy_add_c.add(3, 4) == 7 14 | 15 | def test_2(): 16 | assert cy_add_c.add(5, 6) == 11 17 | 18 | def test_error(): 19 | """ 20 | you should get an TypeError if you try to add something other than numbers 21 | """ 22 | try: 23 | print cy_add_c.add('this', 5) 24 | assert False # shouldn't get here! 25 | except TypeError: 26 | # should have gotten an exception 27 | pass 28 | 29 | if __name__ == "__main__": 30 | test_1() 31 | test_2() 32 | test_error() 33 | 34 | print "if you didn't get an assertion, it worked" 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /Examples/extensions/distutils/add.py: -------------------------------------------------------------------------------- 1 | def add(x, y): 2 | return x+y 3 | -------------------------------------------------------------------------------- /Examples/extensions/distutils/setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup 2 | 3 | setup( 4 | name='add', 5 | version='1.0', 6 | description='Add description', 7 | ext_modules=[], 8 | py_modules=['add'] 9 | ) 10 | -------------------------------------------------------------------------------- /Examples/extensions/pure-c/Makefile: -------------------------------------------------------------------------------- 1 | all: add; gcc -o add add.c 2 | -------------------------------------------------------------------------------- /Examples/extensions/pure-c/add.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int add(int x, int y) { 4 | return x+y; 5 | } 6 | int main(void) { 7 | int w = 3; 8 | int q = 2; 9 | printf("%d + %d = %d\n\n", w, q, add(w,q)); 10 | } 11 | -------------------------------------------------------------------------------- /Examples/extensions/swig/README.rst: -------------------------------------------------------------------------------- 1 | Simple SWIG Example 2 | =================== 3 | 4 | This dir has a very, very simple example of using SWIG to generate a 5 | wrapper around a simple C function. 6 | 7 | The logic, such as it is, is in the add.i interface file. 8 | 9 | To build, siply call: 10 | 11 | python ./setup.py build_ext --in_place 12 | 13 | distutils understands SWIG, so it will run SWIG for you. 14 | 15 | You, of course, need to have SWIG isntalled on your system. 16 | 17 | -------------------------------------------------------------------------------- /Examples/extensions/swig/add.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int add(int x, int y) { 4 | return x+y; 5 | } 6 | int main(void) { 7 | int w = 3; 8 | int q = 2; 9 | printf("%d + %d = %d\n\n", w, q, add(w,q)); 10 | } 11 | -------------------------------------------------------------------------------- /Examples/extensions/swig/add.i: -------------------------------------------------------------------------------- 1 | %module add 2 | %{ 3 | %} 4 | 5 | extern int add(int x, int y); 6 | -------------------------------------------------------------------------------- /Examples/extensions/swig/ruby/add.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int add(int x, int y) { 4 | return x+y; 5 | } 6 | int main(void) { 7 | int w = 3; 8 | int q = 2; 9 | printf("%d + %d = %d\n\n", w, q, add(w,q)); 10 | } 11 | -------------------------------------------------------------------------------- /Examples/extensions/swig/ruby/add.i: -------------------------------------------------------------------------------- 1 | %module add 2 | %{ 3 | extern int add(int x, int y); 4 | %} 5 | 6 | extern int add(int x, int y); 7 | -------------------------------------------------------------------------------- /Examples/extensions/swig/ruby/extconf.rb: -------------------------------------------------------------------------------- 1 | require 'mkmf' 2 | create_makefile('add') 3 | 4 | -------------------------------------------------------------------------------- /Examples/extensions/swig/setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from setuptools import setup, Extension 4 | 5 | setup( 6 | name='add', 7 | py_modules=['add'], 8 | ext_modules=[ 9 | Extension('_add', sources=['add.c', 'add.i']) 10 | ] 11 | ) 12 | -------------------------------------------------------------------------------- /Examples/extensions/swig/test_add.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | simple test file for SWIG-ified add function 5 | """ 6 | 7 | import pytest 8 | 9 | from add import add 10 | 11 | 12 | def test_add1(): 13 | assert add(3, 4) == 7 14 | 15 | 16 | def test_add_float(): 17 | # only integers! 18 | with pytest.raises(TypeError): 19 | assert add(3.1, 4.1) == 7.2 20 | 21 | 22 | def test_add_string(): 23 | # only integers! 24 | with pytest.raises(TypeError): 25 | assert add('2', 4) == 6 26 | -------------------------------------------------------------------------------- /Examples/matplotlib/lena.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/Examples/matplotlib/lena.png -------------------------------------------------------------------------------- /Examples/metaclasses/cool_meta.py: -------------------------------------------------------------------------------- 1 | class CoolMeta(type): 2 | def __new__(meta, name, bases, dct): 3 | print('Creating class', name) 4 | return super(CoolMeta, meta).__new__(meta, name, bases, dct) 5 | def __init__(cls, name, bases, dct): 6 | print('Initializing class', name) 7 | super(CoolMeta, cls).__init__(name, bases, dct) 8 | def __call__(cls, *args, **kw): 9 | print('calling CoolMeta to instantiate ', cls) 10 | return type.__call__(cls, *args, **kw) 11 | 12 | class CoolClass(metaclass=CoolMeta): 13 | def __init__(self): 14 | print('And now my CoolClass object exists') 15 | 16 | print('everything loaded, instantiate a coolclass object now') 17 | foo = CoolClass() 18 | -------------------------------------------------------------------------------- /Examples/metaclasses/mangler.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | 4 | class NameMangler(type): 5 | 6 | def __new__(cls, clsname, bases, _dict): 7 | uppercase_attr = {} 8 | for name, val in _dict.items(): 9 | if not name.startswith('__'): 10 | uppercase_attr[name.upper()] = val 11 | uppercase_attr[name] = val 12 | else: 13 | uppercase_attr[name] = val 14 | 15 | return super().__new__(cls, clsname, bases, uppercase_attr) 16 | 17 | 18 | class Foo(metaclass=NameMangler): 19 | x = 1 20 | 21 | 22 | if __name__ == "__main__": 23 | f = Foo() 24 | print(f.x) 25 | print(f.X) 26 | -------------------------------------------------------------------------------- /Examples/metaclasses/singleton.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | """ 4 | example of using __metaclass__ to impliment the singleton pattern 5 | """ 6 | 7 | 8 | class Singleton(type): 9 | instance = None 10 | 11 | def __call__(cls, *args, **kwargs): 12 | if cls.instance is None: 13 | cls.instance = super().__call__(*args, **kwargs) 14 | return cls.instance 15 | 16 | 17 | class MyClass(metaclass=Singleton): 18 | pass 19 | 20 | object1 = MyClass() 21 | object2 = MyClass() 22 | 23 | print(id(object1)) 24 | print(id(object2)) 25 | -------------------------------------------------------------------------------- /Examples/nosql/mongo_test.py: -------------------------------------------------------------------------------- 1 | #!usr/bin/env python 2 | 3 | """ 4 | simple test file for mongoDB 5 | remember to start database: 6 | $ mongod --dbpath=mongo_data/ 7 | 8 | """ 9 | 10 | from pymongo import MongoClient 11 | 12 | client = MongoClient('localhost', 27017) 13 | 14 | db = client.test_database 15 | 16 | collection = db.test_collection 17 | 18 | chris = {'last_name':'Barker', 19 | 'first_name':'Chris', 20 | 'middle_name':'H', 21 | 'cell_phone':'(123) 555-7890', 22 | 'email':'PythonCHB@gmail.com', 23 | } 24 | 25 | collection.insert(chris) 26 | 27 | print("all the collections") 28 | print(db.collection_names()) 29 | 30 | print(collection.find_one()) 31 | -------------------------------------------------------------------------------- /Examples/numpy/start.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | script to start up demo for numpy talk 5 | 6 | just the one unility at this point.. 7 | """ 8 | 9 | 10 | def print_info(a, name="arr"): 11 | print(name, ":") 12 | print(a) 13 | print("%s.shape:" % name, a.shape) 14 | print("%s.dtype:" % name, a.dtype) 15 | print("%s.itemsize" % name, a.itemsize) 16 | print("%s.ndim:" % name, a.ndim) 17 | print("%s.strides" % name, a.strides) 18 | print("%s.flags:\n" % name, a.flags) 19 | -------------------------------------------------------------------------------- /Examples/packaging/Capitalize/CHANGES.txt: -------------------------------------------------------------------------------- 1 | v 0.0.1, 2014:03:23 -- Initial release. 2 | 3 | -------------------------------------------------------------------------------- /Examples/packaging/Capitalize/LICENSE.txt: -------------------------------------------------------------------------------- 1 | The license for the capitalize package 2 | 3 | Public Domain: do with it what you will. 4 | 5 | -------------------------------------------------------------------------------- /Examples/packaging/Capitalize/MANIFEST.txt: -------------------------------------------------------------------------------- 1 | include *.txt -------------------------------------------------------------------------------- /Examples/packaging/Capitalize/README.txt: -------------------------------------------------------------------------------- 1 | =================== 2 | Capitalize Package 3 | =================== 4 | 5 | A basic pacakge for Capitalizing text in files 6 | 7 | Purpose 8 | ======== 9 | 10 | Nothing useful, just something to demonstrate packaging with. 11 | 12 | -------------------------------------------------------------------------------- /Examples/packaging/Capitalize/bin/cap_script: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | A really simple script just to demonstrate disutils 5 | """ 6 | 7 | import sys 8 | import os 9 | from capitalize import capital_mod 10 | 11 | 12 | if __name__ == "__main__": 13 | try: 14 | infilename = sys.argv[1] 15 | except IndexError: 16 | print("you need to pass in a file to process") 17 | 18 | root, ext = os.path.splitext(infilename) 19 | outfilename = root + "_cap" + ext 20 | 21 | # do the real work: 22 | print("Capitalizing: %s and storing it in %s" % (infilename, outfilename)) 23 | capital_mod.capitalize(infilename, outfilename) 24 | 25 | print("I'm done") 26 | -------------------------------------------------------------------------------- /Examples/packaging/Capitalize/capitalize/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | Capitalize package 3 | 4 | A package to hold the code that capitalizes text for you. 5 | 6 | This only exists to demonstrate package structure and 7 | documentation, so not that much here. 8 | 9 | """ 10 | __version__ = '0.0.1' 11 | 12 | -------------------------------------------------------------------------------- /Examples/packaging/Capitalize/capitalize/test/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | Test package for capitalize module 3 | """ 4 | pass 5 | 6 | import os 7 | 8 | def runall(): 9 | import pytest 10 | pytest.main(os.path.split(__file__)[0]) 11 | 12 | 13 | -------------------------------------------------------------------------------- /Examples/packaging/Capitalize/capitalize/test/sample_text_file.txt: -------------------------------------------------------------------------------- 1 | This is a really simple Text file. 2 | It is here so that I can test the capitalize script. 3 | 4 | And that's only there to try out distutils. 5 | 6 | So there. 7 | -------------------------------------------------------------------------------- /Examples/packaging/Capitalize/capitalize/test/test_capital_mod.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | test code for capitalize module 5 | 6 | can be run with py.test or nosetests 7 | """ 8 | 9 | import capitalize 10 | from capitalize import capital_mod 11 | 12 | print capitalize.__file__ 13 | 14 | def test_init(): 15 | """ makes sure it imports and can be read""" 16 | import capitalize 17 | assert hasattr(capitalize, '__version__') 18 | 19 | def test_capitalize_line(): 20 | line = "this is a Line to capitalize" 21 | expected = "This Is A Line To Capitalize" 22 | 23 | assert capital_mod.capitalize_line(line) == expected 24 | 25 | def test_capitalize(): 26 | """ test an actual string """ 27 | capital_mod.capitalize("sample_text_file.txt", "sample_text_file_cap.txt") 28 | contents = open("sample_text_file_cap.txt", 'U').read() 29 | expected = """This Is A Really Simple Text File. 30 | It Is Here So That I Can Test The Capitalize Script. 31 | 32 | And That's Only There To Try Out Distutils. 33 | 34 | So There.""" 35 | assert contents.strip() == expected 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /Examples/packaging/Capitalize/setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | This is about as simple a setup.py as you can have 5 | 6 | It installs the capitalize module and script 7 | 8 | """ 9 | 10 | from setuptools import setup 11 | 12 | import capitalize # to get __version__ 13 | 14 | setup( 15 | name='Capitalize', 16 | version=capitalize.__version__, 17 | author='Chris Barker', 18 | author_email='PythonCHB@gmail.com', 19 | packages=['capitalize', 20 | 'capitalize/test'], 21 | scripts=['bin/cap_script',], 22 | license='LICENSE.txt', 23 | description='Not very useful capitalizing module and script', 24 | long_description=open('README.txt').read(), 25 | ) 26 | 27 | -------------------------------------------------------------------------------- /Examples/pandas/IntroductionToPandas_files/88x31.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/Examples/pandas/IntroductionToPandas_files/88x31.png -------------------------------------------------------------------------------- /Examples/pandas/IntroductionToPandas_files/count-data.js: -------------------------------------------------------------------------------- 1 | var DISQUSWIDGETS; 2 | 3 | if (typeof DISQUSWIDGETS != 'undefined') { 4 | DISQUSWIDGETS.displayCount({"text":{"and":"and","comments":{"zero":"0 Comments","multiple":"{num} Comments","one":"1 Comment"}},"counts":[{"id":"cache\/posts\/an-introduction-to-pandas.html","comments":4}]}); 5 | } -------------------------------------------------------------------------------- /Examples/pandas/IntroductionToPandas_files/event.js: -------------------------------------------------------------------------------- 1 | (function () {return {resp: "OK"};})(); 2 | -------------------------------------------------------------------------------- /Examples/pandas/IntroductionToPandas_files/mike_head.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/Examples/pandas/IntroductionToPandas_files/mike_head.png -------------------------------------------------------------------------------- /Examples/pandas/IntroductionToPandas_files/noavatar92.b677f9ddbee6f4bb22f473ae3bd61b85.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/Examples/pandas/IntroductionToPandas_files/noavatar92.b677f9ddbee6f4bb22f473ae3bd61b85.png -------------------------------------------------------------------------------- /Examples/pandas/IntroductionToPandas_files/noavatar92.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/Examples/pandas/IntroductionToPandas_files/noavatar92.png -------------------------------------------------------------------------------- /Examples/pandas/README.rst: -------------------------------------------------------------------------------- 1 | Pandas Examples 2 | =============== 3 | 4 | Enclosed in this dir is a cached version of the Pandas tutorial here: 5 | 6 | http://synesthesiam.com/posts/an-introduction-to-pandas.html 7 | 8 | If your net connection is good, I'd suggest working directly with the 9 | online version -- Michael Hansen has done a nice job. 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /Examples/pep8/encoding.py: -------------------------------------------------------------------------------- 1 | 2 | x = "🐳" 3 | 4 | print "whale: " + x 5 | 6 | # coding: utf-8 7 | -------------------------------------------------------------------------------- /Examples/pep8/pep8_fail.py: -------------------------------------------------------------------------------- 1 | import boto 2 | import contextlib 3 | import ftplib 4 | 5 | x = "fklsdj fdjslkfdjs klfjs dklfj dsflkdsfjl ksdfjsdklfsd fjdsklfjdsk l" 6 | 7 | 8 | def my_function(): 9 | return "value" 10 | 11 | 12 | 13 | print my_function() 14 | 15 | -------------------------------------------------------------------------------- /Examples/persistence/Solutions/indent_etree.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """ 3 | indenting function to pretty-print an ElementTree 4 | 5 | from: 6 | 7 | http://infix.se/2007/02/06/gentlemen-indent-your-xml 8 | 9 | why the %*#^ this isn't built-in to etree is beyond me. 10 | 11 | usage: 12 | 13 | indent(tree.getroot()) 14 | 15 | tree.write(outfilename) 16 | 17 | """ 18 | 19 | def indent(elem, level=0): 20 | i = "\n" + level*" " 21 | if len(elem): 22 | if not elem.text or not elem.text.strip(): 23 | elem.text = i + " " 24 | for e in elem: 25 | indent(e, level+1) 26 | if not e.tail or not e.tail.strip(): 27 | e.tail = i + " " 28 | if not e.tail or not e.tail.strip(): 29 | e.tail = i 30 | else: 31 | if level and (not elem.tail or not elem.tail.strip()): 32 | elem.tail = i 33 | 34 | -------------------------------------------------------------------------------- /Examples/persistence/Solutions/ini_file_example.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | Example of how to save data as an "ini" file with ConfigParser 5 | """ 6 | 7 | import configparser 8 | 9 | # get the data from the py file 10 | # ini format really only holds flat data well. 11 | from add_book_data_flat import AddressBook 12 | 13 | outfilename = "addresses.ini" 14 | 15 | # save it in an ini file 16 | data = configparser.ConfigParser() 17 | 18 | for i, person in enumerate(AddressBook): 19 | sec_name = 'person%i' % i 20 | data.add_section(sec_name) 21 | for key, value in person.items(): 22 | data.set(sec_name, key, value) 23 | 24 | data.write(open("add_book.ini", 'w')) 25 | 26 | # see if we can re-load it 27 | data = data = configparser.ConfigParser() 28 | data.read("add_book.ini") 29 | 30 | # extract the data and put into a list of dicts: 31 | AddressBook2 = [] 32 | for sec_name in data.sections(): 33 | AddressBook2.append(dict(data.items(sec_name))) 34 | print(AddressBook2) 35 | 36 | if AddressBook2 == AddressBook: 37 | print("they are the same") 38 | -------------------------------------------------------------------------------- /Examples/persistence/Solutions/json_example.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | Example of how to save (and reload) data as json 5 | """ 6 | 7 | import json 8 | 9 | # get the data from the py file 10 | from add_book_data import AddressBook 11 | 12 | outfilename = "add_book_data.json" 13 | 14 | # dump it as json (it's really this simple) 15 | json.dump(AddressBook, open(outfilename, 'w')) 16 | 17 | # specifying indent pretty-prints the json 18 | # json.dump(AddressBook, open(outfilename, 'w'), indent=4) 19 | 20 | # see if we can re-load it 21 | AddressBook2 = json.load(open(outfilename, 'r')) 22 | 23 | if AddressBook2 == AddressBook: 24 | print("json version is the same as the original") 25 | -------------------------------------------------------------------------------- /Examples/persistence/Solutions/pickle_example.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | Example of how to save data in a pickle 5 | """ 6 | 7 | import pickle 8 | 9 | # get the data from the py file 10 | from add_book_data import AddressBook 11 | 12 | outfilename = "add_book_data.pickle" 13 | 14 | # pickle it (it's really this simple) 15 | pickle.dump(AddressBook, open(outfilename, 'wb')) 16 | 17 | # see if we can re-load it 18 | AddressBook2 = pickle.load(open(outfilename, 'rb')) 19 | 20 | if AddressBook2 == AddressBook: 21 | print("unpickled version is the same as the original") 22 | -------------------------------------------------------------------------------- /Examples/persistence/Solutions/python_literal.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | Example of how to save data as python literals in a py file 5 | 6 | """ 7 | 8 | import pprint 9 | from ast import literal_eval 10 | 11 | # get the data from the py file 12 | from add_book_data import AddressBook 13 | 14 | outfilename = "add_book_data.pyliteral" 15 | 16 | 17 | # save the data as python literals: 18 | with open(outfilename, 'w') as outfile: 19 | outfile.write(repr(AddressBook)) 20 | 21 | # see if we can re-load it 22 | data = open(outfilename, 'r').read() 23 | 24 | # Warning, warning! danger Will Robinson! 25 | # eval() is very dangerous! 26 | AddressBook2 = eval(data) 27 | 28 | if AddressBook2 == AddressBook: 29 | print("they are the same") 30 | 31 | # try again with the pretty print version: 32 | 33 | outfilename = "add_book_data.pyliteral_pretty" 34 | 35 | with open(outfilename, 'w') as outfile: 36 | outfile.write(pprint.pformat(AddressBook)) 37 | 38 | # see if we can re-load it 39 | data = open(outfilename, 'r').read() 40 | 41 | # let's use literal_eval() this time: 42 | AddressBook2 = literal_eval(data) 43 | 44 | if AddressBook2 == AddressBook: 45 | print("pretty printed version is the same as well") 46 | -------------------------------------------------------------------------------- /Examples/persistence/Solutions/shelve_example.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | Example of how to save data in a shelf 5 | 6 | """ 7 | 8 | import shelve 9 | 10 | 11 | # get the data from the py file 12 | from add_book_data import AddressBook 13 | 14 | outfilename = "add_book_data.shelve" 15 | 16 | # since we can put a whole dict on a shelf: 17 | shelf = shelve.open(outfilename, 'n') 18 | 19 | for person in AddressBook: 20 | # create a key: 21 | key = "%(first_name)s%(last_name)s" % person 22 | shelf[key] = person 23 | 24 | shelf.close() 25 | 26 | # see if we can re-load it 27 | shelf2 = shelve.open(outfilename) 28 | 29 | AddressBook2 = [person for person in shelf2.values()] 30 | # note -- there could be an issue with order here. 31 | # so: 32 | # These are lists of dicts -- and dicts are not orderable 33 | # so we stringify them to get something orderable 34 | AddressBook.sort(key=str) 35 | AddressBook2.sort(key=str) 36 | 37 | if AddressBook2 == AddressBook: 38 | print("shelved/unshelved version is the same as the original") 39 | -------------------------------------------------------------------------------- /Examples/persistence/Solutions/xml_example.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | Example of how to save data as xml, using the element tree module 5 | 6 | This version stores all the data as attributes 7 | """ 8 | 9 | import xml.etree.ElementTree as et 10 | from indent_etree import indent # for prettier output 11 | 12 | # get the data from the py file 13 | from add_book_data_flat import AddressBook 14 | 15 | outfilename = "add_book_data.xml" 16 | 17 | # build a tree structure 18 | root = et.Element("address_book") 19 | 20 | # add the elements: 21 | for person in AddressBook: 22 | p = et.SubElement(root, "person") 23 | # This method stores everything in attributes 24 | for key, value in person.items(): 25 | p.set(key, value) 26 | 27 | # wrap it in an ElementTree instance, and save as XML 28 | tree = et.ElementTree(root) 29 | 30 | indent(tree.getroot()) # to make it more pretty 31 | tree.write(outfilename) 32 | 33 | # See if we can re-load it 34 | tree = et.parse(outfilename) 35 | book = tree.getroot() 36 | # re-build the original list: 37 | AddressBook2 = [] 38 | for person in book.getchildren(): 39 | # print (person.attrib) 40 | AddressBook2.append(person.attrib) 41 | 42 | if AddressBook2 == AddressBook: 43 | print("xml version is the same as the original") 44 | 45 | -------------------------------------------------------------------------------- /Examples/persistence/eggs.csv: -------------------------------------------------------------------------------- 1 | Spam, Spam, Spam, Spam, Spam, Baked Beans 2 | Spam, "Lovely, Spam", Wonderful, Spam, and, more 3 | 4 | -------------------------------------------------------------------------------- /Examples/profiling/bna_reader/setup.py: -------------------------------------------------------------------------------- 1 | # setup.py for filecanner -- only builds extension 2 | 3 | from distutils.core import setup 4 | from Cython.Build import cythonize 5 | import numpy as np 6 | 7 | setup( 8 | ext_modules=cythonize("filescanner.pyx"), 9 | include_dirs=[np.get_include()], 10 | ) 11 | -------------------------------------------------------------------------------- /Examples/profiling/data_aggregation/agg.py: -------------------------------------------------------------------------------- 1 | import time 2 | import timer 3 | 4 | x = 0 5 | 6 | # @profile 7 | @timer.timer 8 | def slow(): 9 | x = 0 10 | def doit1(i): 11 | global x 12 | x = x + i 13 | 14 | list = range(100000) 15 | for i in list: 16 | doit1(i) 17 | 18 | # @profile 19 | @timer.timer 20 | def fast(): 21 | x = 0 22 | def doit2(list): 23 | global x 24 | for i in list: 25 | x = x + i 26 | list = range(100000) 27 | doit2(list) 28 | 29 | if __name__ == "__main__": 30 | s1 = slow() 31 | s2 = fast() 32 | assert(s1 == s2) 33 | -------------------------------------------------------------------------------- /Examples/profiling/data_aggregation/containers.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from timer import timer 4 | 5 | list_data = [l.strip() for l in open('/usr/share/dict/words')] * 10 6 | 7 | set_data = set(list_data) 8 | 9 | 10 | @timer 11 | def set_contains(x): 12 | return x in set_data 13 | 14 | @timer 15 | def list_contains(x): 16 | return x in list_data 17 | 18 | 19 | if __name__ == "__main__": 20 | set_contains("zebra") 21 | list_contains("zebra") 22 | -------------------------------------------------------------------------------- /Examples/profiling/data_aggregation/loops.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from timer import timer 4 | 5 | data = [l.strip() for l in open('/usr/share/dict/words')] * 10 6 | 7 | # data contains a list of words. uppercase all elements two ways: 8 | 9 | @timer 10 | def slow(): 11 | upper = [] 12 | for word in data: 13 | upper.append(word.upper()) 14 | return upper 15 | 16 | @timer 17 | def fast_list_comprehension(): 18 | return [x.upper() for x in data] 19 | 20 | @timer 21 | def fast_map(): 22 | return map(str.upper, data) 23 | 24 | @timer 25 | def fast_generator(): 26 | # super fast. but is it doing the same work? 27 | return (x.upper() for x in data) 28 | 29 | if __name__ == "__main__": 30 | slow() 31 | fast_map() 32 | fast_list_comprehension() 33 | fast_generator() 34 | -------------------------------------------------------------------------------- /Examples/profiling/data_aggregation/pycallgraph.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/Examples/profiling/data_aggregation/pycallgraph.png -------------------------------------------------------------------------------- /Examples/profiling/data_aggregation/timer.py: -------------------------------------------------------------------------------- 1 | import time 2 | 3 | 4 | def timer(func): 5 | def timer(*args, **kwargs): 6 | t1 = time.time() 7 | result = func(*args, **kwargs) 8 | t2 = time.time() 9 | print("-- executed %s in %.4f seconds" % (func.__name__, (t2 - t1))) 10 | return result 11 | return timer 12 | -------------------------------------------------------------------------------- /Examples/profiling/django/benchmark/benchmark/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/Examples/profiling/django/benchmark/benchmark/__init__.py -------------------------------------------------------------------------------- /Examples/profiling/django/benchmark/benchmark/templates/index.html: -------------------------------------------------------------------------------- 1 | {% load humanize %} 2 | 3 |

4 | {{ data}} 5 |

6 | 7 |

8 | Benchmark index 9 |

10 | -------------------------------------------------------------------------------- /Examples/profiling/django/benchmark/benchmark/urls.py: -------------------------------------------------------------------------------- 1 | from django.conf.urls import patterns, include, url 2 | 3 | 4 | # Uncomment the next two lines to enable the admin: 5 | # from django.contrib import admin 6 | # admin.autodiscover() 7 | 8 | urlpatterns = patterns('', 9 | # Examples: 10 | url(r'^$', 'benchmarkapp.views.index', name='index'), 11 | # url(r'^benchmark/', include('benchmark.foo.urls')), 12 | 13 | # Uncomment the admin/doc line below to enable admin documentation: 14 | # url(r'^admin/doc/', include('django.contrib.admindocs.urls')), 15 | 16 | # Uncomment the next line to enable the admin: 17 | # url(r'^admin/', include(admin.site.urls)), 18 | ) 19 | -------------------------------------------------------------------------------- /Examples/profiling/django/benchmark/benchmarkapp/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/Examples/profiling/django/benchmark/benchmarkapp/__init__.py -------------------------------------------------------------------------------- /Examples/profiling/django/benchmark/benchmarkapp/index.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/Examples/profiling/django/benchmark/benchmarkapp/index.html -------------------------------------------------------------------------------- /Examples/profiling/django/benchmark/benchmarkapp/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | 3 | # Create your models here. 4 | -------------------------------------------------------------------------------- /Examples/profiling/django/benchmark/benchmarkapp/tests.py: -------------------------------------------------------------------------------- 1 | """ 2 | This file demonstrates writing tests using the unittest module. These will pass 3 | when you run "manage.py test". 4 | 5 | Replace this with more appropriate tests for your application. 6 | """ 7 | 8 | from django.test import TestCase 9 | 10 | 11 | class SimpleTest(TestCase): 12 | def test_basic_addition(self): 13 | """ 14 | Tests that 1 + 1 always equals 2. 15 | """ 16 | self.assertEqual(1 + 1, 2) 17 | -------------------------------------------------------------------------------- /Examples/profiling/django/benchmark/benchmarkapp/views.py: -------------------------------------------------------------------------------- 1 | from django.shortcuts import render_to_response 2 | from django.template import RequestContext 3 | import md5 4 | 5 | def index(request): 6 | d = {'data': md5.md5("99999999").hexdigest()} 7 | return render_to_response("index.html", d, context_instance=RequestContext(request)) 8 | -------------------------------------------------------------------------------- /Examples/profiling/django/benchmark/manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import os 3 | import sys 4 | 5 | if __name__ == "__main__": 6 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "benchmark.settings") 7 | 8 | from django.core.management import execute_from_command_line 9 | 10 | execute_from_command_line(sys.argv) 11 | -------------------------------------------------------------------------------- /Examples/profiling/integrate/integrate.py: -------------------------------------------------------------------------------- 1 | def f(x): 2 | return x**2 3 | 4 | def integrate(f, a, b, N): 5 | s = 0 6 | dx = (b-a)/N 7 | for i in xrange(N): 8 | s += f(a+i*dx) 9 | return s * dx 10 | 11 | def integrate_f_with_functional_tools(a, b, N): 12 | dx = (float(b)-a)/N 13 | return sum(map(f, ((a+y*dx) for y in xrange(N))))*dx 14 | -------------------------------------------------------------------------------- /Examples/profiling/integrate/integrate_main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # from integrate import integrate_f_with_functional_tools as integrate_f 4 | from integrate import integrate, f 5 | 6 | a = 0.0 7 | b = 10.0 8 | 9 | for N in (10**i for i in xrange(1,7)): 10 | print "Numerical solution with N=%(N)d : %(x)f" % \ 11 | {'N': N, 'x': integrate(f, a, b, N)} 12 | -------------------------------------------------------------------------------- /Examples/profiling/integrate/pycallgraph.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/Examples/profiling/integrate/pycallgraph.png -------------------------------------------------------------------------------- /Examples/profiling/json/js.py: -------------------------------------------------------------------------------- 1 | import json 2 | import urllib2 3 | 4 | url = 'http://api.openweathermap.org/data/2.5/weather?q=seattle' 5 | f = urllib2.urlopen(url) 6 | j = json.loads(f.read()) 7 | print j.keys() 8 | print j.get('weather') 9 | 10 | -------------------------------------------------------------------------------- /Examples/profiling/json/pycallgraph.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/Examples/profiling/json/pycallgraph.png -------------------------------------------------------------------------------- /Examples/profiling/line_profiler/integrate.py: -------------------------------------------------------------------------------- 1 | def f(x): 2 | return x**2 3 | 4 | @profile 5 | def integrate(f, a, b, N): 6 | s = 0 7 | dx = (b-a)/N 8 | for i in xrange(N): 9 | s += f(a+i*dx) 10 | return s * dx 11 | 12 | def integrate_f_with_functional_tools(a, b, N): 13 | dx = (float(b)-a)/N 14 | return sum(map(f, ((a+y*dx) for y in xrange(N))))*dx 15 | -------------------------------------------------------------------------------- /Examples/profiling/line_profiler/integrate_main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # from integrate import integrate_f_with_functional_tools as integrate_f 4 | from integrate import integrate, f 5 | 6 | a = 0.0 7 | b = 10.0 8 | 9 | @profile 10 | def test(): 11 | for N in (10**i for i in xrange(1,6)): 12 | print "Numerical solution with N=%(N)d : %(x)f" % \ 13 | {'N': N, 'x': integrate(f, a, b, N)} 14 | 15 | if __name__ == "__main__": 16 | test() 17 | 18 | -------------------------------------------------------------------------------- /Examples/profiling/line_profiler/integrate_main.py.lprof: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/Examples/profiling/line_profiler/integrate_main.py.lprof -------------------------------------------------------------------------------- /Examples/profiling/line_profiler/pycallgraph.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/Examples/profiling/line_profiler/pycallgraph.png -------------------------------------------------------------------------------- /Examples/profiling/numpy/decorators.py: -------------------------------------------------------------------------------- 1 | import time 2 | 3 | def timer(func): 4 | def timer(*args, **kwargs): 5 | t1 = time.time() 6 | result = func(*args, **kwargs) 7 | print "-- executed in %.4f seconds :" % (time.time() - t1) 8 | return result 9 | return timer 10 | 11 | -------------------------------------------------------------------------------- /Examples/profiling/numpy/image_array.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/Examples/profiling/numpy/image_array.png -------------------------------------------------------------------------------- /Examples/profiling/numpy/images.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import numpy as np 4 | from PIL import Image 5 | 6 | image = Image.open('test_image.jpg') 7 | image_array = np.asarray(image) 8 | image_array.setflags(write=True) 9 | 10 | # glitch data 11 | image_array -= 200 12 | w,h,channels = image_array.shape 13 | 14 | # insert black bands 15 | for x in xrange(0,h,20): 16 | image_array[:, x:x+5, :] = 0 17 | 18 | # swap square slices of image 19 | for i in xrange(0, w-20, 20): 20 | for j in xrange(0, h-20, 20): 21 | image_array[i:i+10,j:j+10,:] = image_array[i+10:i+20, j+10:j+20,:] 22 | Image.fromarray(image_array).save('out.png') 23 | -------------------------------------------------------------------------------- /Examples/profiling/numpy/images2.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import sys 4 | 5 | import numpy as np 6 | from PIL import Image 7 | 8 | 9 | image = Image.open(sys.argv[1]) 10 | image_array = np.asarray(image) 11 | image_array.setflags(write=True) 12 | 13 | # glitch data 14 | image_array -= 100 15 | h,w,channels = image_array.shape 16 | 17 | image_array2 = image_array[:,:,:] 18 | # image_array2 = image_array[h:0:-1, w:0:-1, :] 19 | 20 | # swap square slices of image 21 | for i in xrange(0, h-20, 20): 22 | for j in xrange(0, w-20, 20): 23 | pass 24 | # slices = image_array2[i+10:i+20, j+10:j+20,:] 25 | # slices[:,:,0] += 200 26 | # image_array2[i:i+10,j:j+10,:] = slices 27 | # Image.fromarray(image_array).save('out.png') 28 | image_array2[:,:,1:3] = (0,0) 29 | 30 | Image.fromarray(image_array2).save('out2.png') 31 | -------------------------------------------------------------------------------- /Examples/profiling/numpy/matrix.py: -------------------------------------------------------------------------------- 1 | import numpy 2 | import timeit 3 | 4 | from decorators import timer 5 | 6 | @timer 7 | def offset(matrix, x): 8 | for i in xrange(len(matrix)): 9 | for j in xrange(len(matrix[0])): 10 | matrix[i][j] += x 11 | 12 | @timer 13 | def numpy_offset(matrix, x): 14 | """add x to all values in matix""" 15 | matrix += x 16 | 17 | # create a 2D NxN matrix 18 | python_data_setup = "\ 19 | from __main__ import offset;\ 20 | N=3000;\ 21 | python_data = [[x for x in xrange(N)] for y in xrange(N) ]" 22 | 23 | numpy_data_setup = "\ 24 | import numpy;\ 25 | from __main__ import numpy_offset;\ 26 | N=3000;\ 27 | numpy_data = numpy.array([[x for x in xrange(N)] for y in xrange(N) ])" 28 | 29 | pure_python_statement = "offset(python_data, 10)" 30 | numpy_statement = "numpy_offset(numpy_data, 10)" 31 | print "Pure python: %fs" % timeit.timeit(pure_python_statement, setup=python_data_setup, number=3) 32 | print "Numpy: %fs" % timeit.timeit(numpy_statement, setup=numpy_data_setup, number=3) 33 | 34 | -------------------------------------------------------------------------------- /Examples/profiling/numpy/out.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/Examples/profiling/numpy/out.png -------------------------------------------------------------------------------- /Examples/profiling/numpy/shift.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import numpy as np 4 | from PIL import Image 5 | 6 | image = Image.open('test_image.jpg') 7 | image_array = np.asarray(image) 8 | image_array.setflags(write=True) 9 | 10 | h,w,channels = image_array.shape 11 | 12 | # zeros = np.zeros((h,w,3), dtype=np.uint8) 13 | 14 | # zeros[:,0:-150,:] = image_array[:, 150:w, :] 15 | 16 | zeros = image_array[:,150:,:] 17 | 18 | for j in xrange(0, w-150-20,20 ): 19 | for i in xrange(0, h-20, 20): 20 | slice = zeros[i+10:i+20, j+10:j+20,:] 21 | slice[:,:,0] = 255 22 | # zeros[i:i+10,j:j+10,:] = slice[:,: 23 | # image_array[i:i+10,j:j+10,:] = image_array[i+10:i+20, j+10:j+20,:] 24 | 25 | # zeros[:,:,0] = 255 26 | 27 | Image.fromarray(zeros).save('out.png') 28 | Image.fromarray(image_array).save('image_array.png') 29 | -------------------------------------------------------------------------------- /Examples/profiling/numpy/str.py: -------------------------------------------------------------------------------- 1 | import numpy 2 | 3 | from timer import timer 4 | 5 | @timer 6 | def numpy_test(): 7 | # with open('/usr/share/dict/words') as f: 8 | arr = numpy.loadtxt('/usr/share/dict/words', dtype='S20') 9 | # arr = numpy.fromiter( f, dtype='S20' ) 10 | 11 | print numpy.char.upper(arr)[0:10] 12 | 13 | @timer 14 | def py_test(): 15 | with open('/usr/share/dict/words') as f: 16 | arr = [x.upper() for x in f] 17 | 18 | print arr[0:10] 19 | 20 | py_test() 21 | numpy_test() 22 | -------------------------------------------------------------------------------- /Examples/profiling/numpy/test_image.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/Examples/profiling/numpy/test_image.jpg -------------------------------------------------------------------------------- /Examples/profiling/numpy/timer.py: -------------------------------------------------------------------------------- 1 | import time 2 | 3 | def timer(func): 4 | def timer(*args, **kwargs): 5 | t1 = time.time() 6 | result = func(*args, **kwargs) 7 | t2 = time.time() 8 | print "-- executed %s in %.4f seconds" % (func.func_name, (t2 - t1)) 9 | return result 10 | return timer 11 | 12 | -------------------------------------------------------------------------------- /Examples/profiling/numpy/xion.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/Examples/profiling/numpy/xion.jpg -------------------------------------------------------------------------------- /Examples/profiling/pygame/ball.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/Examples/profiling/pygame/ball.gif -------------------------------------------------------------------------------- /Examples/profiling/pygame/bounce.py: -------------------------------------------------------------------------------- 1 | import sys, pygame 2 | pygame.init() 3 | 4 | size = width, height = 800, 600 5 | speed = [2, 2] 6 | black = 0, 0, 0 7 | 8 | screen = pygame.display.set_mode(size) 9 | 10 | ball = pygame.image.load("ball.gif") 11 | ballrect = ball.get_rect() 12 | 13 | while 1: 14 | for event in pygame.event.get(): 15 | if event.type == pygame.QUIT: sys.exit() 16 | 17 | ballrect = ballrect.move(speed) 18 | if ballrect.left < 0 or ballrect.right > width: 19 | speed[0] = -speed[0] 20 | if ballrect.top < 0 or ballrect.bottom > height: 21 | speed[1] = -speed[1] 22 | 23 | screen.fill(black) 24 | screen.blit(ball, ballrect) 25 | pygame.display.flip() 26 | 27 | -------------------------------------------------------------------------------- /Examples/profiling/pygame/out.prof: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/Examples/profiling/pygame/out.prof -------------------------------------------------------------------------------- /Examples/profiling/pygame/pycallgraph.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/Examples/profiling/pygame/pycallgraph.png -------------------------------------------------------------------------------- /Examples/profiling/pygame/sun.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/Examples/profiling/pygame/sun.gif -------------------------------------------------------------------------------- /Examples/profiling/strings/str_comprehensions.py: -------------------------------------------------------------------------------- 1 | from timer import timer 2 | 3 | # @profile 4 | @timer 5 | def slow(): 6 | s = "" 7 | with open('/usr/share/dict/words') as f: 8 | words = [] 9 | for w in f.readlines(): 10 | words.append(w.upper()) 11 | 12 | return words 13 | 14 | # @profile 15 | @timer 16 | def fast(): 17 | with open('/usr/share/dict/words') as f: 18 | words = [w.upper() for w in f ] 19 | # words = (w.upper() for w in f) 20 | return words 21 | 22 | if __name__ == "__main__": 23 | s1 = slow() 24 | s2 = fast() 25 | assert(s1 == s2) 26 | -------------------------------------------------------------------------------- /Examples/profiling/strings/str_concat.py: -------------------------------------------------------------------------------- 1 | from timer import timer 2 | 3 | @timer 4 | def slow(): 5 | s = "" 6 | with open('/usr/share/dict/words') as f: 7 | for l in f: 8 | s += l 9 | return s 10 | 11 | @timer 12 | def fast(): 13 | with open('/usr/share/dict/words') as f: 14 | s = "".join(f) 15 | return s 16 | 17 | if __name__ == "__main__": 18 | s2 = fast() 19 | s1 = slow() 20 | assert(s1 == s2) 21 | -------------------------------------------------------------------------------- /Examples/profiling/strings/timer.py: -------------------------------------------------------------------------------- 1 | import time 2 | 3 | def timer(func): 4 | def timer(*args, **kwargs): 5 | t1 = time.time() 6 | result = func(*args, **kwargs) 7 | t2 = time.time() 8 | print "-- executed %s in %.4f seconds" % (func.func_name, (t2 - t1)) 9 | return result 10 | return timer 11 | 12 | -------------------------------------------------------------------------------- /Examples/profiling/timer/timer_test.py: -------------------------------------------------------------------------------- 1 | import time 2 | 3 | 4 | def timer(func): 5 | def timer(*args, **kwargs): 6 | """a decorator which prints execution time of the decorated 7 | function""" 8 | t1 = time.time() 9 | result = func(*args, **kwargs) 10 | t2 = time.time() 11 | print("-- executed %s in %.4f seconds" % (func.__name__, (t2 - t1))) 12 | return result 13 | return timer 14 | 15 | 16 | @timer 17 | def expensive_function(): 18 | time.sleep(1) 19 | 20 | 21 | @timer 22 | def less_expensive_function(): 23 | time.sleep(.02) 24 | 25 | expensive_function() 26 | less_expensive_function() 27 | -------------------------------------------------------------------------------- /Examples/profiling/wikidef/api.py: -------------------------------------------------------------------------------- 1 | import json 2 | import urllib 3 | import urllib2 4 | 5 | class ParseError(Exception): 6 | pass 7 | 8 | class Wikipedia(object): 9 | """Wikipedia API interface""" 10 | 11 | api_endpoint = "http://en.wikipedia.org/w/api.php?" 12 | 13 | @classmethod 14 | def article(cls, title): 15 | """Return contents of article 16 | 17 | arguments: 18 | 19 | title -- title of article 20 | """ 21 | query_params = urllib.urlencode({'action': 'parse', 'format': 'json', 'prop':'text', 'page': title}) 22 | url = cls.api_endpoint + query_params 23 | response = urllib2.urlopen(url) 24 | json_response = json.load(response) 25 | try: 26 | contents = json_response['parse']['text']['*'] 27 | except KeyError: 28 | raise ParseError(json_response) 29 | 30 | return contents 31 | 32 | -------------------------------------------------------------------------------- /Examples/profiling/wikidef/define.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import sys 4 | 5 | from definitions import Definitions 6 | from html2text import html2text 7 | 8 | title = sys.argv[1] 9 | 10 | definition = Definitions.article(title) 11 | txt = html2text(definition) 12 | print txt.encode('utf-8') 13 | 14 | -------------------------------------------------------------------------------- /Examples/profiling/wikidef/define.py.lprof: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/Examples/profiling/wikidef/define.py.lprof -------------------------------------------------------------------------------- /Examples/profiling/wikidef/definitions.py: -------------------------------------------------------------------------------- 1 | from api import Wikipedia 2 | 3 | class Definitions(object): 4 | 5 | @classmethod 6 | def article(cls, title): 7 | response = Wikipedia.article(title) 8 | return response 9 | -------------------------------------------------------------------------------- /Examples/profiling/wikidef/dump.profile: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/Examples/profiling/wikidef/dump.profile -------------------------------------------------------------------------------- /Examples/profiling/wikidef/print_stats.py: -------------------------------------------------------------------------------- 1 | import pstats 2 | 3 | prof = pstats.Stats('wikidef.prof') 4 | prof.sort_stats('cumulative') 5 | prof.print_stats('^./[a-z]*.py:') 6 | -------------------------------------------------------------------------------- /Examples/profiling/wikidef/pycallgraph.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/Examples/profiling/wikidef/pycallgraph.png -------------------------------------------------------------------------------- /Examples/profiling/wikidef/tests/wikidef_tests.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | from api import Wikipedia, ParseError 4 | from definitions import Definitions 5 | 6 | class WikiDefTest(unittest.TestCase): 7 | 8 | def setUp(self): 9 | pass 10 | 11 | def tearDown(self): 12 | pass 13 | 14 | def test_article_success(self): 15 | article = Definitions.article("Robot") 16 | self.assertIn("mechanical", article) 17 | 18 | def test_missing_article_failure(self): 19 | missing_article_title = "!!!!!-NonExistentArticle" 20 | self.assertRaises(ParseError, Definitions.article, missing_article_title) 21 | -------------------------------------------------------------------------------- /Examples/ref_counting/simple_circular.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | Simple contrived example of circular reference counting 5 | """ 6 | 7 | import sys 8 | 9 | l1 = [1,] 10 | l2 = [2,] 11 | 12 | l1_id = id(l1) 13 | l2_id = id(l2) 14 | 15 | print "initial ref counts:" 16 | print "l1:", sys.getrefcount(l1) 17 | print "l2:", sys.getrefcount(l2) 18 | 19 | print "now add the circular references:" 20 | l1.append(l2) 21 | l2.append(l1) 22 | 23 | print "ref counts after the circular reference is added" 24 | print "l1:", l1, "refcount:", sys.getrefcount(l1) 25 | print "l2:", l2, "refcount:", sys.getrefcount(l2) 26 | 27 | print "delete one" 28 | del l1 29 | print "l2:", sys.getrefcount(l2) 30 | 31 | print "delete the other" 32 | del l2 33 | 34 | print "but are they still there???" 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /Examples/ref_counting/simple_circular_di.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | Simple contrived example of circular reference counting 5 | 6 | This one does some testing with di.ref_by_id 7 | """ 8 | 9 | import sys 10 | import di 11 | import gc 12 | 13 | l1 = [1,] 14 | l2 = [2,] 15 | 16 | l1_id = id(l1) 17 | l2_id = id(l2) 18 | 19 | print "initial ref counts:" 20 | print "l1:", sys.getrefcount(l1) 21 | print "l2:", sys.getrefcount(l2) 22 | 23 | print "now add the circular references:" 24 | l1.append(l2) 25 | l2.append(l1) 26 | 27 | print "ref counts after the circular reference is added" 28 | print "l1:", sys.getrefcount(l1) 29 | print "l2:", sys.getrefcount(l2) 30 | 31 | print "delete one" 32 | del l1 33 | print "l2:", sys.getrefcount(l2) 34 | 35 | print "delete the other" 36 | del l2 37 | 38 | print "are they still there?" 39 | print "l1's refcount:", di.ref_by_id(l1_id) 40 | print "l2's refcount:", di.ref_by_id(l2_id) 41 | print "-- yes they are!" 42 | 43 | print "now run the garbage collector" 44 | print "It collected:", gc.collect(), "objects" 45 | 46 | print "ref counts now???" 47 | print "l1's refcount:", di.ref_by_id(l1_id) 48 | print "l2's refcount:", di.ref_by_id(l2_id) 49 | 50 | print "yup -- they'll get cleaned up" 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /Examples/sql/address_book_ddl.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE Person( 2 | id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, 3 | first_name TEXT, 4 | last_name TEXT, 5 | middle_name TEXT, 6 | cell_phone TEXT, 7 | email TEXT 8 | ); 9 | 10 | CREATE TABLE Address( 11 | id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, 12 | line_1 TEXT, 13 | line_2 TEXT, 14 | city TEXT, 15 | state TEXT, 16 | zip_code TEXT 17 | ); 18 | 19 | CREATE TABLE Household( 20 | id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL 21 | ); 22 | 23 | CREATE TABLE Business( 24 | id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL 25 | ); 26 | -------------------------------------------------------------------------------- /Examples/sql/address_book_sql.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import os 4 | import sqlite3 5 | import sys 6 | 7 | from address_book_model import create_sample 8 | 9 | SCHEMA_FILE = "address_book_ddl.sql" 10 | DB_FILE = "address.sqlite3" 11 | 12 | if os.path.isfile(DB_FILE): 13 | print "%s exists, exiting" % DB_FILE 14 | sys.exit(-1) 15 | 16 | conn = sqlite3.connect(DB_FILE) 17 | cursor = conn.cursor() 18 | 19 | def create_schema(): 20 | with open(SCHEMA_FILE, 'rt') as f: 21 | schema = f.read() 22 | conn.executescript(schema) 23 | 24 | 25 | create_schema() 26 | address_book = create_sample() 27 | 28 | for person in address_book.people: 29 | insert_statement = "INSERT INTO Person(first_name, last_name, middle_name, cell_phone, email) VALUES (?,?,?,?,?)" 30 | row = ( person.first_name, 31 | person.last_name, 32 | person.middle_name, 33 | person.cell_phone, 34 | person.email) 35 | 36 | cursor.execute(insert_statement, row) 37 | print cursor.rowcount 38 | conn.commit() 39 | 40 | # TODO: also insert Addresses, Businesses, AddressBook, and relationships between them. 41 | 42 | conn.close() 43 | -------------------------------------------------------------------------------- /Examples/sql/createdb.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sqlite3 3 | 4 | DB_FILENAME = 'books.db' 5 | DB_IS_NEW = not os.path.exists(DB_FILENAME) 6 | 7 | def main(): 8 | conn = sqlite3.connect(DB_FILENAME) 9 | if DB_IS_NEW: 10 | print 'Need to create database and schema' 11 | else: 12 | print 'Database exists, assume schema does, too.' 13 | conn.close() 14 | 15 | if __name__ == '__main__': 16 | main() -------------------------------------------------------------------------------- /Examples/sql/ddl.sql: -------------------------------------------------------------------------------- 1 | -- Schema for a simple book database 2 | 3 | -- Author table 4 | 5 | CREATE TABLE author( 6 | authorid INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, 7 | name TEXT 8 | ); 9 | 10 | CREATE TABLE book( 11 | bookid INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, 12 | title TEXT, 13 | author INTEGER NOT NULL, 14 | FOREIGN KEY(author) REFERENCES author(authorid) 15 | ); 16 | -------------------------------------------------------------------------------- /Examples/sql/little_bobby_tables.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # http://xkcd.com/327/ 4 | 5 | import sqlite3 6 | 7 | DB_NAME = ":memory:" 8 | 9 | with sqlite3.connect(DB_NAME) as conn: 10 | cursor = conn.cursor() 11 | 12 | create_query = 'CREATE TABLE Students(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)' 13 | insert_query = 'INSERT INTO Students(name) VALUES (?)' 14 | select_query = 'SELECT COUNT(*) FROM Students' 15 | 16 | cursor.execute(create_query) 17 | 18 | student_data = ( 19 | ("Don",), 20 | ("Sally",), 21 | ("Robert');DROP TABLE Students;--",) 22 | ) 23 | cursor.executemany(insert_query, student_data) 24 | 25 | # now get pwned 26 | bad_insert_query = """INSERT INTO Students(name) VALUES ('%s')""" 27 | for name in student_data: 28 | cursor.executescript(bad_insert_query % name) 29 | print "DB contains %s rows" % cursor.execute(select_query).fetchone()[0] 30 | -------------------------------------------------------------------------------- /Examples/sql/placeholders.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import sqlite3 4 | 5 | DB_NAME = ":memory:" 6 | 7 | with sqlite3.connect(DB_NAME) as conn: 8 | cursor = conn.cursor() 9 | 10 | create_query = 'CREATE TABLE foo(id INT, value FLOAT)' 11 | insert_query = 'INSERT INTO foo(id, value) VALUES (?,?)' 12 | select_query = 'SELECT * FROM foo' 13 | 14 | 15 | data_generator = ((x,float(x)*2) for x in xrange(10)) 16 | 17 | cursor.execute(create_query) 18 | 19 | cursor.executemany(insert_query, data_generator) 20 | 21 | print cursor.execute(select_query).fetchall() 22 | 23 | print "row description: %s" % str(cursor.description) 24 | 25 | print cursor.executemany("INSERT INTO foo(id, value) VALUES (?, ?)", ((1,2.0), (2,5.5))) 26 | 27 | print "%d rows affected" % cursor.rowcount 28 | 29 | -------------------------------------------------------------------------------- /Examples/sql/postgres.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import psycopg2 4 | 5 | conn = psycopg2.connect(host="localhost", user="velotron", password="", database="velotron") 6 | 7 | cursor = conn.cursor() 8 | 9 | cursor.execute('select * from foo') 10 | 11 | for row in cursor: 12 | print row 13 | -------------------------------------------------------------------------------- /Examples/sql/utils.py: -------------------------------------------------------------------------------- 1 | TABLEPRAGMA = "PRAGMA table_info(%s);" 2 | 3 | 4 | def print_table_metadata(cursor): 5 | tmpl = "%-10s |" 6 | rowdata = cursor.description 7 | results = cursor.fetchall() 8 | for col in rowdata: 9 | print tmpl % col[0], 10 | print '\n' + '-----------+-'*len(rowdata) 11 | for row in results: 12 | for value in row: 13 | print tmpl % value, 14 | print '\n' + '-----------+-'*len(rowdata) 15 | print '\n' 16 | 17 | 18 | def show_table_metadata(cursor, tablename): 19 | stmt = TABLEPRAGMA % tablename 20 | cursor.execute(stmt) 21 | print "Table Metadata for '%s':" % tablename 22 | print_table_metadata(cursor) 23 | 24 | 25 | AUTHORS_BOOKS = { 26 | 'China Mieville': ["Perdido Street Station", "The Scar", "King Rat"], 27 | 'Frank Herbert': ["Dune", "Hellstrom's Hive"], 28 | 'J.R.R. Tolkien': ["The Hobbit", "The Silmarillion"], 29 | 'Susan Cooper': ["The Dark is Rising", ["The Greenwitch"]], 30 | 'Madeline L\'Engle': ["A Wrinkle in Time", "A Swiftly Tilting Planet"] 31 | } 32 | -------------------------------------------------------------------------------- /Examples/testing/calculator/calculator.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | """calculator 4 | 5 | Usage: 6 | 7 | calculator.py 1 + 3 8 | 9 | """ 10 | 11 | import sys 12 | 13 | import calculator_functions as functions 14 | 15 | 16 | # put the real code in a function so we can test it 17 | def main(): 18 | 19 | if len(sys.argv) != 4: 20 | error_message = """ 21 | 22 | Invalid arguments. 23 | 24 | Usage: 25 | 26 | calculator.py 1 + 3 27 | 28 | or 1 x 3 29 | or 1 / 3 30 | or 1 - 3 31 | """ 32 | raise ValueError(error_message + "\n") 33 | 34 | x = sys.argv[1] 35 | operator = sys.argv[2] 36 | y = sys.argv[3] 37 | 38 | if operator == "+": 39 | return functions.add(x, y) 40 | 41 | elif operator == "-": 42 | return functions.subtract(x, y) 43 | 44 | elif operator == "x": 45 | return functions.multiply(x, y) 46 | 47 | elif operator == "/": 48 | return functions.divide(x, y) 49 | 50 | else: 51 | return "invalid input" 52 | 53 | if __name__ == "__main__": 54 | try: 55 | print(main()) 56 | except ValueError as err: 57 | sys.stderr.write(err.args[0]) 58 | sys.exit(1) 59 | -------------------------------------------------------------------------------- /Examples/testing/calculator/calculator_functions.py: -------------------------------------------------------------------------------- 1 | """calculator functions""" 2 | 3 | 4 | def add(x, y): 5 | """ Add two numbers 6 | 7 | >>> add(1, 2) 8 | 3 9 | >>> add(-7, 2) 10 | -5 11 | """ 12 | return int(x) + int(y) 13 | 14 | 15 | def subtract(x, y): 16 | return int(x) - int(y) 17 | 18 | def multiply(x, y): 19 | return int(x) * int(y) 20 | 21 | def divide(x, y): 22 | return int(x) / int(y) 23 | -------------------------------------------------------------------------------- /Examples/testing/calculator/calculator_test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | test1="2 + 3" 4 | test2="2 - 3" 5 | 6 | echo -n $test1 "= " 7 | ./calculator.py $test1 8 | echo -n $test2 "= " 9 | ./calculator.py $test2 10 | -------------------------------------------------------------------------------- /Examples/testing/calculator/calculator_test_suite.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | from test_calculator import TestCalculatorFunctions 4 | 5 | suite = unittest.TestLoader().loadTestsFromTestCase(TestCalculatorFunctions) 6 | unittest.TextTestRunner(verbosity=2).run(suite) 7 | -------------------------------------------------------------------------------- /Examples/testing/calculator/solution/calculator.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | """calculator 4 | 5 | Usage: 6 | 7 | calculator.py 1 + 3 8 | 9 | """ 10 | 11 | import sys 12 | 13 | import calculator_functions as functions 14 | 15 | 16 | # put the real code in a function so we can test it 17 | def main(): 18 | 19 | if len(sys.argv) != 4: 20 | error_message = """ 21 | 22 | Invalid arguments. 23 | 24 | Usage: 25 | 26 | calculator.py 1 + 3 27 | 28 | or 1 x 3 29 | or 1 / 3 30 | or 1 - 3 31 | """ 32 | raise ValueError(error_message + "\n") 33 | 34 | x = sys.argv[1] 35 | operator = sys.argv[2] 36 | y = sys.argv[3] 37 | 38 | if operator == "+": 39 | return functions.add(x, y) 40 | 41 | elif operator == "-": 42 | return functions.subtract(x, y) 43 | 44 | elif operator == "x": 45 | return functions.multiply(x, y) 46 | 47 | elif operator == "/": 48 | return functions.divide(x, y) 49 | 50 | else: 51 | return "invalid input" 52 | 53 | if __name__ == "__main__": 54 | try: 55 | print(main()) 56 | except ValueError as err: 57 | sys.stderr.write(err.args[0]) 58 | sys.exit(1) 59 | -------------------------------------------------------------------------------- /Examples/testing/calculator/solution/calculator_functions.py: -------------------------------------------------------------------------------- 1 | """calculator functions""" 2 | 3 | 4 | def add(x, y): 5 | """ Add two numbers 6 | 7 | >>> add(1, 2) 8 | 3 9 | >>> add(-7, 2) 10 | -5 11 | """ 12 | return int(x) + int(y) 13 | 14 | 15 | def subtract(x, y): 16 | return int(x) - int(y) 17 | 18 | 19 | def multiply(x, y): 20 | return int(x) * int(y) 21 | 22 | 23 | def divide(x, y): 24 | return int(x) / int(y) 25 | -------------------------------------------------------------------------------- /Examples/testing/calculator/solution/calculator_test_suite.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | from test_calculator import TestCalculatorFunctions 4 | 5 | suite = unittest.TestLoader().loadTestsFromTestCase(TestCalculatorFunctions) 6 | unittest.TextTestRunner(verbosity=2).run(suite) 7 | -------------------------------------------------------------------------------- /Examples/testing/calculator/test_calculator.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | import calculator_functions as calc 4 | 5 | class TestCalculatorFunctions(unittest.TestCase): 6 | 7 | def setUp(self): 8 | self.x = 2 9 | self.y = 3 10 | 11 | def test_add(self): 12 | self.assertEqual(calc.add(self.x, self.y), 5) 13 | 14 | 15 | if __name__ == "__main__": 16 | unittest.main() 17 | -------------------------------------------------------------------------------- /Examples/testing/context_manager/context_manager.py: -------------------------------------------------------------------------------- 1 | import os 2 | import random 3 | import shutil 4 | import time 5 | 6 | 7 | class TemporaryDirectory(object): 8 | def __init__(self, directory): 9 | self.base_directory = directory 10 | 11 | def __enter__(self): 12 | # set things up 13 | self.directory = os.path.join(self.base_directory, str(random.random())) 14 | os.makedirs(self.directory) 15 | return self.directory 16 | 17 | def __exit__(self, type, value, traceback): 18 | # tear it down 19 | shutil.rmtree(self.directory) 20 | 21 | with TemporaryDirectory("tmp") as dir: 22 | # write some temp data into dir 23 | with open(os.path.join(dir, "foo.txt"), 'w') as f: 24 | f.write("foo") 25 | 26 | time.sleep(5) 27 | -------------------------------------------------------------------------------- /Examples/testing/context_manager/exercise1.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | class YourExceptionHandler(object): 4 | def __enter__(self): 5 | pass 6 | 7 | def __exit__(self, ex_type, value, traceback): 8 | print("there was a {} error".format(ex_type)) 9 | if ex_type is ZeroDivisionError: 10 | return True 11 | else: 12 | return False 13 | 14 | 15 | with YourExceptionHandler(): 16 | print("do some stuff here") 17 | 1 / 0 18 | 19 | print("should still reach this point") 20 | 21 | with YourExceptionHandler(): 22 | print("do more") 23 | fasldkj 24 | 25 | print("you should not get here") 26 | 27 | -------------------------------------------------------------------------------- /Examples/testing/coverage/calculator.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """calculator 4 | 5 | Usage: 6 | 7 | calculator.py 1 + 3 8 | 9 | """ 10 | 11 | import sys 12 | 13 | import calculator_functions as functions 14 | 15 | if len(sys.argv) != 4: 16 | error_message = """ 17 | 18 | Invalid arguments. 19 | 20 | Usage: 21 | 22 | calculator.py 1 + 3 23 | """ 24 | sys.stderr.write(error_message + "\n") 25 | sys.exit(-1) 26 | 27 | x = sys.argv[1] 28 | operator = sys.argv[2] 29 | y = sys.argv[3] 30 | 31 | if operator == "+": 32 | print(functions.add(x, y)) 33 | 34 | elif operator == "-": 35 | print(functions.subtract(x, y)) 36 | 37 | elif operator == "*": 38 | print(functions.multiply(x, y)) 39 | 40 | elif operator == "/": 41 | print(functions.divide(x, y)) 42 | 43 | else: 44 | print("invalid input") 45 | -------------------------------------------------------------------------------- /Examples/testing/coverage/calculator_functions.py: -------------------------------------------------------------------------------- 1 | """calculator functions""" 2 | 3 | def add(x, y): 4 | """ Add two numbers 5 | 6 | >>> add(1, 2) 7 | 3 8 | >>> add(-7, 2) 9 | -5 10 | """ 11 | 12 | return int(x)+int(y) 13 | 14 | def subtract(x, y): 15 | return int(x)-int(y) 16 | 17 | def multiply(x, y): 18 | return int(x)*int(y) 19 | 20 | def divide(x, y): 21 | return int(x)/int(y) 22 | 23 | -------------------------------------------------------------------------------- /Examples/testing/coverage/calculator_test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | test1="2 + 3" 4 | test2="2 - 3" 5 | 6 | echo -n $test1 "= " 7 | ./calculator.py $test1 8 | echo -n $test2 "= " 9 | ./calculator.py $test2 10 | -------------------------------------------------------------------------------- /Examples/testing/coverage/calculator_test_suite.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | from test_calculator import TestCalculatorFunctions 4 | 5 | suite = unittest.TestLoader().loadTestsFromTestCase(TestCalculatorFunctions) 6 | unittest.TextTestRunner(verbosity=2).run(suite) 7 | -------------------------------------------------------------------------------- /Examples/testing/coverage/doctests.py: -------------------------------------------------------------------------------- 1 | def square(x): 2 | """Squares x. 3 | 4 | >>> square(2) 5 | 4 6 | >>> square(-2) 7 | 4 8 | """ 9 | 10 | return x * x 11 | 12 | if __name__ == '__main__': 13 | import doctest 14 | doctest.testmod() 15 | -------------------------------------------------------------------------------- /Examples/testing/coverage/myprog.py: -------------------------------------------------------------------------------- 1 | x = False # 1 2 | if x: # 2 3 | print("in branch") # 3 4 | print("out of branch") # 4 5 | -------------------------------------------------------------------------------- /Examples/testing/coverage/test_calculator.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | import calculator_functions as calc 4 | 5 | class TestCalculatorFunctions(unittest.TestCase): 6 | 7 | def setUp(self): 8 | self.x = 2 9 | self.y = 3 10 | 11 | def test_add(self): 12 | self.assertEqual(calc.add(self.x, self.y), 5) 13 | 14 | # def test_add_float(self): 15 | # self.assertEqual(calc.add(.1,.2), .3) 16 | 17 | 18 | if __name__ == "__main__": 19 | unittest.main() 20 | -------------------------------------------------------------------------------- /Examples/testing/decorators/decorators.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | def timer(func): 4 | import time 5 | def timer(*args, **kwargs): 6 | t1 = time.time() 7 | func(*args, **kwargs) 8 | print "\n\n-- function call took: %.4f seconds to run\n\n" % (time.time() - t1) 9 | return timer 10 | 11 | def logger(func): 12 | def logger(*args, **kwargs): 13 | print "\n\n-- calling function\n\n" 14 | func(*args, **kwargs) 15 | print "\n\n-- function call succeeded\n\n" 16 | return logger 17 | 18 | def exception_handler(func): 19 | def handle_exceptions(*args, **kwargs): 20 | try: 21 | print "handling exceptions.." 22 | func(*args, **kwargs) 23 | except Exception as e: 24 | print "\n\n-- Received exception, logging message: %s\n\n" % str(e) 25 | return handle_exceptions 26 | -------------------------------------------------------------------------------- /Examples/testing/decorators/my_solution.py: -------------------------------------------------------------------------------- 1 | from decorators import timer 2 | 3 | @timer 4 | def my_func(): 5 | print "test" 6 | 7 | my_func() 8 | -------------------------------------------------------------------------------- /Examples/testing/doctests/square.py: -------------------------------------------------------------------------------- 1 | def square(x): 2 | """Squares x. 3 | 4 | >>> square(2) 5 | 4 6 | >>> square(-2) 7 | 4 8 | """ 9 | 10 | return x * x 11 | 12 | if __name__ == '__main__': 13 | import doctest 14 | doctest.testmod() 15 | 16 | -------------------------------------------------------------------------------- /Examples/testing/selenium/selenium_test.py: -------------------------------------------------------------------------------- 1 | import time 2 | 3 | from selenium import webdriver 4 | from selenium.webdriver.common.keys import Keys 5 | 6 | driver = webdriver.Firefox() 7 | 8 | try: 9 | url = "http://localhost:8000/week-01-unit-testing/slides/" 10 | driver.get(url) 11 | assert "Isilon" in driver.title 12 | 13 | body = driver.find_element_by_xpath('//body') 14 | for i in xrange(55): 15 | body.send_keys(Keys.ARROW_RIGHT) 16 | 17 | time.sleep(1) 18 | elem = driver.find_element_by_id("selenium") 19 | assert "Selenium" in elem.text 20 | assert "UnFoundText" not in elem.text 21 | assert "UnFoundText" in elem.text 22 | 23 | finally: 24 | driver.close() 25 | -------------------------------------------------------------------------------- /Examples/testing/solutions/calculator_functions.py: -------------------------------------------------------------------------------- 1 | """calculator functions""" 2 | 3 | def add(x, y): 4 | return float(x)+float(y) 5 | 6 | def subtract(x, y): 7 | return float(x)-float(y) 8 | 9 | def multiply(x, y): 10 | return float(x)*float(y) 11 | 12 | def divide(x, y): 13 | return float(x)/float(y) 14 | -------------------------------------------------------------------------------- /Examples/testing/solutions/context_manager_exception_swallower.py: -------------------------------------------------------------------------------- 1 | import traceback 2 | 3 | class YourExceptionHandler(object): 4 | def __enter__(self): 5 | pass 6 | def __exit__(self, _type, value, _traceback): 7 | print("type: %s" % _type) 8 | print("value: %s" % value) 9 | print("traceback: %s" % traceback.format_tb(_traceback)) 10 | return True 11 | 12 | with YourExceptionHandler(): 13 | print("do some stuff here") 14 | 1/0 15 | 16 | print("should still reach this point") 17 | -------------------------------------------------------------------------------- /Examples/testing/solutions/test_calculator.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | import calculator_functions as calc 4 | 5 | class TestCalculatorFunctions(unittest.TestCase): 6 | 7 | def setUp(self): 8 | self.x = 2 9 | self.y = 3 10 | 11 | def test_add(self): 12 | self.assertEqual(calc.add(self.x, self.y), 5) 13 | 14 | def test_subtract(self): 15 | self.assertEqual(calc.subtract(self.x, self.y), -1) 16 | 17 | def test_multiply(self): 18 | self.assertEqual(calc.multiply(self.x, self.y), 6) 19 | 20 | def test_divide(self): 21 | self.assertAlmostEqual(calc.divide(self.x, self.y), .66666666 ) 22 | 23 | def test_divide_by_zero(self): 24 | self.assertRaises(Exception, calc.divide, (self.x, self.y)) 25 | 26 | 27 | if __name__ == "__main__": 28 | unittest.main() 29 | -------------------------------------------------------------------------------- /Examples/testing/test_float.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | 4 | class TestAlmostEqual(unittest.TestCase): 5 | 6 | def setUp(self): 7 | pass 8 | 9 | def test_floating_point(self): 10 | self.assertEqual(3 * .15, .45) 11 | 12 | def test_almost_equal(self): 13 | self.assertAlmostEqual(3 * .15, .45, places=7) 14 | 15 | if __name__ == "__main__": 16 | unittest.main() 17 | -------------------------------------------------------------------------------- /Examples/testing/wikidef/api.py: -------------------------------------------------------------------------------- 1 | import requests 2 | 3 | 4 | class ParseError(Exception): 5 | pass 6 | 7 | 8 | class Wikipedia(object): 9 | """Wikipedia API interface""" 10 | 11 | api_endpoint = "http://en.wikipedia.org/w/api.php?" 12 | 13 | @classmethod 14 | def article(cls, title): 15 | """Return contents of article 16 | 17 | arguments: 18 | 19 | title -- title of article 20 | """ 21 | data = {'action': 'parse', 'format': 'json', 'prop':'text', 'page': title} 22 | response = requests.get(cls.api_endpoint, params=data) 23 | json_response = response.json() 24 | 25 | try: 26 | contents = json_response['parse']['text']['*'] 27 | except KeyError: 28 | raise ParseError(json_response) 29 | 30 | return contents 31 | -------------------------------------------------------------------------------- /Examples/testing/wikidef/define.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | """ 4 | Script to contact Wikipedia and get articles on a specified topic. 5 | python define.py interesting_topic 6 | """ 7 | 8 | import sys 9 | 10 | from definitions import Definitions 11 | 12 | title = sys.argv[1] 13 | 14 | print(Definitions.article(title).encode('utf-8')) 15 | -------------------------------------------------------------------------------- /Examples/testing/wikidef/definitions.py: -------------------------------------------------------------------------------- 1 | from api import Wikipedia 2 | 3 | class Definitions(object): 4 | 5 | @classmethod 6 | def article(cls, title): 7 | return Wikipedia.article(title) 8 | -------------------------------------------------------------------------------- /Examples/testing/wikidef/solution/api.py: -------------------------------------------------------------------------------- 1 | import requests 2 | 3 | 4 | class ParseError(Exception): 5 | pass 6 | 7 | 8 | class Wikipedia(object): 9 | """Wikipedia API interface""" 10 | 11 | api_endpoint = "http://en.wikipedia.org/w/api.php?" 12 | 13 | @classmethod 14 | def article(cls, title): 15 | """Return contents of article 16 | 17 | arguments: 18 | 19 | title -- title of article 20 | """ 21 | json_response = get_article(title, cls.api_endpoint) 22 | 23 | if 'parse' in json_response: 24 | return json_response['parse']['text']['*'] 25 | else: 26 | raise ParseError(json_response['error']['info']) 27 | 28 | 29 | def get_article(title, api_endpoint): 30 | data = {'action': 'parse', 'format': 'json', 'prop':'text', 'page': title} 31 | response = requests.get(api_endpoint, params=data) 32 | return response.json() 33 | 34 | 35 | -------------------------------------------------------------------------------- /Examples/testing/wikidef/solution/define.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | """ 4 | Script to contact Wikipedia and get articles on a specified topic. 5 | python define.py interesting_topic 6 | """ 7 | 8 | import sys 9 | 10 | from definitions import Definitions 11 | 12 | title = sys.argv[1] 13 | 14 | print(Definitions.article(title).encode('utf-8')) 15 | -------------------------------------------------------------------------------- /Examples/testing/wikidef/solution/definitions.py: -------------------------------------------------------------------------------- 1 | from api import Wikipedia 2 | 3 | class Definitions(object): 4 | 5 | @classmethod 6 | def article(cls, title): 7 | return Wikipedia.article(title) 8 | -------------------------------------------------------------------------------- /Examples/testing/wikidef/test_wikidef.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | from api import Wikipedia, ParseError 4 | from definitions import Definitions 5 | 6 | class WikiDefTest(unittest.TestCase): 7 | 8 | def setUp(self): 9 | pass 10 | 11 | def tearDown(self): 12 | pass 13 | 14 | def test_article_success(self): 15 | article = Definitions.article("Robot") 16 | self.assertIn("mechanical", article) 17 | 18 | def test_failing_test(self): 19 | expected = 1 20 | actual = 0 21 | self.assertEqual(expected, actual) 22 | 23 | -------------------------------------------------------------------------------- /Examples/threading-multiprocessing/celery/master.py: -------------------------------------------------------------------------------- 1 | from tasks import add 2 | 3 | results = [] 4 | results.append(add.delay(4,4)) 5 | results.append(add.delay(1,0)) 6 | results.append(add.delay(37337,1)) 7 | 8 | for result in results: 9 | print result.get() 10 | -------------------------------------------------------------------------------- /Examples/threading-multiprocessing/celery/tasks.py: -------------------------------------------------------------------------------- 1 | from celery import Celery 2 | 3 | celery = Celery('tasks', backend="amqp", broker='amqp://guest@localhost//') 4 | 5 | @celery.task 6 | def add(x, y): 7 | return x + y 8 | -------------------------------------------------------------------------------- /Examples/threading-multiprocessing/decorators/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/Examples/threading-multiprocessing/decorators/__init__.py -------------------------------------------------------------------------------- /Examples/threading-multiprocessing/decorators/decorators.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import time 4 | 5 | 6 | def timer(func): 7 | def timer(*args, **kwargs): 8 | t1 = time.time() 9 | result = func(*args, **kwargs) 10 | print("-- executed in %.4f seconds :" % (time.time() - t1)) 11 | return result 12 | return timer 13 | 14 | 15 | def logger(func): 16 | def logger(*args, **kwargs): 17 | print("\n\n-- calling function\n\n") 18 | func(*args, **kwargs) 19 | print("\n\n-- function call succeeded\n\n") 20 | return logger 21 | 22 | 23 | def exception_handler(func): 24 | def handle_exceptions(*args, **kwargs): 25 | try: 26 | print("handling exceptions..") 27 | func(*args, **kwargs) 28 | except Exception as e: 29 | print("\n\n-- Received exception, logging message: %s\n\n" % str(e)) 30 | return handle_exceptions 31 | -------------------------------------------------------------------------------- /Examples/threading-multiprocessing/integrate/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/Examples/threading-multiprocessing/integrate/__init__.py -------------------------------------------------------------------------------- /Examples/threading-multiprocessing/integrate/decorators.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import time 4 | 5 | def timer(func): 6 | def timer(*args, **kwargs): 7 | t1 = time.time() 8 | result = func(*args, **kwargs) 9 | print "-- executed in %.4f seconds :" % (time.time() - t1), 10 | return result 11 | return timer 12 | 13 | def logger(func): 14 | def logger(*args, **kwargs): 15 | print "\n\n-- calling function\n\n" 16 | func(*args, **kwargs) 17 | print "\n\n-- function call succeeded\n\n" 18 | return logger 19 | 20 | def exception_handler(func): 21 | def handle_exceptions(*args, **kwargs): 22 | try: 23 | print "handling exceptions.." 24 | func(*args, **kwargs) 25 | except Exception as e: 26 | print "\n\n-- Received exception, logging message: %s\n\n" % str(e) 27 | return handle_exceptions 28 | -------------------------------------------------------------------------------- /Examples/threading-multiprocessing/integrate/integrate.py: -------------------------------------------------------------------------------- 1 | def f(x): 2 | return x**2 3 | 4 | 5 | def integrate(f, a, b, N): 6 | s = 0 7 | dx = (b - a) / N 8 | for i in range(N): 9 | s += f(a + i * dx) 10 | return s * dx 11 | 12 | 13 | def integrate_f_with_functional_tools(a, b, N): 14 | dx = (float(b) - a) / N 15 | return sum(map(f, ((a + y * dx) for y in range(N)))) * dx 16 | -------------------------------------------------------------------------------- /Examples/threading-multiprocessing/integrate/integrate_main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # from integrate import integrate_f_with_functional_tools as integrate_f 4 | from integrate import integrate, f 5 | 6 | a = 0.0 7 | b = 10.0 8 | 9 | for N in (10**i for i in range(1, 8)): 10 | print("Numerical solution with N=%(N)d : %(x)f" % 11 | {'N': N, 'x': integrate(f, a, b, N)}) 12 | -------------------------------------------------------------------------------- /Examples/threading-multiprocessing/integrate/integrate_main_profiler.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from integrate import f, integrate as _integrate 4 | from decorators import timer 5 | 6 | @timer 7 | def integrate(*args): 8 | return _integrate(*args) 9 | 10 | a = 0.0 11 | b = 10.0 12 | 13 | for N in (10**i for i in xrange(1,8)): 14 | print "Numerical solution with N=%(N)d : %(x)f" % \ 15 | {'N': N, 'x': integrate(f, a, b, N)} 16 | -------------------------------------------------------------------------------- /Examples/threading-multiprocessing/integrate/sequential/integrate_main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import argparse 4 | import sys 5 | sys.path.append("..") 6 | 7 | from integrate import integrate_f_with_functional_tools as integrate_f 8 | 9 | parser = argparse.ArgumentParser(description='integrator') 10 | parser.add_argument('a', nargs='?', type=float, default=0.0) 11 | parser.add_argument('b', nargs='?', type=float, default=10.0) 12 | parser.add_argument('N', nargs='?', type=int, default=10**6) 13 | 14 | args = parser.parse_args() 15 | a = args.a 16 | b = args.b 17 | N = args.N 18 | 19 | print "Numerical solution from (%(a)f to %(b)f with N=%(N)d : \n%(x)f" % \ 20 | {'a': a, 'b': b, 'N': N, 'x': integrate_f(a, b, N)} 21 | -------------------------------------------------------------------------------- /Examples/threading-multiprocessing/lock/simple_locks.py: -------------------------------------------------------------------------------- 1 | import threading 2 | import time 3 | 4 | lock = threading.Lock() 5 | 6 | def f(): 7 | lock.acquire() 8 | print("%s got lock" % threading.current_thread().name) 9 | time.sleep(1) 10 | lock.release() 11 | 12 | threading.Thread(target=f).start() 13 | threading.Thread(target=f).start() 14 | threading.Thread(target=f).start() 15 | -------------------------------------------------------------------------------- /Examples/threading-multiprocessing/lock/stdout_writer.py: -------------------------------------------------------------------------------- 1 | import random 2 | import sys 3 | import threading 4 | import time 5 | 6 | 7 | def write(): 8 | sys.stdout.write("%s writing.." % threading.current_thread().name) 9 | time.sleep(random.random()) 10 | sys.stdout.write("..done\n") 11 | 12 | for i in range(100): 13 | thread = threading.Thread(target=write) 14 | thread.daemon = True # allow ctrl-c to end 15 | thread.start() 16 | time.sleep(.1) 17 | -------------------------------------------------------------------------------- /Examples/threading-multiprocessing/lock/stdout_writer_semaphore.py: -------------------------------------------------------------------------------- 1 | import random 2 | import sys 3 | import threading 4 | import time 5 | 6 | lock = threading.Semaphore(2) 7 | 8 | def write(): 9 | lock.acquire() 10 | sys.stdout.write( "%s writing.." % threading.current_thread().name) 11 | time.sleep(random.random()) 12 | sys.stdout.write( "..done\n") 13 | lock.release() 14 | 15 | 16 | while True: 17 | thread = threading.Thread(target=write) 18 | thread.start() 19 | time.sleep(.1) 20 | 21 | -------------------------------------------------------------------------------- /Examples/threading-multiprocessing/lock/stdout_writer_solution.py: -------------------------------------------------------------------------------- 1 | import random 2 | import sys 3 | import threading 4 | import time 5 | 6 | lock = threading.Lock() 7 | 8 | 9 | def write(): 10 | lock.acquire() 11 | sys.stdout.write("%s writing.." % threading.current_thread().name) 12 | time.sleep(random.random()) 13 | sys.stdout.write("..done\n") 14 | lock.release() 15 | 16 | threads = [] 17 | for i in range(50): 18 | thread = threading.Thread(target=write) 19 | thread.daemon = True # allow ctrl-c to end 20 | thread.start() 21 | threads.append(thread) 22 | time.sleep(.01) 23 | 24 | # Now join() them all so the program won't terminate early 25 | # required because these are all daemon threads 26 | for thread in threads: 27 | thread.join() 28 | 29 | -------------------------------------------------------------------------------- /Examples/threading-multiprocessing/race_condition.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import threading 4 | import time 5 | 6 | x = 1 7 | 8 | def func(): 9 | global x 10 | y = x 11 | time.sleep(0.01) 12 | y += 1 13 | x = y 14 | 15 | threads = [] 16 | # with enough threads, there's sufficient overhead to cause a race 17 | # condition 18 | for i in range(20000): 19 | thread = threading.Thread(target=func) 20 | threads.append(thread) 21 | thread.start() 22 | 23 | for thread in threads: 24 | thread.join() 25 | 26 | print(x) 27 | -------------------------------------------------------------------------------- /Examples/threading-multiprocessing/server/app.py: -------------------------------------------------------------------------------- 1 | from itertools import count 2 | import time 3 | 4 | i = count() 5 | 6 | def app(environ, start_response): 7 | data = "Hello, World. %d\n" % next(i) 8 | start_response("200 OK", [ 9 | ("Content-Type", "text/plain"), 10 | ("Content-Length", str(len(data))) 11 | ]) 12 | time.sleep(0.5) 13 | return iter([data.encode('utf-8')]) 14 | -------------------------------------------------------------------------------- /Examples/threading-multiprocessing/server/client-asyncio.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import os 4 | import sys 5 | from urllib.request import urlopen 6 | import asyncio 7 | 8 | sys.path.append(os.path.join(os.path.dirname(__file__), "..")) 9 | 10 | # from decorators.decorators import timer 11 | 12 | # @timer 13 | 14 | results = asyncio.Queue() 15 | url = "http://localhost:37337" 16 | 17 | @asyncio.coroutine 18 | def producer(): 19 | conn = urlopen(url) 20 | result = conn.read() 21 | return result 22 | 23 | @asyncio.coroutine 24 | def worker(): 25 | result = yield from producer() 26 | results.put(result) 27 | 28 | loop = asyncio.get_event_loop() 29 | 30 | number_of_requests = 100 31 | 32 | for i in range(number_of_requests): 33 | loop.run_until_complete(worker()) 34 | 35 | print( "made %d requests" % number_of_requests) 36 | -------------------------------------------------------------------------------- /Examples/threading-multiprocessing/server/client-mp.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import os 4 | import sys 5 | import urllib.request 6 | import multiprocessing 7 | 8 | sys.path.append(os.path.join(os.path.dirname(__file__), "..")) 9 | 10 | from decorators.decorators import timer 11 | 12 | @timer 13 | def threading_client(number_of_requests=10): 14 | 15 | results = multiprocessing.Queue() 16 | url = "http://localhost:37337" 17 | 18 | def worker(*args): 19 | conn = urllib.request.urlopen(url) 20 | result = conn.read() 21 | conn.close() 22 | results.put(result) 23 | 24 | for i in range(number_of_requests): 25 | proc = multiprocessing.Process(target=worker, args=()) 26 | proc.start() 27 | print("Process %s started" % proc.name) 28 | 29 | for i in range(number_of_requests): 30 | print(results.get(timeout=2)) 31 | 32 | print("made %d requests" % number_of_requests) 33 | 34 | if __name__ == "__main__": 35 | 36 | number_of_requests = 100 37 | threading_client(number_of_requests=number_of_requests) 38 | -------------------------------------------------------------------------------- /Examples/threading-multiprocessing/server/client-pooled-solution.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from multiprocessing.pool import ThreadPool 4 | import os 5 | import sys 6 | import urllib.request, urllib.error, urllib.parse 7 | import queue 8 | 9 | sys.path.append(os.path.join(os.path.dirname(__file__), "..")) 10 | from decorators.decorators import timer 11 | 12 | @timer 13 | def threading_client(number_of_requests=10, thread_count=2): 14 | 15 | results = queue.Queue() 16 | url = "http://localhost:37337" 17 | 18 | def worker(*args): 19 | conn = urllib.request.urlopen(url) 20 | result = conn.read() 21 | conn.close() 22 | results.put(result) 23 | print(result) 24 | 25 | pool = ThreadPool(processes=thread_count) 26 | pool.map(worker, list(range(number_of_requests))) 27 | 28 | 29 | if __name__ == "__main__": 30 | number_of_requests = 100 31 | thread_count = 10 32 | threading_client(number_of_requests=number_of_requests, thread_count = thread_count) 33 | -------------------------------------------------------------------------------- /Examples/threading-multiprocessing/server/client-pooled.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from multiprocessing.pool import ThreadPool 4 | import os 5 | import sys 6 | import urllib.request, urllib.error, urllib.parse 7 | import queue 8 | 9 | sys.path.append(os.path.join(os.path.dirname(__file__), "..")) 10 | 11 | from decorators.decorators import timer 12 | 13 | @timer 14 | def threading_client(number_of_requests=10, thread_count=2): 15 | 16 | results = queue.Queue() 17 | url = "http://localhost:37337" 18 | 19 | def worker(*args): 20 | conn = urllib.request.urlopen(url) 21 | result = conn.read() 22 | conn.close() 23 | print(result) 24 | 25 | pool = ThreadPool(processes=thread_count) 26 | pool.map(worker, list(range(number_of_requests))) 27 | 28 | if __name__ == "__main__": 29 | number_of_requests = 100 30 | thread_count = 10 31 | threading_client(number_of_requests=number_of_requests, thread_count = thread_count) 32 | -------------------------------------------------------------------------------- /Examples/threading-multiprocessing/server/client-threading.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import os 4 | import sys 5 | import urllib.request 6 | import threading, queue 7 | 8 | sys.path.append(os.path.join(os.path.dirname(__file__), "..")) 9 | 10 | from decorators.decorators import timer 11 | 12 | @timer 13 | def threading_client(number_of_requests=10): 14 | 15 | results = queue.Queue() 16 | url = "http://localhost:37337" 17 | 18 | def worker(*args): 19 | conn = urllib.request.urlopen(url) 20 | result = conn.read() 21 | conn.close() 22 | results.put(result) 23 | 24 | for i in range(number_of_requests): 25 | thread = threading.Thread(target=worker, args=()) 26 | thread.start() 27 | print("Thread %s started" % thread.name) 28 | 29 | for i in range(number_of_requests): 30 | print(results.get(timeout=2)) 31 | 32 | print("made %d requests" % number_of_requests) 33 | 34 | if __name__ == "__main__": 35 | 36 | number_of_requests = 100 37 | threading_client(number_of_requests=number_of_requests) 38 | -------------------------------------------------------------------------------- /Examples/threading-multiprocessing/server/serve.py: -------------------------------------------------------------------------------- 1 | from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler 2 | from SocketServer import ThreadingMixIn 3 | import random 4 | import threading 5 | import time 6 | 7 | class Handler(BaseHTTPRequestHandler): 8 | 9 | def do_GET(self): 10 | # t = random.random() / 1000 11 | t=1.0 12 | # time.sleep(t) 13 | self.send_response(200) 14 | self.end_headers() 15 | message = str(t) + " " + threading.currentThread().getName() 16 | self.wfile.write(message) 17 | self.wfile.write('\n') 18 | return 19 | 20 | class ThreadedHTTPServer(ThreadingMixIn, HTTPServer): 21 | """Handle requests in a separate thread.""" 22 | 23 | if __name__ == '__main__': 24 | server = ThreadedHTTPServer(('localhost', 37337), Handler) 25 | print 'Starting server, use to stop' 26 | server.serve_forever() 27 | -------------------------------------------------------------------------------- /Examples/threading-multiprocessing/simple-threading.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import threading 3 | import time 4 | 5 | 6 | def func(): 7 | for i in range(5): 8 | print("hello from thread %s" % threading.current_thread().name) 9 | time.sleep(1) 10 | 11 | threads = [] 12 | for i in range(3): 13 | thread = threading.Thread(target=func, args=()) 14 | thread.start() 15 | threads.append(thread) 16 | 17 | for thread in threads: 18 | thread.join() 19 | -------------------------------------------------------------------------------- /Examples/threading-multiprocessing/test.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/Examples/threading-multiprocessing/test.db -------------------------------------------------------------------------------- /Examples/wxpython/address_book/a_book.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "phone": "123-456-8888", 4 | "first_name": "Chris", 5 | "last_name": "Barker", 6 | "email": "PythonCHB@gmail.com" 7 | }, 8 | { 9 | "phone": "510-555-1234", 10 | "first_name": "Fred", 11 | "last_name": "Jones", 12 | "email": "FredJones@some_company.com" 13 | }, 14 | { 15 | "phone": "423-321-9876", 16 | "first_name": "Nancy", 17 | "last_name": "Wilson", 18 | "email": "Wilson.Nancy@gmail.com" 19 | }, 20 | { 21 | "phone": "555-555-5555", 22 | "first_name": "Charles", 23 | "last_name": "Dickens", 24 | "email": "chuck@victorian.england.com" 25 | } 26 | ] -------------------------------------------------------------------------------- /Examples/wxpython/address_book_solution/a_book.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "Phone": "123-456-8888", 4 | "First Name": "Chris", 5 | "Last Name": "Barker", 6 | "email": "PythonCHB@gmail.com" 7 | }, 8 | { 9 | "Phone": "510-555-1234", 10 | "First Name": "Fred", 11 | "Last Name": "Jones", 12 | "email": "FredJones@some_company.com" 13 | }, 14 | { 15 | "Phone": "423-321-9876", 16 | "First Name": "Nancy", 17 | "Last Name": "Wilson", 18 | "email": "Wilson.Nancy@gmail.com" 19 | }, 20 | { 21 | "Phone": "555-555-5555", 22 | "First Name": "Charles", 23 | "Last Name": "Dickens", 24 | "email": "chuck@victorian.england.com" 25 | } 26 | ] -------------------------------------------------------------------------------- /Examples/wxpython/basic_app_1.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | Example of the very basic, minimal framework for a wxPython application. 5 | """ 6 | 7 | import wx 8 | 9 | class TestFrame(wx.Frame): 10 | def __init__(self, *args, **kwargs): 11 | kwargs.setdefault('title', "Simple test App") 12 | wx.Frame.__init__(self, *args, **kwargs) 13 | 14 | 15 | class TestApp(wx.App): 16 | def OnInit(self): 17 | """ 18 | App initilization goes here -- not much to do in this case 19 | """ 20 | f = TestFrame(None) 21 | f.Show() 22 | 23 | return True 24 | 25 | if __name__ == "__main__": 26 | app = TestApp(False) 27 | app.MainLoop() 28 | 29 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | System Development With Python 2 | ============================== 3 | 4 | System Development With Python: Third class in the Python Certification series. 5 | 6 | This repository contains the source materials for the third class in the University of Washington Professional and Continuing Education Program Python Certification Program: 7 | 8 | .. _Certificate in Python Programming : http://www.pce.uw.edu/certificates/python-programming.html 9 | 10 | See the Syllabus for more detail. 11 | 12 | Class lecture materials are available in a rendered version from: 13 | 14 | http://UWPCE-PythonCert.github.io/SystemDevelopment 15 | 16 | -------------------------------------------------------------------------------- /Syllabus.md: -------------------------------------------------------------------------------- 1 | # UW Certificate Program in Programming in Python 2 | 3 | Python 300 4 | 5 | Spring, 2016 6 | 7 | March 29 through May 31st, Tuesday, 6 PM 8 | 9 | For the complete Syllabus, see: 10 | 11 | http://uwpce-pythoncert.github.io/SystemDevelopment/index.html 12 | 13 | -------------------------------------------------------------------------------- /process_survey.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | """ 4 | some quick processing of the survey for the third class 5 | """ 6 | 7 | pref_map = { '': -1, 8 | 'Not at all':0, 9 | 'Not much':1, 10 | 'Somewhat':2, 11 | 'Very':3, 12 | } 13 | 14 | with open("Python 3 Topic Options (Responses) - Form Responses 1.tsv") as infile: 15 | topics = infile.readline().strip().split('\t')[1:] 16 | topics = [line.split('[')[1].rstrip(']') for line in topics] 17 | data_table = [[pref_map[pref.strip()] for pref in line.split('\t')[1:]] for line in infile] 18 | 19 | results = [] 20 | for i, topic in enumerate(topics): 21 | #get the average for that topic 22 | scores = [row[i] for row in data_table if row[i] >= 0] 23 | results.append(sum(scores) / len(scores)) 24 | results = sorted(zip(topics, results), key= lambda x: -x[1]) 25 | 26 | with open("survey_results.txt", 'w') as outfile: 27 | for topic, score in results: 28 | line = "%50s %.2f"%(topic,score) 29 | outfile.write(line+'\n') 30 | print(line) 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /slides_sources/build_gh_pages.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # simple script to build and push to gh-pages 4 | # designed to be run from master 5 | 6 | GHPAGESDIR=../../SystemDevelopment.gh-pages/ 7 | 8 | # make sure the Gh pages repo is there and in the right branch 9 | pushd $GHPAGESDIR 10 | git checkout gh-pages 11 | popd 12 | 13 | # make the docs 14 | make html 15 | # copy to other repo (on the gh-pages branch) 16 | cp -R build/html/ $GHPAGESDIR 17 | 18 | pushd $GHPAGESDIR 19 | git add * # in case there are new files added 20 | git commit -a -m "updating presentation materials" 21 | git pull -s ours --no-edit 22 | git push 23 | 24 | -------------------------------------------------------------------------------- /slides_sources/html_slides/deckjs/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## v1.1.0 4 | 5 | - Expand `beforeInit` event to allow halting of init event. 6 | - Create alternative init signature with single options object using new `options.selectors.slides` option. 7 | - Added methods `getTopLevelSlides` and `getNestedSlides`. 8 | - Integrated hash plugin into core. 9 | - Allow for touch swiping to be axis specific or disabled. 10 | - Include ARIA attribute considerations in core and extensions. 11 | -------------------------------------------------------------------------------- /slides_sources/html_slides/deckjs/MIT-license.txt: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 2011-2014 Caleb Troughton 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /slides_sources/html_slides/deckjs/Makefile: -------------------------------------------------------------------------------- 1 | SASSOPTS=--scss --style expanded 2 | 3 | default: generate 4 | 5 | generate: 6 | sass --update ${SASSOPTS} . 7 | 8 | force: 9 | sass --update ${SASSOPTS} --force . 10 | 11 | watch: 12 | sass --watch ${SASSOPTS} . 13 | -------------------------------------------------------------------------------- /slides_sources/html_slides/deckjs/core/deck.core.css: -------------------------------------------------------------------------------- 1 | html, body { 2 | height: 100%; 3 | padding: 0; 4 | margin: 0; 5 | } 6 | 7 | .deck-container { 8 | position: relative; 9 | min-height: 100%; 10 | margin: 0 auto; 11 | overflow: hidden; 12 | overflow-y: auto; 13 | } 14 | .js .deck-container { 15 | visibility: hidden; 16 | } 17 | .ready .deck-container { 18 | visibility: visible; 19 | } 20 | .touch .deck-container { 21 | -webkit-text-size-adjust: none; 22 | -moz-text-size-adjust: none; 23 | } 24 | 25 | .deck-loading { 26 | display: none; 27 | } 28 | 29 | .slide { 30 | width: auto; 31 | min-height: 100%; 32 | position: relative; 33 | } 34 | 35 | .deck-before, .deck-previous, .deck-next, .deck-after { 36 | position: absolute; 37 | left: -999em; 38 | top: -999em; 39 | } 40 | 41 | .deck-current { 42 | z-index: 2; 43 | } 44 | 45 | .slide .slide { 46 | visibility: hidden; 47 | position: static; 48 | min-height: 0; 49 | } 50 | 51 | .deck-child-current { 52 | position: static; 53 | z-index: 2; 54 | } 55 | .deck-child-current .slide { 56 | visibility: hidden; 57 | } 58 | .deck-child-current .deck-previous, .deck-child-current .deck-before, .deck-child-current .deck-current { 59 | visibility: visible; 60 | } 61 | -------------------------------------------------------------------------------- /slides_sources/html_slides/deckjs/core/deck.core.scss: -------------------------------------------------------------------------------- 1 | html, body { 2 | height:100%; 3 | padding:0; 4 | margin:0; 5 | } 6 | 7 | .deck-container { 8 | position:relative; 9 | min-height:100%; 10 | margin:0 auto; 11 | overflow:hidden; 12 | overflow-y:auto; 13 | 14 | .js & { 15 | visibility:hidden; 16 | } 17 | 18 | .ready & { 19 | visibility:visible; 20 | } 21 | 22 | .touch & { 23 | -webkit-text-size-adjust:none; 24 | -moz-text-size-adjust:none; 25 | } 26 | } 27 | 28 | .deck-loading { 29 | display:none; 30 | } 31 | 32 | .slide { 33 | width:auto; 34 | min-height:100%; 35 | position:relative; 36 | } 37 | 38 | .deck-before, .deck-previous, .deck-next, .deck-after { 39 | position:absolute; 40 | left:-999em; 41 | top:-999em; 42 | } 43 | 44 | .deck-current { 45 | z-index:2; 46 | } 47 | 48 | .slide .slide { 49 | visibility:hidden; 50 | position:static; 51 | min-height:0; 52 | } 53 | 54 | .deck-child-current { 55 | position:static; 56 | z-index:2; 57 | 58 | .slide { 59 | visibility:hidden; 60 | } 61 | 62 | .deck-previous, .deck-before, .deck-current { 63 | visibility:visible; 64 | } 65 | } -------------------------------------------------------------------------------- /slides_sources/html_slides/deckjs/core/print.css: -------------------------------------------------------------------------------- 1 | body { 2 | font-size: 18pt; 3 | } 4 | 5 | h1 { 6 | font-size: 48pt; 7 | } 8 | 9 | h2 { 10 | font-size: 36pt; 11 | } 12 | 13 | h3 { 14 | font-size: 28pt; 15 | } 16 | 17 | pre { 18 | border: 1px solid #000; 19 | padding: 10px; 20 | white-space: pre-wrap; 21 | } 22 | 23 | .deck-container > .slide { 24 | page-break-after: always; 25 | } 26 | -------------------------------------------------------------------------------- /slides_sources/html_slides/deckjs/core/print.scss: -------------------------------------------------------------------------------- 1 | body { font-size:18pt; } 2 | h1 { font-size:48pt; } 3 | h2 { font-size:36pt; } 4 | h3 { font-size:28pt; } 5 | 6 | pre { 7 | border:1px solid #000; 8 | padding:10px; 9 | white-space:pre-wrap; 10 | } 11 | 12 | .deck-container > .slide { 13 | page-break-after: always; 14 | } 15 | -------------------------------------------------------------------------------- /slides_sources/html_slides/deckjs/extensions/goto/deck.goto.css: -------------------------------------------------------------------------------- 1 | .goto-form { 2 | position: absolute; 3 | z-index: 3; 4 | bottom: 10px; 5 | left: 50%; 6 | height: 1.75em; 7 | margin: 0 0 0 -9.125em; 8 | line-height: 1.75em; 9 | padding: 0.625em; 10 | display: none; 11 | background: #ccc; 12 | overflow: hidden; 13 | border-radius: 10px; 14 | } 15 | .goto-form label { 16 | font-weight: bold; 17 | } 18 | .goto-form label, .goto-form input { 19 | display: inline-block; 20 | font-family: inherit; 21 | } 22 | .deck-goto .goto-form { 23 | display: block; 24 | } 25 | 26 | #goto-slide { 27 | width: 8.375em; 28 | margin: 0 0.625em; 29 | height: 1.4375em; 30 | } 31 | 32 | @media print { 33 | .goto-form, #goto-slide { 34 | display: none; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /slides_sources/html_slides/deckjs/extensions/goto/deck.goto.html: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 | 5 | 6 | 7 |
-------------------------------------------------------------------------------- /slides_sources/html_slides/deckjs/extensions/goto/deck.goto.scss: -------------------------------------------------------------------------------- 1 | .goto-form { 2 | position:absolute; 3 | z-index:3; 4 | bottom:10px; 5 | left:50%; 6 | height:1.75em; 7 | margin:0 0 0 -9.125em; 8 | line-height:1.75em; 9 | padding:0.625em; 10 | display:none; 11 | background:#ccc; 12 | overflow:hidden; 13 | border-radius:10px; 14 | 15 | label { 16 | font-weight:bold; 17 | } 18 | 19 | label, input { 20 | display:inline-block; 21 | font-family:inherit; 22 | } 23 | 24 | .deck-goto & { 25 | display:block; 26 | } 27 | } 28 | 29 | #goto-slide { 30 | width:8.375em; 31 | margin:0 0.625em; 32 | height:1.4375em; 33 | } 34 | 35 | @media print { 36 | .goto-form, #goto-slide { 37 | display:none; 38 | } 39 | } -------------------------------------------------------------------------------- /slides_sources/html_slides/deckjs/extensions/hash/deck.hash.css: -------------------------------------------------------------------------------- 1 | .deck-container .deck-permalink { 2 | display: none; 3 | position: absolute; 4 | z-index: 4; 5 | bottom: 30px; 6 | right: 0; 7 | width: 48px; 8 | text-align: center; 9 | } 10 | 11 | .no-history .deck-container:hover .deck-permalink { 12 | display: block; 13 | } 14 | -------------------------------------------------------------------------------- /slides_sources/html_slides/deckjs/extensions/hash/deck.hash.html: -------------------------------------------------------------------------------- 1 | 2 | # -------------------------------------------------------------------------------- /slides_sources/html_slides/deckjs/extensions/hash/deck.hash.scss: -------------------------------------------------------------------------------- 1 | .deck-container { 2 | .deck-permalink { 3 | display:none; 4 | position:absolute; 5 | z-index:4; 6 | bottom:30px; 7 | right:0; 8 | width:48px; 9 | text-align:center; 10 | } 11 | } 12 | 13 | .no-history .deck-container:hover .deck-permalink { 14 | display:block; 15 | } -------------------------------------------------------------------------------- /slides_sources/html_slides/deckjs/extensions/menu/deck.menu.css: -------------------------------------------------------------------------------- 1 | .deck-menu { 2 | overflow: auto; 3 | } 4 | .deck-menu .slide { 5 | background: #eee; 6 | position: relative; 7 | left: 0; 8 | top: 0; 9 | visibility: visible; 10 | cursor: pointer; 11 | } 12 | .no-csstransforms .deck-menu > .slide { 13 | float: left; 14 | width: 22%; 15 | height: 22%; 16 | min-height: 0; 17 | margin: 1%; 18 | font-size: 0.22em; 19 | overflow: hidden; 20 | padding: 0 0.5%; 21 | } 22 | .csstransforms .deck-menu > .slide { 23 | -webkit-transform: scale(0.22) !important; 24 | -ms-transform: scale(0.22) !important; 25 | transform: scale(0.22) !important; 26 | -webkit-transform-origin: 0 0; 27 | -ms-transform-origin: 0 0; 28 | transform-origin: 0 0; 29 | -moz-box-sizing: border-box; 30 | box-sizing: border-box; 31 | width: 100%; 32 | height: 100%; 33 | overflow: hidden; 34 | padding: 0 48px; 35 | margin: 12px; 36 | } 37 | .deck-menu iframe, .deck-menu img, .deck-menu video { 38 | max-width: 100%; 39 | } 40 | .deck-menu .deck-current, .no-touch .deck-menu .slide:hover { 41 | background: #ddf; 42 | } 43 | .deck-menu.deck-container:hover .deck-prev-link, .deck-menu.deck-container:hover .deck-next-link { 44 | display: none; 45 | } 46 | -------------------------------------------------------------------------------- /slides_sources/html_slides/deckjs/extensions/menu/deck.menu.scss: -------------------------------------------------------------------------------- 1 | .deck-menu { 2 | overflow:auto; 3 | 4 | .slide { 5 | background:#eee; 6 | position:relative; 7 | left:0; 8 | top:0; 9 | visibility:visible; 10 | cursor:pointer; 11 | } 12 | 13 | > .slide { 14 | .no-csstransforms & { 15 | float:left; 16 | width:22%; 17 | height:22%; 18 | min-height:0; 19 | margin:1%; 20 | font-size:0.22em; 21 | overflow:hidden; 22 | padding:0 0.5%; 23 | } 24 | 25 | .csstransforms & { 26 | -webkit-transform:scale(.22) !important; 27 | -ms-transform:scale(.22) !important; 28 | transform:scale(.22) !important; 29 | -webkit-transform-origin:0 0; 30 | -ms-transform-origin:0 0; 31 | transform-origin:0 0; 32 | -moz-box-sizing: border-box; 33 | box-sizing: border-box; 34 | width:100%; 35 | height:100%; 36 | overflow:hidden; 37 | padding:0 48px; 38 | margin:12px; 39 | } 40 | } 41 | 42 | iframe, img, video { 43 | max-width:100%; 44 | } 45 | 46 | .deck-current, .no-touch & .slide:hover { 47 | background:#ddf; 48 | } 49 | 50 | &.deck-container:hover { 51 | .deck-prev-link, .deck-next-link { 52 | display:none; 53 | } 54 | } 55 | } -------------------------------------------------------------------------------- /slides_sources/html_slides/deckjs/extensions/navigation/deck.navigation.css: -------------------------------------------------------------------------------- 1 | .deck-prev-link, .deck-next-link { 2 | display: none; 3 | position: absolute; 4 | z-index: 3; 5 | top: 50%; 6 | width: 32px; 7 | height: 32px; 8 | margin-top: -16px; 9 | font-size: 20px; 10 | font-weight: bold; 11 | line-height: 32px; 12 | vertical-align: middle; 13 | text-align: center; 14 | text-decoration: none; 15 | color: #fff; 16 | background: #888; 17 | border-radius: 16px; 18 | } 19 | .deck-prev-link:hover, .deck-prev-link:focus, .deck-prev-link:active, .deck-prev-link:visited, .deck-next-link:hover, .deck-next-link:focus, .deck-next-link:active, .deck-next-link:visited { 20 | color: #fff; 21 | } 22 | 23 | .deck-prev-link { 24 | left: 8px; 25 | } 26 | 27 | .deck-next-link { 28 | right: 8px; 29 | } 30 | 31 | .deck-container:hover .deck-prev-link, .deck-container:hover .deck-next-link { 32 | display: block; 33 | } 34 | .deck-container:hover .deck-prev-link.deck-nav-disabled, .touch .deck-container:hover .deck-prev-link, .deck-container:hover .deck-next-link.deck-nav-disabled, .touch .deck-container:hover .deck-next-link { 35 | display: none; 36 | } 37 | 38 | @media print { 39 | .deck-prev-link, .deck-next-link { 40 | display: none !important; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /slides_sources/html_slides/deckjs/extensions/navigation/deck.navigation.html: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 | 5 |
6 | -------------------------------------------------------------------------------- /slides_sources/html_slides/deckjs/extensions/navigation/deck.navigation.scss: -------------------------------------------------------------------------------- 1 | .deck-prev-link, .deck-next-link { 2 | display:none; 3 | position:absolute; 4 | z-index:3; 5 | top:50%; 6 | width:32px; 7 | height:32px; 8 | margin-top:-16px; 9 | font-size:20px; 10 | font-weight:bold; 11 | line-height:32px; 12 | vertical-align:middle; 13 | text-align:center; 14 | text-decoration:none; 15 | color:#fff; 16 | background:#888; 17 | border-radius:16px; 18 | 19 | &:hover, &:focus, &:active, &:visited { 20 | color:#fff; 21 | } 22 | } 23 | 24 | .deck-prev-link { 25 | left:8px; 26 | } 27 | 28 | .deck-next-link { 29 | right:8px; 30 | } 31 | 32 | .deck-container:hover .deck-prev-link, .deck-container:hover .deck-next-link { 33 | display:block; 34 | 35 | &.deck-nav-disabled, .touch & { 36 | display:none; 37 | } 38 | } 39 | 40 | @media print { 41 | .deck-prev-link, .deck-next-link { 42 | display:none !important; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /slides_sources/html_slides/deckjs/extensions/scale/deck.scale.css: -------------------------------------------------------------------------------- 1 | .csstransforms .deck-container.deck-scale:not(.deck-menu) { 2 | overflow: hidden; 3 | } 4 | .csstransforms .deck-container.deck-scale:not(.deck-menu) > .slide { 5 | -moz-box-sizing: padding-box; 6 | box-sizing: padding-box; 7 | width: 100%; 8 | padding-bottom: 20px; 9 | } 10 | .csstransforms .deck-container.deck-scale:not(.deck-menu) > .slide > .deck-slide-scaler { 11 | -webkit-transform-origin: 50% 0; 12 | -ms-transform-origin: 50% 0; 13 | transform-origin: 50% 0; 14 | } 15 | 16 | .csstransforms .deck-container.deck-menu .deck-slide-scaler { 17 | -webkit-transform: none !important; 18 | -ms-transform: none !important; 19 | transform: none !important; 20 | } 21 | -------------------------------------------------------------------------------- /slides_sources/html_slides/deckjs/extensions/scale/deck.scale.scss: -------------------------------------------------------------------------------- 1 | .csstransforms .deck-container.deck-scale:not(.deck-menu) { 2 | overflow:hidden; 3 | 4 | > .slide { 5 | -moz-box-sizing: padding-box; 6 | box-sizing: padding-box; 7 | width:100%; 8 | padding-bottom:20px; 9 | 10 | > .deck-slide-scaler { 11 | -webkit-transform-origin: 50% 0; 12 | -ms-transform-origin: 50% 0; 13 | transform-origin: 50% 0; 14 | } 15 | } 16 | } 17 | 18 | .csstransforms .deck-container.deck-menu .deck-slide-scaler { 19 | -webkit-transform:none !important; 20 | -ms-transform:none !important; 21 | transform:none !important; 22 | } -------------------------------------------------------------------------------- /slides_sources/html_slides/deckjs/extensions/status/deck.status.css: -------------------------------------------------------------------------------- 1 | .deck-status { 2 | position: absolute; 3 | bottom: 10px; 4 | right: 5px; 5 | color: #888; 6 | z-index: 3; 7 | margin: 0; 8 | } 9 | 10 | body > .deck-container .deck-status { 11 | position: fixed; 12 | } 13 | 14 | @media print { 15 | .deck-status { 16 | display: none; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /slides_sources/html_slides/deckjs/extensions/status/deck.status.html: -------------------------------------------------------------------------------- 1 | 2 |

3 | 4 | / 5 | 6 |

7 | -------------------------------------------------------------------------------- /slides_sources/html_slides/deckjs/extensions/status/deck.status.scss: -------------------------------------------------------------------------------- 1 | .deck-status { 2 | position:absolute; 3 | bottom:10px; 4 | right:5px; 5 | color:#888; 6 | z-index:3; 7 | margin:0; 8 | } 9 | 10 | body > .deck-container .deck-status { 11 | position:fixed; 12 | } 13 | 14 | @media print { 15 | .deck-status { 16 | display:none; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /slides_sources/html_slides/deckjs/test/fixtures/empty.html: -------------------------------------------------------------------------------- 1 |
2 |
3 | Previous 4 | Next 5 |
6 | 7 |

8 | 9 | / 10 | 11 |

12 | 13 |
14 | 15 | 16 | 17 |
18 | 19 | # 20 | Internal Test Link 21 |
22 | -------------------------------------------------------------------------------- /slides_sources/html_slides/deckjs/test/fixtures/nesteds.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 | 5 |
6 |
7 | 8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 | 19 |
20 |
21 | 22 |
23 |
24 | 25 |

26 | 27 | / 28 | 29 |

30 | 31 |
32 | 33 | 34 | 35 |
36 |
37 | -------------------------------------------------------------------------------- /slides_sources/html_slides/deckjs/test/settings.js: -------------------------------------------------------------------------------- 1 | // SETTINGS, VARS, UTILITY FUNCTIONS 2 | jasmine.getFixtures().fixturesPath = 'fixtures'; 3 | var defaults = $.deck.defaults; 4 | -------------------------------------------------------------------------------- /slides_sources/html_slides/images/200px-SQLite.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/slides_sources/html_slides/images/200px-SQLite.png -------------------------------------------------------------------------------- /slides_sources/html_slides/images/3vl.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/slides_sources/html_slides/images/3vl.png -------------------------------------------------------------------------------- /slides_sources/html_slides/images/6libU.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/slides_sources/html_slides/images/6libU.png -------------------------------------------------------------------------------- /slides_sources/html_slides/images/Diamond_inheritance.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/slides_sources/html_slides/images/Diamond_inheritance.png -------------------------------------------------------------------------------- /slides_sources/html_slides/images/FfBuN.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/slides_sources/html_slides/images/FfBuN.png -------------------------------------------------------------------------------- /slides_sources/html_slides/images/Greenwich_clock.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/slides_sources/html_slides/images/Greenwich_clock.jpg -------------------------------------------------------------------------------- /slides_sources/html_slides/images/OPP.0108.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/slides_sources/html_slides/images/OPP.0108.gif -------------------------------------------------------------------------------- /slides_sources/html_slides/images/big_o.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/slides_sources/html_slides/images/big_o.png -------------------------------------------------------------------------------- /slides_sources/html_slides/images/closures.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/slides_sources/html_slides/images/closures.jpg -------------------------------------------------------------------------------- /slides_sources/html_slides/images/database.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/slides_sources/html_slides/images/database.gif -------------------------------------------------------------------------------- /slides_sources/html_slides/images/flags.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/slides_sources/html_slides/images/flags.jpg -------------------------------------------------------------------------------- /slides_sources/html_slides/images/gil.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/slides_sources/html_slides/images/gil.png -------------------------------------------------------------------------------- /slides_sources/html_slides/images/image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/slides_sources/html_slides/images/image.png -------------------------------------------------------------------------------- /slides_sources/html_slides/images/killGIL.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/slides_sources/html_slides/images/killGIL.jpg -------------------------------------------------------------------------------- /slides_sources/html_slides/images/mysql_100x58.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/slides_sources/html_slides/images/mysql_100x58.gif -------------------------------------------------------------------------------- /slides_sources/html_slides/images/mysql_large.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/slides_sources/html_slides/images/mysql_large.png -------------------------------------------------------------------------------- /slides_sources/html_slides/images/pgsql_100x58.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/slides_sources/html_slides/images/pgsql_100x58.gif -------------------------------------------------------------------------------- /slides_sources/html_slides/images/pgsql_large.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/slides_sources/html_slides/images/pgsql_large.png -------------------------------------------------------------------------------- /slides_sources/html_slides/images/pycallgraph.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/slides_sources/html_slides/images/pycallgraph.png -------------------------------------------------------------------------------- /slides_sources/html_slides/images/python_comrades1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/slides_sources/html_slides/images/python_comrades1.png -------------------------------------------------------------------------------- /slides_sources/html_slides/images/runsnake.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/slides_sources/html_slides/images/runsnake.png -------------------------------------------------------------------------------- /slides_sources/html_slides/images/sql_anatomy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/slides_sources/html_slides/images/sql_anatomy.png -------------------------------------------------------------------------------- /slides_sources/html_slides/images/sql_dbs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/slides_sources/html_slides/images/sql_dbs.png -------------------------------------------------------------------------------- /slides_sources/html_slides/images/state_of_packaging.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/slides_sources/html_slides/images/state_of_packaging.jpg -------------------------------------------------------------------------------- /slides_sources/html_slides/images/x2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/slides_sources/html_slides/images/x2.png -------------------------------------------------------------------------------- /slides_sources/html_slides/pep8/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## v1.1.0 4 | 5 | - Expand `beforeInit` event to allow halting of init event. 6 | - Create alternative init signature with single options object using new `options.selectors.slides` option. 7 | - Added methods `getTopLevelSlides` and `getNestedSlides`. 8 | - Integrated hash plugin into core. 9 | - Allow for touch swiping to be axis specific or disabled. 10 | - Include ARIA attribute considerations in core and extensions. 11 | -------------------------------------------------------------------------------- /slides_sources/html_slides/pep8/MIT-license.txt: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 2011-2014 Caleb Troughton 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /slides_sources/html_slides/pep8/Makefile: -------------------------------------------------------------------------------- 1 | SASSOPTS=--scss --style expanded 2 | 3 | default: generate 4 | 5 | generate: 6 | sass --update ${SASSOPTS} . 7 | 8 | force: 9 | sass --update ${SASSOPTS} --force . 10 | 11 | watch: 12 | sass --watch ${SASSOPTS} . 13 | -------------------------------------------------------------------------------- /slides_sources/html_slides/pep8/core/deck.core.css: -------------------------------------------------------------------------------- 1 | html, body { 2 | height: 100%; 3 | padding: 0; 4 | margin: 0; 5 | } 6 | 7 | .deck-container { 8 | position: relative; 9 | min-height: 100%; 10 | margin: 0 auto; 11 | overflow: hidden; 12 | overflow-y: auto; 13 | } 14 | .js .deck-container { 15 | visibility: hidden; 16 | } 17 | .ready .deck-container { 18 | visibility: visible; 19 | } 20 | .touch .deck-container { 21 | -webkit-text-size-adjust: none; 22 | -moz-text-size-adjust: none; 23 | } 24 | 25 | .deck-loading { 26 | display: none; 27 | } 28 | 29 | .slide { 30 | width: auto; 31 | min-height: 100%; 32 | position: relative; 33 | } 34 | 35 | .deck-before, .deck-previous, .deck-next, .deck-after { 36 | position: absolute; 37 | left: -999em; 38 | top: -999em; 39 | } 40 | 41 | .deck-current { 42 | z-index: 2; 43 | } 44 | 45 | .slide .slide { 46 | visibility: hidden; 47 | position: static; 48 | min-height: 0; 49 | } 50 | 51 | .deck-child-current { 52 | position: static; 53 | z-index: 2; 54 | } 55 | .deck-child-current .slide { 56 | visibility: hidden; 57 | } 58 | .deck-child-current .deck-previous, .deck-child-current .deck-before, .deck-child-current .deck-current { 59 | visibility: visible; 60 | } 61 | -------------------------------------------------------------------------------- /slides_sources/html_slides/pep8/core/deck.core.scss: -------------------------------------------------------------------------------- 1 | html, body { 2 | height:100%; 3 | padding:0; 4 | margin:0; 5 | } 6 | 7 | .deck-container { 8 | position:relative; 9 | min-height:100%; 10 | margin:0 auto; 11 | overflow:hidden; 12 | overflow-y:auto; 13 | 14 | .js & { 15 | visibility:hidden; 16 | } 17 | 18 | .ready & { 19 | visibility:visible; 20 | } 21 | 22 | .touch & { 23 | -webkit-text-size-adjust:none; 24 | -moz-text-size-adjust:none; 25 | } 26 | } 27 | 28 | .deck-loading { 29 | display:none; 30 | } 31 | 32 | .slide { 33 | width:auto; 34 | min-height:100%; 35 | position:relative; 36 | } 37 | 38 | .deck-before, .deck-previous, .deck-next, .deck-after { 39 | position:absolute; 40 | left:-999em; 41 | top:-999em; 42 | } 43 | 44 | .deck-current { 45 | z-index:2; 46 | } 47 | 48 | .slide .slide { 49 | visibility:hidden; 50 | position:static; 51 | min-height:0; 52 | } 53 | 54 | .deck-child-current { 55 | position:static; 56 | z-index:2; 57 | 58 | .slide { 59 | visibility:hidden; 60 | } 61 | 62 | .deck-previous, .deck-before, .deck-current { 63 | visibility:visible; 64 | } 65 | } -------------------------------------------------------------------------------- /slides_sources/html_slides/pep8/core/print.css: -------------------------------------------------------------------------------- 1 | body { 2 | font-size: 18pt; 3 | } 4 | 5 | h1 { 6 | font-size: 48pt; 7 | } 8 | 9 | h2 { 10 | font-size: 36pt; 11 | } 12 | 13 | h3 { 14 | font-size: 28pt; 15 | } 16 | 17 | pre { 18 | border: 1px solid #000; 19 | padding: 10px; 20 | white-space: pre-wrap; 21 | } 22 | 23 | .deck-container > .slide { 24 | page-break-after: always; 25 | } 26 | -------------------------------------------------------------------------------- /slides_sources/html_slides/pep8/core/print.scss: -------------------------------------------------------------------------------- 1 | body { font-size:18pt; } 2 | h1 { font-size:48pt; } 3 | h2 { font-size:36pt; } 4 | h3 { font-size:28pt; } 5 | 6 | pre { 7 | border:1px solid #000; 8 | padding:10px; 9 | white-space:pre-wrap; 10 | } 11 | 12 | .deck-container > .slide { 13 | page-break-after: always; 14 | } 15 | -------------------------------------------------------------------------------- /slides_sources/html_slides/pep8/extensions/goto/deck.goto.css: -------------------------------------------------------------------------------- 1 | .goto-form { 2 | position: absolute; 3 | z-index: 3; 4 | bottom: 10px; 5 | left: 50%; 6 | height: 1.75em; 7 | margin: 0 0 0 -9.125em; 8 | line-height: 1.75em; 9 | padding: 0.625em; 10 | display: none; 11 | background: #ccc; 12 | overflow: hidden; 13 | border-radius: 10px; 14 | } 15 | .goto-form label { 16 | font-weight: bold; 17 | } 18 | .goto-form label, .goto-form input { 19 | display: inline-block; 20 | font-family: inherit; 21 | } 22 | .deck-goto .goto-form { 23 | display: block; 24 | } 25 | 26 | #goto-slide { 27 | width: 8.375em; 28 | margin: 0 0.625em; 29 | height: 1.4375em; 30 | } 31 | 32 | @media print { 33 | .goto-form, #goto-slide { 34 | display: none; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /slides_sources/html_slides/pep8/extensions/goto/deck.goto.html: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 | 5 | 6 | 7 |
-------------------------------------------------------------------------------- /slides_sources/html_slides/pep8/extensions/goto/deck.goto.scss: -------------------------------------------------------------------------------- 1 | .goto-form { 2 | position:absolute; 3 | z-index:3; 4 | bottom:10px; 5 | left:50%; 6 | height:1.75em; 7 | margin:0 0 0 -9.125em; 8 | line-height:1.75em; 9 | padding:0.625em; 10 | display:none; 11 | background:#ccc; 12 | overflow:hidden; 13 | border-radius:10px; 14 | 15 | label { 16 | font-weight:bold; 17 | } 18 | 19 | label, input { 20 | display:inline-block; 21 | font-family:inherit; 22 | } 23 | 24 | .deck-goto & { 25 | display:block; 26 | } 27 | } 28 | 29 | #goto-slide { 30 | width:8.375em; 31 | margin:0 0.625em; 32 | height:1.4375em; 33 | } 34 | 35 | @media print { 36 | .goto-form, #goto-slide { 37 | display:none; 38 | } 39 | } -------------------------------------------------------------------------------- /slides_sources/html_slides/pep8/extensions/menu/deck.menu.css: -------------------------------------------------------------------------------- 1 | .deck-menu { 2 | overflow: auto; 3 | } 4 | .deck-menu .slide { 5 | background: #eee; 6 | position: relative; 7 | left: 0; 8 | top: 0; 9 | visibility: visible; 10 | cursor: pointer; 11 | } 12 | .no-csstransforms .deck-menu > .slide { 13 | float: left; 14 | width: 22%; 15 | height: 22%; 16 | min-height: 0; 17 | margin: 1%; 18 | font-size: 0.22em; 19 | overflow: hidden; 20 | padding: 0 0.5%; 21 | } 22 | .csstransforms .deck-menu > .slide { 23 | -webkit-transform: scale(0.22) !important; 24 | -ms-transform: scale(0.22) !important; 25 | transform: scale(0.22) !important; 26 | -webkit-transform-origin: 0 0; 27 | -ms-transform-origin: 0 0; 28 | transform-origin: 0 0; 29 | -moz-box-sizing: border-box; 30 | box-sizing: border-box; 31 | width: 100%; 32 | height: 100%; 33 | overflow: hidden; 34 | padding: 0 48px; 35 | margin: 12px; 36 | } 37 | .deck-menu iframe, .deck-menu img, .deck-menu video { 38 | max-width: 100%; 39 | } 40 | .deck-menu .deck-current, .no-touch .deck-menu .slide:hover { 41 | background: #ddf; 42 | } 43 | .deck-menu.deck-container:hover .deck-prev-link, .deck-menu.deck-container:hover .deck-next-link { 44 | display: none; 45 | } 46 | -------------------------------------------------------------------------------- /slides_sources/html_slides/pep8/extensions/menu/deck.menu.scss: -------------------------------------------------------------------------------- 1 | .deck-menu { 2 | overflow:auto; 3 | 4 | .slide { 5 | background:#eee; 6 | position:relative; 7 | left:0; 8 | top:0; 9 | visibility:visible; 10 | cursor:pointer; 11 | } 12 | 13 | > .slide { 14 | .no-csstransforms & { 15 | float:left; 16 | width:22%; 17 | height:22%; 18 | min-height:0; 19 | margin:1%; 20 | font-size:0.22em; 21 | overflow:hidden; 22 | padding:0 0.5%; 23 | } 24 | 25 | .csstransforms & { 26 | -webkit-transform:scale(.22) !important; 27 | -ms-transform:scale(.22) !important; 28 | transform:scale(.22) !important; 29 | -webkit-transform-origin:0 0; 30 | -ms-transform-origin:0 0; 31 | transform-origin:0 0; 32 | -moz-box-sizing: border-box; 33 | box-sizing: border-box; 34 | width:100%; 35 | height:100%; 36 | overflow:hidden; 37 | padding:0 48px; 38 | margin:12px; 39 | } 40 | } 41 | 42 | iframe, img, video { 43 | max-width:100%; 44 | } 45 | 46 | .deck-current, .no-touch & .slide:hover { 47 | background:#ddf; 48 | } 49 | 50 | &.deck-container:hover { 51 | .deck-prev-link, .deck-next-link { 52 | display:none; 53 | } 54 | } 55 | } -------------------------------------------------------------------------------- /slides_sources/html_slides/pep8/extensions/navigation/deck.navigation.css: -------------------------------------------------------------------------------- 1 | .deck-prev-link, .deck-next-link { 2 | display: none; 3 | position: absolute; 4 | z-index: 3; 5 | top: 50%; 6 | width: 32px; 7 | height: 32px; 8 | margin-top: -16px; 9 | font-size: 20px; 10 | font-weight: bold; 11 | line-height: 32px; 12 | vertical-align: middle; 13 | text-align: center; 14 | text-decoration: none; 15 | color: #fff; 16 | background: #888; 17 | border-radius: 16px; 18 | } 19 | .deck-prev-link:hover, .deck-prev-link:focus, .deck-prev-link:active, .deck-prev-link:visited, .deck-next-link:hover, .deck-next-link:focus, .deck-next-link:active, .deck-next-link:visited { 20 | color: #fff; 21 | } 22 | 23 | .deck-prev-link { 24 | left: 8px; 25 | } 26 | 27 | .deck-next-link { 28 | right: 8px; 29 | } 30 | 31 | .deck-container:hover .deck-prev-link, .deck-container:hover .deck-next-link { 32 | display: block; 33 | } 34 | .deck-container:hover .deck-prev-link.deck-nav-disabled, .touch .deck-container:hover .deck-prev-link, .deck-container:hover .deck-next-link.deck-nav-disabled, .touch .deck-container:hover .deck-next-link { 35 | display: none; 36 | } 37 | 38 | @media print { 39 | .deck-prev-link, .deck-next-link { 40 | display: none !important; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /slides_sources/html_slides/pep8/extensions/navigation/deck.navigation.html: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 | 5 |
6 | -------------------------------------------------------------------------------- /slides_sources/html_slides/pep8/extensions/navigation/deck.navigation.scss: -------------------------------------------------------------------------------- 1 | .deck-prev-link, .deck-next-link { 2 | display:none; 3 | position:absolute; 4 | z-index:3; 5 | top:50%; 6 | width:32px; 7 | height:32px; 8 | margin-top:-16px; 9 | font-size:20px; 10 | font-weight:bold; 11 | line-height:32px; 12 | vertical-align:middle; 13 | text-align:center; 14 | text-decoration:none; 15 | color:#fff; 16 | background:#888; 17 | border-radius:16px; 18 | 19 | &:hover, &:focus, &:active, &:visited { 20 | color:#fff; 21 | } 22 | } 23 | 24 | .deck-prev-link { 25 | left:8px; 26 | } 27 | 28 | .deck-next-link { 29 | right:8px; 30 | } 31 | 32 | .deck-container:hover .deck-prev-link, .deck-container:hover .deck-next-link { 33 | display:block; 34 | 35 | &.deck-nav-disabled, .touch & { 36 | display:none; 37 | } 38 | } 39 | 40 | @media print { 41 | .deck-prev-link, .deck-next-link { 42 | display:none !important; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /slides_sources/html_slides/pep8/extensions/scale/deck.scale.css: -------------------------------------------------------------------------------- 1 | .csstransforms .deck-container.deck-scale:not(.deck-menu) { 2 | overflow: hidden; 3 | } 4 | .csstransforms .deck-container.deck-scale:not(.deck-menu) > .slide { 5 | -moz-box-sizing: padding-box; 6 | box-sizing: padding-box; 7 | width: 100%; 8 | padding-bottom: 20px; 9 | } 10 | .csstransforms .deck-container.deck-scale:not(.deck-menu) > .slide > .deck-slide-scaler { 11 | -webkit-transform-origin: 50% 0; 12 | -ms-transform-origin: 50% 0; 13 | transform-origin: 50% 0; 14 | } 15 | 16 | .csstransforms .deck-container.deck-menu .deck-slide-scaler { 17 | -webkit-transform: none !important; 18 | -ms-transform: none !important; 19 | transform: none !important; 20 | } 21 | -------------------------------------------------------------------------------- /slides_sources/html_slides/pep8/extensions/scale/deck.scale.scss: -------------------------------------------------------------------------------- 1 | .csstransforms .deck-container.deck-scale:not(.deck-menu) { 2 | overflow:hidden; 3 | 4 | > .slide { 5 | -moz-box-sizing: padding-box; 6 | box-sizing: padding-box; 7 | width:100%; 8 | padding-bottom:20px; 9 | 10 | > .deck-slide-scaler { 11 | -webkit-transform-origin: 50% 0; 12 | -ms-transform-origin: 50% 0; 13 | transform-origin: 50% 0; 14 | } 15 | } 16 | } 17 | 18 | .csstransforms .deck-container.deck-menu .deck-slide-scaler { 19 | -webkit-transform:none !important; 20 | -ms-transform:none !important; 21 | transform:none !important; 22 | } -------------------------------------------------------------------------------- /slides_sources/html_slides/pep8/extensions/status/deck.status.css: -------------------------------------------------------------------------------- 1 | .deck-status { 2 | position: absolute; 3 | bottom: 10px; 4 | right: 5px; 5 | color: #888; 6 | z-index: 3; 7 | margin: 0; 8 | } 9 | 10 | body > .deck-container .deck-status { 11 | position: fixed; 12 | } 13 | 14 | @media print { 15 | .deck-status { 16 | display: none; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /slides_sources/html_slides/pep8/extensions/status/deck.status.html: -------------------------------------------------------------------------------- 1 | 2 |

3 | 4 | / 5 | 6 |

7 | -------------------------------------------------------------------------------- /slides_sources/html_slides/pep8/extensions/status/deck.status.scss: -------------------------------------------------------------------------------- 1 | .deck-status { 2 | position:absolute; 3 | bottom:10px; 4 | right:5px; 5 | color:#888; 6 | z-index:3; 7 | margin:0; 8 | } 9 | 10 | body > .deck-container .deck-status { 11 | position:fixed; 12 | } 13 | 14 | @media print { 15 | .deck-status { 16 | display:none; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /slides_sources/html_slides/pep8/test/fixtures/empty.html: -------------------------------------------------------------------------------- 1 |
2 |
3 | Previous 4 | Next 5 |
6 | 7 |

8 | 9 | / 10 | 11 |

12 | 13 |
14 | 15 | 16 | 17 |
18 | 19 | # 20 | Internal Test Link 21 |
22 | -------------------------------------------------------------------------------- /slides_sources/html_slides/pep8/test/fixtures/nesteds.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 | 5 |
6 |
7 | 8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 | 19 |
20 |
21 | 22 |
23 |
24 | 25 |

26 | 27 | / 28 | 29 |

30 | 31 |
32 | 33 | 34 | 35 |
36 |
37 | -------------------------------------------------------------------------------- /slides_sources/html_slides/pep8/test/settings.js: -------------------------------------------------------------------------------- 1 | // SETTINGS, VARS, UTILITY FUNCTIONS 2 | jasmine.getFixtures().fixturesPath = 'fixtures'; 3 | var defaults = $.deck.defaults; 4 | -------------------------------------------------------------------------------- /slides_sources/requirements.txt: -------------------------------------------------------------------------------- 1 | Jinja2 2 | MarkupSafe 3 | Pygments 4 | Sphinx 5 | docutils 6 | sphinx-rtd-theme 7 | gnureadline 8 | hieroglyph 9 | libsass 10 | -------------------------------------------------------------------------------- /slides_sources/source/_static/Diamond_inheritance.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/slides_sources/source/_static/Diamond_inheritance.png -------------------------------------------------------------------------------- /slides_sources/source/_static/Greenwich_clock.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/slides_sources/source/_static/Greenwich_clock.jpg -------------------------------------------------------------------------------- /slides_sources/source/_static/color_git_prompt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/slides_sources/source/_static/color_git_prompt.png -------------------------------------------------------------------------------- /slides_sources/source/_static/dst_fb_graph.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/slides_sources/source/_static/dst_fb_graph.png -------------------------------------------------------------------------------- /slides_sources/source/_static/dst_sf_graph.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/slides_sources/source/_static/dst_sf_graph.png -------------------------------------------------------------------------------- /slides_sources/source/_static/flake8_output.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/slides_sources/source/_static/flake8_output.png -------------------------------------------------------------------------------- /slides_sources/source/_static/git_another_commit_on_branch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/slides_sources/source/_static/git_another_commit_on_branch.png -------------------------------------------------------------------------------- /slides_sources/source/_static/git_checkout_branch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/slides_sources/source/_static/git_checkout_branch.png -------------------------------------------------------------------------------- /slides_sources/source/_static/git_checkout_master.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/slides_sources/source/_static/git_checkout_master.png -------------------------------------------------------------------------------- /slides_sources/source/_static/git_commit_on_branch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/slides_sources/source/_static/git_commit_on_branch.png -------------------------------------------------------------------------------- /slides_sources/source/_static/git_head.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/slides_sources/source/_static/git_head.png -------------------------------------------------------------------------------- /slides_sources/source/_static/git_master_branch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/slides_sources/source/_static/git_master_branch.png -------------------------------------------------------------------------------- /slides_sources/source/_static/git_merge_commit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/slides_sources/source/_static/git_merge_commit.png -------------------------------------------------------------------------------- /slides_sources/source/_static/git_new_branch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/slides_sources/source/_static/git_new_branch.png -------------------------------------------------------------------------------- /slides_sources/source/_static/git_new_commit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/slides_sources/source/_static/git_new_commit.png -------------------------------------------------------------------------------- /slides_sources/source/_static/git_new_commit_on_master.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/slides_sources/source/_static/git_new_commit_on_master.png -------------------------------------------------------------------------------- /slides_sources/source/_static/git_simple_timeline.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/slides_sources/source/_static/git_simple_timeline.png -------------------------------------------------------------------------------- /slides_sources/source/_static/pc_menu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/slides_sources/source/_static/pc_menu.png -------------------------------------------------------------------------------- /slides_sources/source/_static/plugin_list.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/slides_sources/source/_static/plugin_list.png -------------------------------------------------------------------------------- /slides_sources/source/_static/program_callstack.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/slides_sources/source/_static/program_callstack.png -------------------------------------------------------------------------------- /slides_sources/source/_static/python.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/slides_sources/source/_static/python.png -------------------------------------------------------------------------------- /slides_sources/source/_static/remotes_clone.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/slides_sources/source/_static/remotes_clone.png -------------------------------------------------------------------------------- /slides_sources/source/_static/remotes_fork.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/slides_sources/source/_static/remotes_fork.png -------------------------------------------------------------------------------- /slides_sources/source/_static/remotes_start.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/slides_sources/source/_static/remotes_start.png -------------------------------------------------------------------------------- /slides_sources/source/_static/remotes_upstream.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/slides_sources/source/_static/remotes_upstream.png -------------------------------------------------------------------------------- /slides_sources/source/_static/simple_prompt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/slides_sources/source/_static/simple_prompt.png -------------------------------------------------------------------------------- /slides_sources/source/_static/tab_completion.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/slides_sources/source/_static/tab_completion.png -------------------------------------------------------------------------------- /slides_sources/source/_static/test_v_model.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/slides_sources/source/_static/test_v_model.png -------------------------------------------------------------------------------- /slides_sources/source/_static/transmogrifier.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/slides_sources/source/_static/transmogrifier.jpg -------------------------------------------------------------------------------- /slides_sources/source/_static/two_line_prompt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/slides_sources/source/_static/two_line_prompt.png -------------------------------------------------------------------------------- /slides_sources/source/_static/virtualenv_prompt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/slides_sources/source/_static/virtualenv_prompt.png -------------------------------------------------------------------------------- /slides_sources/source/_templates/end_slide.html: -------------------------------------------------------------------------------- 1 | 2 |
3 |

Thank You!

4 |
5 |

6 | 7 |

8 |
9 | -------------------------------------------------------------------------------- /slides_sources/source/_templates/title_slide.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 |

5 |

6 |

7 |
8 |
9 | -------------------------------------------------------------------------------- /slides_sources/source/homework/index.rst: -------------------------------------------------------------------------------- 1 | Homework Materials 2 | ====================== 3 | 4 | There may be some stuff here for homework 5 | 6 | -------------------------------------------------------------------------------- /slides_sources/source/images/OPP.0108.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/slides_sources/source/images/OPP.0108.gif -------------------------------------------------------------------------------- /slides_sources/source/images/big_o.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/slides_sources/source/images/big_o.png -------------------------------------------------------------------------------- /slides_sources/source/images/flags.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/slides_sources/source/images/flags.jpg -------------------------------------------------------------------------------- /slides_sources/source/images/gil.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/slides_sources/source/images/gil.png -------------------------------------------------------------------------------- /slides_sources/source/images/killGIL.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/slides_sources/source/images/killGIL.jpg -------------------------------------------------------------------------------- /slides_sources/source/images/pycallgraph.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/slides_sources/source/images/pycallgraph.png -------------------------------------------------------------------------------- /slides_sources/source/images/snakeviz.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/slides_sources/source/images/snakeviz.png -------------------------------------------------------------------------------- /slides_sources/source/images/x2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/slides_sources/source/images/x2.png -------------------------------------------------------------------------------- /slides_sources/source/notes/Installing_wxPython_demo.rst: -------------------------------------------------------------------------------- 1 | .. _installing_wxpython_demo: 2 | 3 | ======================== 4 | Installing WXPython Demo 5 | ======================== 6 | 7 | We are going to download the source for the whole project from the github page, and then extract the demo part. 8 | 9 | https://github.com/wxWidgets/Phoenix 10 | 11 | You can use git copy to download the repository: 12 | 13 | git clone https://github.com/wxWidgets/Phoenix.git 14 | 15 | Once it is downlaoded, cd into the Phoenix directory. One of the subdirectories is called demo. Move this entire directory to somewhere useful. Here is the command I used: 16 | 17 | :: 18 | 19 | mv demo ~/python_examples/wxpython_demo 20 | 21 | This moves the directory into a better place and gives it a better name. Now you can delete the rest of the Phoenix directory, as you don't need it. 22 | 23 | Useful links: 24 | 25 | blog post about the demo: 26 | 27 | http://www.blog.pythonlibrary.org/2010/10/15/the-wxpython-demo/ 28 | 29 | blog post about converting demo code to production code: 30 | 31 | http://wiki.wxpython.org/Using%20wxPython%20Demo%20Code 32 | -------------------------------------------------------------------------------- /slides_sources/source/resources/ICanEatGlass.utf16.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/slides_sources/source/resources/ICanEatGlass.utf16.txt -------------------------------------------------------------------------------- /slides_sources/source/resources/ICanEatGlass.utf8.txt: -------------------------------------------------------------------------------- 1 | I Can Eat Glass: 2 | 3 | And from the sublime to the ridiculous, here is a certain phrase in an assortment of languages: 4 | 5 | Sanskrit: काचं शक्नोम्यत्तुम् । नोपहिनस्ति माम् ॥ 6 | 7 | Sanskrit (standard transcription): kācaṃ śaknomyattum; nopahinasti mām. 8 | 9 | Classical Greek: ὕαλον ϕαγεῖν δύναμαι· τοῦτο οὔ με βλάπτει. 10 | 11 | Greek (monotonic): Μπορώ να φάω σπασμένα γυαλιά χωρίς να πάθω τίποτα. 12 | 13 | Greek (polytonic): Μπορῶ νὰ φάω σπασμένα γυαλιὰ χωρὶς νὰ πάθω τίποτα. 14 | 15 | Latin: Vitrum edere possum; mihi non nocet. 16 | 17 | Old French: Je puis mangier del voirre. Ne me nuit. 18 | 19 | French: Je peux manger du verre, ça ne me fait pas mal. 20 | 21 | Provençal / Occitan: Pòdi manjar de veire, me nafrariá pas. 22 | 23 | Québécois: J'peux manger d'la vitre, ça m'fa pas mal. -------------------------------------------------------------------------------- /slides_sources/source/resources/exception_test.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | """ 4 | example for what happens when you pass non-ascii unicode to a Exception 5 | """ 6 | 7 | msg = u'This is an ASCII-compatible unicode message' 8 | 9 | #msg = u'This is an non ASCII\N{EM DASH}compatible unicode message' 10 | 11 | print "\nDo you see this message in the Exception report?\n" 12 | print msg 13 | print 14 | 15 | raise ValueError(msg) 16 | 17 | -------------------------------------------------------------------------------- /slides_sources/source/resources/hello_unicode.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | hello = 'Hello ' 5 | world = u'世界' 6 | 7 | print hello + world 8 | 9 | print u"It was nice weather today: it reached 80\u00B0" 10 | 11 | print u"Maybe it will reach 90\N{degree sign}" 12 | 13 | print u"It is extremely rare for it ever to reach 100° in Seattle" 14 | -------------------------------------------------------------------------------- /slides_sources/source/resources/text.utf16: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/slides_sources/source/resources/text.utf16 -------------------------------------------------------------------------------- /slides_sources/source/resources/text.utf32: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UWPCE-PythonCert/SystemDevelopment/f0043ca0a1a9cc8270812bb036ede59609b32ca9/slides_sources/source/resources/text.utf32 -------------------------------------------------------------------------------- /slides_sources/source/resources/text.utf8: -------------------------------------------------------------------------------- 1 | Origin (in native language) Name (in native language) 2 | Հայաստան Արամ Խաչատրյան 3 | Australia Nicole Kidman 4 | Österreich Johann Strauß 5 | Azərbaycan Vaqif Səmədoğlu 6 | Азәрбајҹан Вагиф Сәмәдоғлу 7 | Azərbaycan Heydər Əliyev 8 | Азәрбајҹан Һејдәр Әлијев 9 | België René Magritte 10 | Belgique René Magritte 11 | Belgien René Magritte 12 | বাংলা সুকুমার রায় 13 | འབྲུག་ཡུལ། མགོན་པོ་རྡོ་རྗེ། 14 | ប្រទេស​​​កម្ពុជា ព្រះ​ពុទ្ឋឃោសាចារ‌្យ​ជួន​ណាត 15 | Canada Céline Dion 16 | ᓄᓇᕗᒻᒥᐅᑦ ᓱᓴᓐ ᐊᒡᓗᒃᑲᖅ 17 | --------------------------------------------------------------------------------