utils Package

utils Package

datefmt Module

class tic.utils.datefmt.FixedOffset(offset, name)[source]

Bases: datetime.tzinfo

Fixed offset in minutes east from UTC.

dst(dt)[source]
localize(dt, is_dst=False)[source]
tzname(dt)[source]
utcoffset(dt)[source]
class tic.utils.datefmt.LocalTimezone[source]

Bases: datetime.tzinfo

A ‘local’ time zone implementation

dst(dt)[source]
localize(dt, is_dst=False)[source]
tzname(dt)[source]
utcoffset(dt)[source]
tic.utils.datefmt.format_date(t=None, format='%x', tzinfo=None)[source]

Convenience method for formatting the date part of a datetime object. See format_datetime for more details.

tic.utils.datefmt.format_datetime(t=None, format='%x %X', tzinfo=None)[source]

Format the datetime object t into an unicode string

If t is None, the current time will be used.

The formatting will be done using the given format, which consist of conventional strftime keys. In addition the format can be ‘iso8601’ to specify the international date format.

tzinfo will default to the local timezone if left to None.

tic.utils.datefmt.format_time(t=None, format='%X', tzinfo=None)[source]

Convenience method for formatting the time part of a datetime object. See format_datetime for more details.

tic.utils.datefmt.get_date_format_hint()[source]

Present the default format used by format_date in a human readable form. This is a format that will be recognized by parse_date when reading a date.

tic.utils.datefmt.get_datetime_format_hint()[source]

Present the default format used by format_datetime in a human readable form. This is a format that will be recognized by parse_date when reading a date.

tic.utils.datefmt.get_timezone(tzname)[source]

Fetch timezone instance by name or return None

tic.utils.datefmt.http_date(t=None)[source]

Format datetime object t as a rfc822 timestamp

tic.utils.datefmt.parse_date(text, tzinfo=None)[source]
tic.utils.datefmt.pretty_timedelta(time1, time2=None, resolution=None)[source]

Calculate time delta between two datetime objects. (the result is somewhat imprecise, only use for prettyprinting).

If either time1 or time2 is None, the current time will be used instead.

tic.utils.datefmt.timezone(tzname)[source]

Fetch timezone instance by name or raise KeyError

tic.utils.datefmt.to_datetime(t, tzinfo=None)[source]

Convert t into a datetime object, using the following rules:

  • If t is already a datetime object, it is simply returned.
  • If t is None, the current time will be used.
  • If t is a number, it is interpreted as a timestamp.

If no tzinfo is given, the local timezone will be used.

Any other input will trigger a TypeError.

tic.utils.datefmt.to_timestamp(dt)[source]

Return the corresponding POSIX timestamp

functional Module

class tic.utils.functional.LazyObject[source]

Bases: object

A wrapper for another class that can be used to delay instantiation of the wrapped class.

By subclassing, you have the opportunity to intercept and alter the instantiation. If you don’t need to do that, use SimpleLazyObject.

importlib Module

tic.utils.importlib.import_module(name, package=None)[source]

Import a module.

The ‘package’ argument is required when performing a relative import. It specifies the package to use as the anchor point from which to resolve the relative import to an absolute import.

tic.utils.importlib.loadclass(module_and_name)[source]

Loads the module and returns the class.

jsparser Module

PyNarcissus

A lexical scanner and parser. JS implemented in JS, ported to Python.

exception tic.utils.jsparser.ParseError[source]

Bases: tic.utils.jsparser.Error_

tic.utils.jsparser.parse(source, filename=None, starting_line_number=1)[source]

Parse some Javascript

Args:

source: the Javascript source, as a string filename: the filename to include in messages starting_line_number: the line number of the first line of the

passed in source, for output messages
Returns:
the parsed source code data structure
Raises:
ParseError

short_cuts Module

tic.utils.short_cuts.object_mapper(source, destination)[source]

Maps all attributes in the source object to attributes in destination object.

if attributes in the destination object do not exit they will be created.

This comes in handy in mapping comming in ‘commands’ to data model objects.

Args:
source:
the copy-from object
destination:
the copy-to object
Returns:
the destination object
Tests & Examples:
>>> class A():
...     def __init__(self):
...         self.a = "this is cool"
...
>>> class B():
...     pass
...
>>> a = A()
>>> object_mapper(a, B()).a
'this is cool'

Table Of Contents

Previous topic

tools Package

Next topic

jsonpickle Package

This Page