swh.search.utils module

swh.search.utils.get_expansion(field, sep=None)[source]
swh.search.utils.is_date_parsable(date_str)[source]

Return True if date_str is in the format %Y-%m-%d or the standard ISO format. Otherwise return False.

swh.search.utils.escape(obj)[source]

Makes the object directly injectable into the query language by converting the escapable parts of the object into escape sequences.

For strings, appends before special characters like ‘, “, and

For arrays, applies the same transformation on each element, joins the elements and returns a string-like representation of the list.

>>> print(escape("foo ' bar"))
"foo \' bar"
>>> print(escape([r"foo ' bar", r"bar \\\' baz", r'foo " baz']))
["foo \' bar", "bar \\\\\\\' baz", "foo \" baz"]
swh.search.utils.unescape(string)[source]

Processes the escaped special characters

>>> unescape(r'''foo " bar''') == r'''foo " bar'''
True
>>> unescape(r'''foo \" bar''') == r'''foo " bar'''
True
>>> unescape(r'''foo \\" bar''') == r'''foo \" bar'''
True
>>> unescape(r'''foo \\\" bar''') == r'''foo \" bar'''
True
>>> unescape(r'''foo \\\\" bar''') == r'''foo \\" bar'''
True
>>> unescape(r'''café \" foo''') == r'''café " foo'''
True