smisk.core – Core functionality

This module is the foundation of Smisk and is implemented in machine native code.

See Smisk C library for documentation of the C interface.

Platforms: Linux, Mac, Unix

Requires:libfcgi

Attributes

smisk.core.__build__

Build identifier in URN form, distinguishing each unique build.

Format changed in version 1.1: in version 1.0 this was an abritrary (per-build unique) string. In 1.1 this is now a uniform URN.

smisk.core.app

Current Application (None if no application has been created).

This is actually a smisk.util.objectproxy.ObjectProxy, inducing a slight performance hit, since accessing the actual application causes intermediate calls. Application.current is the most performance-effective way to access the current application. However, in most cases the performance hit induced by the ObjectProxy is so small, the increased readability and usage of app is preferred.

Example:

>>> import smisk
>>> smisk.app
None
>>> import smisk.core
>>> smisk.core.Application()
<smisk.core.Application object at 0x6a5c0>
>>> smisk.app
<smisk.core.Application object at 0x6a5c0>
See:Application.current

New in version 1.1.

smisk.core.request

Current Request (None if no application is running).

This is actually a smisk.util.objectproxy.ObjectProxy, inducing a slight performance hit, since accessing the actual application causes intermediate calls. Application.current.request is the most performance-effective way to access the current request. However, in most cases the performance hit induced by the ObjectProxy is so small, the increased readability of request is preferred.

See:Application.request

New in version 1.1.

smisk.core.response

Current Response (None if no application is running).

This is actually a smisk.util.objectproxy.ObjectProxy, inducing a slight performance hit, since accessing the actual application causes intermediate calls. Application.current.response is the most performance-effective way to access the current response. However, in most cases the performance hit induced by the ObjectProxy is so small, the increased readability of response is preferred.

See:Application.response

New in version 1.1.

Functions

smisk.core.bind(path[, backlog=-1])

Bind to a specific unix socket or host (and/or port).

Parameters:
  • path (string) – The Unix domain socket (named pipe for WinNT), hostname, hostname and port or just a colon followed by a port number. e.g. "/tmp/fastcgi/mysocket", "some.host:5000", ":5000", "\*:5000".
  • backlog (int) – The listen queue depth used in the :func:’listen()’ call. Set to negative or zero to let the system decide (recommended).
Raises:

smisk.IOError If already bound.

Raises:

IOError If socket creation fails.

See:

unbind(), listening()

smisk.core.unbind()

Unbind from a previous call to bind().

If not bound, calling this function has no effect. You can test wherethere or not the current process is bound by calling listening().

Raises:IOError on failure.

New in version 1.1.

smisk.core.listening()

Find out if this process is a “remote” process, bound to a socket by means of calling bind(). If it is listening, this function returns the address and port or the UNIX socket path.

See also: unbind()

Raises:smisk.IOError On failure.
Returns:Bound path/address or None if not bound.
smisk.core.uid(nbits[, node=None]) → string

Generate a universally Unique Identifier.

See documentation of pack() for an overview of :func:nbits.

The UID is calculated like this:

sha1 ( time.secs, time.usecs, pid, random[, node] )
Note:

This is not a UUID (ISO/IEC 11578:1996) implementation. However it uses an algorithm very similar to UUID v5 (RFC 4122). Most notably, the format of the output is more compact than that of UUID v5.

Parameters:
  • nbits (int) – Number of bits to pack into each byte when creating the string representation. A value in the range 4-6 or 0 in which case 20 raw bytes are returned. Defaults is 5.
  • node (string) – Optional data to be used when creating the uid.

New in version 1.1.

smisk.core.pack(data[, nbits=5]) → string

Pack arbitrary bytes into a printable ASCII string.

Overview of nbits:

0 bits, No packing:
20 bytes "0x00-0xff"
4 bits, Base 16:
40 bytes "0-9a-f"
5 bits, Base 32:
32 bytes "0-9a-v"
6 bits, Base 64:
27 bytes "0-9a-zA-Z,-"
Parameters:
  • data (string) –
  • nbits (int) – Number of bits to pack into each byte when creating the string representation. A value in the range 4-6.
See:

uid()

New in version 1.1.

smisk.core.object_hash(object) → long

Calculate a hash from any python object.

New in version 1.1.

Exceptions

exception smisk.core.Error
exception smisk.core.IOError
exception smisk.core.InvalidSessionError