swh.search.utils module#
- swh.search.utils.parse_and_format_date(date_str: str) str | None[source]#
- Parses a string date in the format %Y-%m-%d or ISO8601 and returns a new string date in the format YYYY-mm-dd if the parsing succeeded otherwise None. 
- 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