hbutils.model.raw¶
raw_support¶
-
hbutils.model.raw.
raw_support
(condition, raw_name: str = 'raw', unraw_name: str = 'unraw', proxy_name='RawProxy')[source]¶ - Overview:
Get raw support wrapper function and class.
- Arguments:
condition: Condition of wrapper, the value will be wrapped only when
condition
is satisfied.raw_name (
str
): Raw function’s name.unraw_name (
str
): Unraw function’s name.proxy_name (
str
): Proxy class’s name.
- Returns:
(raw_func, unraw_func, proxy_class).
- Examples::
>>> from hbutils.model import raw_support >>> raw, unraw, RawProxy = raw_support(lambda x: isinstance(x, dict)) >>> raw(1) 1 >>> raw({'a': 1, 'b': 2}) <RawProxy value: {'a': 1, 'b': 2}>
>>> unraw(1) 1 >>> unraw({'a': 1, 'b': 2}) {'a': 1, 'b': 2} >>> unraw(raw({'a': 1, 'b': 2})) {'a': 1, 'b': 2}