Best Python code snippet using slash
inttype.py
Source:inttype.py
...9 DIRECTIONS = [Parameter.DIRECTION_IN]10 CTYPES = ['int', 'int32_t']11 def convert_c_to_python(self, wrapper):12 assert isinstance(wrapper, ReverseWrapperBase)13 wrapper.build_params.add_parameter('i', [self.value])14 def convert_python_to_c(self, wrapper):15 assert isinstance(wrapper, ForwardWrapperBase)16 name = wrapper.declarations.declare_variable(self.ctype_no_const, self.name, self.default_value)17 wrapper.parse_params.add_parameter('i', ['&'+name], self.name, optional=bool(self.default_value))18 wrapper.call_params.append(name)19class UnsignedIntParam(Parameter):20 DIRECTIONS = [Parameter.DIRECTION_IN]21 CTYPES = ['unsigned int', 'uint32_t']22 def convert_c_to_python(self, wrapper):23 assert isinstance(wrapper, ReverseWrapperBase)24 wrapper.build_params.add_parameter('N', ["PyLong_FromUnsignedLong(%s)" % self.value])25 def convert_python_to_c(self, wrapper):26 assert isinstance(wrapper, ForwardWrapperBase)27 name = wrapper.declarations.declare_variable('unsigned int', self.name, self.default_value)28 wrapper.parse_params.add_parameter('I', ['&'+name], self.name, optional=bool(self.default_value))29 wrapper.call_params.append(name)30class UnsignedIntPtrParam(PointerParameter):31 DIRECTIONS = [Parameter.DIRECTION_IN, Parameter.DIRECTION_OUT, Parameter.DIRECTION_INOUT]32 CTYPES = ['unsigned int*', 'uint32_t*']33 def __init__(self, ctype, name, direction=Parameter.DIRECTION_IN, is_const=False,34 default_value=None, transfer_ownership=False, array_length=None):35 super(UnsignedIntPtrParam, self).__init__(ctype, name, direction, is_const, default_value, transfer_ownership)36 self.array_length = array_length37 if transfer_ownership:38 raise NotSupportedError("%s: transfer_ownership=True not yet implemented." % ctype)39 def convert_c_to_python(self, wrapper):40 if self.direction & self.DIRECTION_IN:41 wrapper.build_params.add_parameter('I', ['*'+self.value])42 if self.direction & self.DIRECTION_OUT:43 wrapper.parse_params.add_parameter('I', [self.value], self.name)44 def convert_python_to_c(self, wrapper):45 #assert self.ctype == 'unsigned int*'46 if self.array_length is None:47 name = wrapper.declarations.declare_variable(str(self.type_traits.target), self.name)48 wrapper.call_params.append('&'+name)49 if self.direction & self.DIRECTION_IN:50 wrapper.parse_params.add_parameter('I', ['&'+name], self.name)51 if self.direction & self.DIRECTION_OUT:52 wrapper.build_params.add_parameter('I', [name])53 else: # complicated code path to deal with arrays...54 name = wrapper.declarations.declare_variable(str(self.type_traits.target), self.name, array="[%i]" % self.array_length)55 py_list = wrapper.declarations.declare_variable("PyObject*", "py_list")56 idx = wrapper.declarations.declare_variable("int", "idx")57 wrapper.call_params.append(name)58 if self.direction & self.DIRECTION_IN:59 elem = wrapper.declarations.declare_variable("PyObject*", "element")60 wrapper.parse_params.add_parameter('O!', ['&PyList_Type', '&'+py_list], self.name)61 wrapper.before_call.write_error_check(62 'PyList_Size(%s) != %i' % (py_list, self.array_length),63 'PyErr_SetString(PyExc_TypeError, "Parameter `%s\' must be a list of %i ints/longs");'64 % (self.name, self.array_length))65 wrapper.before_call.write_code(66 "for (%s = 0; %s < %i; %s++) {" % (idx, idx, self.array_length, idx))67 wrapper.before_call.indent()68 wrapper.before_call.write_code("%(elem)s = PyList_GET_ITEM(%(py_list)s, %(idx)s);" % vars())69 wrapper.before_call.write_error_check(70 '!(PyInt_Check(%(elem)s) || PyLong_Check(%(elem)s))',71 'PyErr_SetString(PyExc_TypeError, "Parameter `%s\' must be a list of %i ints / longs");'72 % (self.name, self.array_length))73 wrapper.before_call.write_code("%(name)s[%(idx)s] = PyLong_AsUnsignedInt(%(elem)s);" % vars())74 wrapper.before_call.unindent()75 wrapper.before_call.write_code('}')76 if self.direction & self.DIRECTION_OUT:77 wrapper.after_call.write_code("%s = PyList_New(%i);" % (py_list, self.array_length))78 wrapper.after_call.write_code(79 "for (%s = 0; %s < %i; %s++) {" % (idx, idx, self.array_length, idx))80 wrapper.after_call.indent()81 wrapper.after_call.write_code("PyList_SET_ITEM(%(py_list)s, %(idx)s, PyLong_FromUnsignedLong(%(name)s[%(idx)s]));"82 % vars())83 wrapper.after_call.unindent()84 wrapper.after_call.write_code('}')85 wrapper.build_params.add_parameter("N", [py_list])86class IntReturn(ReturnValue):87 CTYPES = ['int', 'int32_t']88 def get_c_error_return(self):89 return "return INT_MIN;"90 91 def convert_python_to_c(self, wrapper):92 wrapper.parse_params.add_parameter("i", ["&"+self.value], prepend=True)93 def convert_c_to_python(self, wrapper):94 wrapper.build_params.add_parameter("i", [self.value], prepend=True)95class UnsignedIntReturn(ReturnValue):96 CTYPES = ['unsigned int', 'uint32_t']97 def get_c_error_return(self):98 return "return 0;"99 100 def convert_python_to_c(self, wrapper):101 wrapper.parse_params.add_parameter("I", ["&"+self.value], prepend=True)102 def convert_c_to_python(self, wrapper):103 wrapper.build_params.add_parameter('N', ["PyLong_FromUnsignedLong(%s)" % self.value], prepend=True)104class IntPtrParam(PointerParameter):105 DIRECTIONS = [Parameter.DIRECTION_IN, Parameter.DIRECTION_OUT,106 Parameter.DIRECTION_IN|Parameter.DIRECTION_OUT]107 CTYPES = ['int*']108 def __init__(self, ctype, name, direction=None, is_const=None, transfer_ownership=None):109 if direction is None:110 if is_const:111 direction = Parameter.DIRECTION_IN112 else:113 raise TypeConfigurationError("direction not given")114 115 super(IntPtrParam, self).__init__(ctype, name, direction, is_const, transfer_ownership)116 117 def convert_c_to_python(self, wrapper):118 if self.direction & self.DIRECTION_IN:119 wrapper.build_params.add_parameter('i', ['*'+self.value])120 if self.direction & self.DIRECTION_OUT:121 wrapper.parse_params.add_parameter("i", [self.value], self.name)122 def convert_python_to_c(self, wrapper):123 name = wrapper.declarations.declare_variable(self.ctype_no_const[:-1], self.name)124 wrapper.call_params.append('&'+name)125 if self.direction & self.DIRECTION_IN:126 wrapper.parse_params.add_parameter('i', ['&'+name], self.name)127 if self.direction & self.DIRECTION_OUT:128 wrapper.build_params.add_parameter("i", [name])129 130class IntRefParam(Parameter):131 DIRECTIONS = [Parameter.DIRECTION_IN, Parameter.DIRECTION_OUT,132 Parameter.DIRECTION_IN|Parameter.DIRECTION_OUT]133 CTYPES = ['int&']134 135 def convert_c_to_python(self, wrapper):136 if self.direction & self.DIRECTION_IN:137 wrapper.build_params.add_parameter('i', [self.value])138 if self.direction & self.DIRECTION_OUT:139 wrapper.parse_params.add_parameter("i", [self.value], self.name)140 def convert_python_to_c(self, wrapper):141 #assert self.ctype == 'int&'142 name = wrapper.declarations.declare_variable(self.ctype_no_const[:-1], self.name)143 wrapper.call_params.append(name)144 if self.direction & self.DIRECTION_IN:145 wrapper.parse_params.add_parameter('i', ['&'+name], self.name)146 if self.direction & self.DIRECTION_OUT:147 wrapper.build_params.add_parameter("i", [name])148class UnsignedIntRefParam(Parameter):149 DIRECTIONS = [Parameter.DIRECTION_IN, Parameter.DIRECTION_OUT,150 Parameter.DIRECTION_IN|Parameter.DIRECTION_OUT]151 CTYPES = ['unsigned int&', 'unsigned &']152 153 def convert_c_to_python(self, wrapper):154 if self.direction & self.DIRECTION_IN:155 wrapper.build_params.add_parameter('I', [self.value])156 if self.direction & self.DIRECTION_OUT:157 wrapper.parse_params.add_parameter("I", [self.value], self.name)158 def convert_python_to_c(self, wrapper):159 #assert self.ctype == 'int&'160 name = wrapper.declarations.declare_variable(self.ctype_no_const[:-1], self.name)161 wrapper.call_params.append(name)162 if self.direction & self.DIRECTION_IN:163 wrapper.parse_params.add_parameter('I', ['&'+name], self.name)164 if self.direction & self.DIRECTION_OUT:165 wrapper.build_params.add_parameter("I", [name])166class UInt16Return(ReturnValue):167 CTYPES = ['uint16_t', 'unsigned short', 'unsigned short int', 'short unsigned int']168 def get_c_error_return(self):169 return "return 0;"170 171 def convert_python_to_c(self, wrapper):172 tmp_var = wrapper.declarations.declare_variable("int", "tmp")173 wrapper.parse_params.add_parameter("i", ["&"+tmp_var], prepend=True)174 wrapper.after_call.write_error_check('%s > 0xffff' % tmp_var,175 'PyErr_SetString(PyExc_ValueError, "Out of range");')176 wrapper.after_call.write_code(177 "%s = %s;" % (self.value, tmp_var))178 def convert_c_to_python(self, wrapper):179 wrapper.build_params.add_parameter("i", [self.value], prepend=True)180class Int16Return(ReturnValue):181 CTYPES = ['int16_t', 'short', 'short int']182 def get_c_error_return(self):183 return "return 0;"184 185 def convert_python_to_c(self, wrapper):186 tmp_var = wrapper.declarations.declare_variable("int", "tmp")187 wrapper.parse_params.add_parameter("i", ["&"+tmp_var], prepend=True)188 wrapper.after_call.write_error_check('%s > 32767 || %s < -32768' % (tmp_var, tmp_var),189 'PyErr_SetString(PyExc_ValueError, "Out of range");')190 wrapper.after_call.write_code(191 "%s = %s;" % (self.value, tmp_var))192 def convert_c_to_python(self, wrapper):193 wrapper.build_params.add_parameter("i", [self.value], prepend=True)194class UInt16Param(Parameter):195 DIRECTIONS = [Parameter.DIRECTION_IN]196 CTYPES = ['uint16_t', 'unsigned short', 'unsigned short int']197 def convert_c_to_python(self, wrapper):198 assert isinstance(wrapper, ReverseWrapperBase)199 wrapper.build_params.add_parameter('i', ["(int) "+self.value])200 def convert_python_to_c(self, wrapper):201 assert isinstance(wrapper, ForwardWrapperBase)202 name = wrapper.declarations.declare_variable("int", self.name, self.default_value)203 wrapper.parse_params.add_parameter('i', ['&'+name], self.name, optional=bool(self.default_value))204 wrapper.before_call.write_error_check('%s > 0xffff' % name,205 'PyErr_SetString(PyExc_ValueError, "Out of range");')206 wrapper.call_params.append(name)207class UInt16RefParam(Parameter):208 DIRECTIONS = [Parameter.DIRECTION_IN, Parameter.DIRECTION_INOUT, Parameter.DIRECTION_OUT]209 CTYPES = ['uint16_t&', 'unsigned short&', 'unsigned short int&', 'short unsigned&', 'short unsigned int&']210 def convert_c_to_python(self, wrapper):211 assert isinstance(wrapper, ReverseWrapperBase)212 if self.direction & self.DIRECTION_IN:213 wrapper.build_params.add_parameter('H', [self.value])214 if self.direction & self.DIRECTION_OUT:215 wrapper.parse_params.add_parameter("H", [self.value], self.name)216 def convert_python_to_c(self, wrapper):217 name = wrapper.declarations.declare_variable(self.ctype_no_const[:-1], self.name)218 wrapper.call_params.append(name)219 if self.direction & self.DIRECTION_IN:220 wrapper.parse_params.add_parameter('H', ['&'+name], self.name)221 if self.direction & self.DIRECTION_OUT:222 wrapper.build_params.add_parameter("H", [name])223class Int16Param(Parameter):224 DIRECTIONS = [Parameter.DIRECTION_IN]225 CTYPES = ['int16_t', 'short', 'short int']226 def convert_c_to_python(self, wrapper):227 assert isinstance(wrapper, ReverseWrapperBase)228 wrapper.build_params.add_parameter('i', ["(int) "+self.value])229 def convert_python_to_c(self, wrapper):230 assert isinstance(wrapper, ForwardWrapperBase)231 name = wrapper.declarations.declare_variable("int", self.name, self.default_value)232 wrapper.parse_params.add_parameter('i', ['&'+name], self.name, optional=bool(self.default_value))233 wrapper.before_call.write_error_check('%s > 0x7fff' % name,234 'PyErr_SetString(PyExc_ValueError, "Out of range");')235 wrapper.call_params.append(name)236class Int16RefParam(Parameter):237 DIRECTIONS = [Parameter.DIRECTION_IN, Parameter.DIRECTION_INOUT, Parameter.DIRECTION_OUT]238 CTYPES = ['int16_t&', 'short&', 'short int&']239 def convert_c_to_python(self, wrapper):240 assert isinstance(wrapper, ReverseWrapperBase)241 if self.direction & self.DIRECTION_IN:242 wrapper.build_params.add_parameter('h', [self.value])243 if self.direction & self.DIRECTION_OUT:244 wrapper.parse_params.add_parameter("h", [self.value], self.name)245 def convert_python_to_c(self, wrapper):246 name = wrapper.declarations.declare_variable(self.ctype_no_const[:-1], self.name)247 wrapper.call_params.append(name)248 if self.direction & self.DIRECTION_IN:249 wrapper.parse_params.add_parameter('h', ['&'+name], self.name)250 if self.direction & self.DIRECTION_OUT:251 wrapper.build_params.add_parameter("h", [name])252class UInt8Param(Parameter):253 DIRECTIONS = [Parameter.DIRECTION_IN]254 CTYPES = ['uint8_t', 'unsigned char', 'char unsigned']255 def convert_c_to_python(self, wrapper):256 assert isinstance(wrapper, ReverseWrapperBase)257 wrapper.build_params.add_parameter('i', ["(int) "+self.value])258 def convert_python_to_c(self, wrapper):259 assert isinstance(wrapper, ForwardWrapperBase)260 name = wrapper.declarations.declare_variable("int", self.name, self.default_value)261 wrapper.parse_params.add_parameter('i', ['&'+name], self.name, optional=bool(self.default_value))262 wrapper.before_call.write_error_check('%s > 0xff' % name,263 'PyErr_SetString(PyExc_ValueError, "Out of range");')264 wrapper.call_params.append(name)265class UInt8RefParam(Parameter):266 DIRECTIONS = [Parameter.DIRECTION_IN, Parameter.DIRECTION_INOUT, Parameter.DIRECTION_OUT]267 CTYPES = ['uint8_t&', 'unsigned char&', 'char unsigned&']268 def convert_c_to_python(self, wrapper):269 assert isinstance(wrapper, ReverseWrapperBase)270 if self.direction & self.DIRECTION_IN:271 wrapper.build_params.add_parameter('B', [self.value])272 if self.direction & self.DIRECTION_OUT:273 wrapper.parse_params.add_parameter("B", [self.value], self.name)274 def convert_python_to_c(self, wrapper):275 name = wrapper.declarations.declare_variable(self.ctype_no_const[:-1], self.name)276 wrapper.call_params.append(name)277 if self.direction & self.DIRECTION_IN:278 wrapper.parse_params.add_parameter('B', ['&'+name], self.name)279 if self.direction & self.DIRECTION_OUT:280 wrapper.build_params.add_parameter("B", [name])281class UInt8Return(ReturnValue):282 CTYPES = ['uint8_t', 'unsigned char', 'char unsigned']283 def get_c_error_return(self):284 return "return 0;"285 286 def convert_python_to_c(self, wrapper):287 tmp_var = wrapper.declarations.declare_variable("int", "tmp")288 wrapper.parse_params.add_parameter("i", ["&"+tmp_var], prepend=True)289 wrapper.after_call.write_error_check('%s > 0xff' % tmp_var,290 'PyErr_SetString(PyExc_ValueError, "Out of range");')291 wrapper.after_call.write_code(292 "%s = %s;" % (self.value, tmp_var))293 def convert_c_to_python(self, wrapper):294 wrapper.build_params.add_parameter("i", ['(int)' + self.value], prepend=True)295class Int8Param(Parameter):296 DIRECTIONS = [Parameter.DIRECTION_IN]297 CTYPES = ['int8_t', 'signed char', 'char signed']298 def convert_c_to_python(self, wrapper):299 assert isinstance(wrapper, ReverseWrapperBase)300 wrapper.build_params.add_parameter('i', ["(int) "+self.value])301 def convert_python_to_c(self, wrapper):302 assert isinstance(wrapper, ForwardWrapperBase)303 name = wrapper.declarations.declare_variable("int", self.name, self.default_value)304 wrapper.parse_params.add_parameter('i', ['&'+name], self.name, optional=bool(self.default_value))305 wrapper.before_call.write_error_check('%s > 0x7f' % name,306 'PyErr_SetString(PyExc_ValueError, "Out of range");')307 wrapper.call_params.append(name)308class Int8RefParam(Parameter):309 DIRECTIONS = [Parameter.DIRECTION_IN, Parameter.DIRECTION_INOUT, Parameter.DIRECTION_OUT]310 CTYPES = ['int8_t&', 'signed char &', 'char signed&']311 def convert_c_to_python(self, wrapper):312 assert isinstance(wrapper, ReverseWrapperBase)313 if self.direction & self.DIRECTION_IN:314 wrapper.build_params.add_parameter('b', [self.value])315 if self.direction & self.DIRECTION_OUT:316 wrapper.parse_params.add_parameter("b", [self.value], self.name)317 def convert_python_to_c(self, wrapper):318 name = wrapper.declarations.declare_variable(self.ctype_no_const[:-1], self.name)319 wrapper.call_params.append(name)320 if self.direction & self.DIRECTION_IN:321 wrapper.parse_params.add_parameter('b', ['&'+name], self.name)322 if self.direction & self.DIRECTION_OUT:323 wrapper.build_params.add_parameter("b", [name])324class Int8Return(ReturnValue):325 CTYPES = ['int8_t', 'signed char']326 def get_c_error_return(self):327 return "return 0;"328 329 def convert_python_to_c(self, wrapper):330 tmp_var = wrapper.declarations.declare_variable("int", "tmp")331 wrapper.parse_params.add_parameter("i", ["&"+tmp_var], prepend=True)332 wrapper.after_call.write_error_check('%s > 128 || %s < -127' % (tmp_var, tmp_var),333 'PyErr_SetString(PyExc_ValueError, "Out of range");')334 wrapper.after_call.write_code(335 "%s = %s;" % (self.value, tmp_var))336 def convert_c_to_python(self, wrapper):337 wrapper.build_params.add_parameter("i", [self.value], prepend=True)338class UnsignedLongLongParam(Parameter):339 DIRECTIONS = [Parameter.DIRECTION_IN]340 CTYPES = ['unsigned long long', 'uint64_t', 'unsigned long long int', 'long long unsigned int', 'long long unsigned']341 def get_ctype_without_ref(self):342 return str(self.type_traits.ctype_no_const)343 def convert_c_to_python(self, wrapper):344 assert isinstance(wrapper, ReverseWrapperBase)345 wrapper.build_params.add_parameter('K', [self.value])346 def convert_python_to_c(self, wrapper):347 assert isinstance(wrapper, ForwardWrapperBase)348 name = wrapper.declarations.declare_variable(self.get_ctype_without_ref(), self.name, self.default_value)349 wrapper.parse_params.add_parameter('K', ['&'+name], self.name, optional=bool(self.default_value))350 wrapper.call_params.append(name)351class UnsignedLongLongRefParam(UnsignedLongLongParam):352 DIRECTIONS = [Parameter.DIRECTION_IN]353 CTYPES = ['unsigned long long&', 'uint64_t&', 'long long unsigned int&']354 def get_ctype_without_ref(self):355 assert self.type_traits.target is not None356 return str(self.type_traits.target)357class UnsignedLongLongReturn(ReturnValue):358 CTYPES = ['unsigned long long', 'uint64_t', 'long long unsigned int']359 def get_c_error_return(self):360 return "return 0;"361 362 def convert_python_to_c(self, wrapper):363 wrapper.parse_params.add_parameter("K", ["&"+self.value], prepend=True)364 def convert_c_to_python(self, wrapper):365 wrapper.build_params.add_parameter("K", [self.value], prepend=True)366class UnsignedLongParam(Parameter):367 DIRECTIONS = [Parameter.DIRECTION_IN]368 CTYPES = ['unsigned long', 'unsigned long int', 'long unsigned', 'long unsigned int']369 def get_ctype_without_ref(self):370 return str(self.type_traits.ctype_no_const)371 def convert_c_to_python(self, wrapper):372 assert isinstance(wrapper, ReverseWrapperBase)373 wrapper.build_params.add_parameter('k', [self.value])374 def convert_python_to_c(self, wrapper):375 assert isinstance(wrapper, ForwardWrapperBase)376 name = wrapper.declarations.declare_variable(self.get_ctype_without_ref(), self.name, self.default_value)377 wrapper.parse_params.add_parameter('k', ['&'+name], self.name, optional=bool(self.default_value))378 wrapper.call_params.append(name)379class UnsignedLongRefParam(UnsignedLongParam):380 DIRECTIONS = [Parameter.DIRECTION_IN]381 CTYPES = ['unsigned long&', 'long unsigned&', 'long unsigned int&', 'unsigned long int&']382 def get_ctype_without_ref(self):383 assert self.type_traits.target is not None384 return str(self.type_traits.target)385class UnsignedLongReturn(ReturnValue):386 CTYPES = ['unsigned long', 'long unsigned int']387 def get_c_error_return(self):388 return "return 0;"389 390 def convert_python_to_c(self, wrapper):391 wrapper.parse_params.add_parameter("k", ["&"+self.value], prepend=True)392 def convert_c_to_python(self, wrapper):393 wrapper.build_params.add_parameter("k", [self.value], prepend=True)394class LongParam(Parameter):395 DIRECTIONS = [Parameter.DIRECTION_IN]396 CTYPES = ['signed long', 'signed long int', 'long', 'long int', 'long signed', 'long signed int']397 def get_ctype_without_ref(self):398 return str(self.type_traits.ctype_no_const)399 def convert_c_to_python(self, wrapper):400 assert isinstance(wrapper, ReverseWrapperBase)401 wrapper.build_params.add_parameter('l', [self.value])402 def convert_python_to_c(self, wrapper):403 assert isinstance(wrapper, ForwardWrapperBase)404 name = wrapper.declarations.declare_variable(self.get_ctype_without_ref(), self.name, self.default_value)405 wrapper.parse_params.add_parameter('l', ['&'+name], self.name, optional=bool(self.default_value))406 wrapper.call_params.append(name)407class LongRefParam(LongParam):408 DIRECTIONS = [Parameter.DIRECTION_IN]409 CTYPES = ['signed long&', 'long signed&', 'long&', 'long int&', 'long signed int&', 'signed long int&']410 def get_ctype_without_ref(self):411 assert self.type_traits.target is not None412 return str(self.type_traits.target)413class LongReturn(ReturnValue):414 CTYPES = ['signed long', 'long signed int', 'long', 'long int']415 def get_c_error_return(self):416 return "return 0;"417 418 def convert_python_to_c(self, wrapper):419 wrapper.parse_params.add_parameter("l", ["&"+self.value], prepend=True)420 def convert_c_to_python(self, wrapper):421 wrapper.build_params.add_parameter("l", [self.value], prepend=True)422class SizeTReturn(ReturnValue):423 CTYPES = ['size_t',]424 def get_c_error_return(self):425 return "return 0;"426 427 def convert_python_to_c(self, wrapper):428 # using the intermediate variable is not always necessary but429 # it's safer this way in case of weird platforms where430 # sizeof(size_t) != sizeof(unsigned PY_LONG_LONG).431 name = wrapper.declarations.declare_variable("unsigned PY_LONG_LONG", "retval_tmp", self.value)432 wrapper.parse_params.add_parameter("K", ["&"+name], prepend=True)433 wrapper.after_call.write_code("retval = %s;" % (name))434 def convert_c_to_python(self, wrapper):435 wrapper.build_params.add_parameter("K", ["((unsigned PY_LONG_LONG) %s)" % self.value], prepend=True)436class SizeTParam(Parameter):437 DIRECTIONS = [Parameter.DIRECTION_IN]438 CTYPES = ['size_t']439 def get_ctype_without_ref(self):440 return str(self.type_traits.ctype_no_const)441 def convert_c_to_python(self, wrapper):442 assert isinstance(wrapper, ReverseWrapperBase)443 wrapper.build_params.add_parameter('K', ["((unsigned PY_LONG_LONG) %s)" % self.value])444 def convert_python_to_c(self, wrapper):445 assert isinstance(wrapper, ForwardWrapperBase)446 name = wrapper.declarations.declare_variable("unsigned PY_LONG_LONG", self.name, self.default_value)447 wrapper.parse_params.add_parameter('K', ['&'+name], self.name, optional=bool(self.default_value))448 wrapper.call_params.append(name)449class LongLongParam(Parameter):450 DIRECTIONS = [Parameter.DIRECTION_IN]451 CTYPES = ['long long', 'int64_t', 'long long int']452 def get_ctype_without_ref(self):453 return str(self.type_traits.ctype_no_const)454 def convert_c_to_python(self, wrapper):455 assert isinstance(wrapper, ReverseWrapperBase)456 wrapper.build_params.add_parameter('L', [self.value])457 def convert_python_to_c(self, wrapper):458 assert isinstance(wrapper, ForwardWrapperBase)459 name = wrapper.declarations.declare_variable(self.get_ctype_without_ref(), self.name, self.default_value)460 wrapper.parse_params.add_parameter('L', ['&'+name], self.name, optional=bool(self.default_value))461 wrapper.call_params.append(name)462class LongLongRefParam(LongLongParam):463 DIRECTIONS = [Parameter.DIRECTION_IN] # other directions not yet implemented464 CTYPES = ['long long&', 'int64_t&', 'long long int&']465 def get_ctype_without_ref(self):466 assert self.type_traits.target is not None467 return str(self.type_traits.target)468class LongLongReturn(ReturnValue):469 CTYPES = ['long long', 'int64_t', 'long long int']470 def get_c_error_return(self):471 return "return 0;"472 473 def convert_python_to_c(self, wrapper):474 wrapper.parse_params.add_parameter("L", ["&"+self.value], prepend=True)475 def convert_c_to_python(self, wrapper):476 wrapper.build_params.add_parameter("L", [self.value], prepend=True)477class Int8PtrParam(PointerParameter):478 DIRECTIONS = [Parameter.DIRECTION_IN, Parameter.DIRECTION_OUT,479 Parameter.DIRECTION_IN|Parameter.DIRECTION_OUT]480 CTYPES = ['int8_t*']481 def __init__(self, ctype, name, direction=None, is_const=None, default_value=None, transfer_ownership=None):482 if direction is None:483 if is_const:484 direction = Parameter.DIRECTION_IN485 else:486 raise TypeConfigurationError("direction not given")487 488 super(Int8PtrParam, self).__init__(ctype, name, direction, is_const, default_value, transfer_ownership)489 490 def convert_c_to_python(self, wrapper):491 if self.direction & self.DIRECTION_IN:492 wrapper.build_params.add_parameter('b', ['*'+self.value])493 if self.direction & self.DIRECTION_OUT:494 wrapper.parse_params.add_parameter("b", [self.value], self.name)495 def convert_python_to_c(self, wrapper):496 name = wrapper.declarations.declare_variable('int8_t', self.name)497 wrapper.call_params.append('&'+name)498 if self.direction & self.DIRECTION_IN:499 wrapper.parse_params.add_parameter('b', ['&'+name], self.name)500 if self.direction & self.DIRECTION_OUT:501 wrapper.build_params.add_parameter("b", [name])502class UInt8PtrParam(PointerParameter):503 DIRECTIONS = [Parameter.DIRECTION_IN, Parameter.DIRECTION_OUT,504 Parameter.DIRECTION_IN|Parameter.DIRECTION_OUT]505 CTYPES = ['uint8_t*']506 def __init__(self, ctype, name, direction=None, is_const=None, default_value=None, transfer_ownership=None):507 if direction is None:508 if is_const:509 direction = Parameter.DIRECTION_IN510 else:511 raise TypeConfigurationError("direction not given")512 513 super(UInt8PtrParam, self).__init__(ctype, name, direction, is_const, default_value, transfer_ownership)514 515 def convert_c_to_python(self, wrapper):516 if self.direction & self.DIRECTION_IN:517 wrapper.build_params.add_parameter('B', ['*'+self.value])518 if self.direction & self.DIRECTION_OUT:519 wrapper.parse_params.add_parameter("B", [self.value], self.name)520 def convert_python_to_c(self, wrapper):521 name = wrapper.declarations.declare_variable('uint8_t', self.name)522 wrapper.call_params.append('&'+name)523 if self.direction & self.DIRECTION_IN:524 wrapper.parse_params.add_parameter('B', ['&'+name], self.name)525 if self.direction & self.DIRECTION_OUT:...
LeeNet.py
Source:LeeNet.py
1from SloppyCell.ReactionNetworks import *2net = Network('Lee2003')3net.add_compartment('extract')4net.add_parameter('Dsh0', 100, name = r'Dsh^0')5net.add_parameter('APC0', 100, name = r'APC^0')6net.add_parameter('TCF0', 15, name = r'TCF^0')7net.add_parameter('GSK0', 50, name = r'GSK^0')8net.add_species('X2', 'extract', 0)#, name=r'Dsh_a')9net.add_species('X3', 'extract', 0)#, name=r'APC^*/axin^*/GSK3')10net.add_species('X4', 'extract', 0)#, name=r'APC/axin/GSK3')11net.add_species('X9', 'extract', 0)#, name=r'\beta-catenin^*/APC^*/axin^*/GSK3')12net.add_species('X10', 'extract', 0)#, name=r'\beta-catenin^*')13net.add_species('X11', 'extract', 0)#, name=r'\beta-catenin')14net.add_species('X12', 'extract', 0)#, name=r'Axin')15#net.add_species('X5', 'extract', 'GSK0', is_constant=True)#, name=r'GSK3')16net.add_species('X5', 'extract', 'GSK0', is_constant=True)#, name=r'GSK3')17net.add_species('X1', 'extract')#, name=r'Dsh_i')18net.add_species('X6', 'extract')#, name=r'APC/axin')19net.add_species('X7', 'extract')#, name=r'APC')20net.add_species('X8', 'extract')#, name=r'\beta-catenin/APC^*/axin^*/GSK3')21net.add_species('X13', 'extract')#, name=r'TCF')22net.add_species('X14', 'extract')#, name=r'\beta-catenin/TCF')23net.add_species('X15', 'extract')#, name=r'\beta-catenin/APC')24net.add_parameter('K7', 50, name = r'K_7')25net.add_parameter('K8', 120, name = r'K_8')26net.add_parameter('K16', 30, name = r'K_16')27net.add_parameter('K17', 1200, name = r'K_17')28net.add_parameter('k1', 0.182, name = r'k_{1}')29net.add_parameter('k2', 1.82e-2, name = r'k_{2}')30net.add_parameter('k3', 5e-2, name = r'k_{3}')31net.add_parameter('k4', 0.267, name = r'k_{4}')32net.add_parameter('k5', 0.133, name = r'k_{5}')33net.add_parameter('k6', 9.09e-2, name = r'k_{6}')34net.add_parameter('km6', 0.909, name = 'k_{-6}')35net.add_parameter('k9', 206, name = r'k_{9}')36net.add_parameter('k10', 206, name = r'k_{10}')37net.add_parameter('k11', 0.417, name = r'k_{11}')38net.add_parameter('k13', 2.57e-4, name = r'k_{13}')39net.add_parameter('k15', 0.167, name = r'k_{15}')40net.add_parameter('v12', 0.423, name = r'v_{12}')41net.add_parameter('v14', 8.22e-5, name = r'v_{14}')42#net.add_parameter('k1', 0.18, name = r'k_{1}')43#net.add_parameter('k2', 1.8e-2, name = r'k_{2}')44#net.add_parameter('k3', 5e-2, name = r'k_{3}')45#net.add_parameter('k4', 0.27, name = r'k_{4}')46#net.add_parameter('k5', 0.13, name = r'k_{5}')47#net.add_parameter('k6', 9.1e-2, name = r'k_{6}')48#net.add_parameter('km6', 0.91, name = 'k_{-6}')49#net.add_parameter('k9', 210, name = r'k_{9}')50#net.add_parameter('k10', 210, name = r'k_{10}')51#net.add_parameter('k11', 0.42, name = r'k_{11}')52#net.add_parameter('k13', 2.6e-4, name = r'k_{13}')53#net.add_parameter('k15', 0.17, name = r'k_{15}')54#55#net.add_parameter('v12', 0.42, name = r'v_{12}')56#net.add_parameter('v14', 8.2e-5, name = r'v_{14}')57net.add_parameter('W', 0, is_optimizable=False)58net.add_rate_rule('X2', 'k1*W*(Dsh0-X2)-k2*X2')59net.add_rate_rule('X9', 'k9 * X8 - k10*X9')60net.add_rate_rule('X10', 'k10*X9-k11*X10')61net.add_rate_rule('X4', '-k3*X2*X4 - k4*X4 + k5*X3 + k6*X5*X6 - km6*X4')62net.add_parameter('a')63net.add_assignment_rule('a', '1+APC0*K17/(K7*(K17+X11))')64net.add_parameter('b')65net.add_assignment_rule('b', 'APC0*K17*X12/(K7*(K17+X11)**2)')66net.add_parameter('c')67net.add_assignment_rule('c', 'k3*X2*X4 - k6 * GSK0*APC0*K17*X12/(K7*(K17+X11)) + km6*X4 + v14 - k15*X12')68net.add_parameter('d')69net.add_assignment_rule('d', '1+X11/K8')70net.add_parameter('e')71net.add_assignment_rule('e', 'X3/K8')72net.add_parameter('f')73net.add_assignment_rule('f', 'k4*X4 - k5*X3 - k9*X3*X11/K8 + k10*X9')74net.add_parameter('g')75net.add_assignment_rule('g', '1+X3/K8+TCF0*K16/(K16+X11)**2 + APC0*K17/(K17+X11)**2')76net.add_parameter('h')77net.add_assignment_rule('h', 'X11/K8')78net.add_parameter('i')79net.add_assignment_rule('i', 'v12 - (k9*X3/K8 + k13)*X11')80net.add_parameter('rhsX11', name = 'rhs_{X11}')81net.add_assignment_rule('rhsX11', '(d*i - f*h)/(d*g - e*h)')82net.add_rate_rule('X11', 'rhsX11')83net.add_rate_rule('X12', '(c + rhsX11*b)/a')84net.add_rate_rule('X3', '(e*i - f*g)/(e*h - d*g)')85net.add_assignment_rule('X1', 'Dsh0 - X2')86net.add_assignment_rule('X7', 'K17*APC0/(K17+X11)')87net.add_assignment_rule('X15', 'X11*APC0/(K17+X11)')88net.add_assignment_rule('X13', 'K16*TCF0/(K16+X11)')89net.add_assignment_rule('X14', 'X11*TCF0/(K16+X11)')90net.add_assignment_rule('X8', 'X3*X11/K8')91net.add_assignment_rule('X6', 'K17*X12*APC0/(K7*(K17+X11))')92# These are just for my own monitoring purposes93net.add_parameter('BCatenin', name = r'\beta-catenin')94net.add_assignment_rule('BCatenin', 'X8+X9+X10+X11+X14+X15')95net.add_parameter('Axin', name = r'Axin')...
GenerateFilmSpecimen.py
Source:GenerateFilmSpecimen.py
1#! /usr/bin/env python32# -*- coding: utf-8 -*-3from FilmSpecimenGenerator import Config4cfg = Config()5cfg.add_parameter("sizeX", "real_t", "0", "Specimen length (x direction)")6cfg.add_parameter("sizeY", "real_t", "0", "Specimen length (y direction)")7cfg.add_parameter("sizeZ", "real_t", "0", "Specimen length (z direction)")8cfg.add_parameter("oopp", "bool", "false", "Specimen out-of-plane periodicity (0 - film, 1 - cnt material)")9cfg.add_parameter("numBlocksX", "uint_t", "1", "Number of blocks in x direction")10cfg.add_parameter("numBlocksY", "uint_t", "1", "Number of blocks in y direction")11cfg.add_parameter("numBlocksZ", "uint_t", "1", "Number of blocks in z direction")12cfg.add_parameter("min_OOP", "real_t", "0", "Out-of-plane angle minimum")13cfg.add_parameter("max_OOP", "real_t", "0", "Out-of-plane angle maximum")14cfg.add_parameter("numCNTs", "int", "0", "Number of CNTs")15cfg.add_parameter("numSegs", "int", "0", "Number of segments in a CNT")16cfg.add_parameter("spacing", "real_t", "0", "Segment half-spacing")17cfg.add_parameter("localDamping", "real_t", "0", "Local damping coefficient")18cfg.add_parameter("viscousDamping", "real_t", "0", "Viscous damping coefficient")19cfg.add_parameter("seed", "uint_t", "0", "random generator seed")20cfg.add_parameter("vdW", "int", "0", "type of vdW interaction model")21cfg.add_parameter("simulationSteps", "int", "0", "Relaxation duration")22cfg.add_parameter("saveVTKEveryNthStep", "int", "0", "timesteps between saving VTK outputs")23cfg.add_parameter("saveEnergyEveryNthStep", "int", "0", "timesteps between saving energies")24cfg.add_parameter("saveConfEveryNthStep", "int", "0", "timesteps between saving confs")25cfg.add_parameter("vtkFolder", "std::string", '"."', "Folder for VTK files")26cfg.add_parameter("energyFolder", "std::string", '"."', "Folder for energy files")27cfg.add_parameter("confFolder", "std::string", '"."', "Folder for conf files")28cfg.add_parameter("useMPIIO", "bool", "false", "Write a single file instead of one file per process")29cfg.add_parameter("sqlFile", "std::string", '"cnt.sqlite"', "database file")30cfg.add_parameter("initialConfigurationFile", "std::string", '""', "restart from checkpoint")...
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!!