uw package

Subpackages

Submodules

uw.color module

Color-manipulating utility routines.

Convenient functions for converting between RGB and HSV color spaces, formatting colors for use in HTML/CSS, and generating a series of (relatively) contrasting hues.

uw.color.hsv2rgb(hsv)[source]

Convert HSV color to RGB.

Parameters:hsv – a 3-tuple containing the H, S, and V values.
Returns:the RGB representation of the color as a 3-tuple.
uw.color.html_row(i, hsv)[source]

Create a table row to demonstrate a hue.

Parameters:
  • i (int) – the number of the row within the table, for inclusion in the first column.
  • hsv – the color to demonstrate.
Returns:

an HTML <tr> element showing the color, as well as related colors with 70% and 40% of the saturation of the given color.

For use by html_sample().

uw.color.html_sample(n)[source]

Create a sample HTML page showing hues generated by hues().

Parameters:n (int) – the number of hues to generate.
Returns:an HTML document containing a table with one row per hue.
uw.color.hues(start=0)[source]

Generate a sequence of hues intended to be contrasting.

Parameters:start – the starting point in the sequence of colors.
Returns:a generator which returns successive hue values.

The hues start out with red (assuming the default start value is used) and rotate around the spectrum spaced out so that the set of hues returned up to any point is evenly distributed according to hue values. No attempt is made to optimize the distribution for human color perception, i.e., filling in some parts of the spectrum more or less densely to improve the human-visible contrast.

uw.color.rgb2hsv(rgb)[source]

Convert RGB color to HSV.

Parameters:rgb – a 3-tuple containing the R, G, and B values.
Returns:the HSV representation of the color as a 3-tuple.
uw.color.rgb2html(rgb)[source]

Write an RGB color in HTML representation.

Parameters:rgb – a 3-tuple containing the R, G, and B values.
Returns:HTML/CSS attribute value representing the color.

uw.emailutils module

Email-related utilities.

Contains a class that provides a simple extension of some Python standard email.utils routines.

class uw.emailutils.emailaddr[source]

Bases: tuple

Simple class to represent an email address.

Parameters:
  • realname – the realname to be displayed with the email address, or empty for no real name.
  • email – the email address itself.

Instances are always 2-tuples. The two elements are the realname and address. This mostly just wraps procedures in email.utils.

email

The email address itself.

static parse(fieldvalues)[source]

Parse email addresses using email.utils.getaddresses().

static parse1(address)[source]

Parse a single email address using email.utils.parseaddr().

realname

The realname associated with the email address.

valid

Perform a simple check for validity.

Runs this address through email.utils.getaddresses() and verifies that the result is a single address whose address component contains an ‘@’.

uw.stringtools module

String-handling utilities.

Contains a procedure to facilitate multiple string substitutions, and a slight enhancement of the Python-standard str.strip().

uw.stringtools.multiReplace(changes)[source]

Create a procedure to perform multiple string substitutions.

Parameters:changes (dict) – dictionary of substitutions; keys will be replaced by values.

The returned procedure expects a string and returns a string. The result string consists of the input string with the specified substitutions performed.

The changes are a dictionary of find/replace values. The “find” values (dictionary keys) are simultaneously found and each occurrence is replaced by the corresponding “replace” value (dictionary value).

Works by constructing a regular expression corresponding to the alternation of the keys of the dictionary. In the event that “find” strings overlap, behaviour is determined by the re library.

A special case allows for correct handling of the “empty dictionary” case of no replacements.

uw.stringtools.strip_string(s)[source]

Trim whitespace off a string, and recognize empty strings.

Parameters:s (str) – the string to strip.

This is intended for processing text form fields. It strips whitespace off the ends of the string; if an empty string is all that remains, None is returned. None is also returned if s is None.

Module contents

Top-level package for UW-written Python code.

This is the top-level package for locally-written Python code.

Code that is actually specific to UW applications belongs in uw.local, while code that could be useful outside of UW and is designed without local assumptions goes outside of uw.local.