uw.local package

Subpackages

Submodules

uw.local.config module

Simple password configuration.

This module provides a ConfigParser for ~/.odyssey_pw in order to allow storing non-Postgres credentials outside of program code.

uw.local.config.read_config()[source]

uw.local.dbtools module

class uw.local.dbtools.Cursor(connection, cursor)[source]

Bases: uw.sql.wrap.Cursor

person_by_userid(**parameters)
term_by_code(**parameters)
unit_by_code(**parameters)
uw.local.dbtools.person_delegate(dir_handler, arc_handler)[source]
uw.local.dbtools.person_from_arc(arc, cursor, **params)[source]
uw.local.dbtools.term_delegate(dir_handler, arc_handler)[source]
uw.local.dbtools.term_from_arc(arc, cursor, **params)[source]
uw.local.dbtools.unit_delegate(dir_handler, arc_handler)[source]
uw.local.dbtools.unit_from_arc(arc, cursor, **params)[source]

uw.local.debug module

Debug utilities.

Functions which may be useful for debugging.

uw.local.debug.stopwatch(msg)[source]

Create a decorator which may be used to time execution of a function.

Parameters

msg (str) – A message to print out when the wrapped function is timed.

Returns

A decorator which times the function to which it is applied and prints the time along with the specified message.

uw.local.debug.sw(msg, f)[source]

Call a function and time its execution.

Parameters
  • msg (str) – A message to print out when the wrapped function is timed.

  • f – The function to time. This must expect no parameters. Providing a no-parameter lambda expression is likely to be useful.

Returns

The result of calling the wrapped function.

uw.local.termtools module

class uw.local.termtools.Term(sequence)[source]

Bases: object

Class representing UW terms.

Terms can be converted to and from term codes, written as text strings or as integers. Methods are available to print useful representations of terms and perform arithmetic on them.

abbreviation()[source]
code()[source]
countFrom(by=1)[source]
description()[source]
month()[source]
nextTerm()[source]
nextYear()[source]
numericCode()[source]
oldCode()[source]
prevTerm()[source]
prevYear()[source]
render_date_selector(name, current=None)[source]
render_time_selector(name, start, hours, current=None)[source]
seasonInitial()[source]
seasonName()[source]
startDate()[source]
year()[source]
uw.local.termtools.current()[source]
uw.local.termtools.fromCode(code)[source]
uw.local.termtools.fromDate(date)[source]
uw.local.termtools.fromOldCode(code)[source]

Convert an old term code into a term object.

Years from 50-99 are assuming to be in the 1900s while 00-49 are 2000s. This allows all old term codes from just before the founding of the University up to Fall 2049 to be processed correctly. If we’re still using the old codes for anything in Fall 2049 then I’m not responsible for the consequences.

uw.local.termtools.make(year, month)[source]
uw.local.termtools.render_term_select(name, terms, term=None, blank=False, class_=None)[source]

uw.local.termtools_test module

class uw.local.termtools_test.TermtoolsTests(methodName='runTest')[source]

Bases: unittest.case.TestCase

setUp()[source]

Setup method which runs before each test case.

test_abbreviation()[source]

Tests if the abbreviation () method works as expected.

test_code()[source]

Tests if the code () method works as expected.

test_description()[source]

Tests if the description () method works as expected.

test_from_code()[source]

Tests if the from_code () function works as expected.

test_from_date()[source]

Tests if the from_date () function works as expected.

test_make_returns_correct_term()[source]

Tests if the make () function works when given a valid input.

test_make_throws_value_error()[source]

Tests if the make () function throws an error when given an invalid input.

test_month()[source]

Tests if the month () method works as expected.

test_next_term()[source]

Tests if the next_term () method works as expected.

test_next_year()[source]

Tests if the next_year () method works as expected.

test_numeric_code()[source]

Tests if the numeric () method works as expected.

test_prev_term()[source]

Tests if the prev_term () method works as expected.

test_season_initial()[source]

Tests if the seasonInitial () method works as expected.

test_season_name()[source]

Tests if the seasonName () method works as expected.

test_start_date()[source]

Tests if the start_date () method works as expected.

test_year()[source]

Tests if the year () method works as expected.

uw.local.webtools module

uw.local.webtools.test_template(title, page, environ, header_insert=None)[source]
uw.local.webtools.web_main(Cursor, wsgifunc, template=<function test_template>, header_insert=None)[source]
uw.local.webtools.wsgi_application(Cursor, wsgifunc, demo_mode=False, template=<function test_template>, header_insert=None)[source]
uw.local.webtools.wsgimain(wsgifunc, db=None, connection_pool=None, server_address=None, template=<function test_template>, header_insert=None)[source]

Standard WSGI main function.

Each application is started by invoking this routine with the proper wsgifunc which is responsible for handling web requests.

The db parameter should be an instance of uw.local.dbtools.Database. If provided the given wsgifunc will be wrapped with the sql_db and sql_transaction handlers.

The provided wsgifunc will be wrapped in the following order, from innermost (first) to outermost (last):

  • Demo handler, if environment variable DEMO_MODE is set to ‘yes’

  • Standard wrappers, as per wsgiwrap()

  • SQL access wrappers, if db parameter is specified

The SQL access is outermost so that exceptions used within the other handlers to return valid results (e.g., 302 HTTP Found results) do not interfere with the SQL wrappers’ handling of transactions.

uw.local.webtools.wsgiwrap(handler, demo_mode=False, connection_pool=None, template=<function test_template>, header_insert=None)[source]

Standard WSGI wrapper.

This introduces the CLF template and error handling.

Note that the CLF is wrapped after the error handler. If this order is reversed, it actually still works because the same environ is passed down and the template variable is added to it. If a modified copy of the environment were passed down (i.e., proper functional style) then the other would not work.

Module contents

UW-local modules.

This package contains all code specific to UW applications. Code in here is likely not useful out of the context of each individual application.