Utilities

util - project utilities

console - Interactive REPL / web console

class pybald.util.console.Console(project_name, package_name=None, app=None, additional_symbols=None)

Pybald console including history buffer per project.

init_history(histfile)
run()

Start the console with the project, controllers, and models defined in the console’s namespace.

save_history(histfile)
pybald.util.console.start_console(app, options=None)

Start a console with a particular app.

Parameters:
  • app – wsgi application passed in
  • options – an object or named tuple containing the options for the web server such as host and port. Generally an argparser object is passed in for command line invokation

A pybald application must be configured before starting a console.

static_serve - Simple debugging static server

class pybald.util.static_serve.StaticServer(application, path, browser_caching=False)

A very simple static asset server. Do not use in production, just for test or development use.

StaticServer is a WSGI application that can be included in the WSGI pipeline to intercept static requests (and perform file system lookups). If the file lookup fails, the pipeline is allowed to continue to any dynamic components.

Parameters:
  • application – is the remaining WSGI pipeline to connect to.
  • path – is directory where static files are stored
  • browser_caching – whether to send 30d expires future headers
send_file(file_path, size)

Read a file from the filesystem and yield 64k chunks of the file as a generator / iterable.

text - text processing helper functions

pybald.util.text.camel_to_underscore(text)

Convert CamelCase text into underscore_separated text.

pybald.util.text.ordinal_suffix(num)

Returns the ordinal suffix of an interger (1st, 2nd, 3rd).

pybald.util.text.pluralize(text)

Returns a pluralized from of the input text following simple naive english language pluralization rules.

Smart enough to turn fox into foxes and quiz into quizzes. Does not catch all pluralization rules, however.

pybald.util.text.strip_accents(text)

Strip diacriticals from characters. This will change the meaning of words but for places where unicode can’t be used (or ASCII only) francais looks better than fran-ais or fran?ais.

pybald.util.text.underscore_to_camel(text)

Convert underscore_separated text into CamelCase text.

pybald.util.text.unicode(txt, errors=None)