Acquire.ObjectStore._encoding module

bytes_to_string(b)[source]

Return the passed binary bytes safely encoded to a base64 utf-8 string

string_to_bytes(s)[source]

Return the passed base64 utf-8 encoded binary data back converted from a string back to bytes. Note that this can only convert strings that were encoded using bytes_to_string - you cannot use this to convert arbitrary strings to bytes

string_to_encoded(s)[source]

Return the passed unicode string encoded to a safely encoded base64 utf-8 string

encoded_to_string(b)[source]

Return the passed encoded base64 utf-8 string converted back into a unicode string

url_to_encoded(url)[source]

Return an encoding of the passed url that is safe to use as a name, filename or key in an object store

encoded_to_url(e)[source]

Decode the passed encoded data back to the URL. This will only produce valid output for inputs created using url_to_encoded

decimal_to_string(d)[source]

Return the passed decimal number encoded as a string that can be safely serialised via json

string_to_decimal(s)[source]

Return the decimal that had been encoded via ‘decimal_to_string’. This string must have been created via ‘decimal_to_string’

datetime_to_string(d)[source]

Return the passed datetime encoded to a string. This will be a standard iso-formatted time in the UTC timezone (converting to UTC if the passed datetime is for another timezone)

string_to_datetime(s)[source]

Return the datetime that had been encoded to the passed string via datetime_to_string. This string must have been created via ‘datetime_to_string’

date_to_string(d)[source]

Return the date that has been encoded to a string. This will write the date as a standard iso-formatted date. IF a datetime is passed then this will be in the UTC timezone (converting to UTC if the passed datetime is for another timezone)

string_to_date(s)[source]

Return a date from the string that has been encoded using ‘date_to_string’. This is only guaranteed to work for strings that were created using that function

time_to_string(t)[source]

Return the time that has been encoded to a string. This will write the time as a standard iso-formatted time. If a datetime is passed then this will be in the UTC timezone (converting to UTC if the passed datetime is for another timezone)

string_to_time(s)[source]

Return a time from the string that was encoded by ‘time_to_string’. This will only be guaranteed to produce valid output for strings produced using that function

get_datetime_now()[source]

Return the current time in the UTC timezone. This creates an object that will be properly stored using datetime_to_string and string_to_datetime

datetime_to_datetime(d)[source]

Return the passed datetime as a datetime that is clean and usable by Acquire. This will move the datetime to UTC, adding the timezone if this is missing

string_to_safestring(s)[source]

Return a safe (base64) encoded version of ‘s’. This string has no special characters or spaces, thereby making it safe for use, e.g. as a filename or to save in a database

safestring_to_string(s)[source]

Return the original string encoded by string_to_safestring

string_to_list(s, C)[source]

Convert the string encoded using list_to_string back to a list of objects of type C. Note that all objects must have the same type

list_to_string(l)[source]

Return the passed list of items converted to a json string. All items should have the same type

string_to_dict(s, C)[source]

Convert the string encoded using dict_to_string back to a dict of objects of type C. Note that all objects must have the same type

dict_to_string(d)[source]

Return the passed dict of items converted to a json string. All items should have the same type

string_to_filepath(path)[source]

This function cleans the passed path so that doesn’t contain redundant slashes or ‘..’ etc., so that all backslashes are forwards slashes, and that the trailing slash is removed

string_to_filepath_parts(path)[source]

Break the passed path into a list of the individual parts, e.g. /home/user/test/../something/./new.txt will return

[‘home’, ‘user’, ‘something’, ‘new.txt’]

get_datetime_future(weeks=0, days=0, hours=0, minutes=0, seconds=0, timedelta=None)[source]

Return the datetime that is the supplied time in the future. This will raise an exception if the time is not in the future!

get_datetime_now_to_string()[source]

Convenience function that returns the result of get_datetime_now as a string converted via datetime_to_string

date_and_time_to_datetime(date, time=datetime.time(0, 0))[source]

Return the passed date and time as a UTC datetime. By default the time is midnight (first second of the day)

create_uuid()[source]

Return a newly created random uuid. This is highly likely to be globally unique