How to use _unused method in Slash

Best Python code snippet using slash

ABuChecker.py

Source:ABuChecker.py Github

copy

Full Screen

1# -*- encoding:utf-8 -*-2"""3 检查类,检查函数对象、函数参数、函数返回值4"""5from __future__ import print_function6from __future__ import absolute_import7from __future__ import division8from toolz import valmap9from functools import wraps10from ..CheckBu.ABuFuncUtil import *11from ..CheckBu.ABuChecks import *12from ..CheckBu.ABuProcessor import arg_process, return_process13__author__ = '夜猫'14__weixin__ = 'abu_quant'15class _NoInstances(six.with_metaclass(ABCMeta, type)):16 """阻止实例化"""17 def __call__(cls, *args, **kwargs):18 raise TypeError("Can't instantiate directly")19class FuncChecker(six.with_metaclass(ABCMeta, _NoInstances)):20 """函数相关的检查类"""21 @staticmethod22 def check_iscallable(func):23 """24 检查传入参数对象是否是函数;不是函数raise CheckError25 :param func: 传入参数对象26 """27 if not callable(func):28 raise CheckError('%s is not callable' % get_func_name(func))29class ArgChecker(six.with_metaclass(ABCMeta, _NoInstances)):30 """函数参数相关的检查类"""31 @staticmethod32 def check_type(*ty_args, **ty_kwargs):33 """34 【装饰器】35 检查输入参数类型;检查失败raise CheckError36 :param ty_args: 类型tuple37 :param ty_kwargs: 类型dict38 :return: 39 """40 # 检查是否有不合规的tuple参数41 for ty in ty_args:42 if not isinstance(ty, (type, tuple)):43 raise TypeError(44 "check_type() expected a type or tuple of types"45 ", but got {type_} instead.".format(46 type_=ty,47 )48 )49 # 检查是否有不合规的dict参数50 for name, ty in six.iteritems(ty_kwargs):51 if not isinstance(ty, (type, tuple)):52 raise TypeError(53 "check_type() expected a type or tuple of types for "54 "argument '{name}', but got {type_} instead.".format(55 name=name, type_=ty,56 )57 )58 # 将type_check作用在函数参数上59 return arg_process(*map(type_check, list(ty_args)), **valmap(type_check, ty_kwargs))60 @staticmethod61 def check_bound(*bd_args, **bd_kwargs):62 """63 【装饰器】64 检查输入参数是否在某一范围内;检查失败raise CheckError65 传入参数形式应为`` (min_value, max_value)``.66 ``None`` 可以作为 ``min_value`` 或 ``max_value``,相当于正负无穷67 :param bd_args: tuple范围参数68 :param bd_kwargs: dict范围参数69 :return: 70 """71 # 将bound_valid_and_check作用在函数参数上72 return arg_process(*map(bound_valid_and_check, list(bd_args)),73 **valmap(bound_valid_and_check, bd_kwargs))74 @staticmethod75 def _check_default(check_no, *names, **_unused):76 """77 【装饰器】78 检查函数参数是否有或者没有默认值;检查失败raise CheckError79 :param staticmethod: 检查有 or 没有80 :param names: 待检查参数的名称81 :param _unused: 屏蔽dict参数82 :return: 83 """84 # 屏蔽dict参数85 if _unused:86 raise TypeError("_check_default() doesn't accept dict processors")87 check_err_msg = '' if check_no else 'no '88 def decorate(func):89 # 获取默认参数字典90 arg_defaults = get_arg_defaults(func)91 for name in names:92 if name not in arg_defaults:93 # 传入了并不存在的参数名94 raise TypeError(get_func_name(func) + ' has no argument named ' + name)95 if bool(check_no) != (isinstance(arg_defaults[name], ArgNoDefault)):96 # 检查失败97 raise CheckError(98 'In ' + get_func_name(func) + ' argument {} has {}default'.format(name, check_err_msg))99 @wraps(func)100 def wrapper(*args, **kwargs):101 # 直接返回被装饰函数结果102 return func(*args, **kwargs)103 return wrapper104 return decorate105 @staticmethod106 def check_hasdefault(*names, **_unused):107 """108 【装饰器】109 检查函数参数是否有默认值;检查失败raise CheckError110 :param names: 待检查参数的名称111 :param _unused: 屏蔽dict参数112 :return: 113 """114 return ArgChecker._check_default(False, *names, **_unused)115 @staticmethod116 def check_nodefault(*names, **_unused):117 """118 【装饰器】119 检查函数参数是否没有默认值;检查失败raise CheckError120 :param names: 待检查参数的名称121 :param _unused: 屏蔽dict参数122 :return: 123 """124 return ArgChecker._check_default(True, *names, **_unused)125 @staticmethod126 def check_hasargs(func):127 """128 【装饰器】129 检查函数是否有*args参数;检查失败raise CheckError130 :param func: 传入函数对象131 :return: 132 """133 # 解包函数参数及默认值134 argspec = getargspec(func)135 spec_args = argspec.args if argspec.args else []136 defaults = argspec.defaults if argspec.defaults else ()137 if len(spec_args) - len(defaults) == 0:138 # 函数没有tuple参数139 raise CheckError(get_func_name(func) + ' has no args')140 @wraps(func)141 def wrapper(*args_inner, **kwargs):142 # 直接返回被装饰函数结果143 return func(*args_inner, **kwargs)144 return wrapper145 @staticmethod146 def check_haskwargs(func):147 """148 【装饰器149 检查函数是否有**kwargs参数;检查失败raise CheckError150 :param func: 传入函数对象151 :return: 152 """153 # 解包函数参数及默认值154 argspec = getargspec(func)155 defaults = argspec.defaults if argspec.defaults else ()156 if not defaults:157 # 函数没有dict参数158 raise CheckError(get_func_name(func) + ' has no kwargs')159 @wraps(func)160 def wrapper(*args, **kwargs):161 # 直接返回被装饰函数结果162 return func(*args, **kwargs)163 return wrapper164 @staticmethod165 def check_subset(*ss_args, **ss_kwargs):166 """167 【装饰器】168 检查输入参数是否是某一集合的子集;检查失败raise CheckError169 :param ss_args: 参数集合tuple170 :param ss_kwargs: 参数集合dict171 :return: 172 """173 # 检查是否有不合规的tuple参数174 for ss in ss_args:175 if not isinstance(ss, (list, set, type(None))):176 raise TypeError(177 "check_subset() expected a list or set or None of values"178 ", but got {subset_} or tuple instead.".format(179 subset_=str(type(ss)),180 )181 )182 # 检查是否有不合规的dict参数183 for name, ss in six.iteritems(ss_kwargs):184 if not isinstance(ss, (list, set, type(None))):185 raise TypeError(186 "check_subset() expected a list or set of values for "187 "argument '{name_}', but got {subset_} or tuple instead.".format(188 name_=name, subset_=str(type(ss)),189 )190 )191 # 将subset_check函数作用在函数参数上192 return arg_process(*map(subset_check, list(ss_args)), **valmap(subset_check, ss_kwargs))193class ReturnChecker(six.with_metaclass(ABCMeta, _NoInstances)):194 """函数返回值相关的检查类"""195 @staticmethod196 def check_type(*types, **_unused):197 """198 【装饰器】199 检查返回值类型;检查失败raise CheckError200 :param types: 类型tuple201 :param _unused: 屏蔽dict参数202 :return: 203 """204 # 屏蔽dict参数205 if _unused:206 raise TypeError("check_type() doesn't accept dict processors")207 # 检查是否有不合格的tuple参数208 for type_ in types:209 if not isinstance(type_, (type, tuple, type(None))): # tuple or 内置类型210 raise TypeError(211 "check_return_type() expected a type or tuple of types, but got {type_msg} instead.".format(212 type_msg=type_,213 )214 )215 # 将type_check函数作用在函数返回值上216 return return_process(*map(type_check, list(types)))217 @staticmethod218 def check_bound(*bounds, **_unused):219 """220 【装饰器】221 检查返回参数是否在某一范围内;检查失败raise CheckError222 传入参数形式应为`` (min_value, max_value)``.223 ``None`` 可以作为 ``min_value`` 或 ``max_value``,相当于正负无穷224 :param bounds: tuple范围参数225 :param _unused: 屏蔽dict参数226 :return: 227 """228 # 屏蔽dict参数229 if _unused:230 raise TypeError("check_bound() doesn't accept dict processors")231 # 将bound_valid_and_check函数作用在函数返回值上232 return return_process(*map(bound_valid_and_check, list(bounds)))233 @staticmethod234 def check_subset(*ss_args, **_unused):235 """236 【装饰器】237 检查输入参数是否是某一集合的子集;检查失败raise CheckError238 :param ss_args: 参数集合tuple239 :param _unused: 屏蔽dict参数240 :return: 241 """242 # 屏蔽dict参数243 if _unused:244 raise TypeError("check_subset() doesn't accept dict processors")245 # 检查传入的tuple参数246 for ss in ss_args:247 if not isinstance(ss, (list, set, type(None))):248 raise TypeError(249 "check_subset() expected a list or set or None of values"250 ", but got {subset_} or tuple instead.".format(251 subset_=str(type(ss)),252 )253 )254 # 将subset_check函数作用在函数返回值上...

Full Screen

Full Screen

libwebp.py

Source:libwebp.py Github

copy

Full Screen

1# This file was automatically generated by SWIG (http://www.swig.org).2# Version 2.0.43#4# Do not make changes to this file unless you know what you are doing--modify5# the SWIG interface file instead.6from sys import version_info7if version_info >= (2,6,0):8 def swig_import_helper():9 from os.path import dirname10 import imp11 fp = None12 try:13 fp, pathname, description = imp.find_module('_libwebp', [dirname(__file__)])14 except ImportError:15 import _libwebp16 return _libwebp17 if fp is not None:18 try:19 _mod = imp.load_module('_libwebp', fp, pathname, description)20 finally:21 fp.close()22 return _mod23 _libwebp = swig_import_helper()24 del swig_import_helper25else:26 import _libwebp27del version_info28try:29 _swig_property = property30except NameError:31 pass # Python < 2.2 doesn't have 'property'.32def _swig_setattr_nondynamic(self,class_type,name,value,static=1):33 if (name == "thisown"): return self.this.own(value)34 if (name == "this"):35 if type(value).__name__ == 'SwigPyObject':36 self.__dict__[name] = value37 return38 method = class_type.__swig_setmethods__.get(name,None)39 if method: return method(self,value)40 if (not static):41 self.__dict__[name] = value42 else:43 raise AttributeError("You cannot add attributes to %s" % self)44def _swig_setattr(self,class_type,name,value):45 return _swig_setattr_nondynamic(self,class_type,name,value,0)46def _swig_getattr(self,class_type,name):47 if (name == "thisown"): return self.this.own()48 method = class_type.__swig_getmethods__.get(name,None)49 if method: return method(self)50 raise AttributeError(name)51def _swig_repr(self):52 try: strthis = "proxy of " + self.this.__repr__()53 except: strthis = ""54 return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,)55try:56 _object = object57 _newclass = 158except AttributeError:59 class _object : pass60 _newclass = 061def WebPGetDecoderVersion():62 """WebPGetDecoderVersion() -> int"""63 return _libwebp.WebPGetDecoderVersion()64def WebPGetInfo(*args):65 """WebPGetInfo(uint8_t data) -> (width, height)"""66 return _libwebp.WebPGetInfo(*args)67def WebPDecodeRGB(*args):68 """WebPDecodeRGB(uint8_t data) -> (rgb, width, height)"""69 return _libwebp.WebPDecodeRGB(*args)70def WebPDecodeRGBA(*args):71 """WebPDecodeRGBA(uint8_t data) -> (rgb, width, height)"""72 return _libwebp.WebPDecodeRGBA(*args)73def WebPDecodeARGB(*args):74 """WebPDecodeARGB(uint8_t data) -> (rgb, width, height)"""75 return _libwebp.WebPDecodeARGB(*args)76def WebPDecodeBGR(*args):77 """WebPDecodeBGR(uint8_t data) -> (rgb, width, height)"""78 return _libwebp.WebPDecodeBGR(*args)79def WebPDecodeBGRA(*args):80 """WebPDecodeBGRA(uint8_t data) -> (rgb, width, height)"""81 return _libwebp.WebPDecodeBGRA(*args)82def WebPGetEncoderVersion():83 """WebPGetEncoderVersion() -> int"""84 return _libwebp.WebPGetEncoderVersion()85def wrap_WebPEncodeRGB(*args):86 """private, do not call directly."""87 return _libwebp.wrap_WebPEncodeRGB(*args)88def wrap_WebPEncodeBGR(*args):89 """private, do not call directly."""90 return _libwebp.wrap_WebPEncodeBGR(*args)91def wrap_WebPEncodeRGBA(*args):92 """private, do not call directly."""93 return _libwebp.wrap_WebPEncodeRGBA(*args)94def wrap_WebPEncodeBGRA(*args):95 """private, do not call directly."""96 return _libwebp.wrap_WebPEncodeBGRA(*args)97def wrap_WebPEncodeLosslessRGB(*args):98 """private, do not call directly."""99 return _libwebp.wrap_WebPEncodeLosslessRGB(*args)100def wrap_WebPEncodeLosslessBGR(*args):101 """private, do not call directly."""102 return _libwebp.wrap_WebPEncodeLosslessBGR(*args)103def wrap_WebPEncodeLosslessRGBA(*args):104 """private, do not call directly."""105 return _libwebp.wrap_WebPEncodeLosslessRGBA(*args)106def wrap_WebPEncodeLosslessBGRA(*args):107 """private, do not call directly."""108 return _libwebp.wrap_WebPEncodeLosslessBGRA(*args)109_UNUSED = 1110def WebPEncodeRGB(rgb, width, height, stride, quality_factor):111 """WebPEncodeRGB(uint8_t rgb, int width, int height, int stride, float quality_factor) -> lossy_webp"""112 webp = wrap_WebPEncodeRGB(113 rgb, _UNUSED, _UNUSED, width, height, stride, quality_factor)114 if len(webp[0]) == 0:115 return None116 return webp[0]117def WebPEncodeRGBA(rgb, width, height, stride, quality_factor):118 """WebPEncodeRGBA(uint8_t rgb, int width, int height, int stride, float quality_factor) -> lossy_webp"""119 webp = wrap_WebPEncodeRGBA(120 rgb, _UNUSED, _UNUSED, width, height, stride, quality_factor)121 if len(webp[0]) == 0:122 return None123 return webp[0]124def WebPEncodeBGR(rgb, width, height, stride, quality_factor):125 """WebPEncodeBGR(uint8_t rgb, int width, int height, int stride, float quality_factor) -> lossy_webp"""126 webp = wrap_WebPEncodeBGR(127 rgb, _UNUSED, _UNUSED, width, height, stride, quality_factor)128 if len(webp[0]) == 0:129 return None130 return webp[0]131def WebPEncodeBGRA(rgb, width, height, stride, quality_factor):132 """WebPEncodeBGRA(uint8_t rgb, int width, int height, int stride, float quality_factor) -> lossy_webp"""133 webp = wrap_WebPEncodeBGRA(134 rgb, _UNUSED, _UNUSED, width, height, stride, quality_factor)135 if len(webp[0]) == 0:136 return None137 return webp[0]138def WebPEncodeLosslessRGB(rgb, width, height, stride):139 """WebPEncodeLosslessRGB(uint8_t rgb, int width, int height, int stride) -> lossless_webp"""140 webp = wrap_WebPEncodeLosslessRGB(rgb, _UNUSED, _UNUSED, width, height, stride)141 if len(webp[0]) == 0:142 return None143 return webp[0]144def WebPEncodeLosslessRGBA(rgb, width, height, stride):145 """WebPEncodeLosslessRGBA(uint8_t rgb, int width, int height, int stride) -> lossless_webp"""146 webp = wrap_WebPEncodeLosslessRGBA(rgb, _UNUSED, _UNUSED, width, height, stride)147 if len(webp[0]) == 0:148 return None149 return webp[0]150def WebPEncodeLosslessBGR(rgb, width, height, stride):151 """WebPEncodeLosslessBGR(uint8_t rgb, int width, int height, int stride) -> lossless_webp"""152 webp = wrap_WebPEncodeLosslessBGR(rgb, _UNUSED, _UNUSED, width, height, stride)153 if len(webp[0]) == 0:154 return None155 return webp[0]156def WebPEncodeLosslessBGRA(rgb, width, height, stride):157 """WebPEncodeLosslessBGRA(uint8_t rgb, int width, int height, int stride) -> lossless_webp"""158 webp = wrap_WebPEncodeLosslessBGRA(rgb, _UNUSED, _UNUSED, width, height, stride)159 if len(webp[0]) == 0:160 return None161 return webp[0]...

Full Screen

Full Screen

SAC.py

Source:SAC.py Github

copy

Full Screen

1def inWords(n):2 return 4 * n3def openSAC(file):4 pass5# floats (word 0-69)6HdrFloats = ["DELTA", "DEPMIN", "DEPMAX", "SCALE", "ODELTA",7 "B", "E", "O", "A", "_INTERNAL",8 "T0", "T1", "T2", "T3", "T4",9 "T5", "T6", "T7", "T8", "T9",10 "F", "RESP0", "RESP1", "RESP2", "RESP3",11 "RESP4", "RESP5", "RESP6", "RESP7", "RESP8",12 "RESP9", "STLA", "STLO", "STEL", "STDP",13 "EVLA", "EVLO", "EVEL", "EVDP", "MAG",14 "USER0", "USER1", "USER2", "USER3", "USER4",15 "USER5", "USER6", "USER7", "USER8", "USER9",16 "DIST", "AZ", "BAZ", "GCARC", "_INTERNAL",17 "_INTERNAL", "DEPMEN", "CMPAZ", "CMPINC", "XMINIMUM",18 "XMAXIMUM", "YMINIMUM", "YMAXIMUM", "_UNUSED", "_UNUSED",19 "_UNUSED", "_UNUSED", "_UNUSED", "_UNUSED", "_UNUSED"]20assert len(HdrFloats) == 7021# integers and enumerated (words 70-104)22HdrInts = ["NZYEAR", "NZJDAY", "NZHOUR", "NZMIN", "NZSEC",23 "NZMSEC", "NVHDR", "NORID", "NEVID", "NPTS",24 "_INTERNAL", "NWFID", "NXSIZE", "NYSIZE", "_UNUSED",25 "IFTYPE", "IDEP", "IZTYPE", "_UNUSED", "IINST",26 "ISTREG", "IEVREG", "IEVTYP", "IQUAL", "ISYNTH",27 "IMAGTYP", "IMAGSRC", "_UNUSED", "_UNUSED", "_UNUSED",28 "_UNUSED", "_UNUSED", "_UNUSED", "_UNUSED", "_UNUSED"]29assert len(HdrInts) == 3530# logical (boolean) (words 105-109)31HdrLogicals = ["LEVEN", "LPSPOL", "LOVROK", "LCALDA", "_UNUSED"]32assert len(HdrLogicals) == 533# alphanumeric (each is 2 words [8 ASCII characters] big)34# (KEVNM takes two slots as KEVNM_1, KEVNM_2)35HdrTexts = ["KSTNM", "KEVNM_1", "KEVNM_2",36 "KHOLE", "KO", "KA",37 "KT0", "KT1", "KT2",38 "KT3", "KT4", "KT5",39 "KT6", "KT7", "KT8",40 "KT9", "KF", "KUSER0",41 "KUSER1", "KUSER2", "KCMPNM",42 "KNETWK", "KDATRD", "KINST"]43assert len(HdrTexts) == 2444import struct45HEADER_SIZE = inWords(158)46def headerVersion(raw_header):47 """Returns a tuple of the (version, big-endian) or (None, None)48 49 nvhdr should be loaded from a SAC file at NVHDR_LOCATION.50 """51 _valid_version = range(1, 20)52 def valid_version(x):53 return x in _valid_version54 nvhdr_string = raw_header[inWords(76):inWords(77)]55 if len(nvhdr_string) != 4:56 raise ValueError, "nvhdr_string must be 4 bytes long"57 le_ver = struct.unpack("<i", nvhdr_string)[0]58 be_ver = struct.unpack(">i", nvhdr_string)[0]59 if valid_version(le_ver) and valid_version(be_ver):60 # can't decide (I don't even know if this can happen)61 return (None, None)62 if valid_version(le_ver):63 return (le_ver, False)64 if valid_version(be_ver):65 return (be_ver, True)66 else:67 return (None, None)68class Header():69 def __init__(self, raw_header):70 data = {}71 self.data = data72 def header_range(start, end):73 return raw_header[inWords(start):inWords(end+1)]74 required_size = inWords(158)75 if len(raw_header) != required_size:76 raise ValueError, "header size error (size=%d)" % len(raw_header)77 (version, big_endian) = headerVersion(raw_header)78 if not version:79 raise ValueError, "invalid header format"80 if big_endian:81 endian = ">"82 else:83 endian = "<"84 self.version = version85 self.big_endian = big_endian86 floats = struct.unpack(endian + "70f", header_range(0, 69))87 for (name, val) in zip(HdrFloats, floats):88 data[name] = val89 # integers, enumerated, and logicals90 ints = struct.unpack(endian + "40i", header_range(70, 109))91 for (name, val) in zip(HdrInts + HdrLogicals, ints):92 data[name] = val93 94 text_data = header_range(110, 157)95 for (name, index) in zip(HdrTexts, range(0, 4 * 24, 4)):96 data[name] = text_data[index:index+4]97 data["KEVNM"] = data["KEVNM_1"] + data["KEVNM_2"]98class Reader():99 def __init__(self, file):100 header_data = file.read(inWords(158))101 self.header = Header(header_data)102 npts = self.header.data["NPTS"]...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Slash automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful