graviti.utility.common#

Common tools.

Module Contents#

Classes#

LazyAttr

The descriptor for the lazy loaded attr.

CachedProperty

The descriptor for the cached property.

ModuleMocker

A fake module to raise ModuleNotFoundError lazily.

Functions#

urlnorm(url)

Normalized the input url by removing the trailing slash.

locked(func)

The decorator to add threading lock for methods.

shorten(origin)

Return the first 7 characters of the original string.

convert_iso_to_datetime(date_string)

Convert iso 8601 format string to datetime format time with local timezone.

convert_datetime_to_gmt(utctime)

Convert datetime to gmt format string.

Attributes#

graviti.utility.common.locks :DefaultDict[int, threading.Lock][source]#
graviti.utility.common.urlnorm(url)[source]#

Normalized the input url by removing the trailing slash.

Parameters

url (str) – the url needs to be normalized.

Returns

The normalized url.

Return type

str

graviti.utility.common.locked(func)[source]#

The decorator to add threading lock for methods.

Parameters

func (_CallableWithoutReturnValue) – The method needs to add threading lock.

Returns

The method with theading locked.

Return type

_CallableWithoutReturnValue

graviti.utility.common.shorten(origin)[source]#

Return the first 7 characters of the original string.

Parameters

origin (str) – The string needed to be shortened.

Returns

A string of length 7.

Return type

str

graviti.utility.common.convert_iso_to_datetime(date_string)[source]#

Convert iso 8601 format string to datetime format time with local timezone.

Parameters

date_string (str) – The iso 8601 format string.

Returns

The datetime format time with local timezone.

Return type

datetime.datetime

graviti.utility.common.convert_datetime_to_gmt(utctime)[source]#

Convert datetime to gmt format string.

Parameters

utctime (datetime.datetime) – The datetime with utc timezone.

Returns

The gmt format string.

Return type

str

class graviti.utility.common.LazyAttr[source]#

Bases: Generic[_T]

The descriptor for the lazy loaded attr.

class graviti.utility.common.CachedProperty(func)[source]#

Bases: Generic[_S, _T]

The descriptor for the cached property.

Parameters

func (Callable[[_S], _T]) – the property function needs to be cached.

class graviti.utility.common.ModuleMocker(message)[source]#

A fake module to raise ModuleNotFoundError lazily.

Parameters

message (str) – The error message for the raised ModuleNotFoundError.