PK!<@@mimesis_factory.py# -*- coding: utf-8 -*- import contextlib from factory import declarations from mimesis import config from mimesis.schema import Field class MimesisField(declarations.BaseDeclaration): """ Mimesis integration with FactoryBoy starts here. This class provides common interface for FactoryBoy, but inside it has Mimesis generators. That's how it works: 1. We have """ _CACHED_INSTANCES = {} _DEFAULT_LOCALE = config.DEFAULT_LOCALE def __init__(self, field, locale=None, **kwargs): """ Creates a field instance. The created field is lazy. It also receives build time parameters. This parameters are not applied yet. Args: field: field name to be passed to `Field` from `Mimesis`. locale: locale to use. This parameter has the highest priority over other locale parameters. kwargs: optional parameters that would be passed to `Field`. """ super().__init__() self.locale = locale self.kwargs = kwargs self.field = field def evaluate(self, instance, step, extra): """Evaluates the lazy field.""" if extra is None: extra = {} kwargs = {} kwargs.update(self.kwargs) kwargs.update(extra) mimesis = self._get_cached_instance(locale=self.locale) return mimesis(self.field, **kwargs) @classmethod @contextlib.contextmanager def override_locale(cls, locale): """ Overrides unspecified locales. Remember, that implicit locales would not be overridden. """ old_locale = cls._DEFAULT_LOCALE cls._DEFAULT_LOCALE = locale try: yield finally: cls._DEFAULT_LOCALE = old_locale @classmethod def _get_cached_instance(cls, locale=None): if locale is None: locale = cls._DEFAULT_LOCALE if locale not in cls._CACHED_INSTANCES: cls._CACHED_INSTANCES[locale] = Field(locale) return cls._CACHED_INSTANCES[locale] PK!jI..'mimesis_factory-0.1.0.dist-info/LICENSEMIT License Copyright (c) 2017 Nikita Sobolev Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.PK!HƣxST%mimesis_factory-0.1.0.dist-info/WHEEL A н#J;/"d&F]xzw>@Zpy3F ]n2H%_60{8&baPa>PK!H((U (mimesis_factory-0.1.0.dist-info/METADATAVnF}߯:0$K aq5jFF!-evF/p(;q&w̜9; 4hu؋v5~uY׆J>c_JbI>% O#ŋx\Te09>+*ە,ӞRj'bOR|V/G|ڶqQ䩧ƴ:MHL{ID0B,=R-yE5eݱp`Վ/C6]`G 13R*[&h;~~&SEAYTاF\*lwY=ߑgڐ xe6 c%% 4ѤWΥ\7`x2C0kE>:hلKs 8Ua2c3 lt* aӡl>J*s2;vоʭ;n~ ޣl$&{q 架 2m.Rk ϕa3fdSQߜ/+6R,HL)R*Uf> ΧOB¶{6쎜{weo]/iC.l C=}FAgih &}6$p0fmc`m+!Fy3NS]%ϣ `_|; ҫǨ%xUbFHɲFK c!,-A!͋ F֥q1-AfA\ڞwAc B/M M5lr%hǝGbsqg*x-YV2LvSֻ:QPK!HB[&mimesis_factory-0.1.0.dist-info/RECORD=z0ݳ8tJ(P$MOɡ^-2^56[ 1#N Wu*&axWAN țCF꿔MdBR̛{d?.bd3ޯ,LWD~K q|ç~ >E2oL/P1_w Uxi*-ܦ|`K;S'v|2iw9++c'RͷOL!oNPK!<@@mimesis_factory.pyPK!jI..'pmimesis_factory-0.1.0.dist-info/LICENSEPK!HƣxST% mimesis_factory-0.1.0.dist-info/WHEELPK!H((U (y mimesis_factory-0.1.0.dist-info/METADATAPK!HB[&mimesis_factory-0.1.0.dist-info/RECORDPKU