Best Python code snippet using pypom_form_python
reformer.py
Source:reformer.py
...24 return value._transform(item or obj)25 return value26 def as_(self, schema):27 getter = self._getter28 def _getter(obj):29 item = getter(obj)30 if isinstance(schema, dict):31 res = OrderedDict()32 for key, value in schema.items():33 res[self.__get_value(key, obj, item)] = self.__get_value(value, obj, item)34 return res35 if isinstance(schema, (list, tuple)):36 res = []37 for value in schema:38 res.append(self.__get_value(value, obj, item))39 return type(schema)(res)40 return self.__get_value(schema, obj, item)41 self._getter = _getter42 return self43 in_form = as_44 def iter(self, schema, condition=None):45 getter = self._getter46 def _getter(obj):47 obj = getter(obj)48 if isinstance(obj, dict):49 obj = [{'key': k, 'value': v} for k, v in obj.items()]50 if isinstance(schema, dict):51 res = OrderedDict()52 _key, _value = list(schema.items())[0]53 for item in obj:54 if condition and not self.__get_value(condition, obj, item):55 continue56 res[self.__get_value(_key, obj, item)] = self.__get_value(_value, obj, item)57 return res58 if isinstance(schema, (tuple, list)):59 res = []60 _value = schema[0]61 for item in obj:62 if condition and not self.__get_value(condition, obj, item):63 continue64 res.append(self.__get_value(_value, obj, item))65 return type(schema)(res)66 self._getter = _getter67 return self68 def compare(self, item, operator=operator.eq):69 getter = self._getter70 self._getter = lambda obj: operator(getter(obj), self.__get_value(item, obj))71 return self72 def at(self, container):73 getter = self._getter74 self._getter = lambda obj: (getter(obj) in container)75 return self76 def contains(self, item):77 getter = self._getter78 self._getter = lambda obj: (item in getter(obj))79 return self80 def to(self, type):81 getter = self._getter82 self._getter = lambda obj: type(getter(obj))83 return self84 def to_str(self):85 return self.to(str)86 def to_int(self):87 return self.to(int)88 def map(self, choices, default=None):89 getter = self._getter90 def _getter(obj):91 obj = getter(obj)92 if isinstance(choices, (list, tuple)):93 assert isinstance(obj, int)94 if len(choices) > obj:95 return choices[obj]96 return default97 if isinstance(choices, dict):98 return choices.get(obj, default)99 return getattr(choices, obj, default)100 self._getter = _getter101 return self102 def call(self, function):103 getter = self._getter104 def _getter(obj):105 obj = getter(obj)106 return function(obj)107 self._getter = _getter108 return self109 handle = call110 def set_null(self):111 self.__null = True112 return self113 def set_default(self, value):114 self.__default = value115 return self116 def set_as_item(self, value=True):117 self.__item = value118 return self119 def __getattr__(self, item):120 getter = self._getter121 def _getter(obj):122 obj = getter(obj)123 if isinstance(item, str) and hasattr(obj, item):124 return getattr(obj, item)125 return obj[item]126 self._getter = _getter127 return self128 __getitem__ = __getattr__129 def __call__(self, *args, **kwargs):130 getter = self._getter131 def _getter(obj):132 _args = [a._get(obj) if isinstance(a, _Target) else a for a in args]133 _kw = {k._get(obj) if isinstance(k, _Target) else k: v._get(obj) if isinstance(v, _Target) else v134 for k, v in kwargs.items()}135 return getter(obj)(*_args, **_kw)136 self._getter = _getter137 return self138 def __iter__(self):139 raise NotImplementedError140 def __add__(self, other):141 getter = self._getter142 if isinstance(other, _Target):143 self._getter = lambda obj: (getter(obj) + other._getter(obj))144 else:145 self._getter = lambda obj: (getter(obj) + other)146 return self147 def __radd__(self, other):148 getter = self._getter149 if isinstance(other, _Target):150 self._getter = lambda obj: (other._getter(obj) + getter(obj))151 else:152 self._getter = lambda obj: (other + getter(obj))153 return self154 def __mul__(self, other):155 getter = self._getter156 if isinstance(other, _Target):157 self._getter = lambda obj: (getter(obj) * other._getter(obj))158 else:159 self._getter = lambda obj: (getter(obj) * other)160 return self161 def __rmul__(self, other):162 getter = self._getter163 if isinstance(other, _Target):164 self._getter = lambda obj: (other._getter(obj) * getter(obj))165 else:166 self._getter = lambda obj: (other * getter(obj))167 return self168 def __eq__(self, other):169 return self.compare(other)170 def __gt__(self, other):171 return self.compare(other, operator.gt)172 def __ge__(self, other):173 return self.compare(other, operator.ge)174 def __lt__(self, other):175 return self.compare(other, operator.lt)176 def __le__(self, other):177 return self.compare(other, operator.le)178 def __hash__(self):179 return hash(self._getter)180 def _get(self, obj):181 try:182 return self._getter(obj)183 except (KeyError, AttributeError, TypeError):184 if self.__null or self.__default is not None:185 return self.__default186 raise187class _ReformerMeta(type):188 @classmethod189 def __prepare__(mcs, name, bases):190 return OrderedDict()191 def __new__(mcs, name, bases, attrs):192 attrs.setdefault(ATTR_NAME, [])193 for base in bases:194 for _name in getattr(base, ATTR_NAME, []):195 if _name not in attrs:196 attrs[ATTR_NAME].append(_name)197 if '_fields_' in attrs:198 for name in attrs['_fields_']:199 attrs[name] = Field(name)200 attrs[ATTR_NAME].append(name)201 for key, value in attrs.items():202 if isinstance(value, _Target):203 if isinstance(value, Field):204 value.set_as_item(False)205 value._name = key206 if value._source is None:207 value._source = key208 if key not in attrs[ATTR_NAME]:209 attrs[ATTR_NAME].append(key)210 return type.__new__(mcs, name, bases, attrs)211class Field(_Target):212 def __init__(self, source=None, schema=None, to=None,213 handler=None, choices=None, required=True, default=None):214 self._name = None215 self._source = source216 def initial_getter(obj):217 result = obj218 for _source in self._source.split('.'):219 if _source in ['self']:220 continue221 if hasattr(result, _source):222 result = getattr(result, _source)223 else:224 result = result[_source]225 return result226 super().__init__(getter=initial_getter)227 self.set_as_item()228 self.set_default(default)229 if not required:230 self.set_null()...
listener.py
Source:listener.py
2from ctypes import pointer3from functools import partial4from .main import bass_call, update_3d_system5from .external.pybass import *6def _getter(base_prop, attr, obj):7 """8 Args:9 base_prop: 10 attr: 11 obj: 12 Returns:13 """14 return getattr(getattr(obj, base_prop), attr)15def _setter(base_prop, subattr, obj, val):16 """17 Args:18 base_prop: 19 subattr: 20 obj: ...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!