core.utils

Module Contents

Functions

utcNow()

generateRandomString(length: int = 13) → str

Return a string containing random characters of given length.

getCurrentUser()

Retrieve current user, if logged in.

markFileForDeletion(dlkey)

Adds a marker to the data store that the file specified as dlkey can be deleted.

escapeString(val, maxLength=254)

Quotes several characters and removes “\n” and “\0” to prevent XSS injection.

hmacSign(data: Any) → str

hmacVerify(data: Any, signature: str) → bool

downloadUrlFor(folder: str, fileName: str, derived: bool = False, expires: Union[(timedelta, None)] = timedelta(hours=1)) → str

seoUrlToEntry(module, entry=None, skelType=None, language=None)

seoUrlToFunction(module, function, render=None)

normalizeKey(key: Union[(None, 'db.KeyClass')]) → Union[(None, 'db.KeyClass')]

Normalizes a datastore key (replacing _application with the current one)

core.utils.currentRequest
core.utils.currentRequestData
core.utils.currentSession
core.utils.currentLanguage
core.utils.projectBasePath
core.utils.isLocalDevelopmentServer
core.utils.utcNow()
core.utils.generateRandomString(length: int = 13)str

Return a string containing random characters of given length. Its safe to use this string in URLs or HTML.

Parameters

length (int) – The desired length of the generated string.

Returns

A string with random characters of the given length.

Return type

str

core.utils.getCurrentUser()

Retrieve current user, if logged in.

If a user is logged in, this function returns a dict containing user data.

If no user is logged in, the function returns None.

Return type

dict | bool

Returns

A dict containing information about the logged-in user, None if no user is logged in.

core.utils.markFileForDeletion(dlkey)

Adds a marker to the data store that the file specified as dlkey can be deleted.

Once the mark has been set, the data store is checked four times (default: every 4 hours) if the file is in use somewhere. If it is still in use, the mark goes away, otherwise the mark and the file are removed from the datastore. These delayed checks are necessary due to database inconsistency.

Parameters

dlkey (str) – Unique download-key of the file that shall be marked for deletion.

core.utils.escapeString(val, maxLength=254)

Quotes several characters and removes “\n” and “\0” to prevent XSS injection.

Parameters
  • val (str) – The value to be escaped.

  • maxLength (int) – Cut-off after maxLength characters. A value of 0 means “unlimited”.

Returns

The quoted string.

Return type

str

core.utils.hmacSign(data: Any)str
core.utils.hmacVerify(data: Any, signature: str)bool
core.utils.downloadUrlFor(folder: str, fileName: str, derived: bool = False, expires: Union[timedelta, None] = timedelta(hours=1))str
core.utils.seoUrlToEntry(module, entry=None, skelType=None, language=None)
core.utils.seoUrlToFunction(module, function, render=None)
core.utils.normalizeKey(key: Union[None, db.KeyClass])Union[None, db.KeyClass]

Normalizes a datastore key (replacing _application with the current one)

Parameters

key – Key to be normalized.

Returns

Normalized key in string representation.