Utilitarian Functions¶
Source code: hyccup/util.hy
Strings Handling¶
- (hyccup.util.escape-html string mode escape-strings)¶
Change special characters into HTML character entities.
- class hyccup.util.RawStr¶
Raw string class, subclass of
str
.Instances of this class are not escaped.
- classmethod (from-obj-or-iterable cls obj)¶
Produce a raw string from an object or a collection.
- (hyccup.util.to-str obj)¶
Convert any object to string.
In particular:
Convert fraction to string of its decimal result.
Convert a
url.parse.SplitResult
object to its URL withstr-of-url
.For any other case, convert with
str
constructor.
URLs Handling¶
- (hyccup.util.url #* parts #** query-params)¶
Convert parts of an URL and query params to a
url.parse.SplitResult
.
- (hyccup.util.to-uri obj)¶
Convert an object to a
url.parse.SplitResult
.
- (hyccup.util.base-url #* args #** kwds)¶
Context manager specifying base URL for URLs.
=> (with [(base-url "/foo")] ... (setv my-url (to-str (to-uri "/bar")))) => (print my-url) "/foo/bar"
>>> with base_url('/foo'): ... my_url = to_str(to_uri('/bar')) ... >>> print(my-url) /foo/bar
- (hyccup.util.str-of-url split-result)¶
Make URL from
url.parse.SplitResult
object.
- (hyccup.util.url-encode obj)¶
Quote obj for URL encoding.
If obj is a dict, use
url.parse.urlencode
.Else use
url.parse.quote_plus
.
- (hyccup.util.encoding #* args #** kwds)¶
Context manager specifying encoding.
=> (with [(encoding "UTF-8")] ... (url-encode {"iroha" "いろは"})) "iroha=%E3%81%84%E3%82%8D%E3%81%AF" => (with [(encoding "ISO-2022-JP")] ... (url-encode {"iroha" "いろは"})) "iroha=%1B%24B%24%24%24m%24O%1B%28B"
>>> with encoding('UTF-8'): ... print(url_encode({'iroha': 'いろは'})) ... iroha=%E3%81%84%E3%82%8D%E3%81%AF >>> with encoding('ISO-2022-JP'): ... print(url_encode({'iroha': 'いろは'})) ... iroha=%1B%24B%24%24%24m%24O%1B%28B