PaferaPy Async 0.1
ASGI framework focused on simplicity and efficiency
Loading...
Searching...
No Matches
Functions
pafera.utils Namespace Reference

Functions

def b64decodepad (s)
 Helper function to ensure that a b64 string is correctly padded to four spaces. More...
 
def BestTranslation (translations, languages, defaultlang='en')
 Returns the best translation found in a dict of different translations. More...
 
def Bound (val, min, max)
 Returns a value that is no smaller than min or larger than max. More...
 
def CodeDir (code)
 Separates a filename into three character segments with the directory separator '/' in between. More...
 
def EscapeSQL (s)
 Escapes special characters to be used in a SQL query string. More...
 
def FromShortCode (code, chars='0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_')
 Turns a six character alphanumeric code into a 32-bit value. More...
 
def GetModel (model)
 Returns the model object from the correct module. More...
 
def KeyFromValue (ls, value)
 Does a reverse lookup to find the key of a value in a dict. More...
 
def LoadTranslation (g, app, translation, languages)
 Load the translation into the global language dict in g.T. More...
 
def MakeRBID ()
 Returns a random 64-bit int ID. More...
 
def MakeRID ()
 Returns a random 32-bit int ID. More...
 
def ToShortCode (val, chars='0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_')
 Turns a 32-bit value into a six character alphanumeric code. More...
 

Function Documentation

◆ b64decodepad()

def pafera.utils.b64decodepad (   s)

Helper function to ensure that a b64 string is correctly padded to four spaces.

Definition at line 174 of file utils.py.

◆ BestTranslation()

def pafera.utils.BestTranslation (   translations,
  languages,
  defaultlang = 'en' 
)

Returns the best translation found in a dict of different translations.

languages should be a list of of ISO 639-1 language codes.

defaultlang is set to 'en', so be sure to set it to your native language if used on other systems.

Definition at line 104 of file utils.py.

◆ Bound()

def pafera.utils.Bound (   val,
  min,
  max 
)

Returns a value that is no smaller than min or larger than max.

Definition at line 21 of file utils.py.

◆ CodeDir()

def pafera.utils.CodeDir (   code)

Separates a filename into three character segments with the directory separator '/' in between.

Useful for avoiding having millions of small files inside of the same directory, which is known to severely degrade performance on some filesystems.

Definition at line 87 of file utils.py.

◆ EscapeSQL()

def pafera.utils.EscapeSQL (   s)

Escapes special characters to be used in a SQL query string.

Taken from mysql-connector's version.

Definition at line 190 of file utils.py.

◆ FromShortCode()

def pafera.utils.FromShortCode (   code,
  chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_' 
)

Turns a six character alphanumeric code into a 32-bit value.

It's the reverse of ToShortCode()

Definition at line 61 of file utils.py.

◆ GetModel()

def pafera.utils.GetModel (   model)

Returns the model object from the correct module.

Definition at line 155 of file utils.py.

◆ KeyFromValue()

def pafera.utils.KeyFromValue (   ls,
  value 
)

Does a reverse lookup to find the key of a value in a dict.

Definition at line 218 of file utils.py.

◆ LoadTranslation()

def pafera.utils.LoadTranslation (   g,
  app,
  translation,
  languages 
)

Load the translation into the global language dict in g.T.

languages should be a list of of ISO 639-1 language codes.

'en' will always be the last language code on the list.

Definition at line 129 of file utils.py.

◆ MakeRBID()

def pafera.utils.MakeRBID ( )

Returns a random 64-bit int ID.

Definition at line 15 of file utils.py.

◆ MakeRID()

def pafera.utils.MakeRID ( )

Returns a random 32-bit int ID.

Definition at line 9 of file utils.py.

◆ ToShortCode()

def pafera.utils.ToShortCode (   val,
  chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_' 
)

Turns a 32-bit value into a six character alphanumeric code.

Useful for shortening JSON data or use in URLs.

Thanks to http://programanddesign.com/php/base62-encode/

Definition at line 33 of file utils.py.