PK!lXffLICENSECopyright (c) 2018 macheins Provided that these terms and disclaimer and all copyright notices are retained or reproduced in an accompanying document, permission is granted to deal in this work without restriction, including un- limited rights to use, publicly perform, distribute, sell, modify, merge, give away, or sublicence. This work is provided "AS IS" and WITHOUT WARRANTY of any kind, to the utmost extent permitted by applicable law, neither express nor implied; without malicious intent or gross negligence. In no event may a licensor, author or contributor be held liable for indirect, direct, other damage, loss, or other issues arising in any way out of dealing in the work, even if advised of the possibility of such damage or existence of a defect, except proven that it results out of said person's immediate fault when using the work as intended. PK!`^hypothesis_json/__init__.pyimport pkg_resources try: __version__ = pkg_resources.get_distribution(__name__).version except pkg_resources.DistributionNotFound: # pragma: no cover pass PK!:hypothesis_json/_utils.pyfrom math import isinf, isnan from typing import Any from hypothesis.internal.floats import next_down, next_up from .errors import InvalidArgument, InvalidArgumentValue def validate_bool(x: Any, *, optional: bool = False) -> None: """Raise iff x is not a bool.""" assert isinstance(optional, bool) if x is None: if not optional: raise InvalidArgument() else: if not isinstance(x, bool): raise InvalidArgumentValue() def wrap(i_min: int, i_max: int, i: int) -> int: """Wrap i between i_min and i_max.""" assert isinstance(i_min, int) assert isinstance(i_max, int) assert isinstance(i, int) assert i_min <= i_max i_range = (i_max + 1) - i_min return (((i - i_min) % i_range) + i_range) % i_range + i_min def ensure_not_integer(f: float) -> float: """Iff a f is an integer return the closest float.""" assert isinstance(f, float) if not (isinf(f) or isnan(f)): i = int(f) if f == i: i = wrap(-(2 ** 52), +(2 ** 52), i) if i < 0: f = next_up(float(i)) # type: ignore else: f = next_down(float(i)) # type: ignore assert isinstance(f, float) assert f != int(f) return f PK!5lhypothesis_json/errors.pyfrom hypothesis.errors import InvalidArgument class InvalidArgumentValue(InvalidArgument, ValueError): """Used to indicate that arguments passed to a Hypothesis strategy have a invalid value.""" PK!hypothesis_json/py.typedPK!{Shypothesis_json/strategies.pyimport math from functools import partial from typing import List # noqa: F401 from typing import Optional as Opt, Union import hypothesis.strategies as hs from hypothesis.internal.floats import next_down, next_up from hypothesis.searchstrategy import SearchStrategy from ._utils import ensure_not_integer, validate_bool, wrap from .errors import InvalidArgument, InvalidArgumentValue from .typing import JSON, Primitive def _null() -> SearchStrategy[None]: return hs.none() def _booleans() -> SearchStrategy[bool]: return hs.booleans() def _integers( min_value: int = -(2 ** 53), max_value: int = +(2 ** 53) ) -> SearchStrategy[int]: assert isinstance(min_value, int) assert isinstance(max_value, int) assert min_value <= max_value return hs.integers().map(partial(wrap, min_value, max_value)) def _numbers( *, infs: bool = True, nan: bool = True, integers: bool = True ) -> SearchStrategy[Union[float, int]]: assert isinstance(infs, bool) assert isinstance(nan, bool) assert isinstance(integers, bool) if integers: ints = _integers() return hs.one_of( ints, ints.map(float), hs.floats(allow_infinity=infs, allow_nan=nan), ) fints = _integers(-(2 ** 52) - 1, +(2 ** 52) + 1).map(float) return hs.one_of( fints.map(next_down), fints.map(next_up), hs.floats(allow_infinity=infs, allow_nan=nan).map(ensure_not_integer), ) def _strings() -> SearchStrategy[str]: return hs.one_of( hs.sampled_from( [ "null", "None", "true", "True", "false", "False", "-Infinity", "-inf", "Infinity", "inf", "NaN", "nan", ] ), _numbers().map(str), hs.text(), ) def primitives( *, default: bool = True, null: Opt[bool] = None, booleans: Opt[bool] = None, numbers: Opt[bool] = None, infs: Opt[bool] = None, nan: Opt[bool] = None, integers: Opt[bool] = None, strings: Opt[bool] = None ) -> SearchStrategy[Primitive]: """Strategy to generate JSON primitives.""" validate_bool(default) validate_bool(null, optional=True) validate_bool(booleans, optional=True) validate_bool(numbers, optional=True) validate_bool(infs, optional=True) validate_bool(nan, optional=True) validate_bool(integers, optional=True) validate_bool(strings, optional=True) if null is None: null = default if booleans is None: booleans = default if numbers is None: numbers = default if infs is None: infs = numbers if nan is None: nan = numbers if integers is None: integers = numbers if strings is None: strings = default args = [] # type: List[SearchStrategy[Primitive]] if null: args.append(_null()) if booleans: args.append(_booleans()) if numbers: args.append(_numbers(infs=infs, nan=nan, integers=integers)) else: if nan: args.append(hs.just(math.nan)) if infs: args.append(hs.sampled_from([-math.inf, +math.inf])) if integers: args.append(_integers()) if strings: args.append(_strings()) return hs.one_of(*args) def jsons( *, default: bool = True, arrays: Opt[bool] = None, objects: Opt[bool] = None, max_leaves: int = 100, null: Opt[bool] = None, booleans: Opt[bool] = None, numbers: Opt[bool] = None, infs: Opt[bool] = None, nan: Opt[bool] = None, integers: Opt[bool] = None, strings: Opt[bool] = None ) -> SearchStrategy[JSON]: """Strategy to generate JSONs.""" validate_bool(default) validate_bool(arrays, optional=True) validate_bool(objects, optional=True) if arrays is None: arrays = default if objects is None: objects = default if not isinstance(max_leaves, int): raise InvalidArgument() if max_leaves < 0: raise InvalidArgumentValue() base = primitives( default=default, null=null, booleans=booleans, numbers=numbers, infs=infs, nan=nan, integers=integers, strings=strings, ) extend = None if arrays and objects: extend = lambda cs: hs.one_of( # noqa: E731 hs.lists(cs), hs.dictionaries(_strings(), cs) ) elif arrays: extend = hs.lists elif objects: extend = partial(hs.dictionaries, _strings()) if extend: return hs.recursive(base, extend, max_leaves=max_leaves) return base PK!r&hypothesis_json/typing.pyfrom typing import Dict, List, Union Primitive = Union[None, bool, float, int, str] JSON = Union[Primitive, Dict[str, "JSON"], List["JSON"]] # type: ignore PK!lXff'hypothesis_json-1.2.2.dist-info/LICENSECopyright (c) 2018 macheins Provided that these terms and disclaimer and all copyright notices are retained or reproduced in an accompanying document, permission is granted to deal in this work without restriction, including un- limited rights to use, publicly perform, distribute, sell, modify, merge, give away, or sublicence. This work is provided "AS IS" and WITHOUT WARRANTY of any kind, to the utmost extent permitted by applicable law, neither express nor implied; without malicious intent or gross negligence. In no event may a licensor, author or contributor be held liable for indirect, direct, other damage, loss, or other issues arising in any way out of dealing in the work, even if advised of the possibility of such damage or existence of a defect, except proven that it results out of said person's immediate fault when using the work as intended. PK!HnHTU%hypothesis_json-1.2.2.dist-info/WHEEL A н#Z;/"d&F[xzw@Zpy3Fv]\fi4WZ^EgM_-]#0(q7PK!HQc+ (hypothesis_json-1.2.2.dist-info/METADATAVo8 ~_A`% mk{ND,y%;uÚG#,e6\%apr\¦*ݠ&b hULWKxc5*XDW;cXkmaMG9K6ȥ'( ݜ}~yp\ڍKYWMxY ;sMD`# U(-,¥ViXJO=7UT0ҢL12(t& mdS8. 0{ =cJgMs.p交;˺>xODv[,UwR2{O_ 7ء4[x \- eU:xO$Nckb ][|dSAꧮ 7ĩI`ɽ+OV;NEUHu?#6T(BpF5#Y{V> 8WGt]l(3ҲJ q',9M= \7٧)ITJQ^_Hb|􃣣#ȴʁZyJ=mq5.Lm6ޠ?^/,3&tu|:.3:k?q4Gl ry>p1̇h:O y4GʌKn+f2_LxDAѴ lu|Ä`0H }*eBv'!42lvJit`Ni4>B