How to use code method in stryker-parent

Best JavaScript code snippet using stryker-parent

ModuleNode.py

Source:ModuleNode.py Github

copy

Full Screen

...87 env.return_type = PyrexTypes.c_void_type88 self.referenced_modules = []89 self.find_referenced_modules(env, self.referenced_modules, {})90 self.sort_cdef_classes(env)91 self.generate_c_code(env, options, result)92 self.generate_h_code(env, options, result)93 self.generate_api_code(env, result)94 def has_imported_c_functions(self):95 for module in self.referenced_modules:96 for entry in module.cfunc_entries:97 if entry.defined_in_pxd:98 return 199 return 0100 def generate_h_code(self, env, options, result):101 def h_entries(entries, api=0, pxd=0):102 return [entry for entry in entries103 if ((entry.visibility == 'public') or104 (api and entry.api) or105 (pxd and entry.defined_in_pxd))]106 h_types = h_entries(env.type_entries, api=1)107 h_vars = h_entries(env.var_entries)108 h_funcs = h_entries(env.cfunc_entries)109 h_extension_types = h_entries(env.c_class_entries)110 if (h_types or h_vars or h_funcs or h_extension_types):111 result.h_file = replace_suffix(result.c_file, ".h")112 h_code = Code.CCodeWriter()113 Code.GlobalState(h_code, self)114 if options.generate_pxi:115 result.i_file = replace_suffix(result.c_file, ".pxi")116 i_code = Code.PyrexCodeWriter(result.i_file)117 else:118 i_code = None119 h_guard = Naming.h_guard_prefix + self.api_name(env)120 h_code.put_h_guard(h_guard)121 h_code.putln("")122 self.generate_type_header_code(h_types, h_code)123 if options.capi_reexport_cincludes:124 self.generate_includes(env, [], h_code)125 h_code.putln("")126 api_guard = Naming.api_guard_prefix + self.api_name(env)127 h_code.putln("#ifndef %s" % api_guard)128 h_code.putln("")129 self.generate_extern_c_macro_definition(h_code)130 if h_extension_types:131 h_code.putln("")132 for entry in h_extension_types:133 self.generate_cclass_header_code(entry.type, h_code)134 if i_code:135 self.generate_cclass_include_code(entry.type, i_code)136 if h_funcs:137 h_code.putln("")138 for entry in h_funcs:139 self.generate_public_declaration(entry, h_code, i_code)140 if h_vars:141 h_code.putln("")142 for entry in h_vars:143 self.generate_public_declaration(entry, h_code, i_code)144 h_code.putln("")145 h_code.putln("#endif /* !%s */" % api_guard)146 h_code.putln("")147 h_code.putln("#if PY_MAJOR_VERSION < 3")148 h_code.putln("PyMODINIT_FUNC init%s(void);" % env.module_name)149 h_code.putln("#else")150 h_code.putln("PyMODINIT_FUNC PyInit_%s(void);" % env.module_name)151 h_code.putln("#endif")152 h_code.putln("")153 h_code.putln("#endif /* !%s */" % h_guard)154 f = open_new_file(result.h_file)155 try:156 h_code.copyto(f)157 finally:158 f.close()159 def generate_public_declaration(self, entry, h_code, i_code):160 h_code.putln("%s %s;" % (161 Naming.extern_c_macro,162 entry.type.declaration_code(163 entry.cname, dll_linkage = "DL_IMPORT")))164 if i_code:165 i_code.putln("cdef extern %s" %166 entry.type.declaration_code(entry.cname, pyrex = 1))167 def api_name(self, env):168 return env.qualified_name.replace(".", "__")169 def generate_api_code(self, env, result):170 def api_entries(entries, pxd=0):171 return [entry for entry in entries172 if entry.api or (pxd and entry.defined_in_pxd)]173 api_vars = api_entries(env.var_entries)174 api_funcs = api_entries(env.cfunc_entries)175 api_extension_types = api_entries(env.c_class_entries)176 if api_vars or api_funcs or api_extension_types:177 result.api_file = replace_suffix(result.c_file, "_api.h")178 h_code = Code.CCodeWriter()179 Code.GlobalState(h_code, self)180 api_guard = Naming.api_guard_prefix + self.api_name(env)181 h_code.put_h_guard(api_guard)182 h_code.putln('#include "Python.h"')183 if result.h_file:184 h_code.putln('#include "%s"' % os.path.basename(result.h_file))185 if api_extension_types:186 h_code.putln("")187 for entry in api_extension_types:188 type = entry.type189 h_code.putln("static PyTypeObject *%s = 0;" % type.typeptr_cname)190 h_code.putln("#define %s (*%s)" % (191 type.typeobj_cname, type.typeptr_cname))192 if api_funcs:193 h_code.putln("")194 for entry in api_funcs:195 type = CPtrType(entry.type)196 cname = env.mangle(Naming.func_prefix, entry.name)197 h_code.putln("static %s = 0;" % type.declaration_code(cname))198 h_code.putln("#define %s %s" % (entry.name, cname))199 if api_vars:200 h_code.putln("")201 for entry in api_vars:202 type = CPtrType(entry.type)203 cname = env.mangle(Naming.varptr_prefix, entry.name)204 h_code.putln("static %s = 0;" % type.declaration_code(cname))205 h_code.putln("#define %s (*%s)" % (entry.name, cname))206 h_code.put(UtilityCode.load_as_string("PyIdentifierFromString", "ImportExport.c")[0])207 h_code.put(UtilityCode.load_as_string("ModuleImport", "ImportExport.c")[1])208 if api_vars:209 h_code.put(UtilityCode.load_as_string("VoidPtrImport", "ImportExport.c")[1])210 if api_funcs:211 h_code.put(UtilityCode.load_as_string("FunctionImport", "ImportExport.c")[1])212 if api_extension_types:213 h_code.put(UtilityCode.load_as_string("TypeImport", "ImportExport.c")[1])214 h_code.putln("")215 h_code.putln("static int import_%s(void) {" % self.api_name(env))216 h_code.putln("PyObject *module = 0;")217 h_code.putln('module = __Pyx_ImportModule("%s");' % env.qualified_name)218 h_code.putln("if (!module) goto bad;")219 for entry in api_funcs:220 cname = env.mangle(Naming.func_prefix, entry.name)221 sig = entry.type.signature_string()222 h_code.putln(223 'if (__Pyx_ImportFunction(module, "%s", (void (**)(void))&%s, "%s") < 0) goto bad;'224 % (entry.name, cname, sig))225 for entry in api_vars:226 cname = env.mangle(Naming.varptr_prefix, entry.name)227 sig = entry.type.declaration_code("")228 h_code.putln(229 'if (__Pyx_ImportVoidPtr(module, "%s", (void **)&%s, "%s") < 0) goto bad;'230 % (entry.name, cname, sig))231 h_code.putln("Py_DECREF(module); module = 0;")232 for entry in api_extension_types:233 self.generate_type_import_call(234 entry.type, h_code,235 "if (!%s) goto bad;" % entry.type.typeptr_cname)236 h_code.putln("return 0;")237 h_code.putln("bad:")238 h_code.putln("Py_XDECREF(module);")239 h_code.putln("return -1;")240 h_code.putln("}")241 h_code.putln("")242 h_code.putln("#endif /* !%s */" % api_guard)243 f = open_new_file(result.api_file)244 try:245 h_code.copyto(f)246 finally:247 f.close()248 def generate_cclass_header_code(self, type, h_code):249 h_code.putln("%s %s %s;" % (250 Naming.extern_c_macro,251 PyrexTypes.public_decl("PyTypeObject", "DL_IMPORT"),252 type.typeobj_cname))253 def generate_cclass_include_code(self, type, i_code):254 i_code.putln("cdef extern class %s.%s:" % (255 type.module_name, type.name))256 i_code.indent()257 var_entries = type.scope.var_entries258 if var_entries:259 for entry in var_entries:260 i_code.putln("cdef %s" %261 entry.type.declaration_code(entry.cname, pyrex = 1))262 else:263 i_code.putln("pass")264 i_code.dedent()265 def generate_c_code(self, env, options, result):266 modules = self.referenced_modules267 if Options.annotate or options.annotate:268 emit_linenums = False269 rootwriter = Annotate.AnnotationCCodeWriter()270 else:271 emit_linenums = options.emit_linenums272 rootwriter = Code.CCodeWriter(emit_linenums=emit_linenums, c_line_in_traceback=options.c_line_in_traceback)273 globalstate = Code.GlobalState(rootwriter, self, emit_linenums, options.common_utility_include_dir)274 globalstate.initialize_main_c_code()275 h_code = globalstate['h_code']276 self.generate_module_preamble(env, modules, h_code)277 globalstate.module_pos = self.pos278 globalstate.directives = self.directives279 globalstate.use_utility_code(refnanny_utility_code)280 code = globalstate['before_global_var']281 code.putln('#define __Pyx_MODULE_NAME "%s"' % self.full_module_name)282 code.putln("int %s%s = 0;" % (Naming.module_is_main, self.full_module_name.replace('.', '__')))283 code.putln("")284 code.putln("/* Implementation of '%s' */" % env.qualified_name)285 code = globalstate['all_the_rest']286 self.generate_cached_builtins_decls(env, code)287 self.generate_lambda_definitions(env, code)288 # generate normal variable and function definitions289 self.generate_variable_definitions(env, code)290 self.body.generate_function_definitions(env, code)291 code.mark_pos(None)292 self.generate_typeobj_definitions(env, code)293 self.generate_method_table(env, code)294 if env.has_import_star:295 self.generate_import_star(env, code)296 self.generate_pymoduledef_struct(env, code)297 # init_globals is inserted before this298 self.generate_module_init_func(modules[:-1], env, globalstate['init_module'])299 self.generate_module_cleanup_func(env, globalstate['cleanup_module'])300 if Options.embed:301 self.generate_main_method(env, globalstate['main_method'])302 self.generate_filename_table(globalstate['filename_table'])303 self.generate_declarations_for_modules(env, modules, globalstate)304 h_code.write('\n')305 for utilcode in env.utility_code_list[:]:306 globalstate.use_utility_code(utilcode)307 globalstate.finalize_main_c_code()308 f = open_new_file(result.c_file)309 try:310 rootwriter.copyto(f)311 finally:312 f.close()313 result.c_file_generated = 1314 if options.gdb_debug:315 self._serialize_lineno_map(env, rootwriter)316 if Options.annotate or options.annotate:317 self._generate_annotations(rootwriter, result)318 def _generate_annotations(self, rootwriter, result):319 self.annotate(rootwriter)320 rootwriter.save_annotation(result.main_source_file, result.c_file)321 # if we included files, additionally generate one annotation file for each322 if not self.scope.included_files:323 return324 search_include_file = self.scope.context.search_include_directories325 target_dir = os.path.abspath(os.path.dirname(result.c_file))326 for included_file in self.scope.included_files:327 target_file = os.path.abspath(os.path.join(target_dir, included_file))328 target_file_dir = os.path.dirname(target_file)329 if not target_file_dir.startswith(target_dir):330 # any other directories may not be writable => avoid trying331 continue332 source_file = search_include_file(included_file, "", self.pos, include=True)333 if not source_file:334 continue335 if target_file_dir != target_dir and not os.path.exists(target_file_dir):336 try:337 os.makedirs(target_file_dir)338 except OSError, e:339 import errno340 if e.errno != errno.EEXIST:341 raise342 rootwriter.save_annotation(source_file, target_file)343 def _serialize_lineno_map(self, env, ccodewriter):344 tb = env.context.gdb_debug_outputwriter345 markers = ccodewriter.buffer.allmarkers()346 d = {}347 for c_lineno, cython_lineno in enumerate(markers):348 if cython_lineno > 0:349 d.setdefault(cython_lineno, []).append(c_lineno + 1)350 tb.start('LineNumberMapping')351 for cython_lineno, c_linenos in sorted(d.iteritems()):352 attrs = {353 'c_linenos': ' '.join(map(str, c_linenos)),354 'cython_lineno': str(cython_lineno),355 }356 tb.start('LineNumber', attrs)357 tb.end('LineNumber')358 tb.end('LineNumberMapping')359 tb.serialize()360 def find_referenced_modules(self, env, module_list, modules_seen):361 if env not in modules_seen:362 modules_seen[env] = 1363 for imported_module in env.cimported_modules:364 self.find_referenced_modules(imported_module, module_list, modules_seen)365 module_list.append(env)366 def sort_types_by_inheritance(self, type_dict, type_order, getkey):367 # copy the types into a list moving each parent type before368 # its first child369 type_list = []370 for i, key in enumerate(type_order):371 new_entry = type_dict[key]372 # collect all base classes to check for children373 hierarchy = set()374 base = new_entry375 while base:376 base_type = base.type.base_type377 if not base_type:378 break379 base_key = getkey(base_type)380 hierarchy.add(base_key)381 base = type_dict.get(base_key)382 new_entry.base_keys = hierarchy383 # find the first (sub-)subclass and insert before that384 for j in range(i):385 entry = type_list[j]386 if key in entry.base_keys:387 type_list.insert(j, new_entry)388 break389 else:390 type_list.append(new_entry)391 return type_list392 def sort_type_hierarchy(self, module_list, env):393 # poor developer's OrderedDict394 vtab_dict, vtab_dict_order = {}, []395 vtabslot_dict, vtabslot_dict_order = {}, []396 for module in module_list:397 for entry in module.c_class_entries:398 if entry.used and not entry.in_cinclude:399 type = entry.type400 key = type.vtabstruct_cname401 if not key:402 continue403 if key in vtab_dict:404 # FIXME: this should *never* happen, but apparently it does405 # for Cython generated utility code406 from Cython.Compiler.UtilityCode import NonManglingModuleScope407 assert isinstance(entry.scope, NonManglingModuleScope), str(entry.scope)408 assert isinstance(vtab_dict[key].scope, NonManglingModuleScope), str(vtab_dict[key].scope)409 else:410 vtab_dict[key] = entry411 vtab_dict_order.append(key)412 all_defined_here = module is env413 for entry in module.type_entries:414 if entry.used and (all_defined_here or entry.defined_in_pxd):415 type = entry.type416 if type.is_extension_type and not entry.in_cinclude:417 type = entry.type418 key = type.objstruct_cname419 assert key not in vtabslot_dict, key420 vtabslot_dict[key] = entry421 vtabslot_dict_order.append(key)422 def vtabstruct_cname(entry_type):423 return entry_type.vtabstruct_cname424 vtab_list = self.sort_types_by_inheritance(425 vtab_dict, vtab_dict_order, vtabstruct_cname)426 def objstruct_cname(entry_type):427 return entry_type.objstruct_cname428 vtabslot_list = self.sort_types_by_inheritance(429 vtabslot_dict, vtabslot_dict_order, objstruct_cname)430 return (vtab_list, vtabslot_list)431 def sort_cdef_classes(self, env):432 key_func = operator.attrgetter('objstruct_cname')433 entry_dict, entry_order = {}, []434 for entry in env.c_class_entries:435 key = key_func(entry.type)436 assert key not in entry_dict, key437 entry_dict[key] = entry438 entry_order.append(key)439 env.c_class_entries[:] = self.sort_types_by_inheritance(440 entry_dict, entry_order, key_func)441 def generate_type_definitions(self, env, modules, vtab_list, vtabslot_list, code):442 # TODO: Why are these separated out?443 for entry in vtabslot_list:444 self.generate_objstruct_predeclaration(entry.type, code)445 vtabslot_entries = set(vtabslot_list)446 for module in modules:447 definition = module is env448 if definition:449 type_entries = module.type_entries450 else:451 type_entries = []452 for entry in module.type_entries:453 if entry.defined_in_pxd:454 type_entries.append(entry)455 type_entries = [t for t in type_entries if t not in vtabslot_entries]456 self.generate_type_header_code(type_entries, code)457 for entry in vtabslot_list:458 self.generate_objstruct_definition(entry.type, code)459 self.generate_typeobj_predeclaration(entry, code)460 for entry in vtab_list:461 self.generate_typeobj_predeclaration(entry, code)462 self.generate_exttype_vtable_struct(entry, code)463 self.generate_exttype_vtabptr_declaration(entry, code)464 self.generate_exttype_final_methods_declaration(entry, code)465 def generate_declarations_for_modules(self, env, modules, globalstate):466 typecode = globalstate['type_declarations']467 typecode.putln("")468 typecode.putln("/*--- Type declarations ---*/")469 # This is to work around the fact that array.h isn't part of the C-API,470 # but we need to declare it earlier than utility code.471 if 'cpython.array' in [m.qualified_name for m in modules]:472 typecode.putln('#ifndef _ARRAYARRAY_H')473 typecode.putln('struct arrayobject;')474 typecode.putln('typedef struct arrayobject arrayobject;')475 typecode.putln('#endif')476 vtab_list, vtabslot_list = self.sort_type_hierarchy(modules, env)477 self.generate_type_definitions(478 env, modules, vtab_list, vtabslot_list, typecode)479 modulecode = globalstate['module_declarations']480 for module in modules:481 defined_here = module is env482 modulecode.putln("")483 modulecode.putln("/* Module declarations from '%s' */" % module.qualified_name)484 self.generate_c_class_declarations(module, modulecode, defined_here)485 self.generate_cvariable_declarations(module, modulecode, defined_here)486 self.generate_cfunction_declarations(module, modulecode, defined_here)487 def generate_module_preamble(self, env, cimported_modules, code):488 code.putln("/* Generated by Cython %s */" % Version.watermark)489 code.putln("")490 code.putln("#define PY_SSIZE_T_CLEAN")491 # sizeof(PyLongObject.ob_digit[0]) may have been determined dynamically492 # at compile time in CPython, in which case we can't know the correct493 # storage size for an installed system. We can rely on it only if494 # pyconfig.h defines it statically, i.e. if it was set by "configure".495 # Once we include "Python.h", it will come up with its own idea about496 # a suitable value, which may or may not match the real one.497 code.putln("#ifndef CYTHON_USE_PYLONG_INTERNALS")498 code.putln("#ifdef PYLONG_BITS_IN_DIGIT")499 # assume it's an incorrect left-over500 code.putln("#define CYTHON_USE_PYLONG_INTERNALS 0")501 code.putln("#else")502 code.putln('#include "pyconfig.h"')503 code.putln("#ifdef PYLONG_BITS_IN_DIGIT")504 code.putln("#define CYTHON_USE_PYLONG_INTERNALS 1")505 code.putln("#else")506 code.putln("#define CYTHON_USE_PYLONG_INTERNALS 0")507 code.putln("#endif")508 code.putln("#endif")509 code.putln("#endif")510 for filename in env.python_include_files:511 code.putln('#include "%s"' % filename)512 code.putln("#ifndef Py_PYTHON_H")513 code.putln(" #error Python headers needed to compile C extensions, please install development version of Python.")514 code.putln("#elif PY_VERSION_HEX < 0x02040000")515 code.putln(" #error Cython requires Python 2.4+.")516 code.putln("#else")517 code.globalstate["end"].putln("#endif /* Py_PYTHON_H */")518 from Cython import __version__519 code.putln('#define CYTHON_ABI "%s"' % __version__.replace('.', '_'))520 code.put(UtilityCode.load_as_string("CModulePreamble", "ModuleSetupCode.c")[1])521 code.put("""522#if PY_MAJOR_VERSION >= 3523 #define __Pyx_PyNumber_Divide(x,y) PyNumber_TrueDivide(x,y)524 #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceTrueDivide(x,y)525#else526""")527 if Future.division in env.context.future_directives:528 code.putln(" #define __Pyx_PyNumber_Divide(x,y) PyNumber_TrueDivide(x,y)")529 code.putln(" #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceTrueDivide(x,y)")530 else:531 code.putln(" #define __Pyx_PyNumber_Divide(x,y) PyNumber_Divide(x,y)")532 code.putln(" #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceDivide(x,y)")533 code.putln("#endif")534 code.putln("")535 self.generate_extern_c_macro_definition(code)536 code.putln("")537 code.putln("#if defined(WIN32) || defined(MS_WINDOWS)")538 code.putln("#define _USE_MATH_DEFINES")539 code.putln("#endif")540 code.putln("#include <math.h>")541 code.putln("#define %s" % Naming.h_guard_prefix + self.api_name(env))542 code.putln("#define %s" % Naming.api_guard_prefix + self.api_name(env))543 self.generate_includes(env, cimported_modules, code)544 code.putln("")545 code.putln("#ifdef PYREX_WITHOUT_ASSERTIONS")546 code.putln("#define CYTHON_WITHOUT_ASSERTIONS")547 code.putln("#endif")548 code.putln("")549 if env.directives['ccomplex']:550 code.putln("")551 code.putln("#if !defined(CYTHON_CCOMPLEX)")552 code.putln("#define CYTHON_CCOMPLEX 1")553 code.putln("#endif")554 code.putln("")555 code.put(UtilityCode.load_as_string("UtilityFunctionPredeclarations", "ModuleSetupCode.c")[0])556 c_string_type = env.directives['c_string_type']557 c_string_encoding = env.directives['c_string_encoding']558 if c_string_type not in ('bytes', 'bytearray') and not c_string_encoding:559 error(self.pos, "a default encoding must be provided if c_string_type is not a byte type")560 code.putln('#define __PYX_DEFAULT_STRING_ENCODING_IS_ASCII %s' % int(c_string_encoding == 'ascii'))561 if c_string_encoding == 'default':562 code.putln('#define __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT 1')563 else:564 code.putln('#define __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT 0')565 code.putln('#define __PYX_DEFAULT_STRING_ENCODING "%s"' % c_string_encoding)566 if c_string_type == 'bytearray':567 c_string_func_name = 'ByteArray'568 else:569 c_string_func_name = c_string_type.title()570 code.putln('#define __Pyx_PyObject_FromString __Pyx_Py%s_FromString' % c_string_func_name)571 code.putln('#define __Pyx_PyObject_FromStringAndSize __Pyx_Py%s_FromStringAndSize' % c_string_func_name)572 code.put(UtilityCode.load_as_string("TypeConversions", "TypeConversion.c")[0])573 # These utility functions are assumed to exist and used elsewhere.574 PyrexTypes.c_long_type.create_to_py_utility_code(env)575 PyrexTypes.c_long_type.create_from_py_utility_code(env)576 PyrexTypes.c_int_type.create_from_py_utility_code(env)577 code.put(Nodes.branch_prediction_macros)578 code.putln('')579 code.putln('static PyObject *%s;' % env.module_cname)580 code.putln('static PyObject *%s;' % env.module_dict_cname)581 code.putln('static PyObject *%s;' % Naming.builtins_cname)582 code.putln('static PyObject *%s;' % Naming.empty_tuple)583 code.putln('static PyObject *%s;' % Naming.empty_bytes)584 if Options.pre_import is not None:585 code.putln('static PyObject *%s;' % Naming.preimport_cname)586 code.putln('static int %s;' % Naming.lineno_cname)587 code.putln('static int %s = 0;' % Naming.clineno_cname)588 code.putln('static const char * %s= %s;' % (Naming.cfilenm_cname, Naming.file_c_macro))589 code.putln('static const char *%s;' % Naming.filename_cname)590 def generate_extern_c_macro_definition(self, code):591 name = Naming.extern_c_macro592 code.putln("#ifndef %s" % name)593 code.putln(" #ifdef __cplusplus")594 code.putln(' #define %s extern "C"' % name)595 code.putln(" #else")596 code.putln(" #define %s extern" % name)597 code.putln(" #endif")598 code.putln("#endif")599 def generate_includes(self, env, cimported_modules, code):600 includes = []601 for filename in env.include_files:602 byte_decoded_filenname = str(filename)603 if byte_decoded_filenname[0] == '<' and byte_decoded_filenname[-1] == '>':604 code.putln('#include %s' % byte_decoded_filenname)605 else:606 code.putln('#include "%s"' % byte_decoded_filenname)607 code.putln_openmp("#include <omp.h>")608 def generate_filename_table(self, code):609 code.putln("")610 code.putln("static const char *%s[] = {" % Naming.filetable_cname)611 if code.globalstate.filename_list:612 for source_desc in code.globalstate.filename_list:613 filename = os.path.basename(source_desc.get_filenametable_entry())614 escaped_filename = filename.replace("\\", "\\\\").replace('"', r'\"')615 code.putln('"%s",' % escaped_filename)616 else:617 # Some C compilers don't like an empty array618 code.putln("0")619 code.putln("};")620 def generate_type_predeclarations(self, env, code):621 pass622 def generate_type_header_code(self, type_entries, code):623 # Generate definitions of structs/unions/enums/typedefs/objstructs.624 #self.generate_gcc33_hack(env, code) # Is this still needed?625 # Forward declarations626 for entry in type_entries:627 if not entry.in_cinclude:628 #print "generate_type_header_code:", entry.name, repr(entry.type) ###629 type = entry.type630 if type.is_typedef: # Must test this first!631 pass632 elif type.is_struct_or_union or type.is_cpp_class:633 self.generate_struct_union_predeclaration(entry, code)634 elif type.is_extension_type:635 self.generate_objstruct_predeclaration(type, code)636 # Actual declarations637 for entry in type_entries:638 if not entry.in_cinclude:639 #print "generate_type_header_code:", entry.name, repr(entry.type) ###640 type = entry.type641 if type.is_typedef: # Must test this first!642 self.generate_typedef(entry, code)643 elif type.is_enum:644 self.generate_enum_definition(entry, code)645 elif type.is_struct_or_union:646 self.generate_struct_union_definition(entry, code)647 elif type.is_cpp_class:648 self.generate_cpp_class_definition(entry, code)649 elif type.is_extension_type:650 self.generate_objstruct_definition(type, code)651 def generate_gcc33_hack(self, env, code):652 # Workaround for spurious warning generation in gcc 3.3653 code.putln("")654 for entry in env.c_class_entries:655 type = entry.type656 if not type.typedef_flag:657 name = type.objstruct_cname658 if name.startswith("__pyx_"):659 tail = name[6:]660 else:661 tail = name662 code.putln("typedef struct %s __pyx_gcc33_%s;" % (663 name, tail))664 def generate_typedef(self, entry, code):665 base_type = entry.type.typedef_base_type666 if base_type.is_numeric:667 try:668 writer = code.globalstate['numeric_typedefs']669 except KeyError:670 writer = code671 else:672 writer = code673 writer.mark_pos(entry.pos)674 writer.putln("typedef %s;" % base_type.declaration_code(entry.cname))675 def sue_predeclaration(self, type, kind, name):676 if type.typedef_flag:677 return "%s %s;\ntypedef %s %s %s;" % (678 kind, name,679 kind, name, name)680 else:681 return "%s %s;" % (kind, name)682 def generate_struct_union_predeclaration(self, entry, code):683 type = entry.type684 if type.is_cpp_class and type.templates:685 code.putln("template <typename %s>" % ", typename ".join([T.declaration_code("") for T in type.templates]))686 code.putln(self.sue_predeclaration(type, type.kind, type.cname))687 def sue_header_footer(self, type, kind, name):688 header = "%s %s {" % (kind, name)689 footer = "};"690 return header, footer691 def generate_struct_union_definition(self, entry, code):692 code.mark_pos(entry.pos)693 type = entry.type694 scope = type.scope695 if scope:696 kind = type.kind697 packed = type.is_struct and type.packed698 if packed:699 kind = "%s %s" % (type.kind, "__Pyx_PACKED")700 code.globalstate.use_utility_code(packed_struct_utility_code)701 header, footer = \702 self.sue_header_footer(type, kind, type.cname)703 if packed:704 code.putln("#if defined(__SUNPRO_C)")705 code.putln(" #pragma pack(1)")706 code.putln("#elif !defined(__GNUC__)")707 code.putln(" #pragma pack(push, 1)")708 code.putln("#endif")709 code.putln(header)710 var_entries = scope.var_entries711 if not var_entries:712 error(entry.pos,713 "Empty struct or union definition not allowed outside a"714 " 'cdef extern from' block")715 for attr in var_entries:716 code.putln(717 "%s;" %718 attr.type.declaration_code(attr.cname))719 code.putln(footer)720 if packed:721 code.putln("#if defined(__SUNPRO_C)")722 code.putln(" #pragma pack()")723 code.putln("#elif !defined(__GNUC__)")724 code.putln(" #pragma pack(pop)")725 code.putln("#endif")726 def generate_cpp_class_definition(self, entry, code):727 code.mark_pos(entry.pos)728 type = entry.type729 scope = type.scope730 if scope:731 if type.templates:732 code.putln("template <class %s>" % ", class ".join([T.declaration_code("") for T in type.templates]))733 # Just let everything be public.734 code.put("struct %s" % type.cname)735 if type.base_classes:736 base_class_decl = ", public ".join(737 [base_class.declaration_code("") for base_class in type.base_classes])738 code.put(" : public %s" % base_class_decl)739 code.putln(" {")740 has_virtual_methods = False741 has_destructor = False742 for attr in scope.var_entries:743 if attr.type.is_cfunction and attr.name != "<init>":744 code.put("virtual ")745 has_virtual_methods = True746 if attr.cname[0] == '~':747 has_destructor = True748 code.putln(749 "%s;" %750 attr.type.declaration_code(attr.cname))751 if has_virtual_methods and not has_destructor:752 code.put("virtual ~%s() { }" % type.cname)753 code.putln("};")754 def generate_enum_definition(self, entry, code):755 code.mark_pos(entry.pos)756 type = entry.type757 name = entry.cname or entry.name or ""758 header, footer = \759 self.sue_header_footer(type, "enum", name)760 code.putln(header)761 enum_values = entry.enum_values762 if not enum_values:763 error(entry.pos,764 "Empty enum definition not allowed outside a"765 " 'cdef extern from' block")766 else:767 last_entry = enum_values[-1]768 # this does not really generate code, just builds the result value769 for value_entry in enum_values:770 if value_entry.value_node is not None:771 value_entry.value_node.generate_evaluation_code(code)772 for value_entry in enum_values:773 if value_entry.value_node is None:774 value_code = value_entry.cname775 else:776 value_code = ("%s = %s" % (777 value_entry.cname,778 value_entry.value_node.result()))779 if value_entry is not last_entry:780 value_code += ","781 code.putln(value_code)782 code.putln(footer)783 if entry.type.typedef_flag:784 # Not pre-declared.785 code.putln("typedef enum %s %s;" % (name, name))786 def generate_typeobj_predeclaration(self, entry, code):787 code.putln("")788 name = entry.type.typeobj_cname789 if name:790 if entry.visibility == 'extern' and not entry.in_cinclude:791 code.putln("%s %s %s;" % (792 Naming.extern_c_macro,793 PyrexTypes.public_decl("PyTypeObject", "DL_IMPORT"),794 name))795 elif entry.visibility == 'public':796 code.putln("%s %s %s;" % (797 Naming.extern_c_macro,798 PyrexTypes.public_decl("PyTypeObject", "DL_EXPORT"),799 name))800 # ??? Do we really need the rest of this? ???801 #else:802 # code.putln("static PyTypeObject %s;" % name)803 def generate_exttype_vtable_struct(self, entry, code):804 if not entry.used:805 return806 code.mark_pos(entry.pos)807 # Generate struct declaration for an extension type's vtable.808 type = entry.type809 scope = type.scope810 self.specialize_fused_types(scope)811 if type.vtabstruct_cname:812 code.putln("")813 code.putln(814 "struct %s {" %815 type.vtabstruct_cname)816 if type.base_type and type.base_type.vtabstruct_cname:817 code.putln("struct %s %s;" % (818 type.base_type.vtabstruct_cname,819 Naming.obj_base_cname))820 for method_entry in scope.cfunc_entries:821 if not method_entry.is_inherited:822 code.putln(823 "%s;" % method_entry.type.declaration_code("(*%s)" % method_entry.cname))824 code.putln(825 "};")826 def generate_exttype_vtabptr_declaration(self, entry, code):827 if not entry.used:828 return829 code.mark_pos(entry.pos)830 # Generate declaration of pointer to an extension type's vtable.831 type = entry.type832 if type.vtabptr_cname:833 code.putln("static struct %s *%s;" % (834 type.vtabstruct_cname,835 type.vtabptr_cname))836 def generate_exttype_final_methods_declaration(self, entry, code):837 if not entry.used:838 return839 code.mark_pos(entry.pos)840 # Generate final methods prototypes841 type = entry.type842 for method_entry in entry.type.scope.cfunc_entries:843 if not method_entry.is_inherited and method_entry.final_func_cname:844 declaration = method_entry.type.declaration_code(845 method_entry.final_func_cname)846 modifiers = code.build_function_modifiers(method_entry.func_modifiers)847 code.putln("static %s%s;" % (modifiers, declaration))848 def generate_objstruct_predeclaration(self, type, code):849 if not type.scope:850 return851 code.putln(self.sue_predeclaration(type, "struct", type.objstruct_cname))852 def generate_objstruct_definition(self, type, code):853 code.mark_pos(type.pos)854 # Generate object struct definition for an855 # extension type.856 if not type.scope:857 return # Forward declared but never defined858 header, footer = \859 self.sue_header_footer(type, "struct", type.objstruct_cname)860 code.putln(header)861 base_type = type.base_type862 if base_type:863 basestruct_cname = base_type.objstruct_cname864 if basestruct_cname == "PyTypeObject":865 # User-defined subclasses of type are heap allocated.866 basestruct_cname = "PyHeapTypeObject"867 code.putln(868 "%s%s %s;" % (869 ("struct ", "")[base_type.typedef_flag],870 basestruct_cname,871 Naming.obj_base_cname))872 else:873 code.putln(874 "PyObject_HEAD")875 if type.vtabslot_cname and not (type.base_type and type.base_type.vtabslot_cname):876 code.putln(877 "struct %s *%s;" % (878 type.vtabstruct_cname,879 type.vtabslot_cname))880 for attr in type.scope.var_entries:881 if attr.is_declared_generic:882 attr_type = py_object_type883 else:884 attr_type = attr.type885 code.putln(886 "%s;" %887 attr_type.declaration_code(attr.cname))888 code.putln(footer)889 if type.objtypedef_cname is not None:890 # Only for exposing public typedef name.891 code.putln("typedef struct %s %s;" % (type.objstruct_cname, type.objtypedef_cname))892 def generate_c_class_declarations(self, env, code, definition):893 for entry in env.c_class_entries:894 if definition or entry.defined_in_pxd:895 code.putln("static PyTypeObject *%s = 0;" %896 entry.type.typeptr_cname)897 def generate_cvariable_declarations(self, env, code, definition):898 if env.is_cython_builtin:899 return900 for entry in env.var_entries:901 if (entry.in_cinclude or entry.in_closure or902 (entry.visibility == 'private' and903 not (entry.defined_in_pxd or entry.used))):904 continue905 storage_class = None906 dll_linkage = None907 cname = None908 init = None909 if entry.visibility == 'extern':910 storage_class = Naming.extern_c_macro911 dll_linkage = "DL_IMPORT"912 elif entry.visibility == 'public':913 storage_class = Naming.extern_c_macro914 if definition:915 dll_linkage = "DL_EXPORT"916 else:917 dll_linkage = "DL_IMPORT"918 elif entry.visibility == 'private':919 storage_class = "static"920 dll_linkage = None921 if entry.init is not None:922 init = entry.type.literal_code(entry.init)923 type = entry.type924 cname = entry.cname925 if entry.defined_in_pxd and not definition:926 storage_class = "static"927 dll_linkage = None928 type = CPtrType(type)929 cname = env.mangle(Naming.varptr_prefix, entry.name)930 init = 0931 if storage_class:932 code.put("%s " % storage_class)933 code.put(type.declaration_code(934 cname, dll_linkage = dll_linkage))935 if init is not None:936 code.put_safe(" = %s" % init)937 code.putln(";")938 if entry.cname != cname:939 code.putln("#define %s (*%s)" % (entry.cname, cname))940 def generate_cfunction_declarations(self, env, code, definition):941 for entry in env.cfunc_entries:942 if entry.used or (entry.visibility == 'public' or entry.api):943 generate_cfunction_declaration(entry, env, code, definition)944 def generate_variable_definitions(self, env, code):945 for entry in env.var_entries:946 if (not entry.in_cinclude and947 entry.visibility == "public"):948 code.put(entry.type.declaration_code(entry.cname))949 if entry.init is not None:950 init = entry.type.literal_code(entry.init)951 code.put_safe(" = %s" % init)952 code.putln(";")953 def generate_typeobj_definitions(self, env, code):954 full_module_name = env.qualified_name955 for entry in env.c_class_entries:956 #print "generate_typeobj_definitions:", entry.name957 #print "...visibility =", entry.visibility958 if entry.visibility != 'extern':959 type = entry.type960 scope = type.scope961 if scope: # could be None if there was an error962 self.generate_exttype_vtable(scope, code)963 self.generate_new_function(scope, code, entry)964 self.generate_dealloc_function(scope, code)965 if scope.needs_gc():966 self.generate_traverse_function(scope, code, entry)967 if scope.needs_tp_clear():968 self.generate_clear_function(scope, code, entry)969 if scope.defines_any(["__getitem__"]):970 self.generate_getitem_int_function(scope, code)971 if scope.defines_any(["__setitem__", "__delitem__"]):972 self.generate_ass_subscript_function(scope, code)973 if scope.defines_any(["__getslice__", "__setslice__", "__delslice__"]):974 warning(self.pos, "__getslice__, __setslice__, and __delslice__ are not supported by Python 3, use __getitem__, __setitem__, and __delitem__ instead", 1)975 code.putln("#if PY_MAJOR_VERSION >= 3")976 code.putln("#error __getslice__, __setslice__, and __delslice__ not supported in Python 3.")977 code.putln("#endif")978 if scope.defines_any(["__setslice__", "__delslice__"]):979 self.generate_ass_slice_function(scope, code)980 if scope.defines_any(["__getattr__","__getattribute__"]):981 self.generate_getattro_function(scope, code)982 if scope.defines_any(["__setattr__", "__delattr__"]):983 self.generate_setattro_function(scope, code)984 if scope.defines_any(["__get__"]):985 self.generate_descr_get_function(scope, code)986 if scope.defines_any(["__set__", "__delete__"]):987 self.generate_descr_set_function(scope, code)988 self.generate_property_accessors(scope, code)989 self.generate_method_table(scope, code)990 self.generate_getset_table(scope, code)991 self.generate_typeobj_definition(full_module_name, entry, code)992 def generate_exttype_vtable(self, scope, code):993 # Generate the definition of an extension type's vtable.994 type = scope.parent_type995 if type.vtable_cname:996 code.putln("static struct %s %s;" % (997 type.vtabstruct_cname,998 type.vtable_cname))999 def generate_self_cast(self, scope, code):1000 type = scope.parent_type1001 code.putln(1002 "%s = (%s)o;" % (1003 type.declaration_code("p"),1004 type.declaration_code("")))1005 def generate_new_function(self, scope, code, cclass_entry):1006 tp_slot = TypeSlots.ConstructorSlot("tp_new", '__new__')1007 slot_func = scope.mangle_internal("tp_new")1008 type = scope.parent_type1009 base_type = type.base_type1010 have_entries, (py_attrs, py_buffers, memoryview_slices) = \1011 scope.get_refcounted_entries()1012 is_final_type = scope.parent_type.is_final_type1013 if scope.is_internal:1014 # internal classes (should) never need None inits, normal zeroing will do1015 py_attrs = []1016 cpp_class_attrs = [entry for entry in scope.var_entries1017 if entry.type.is_cpp_class]1018 new_func_entry = scope.lookup_here("__new__")1019 if base_type or (new_func_entry and new_func_entry.is_special1020 and not new_func_entry.trivial_signature):1021 unused_marker = ''1022 else:1023 unused_marker = 'CYTHON_UNUSED '1024 if base_type:1025 freelist_size = 0 # not currently supported1026 else:1027 freelist_size = scope.directives.get('freelist', 0)1028 freelist_name = scope.mangle_internal(Naming.freelist_name)1029 freecount_name = scope.mangle_internal(Naming.freecount_name)1030 decls = code.globalstate['decls']1031 decls.putln("static PyObject *%s(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/" %1032 slot_func)1033 code.putln("")1034 if freelist_size:1035 code.putln("static %s[%d];" % (1036 scope.parent_type.declaration_code(freelist_name),1037 freelist_size))1038 code.putln("static int %s = 0;" % freecount_name)1039 code.putln("")1040 code.putln(1041 "static PyObject *%s(PyTypeObject *t, %sPyObject *a, %sPyObject *k) {"1042 % (slot_func, unused_marker, unused_marker))1043 need_self_cast = (type.vtabslot_cname or1044 (py_buffers or memoryview_slices or py_attrs) or1045 cpp_class_attrs)1046 if need_self_cast:1047 code.putln("%s;" % scope.parent_type.declaration_code("p"))1048 if base_type:1049 tp_new = TypeSlots.get_base_slot_function(scope, tp_slot)1050 if tp_new is None:1051 tp_new = "%s->tp_new" % base_type.typeptr_cname1052 code.putln("PyObject *o = %s(t, a, k);" % tp_new)1053 else:1054 code.putln("PyObject *o;")1055 if freelist_size:1056 code.globalstate.use_utility_code(1057 UtilityCode.load_cached("IncludeStringH", "StringTools.c"))1058 if is_final_type:1059 type_safety_check = ''1060 else:1061 type_safety_check = ' & ((t->tp_flags & (Py_TPFLAGS_IS_ABSTRACT | Py_TPFLAGS_HEAPTYPE)) == 0)'1062 obj_struct = type.declaration_code("", deref=True)1063 code.putln("if (CYTHON_COMPILING_IN_CPYTHON && likely((%s > 0) & (t->tp_basicsize == sizeof(%s))%s)) {" % (1064 freecount_name, obj_struct, type_safety_check))1065 code.putln("o = (PyObject*)%s[--%s];" % (1066 freelist_name, freecount_name))1067 code.putln("memset(o, 0, sizeof(%s));" % obj_struct)1068 code.putln("(void) PyObject_INIT(o, t);")1069 if scope.needs_gc():1070 code.putln("PyObject_GC_Track(o);")1071 code.putln("} else {")1072 if not is_final_type:1073 code.putln("if (likely((t->tp_flags & Py_TPFLAGS_IS_ABSTRACT) == 0)) {")1074 code.putln("o = (*t->tp_alloc)(t, 0);")1075 if not is_final_type:1076 code.putln("} else {")1077 code.putln("o = (PyObject *) PyBaseObject_Type.tp_new(t, %s, 0);" % Naming.empty_tuple)1078 code.putln("}")1079 code.putln("if (unlikely(!o)) return 0;")1080 if freelist_size and not base_type:1081 code.putln('}')1082 if need_self_cast:1083 code.putln("p = %s;" % type.cast_code("o"))1084 #if need_self_cast:1085 # self.generate_self_cast(scope, code)1086 if type.vtabslot_cname:1087 vtab_base_type = type1088 while vtab_base_type.base_type and vtab_base_type.base_type.vtabstruct_cname:1089 vtab_base_type = vtab_base_type.base_type1090 if vtab_base_type is not type:1091 struct_type_cast = "(struct %s*)" % vtab_base_type.vtabstruct_cname1092 else:1093 struct_type_cast = ""1094 code.putln("p->%s = %s%s;" % (1095 type.vtabslot_cname,1096 struct_type_cast, type.vtabptr_cname))1097 for entry in cpp_class_attrs:1098 code.putln("new((void*)&(p->%s)) %s();" %1099 (entry.cname, entry.type.declaration_code("")))1100 for entry in py_attrs:1101 code.put_init_var_to_py_none(entry, "p->%s", nanny=False)1102 for entry in memoryview_slices:1103 code.putln("p->%s.data = NULL;" % entry.cname)1104 code.putln("p->%s.memview = NULL;" % entry.cname)1105 for entry in py_buffers:1106 code.putln("p->%s.obj = NULL;" % entry.cname)1107 if cclass_entry.cname == '__pyx_memoryviewslice':1108 code.putln("p->from_slice.memview = NULL;")1109 if new_func_entry and new_func_entry.is_special:1110 if new_func_entry.trivial_signature:1111 cinit_args = "o, %s, NULL" % Naming.empty_tuple1112 else:1113 cinit_args = "o, a, k"1114 code.putln(1115 "if (unlikely(%s(%s) < 0)) {" %1116 (new_func_entry.func_cname, cinit_args))1117 code.put_decref_clear("o", py_object_type, nanny=False)1118 code.putln(1119 "}")1120 code.putln(1121 "return o;")1122 code.putln(1123 "}")1124 def generate_dealloc_function(self, scope, code):1125 tp_slot = TypeSlots.ConstructorSlot("tp_dealloc", '__dealloc__')1126 slot_func = scope.mangle_internal("tp_dealloc")1127 base_type = scope.parent_type.base_type1128 if tp_slot.slot_code(scope) != slot_func:1129 return # never used1130 slot_func_cname = scope.mangle_internal("tp_dealloc")1131 code.putln("")1132 code.putln(1133 "static void %s(PyObject *o) {" % slot_func_cname)1134 is_final_type = scope.parent_type.is_final_type1135 needs_gc = scope.needs_gc()1136 weakref_slot = scope.lookup_here("__weakref__")1137 if weakref_slot not in scope.var_entries:1138 weakref_slot = None1139 _, (py_attrs, _, memoryview_slices) = scope.get_refcounted_entries()1140 cpp_class_attrs = [entry for entry in scope.var_entries1141 if entry.type.is_cpp_class]1142 if py_attrs or cpp_class_attrs or memoryview_slices or weakref_slot:1143 self.generate_self_cast(scope, code)1144 if not is_final_type:1145 # in Py3.4+, call tp_finalize() as early as possible1146 code.putln("#if PY_VERSION_HEX >= 0x030400a1")1147 if needs_gc:1148 finalised_check = '!_PyGC_FINALIZED(o)'1149 else:1150 finalised_check = (1151 '(!PyType_IS_GC(Py_TYPE(o)) || !_PyGC_FINALIZED(o))')1152 code.putln("if (unlikely(Py_TYPE(o)->tp_finalize) && %s) {" %1153 finalised_check)1154 # if instance was resurrected by finaliser, return1155 code.putln("if (PyObject_CallFinalizerFromDealloc(o)) return;")1156 code.putln("}")1157 code.putln("#endif")1158 if needs_gc:1159 # We must mark this object as (gc) untracked while tearing1160 # it down, lest the garbage collection is invoked while1161 # running this destructor.1162 code.putln("PyObject_GC_UnTrack(o);")1163 # call the user's __dealloc__1164 self.generate_usr_dealloc_call(scope, code)1165 if weakref_slot:1166 code.putln("if (p->__weakref__) PyObject_ClearWeakRefs(o);")1167 for entry in cpp_class_attrs:1168 code.putln("__Pyx_call_destructor(&p->%s);" % entry.cname)1169 for entry in py_attrs:1170 code.put_xdecref_clear("p->%s" % entry.cname, entry.type, nanny=False,1171 clear_before_decref=True)1172 for entry in memoryview_slices:1173 code.put_xdecref_memoryviewslice("p->%s" % entry.cname,1174 have_gil=True)1175 if base_type:1176 if needs_gc:1177 # The base class deallocator probably expects this to be tracked,1178 # so undo the untracking above.1179 if base_type.scope and base_type.scope.needs_gc():1180 code.putln("PyObject_GC_Track(o);")1181 else:1182 code.putln("#if CYTHON_COMPILING_IN_CPYTHON")1183 code.putln("if (PyType_IS_GC(Py_TYPE(o)->tp_base))")1184 code.putln("#endif")1185 code.putln("PyObject_GC_Track(o);")1186 tp_dealloc = TypeSlots.get_base_slot_function(scope, tp_slot)1187 if tp_dealloc is not None:1188 code.putln("%s(o);" % tp_dealloc)1189 elif base_type.is_builtin_type:1190 code.putln("%s->tp_dealloc(o);" % base_type.typeptr_cname)1191 else:1192 # This is an externally defined type. Calling through the1193 # cimported base type pointer directly interacts badly with1194 # the module cleanup, which may already have cleared it.1195 # In that case, fall back to traversing the type hierarchy.1196 base_cname = base_type.typeptr_cname1197 code.putln("if (likely(%s)) %s->tp_dealloc(o); "1198 "else __Pyx_call_next_tp_dealloc(o, %s);" % (1199 base_cname, base_cname, slot_func_cname))1200 code.globalstate.use_utility_code(1201 UtilityCode.load_cached("CallNextTpDealloc", "ExtensionTypes.c"))1202 else:1203 freelist_size = scope.directives.get('freelist', 0)1204 if freelist_size:1205 freelist_name = scope.mangle_internal(Naming.freelist_name)1206 freecount_name = scope.mangle_internal(Naming.freecount_name)1207 if is_final_type:1208 type_safety_check = ''1209 else:1210 type_safety_check = (1211 ' & ((Py_TYPE(o)->tp_flags & (Py_TPFLAGS_IS_ABSTRACT | Py_TPFLAGS_HEAPTYPE)) == 0)')1212 type = scope.parent_type1213 code.putln("if (CYTHON_COMPILING_IN_CPYTHON && ((%s < %d) & (Py_TYPE(o)->tp_basicsize == sizeof(%s))%s)) {" % (1214 freecount_name, freelist_size, type.declaration_code("", deref=True),1215 type_safety_check))1216 code.putln("%s[%s++] = %s;" % (1217 freelist_name, freecount_name, type.cast_code("o")))1218 code.putln("} else {")1219 code.putln("(*Py_TYPE(o)->tp_free)(o);")1220 if freelist_size:1221 code.putln("}")1222 code.putln(1223 "}")1224 def generate_usr_dealloc_call(self, scope, code):1225 entry = scope.lookup_here("__dealloc__")1226 if not entry:1227 return1228 code.putln("{")1229 code.putln("PyObject *etype, *eval, *etb;")1230 code.putln("PyErr_Fetch(&etype, &eval, &etb);")1231 code.putln("++Py_REFCNT(o);")1232 code.putln("%s(o);" % entry.func_cname)1233 code.putln("--Py_REFCNT(o);")1234 code.putln("PyErr_Restore(etype, eval, etb);")1235 code.putln("}")1236 def generate_traverse_function(self, scope, code, cclass_entry):1237 tp_slot = TypeSlots.GCDependentSlot("tp_traverse")1238 slot_func = scope.mangle_internal("tp_traverse")1239 base_type = scope.parent_type.base_type1240 if tp_slot.slot_code(scope) != slot_func:1241 return # never used1242 code.putln("")1243 code.putln(1244 "static int %s(PyObject *o, visitproc v, void *a) {"1245 % slot_func)1246 have_entries, (py_attrs, py_buffers, memoryview_slices) = (1247 scope.get_refcounted_entries(include_gc_simple=False))1248 if base_type or py_attrs:1249 code.putln("int e;")1250 if py_attrs or py_buffers:1251 self.generate_self_cast(scope, code)1252 if base_type:1253 # want to call it explicitly if possible so inlining can be performed1254 static_call = TypeSlots.get_base_slot_function(scope, tp_slot)1255 if static_call:1256 code.putln("e = %s(o, v, a); if (e) return e;" % static_call)1257 elif base_type.is_builtin_type:1258 base_cname = base_type.typeptr_cname1259 code.putln("if (!%s->tp_traverse); else { e = %s->tp_traverse(o,v,a); if (e) return e; }" % (1260 base_cname, base_cname))1261 else:1262 # This is an externally defined type. Calling through the1263 # cimported base type pointer directly interacts badly with1264 # the module cleanup, which may already have cleared it.1265 # In that case, fall back to traversing the type hierarchy.1266 base_cname = base_type.typeptr_cname1267 code.putln("e = ((likely(%s)) ? ((%s->tp_traverse) ? %s->tp_traverse(o, v, a) : 0) : __Pyx_call_next_tp_traverse(o, v, a, %s)); if (e) return e;" % (1268 base_cname, base_cname, base_cname, slot_func))1269 code.globalstate.use_utility_code(1270 UtilityCode.load_cached("CallNextTpTraverse", "ExtensionTypes.c"))1271 for entry in py_attrs:1272 var_code = "p->%s" % entry.cname1273 code.putln(1274 "if (%s) {"1275 % var_code)1276 if entry.type.is_extension_type:1277 var_code = "((PyObject*)%s)" % var_code1278 code.putln(1279 "e = (*v)(%s, a); if (e) return e;"1280 % var_code)1281 code.putln(1282 "}")1283 # Traverse buffer exporting objects.1284 # Note: not traversing memoryview attributes of memoryview slices!1285 # When triggered by the GC, it would cause multiple visits (gc_refs1286 # subtractions which is not matched by its reference count!)1287 for entry in py_buffers:1288 cname = entry.cname + ".obj"1289 code.putln("if (p->%s) {" % cname)1290 code.putln( "e = (*v)(p->%s, a); if (e) return e;" % cname)1291 code.putln("}")1292 code.putln(1293 "return 0;")1294 code.putln(1295 "}")1296 def generate_clear_function(self, scope, code, cclass_entry):1297 tp_slot = TypeSlots.GCDependentSlot("tp_clear")1298 slot_func = scope.mangle_internal("tp_clear")1299 base_type = scope.parent_type.base_type1300 if tp_slot.slot_code(scope) != slot_func:1301 return # never used1302 have_entries, (py_attrs, py_buffers, memoryview_slices) = (1303 scope.get_refcounted_entries(include_gc_simple=False))1304 if py_attrs or py_buffers or base_type:1305 unused = ''1306 else:1307 unused = 'CYTHON_UNUSED '1308 code.putln("")1309 code.putln("static int %s(%sPyObject *o) {" % (slot_func, unused))1310 if py_attrs and Options.clear_to_none:1311 code.putln("PyObject* tmp;")1312 if py_attrs or py_buffers:1313 self.generate_self_cast(scope, code)1314 if base_type:1315 # want to call it explicitly if possible so inlining can be performed1316 static_call = TypeSlots.get_base_slot_function(scope, tp_slot)1317 if static_call:1318 code.putln("%s(o);" % static_call)1319 elif base_type.is_builtin_type:1320 base_cname = base_type.typeptr_cname1321 code.putln("if (!%s->tp_clear); else %s->tp_clear(o);" % (1322 base_cname, base_cname))1323 else:1324 # This is an externally defined type. Calling through the1325 # cimported base type pointer directly interacts badly with1326 # the module cleanup, which may already have cleared it.1327 # In that case, fall back to traversing the type hierarchy.1328 base_cname = base_type.typeptr_cname1329 code.putln("if (likely(%s)) { if (%s->tp_clear) %s->tp_clear(o); } else __Pyx_call_next_tp_clear(o, %s);" % (1330 base_cname, base_cname, base_cname, slot_func))1331 code.globalstate.use_utility_code(1332 UtilityCode.load_cached("CallNextTpClear", "ExtensionTypes.c"))1333 if Options.clear_to_none:1334 for entry in py_attrs:1335 name = "p->%s" % entry.cname1336 code.putln("tmp = ((PyObject*)%s);" % name)1337 if entry.is_declared_generic:1338 code.put_init_to_py_none(name, py_object_type, nanny=False)1339 else:1340 code.put_init_to_py_none(name, entry.type, nanny=False)1341 code.putln("Py_XDECREF(tmp);")1342 else:1343 for entry in py_attrs:1344 code.putln("Py_CLEAR(p->%s);" % entry.cname)1345 for entry in py_buffers:1346 # Note: shouldn't this call __Pyx_ReleaseBuffer ??1347 code.putln("Py_CLEAR(p->%s.obj);" % entry.cname)1348 if cclass_entry.cname == '__pyx_memoryviewslice':1349 code.putln("__PYX_XDEC_MEMVIEW(&p->from_slice, 1);")1350 code.putln(1351 "return 0;")1352 code.putln(1353 "}")1354 def generate_getitem_int_function(self, scope, code):1355 # This function is put into the sq_item slot when1356 # a __getitem__ method is present. It converts its1357 # argument to a Python integer and calls mp_subscript.1358 code.putln(1359 "static PyObject *%s(PyObject *o, Py_ssize_t i) {" %1360 scope.mangle_internal("sq_item"))1361 code.putln(1362 "PyObject *r;")1363 code.putln(1364 "PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0;")1365 code.putln(1366 "r = Py_TYPE(o)->tp_as_mapping->mp_subscript(o, x);")1367 code.putln(1368 "Py_DECREF(x);")1369 code.putln(1370 "return r;")1371 code.putln(1372 "}")1373 def generate_ass_subscript_function(self, scope, code):1374 # Setting and deleting an item are both done through1375 # the ass_subscript method, so we dispatch to user's __setitem__1376 # or __delitem__, or raise an exception.1377 base_type = scope.parent_type.base_type1378 set_entry = scope.lookup_here("__setitem__")1379 del_entry = scope.lookup_here("__delitem__")1380 code.putln("")1381 code.putln(1382 "static int %s(PyObject *o, PyObject *i, PyObject *v) {" %1383 scope.mangle_internal("mp_ass_subscript"))1384 code.putln(1385 "if (v) {")1386 if set_entry:1387 code.putln(1388 "return %s(o, i, v);" %1389 set_entry.func_cname)1390 else:1391 self.generate_guarded_basetype_call(1392 base_type, "tp_as_mapping", "mp_ass_subscript", "o, i, v", code)1393 code.putln(1394 "PyErr_Format(PyExc_NotImplementedError,")1395 code.putln(1396 ' "Subscript assignment not supported by %.200s", Py_TYPE(o)->tp_name);')1397 code.putln(1398 "return -1;")1399 code.putln(1400 "}")1401 code.putln(1402 "else {")1403 if del_entry:1404 code.putln(1405 "return %s(o, i);" %1406 del_entry.func_cname)1407 else:1408 self.generate_guarded_basetype_call(1409 base_type, "tp_as_mapping", "mp_ass_subscript", "o, i, v", code)1410 code.putln(1411 "PyErr_Format(PyExc_NotImplementedError,")1412 code.putln(1413 ' "Subscript deletion not supported by %.200s", Py_TYPE(o)->tp_name);')1414 code.putln(1415 "return -1;")1416 code.putln(1417 "}")1418 code.putln(1419 "}")1420 def generate_guarded_basetype_call(1421 self, base_type, substructure, slot, args, code):1422 if base_type:1423 base_tpname = base_type.typeptr_cname1424 if substructure:1425 code.putln(1426 "if (%s->%s && %s->%s->%s)" % (1427 base_tpname, substructure, base_tpname, substructure, slot))1428 code.putln(1429 " return %s->%s->%s(%s);" % (1430 base_tpname, substructure, slot, args))1431 else:1432 code.putln(1433 "if (%s->%s)" % (1434 base_tpname, slot))1435 code.putln(1436 " return %s->%s(%s);" % (1437 base_tpname, slot, args))1438 def generate_ass_slice_function(self, scope, code):1439 # Setting and deleting a slice are both done through1440 # the ass_slice method, so we dispatch to user's __setslice__1441 # or __delslice__, or raise an exception.1442 base_type = scope.parent_type.base_type1443 set_entry = scope.lookup_here("__setslice__")1444 del_entry = scope.lookup_here("__delslice__")1445 code.putln("")1446 code.putln(1447 "static int %s(PyObject *o, Py_ssize_t i, Py_ssize_t j, PyObject *v) {" %1448 scope.mangle_internal("sq_ass_slice"))1449 code.putln(1450 "if (v) {")1451 if set_entry:1452 code.putln(1453 "return %s(o, i, j, v);" %1454 set_entry.func_cname)1455 else:1456 self.generate_guarded_basetype_call(1457 base_type, "tp_as_sequence", "sq_ass_slice", "o, i, j, v", code)1458 code.putln(1459 "PyErr_Format(PyExc_NotImplementedError,")1460 code.putln(1461 ' "2-element slice assignment not supported by %.200s", Py_TYPE(o)->tp_name);')1462 code.putln(1463 "return -1;")1464 code.putln(1465 "}")1466 code.putln(1467 "else {")1468 if del_entry:1469 code.putln(1470 "return %s(o, i, j);" %1471 del_entry.func_cname)1472 else:1473 self.generate_guarded_basetype_call(1474 base_type, "tp_as_sequence", "sq_ass_slice", "o, i, j, v", code)1475 code.putln(1476 "PyErr_Format(PyExc_NotImplementedError,")1477 code.putln(1478 ' "2-element slice deletion not supported by %.200s", Py_TYPE(o)->tp_name);')1479 code.putln(1480 "return -1;")1481 code.putln(1482 "}")1483 code.putln(1484 "}")1485 def generate_getattro_function(self, scope, code):1486 # First try to get the attribute using __getattribute__, if defined, or1487 # PyObject_GenericGetAttr.1488 #1489 # If that raises an AttributeError, call the __getattr__ if defined.1490 #1491 # In both cases, defined can be in this class, or any base class.1492 def lookup_here_or_base(n,type=None):1493 # Recursive lookup1494 if type is None:1495 type = scope.parent_type1496 r = type.scope.lookup_here(n)1497 if r is None and \1498 type.base_type is not None:1499 return lookup_here_or_base(n,type.base_type)1500 else:1501 return r1502 getattr_entry = lookup_here_or_base("__getattr__")1503 getattribute_entry = lookup_here_or_base("__getattribute__")1504 code.putln("")1505 code.putln(1506 "static PyObject *%s(PyObject *o, PyObject *n) {"1507 % scope.mangle_internal("tp_getattro"))1508 if getattribute_entry is not None:1509 code.putln(1510 "PyObject *v = %s(o, n);" %1511 getattribute_entry.func_cname)1512 else:1513 code.putln(1514 "PyObject *v = PyObject_GenericGetAttr(o, n);")1515 if getattr_entry is not None:1516 code.putln(1517 "if (!v && PyErr_ExceptionMatches(PyExc_AttributeError)) {")1518 code.putln(1519 "PyErr_Clear();")1520 code.putln(1521 "v = %s(o, n);" %1522 getattr_entry.func_cname)1523 code.putln(1524 "}")1525 code.putln(1526 "return v;")1527 code.putln(1528 "}")1529 def generate_setattro_function(self, scope, code):1530 # Setting and deleting an attribute are both done through1531 # the setattro method, so we dispatch to user's __setattr__1532 # or __delattr__ or fall back on PyObject_GenericSetAttr.1533 base_type = scope.parent_type.base_type1534 set_entry = scope.lookup_here("__setattr__")1535 del_entry = scope.lookup_here("__delattr__")1536 code.putln("")1537 code.putln(1538 "static int %s(PyObject *o, PyObject *n, PyObject *v) {" %1539 scope.mangle_internal("tp_setattro"))1540 code.putln(1541 "if (v) {")1542 if set_entry:1543 code.putln(1544 "return %s(o, n, v);" %1545 set_entry.func_cname)1546 else:1547 self.generate_guarded_basetype_call(1548 base_type, None, "tp_setattro", "o, n, v", code)1549 code.putln(1550 "return PyObject_GenericSetAttr(o, n, v);")1551 code.putln(1552 "}")1553 code.putln(1554 "else {")1555 if del_entry:1556 code.putln(1557 "return %s(o, n);" %1558 del_entry.func_cname)1559 else:1560 self.generate_guarded_basetype_call(1561 base_type, None, "tp_setattro", "o, n, v", code)1562 code.putln(1563 "return PyObject_GenericSetAttr(o, n, 0);")1564 code.putln(1565 "}")1566 code.putln(1567 "}")1568 def generate_descr_get_function(self, scope, code):1569 # The __get__ function of a descriptor object can be1570 # called with NULL for the second or third arguments1571 # under some circumstances, so we replace them with1572 # None in that case.1573 user_get_entry = scope.lookup_here("__get__")1574 code.putln("")1575 code.putln(1576 "static PyObject *%s(PyObject *o, PyObject *i, PyObject *c) {" %1577 scope.mangle_internal("tp_descr_get"))1578 code.putln(1579 "PyObject *r = 0;")1580 code.putln(1581 "if (!i) i = Py_None;")1582 code.putln(1583 "if (!c) c = Py_None;")1584 #code.put_incref("i", py_object_type)1585 #code.put_incref("c", py_object_type)1586 code.putln(1587 "r = %s(o, i, c);" %1588 user_get_entry.func_cname)1589 #code.put_decref("i", py_object_type)1590 #code.put_decref("c", py_object_type)1591 code.putln(1592 "return r;")1593 code.putln(1594 "}")1595 def generate_descr_set_function(self, scope, code):1596 # Setting and deleting are both done through the __set__1597 # method of a descriptor, so we dispatch to user's __set__1598 # or __delete__ or raise an exception.1599 base_type = scope.parent_type.base_type1600 user_set_entry = scope.lookup_here("__set__")1601 user_del_entry = scope.lookup_here("__delete__")1602 code.putln("")1603 code.putln(1604 "static int %s(PyObject *o, PyObject *i, PyObject *v) {" %1605 scope.mangle_internal("tp_descr_set"))1606 code.putln(1607 "if (v) {")1608 if user_set_entry:1609 code.putln(1610 "return %s(o, i, v);" %1611 user_set_entry.func_cname)1612 else:1613 self.generate_guarded_basetype_call(1614 base_type, None, "tp_descr_set", "o, i, v", code)1615 code.putln(1616 'PyErr_SetString(PyExc_NotImplementedError, "__set__");')1617 code.putln(1618 "return -1;")1619 code.putln(1620 "}")1621 code.putln(1622 "else {")1623 if user_del_entry:1624 code.putln(1625 "return %s(o, i);" %1626 user_del_entry.func_cname)1627 else:1628 self.generate_guarded_basetype_call(1629 base_type, None, "tp_descr_set", "o, i, v", code)1630 code.putln(1631 'PyErr_SetString(PyExc_NotImplementedError, "__delete__");')1632 code.putln(1633 "return -1;")1634 code.putln(1635 "}")1636 code.putln(1637 "}")1638 def generate_property_accessors(self, cclass_scope, code):1639 for entry in cclass_scope.property_entries:1640 property_scope = entry.scope1641 if property_scope.defines_any(["__get__"]):1642 self.generate_property_get_function(entry, code)1643 if property_scope.defines_any(["__set__", "__del__"]):1644 self.generate_property_set_function(entry, code)1645 def generate_property_get_function(self, property_entry, code):1646 property_scope = property_entry.scope1647 property_entry.getter_cname = property_scope.parent_scope.mangle(1648 Naming.prop_get_prefix, property_entry.name)1649 get_entry = property_scope.lookup_here("__get__")1650 code.putln("")1651 code.putln(1652 "static PyObject *%s(PyObject *o, CYTHON_UNUSED void *x) {" %1653 property_entry.getter_cname)1654 code.putln(1655 "return %s(o);" %1656 get_entry.func_cname)1657 code.putln(1658 "}")1659 def generate_property_set_function(self, property_entry, code):1660 property_scope = property_entry.scope1661 property_entry.setter_cname = property_scope.parent_scope.mangle(1662 Naming.prop_set_prefix, property_entry.name)1663 set_entry = property_scope.lookup_here("__set__")1664 del_entry = property_scope.lookup_here("__del__")1665 code.putln("")1666 code.putln(1667 "static int %s(PyObject *o, PyObject *v, CYTHON_UNUSED void *x) {" %1668 property_entry.setter_cname)1669 code.putln(1670 "if (v) {")1671 if set_entry:1672 code.putln(1673 "return %s(o, v);" %1674 set_entry.func_cname)1675 else:1676 code.putln(1677 'PyErr_SetString(PyExc_NotImplementedError, "__set__");')1678 code.putln(1679 "return -1;")1680 code.putln(1681 "}")1682 code.putln(1683 "else {")1684 if del_entry:1685 code.putln(1686 "return %s(o);" %1687 del_entry.func_cname)1688 else:1689 code.putln(1690 'PyErr_SetString(PyExc_NotImplementedError, "__del__");')1691 code.putln(1692 "return -1;")1693 code.putln(1694 "}")1695 code.putln(1696 "}")1697 def generate_typeobj_definition(self, modname, entry, code):1698 type = entry.type1699 scope = type.scope1700 for suite in TypeSlots.substructures:1701 suite.generate_substructure(scope, code)1702 code.putln("")1703 if entry.visibility == 'public':1704 header = "DL_EXPORT(PyTypeObject) %s = {"1705 else:1706 header = "static PyTypeObject %s = {"1707 #code.putln(header % scope.parent_type.typeobj_cname)1708 code.putln(header % type.typeobj_cname)1709 code.putln(1710 "PyVarObject_HEAD_INIT(0, 0)")1711 code.putln(1712 '__Pyx_NAMESTR("%s.%s"), /*tp_name*/' % (1713 self.full_module_name, scope.class_name))1714 if type.typedef_flag:1715 objstruct = type.objstruct_cname1716 else:1717 objstruct = "struct %s" % type.objstruct_cname1718 code.putln(1719 "sizeof(%s), /*tp_basicsize*/" %1720 objstruct)1721 code.putln(1722 "0, /*tp_itemsize*/")1723 for slot in TypeSlots.slot_table:1724 slot.generate(scope, code)1725 code.putln(1726 "};")1727 def generate_method_table(self, env, code):1728 if env.is_c_class_scope and not env.pyfunc_entries:1729 return1730 code.putln("")1731 code.putln(1732 "static PyMethodDef %s[] = {" %1733 env.method_table_cname)1734 for entry in env.pyfunc_entries:1735 if not entry.fused_cfunction:1736 code.put_pymethoddef(entry, ",")1737 code.putln(1738 "{0, 0, 0, 0}")1739 code.putln(1740 "};")1741 def generate_getset_table(self, env, code):1742 if env.property_entries:1743 code.putln("")1744 code.putln(1745 "static struct PyGetSetDef %s[] = {" %1746 env.getset_table_cname)1747 for entry in env.property_entries:1748 if entry.doc:1749 doc_code = "__Pyx_DOCSTR(%s)" % code.get_string_const(entry.doc)1750 else:1751 doc_code = "0"1752 code.putln(1753 '{(char *)"%s", %s, %s, %s, 0},' % (1754 entry.name,1755 entry.getter_cname or "0",1756 entry.setter_cname or "0",1757 doc_code))1758 code.putln(1759 "{0, 0, 0, 0, 0}")1760 code.putln(1761 "};")1762 def generate_import_star(self, env, code):1763 env.use_utility_code(streq_utility_code)1764 code.putln()1765 code.putln("static char* %s_type_names[] = {" % Naming.import_star)1766 for name, entry in sorted(env.entries.items()):1767 if entry.is_type:1768 code.putln('"%s",' % name)1769 code.putln("0")1770 code.putln("};")1771 code.putln()1772 code.enter_cfunc_scope() # as we need labels1773 code.putln("static int %s(PyObject *o, PyObject* py_name, char *name) {" % Naming.import_star_set)1774 code.putln("char** type_name = %s_type_names;" % Naming.import_star)1775 code.putln("while (*type_name) {")1776 code.putln("if (__Pyx_StrEq(name, *type_name)) {")1777 code.putln('PyErr_Format(PyExc_TypeError, "Cannot overwrite C type %s", name);')1778 code.putln('goto bad;')1779 code.putln("}")1780 code.putln("type_name++;")1781 code.putln("}")1782 old_error_label = code.new_error_label()1783 code.putln("if (0);") # so the first one can be "else if"1784 for name, entry in env.entries.items():1785 if entry.is_cglobal and entry.used:1786 code.putln('else if (__Pyx_StrEq(name, "%s")) {' % name)1787 if entry.type.is_pyobject:1788 if entry.type.is_extension_type or entry.type.is_builtin_type:1789 code.putln("if (!(%s)) %s;" % (1790 entry.type.type_test_code("o"),1791 code.error_goto(entry.pos)))1792 code.putln("Py_INCREF(o);")1793 code.put_decref(entry.cname, entry.type, nanny=False)1794 code.putln("%s = %s;" % (1795 entry.cname,1796 PyrexTypes.typecast(entry.type, py_object_type, "o")))1797 elif entry.type.from_py_function:1798 rhs = "%s(o)" % entry.type.from_py_function1799 if entry.type.is_enum:1800 rhs = PyrexTypes.typecast(entry.type, PyrexTypes.c_long_type, rhs)1801 code.putln("%s = %s; if (%s) %s;" % (1802 entry.cname,1803 rhs,1804 entry.type.error_condition(entry.cname),1805 code.error_goto(entry.pos)))1806 else:1807 code.putln('PyErr_Format(PyExc_TypeError, "Cannot convert Python object %s to %s");' % (name, entry.type))1808 code.putln(code.error_goto(entry.pos))1809 code.putln("}")1810 code.putln("else {")1811 code.putln("if (PyObject_SetAttr(%s, py_name, o) < 0) goto bad;" % Naming.module_cname)1812 code.putln("}")1813 code.putln("return 0;")1814 if code.label_used(code.error_label):1815 code.put_label(code.error_label)1816 # This helps locate the offending name.1817 code.put_add_traceback(self.full_module_name)1818 code.error_label = old_error_label1819 code.putln("bad:")1820 code.putln("return -1;")1821 code.putln("}")1822 code.putln(import_star_utility_code)1823 code.exit_cfunc_scope() # done with labels1824 def generate_module_init_func(self, imported_modules, env, code):1825 code.enter_cfunc_scope()1826 code.putln("")1827 header2 = "PyMODINIT_FUNC init%s(void)" % env.module_name1828 header3 = "PyMODINIT_FUNC PyInit_%s(void)" % env.module_name1829 code.putln("#if PY_MAJOR_VERSION < 3")1830 code.putln("%s; /*proto*/" % header2)1831 code.putln(header2)1832 code.putln("#else")1833 code.putln("%s; /*proto*/" % header3)1834 code.putln(header3)1835 code.putln("#endif")1836 code.putln("{")1837 tempdecl_code = code.insertion_point()1838 code.put_declare_refcount_context()1839 code.putln("#if CYTHON_REFNANNY")1840 code.putln("__Pyx_RefNanny = __Pyx_RefNannyImportAPI(\"refnanny\");")1841 code.putln("if (!__Pyx_RefNanny) {")1842 code.putln(" PyErr_Clear();")1843 code.putln(" __Pyx_RefNanny = __Pyx_RefNannyImportAPI(\"Cython.Runtime.refnanny\");")1844 code.putln(" if (!__Pyx_RefNanny)")1845 code.putln(" Py_FatalError(\"failed to import 'refnanny' module\");")1846 code.putln("}")1847 code.putln("#endif")1848 code.put_setup_refcount_context(header3)1849 env.use_utility_code(UtilityCode.load("CheckBinaryVersion", "ModuleSetupCode.c"))1850 code.putln("if ( __Pyx_check_binary_version() < 0) %s" % code.error_goto(self.pos))1851 code.putln("%s = PyTuple_New(0); %s" % (Naming.empty_tuple, code.error_goto_if_null(Naming.empty_tuple, self.pos)))1852 code.putln("%s = PyBytes_FromStringAndSize(\"\", 0); %s" % (Naming.empty_bytes, code.error_goto_if_null(Naming.empty_bytes, self.pos)))1853 code.putln("#ifdef __Pyx_CyFunction_USED")1854 code.putln("if (__Pyx_CyFunction_init() < 0) %s" % code.error_goto(self.pos))1855 code.putln("#endif")1856 code.putln("#ifdef __Pyx_FusedFunction_USED")1857 code.putln("if (__pyx_FusedFunction_init() < 0) %s" % code.error_goto(self.pos))1858 code.putln("#endif")1859 code.putln("#ifdef __Pyx_Generator_USED")1860 code.putln("if (__pyx_Generator_init() < 0) %s" % code.error_goto(self.pos))1861 code.putln("#endif")1862 code.putln("/*--- Library function declarations ---*/")1863 env.generate_library_function_declarations(code)1864 code.putln("/*--- Threads initialization code ---*/")1865 code.putln("#if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS")1866 code.putln("#ifdef WITH_THREAD /* Python build with threading support? */")1867 code.putln("PyEval_InitThreads();")1868 code.putln("#endif")1869 code.putln("#endif")1870 code.putln("/*--- Module creation code ---*/")1871 self.generate_module_creation_code(env, code)1872 code.putln("/*--- Initialize various global constants etc. ---*/")1873 code.putln(code.error_goto_if_neg("__Pyx_InitGlobals()", self.pos))1874 code.putln("#if PY_MAJOR_VERSION < 3 && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT)")1875 code.putln("if (__Pyx_init_sys_getdefaultencoding_params() < 0) %s" % code.error_goto(self.pos))1876 code.putln("#endif")1877 __main__name = code.globalstate.get_py_string_const(1878 EncodedString("__main__"), identifier=True)1879 code.putln("if (%s%s) {" % (Naming.module_is_main, self.full_module_name.replace('.', '__')))1880 code.putln(1881 'if (__Pyx_SetAttrString(%s, "__name__", %s) < 0) %s;' % (1882 env.module_cname,1883 __main__name.cname,1884 code.error_goto(self.pos)))1885 code.putln("}")1886 # set up __file__ and __path__, then add the module to sys.modules1887 self.generate_module_import_setup(env, code)1888 if Options.cache_builtins:1889 code.putln("/*--- Builtin init code ---*/")1890 code.putln(code.error_goto_if_neg("__Pyx_InitCachedBuiltins()", self.pos))1891 code.putln("/*--- Constants init code ---*/")1892 code.putln(code.error_goto_if_neg("__Pyx_InitCachedConstants()", self.pos))1893 code.putln("/*--- Global init code ---*/")1894 self.generate_global_init_code(env, code)1895 code.putln("/*--- Variable export code ---*/")1896 self.generate_c_variable_export_code(env, code)1897 code.putln("/*--- Function export code ---*/")1898 self.generate_c_function_export_code(env, code)1899 code.putln("/*--- Type init code ---*/")1900 self.generate_type_init_code(env, code)1901 code.putln("/*--- Type import code ---*/")1902 for module in imported_modules:1903 self.generate_type_import_code_for_module(module, env, code)1904 code.putln("/*--- Variable import code ---*/")1905 for module in imported_modules:1906 self.generate_c_variable_import_code_for_module(module, env, code)1907 code.putln("/*--- Function import code ---*/")1908 for module in imported_modules:1909 self.specialize_fused_types(module)1910 self.generate_c_function_import_code_for_module(module, env, code)1911 code.putln("/*--- Execution code ---*/")1912 code.mark_pos(None)1913 self.body.generate_execution_code(code)1914 if Options.generate_cleanup_code:1915 code.globalstate.use_utility_code(1916 UtilityCode.load_cached("RegisterModuleCleanup", "ModuleSetupCode.c"))1917 code.putln("if (__Pyx_RegisterCleanup()) %s;" % code.error_goto(self.pos))1918 code.put_goto(code.return_label)1919 code.put_label(code.error_label)1920 for cname, type in code.funcstate.all_managed_temps():1921 code.put_xdecref(cname, type)1922 code.putln('if (%s) {' % env.module_cname)1923 code.put_add_traceback("init %s" % env.qualified_name)1924 env.use_utility_code(Nodes.traceback_utility_code)1925 code.put_decref_clear(env.module_cname, py_object_type, nanny=False)1926 code.putln('} else if (!PyErr_Occurred()) {')1927 code.putln('PyErr_SetString(PyExc_ImportError, "init %s");' % env.qualified_name)1928 code.putln('}')1929 code.put_label(code.return_label)1930 code.put_finish_refcount_context()1931 code.putln("#if PY_MAJOR_VERSION < 3")1932 code.putln("return;")1933 code.putln("#else")1934 code.putln("return %s;" % env.module_cname)1935 code.putln("#endif")1936 code.putln('}')1937 tempdecl_code.put_temp_declarations(code.funcstate)1938 code.exit_cfunc_scope()1939 def generate_module_import_setup(self, env, code):1940 module_path = env.directives['set_initial_path']1941 if module_path == 'SOURCEFILE':1942 module_path = self.pos[0].filename1943 if module_path:1944 code.putln('if (__Pyx_SetAttrString(%s, "__file__", %s) < 0) %s;' % (1945 env.module_cname,1946 code.globalstate.get_py_string_const(1947 EncodedString(decode_filename(module_path))).cname,1948 code.error_goto(self.pos)))1949 if env.is_package:1950 # set __path__ to mark the module as package1951 temp = code.funcstate.allocate_temp(py_object_type, True)1952 code.putln('%s = Py_BuildValue("[O]", %s); %s' % (1953 temp,1954 code.globalstate.get_py_string_const(1955 EncodedString(decode_filename(1956 os.path.dirname(module_path)))).cname,1957 code.error_goto_if_null(temp, self.pos)))1958 code.put_gotref(temp)1959 code.putln(1960 'if (__Pyx_SetAttrString(%s, "__path__", %s) < 0) %s;' % (1961 env.module_cname, temp, code.error_goto(self.pos)))1962 code.put_decref_clear(temp, py_object_type)1963 code.funcstate.release_temp(temp)1964 elif env.is_package:1965 # packages require __path__, so all we can do is try to figure1966 # out the module path at runtime by rerunning the import lookup1967 package_name, _ = self.full_module_name.rsplit('.', 1)1968 if '.' in package_name:1969 parent_name = '"%s"' % (package_name.rsplit('.', 1)[0],)1970 else:1971 parent_name = 'NULL'1972 code.globalstate.use_utility_code(UtilityCode.load(1973 "SetPackagePathFromImportLib", "ImportExport.c"))1974 code.putln(code.error_goto_if_neg(1975 '__Pyx_SetPackagePathFromImportLib(%s, %s)' % (1976 parent_name,1977 code.globalstate.get_py_string_const(1978 EncodedString(env.module_name)).cname),1979 self.pos))1980 # CPython may not have put us into sys.modules yet, but relative imports and reimports require it1981 fq_module_name = self.full_module_name1982 if fq_module_name.endswith('.__init__'):1983 fq_module_name = fq_module_name[:-len('.__init__')]1984 code.putln("#if PY_MAJOR_VERSION >= 3")1985 code.putln("{")1986 code.putln("PyObject *modules = PyImport_GetModuleDict(); %s" %1987 code.error_goto_if_null("modules", self.pos))1988 code.putln('if (!PyDict_GetItemString(modules, "%s")) {' % fq_module_name)1989 code.putln(code.error_goto_if_neg('PyDict_SetItemString(modules, "%s", %s)' % (1990 fq_module_name, env.module_cname), self.pos))1991 code.putln("}")1992 code.putln("}")1993 code.putln("#endif")1994 def generate_module_cleanup_func(self, env, code):1995 if not Options.generate_cleanup_code:1996 return1997 code.putln('static void %s(CYTHON_UNUSED PyObject *self) {' %1998 Naming.cleanup_cname)1999 if Options.generate_cleanup_code >= 2:2000 code.putln("/*--- Global cleanup code ---*/")2001 rev_entries = list(env.var_entries)2002 rev_entries.reverse()2003 for entry in rev_entries:2004 if entry.visibility != 'extern':2005 if entry.type.is_pyobject and entry.used:2006 code.put_xdecref_clear(2007 entry.cname, entry.type,2008 clear_before_decref=True,2009 nanny=False)2010 code.putln("__Pyx_CleanupGlobals();")2011 if Options.generate_cleanup_code >= 3:2012 code.putln("/*--- Type import cleanup code ---*/")2013 for ext_type in sorted(env.types_imported, key=operator.attrgetter('typeptr_cname')):2014 code.put_xdecref_clear(2015 ext_type.typeptr_cname, ext_type,2016 clear_before_decref=True,2017 nanny=False)2018 if Options.cache_builtins:2019 code.putln("/*--- Builtin cleanup code ---*/")2020 for entry in env.cached_builtins:2021 code.put_xdecref_clear(2022 entry.cname, PyrexTypes.py_object_type,2023 clear_before_decref=True,2024 nanny=False)2025 code.putln("/*--- Intern cleanup code ---*/")2026 code.put_decref_clear(Naming.empty_tuple,2027 PyrexTypes.py_object_type,2028 clear_before_decref=True,2029 nanny=False)2030 for entry in env.c_class_entries:2031 cclass_type = entry.type2032 if cclass_type.is_external or cclass_type.base_type:2033 continue2034 if cclass_type.scope.directives.get('freelist', 0):2035 scope = cclass_type.scope2036 freelist_name = scope.mangle_internal(Naming.freelist_name)2037 freecount_name = scope.mangle_internal(Naming.freecount_name)2038 code.putln("while (%s > 0) {" % freecount_name)2039 code.putln("PyObject* o = (PyObject*)%s[--%s];" % (2040 freelist_name, freecount_name))2041 code.putln("(*Py_TYPE(o)->tp_free)(o);")2042 code.putln("}")2043# for entry in env.pynum_entries:2044# code.put_decref_clear(entry.cname,2045# PyrexTypes.py_object_type,2046# nanny=False)2047# for entry in env.all_pystring_entries:2048# if entry.is_interned:2049# code.put_decref_clear(entry.pystring_cname,2050# PyrexTypes.py_object_type,2051# nanny=False)2052# for entry in env.default_entries:2053# if entry.type.is_pyobject and entry.used:2054# code.putln("Py_DECREF(%s); %s = 0;" % (2055# code.entry_as_pyobject(entry), entry.cname))2056 code.putln('#if CYTHON_COMPILING_IN_PYPY')2057 code.putln('Py_CLEAR(%s);' % Naming.builtins_cname)2058 code.putln('#endif')2059 code.put_decref_clear(env.module_dict_cname, py_object_type,2060 nanny=False, clear_before_decref=True)2061 def generate_main_method(self, env, code):2062 module_is_main = "%s%s" % (Naming.module_is_main, self.full_module_name.replace('.', '__'))2063 if Options.embed == "main":2064 wmain = "wmain"2065 else:2066 wmain = Options.embed2067 code.globalstate.use_utility_code(2068 main_method.specialize(2069 module_name = env.module_name,2070 module_is_main = module_is_main,2071 main_method = Options.embed,2072 wmain_method = wmain))2073 def generate_pymoduledef_struct(self, env, code):2074 if env.doc:2075 doc = "__Pyx_DOCSTR(%s)" % code.get_string_const(env.doc)2076 else:2077 doc = "0"2078 if Options.generate_cleanup_code:2079 cleanup_func = "(freefunc)%s" % Naming.cleanup_cname2080 else:2081 cleanup_func = 'NULL'2082 code.putln("")2083 code.putln("#if PY_MAJOR_VERSION >= 3")2084 code.putln("static struct PyModuleDef %s = {" % Naming.pymoduledef_cname)2085 code.putln("#if PY_VERSION_HEX < 0x03020000")2086 # fix C compiler warnings due to missing initialisers2087 code.putln(" { PyObject_HEAD_INIT(NULL) NULL, 0, NULL },")2088 code.putln("#else")2089 code.putln(" PyModuleDef_HEAD_INIT,")2090 code.putln("#endif")2091 code.putln(' __Pyx_NAMESTR("%s"),' % env.module_name)2092 code.putln(" %s, /* m_doc */" % doc)2093 code.putln(" -1, /* m_size */")2094 code.putln(" %s /* m_methods */," % env.method_table_cname)2095 code.putln(" NULL, /* m_reload */")2096 code.putln(" NULL, /* m_traverse */")2097 code.putln(" NULL, /* m_clear */")2098 code.putln(" %s /* m_free */" % cleanup_func)2099 code.putln("};")2100 code.putln("#endif")2101 def generate_module_creation_code(self, env, code):2102 # Generate code to create the module object and2103 # install the builtins.2104 if env.doc:2105 doc = "__Pyx_DOCSTR(%s)" % code.get_string_const(env.doc)2106 else:2107 doc = "0"2108 code.putln("#if PY_MAJOR_VERSION < 3")2109 code.putln(2110 '%s = Py_InitModule4(__Pyx_NAMESTR("%s"), %s, %s, 0, PYTHON_API_VERSION); Py_XINCREF(%s);' % (2111 env.module_cname,2112 env.module_name,2113 env.method_table_cname,2114 doc,2115 env.module_cname))2116 code.putln("#else")2117 code.putln(2118 "%s = PyModule_Create(&%s);" % (2119 env.module_cname,2120 Naming.pymoduledef_cname))2121 code.putln("#endif")2122 code.putln(code.error_goto_if_null(env.module_cname, self.pos))2123 code.putln(2124 "%s = PyModule_GetDict(%s); %s" % (2125 env.module_dict_cname, env.module_cname,2126 code.error_goto_if_null(env.module_dict_cname, self.pos)))2127 code.put_incref(env.module_dict_cname, py_object_type, nanny=False)2128 code.putln(2129 '%s = PyImport_AddModule(__Pyx_NAMESTR(__Pyx_BUILTIN_MODULE_NAME)); %s' % (2130 Naming.builtins_cname,2131 code.error_goto_if_null(Naming.builtins_cname, self.pos)))2132 code.putln('#if CYTHON_COMPILING_IN_PYPY')2133 code.putln('Py_INCREF(%s);' % Naming.builtins_cname)2134 code.putln('#endif')2135 code.putln(2136 'if (__Pyx_SetAttrString(%s, "__builtins__", %s) < 0) %s;' % (2137 env.module_cname,2138 Naming.builtins_cname,2139 code.error_goto(self.pos)))2140 if Options.pre_import is not None:2141 code.putln(2142 '%s = PyImport_AddModule(__Pyx_NAMESTR("%s")); %s' % (2143 Naming.preimport_cname,2144 Options.pre_import,2145 code.error_goto_if_null(Naming.preimport_cname, self.pos)))2146 def generate_global_init_code(self, env, code):2147 # Generate code to initialise global PyObject *2148 # variables to None.2149 for entry in env.var_entries:2150 if entry.visibility != 'extern':2151 if entry.used:2152 entry.type.global_init_code(entry, code)2153 def generate_c_variable_export_code(self, env, code):2154 # Generate code to create PyCFunction wrappers for exported C functions.2155 entries = []2156 for entry in env.var_entries:2157 if (entry.api2158 or entry.defined_in_pxd2159 or (Options.cimport_from_pyx and not entry.visibility == 'extern')):2160 entries.append(entry)2161 if entries:2162 env.use_utility_code(UtilityCode.load_cached("VoidPtrExport", "ImportExport.c"))2163 for entry in entries:2164 signature = entry.type.declaration_code("")2165 name = code.intern_identifier(entry.name)2166 code.putln('if (__Pyx_ExportVoidPtr(%s, (void *)&%s, "%s") < 0) %s' % (2167 name, entry.cname, signature,2168 code.error_goto(self.pos)))2169 def generate_c_function_export_code(self, env, code):2170 # Generate code to create PyCFunction wrappers for exported C functions.2171 entries = []2172 for entry in env.cfunc_entries:2173 if (entry.api2174 or entry.defined_in_pxd2175 or (Options.cimport_from_pyx and not entry.visibility == 'extern')):2176 entries.append(entry)2177 if entries:2178 env.use_utility_code(2179 UtilityCode.load_cached("FunctionExport", "ImportExport.c"))2180 for entry in entries:2181 signature = entry.type.signature_string()2182 code.putln('if (__Pyx_ExportFunction("%s", (void (*)(void))%s, "%s") < 0) %s' % (2183 entry.name,2184 entry.cname,2185 signature,2186 code.error_goto(self.pos)))2187 def generate_type_import_code_for_module(self, module, env, code):2188 # Generate type import code for all exported extension types in2189 # an imported module.2190 #if module.c_class_entries:2191 for entry in module.c_class_entries:2192 if entry.defined_in_pxd:2193 self.generate_type_import_code(env, entry.type, entry.pos, code)2194 def specialize_fused_types(self, pxd_env):2195 """2196 If fused c(p)def functions are defined in an imported pxd, but not2197 used in this implementation file, we still have fused entries and2198 not specialized ones. This method replaces any fused entries with their2199 specialized ones.2200 """2201 for entry in pxd_env.cfunc_entries[:]:2202 if entry.type.is_fused:2203 # This call modifies the cfunc_entries in-place2204 entry.type.get_all_specialized_function_types()2205 def generate_c_variable_import_code_for_module(self, module, env, code):2206 # Generate import code for all exported C functions in a cimported module.2207 entries = []2208 for entry in module.var_entries:2209 if entry.defined_in_pxd:2210 entries.append(entry)2211 if entries:2212 env.use_utility_code(2213 UtilityCode.load_cached("ModuleImport", "ImportExport.c"))2214 env.use_utility_code(2215 UtilityCode.load_cached("VoidPtrImport", "ImportExport.c"))2216 temp = code.funcstate.allocate_temp(py_object_type, manage_ref=True)2217 code.putln(2218 '%s = __Pyx_ImportModule("%s"); if (!%s) %s' % (2219 temp,2220 module.qualified_name,2221 temp,2222 code.error_goto(self.pos)))2223 for entry in entries:2224 if env is module:2225 cname = entry.cname2226 else:2227 cname = module.mangle(Naming.varptr_prefix, entry.name)2228 signature = entry.type.declaration_code("")2229 code.putln(2230 'if (__Pyx_ImportVoidPtr(%s, "%s", (void **)&%s, "%s") < 0) %s' % (2231 temp, entry.name, cname, signature,2232 code.error_goto(self.pos)))2233 code.putln("Py_DECREF(%s); %s = 0;" % (temp, temp))2234 def generate_c_function_import_code_for_module(self, module, env, code):2235 # Generate import code for all exported C functions in a cimported module.2236 entries = []2237 for entry in module.cfunc_entries:2238 if entry.defined_in_pxd and entry.used:2239 entries.append(entry)2240 if entries:2241 env.use_utility_code(2242 UtilityCode.load_cached("ModuleImport", "ImportExport.c"))2243 env.use_utility_code(2244 UtilityCode.load_cached("FunctionImport", "ImportExport.c"))2245 temp = code.funcstate.allocate_temp(py_object_type, manage_ref=True)2246 code.putln(2247 '%s = __Pyx_ImportModule("%s"); if (!%s) %s' % (2248 temp,2249 module.qualified_name,2250 temp,2251 code.error_goto(self.pos)))2252 for entry in entries:2253 code.putln(2254 'if (__Pyx_ImportFunction(%s, "%s", (void (**)(void))&%s, "%s") < 0) %s' % (2255 temp,2256 entry.name,2257 entry.cname,2258 entry.type.signature_string(),2259 code.error_goto(self.pos)))2260 code.putln("Py_DECREF(%s); %s = 0;" % (temp, temp))2261 def generate_type_init_code(self, env, code):2262 # Generate type import code for extern extension types2263 # and type ready code for non-extern ones.2264 for entry in env.c_class_entries:2265 if entry.visibility == 'extern' and not entry.utility_code_definition:2266 self.generate_type_import_code(env, entry.type, entry.pos, code)2267 else:2268 self.generate_base_type_import_code(env, entry, code)2269 self.generate_exttype_vtable_init_code(entry, code)2270 self.generate_type_ready_code(env, entry, code)2271 self.generate_typeptr_assignment_code(entry, code)2272 def generate_base_type_import_code(self, env, entry, code):2273 base_type = entry.type.base_type2274 if (base_type and base_type.module_name != env.qualified_name and not2275 base_type.is_builtin_type and not entry.utility_code_definition):2276 self.generate_type_import_code(env, base_type, self.pos, code)2277 def generate_type_import_code(self, env, type, pos, code):2278 # If not already done, generate code to import the typeobject of an2279 # extension type defined in another module, and extract its C method2280 # table pointer if any.2281 if type in env.types_imported:2282 return2283 env.use_utility_code(UtilityCode.load_cached("TypeImport", "ImportExport.c"))2284 self.generate_type_import_call(type, code,2285 code.error_goto_if_null(type.typeptr_cname, pos))2286 if type.vtabptr_cname:2287 code.globalstate.use_utility_code(2288 UtilityCode.load_cached('GetVTable', 'ImportExport.c'))2289 code.putln("%s = (struct %s*)__Pyx_GetVtable(%s->tp_dict); %s" % (2290 type.vtabptr_cname,2291 type.vtabstruct_cname,2292 type.typeptr_cname,2293 code.error_goto_if_null(type.vtabptr_cname, pos)))2294 env.types_imported.add(type)2295 py3_type_name_map = {'str' : 'bytes', 'unicode' : 'str'}2296 def generate_type_import_call(self, type, code, error_code):2297 if type.typedef_flag:2298 objstruct = type.objstruct_cname2299 else:2300 objstruct = "struct %s" % type.objstruct_cname2301 sizeof_objstruct = objstruct2302 module_name = type.module_name2303 condition = replacement = None2304 if module_name not in ('__builtin__', 'builtins'):2305 module_name = '"%s"' % module_name2306 else:2307 module_name = '__Pyx_BUILTIN_MODULE_NAME'2308 if type.name in Code.non_portable_builtins_map:2309 condition, replacement = Code.non_portable_builtins_map[type.name]2310 if objstruct in Code.basicsize_builtins_map:2311 # Some builtin types have a tp_basicsize which differs from sizeof(...):2312 sizeof_objstruct = Code.basicsize_builtins_map[objstruct]2313 code.put('%s = __Pyx_ImportType(%s,' % (2314 type.typeptr_cname,2315 module_name))2316 if condition and replacement:2317 code.putln("") # start in new line2318 code.putln("#if %s" % condition)2319 code.putln('"%s",' % replacement)2320 code.putln("#else")2321 code.putln('"%s",' % type.name)2322 code.putln("#endif")2323 else:2324 code.put(' "%s", ' % type.name)2325 if sizeof_objstruct != objstruct:2326 if not condition:2327 code.putln("") # start in new line2328 code.putln("#if CYTHON_COMPILING_IN_PYPY")2329 code.putln('sizeof(%s),' % objstruct)2330 code.putln("#else")2331 code.putln('sizeof(%s),' % sizeof_objstruct)2332 code.putln("#endif")2333 else:2334 code.put('sizeof(%s), ' % objstruct)2335 code.putln('%i); %s' % (2336 not type.is_external or type.is_subclassed,2337 error_code))2338 def generate_type_ready_code(self, env, entry, code):2339 # Generate a call to PyType_Ready for an extension2340 # type defined in this module.2341 type = entry.type2342 typeobj_cname = type.typeobj_cname2343 scope = type.scope2344 if scope: # could be None if there was an error2345 if entry.visibility != 'extern':2346 for slot in TypeSlots.slot_table:2347 slot.generate_dynamic_init_code(scope, code)2348 code.putln(2349 "if (PyType_Ready(&%s) < 0) %s" % (2350 typeobj_cname,2351 code.error_goto(entry.pos)))2352 # Don't inherit tp_print from builtin types, restoring the2353 # behavior of using tp_repr or tp_str instead.2354 code.putln("%s.tp_print = 0;" % typeobj_cname)2355 # Fix special method docstrings. This is a bit of a hack, but2356 # unless we let PyType_Ready create the slot wrappers we have2357 # a significant performance hit. (See trac #561.)2358 for func in entry.type.scope.pyfunc_entries:2359 is_buffer = func.name in ('__getbuffer__',2360 '__releasebuffer__')2361 if (func.is_special and Options.docstrings and2362 func.wrapperbase_cname and not is_buffer):2363 slot = TypeSlots.method_name_to_slot[func.name]2364 preprocessor_guard = slot.preprocessor_guard_code()2365 if preprocessor_guard:2366 code.putln(preprocessor_guard)2367 code.putln('#if CYTHON_COMPILING_IN_CPYTHON')2368 code.putln("{")2369 code.putln(2370 'PyObject *wrapper = __Pyx_GetAttrString((PyObject *)&%s, "%s"); %s' % (2371 typeobj_cname,2372 func.name,2373 code.error_goto_if_null('wrapper', entry.pos)))2374 code.putln(2375 "if (Py_TYPE(wrapper) == &PyWrapperDescr_Type) {")2376 code.putln(2377 "%s = *((PyWrapperDescrObject *)wrapper)->d_base;" % (2378 func.wrapperbase_cname))2379 code.putln(2380 "%s.doc = %s;" % (func.wrapperbase_cname, func.doc_cname))2381 code.putln(2382 "((PyWrapperDescrObject *)wrapper)->d_base = &%s;" % (2383 func.wrapperbase_cname))2384 code.putln("}")2385 code.putln("}")2386 code.putln('#endif')2387 if preprocessor_guard:2388 code.putln('#endif')2389 if type.vtable_cname:2390 code.putln(2391 "if (__Pyx_SetVtable(%s.tp_dict, %s) < 0) %s" % (2392 typeobj_cname,2393 type.vtabptr_cname,2394 code.error_goto(entry.pos)))2395 code.globalstate.use_utility_code(2396 UtilityCode.load_cached('SetVTable', 'ImportExport.c'))2397 if not type.scope.is_internal and not type.scope.directives['internal']:2398 # scope.is_internal is set for types defined by2399 # Cython (such as closures), the 'internal'2400 # directive is set by users2401 code.putln(2402 'if (__Pyx_SetAttrString(%s, "%s", (PyObject *)&%s) < 0) %s' % (2403 Naming.module_cname,2404 scope.class_name,2405 typeobj_cname,2406 code.error_goto(entry.pos)))2407 weakref_entry = scope.lookup_here("__weakref__")2408 if weakref_entry:2409 if weakref_entry.type is py_object_type:2410 tp_weaklistoffset = "%s.tp_weaklistoffset" % typeobj_cname2411 if type.typedef_flag:2412 objstruct = type.objstruct_cname2413 else:2414 objstruct = "struct %s" % type.objstruct_cname2415 code.putln("if (%s == 0) %s = offsetof(%s, %s);" % (2416 tp_weaklistoffset,2417 tp_weaklistoffset,2418 objstruct,2419 weakref_entry.cname))2420 else:2421 error(weakref_entry.pos, "__weakref__ slot must be of type 'object'")2422 def generate_exttype_vtable_init_code(self, entry, code):2423 # Generate code to initialise the C method table of an2424 # extension type.2425 type = entry.type2426 if type.vtable_cname:2427 code.putln(2428 "%s = &%s;" % (2429 type.vtabptr_cname,2430 type.vtable_cname))2431 if type.base_type and type.base_type.vtabptr_cname:2432 code.putln(2433 "%s.%s = *%s;" % (2434 type.vtable_cname,2435 Naming.obj_base_cname,2436 type.base_type.vtabptr_cname))2437 c_method_entries = [2438 entry for entry in type.scope.cfunc_entries2439 if entry.func_cname ]2440 if c_method_entries:2441 for meth_entry in c_method_entries:2442 cast = meth_entry.type.signature_cast_string()2443 code.putln(2444 "%s.%s = %s%s;" % (2445 type.vtable_cname,2446 meth_entry.cname,2447 cast,2448 meth_entry.func_cname))2449 def generate_typeptr_assignment_code(self, entry, code):2450 # Generate code to initialise the typeptr of an extension2451 # type defined in this module to point to its type object.2452 type = entry.type2453 if type.typeobj_cname:2454 code.putln(2455 "%s = &%s;" % (2456 type.typeptr_cname, type.typeobj_cname))2457def generate_cfunction_declaration(entry, env, code, definition):2458 from_cy_utility = entry.used and entry.utility_code_definition2459 if entry.used and entry.inline_func_in_pxd or (not entry.in_cinclude and (definition2460 or entry.defined_in_pxd or entry.visibility == 'extern' or from_cy_utility)):2461 if entry.visibility == 'extern':2462 storage_class = Naming.extern_c_macro2463 dll_linkage = "DL_IMPORT"2464 elif entry.visibility == 'public':2465 storage_class = Naming.extern_c_macro2466 dll_linkage = "DL_EXPORT"2467 elif entry.visibility == 'private':2468 storage_class = "static"2469 dll_linkage = None2470 else:2471 storage_class = "static"2472 dll_linkage = None2473 type = entry.type2474 if entry.defined_in_pxd and not definition:2475 storage_class = "static"2476 dll_linkage = None2477 type = CPtrType(type)2478 header = type.declaration_code(2479 entry.cname, dll_linkage = dll_linkage)2480 modifiers = code.build_function_modifiers(entry.func_modifiers)2481 code.putln("%s %s%s; /*proto*/" % (2482 storage_class,2483 modifiers,2484 header))2485#------------------------------------------------------------------------------------2486#2487# Runtime support code2488#2489#------------------------------------------------------------------------------------2490streq_utility_code = UtilityCode(2491proto = """2492static CYTHON_INLINE int __Pyx_StrEq(const char *, const char *); /*proto*/...

Full Screen

Full Screen

AppleEvents.py

Source:AppleEvents.py Github

copy

Full Screen

1# Generated from 'AEDataModel.h'2def FOUR_CHAR_CODE(x): return x3typeApplicationBundleID = FOUR_CHAR_CODE('bund')4typeBoolean = FOUR_CHAR_CODE('bool')5typeChar = FOUR_CHAR_CODE('TEXT')6typeSInt16 = FOUR_CHAR_CODE('shor')7typeSInt32 = FOUR_CHAR_CODE('long')8typeUInt32 = FOUR_CHAR_CODE('magn')9typeSInt64 = FOUR_CHAR_CODE('comp')10typeIEEE32BitFloatingPoint = FOUR_CHAR_CODE('sing')11typeIEEE64BitFloatingPoint = FOUR_CHAR_CODE('doub')12type128BitFloatingPoint = FOUR_CHAR_CODE('ldbl')13typeDecimalStruct = FOUR_CHAR_CODE('decm')14typeSMInt = typeSInt1615typeShortInteger = typeSInt1616typeInteger = typeSInt3217typeLongInteger = typeSInt3218typeMagnitude = typeUInt3219typeComp = typeSInt6420typeSMFloat = typeIEEE32BitFloatingPoint21typeShortFloat = typeIEEE32BitFloatingPoint22typeFloat = typeIEEE64BitFloatingPoint23typeLongFloat = typeIEEE64BitFloatingPoint24typeExtended = FOUR_CHAR_CODE('exte')25typeAEList = FOUR_CHAR_CODE('list')26typeAERecord = FOUR_CHAR_CODE('reco')27typeAppleEvent = FOUR_CHAR_CODE('aevt')28typeEventRecord = FOUR_CHAR_CODE('evrc')29typeTrue = FOUR_CHAR_CODE('true')30typeFalse = FOUR_CHAR_CODE('fals')31typeAlias = FOUR_CHAR_CODE('alis')32typeEnumerated = FOUR_CHAR_CODE('enum')33typeType = FOUR_CHAR_CODE('type')34typeAppParameters = FOUR_CHAR_CODE('appa')35typeProperty = FOUR_CHAR_CODE('prop')36typeFSS = FOUR_CHAR_CODE('fss ')37typeFSRef = FOUR_CHAR_CODE('fsrf')38typeFileURL = FOUR_CHAR_CODE('furl')39typeKeyword = FOUR_CHAR_CODE('keyw')40typeSectionH = FOUR_CHAR_CODE('sect')41typeWildCard = FOUR_CHAR_CODE('****')42typeApplSignature = FOUR_CHAR_CODE('sign')43typeQDRectangle = FOUR_CHAR_CODE('qdrt')44typeFixed = FOUR_CHAR_CODE('fixd')45typeProcessSerialNumber = FOUR_CHAR_CODE('psn ')46typeApplicationURL = FOUR_CHAR_CODE('aprl')47typeNull = FOUR_CHAR_CODE('null')48typeSessionID = FOUR_CHAR_CODE('ssid')49typeTargetID = FOUR_CHAR_CODE('targ')50typeDispatcherID = FOUR_CHAR_CODE('dspt')51keyTransactionIDAttr = FOUR_CHAR_CODE('tran')52keyReturnIDAttr = FOUR_CHAR_CODE('rtid')53keyEventClassAttr = FOUR_CHAR_CODE('evcl')54keyEventIDAttr = FOUR_CHAR_CODE('evid')55keyAddressAttr = FOUR_CHAR_CODE('addr')56keyOptionalKeywordAttr = FOUR_CHAR_CODE('optk')57keyTimeoutAttr = FOUR_CHAR_CODE('timo')58keyInteractLevelAttr = FOUR_CHAR_CODE('inte')59keyEventSourceAttr = FOUR_CHAR_CODE('esrc')60keyMissedKeywordAttr = FOUR_CHAR_CODE('miss')61keyOriginalAddressAttr = FOUR_CHAR_CODE('from')62keyAcceptTimeoutAttr = FOUR_CHAR_CODE('actm')63kAEDescListFactorNone = 064kAEDescListFactorType = 465kAEDescListFactorTypeAndSize = 866kAutoGenerateReturnID = -167kAnyTransactionID = 068kAEDataArray = 069kAEPackedArray = 170kAEDescArray = 371kAEKeyDescArray = 472kAEHandleArray = 273kAENormalPriority = 0x0000000074kAEHighPriority = 0x0000000175kAENoReply = 0x0000000176kAEQueueReply = 0x0000000277kAEWaitReply = 0x0000000378kAEDontReconnect = 0x0000008079kAEWantReceipt = 0x0000020080kAENeverInteract = 0x0000001081kAECanInteract = 0x0000002082kAEAlwaysInteract = 0x0000003083kAECanSwitchLayer = 0x0000004084kAEDontRecord = 0x0000100085kAEDontExecute = 0x0000200086kAEProcessNonReplyEvents = 0x0000800087kAEDefaultTimeout = -188kNoTimeOut = -289kAEInteractWithSelf = 090kAEInteractWithLocal = 191kAEInteractWithAll = 292kAEDoNotIgnoreHandler = 0x0000000093kAEIgnoreAppPhacHandler = 0x0000000194kAEIgnoreAppEventHandler = 0x0000000295kAEIgnoreSysPhacHandler = 0x0000000496kAEIgnoreSysEventHandler = 0x0000000897kAEIngoreBuiltInEventHandler = 0x0000001098# kAEDontDisposeOnResume = (long)0x8000000099kAENoDispatch = 0100# kAEUseStandardDispatch = (long)0xFFFFFFFF101keyDirectObject = FOUR_CHAR_CODE('----')102keyErrorNumber = FOUR_CHAR_CODE('errn')103keyErrorString = FOUR_CHAR_CODE('errs')104keyProcessSerialNumber = FOUR_CHAR_CODE('psn ')105keyPreDispatch = FOUR_CHAR_CODE('phac')106keySelectProc = FOUR_CHAR_CODE('selh')107keyAERecorderCount = FOUR_CHAR_CODE('recr')108keyAEVersion = FOUR_CHAR_CODE('vers')109kCoreEventClass = FOUR_CHAR_CODE('aevt')110kAEOpenApplication = FOUR_CHAR_CODE('oapp')111kAEOpenDocuments = FOUR_CHAR_CODE('odoc')112kAEPrintDocuments = FOUR_CHAR_CODE('pdoc')113kAEQuitApplication = FOUR_CHAR_CODE('quit')114kAEAnswer = FOUR_CHAR_CODE('ansr')115kAEApplicationDied = FOUR_CHAR_CODE('obit')116kAEShowPreferences = FOUR_CHAR_CODE('pref')117kAEStartRecording = FOUR_CHAR_CODE('reca')118kAEStopRecording = FOUR_CHAR_CODE('recc')119kAENotifyStartRecording = FOUR_CHAR_CODE('rec1')120kAENotifyStopRecording = FOUR_CHAR_CODE('rec0')121kAENotifyRecording = FOUR_CHAR_CODE('recr')122kAEUnknownSource = 0123kAEDirectCall = 1124kAESameProcess = 2125kAELocalProcess = 3126kAERemoteProcess = 4127cAEList = FOUR_CHAR_CODE('list')128cApplication = FOUR_CHAR_CODE('capp')129cArc = FOUR_CHAR_CODE('carc')130cBoolean = FOUR_CHAR_CODE('bool')131cCell = FOUR_CHAR_CODE('ccel')132cChar = FOUR_CHAR_CODE('cha ')133cColorTable = FOUR_CHAR_CODE('clrt')134cColumn = FOUR_CHAR_CODE('ccol')135cDocument = FOUR_CHAR_CODE('docu')136cDrawingArea = FOUR_CHAR_CODE('cdrw')137cEnumeration = FOUR_CHAR_CODE('enum')138cFile = FOUR_CHAR_CODE('file')139cFixed = FOUR_CHAR_CODE('fixd')140cFixedPoint = FOUR_CHAR_CODE('fpnt')141cFixedRectangle = FOUR_CHAR_CODE('frct')142cGraphicLine = FOUR_CHAR_CODE('glin')143cGraphicObject = FOUR_CHAR_CODE('cgob')144cGraphicShape = FOUR_CHAR_CODE('cgsh')145cGraphicText = FOUR_CHAR_CODE('cgtx')146cGroupedGraphic = FOUR_CHAR_CODE('cpic')147cInsertionLoc = FOUR_CHAR_CODE('insl')148cInsertionPoint = FOUR_CHAR_CODE('cins')149cIntlText = FOUR_CHAR_CODE('itxt')150cIntlWritingCode = FOUR_CHAR_CODE('intl')151cItem = FOUR_CHAR_CODE('citm')152cLine = FOUR_CHAR_CODE('clin')153cLongDateTime = FOUR_CHAR_CODE('ldt ')154cLongFixed = FOUR_CHAR_CODE('lfxd')155cLongFixedPoint = FOUR_CHAR_CODE('lfpt')156cLongFixedRectangle = FOUR_CHAR_CODE('lfrc')157cLongInteger = FOUR_CHAR_CODE('long')158cLongPoint = FOUR_CHAR_CODE('lpnt')159cLongRectangle = FOUR_CHAR_CODE('lrct')160cMachineLoc = FOUR_CHAR_CODE('mLoc')161cMenu = FOUR_CHAR_CODE('cmnu')162cMenuItem = FOUR_CHAR_CODE('cmen')163cObject = FOUR_CHAR_CODE('cobj')164cObjectSpecifier = FOUR_CHAR_CODE('obj ')165cOpenableObject = FOUR_CHAR_CODE('coob')166cOval = FOUR_CHAR_CODE('covl')167cParagraph = FOUR_CHAR_CODE('cpar')168cPICT = FOUR_CHAR_CODE('PICT')169cPixel = FOUR_CHAR_CODE('cpxl')170cPixelMap = FOUR_CHAR_CODE('cpix')171cPolygon = FOUR_CHAR_CODE('cpgn')172cProperty = FOUR_CHAR_CODE('prop')173cQDPoint = FOUR_CHAR_CODE('QDpt')174cQDRectangle = FOUR_CHAR_CODE('qdrt')175cRectangle = FOUR_CHAR_CODE('crec')176cRGBColor = FOUR_CHAR_CODE('cRGB')177cRotation = FOUR_CHAR_CODE('trot')178cRoundedRectangle = FOUR_CHAR_CODE('crrc')179cRow = FOUR_CHAR_CODE('crow')180cSelection = FOUR_CHAR_CODE('csel')181cShortInteger = FOUR_CHAR_CODE('shor')182cTable = FOUR_CHAR_CODE('ctbl')183cText = FOUR_CHAR_CODE('ctxt')184cTextFlow = FOUR_CHAR_CODE('cflo')185cTextStyles = FOUR_CHAR_CODE('tsty')186cType = FOUR_CHAR_CODE('type')187cVersion = FOUR_CHAR_CODE('vers')188cWindow = FOUR_CHAR_CODE('cwin')189cWord = FOUR_CHAR_CODE('cwor')190enumArrows = FOUR_CHAR_CODE('arro')191enumJustification = FOUR_CHAR_CODE('just')192enumKeyForm = FOUR_CHAR_CODE('kfrm')193enumPosition = FOUR_CHAR_CODE('posi')194enumProtection = FOUR_CHAR_CODE('prtn')195enumQuality = FOUR_CHAR_CODE('qual')196enumSaveOptions = FOUR_CHAR_CODE('savo')197enumStyle = FOUR_CHAR_CODE('styl')198enumTransferMode = FOUR_CHAR_CODE('tran')199formUniqueID = FOUR_CHAR_CODE('ID ')200kAEAbout = FOUR_CHAR_CODE('abou')201kAEAfter = FOUR_CHAR_CODE('afte')202kAEAliasSelection = FOUR_CHAR_CODE('sali')203kAEAllCaps = FOUR_CHAR_CODE('alcp')204kAEArrowAtEnd = FOUR_CHAR_CODE('aren')205kAEArrowAtStart = FOUR_CHAR_CODE('arst')206kAEArrowBothEnds = FOUR_CHAR_CODE('arbo')207kAEAsk = FOUR_CHAR_CODE('ask ')208kAEBefore = FOUR_CHAR_CODE('befo')209kAEBeginning = FOUR_CHAR_CODE('bgng')210kAEBeginsWith = FOUR_CHAR_CODE('bgwt')211kAEBeginTransaction = FOUR_CHAR_CODE('begi')212kAEBold = FOUR_CHAR_CODE('bold')213kAECaseSensEquals = FOUR_CHAR_CODE('cseq')214kAECentered = FOUR_CHAR_CODE('cent')215kAEChangeView = FOUR_CHAR_CODE('view')216kAEClone = FOUR_CHAR_CODE('clon')217kAEClose = FOUR_CHAR_CODE('clos')218kAECondensed = FOUR_CHAR_CODE('cond')219kAEContains = FOUR_CHAR_CODE('cont')220kAECopy = FOUR_CHAR_CODE('copy')221kAECoreSuite = FOUR_CHAR_CODE('core')222kAECountElements = FOUR_CHAR_CODE('cnte')223kAECreateElement = FOUR_CHAR_CODE('crel')224kAECreatePublisher = FOUR_CHAR_CODE('cpub')225kAECut = FOUR_CHAR_CODE('cut ')226kAEDelete = FOUR_CHAR_CODE('delo')227kAEDoObjectsExist = FOUR_CHAR_CODE('doex')228kAEDoScript = FOUR_CHAR_CODE('dosc')229kAEDrag = FOUR_CHAR_CODE('drag')230kAEDuplicateSelection = FOUR_CHAR_CODE('sdup')231kAEEditGraphic = FOUR_CHAR_CODE('edit')232kAEEmptyTrash = FOUR_CHAR_CODE('empt')233kAEEnd = FOUR_CHAR_CODE('end ')234kAEEndsWith = FOUR_CHAR_CODE('ends')235kAEEndTransaction = FOUR_CHAR_CODE('endt')236kAEEquals = FOUR_CHAR_CODE('= ')237kAEExpanded = FOUR_CHAR_CODE('pexp')238kAEFast = FOUR_CHAR_CODE('fast')239kAEFinderEvents = FOUR_CHAR_CODE('FNDR')240kAEFormulaProtect = FOUR_CHAR_CODE('fpro')241kAEFullyJustified = FOUR_CHAR_CODE('full')242kAEGetClassInfo = FOUR_CHAR_CODE('qobj')243kAEGetData = FOUR_CHAR_CODE('getd')244kAEGetDataSize = FOUR_CHAR_CODE('dsiz')245kAEGetEventInfo = FOUR_CHAR_CODE('gtei')246kAEGetInfoSelection = FOUR_CHAR_CODE('sinf')247kAEGetPrivilegeSelection = FOUR_CHAR_CODE('sprv')248kAEGetSuiteInfo = FOUR_CHAR_CODE('gtsi')249kAEGreaterThan = FOUR_CHAR_CODE('> ')250kAEGreaterThanEquals = FOUR_CHAR_CODE('>= ')251kAEGrow = FOUR_CHAR_CODE('grow')252kAEHidden = FOUR_CHAR_CODE('hidn')253kAEHiQuality = FOUR_CHAR_CODE('hiqu')254kAEImageGraphic = FOUR_CHAR_CODE('imgr')255kAEIsUniform = FOUR_CHAR_CODE('isun')256kAEItalic = FOUR_CHAR_CODE('ital')257kAELeftJustified = FOUR_CHAR_CODE('left')258kAELessThan = FOUR_CHAR_CODE('< ')259kAELessThanEquals = FOUR_CHAR_CODE('<= ')260kAELowercase = FOUR_CHAR_CODE('lowc')261kAEMakeObjectsVisible = FOUR_CHAR_CODE('mvis')262kAEMiscStandards = FOUR_CHAR_CODE('misc')263kAEModifiable = FOUR_CHAR_CODE('modf')264kAEMove = FOUR_CHAR_CODE('move')265kAENo = FOUR_CHAR_CODE('no ')266kAENoArrow = FOUR_CHAR_CODE('arno')267kAENonmodifiable = FOUR_CHAR_CODE('nmod')268kAEOpen = FOUR_CHAR_CODE('odoc')269kAEOpenSelection = FOUR_CHAR_CODE('sope')270kAEOutline = FOUR_CHAR_CODE('outl')271kAEPageSetup = FOUR_CHAR_CODE('pgsu')272kAEPaste = FOUR_CHAR_CODE('past')273kAEPlain = FOUR_CHAR_CODE('plan')274kAEPrint = FOUR_CHAR_CODE('pdoc')275kAEPrintSelection = FOUR_CHAR_CODE('spri')276kAEPrintWindow = FOUR_CHAR_CODE('pwin')277kAEPutAwaySelection = FOUR_CHAR_CODE('sput')278kAEQDAddOver = FOUR_CHAR_CODE('addo')279kAEQDAddPin = FOUR_CHAR_CODE('addp')280kAEQDAdMax = FOUR_CHAR_CODE('admx')281kAEQDAdMin = FOUR_CHAR_CODE('admn')282kAEQDBic = FOUR_CHAR_CODE('bic ')283kAEQDBlend = FOUR_CHAR_CODE('blnd')284kAEQDCopy = FOUR_CHAR_CODE('cpy ')285kAEQDNotBic = FOUR_CHAR_CODE('nbic')286kAEQDNotCopy = FOUR_CHAR_CODE('ncpy')287kAEQDNotOr = FOUR_CHAR_CODE('ntor')288kAEQDNotXor = FOUR_CHAR_CODE('nxor')289kAEQDOr = FOUR_CHAR_CODE('or ')290kAEQDSubOver = FOUR_CHAR_CODE('subo')291kAEQDSubPin = FOUR_CHAR_CODE('subp')292kAEQDSupplementalSuite = FOUR_CHAR_CODE('qdsp')293kAEQDXor = FOUR_CHAR_CODE('xor ')294kAEQuickdrawSuite = FOUR_CHAR_CODE('qdrw')295kAEQuitAll = FOUR_CHAR_CODE('quia')296kAERedo = FOUR_CHAR_CODE('redo')297kAERegular = FOUR_CHAR_CODE('regl')298kAEReopenApplication = FOUR_CHAR_CODE('rapp')299kAEReplace = FOUR_CHAR_CODE('rplc')300kAERequiredSuite = FOUR_CHAR_CODE('reqd')301kAERestart = FOUR_CHAR_CODE('rest')302kAERevealSelection = FOUR_CHAR_CODE('srev')303kAERevert = FOUR_CHAR_CODE('rvrt')304kAERightJustified = FOUR_CHAR_CODE('rght')305kAESave = FOUR_CHAR_CODE('save')306kAESelect = FOUR_CHAR_CODE('slct')307kAESetData = FOUR_CHAR_CODE('setd')308kAESetPosition = FOUR_CHAR_CODE('posn')309kAEShadow = FOUR_CHAR_CODE('shad')310kAEShowClipboard = FOUR_CHAR_CODE('shcl')311kAEShutDown = FOUR_CHAR_CODE('shut')312kAESleep = FOUR_CHAR_CODE('slep')313kAESmallCaps = FOUR_CHAR_CODE('smcp')314kAESpecialClassProperties = FOUR_CHAR_CODE('c@#!')315kAEStrikethrough = FOUR_CHAR_CODE('strk')316kAESubscript = FOUR_CHAR_CODE('sbsc')317kAESuperscript = FOUR_CHAR_CODE('spsc')318kAETableSuite = FOUR_CHAR_CODE('tbls')319kAETextSuite = FOUR_CHAR_CODE('TEXT')320kAETransactionTerminated = FOUR_CHAR_CODE('ttrm')321kAEUnderline = FOUR_CHAR_CODE('undl')322kAEUndo = FOUR_CHAR_CODE('undo')323kAEWholeWordEquals = FOUR_CHAR_CODE('wweq')324kAEYes = FOUR_CHAR_CODE('yes ')325kAEZoom = FOUR_CHAR_CODE('zoom')326kAEMouseClass = FOUR_CHAR_CODE('mous')327kAEDown = FOUR_CHAR_CODE('down')328kAEUp = FOUR_CHAR_CODE('up ')329kAEMoved = FOUR_CHAR_CODE('move')330kAEStoppedMoving = FOUR_CHAR_CODE('stop')331kAEWindowClass = FOUR_CHAR_CODE('wind')332kAEUpdate = FOUR_CHAR_CODE('updt')333kAEActivate = FOUR_CHAR_CODE('actv')334kAEDeactivate = FOUR_CHAR_CODE('dact')335kAECommandClass = FOUR_CHAR_CODE('cmnd')336kAEKeyClass = FOUR_CHAR_CODE('keyc')337kAERawKey = FOUR_CHAR_CODE('rkey')338kAEVirtualKey = FOUR_CHAR_CODE('keyc')339kAENavigationKey = FOUR_CHAR_CODE('nave')340kAEAutoDown = FOUR_CHAR_CODE('auto')341kAEApplicationClass = FOUR_CHAR_CODE('appl')342kAESuspend = FOUR_CHAR_CODE('susp')343kAEResume = FOUR_CHAR_CODE('rsme')344kAEDiskEvent = FOUR_CHAR_CODE('disk')345kAENullEvent = FOUR_CHAR_CODE('null')346kAEWakeUpEvent = FOUR_CHAR_CODE('wake')347kAEScrapEvent = FOUR_CHAR_CODE('scrp')348kAEHighLevel = FOUR_CHAR_CODE('high')349keyAEAngle = FOUR_CHAR_CODE('kang')350keyAEArcAngle = FOUR_CHAR_CODE('parc')351keyAEBaseAddr = FOUR_CHAR_CODE('badd')352keyAEBestType = FOUR_CHAR_CODE('pbst')353keyAEBgndColor = FOUR_CHAR_CODE('kbcl')354keyAEBgndPattern = FOUR_CHAR_CODE('kbpt')355keyAEBounds = FOUR_CHAR_CODE('pbnd')356keyAECellList = FOUR_CHAR_CODE('kclt')357keyAEClassID = FOUR_CHAR_CODE('clID')358keyAEColor = FOUR_CHAR_CODE('colr')359keyAEColorTable = FOUR_CHAR_CODE('cltb')360keyAECurveHeight = FOUR_CHAR_CODE('kchd')361keyAECurveWidth = FOUR_CHAR_CODE('kcwd')362keyAEDashStyle = FOUR_CHAR_CODE('pdst')363keyAEData = FOUR_CHAR_CODE('data')364keyAEDefaultType = FOUR_CHAR_CODE('deft')365keyAEDefinitionRect = FOUR_CHAR_CODE('pdrt')366keyAEDescType = FOUR_CHAR_CODE('dstp')367keyAEDestination = FOUR_CHAR_CODE('dest')368keyAEDoAntiAlias = FOUR_CHAR_CODE('anta')369keyAEDoDithered = FOUR_CHAR_CODE('gdit')370keyAEDoRotate = FOUR_CHAR_CODE('kdrt')371keyAEDoScale = FOUR_CHAR_CODE('ksca')372keyAEDoTranslate = FOUR_CHAR_CODE('ktra')373keyAEEditionFileLoc = FOUR_CHAR_CODE('eloc')374keyAEElements = FOUR_CHAR_CODE('elms')375keyAEEndPoint = FOUR_CHAR_CODE('pend')376keyAEEventClass = FOUR_CHAR_CODE('evcl')377keyAEEventID = FOUR_CHAR_CODE('evti')378keyAEFile = FOUR_CHAR_CODE('kfil')379keyAEFileType = FOUR_CHAR_CODE('fltp')380keyAEFillColor = FOUR_CHAR_CODE('flcl')381keyAEFillPattern = FOUR_CHAR_CODE('flpt')382keyAEFlipHorizontal = FOUR_CHAR_CODE('kfho')383keyAEFlipVertical = FOUR_CHAR_CODE('kfvt')384keyAEFont = FOUR_CHAR_CODE('font')385keyAEFormula = FOUR_CHAR_CODE('pfor')386keyAEGraphicObjects = FOUR_CHAR_CODE('gobs')387keyAEID = FOUR_CHAR_CODE('ID ')388keyAEImageQuality = FOUR_CHAR_CODE('gqua')389keyAEInsertHere = FOUR_CHAR_CODE('insh')390keyAEKeyForms = FOUR_CHAR_CODE('keyf')391keyAEKeyword = FOUR_CHAR_CODE('kywd')392keyAELevel = FOUR_CHAR_CODE('levl')393keyAELineArrow = FOUR_CHAR_CODE('arro')394keyAEName = FOUR_CHAR_CODE('pnam')395keyAENewElementLoc = FOUR_CHAR_CODE('pnel')396keyAEObject = FOUR_CHAR_CODE('kobj')397keyAEObjectClass = FOUR_CHAR_CODE('kocl')398keyAEOffStyles = FOUR_CHAR_CODE('ofst')399keyAEOnStyles = FOUR_CHAR_CODE('onst')400keyAEParameters = FOUR_CHAR_CODE('prms')401keyAEParamFlags = FOUR_CHAR_CODE('pmfg')402keyAEPenColor = FOUR_CHAR_CODE('ppcl')403keyAEPenPattern = FOUR_CHAR_CODE('pppa')404keyAEPenWidth = FOUR_CHAR_CODE('ppwd')405keyAEPixelDepth = FOUR_CHAR_CODE('pdpt')406keyAEPixMapMinus = FOUR_CHAR_CODE('kpmm')407keyAEPMTable = FOUR_CHAR_CODE('kpmt')408keyAEPointList = FOUR_CHAR_CODE('ptlt')409keyAEPointSize = FOUR_CHAR_CODE('ptsz')410keyAEPosition = FOUR_CHAR_CODE('kpos')411keyAEPropData = FOUR_CHAR_CODE('prdt')412keyAEProperties = FOUR_CHAR_CODE('qpro')413keyAEProperty = FOUR_CHAR_CODE('kprp')414keyAEPropFlags = FOUR_CHAR_CODE('prfg')415keyAEPropID = FOUR_CHAR_CODE('prop')416keyAEProtection = FOUR_CHAR_CODE('ppro')417keyAERenderAs = FOUR_CHAR_CODE('kren')418keyAERequestedType = FOUR_CHAR_CODE('rtyp')419keyAEResult = FOUR_CHAR_CODE('----')420keyAEResultInfo = FOUR_CHAR_CODE('rsin')421keyAERotation = FOUR_CHAR_CODE('prot')422keyAERotPoint = FOUR_CHAR_CODE('krtp')423keyAERowList = FOUR_CHAR_CODE('krls')424keyAESaveOptions = FOUR_CHAR_CODE('savo')425keyAEScale = FOUR_CHAR_CODE('pscl')426keyAEScriptTag = FOUR_CHAR_CODE('psct')427keyAEShowWhere = FOUR_CHAR_CODE('show')428keyAEStartAngle = FOUR_CHAR_CODE('pang')429keyAEStartPoint = FOUR_CHAR_CODE('pstp')430keyAEStyles = FOUR_CHAR_CODE('ksty')431keyAESuiteID = FOUR_CHAR_CODE('suit')432keyAEText = FOUR_CHAR_CODE('ktxt')433keyAETextColor = FOUR_CHAR_CODE('ptxc')434keyAETextFont = FOUR_CHAR_CODE('ptxf')435keyAETextPointSize = FOUR_CHAR_CODE('ptps')436keyAETextStyles = FOUR_CHAR_CODE('txst')437keyAETextLineHeight = FOUR_CHAR_CODE('ktlh')438keyAETextLineAscent = FOUR_CHAR_CODE('ktas')439keyAETheText = FOUR_CHAR_CODE('thtx')440keyAETransferMode = FOUR_CHAR_CODE('pptm')441keyAETranslation = FOUR_CHAR_CODE('ptrs')442keyAETryAsStructGraf = FOUR_CHAR_CODE('toog')443keyAEUniformStyles = FOUR_CHAR_CODE('ustl')444keyAEUpdateOn = FOUR_CHAR_CODE('pupd')445keyAEUserTerm = FOUR_CHAR_CODE('utrm')446keyAEWindow = FOUR_CHAR_CODE('wndw')447keyAEWritingCode = FOUR_CHAR_CODE('wrcd')448keyMiscellaneous = FOUR_CHAR_CODE('fmsc')449keySelection = FOUR_CHAR_CODE('fsel')450keyWindow = FOUR_CHAR_CODE('kwnd')451keyWhen = FOUR_CHAR_CODE('when')452keyWhere = FOUR_CHAR_CODE('wher')453keyModifiers = FOUR_CHAR_CODE('mods')454keyKey = FOUR_CHAR_CODE('key ')455keyKeyCode = FOUR_CHAR_CODE('code')456keyKeyboard = FOUR_CHAR_CODE('keyb')457keyDriveNumber = FOUR_CHAR_CODE('drv#')458keyErrorCode = FOUR_CHAR_CODE('err#')459keyHighLevelClass = FOUR_CHAR_CODE('hcls')460keyHighLevelID = FOUR_CHAR_CODE('hid ')461pArcAngle = FOUR_CHAR_CODE('parc')462pBackgroundColor = FOUR_CHAR_CODE('pbcl')463pBackgroundPattern = FOUR_CHAR_CODE('pbpt')464pBestType = FOUR_CHAR_CODE('pbst')465pBounds = FOUR_CHAR_CODE('pbnd')466pClass = FOUR_CHAR_CODE('pcls')467pClipboard = FOUR_CHAR_CODE('pcli')468pColor = FOUR_CHAR_CODE('colr')469pColorTable = FOUR_CHAR_CODE('cltb')470pContents = FOUR_CHAR_CODE('pcnt')471pCornerCurveHeight = FOUR_CHAR_CODE('pchd')472pCornerCurveWidth = FOUR_CHAR_CODE('pcwd')473pDashStyle = FOUR_CHAR_CODE('pdst')474pDefaultType = FOUR_CHAR_CODE('deft')475pDefinitionRect = FOUR_CHAR_CODE('pdrt')476pEnabled = FOUR_CHAR_CODE('enbl')477pEndPoint = FOUR_CHAR_CODE('pend')478pFillColor = FOUR_CHAR_CODE('flcl')479pFillPattern = FOUR_CHAR_CODE('flpt')480pFont = FOUR_CHAR_CODE('font')481pFormula = FOUR_CHAR_CODE('pfor')482pGraphicObjects = FOUR_CHAR_CODE('gobs')483pHasCloseBox = FOUR_CHAR_CODE('hclb')484pHasTitleBar = FOUR_CHAR_CODE('ptit')485pID = FOUR_CHAR_CODE('ID ')486pIndex = FOUR_CHAR_CODE('pidx')487pInsertionLoc = FOUR_CHAR_CODE('pins')488pIsFloating = FOUR_CHAR_CODE('isfl')489pIsFrontProcess = FOUR_CHAR_CODE('pisf')490pIsModal = FOUR_CHAR_CODE('pmod')491pIsModified = FOUR_CHAR_CODE('imod')492pIsResizable = FOUR_CHAR_CODE('prsz')493pIsStationeryPad = FOUR_CHAR_CODE('pspd')494pIsZoomable = FOUR_CHAR_CODE('iszm')495pIsZoomed = FOUR_CHAR_CODE('pzum')496pItemNumber = FOUR_CHAR_CODE('itmn')497pJustification = FOUR_CHAR_CODE('pjst')498pLineArrow = FOUR_CHAR_CODE('arro')499pMenuID = FOUR_CHAR_CODE('mnid')500pName = FOUR_CHAR_CODE('pnam')501pNewElementLoc = FOUR_CHAR_CODE('pnel')502pPenColor = FOUR_CHAR_CODE('ppcl')503pPenPattern = FOUR_CHAR_CODE('pppa')504pPenWidth = FOUR_CHAR_CODE('ppwd')505pPixelDepth = FOUR_CHAR_CODE('pdpt')506pPointList = FOUR_CHAR_CODE('ptlt')507pPointSize = FOUR_CHAR_CODE('ptsz')508pProtection = FOUR_CHAR_CODE('ppro')509pRotation = FOUR_CHAR_CODE('prot')510pScale = FOUR_CHAR_CODE('pscl')511pScript = FOUR_CHAR_CODE('scpt')512pScriptTag = FOUR_CHAR_CODE('psct')513pSelected = FOUR_CHAR_CODE('selc')514pSelection = FOUR_CHAR_CODE('sele')515pStartAngle = FOUR_CHAR_CODE('pang')516pStartPoint = FOUR_CHAR_CODE('pstp')517pTextColor = FOUR_CHAR_CODE('ptxc')518pTextFont = FOUR_CHAR_CODE('ptxf')519pTextItemDelimiters = FOUR_CHAR_CODE('txdl')520pTextPointSize = FOUR_CHAR_CODE('ptps')521pTextStyles = FOUR_CHAR_CODE('txst')522pTransferMode = FOUR_CHAR_CODE('pptm')523pTranslation = FOUR_CHAR_CODE('ptrs')524pUniformStyles = FOUR_CHAR_CODE('ustl')525pUpdateOn = FOUR_CHAR_CODE('pupd')526pUserSelection = FOUR_CHAR_CODE('pusl')527pVersion = FOUR_CHAR_CODE('vers')528pVisible = FOUR_CHAR_CODE('pvis')529typeAEText = FOUR_CHAR_CODE('tTXT')530typeArc = FOUR_CHAR_CODE('carc')531typeBest = FOUR_CHAR_CODE('best')532typeCell = FOUR_CHAR_CODE('ccel')533typeClassInfo = FOUR_CHAR_CODE('gcli')534typeColorTable = FOUR_CHAR_CODE('clrt')535typeColumn = FOUR_CHAR_CODE('ccol')536typeDashStyle = FOUR_CHAR_CODE('tdas')537typeData = FOUR_CHAR_CODE('tdta')538typeDrawingArea = FOUR_CHAR_CODE('cdrw')539typeElemInfo = FOUR_CHAR_CODE('elin')540typeEnumeration = FOUR_CHAR_CODE('enum')541typeEPS = FOUR_CHAR_CODE('EPS ')542typeEventInfo = FOUR_CHAR_CODE('evin')543typeFinderWindow = FOUR_CHAR_CODE('fwin')544typeFixedPoint = FOUR_CHAR_CODE('fpnt')545typeFixedRectangle = FOUR_CHAR_CODE('frct')546typeGraphicLine = FOUR_CHAR_CODE('glin')547typeGraphicText = FOUR_CHAR_CODE('cgtx')548typeGroupedGraphic = FOUR_CHAR_CODE('cpic')549typeInsertionLoc = FOUR_CHAR_CODE('insl')550typeIntlText = FOUR_CHAR_CODE('itxt')551typeIntlWritingCode = FOUR_CHAR_CODE('intl')552typeLongDateTime = FOUR_CHAR_CODE('ldt ')553typeLongFixed = FOUR_CHAR_CODE('lfxd')554typeLongFixedPoint = FOUR_CHAR_CODE('lfpt')555typeLongFixedRectangle = FOUR_CHAR_CODE('lfrc')556typeLongPoint = FOUR_CHAR_CODE('lpnt')557typeLongRectangle = FOUR_CHAR_CODE('lrct')558typeMachineLoc = FOUR_CHAR_CODE('mLoc')559typeOval = FOUR_CHAR_CODE('covl')560typeParamInfo = FOUR_CHAR_CODE('pmin')561typePict = FOUR_CHAR_CODE('PICT')562typePixelMap = FOUR_CHAR_CODE('cpix')563typePixMapMinus = FOUR_CHAR_CODE('tpmm')564typePolygon = FOUR_CHAR_CODE('cpgn')565typePropInfo = FOUR_CHAR_CODE('pinf')566typePtr = FOUR_CHAR_CODE('ptr ')567typeQDPoint = FOUR_CHAR_CODE('QDpt')568typeQDRegion = FOUR_CHAR_CODE('Qrgn')569typeRectangle = FOUR_CHAR_CODE('crec')570typeRGB16 = FOUR_CHAR_CODE('tr16')571typeRGB96 = FOUR_CHAR_CODE('tr96')572typeRGBColor = FOUR_CHAR_CODE('cRGB')573typeRotation = FOUR_CHAR_CODE('trot')574typeRoundedRectangle = FOUR_CHAR_CODE('crrc')575typeRow = FOUR_CHAR_CODE('crow')576typeScrapStyles = FOUR_CHAR_CODE('styl')577typeScript = FOUR_CHAR_CODE('scpt')578typeStyledText = FOUR_CHAR_CODE('STXT')579typeSuiteInfo = FOUR_CHAR_CODE('suin')580typeTable = FOUR_CHAR_CODE('ctbl')581typeTextStyles = FOUR_CHAR_CODE('tsty')582typeTIFF = FOUR_CHAR_CODE('TIFF')583typeVersion = FOUR_CHAR_CODE('vers')584kAEMenuClass = FOUR_CHAR_CODE('menu')585kAEMenuSelect = FOUR_CHAR_CODE('mhit')586kAEMouseDown = FOUR_CHAR_CODE('mdwn')587kAEMouseDownInBack = FOUR_CHAR_CODE('mdbk')588kAEKeyDown = FOUR_CHAR_CODE('kdwn')589kAEResized = FOUR_CHAR_CODE('rsiz')590kAEPromise = FOUR_CHAR_CODE('prom')591keyMenuID = FOUR_CHAR_CODE('mid ')592keyMenuItem = FOUR_CHAR_CODE('mitm')593keyCloseAllWindows = FOUR_CHAR_CODE('caw ')594keyOriginalBounds = FOUR_CHAR_CODE('obnd')595keyNewBounds = FOUR_CHAR_CODE('nbnd')596keyLocalWhere = FOUR_CHAR_CODE('lwhr')597typeHIMenu = FOUR_CHAR_CODE('mobj')598typeHIWindow = FOUR_CHAR_CODE('wobj')599kBySmallIcon = 0600kByIconView = 1601kByNameView = 2602kByDateView = 3603kBySizeView = 4604kByKindView = 5605kByCommentView = 6606kByLabelView = 7607kByVersionView = 8608kAEInfo = 11609kAEMain = 0610kAESharing = 13611kAEZoomIn = 7612kAEZoomOut = 8613kTextServiceClass = FOUR_CHAR_CODE('tsvc')614kUpdateActiveInputArea = FOUR_CHAR_CODE('updt')615kShowHideInputWindow = FOUR_CHAR_CODE('shiw')616kPos2Offset = FOUR_CHAR_CODE('p2st')617kOffset2Pos = FOUR_CHAR_CODE('st2p')618kUnicodeNotFromInputMethod = FOUR_CHAR_CODE('unim')619kGetSelectedText = FOUR_CHAR_CODE('gtxt')620keyAETSMDocumentRefcon = FOUR_CHAR_CODE('refc')621keyAEServerInstance = FOUR_CHAR_CODE('srvi')622keyAETheData = FOUR_CHAR_CODE('kdat')623keyAEFixLength = FOUR_CHAR_CODE('fixl')624keyAEUpdateRange = FOUR_CHAR_CODE('udng')625keyAECurrentPoint = FOUR_CHAR_CODE('cpos')626keyAEBufferSize = FOUR_CHAR_CODE('buff')627keyAEMoveView = FOUR_CHAR_CODE('mvvw')628keyAENextBody = FOUR_CHAR_CODE('nxbd')629keyAETSMScriptTag = FOUR_CHAR_CODE('sclg')630keyAETSMTextFont = FOUR_CHAR_CODE('ktxf')631keyAETSMTextFMFont = FOUR_CHAR_CODE('ktxm')632keyAETSMTextPointSize = FOUR_CHAR_CODE('ktps')633keyAETSMEventRecord = FOUR_CHAR_CODE('tevt')634keyAETSMEventRef = FOUR_CHAR_CODE('tevr')635keyAETextServiceEncoding = FOUR_CHAR_CODE('tsen')636keyAETextServiceMacEncoding = FOUR_CHAR_CODE('tmen')637typeTextRange = FOUR_CHAR_CODE('txrn')638typeComponentInstance = FOUR_CHAR_CODE('cmpi')639typeOffsetArray = FOUR_CHAR_CODE('ofay')640typeTextRangeArray = FOUR_CHAR_CODE('tray')641typeLowLevelEventRecord = FOUR_CHAR_CODE('evtr')642typeEventRef = FOUR_CHAR_CODE('evrf')643typeText = typeChar644kTSMOutsideOfBody = 1645kTSMInsideOfBody = 2646kTSMInsideOfActiveInputArea = 3647kNextBody = 1648kPreviousBody = 2649kCaretPosition = 1650kRawText = 2651kSelectedRawText = 3652kConvertedText = 4653kSelectedConvertedText = 5654kBlockFillText = 6655kOutlineText = 7656kSelectedText = 8657keyAEHiliteRange = FOUR_CHAR_CODE('hrng')658keyAEPinRange = FOUR_CHAR_CODE('pnrg')659keyAEClauseOffsets = FOUR_CHAR_CODE('clau')660keyAEOffset = FOUR_CHAR_CODE('ofst')661keyAEPoint = FOUR_CHAR_CODE('gpos')662keyAELeftSide = FOUR_CHAR_CODE('klef')663keyAERegionClass = FOUR_CHAR_CODE('rgnc')664keyAEDragging = FOUR_CHAR_CODE('bool')665keyAELeadingEdge = keyAELeftSide666typeUnicodeText = FOUR_CHAR_CODE('utxt')667typeStyledUnicodeText = FOUR_CHAR_CODE('sutx')668typeEncodedString = FOUR_CHAR_CODE('encs')669typeCString = FOUR_CHAR_CODE('cstr')670typePString = FOUR_CHAR_CODE('pstr')671typeMeters = FOUR_CHAR_CODE('metr')672typeInches = FOUR_CHAR_CODE('inch')673typeFeet = FOUR_CHAR_CODE('feet')674typeYards = FOUR_CHAR_CODE('yard')675typeMiles = FOUR_CHAR_CODE('mile')676typeKilometers = FOUR_CHAR_CODE('kmtr')677typeCentimeters = FOUR_CHAR_CODE('cmtr')678typeSquareMeters = FOUR_CHAR_CODE('sqrm')679typeSquareFeet = FOUR_CHAR_CODE('sqft')680typeSquareYards = FOUR_CHAR_CODE('sqyd')681typeSquareMiles = FOUR_CHAR_CODE('sqmi')682typeSquareKilometers = FOUR_CHAR_CODE('sqkm')683typeLiters = FOUR_CHAR_CODE('litr')684typeQuarts = FOUR_CHAR_CODE('qrts')685typeGallons = FOUR_CHAR_CODE('galn')686typeCubicMeters = FOUR_CHAR_CODE('cmet')687typeCubicFeet = FOUR_CHAR_CODE('cfet')688typeCubicInches = FOUR_CHAR_CODE('cuin')689typeCubicCentimeter = FOUR_CHAR_CODE('ccmt')690typeCubicYards = FOUR_CHAR_CODE('cyrd')691typeKilograms = FOUR_CHAR_CODE('kgrm')692typeGrams = FOUR_CHAR_CODE('gram')693typeOunces = FOUR_CHAR_CODE('ozs ')694typePounds = FOUR_CHAR_CODE('lbs ')695typeDegreesC = FOUR_CHAR_CODE('degc')696typeDegreesF = FOUR_CHAR_CODE('degf')697typeDegreesK = FOUR_CHAR_CODE('degk')698kFAServerApp = FOUR_CHAR_CODE('ssrv')699kDoFolderActionEvent = FOUR_CHAR_CODE('fola')700kFolderActionCode = FOUR_CHAR_CODE('actn')701kFolderOpenedEvent = FOUR_CHAR_CODE('fopn')702kFolderClosedEvent = FOUR_CHAR_CODE('fclo')703kFolderWindowMovedEvent = FOUR_CHAR_CODE('fsiz')704kFolderItemsAddedEvent = FOUR_CHAR_CODE('fget')705kFolderItemsRemovedEvent = FOUR_CHAR_CODE('flos')706kItemList = FOUR_CHAR_CODE('flst')707kNewSizeParameter = FOUR_CHAR_CODE('fnsz')708kFASuiteCode = FOUR_CHAR_CODE('faco')709kFAAttachCommand = FOUR_CHAR_CODE('atfa')710kFARemoveCommand = FOUR_CHAR_CODE('rmfa')711kFAEditCommand = FOUR_CHAR_CODE('edfa')712kFAFileParam = FOUR_CHAR_CODE('faal')713kFAIndexParam = FOUR_CHAR_CODE('indx')714kAEInternetSuite = FOUR_CHAR_CODE('gurl')715kAEISWebStarSuite = FOUR_CHAR_CODE('WWW\xbd')716kAEISGetURL = FOUR_CHAR_CODE('gurl')717KAEISHandleCGI = FOUR_CHAR_CODE('sdoc')718cURL = FOUR_CHAR_CODE('url ')719cInternetAddress = FOUR_CHAR_CODE('IPAD')720cHTML = FOUR_CHAR_CODE('html')721cFTPItem = FOUR_CHAR_CODE('ftp ')722kAEISHTTPSearchArgs = FOUR_CHAR_CODE('kfor')723kAEISPostArgs = FOUR_CHAR_CODE('post')724kAEISMethod = FOUR_CHAR_CODE('meth')725kAEISClientAddress = FOUR_CHAR_CODE('addr')726kAEISUserName = FOUR_CHAR_CODE('user')727kAEISPassword = FOUR_CHAR_CODE('pass')728kAEISFromUser = FOUR_CHAR_CODE('frmu')729kAEISServerName = FOUR_CHAR_CODE('svnm')730kAEISServerPort = FOUR_CHAR_CODE('svpt')731kAEISScriptName = FOUR_CHAR_CODE('scnm')732kAEISContentType = FOUR_CHAR_CODE('ctyp')733kAEISReferrer = FOUR_CHAR_CODE('refr')734kAEISUserAgent = FOUR_CHAR_CODE('Agnt')735kAEISAction = FOUR_CHAR_CODE('Kact')736kAEISActionPath = FOUR_CHAR_CODE('Kapt')737kAEISClientIP = FOUR_CHAR_CODE('Kcip')738kAEISFullRequest = FOUR_CHAR_CODE('Kfrq')739pScheme = FOUR_CHAR_CODE('pusc')740pHost = FOUR_CHAR_CODE('HOST')741pPath = FOUR_CHAR_CODE('FTPc')742pUserName = FOUR_CHAR_CODE('RAun')743pUserPassword = FOUR_CHAR_CODE('RApw')744pDNSForm = FOUR_CHAR_CODE('pDNS')745pURL = FOUR_CHAR_CODE('pURL')746pTextEncoding = FOUR_CHAR_CODE('ptxe')747pFTPKind = FOUR_CHAR_CODE('kind')748eScheme = FOUR_CHAR_CODE('esch')749eurlHTTP = FOUR_CHAR_CODE('http')750eurlHTTPS = FOUR_CHAR_CODE('htps')751eurlFTP = FOUR_CHAR_CODE('ftp ')752eurlMail = FOUR_CHAR_CODE('mail')753eurlFile = FOUR_CHAR_CODE('file')754eurlGopher = FOUR_CHAR_CODE('gphr')755eurlTelnet = FOUR_CHAR_CODE('tlnt')756eurlNews = FOUR_CHAR_CODE('news')757eurlSNews = FOUR_CHAR_CODE('snws')758eurlNNTP = FOUR_CHAR_CODE('nntp')759eurlMessage = FOUR_CHAR_CODE('mess')760eurlMailbox = FOUR_CHAR_CODE('mbox')761eurlMulti = FOUR_CHAR_CODE('mult')762eurlLaunch = FOUR_CHAR_CODE('laun')763eurlAFP = FOUR_CHAR_CODE('afp ')764eurlAT = FOUR_CHAR_CODE('at ')765eurlEPPC = FOUR_CHAR_CODE('eppc')766eurlRTSP = FOUR_CHAR_CODE('rtsp')767eurlIMAP = FOUR_CHAR_CODE('imap')768eurlNFS = FOUR_CHAR_CODE('unfs')769eurlPOP = FOUR_CHAR_CODE('upop')770eurlLDAP = FOUR_CHAR_CODE('uldp')771eurlUnknown = FOUR_CHAR_CODE('url?')772kConnSuite = FOUR_CHAR_CODE('macc')773cDevSpec = FOUR_CHAR_CODE('cdev')774cAddressSpec = FOUR_CHAR_CODE('cadr')775cADBAddress = FOUR_CHAR_CODE('cadb')776cAppleTalkAddress = FOUR_CHAR_CODE('cat ')777cBusAddress = FOUR_CHAR_CODE('cbus')778cEthernetAddress = FOUR_CHAR_CODE('cen ')779cFireWireAddress = FOUR_CHAR_CODE('cfw ')780cIPAddress = FOUR_CHAR_CODE('cip ')781cLocalTalkAddress = FOUR_CHAR_CODE('clt ')782cSCSIAddress = FOUR_CHAR_CODE('cscs')783cTokenRingAddress = FOUR_CHAR_CODE('ctok')784cUSBAddress = FOUR_CHAR_CODE('cusb')785pDeviceType = FOUR_CHAR_CODE('pdvt')786pDeviceAddress = FOUR_CHAR_CODE('pdva')787pConduit = FOUR_CHAR_CODE('pcon')788pProtocol = FOUR_CHAR_CODE('pprt')789pATMachine = FOUR_CHAR_CODE('patm')790pATZone = FOUR_CHAR_CODE('patz')791pATType = FOUR_CHAR_CODE('patt')792pDottedDecimal = FOUR_CHAR_CODE('pipd')793pDNS = FOUR_CHAR_CODE('pdns')794pPort = FOUR_CHAR_CODE('ppor')795pNetwork = FOUR_CHAR_CODE('pnet')796pNode = FOUR_CHAR_CODE('pnod')797pSocket = FOUR_CHAR_CODE('psoc')798pSCSIBus = FOUR_CHAR_CODE('pscb')799pSCSILUN = FOUR_CHAR_CODE('pslu')800eDeviceType = FOUR_CHAR_CODE('edvt')801eAddressSpec = FOUR_CHAR_CODE('eads')802eConduit = FOUR_CHAR_CODE('econ')803eProtocol = FOUR_CHAR_CODE('epro')804eADB = FOUR_CHAR_CODE('eadb')805eAnalogAudio = FOUR_CHAR_CODE('epau')806eAppleTalk = FOUR_CHAR_CODE('epat')807eAudioLineIn = FOUR_CHAR_CODE('ecai')808eAudioLineOut = FOUR_CHAR_CODE('ecal')809eAudioOut = FOUR_CHAR_CODE('ecao')810eBus = FOUR_CHAR_CODE('ebus')811eCDROM = FOUR_CHAR_CODE('ecd ')812eCommSlot = FOUR_CHAR_CODE('eccm')813eDigitalAudio = FOUR_CHAR_CODE('epda')814eDisplay = FOUR_CHAR_CODE('edds')815eDVD = FOUR_CHAR_CODE('edvd')816eEthernet = FOUR_CHAR_CODE('ecen')817eFireWire = FOUR_CHAR_CODE('ecfw')818eFloppy = FOUR_CHAR_CODE('efd ')819eHD = FOUR_CHAR_CODE('ehd ')820eInfrared = FOUR_CHAR_CODE('ecir')821eIP = FOUR_CHAR_CODE('epip')822eIrDA = FOUR_CHAR_CODE('epir')823eIRTalk = FOUR_CHAR_CODE('epit')824eKeyboard = FOUR_CHAR_CODE('ekbd')825eLCD = FOUR_CHAR_CODE('edlc')826eLocalTalk = FOUR_CHAR_CODE('eclt')827eMacIP = FOUR_CHAR_CODE('epmi')828eMacVideo = FOUR_CHAR_CODE('epmv')829eMicrophone = FOUR_CHAR_CODE('ecmi')830eModemPort = FOUR_CHAR_CODE('ecmp')831eModemPrinterPort = FOUR_CHAR_CODE('empp')832eModem = FOUR_CHAR_CODE('edmm')833eMonitorOut = FOUR_CHAR_CODE('ecmn')834eMouse = FOUR_CHAR_CODE('emou')835eNuBusCard = FOUR_CHAR_CODE('ednb')836eNuBus = FOUR_CHAR_CODE('enub')837ePCcard = FOUR_CHAR_CODE('ecpc')838ePCIbus = FOUR_CHAR_CODE('ecpi')839ePCIcard = FOUR_CHAR_CODE('edpi')840ePDSslot = FOUR_CHAR_CODE('ecpd')841ePDScard = FOUR_CHAR_CODE('epds')842ePointingDevice = FOUR_CHAR_CODE('edpd')843ePostScript = FOUR_CHAR_CODE('epps')844ePPP = FOUR_CHAR_CODE('eppp')845ePrinterPort = FOUR_CHAR_CODE('ecpp')846ePrinter = FOUR_CHAR_CODE('edpr')847eSvideo = FOUR_CHAR_CODE('epsv')848eSCSI = FOUR_CHAR_CODE('ecsc')849eSerial = FOUR_CHAR_CODE('epsr')850eSpeakers = FOUR_CHAR_CODE('edsp')851eStorageDevice = FOUR_CHAR_CODE('edst')852eSVGA = FOUR_CHAR_CODE('epsg')853eTokenRing = FOUR_CHAR_CODE('etok')854eTrackball = FOUR_CHAR_CODE('etrk')855eTrackpad = FOUR_CHAR_CODE('edtp')856eUSB = FOUR_CHAR_CODE('ecus')857eVideoIn = FOUR_CHAR_CODE('ecvi')858eVideoMonitor = FOUR_CHAR_CODE('edvm')859eVideoOut = FOUR_CHAR_CODE('ecvo')860cKeystroke = FOUR_CHAR_CODE('kprs')861pKeystrokeKey = FOUR_CHAR_CODE('kMsg')862pModifiers = FOUR_CHAR_CODE('kMod')863pKeyKind = FOUR_CHAR_CODE('kknd')864eModifiers = FOUR_CHAR_CODE('eMds')865eOptionDown = FOUR_CHAR_CODE('Kopt')866eCommandDown = FOUR_CHAR_CODE('Kcmd')867eControlDown = FOUR_CHAR_CODE('Kctl')868eShiftDown = FOUR_CHAR_CODE('Ksft')869eCapsLockDown = FOUR_CHAR_CODE('Kclk')870eKeyKind = FOUR_CHAR_CODE('ekst')871eEscapeKey = 0x6B733500872eDeleteKey = 0x6B733300873eTabKey = 0x6B733000874eReturnKey = 0x6B732400875eClearKey = 0x6B734700876eEnterKey = 0x6B734C00877eUpArrowKey = 0x6B737E00878eDownArrowKey = 0x6B737D00879eLeftArrowKey = 0x6B737B00880eRightArrowKey = 0x6B737C00881eHelpKey = 0x6B737200882eHomeKey = 0x6B737300883ePageUpKey = 0x6B737400884ePageDownKey = 0x6B737900885eForwardDelKey = 0x6B737500886eEndKey = 0x6B737700887eF1Key = 0x6B737A00888eF2Key = 0x6B737800889eF3Key = 0x6B736300890eF4Key = 0x6B737600891eF5Key = 0x6B736000892eF6Key = 0x6B736100893eF7Key = 0x6B736200894eF8Key = 0x6B736400895eF9Key = 0x6B736500896eF10Key = 0x6B736D00897eF11Key = 0x6B736700898eF12Key = 0x6B736F00899eF13Key = 0x6B736900900eF14Key = 0x6B736B00901eF15Key = 0x6B737100902kAEAND = FOUR_CHAR_CODE('AND ')903kAEOR = FOUR_CHAR_CODE('OR ')904kAENOT = FOUR_CHAR_CODE('NOT ')905kAEFirst = FOUR_CHAR_CODE('firs')906kAELast = FOUR_CHAR_CODE('last')907kAEMiddle = FOUR_CHAR_CODE('midd')908kAEAny = FOUR_CHAR_CODE('any ')909kAEAll = FOUR_CHAR_CODE('all ')910kAENext = FOUR_CHAR_CODE('next')911kAEPrevious = FOUR_CHAR_CODE('prev')912keyAECompOperator = FOUR_CHAR_CODE('relo')913keyAELogicalTerms = FOUR_CHAR_CODE('term')914keyAELogicalOperator = FOUR_CHAR_CODE('logc')915keyAEObject1 = FOUR_CHAR_CODE('obj1')916keyAEObject2 = FOUR_CHAR_CODE('obj2')917keyAEDesiredClass = FOUR_CHAR_CODE('want')918keyAEContainer = FOUR_CHAR_CODE('from')919keyAEKeyForm = FOUR_CHAR_CODE('form')920keyAEKeyData = FOUR_CHAR_CODE('seld')921keyAERangeStart = FOUR_CHAR_CODE('star')922keyAERangeStop = FOUR_CHAR_CODE('stop')923keyDisposeTokenProc = FOUR_CHAR_CODE('xtok')924keyAECompareProc = FOUR_CHAR_CODE('cmpr')925keyAECountProc = FOUR_CHAR_CODE('cont')926keyAEMarkTokenProc = FOUR_CHAR_CODE('mkid')927keyAEMarkProc = FOUR_CHAR_CODE('mark')928keyAEAdjustMarksProc = FOUR_CHAR_CODE('adjm')929keyAEGetErrDescProc = FOUR_CHAR_CODE('indc')930formAbsolutePosition = FOUR_CHAR_CODE('indx')931formRelativePosition = FOUR_CHAR_CODE('rele')932formTest = FOUR_CHAR_CODE('test')933formRange = FOUR_CHAR_CODE('rang')934formPropertyID = FOUR_CHAR_CODE('prop')935formName = FOUR_CHAR_CODE('name')936typeObjectSpecifier = FOUR_CHAR_CODE('obj ')937typeObjectBeingExamined = FOUR_CHAR_CODE('exmn')938typeCurrentContainer = FOUR_CHAR_CODE('ccnt')939typeToken = FOUR_CHAR_CODE('toke')940typeRelativeDescriptor = FOUR_CHAR_CODE('rel ')941typeAbsoluteOrdinal = FOUR_CHAR_CODE('abso')942typeIndexDescriptor = FOUR_CHAR_CODE('inde')943typeRangeDescriptor = FOUR_CHAR_CODE('rang')944typeLogicalDescriptor = FOUR_CHAR_CODE('logi')945typeCompDescriptor = FOUR_CHAR_CODE('cmpd')946typeOSLTokenList = FOUR_CHAR_CODE('ostl')947kAEIDoMinimum = 0x0000948kAEIDoWhose = 0x0001949kAEIDoMarking = 0x0004950kAEPassSubDescs = 0x0008951kAEResolveNestedLists = 0x0010952kAEHandleSimpleRanges = 0x0020953kAEUseRelativeIterators = 0x0040954typeWhoseDescriptor = FOUR_CHAR_CODE('whos')955formWhose = FOUR_CHAR_CODE('whos')956typeWhoseRange = FOUR_CHAR_CODE('wrng')957keyAEWhoseRangeStart = FOUR_CHAR_CODE('wstr')958keyAEWhoseRangeStop = FOUR_CHAR_CODE('wstp')959keyAEIndex = FOUR_CHAR_CODE('kidx')...

Full Screen

Full Screen

linuxshellcodegenerator.py

Source:linuxshellcodegenerator.py Github

copy

Full Screen

...546 547 from exploitutils import *548 import shellcodeGenerator549 550 def test_shellcode(procname, shellcodename, shellcodeargs = None):551 try:552 shellcodegen = getattr(shellcodeGenerator, 'linux_' + procname)553 except:554 return555 shellcodegen = shellcodegen()556 shellcodegen.addAttr(shellcodename, shellcodeargs)557 shellcode = shellcodegen.get()558 if shellcodeargs:559 shellcodeargs = " " + str(shellcodeargs)560 else:561 shellcodeargs = ""562 print "- %s%s length:%d" % (shellcodename, shellcodeargs, len(shellcode))563 print shellcode_dump(shellcode, mode="RISC")564 565 #########566 #567 # mipsel568 #569 #########570 571 print "testing Linux/mipsel ..."572 573 test_shellcode("mipsel", "GOFindSockWithShell")574 test_shellcode("mipsel", "GOFindSockWithShell", ["CleanSockOpt"])575 576 print "Linux/mipsel tests done.\n"577 578 #########579 #580 # armel581 #582 #########583 584 print "testing Linux/armel ..."585 586 test_shellcode("armel", "setuid+execve")587 588 print "Linux/armel tests done.\n"589 590 #########591 #592 # ppc593 #594 #########595 596 print "testing Linux/ppc ..."597 598 test_shellcode("ppc", "execve")599 test_shellcode("ppc", "execve+exit")600 test_shellcode("ppc", "setreuid+execve")601 test_shellcode("ppc", "setreuid+execve+exit")602 test_shellcode("ppc", "GOOOFindSockWithShell")603 test_shellcode("ppc", "read_exec")604 test_shellcode("ppc", "read_exec_loop")605 ...

Full Screen

Full Screen

app.js

Source:app.js Github

copy

Full Screen

1//let countryCode = document.getElementById("countryCode")2let country = document.getElementById("country");3let phone = document.getElementById("phone");4let sendMsg = document.getElementById("sendMsg");5let msg = document.getElementById("msg");6let linkOfWA = document.getElementById("waLink");7let whatsApp = "https://wa.me/";8//countrycodes with names9let countryInfo = {10 "countries": [{11 "code": "+7840",12 "name": "Abkhazia"13 },14 {15 "code": "+93",16 "name": "Afghanistan"17 },18 {19 "code": "+355",20 "name": "Albania"21 },22 {23 "code": "+213",24 "name": "Algeria"25 },26 {27 "code": "+1 684",28 "name": "American Samoa"29 },30 {31 "code": "+376",32 "name": "Andorra"33 },34 {35 "code": "+244",36 "name": "Angola"37 },38 {39 "code": "+1 264",40 "name": "Anguilla"41 },42 {43 "code": "+1 268",44 "name": "Antigua and Barbuda"45 },46 {47 "code": "+54",48 "name": "Argentina"49 },50 {51 "code": "+374",52 "name": "Armenia"53 },54 {55 "code": "+297",56 "name": "Aruba"57 },58 {59 "code": "+247",60 "name": "Ascension"61 },62 {63 "code": "+61",64 "name": "Australia"65 },66 {67 "code": "+672",68 "name": "Australian External Territories"69 },70 {71 "code": "+43",72 "name": "Austria"73 },74 {75 "code": "+994",76 "name": "Azerbaijan"77 },78 {79 "code": "+1 242",80 "name": "Bahamas"81 },82 {83 "code": "+973",84 "name": "Bahrain"85 },86 {87 "code": "+880",88 "name": "Bangladesh"89 },90 {91 "code": "+1 246",92 "name": "Barbados"93 },94 {95 "code": "+1 268",96 "name": "Barbuda"97 },98 {99 "code": "+375",100 "name": "Belarus"101 },102 {103 "code": "+32",104 "name": "Belgium"105 },106 {107 "code": "+501",108 "name": "Belize"109 },110 {111 "code": "+229",112 "name": "Benin"113 },114 {115 "code": "+1 441",116 "name": "Bermuda"117 },118 {119 "code": "+975",120 "name": "Bhutan"121 },122 {123 "code": "+591",124 "name": "Bolivia"125 },126 {127 "code": "+387",128 "name": "Bosnia and Herzegovina"129 },130 {131 "code": "+267",132 "name": "Botswana"133 },134 {135 "code": "+55",136 "name": "Brazil"137 },138 {139 "code": "+246",140 "name": "British Indian Ocean Territory"141 },142 {143 "code": "+1 284",144 "name": "British Virgin Islands"145 },146 {147 "code": "+673",148 "name": "Brunei"149 },150 {151 "code": "+359",152 "name": "Bulgaria"153 },154 {155 "code": "+226",156 "name": "Burkina Faso"157 },158 {159 "code": "+257",160 "name": "Burundi"161 },162 {163 "code": "+855",164 "name": "Cambodia"165 },166 {167 "code": "+237",168 "name": "Cameroon"169 },170 {171 "code": "+1",172 "name": "Canada"173 },174 {175 "code": "+238",176 "name": "Cape Verde"177 },178 {179 "code": "+ 345",180 "name": "Cayman Islands"181 },182 {183 "code": "+236",184 "name": "Central African Republic"185 },186 {187 "code": "+235",188 "name": "Chad"189 },190 {191 "code": "+56",192 "name": "Chile"193 },194 {195 "code": "+86",196 "name": "China"197 },198 {199 "code": "+61",200 "name": "Christmas Island"201 },202 {203 "code": "+61",204 "name": "Cocos-Keeling Islands"205 },206 {207 "code": "+57",208 "name": "Colombia"209 },210 {211 "code": "+269",212 "name": "Comoros"213 },214 {215 "code": "+242",216 "name": "Congo"217 },218 {219 "code": "+243",220 "name": "Congo, Dem. Rep. of (Zaire)"221 },222 {223 "code": "+682",224 "name": "Cook Islands"225 },226 {227 "code": "+506",228 "name": "Costa Rica"229 },230 {231 "code": "+385",232 "name": "Croatia"233 },234 {235 "code": "+53",236 "name": "Cuba"237 },238 {239 "code": "+599",240 "name": "Curacao"241 },242 {243 "code": "+537",244 "name": "Cyprus"245 },246 {247 "code": "+420",248 "name": "Czech Republic"249 },250 {251 "code": "+45",252 "name": "Denmark"253 },254 {255 "code": "+246",256 "name": "Diego Garcia"257 },258 {259 "code": "+253",260 "name": "Djibouti"261 },262 {263 "code": "+1 767",264 "name": "Dominica"265 },266 {267 "code": "+1 809",268 "name": "Dominican Republic"269 },270 {271 "code": "+670",272 "name": "East Timor"273 },274 {275 "code": "+56",276 "name": "Easter Island"277 },278 {279 "code": "+593",280 "name": "Ecuador"281 },282 {283 "code": "+20",284 "name": "Egypt"285 },286 {287 "code": "+503",288 "name": "El Salvador"289 },290 {291 "code": "+240",292 "name": "Equatorial Guinea"293 },294 {295 "code": "+291",296 "name": "Eritrea"297 },298 {299 "code": "+372",300 "name": "Estonia"301 },302 {303 "code": "+251",304 "name": "Ethiopia"305 },306 {307 "code": "+500",308 "name": "Falkland Islands"309 },310 {311 "code": "+298",312 "name": "Faroe Islands"313 },314 {315 "code": "+679",316 "name": "Fiji"317 },318 {319 "code": "+358",320 "name": "Finland"321 },322 {323 "code": "+33",324 "name": "France"325 },326 {327 "code": "+596",328 "name": "French Antilles"329 },330 {331 "code": "+594",332 "name": "French Guiana"333 },334 {335 "code": "+689",336 "name": "French Polynesia"337 },338 {339 "code": "+241",340 "name": "Gabon"341 },342 {343 "code": "+220",344 "name": "Gambia"345 },346 {347 "code": "+995",348 "name": "Georgia"349 },350 {351 "code": "+49",352 "name": "Germany"353 },354 {355 "code": "+233",356 "name": "Ghana"357 },358 {359 "code": "+350",360 "name": "Gibraltar"361 },362 {363 "code": "+30",364 "name": "Greece"365 },366 {367 "code": "+299",368 "name": "Greenland"369 },370 {371 "code": "+1 473",372 "name": "Grenada"373 },374 {375 "code": "+590",376 "name": "Guadeloupe"377 },378 {379 "code": "+1 671",380 "name": "Guam"381 },382 {383 "code": "+502",384 "name": "Guatemala"385 },386 {387 "code": "+224",388 "name": "Guinea"389 },390 {391 "code": "+245",392 "name": "Guinea-Bissau"393 },394 {395 "code": "+595",396 "name": "Guyana"397 },398 {399 "code": "+509",400 "name": "Haiti"401 },402 {403 "code": "+504",404 "name": "Honduras"405 },406 {407 "code": "+852",408 "name": "Hong Kong SAR China"409 },410 {411 "code": "+36",412 "name": "Hungary"413 },414 {415 "code": "+354",416 "name": "Iceland"417 },418 {419 "code": "+91",420 "name": "India"421 },422 {423 "code": "+62",424 "name": "Indonesia"425 },426 {427 "code": "+98",428 "name": "Iran"429 },430 {431 "code": "+964",432 "name": "Iraq"433 },434 {435 "code": "+353",436 "name": "Ireland"437 },438 {439 "code": "+972",440 "name": "Israel"441 },442 {443 "code": "+39",444 "name": "Italy"445 },446 {447 "code": "+225",448 "name": "Ivory Coast"449 },450 {451 "code": "+1 876",452 "name": "Jamaica"453 },454 {455 "code": "+81",456 "name": "Japan"457 },458 {459 "code": "+962",460 "name": "Jordan"461 },462 {463 "code": "+7 7",464 "name": "Kazakhstan"465 },466 {467 "code": "+254",468 "name": "Kenya"469 },470 {471 "code": "+686",472 "name": "Kiribati"473 },474 {475 "code": "+965",476 "name": "Kuwait"477 },478 {479 "code": "+996",480 "name": "Kyrgyzstan"481 },482 {483 "code": "+856",484 "name": "Laos"485 },486 {487 "code": "+371",488 "name": "Latvia"489 },490 {491 "code": "+961",492 "name": "Lebanon"493 },494 {495 "code": "+266",496 "name": "Lesotho"497 },498 {499 "code": "+231",500 "name": "Liberia"501 },502 {503 "code": "+218",504 "name": "Libya"505 },506 {507 "code": "+423",508 "name": "Liechtenstein"509 },510 {511 "code": "+370",512 "name": "Lithuania"513 },514 {515 "code": "+352",516 "name": "Luxembourg"517 },518 {519 "code": "+853",520 "name": "Macau SAR China"521 },522 {523 "code": "+389",524 "name": "Macedonia"525 },526 {527 "code": "+261",528 "name": "Madagascar"529 },530 {531 "code": "+265",532 "name": "Malawi"533 },534 {535 "code": "+60",536 "name": "Malaysia"537 },538 {539 "code": "+960",540 "name": "Maldives"541 },542 {543 "code": "+223",544 "name": "Mali"545 },546 {547 "code": "+356",548 "name": "Malta"549 },550 {551 "code": "+692",552 "name": "Marshall Islands"553 },554 {555 "code": "+596",556 "name": "Martinique"557 },558 {559 "code": "+222",560 "name": "Mauritania"561 },562 {563 "code": "+230",564 "name": "Mauritius"565 },566 {567 "code": "+262",568 "name": "Mayotte"569 },570 {571 "code": "+52",572 "name": "Mexico"573 },574 {575 "code": "+691",576 "name": "Micronesia"577 },578 {579 "code": "+1 808",580 "name": "Midway Island"581 },582 {583 "code": "+373",584 "name": "Moldova"585 },586 {587 "code": "+377",588 "name": "Monaco"589 },590 {591 "code": "+976",592 "name": "Mongolia"593 },594 {595 "code": "+382",596 "name": "Montenegro"597 },598 {599 "code": "+1664",600 "name": "Montserrat"601 },602 {603 "code": "+212",604 "name": "Morocco"605 },606 {607 "code": "+95",608 "name": "Myanmar"609 },610 {611 "code": "+264",612 "name": "Namibia"613 },614 {615 "code": "+674",616 "name": "Nauru"617 },618 {619 "code": "+977",620 "name": "Nepal"621 },622 {623 "code": "+31",624 "name": "Netherlands"625 },626 {627 "code": "+599",628 "name": "Netherlands Antilles"629 },630 {631 "code": "+1 869",632 "name": "Nevis"633 },634 {635 "code": "+687",636 "name": "New Caledonia"637 },638 {639 "code": "+64",640 "name": "New Zealand"641 },642 {643 "code": "+505",644 "name": "Nicaragua"645 },646 {647 "code": "+227",648 "name": "Niger"649 },650 {651 "code": "+234",652 "name": "Nigeria"653 },654 {655 "code": "+683",656 "name": "Niue"657 },658 {659 "code": "+672",660 "name": "Norfolk Island"661 },662 {663 "code": "+850",664 "name": "North Korea"665 },666 {667 "code": "+1 670",668 "name": "Northern Mariana Islands"669 },670 {671 "code": "+47",672 "name": "Norway"673 },674 {675 "code": "+968",676 "name": "Oman"677 },678 {679 "code": "+92",680 "name": "Pakistan"681 },682 {683 "code": "+680",684 "name": "Palau"685 },686 {687 "code": "+970",688 "name": "Palestinian Territory"689 },690 {691 "code": "+507",692 "name": "Panama"693 },694 {695 "code": "+675",696 "name": "Papua New Guinea"697 },698 {699 "code": "+595",700 "name": "Paraguay"701 },702 {703 "code": "+51",704 "name": "Peru"705 },706 {707 "code": "+63",708 "name": "Philippines"709 },710 {711 "code": "+48",712 "name": "Poland"713 },714 {715 "code": "+351",716 "name": "Portugal"717 },718 {719 "code": "+1 787",720 "name": "Puerto Rico"721 },722 {723 "code": "+974",724 "name": "Qatar"725 },726 {727 "code": "+262",728 "name": "Reunion"729 },730 {731 "code": "+40",732 "name": "Romania"733 },734 {735 "code": "+7",736 "name": "Russia"737 },738 {739 "code": "+250",740 "name": "Rwanda"741 },742 {743 "code": "+685",744 "name": "Samoa"745 },746 {747 "code": "+378",748 "name": "San Marino"749 },750 {751 "code": "+966",752 "name": "Saudi Arabia"753 },754 {755 "code": "+221",756 "name": "Senegal"757 },758 {759 "code": "+381",760 "name": "Serbia"761 },762 {763 "code": "+248",764 "name": "Seychelles"765 },766 {767 "code": "+232",768 "name": "Sierra Leone"769 },770 {771 "code": "+65",772 "name": "Singapore"773 },774 {775 "code": "+421",776 "name": "Slovakia"777 },778 {779 "code": "+386",780 "name": "Slovenia"781 },782 {783 "code": "+677",784 "name": "Solomon Islands"785 },786 {787 "code": "+27",788 "name": "South Africa"789 },790 {791 "code": "+500",792 "name": "South Georgia and the South Sandwich Islands"793 },794 {795 "code": "+82",796 "name": "South Korea"797 },798 {799 "code": "+34",800 "name": "Spain"801 },802 {803 "code": "+94",804 "name": "Sri Lanka"805 },806 {807 "code": "+249",808 "name": "Sudan"809 },810 {811 "code": "+597",812 "name": "Suriname"813 },814 {815 "code": "+268",816 "name": "Swaziland"817 },818 {819 "code": "+46",820 "name": "Sweden"821 },822 {823 "code": "+41",824 "name": "Switzerland"825 },826 {827 "code": "+963",828 "name": "Syria"829 },830 {831 "code": "+886",832 "name": "Taiwan"833 },834 {835 "code": "+992",836 "name": "Tajikistan"837 },838 {839 "code": "+255",840 "name": "Tanzania"841 },842 {843 "code": "+66",844 "name": "Thailand"845 },846 {847 "code": "+670",848 "name": "Timor Leste"849 },850 {851 "code": "+228",852 "name": "Togo"853 },854 {855 "code": "+690",856 "name": "Tokelau"857 },858 {859 "code": "+676",860 "name": "Tonga"861 },862 {863 "code": "+1 868",864 "name": "Trinidad and Tobago"865 },866 {867 "code": "+216",868 "name": "Tunisia"869 },870 {871 "code": "+90",872 "name": "Turkey"873 },874 {875 "code": "+993",876 "name": "Turkmenistan"877 },878 {879 "code": "+1 649",880 "name": "Turks and Caicos Islands"881 },882 {883 "code": "+688",884 "name": "Tuvalu"885 },886 {887 "code": "+1 340",888 "name": "U.S. Virgin Islands"889 },890 {891 "code": "+256",892 "name": "Uganda"893 },894 {895 "code": "+380",896 "name": "Ukraine"897 },898 {899 "code": "+971",900 "name": "United Arab Emirates"901 },902 {903 "code": "+44",904 "name": "United Kingdom"905 },906 {907 "code": "+1",908 "name": "United States"909 },910 {911 "code": "+598",912 "name": "Uruguay"913 },914 {915 "code": "+998",916 "name": "Uzbekistan"917 },918 {919 "code": "+678",920 "name": "Vanuatu"921 },922 {923 "code": "+58",924 "name": "Venezuela"925 },926 {927 "code": "+84",928 "name": "Vietnam"929 },930 {931 "code": "+1 808",932 "name": "Wake Island"933 },934 {935 "code": "+681",936 "name": "Wallis and Futuna"937 },938 {939 "code": "+967",940 "name": "Yemen"941 },942 {943 "code": "+260",944 "name": "Zambia"945 },946 {947 "code": "+255",948 "name": "Zanzibar"949 },950 {951 "code": "+263",952 "name": "Zimbabwe"953 }954 ]955}956phone.addEventListener("input", () => {957 let countryArray = countryInfo.countries;958 //looping through array inside object959 for (let i = 0; i < countryArray.length; i++) {960 if (phone.value.includes(countryArray[i].code)) {961 country.innerText = countryArray[i].name;962 }963 if (phone.value === "") {964 country.innerText = " ";965 }966 }967})968sendMsg.addEventListener("click", ()=>{969 linkOfWA.setAttribute("href", `${whatsApp}${phone.value}?text=${msg.value}`);...

Full Screen

Full Screen

utils.js

Source:utils.js Github

copy

Full Screen

1// @flow2export const countries = [3 { name: 'Afghanistan',4 dialCode: '93',5 code: 'af' },6 { name: 'Aland Islands',7 dialCode: '358',8 code: 'ax' },9 { name: 'Albania',10 dialCode: '355',11 code: 'al' },12 { name: 'Algeria',13 dialCode: '213',14 code: 'dz' },15 { name: 'AmericanSamoa',16 dialCode: '1684',17 code: 'as' },18 { name: 'Andorra',19 dialCode: '376',20 code: 'ad' },21 { name: 'Angola',22 dialCode: '244',23 code: 'ao' },24 { name: 'Anguilla',25 dialCode: '1264',26 code: 'ai' },27 { name: 'Antarctica',28 dialCode: '672',29 code: 'aq' },30 { name: 'Antigua and Barbuda',31 dialCode: '1268',32 code: 'ag' },33 { name: 'Argentina',34 dialCode: '54',35 code: 'ar' },36 { name: 'Armenia',37 dialCode: '374',38 code: 'am' },39 { name: 'Aruba',40 dialCode: '297',41 code: 'aw' },42 { name: 'Australia',43 dialCode: '61',44 code: 'au' },45 { name: 'Austria',46 dialCode: '43',47 code: 'at' },48 { name: 'Azerbaijan',49 dialCode: '994',50 code: 'az' },51 { name: 'Bahamas',52 dialCode: '1242',53 code: 'bs' },54 { name: 'Bahrain',55 dialCode: '973',56 code: 'bh' },57 { name: 'Bangladesh',58 dialCode: '880',59 code: 'bd' },60 { name: 'Barbados',61 dialCode: '1246',62 code: 'bb' },63 { name: 'Belarus',64 dialCode: '375',65 code: 'by' },66 { name: 'Belgium',67 dialCode: '32',68 code: 'be' },69 { name: 'Belize',70 dialCode: '501',71 code: 'bz' },72 { name: 'Benin',73 dialCode: '229',74 code: 'bj' },75 { name: 'Bermuda',76 dialCode: '1441',77 code: 'bm' },78 { name: 'Bhutan',79 dialCode: '975',80 code: 'bt' },81 { name: 'Bolivia, Plurinational State of',82 dialCode: '591',83 code: 'bo' },84 { name: 'Bosnia and Herzegovina',85 dialCode: '387',86 code: 'ba' },87 { name: 'Botswana',88 dialCode: '267',89 code: 'bw' },90 { name: 'Brazil',91 dialCode: '55',92 code: 'br' },93 { name: 'British Indian Ocean Territory',94 dialCode: '246',95 code: 'io' },96 { name: 'Brunei Darussalam',97 dialCode: '673',98 code: 'bn' },99 { name: 'Bulgaria',100 dialCode: '359',101 code: 'bg' },102 { name: 'Burkina Faso',103 dialCode: '226',104 code: 'bf' },105 { name: 'Burundi',106 dialCode: '257',107 code: 'bi' },108 { name: 'Cambodia',109 dialCode: '855',110 code: 'kh' },111 { name: 'Cameroon',112 dialCode: '237',113 code: 'cm' },114 { name: 'Canada',115 dialCode: '1',116 code: 'ca' },117 { name: 'Cape Verde',118 dialCode: '238',119 code: 'cv' },120 { name: 'Cayman Islands',121 dialCode: ' 345',122 code: 'ky' },123 { name: 'Central African Republic',124 dialCode: '236',125 code: 'cf' },126 { name: 'Chad',127 dialCode: '235',128 code: 'td' },129 { name: 'Chile',130 dialCode: '56',131 code: 'cl' },132 { name: 'China',133 dialCode: '86',134 code: 'cn' },135 { name: 'Christmas Island',136 dialCode: '61',137 code: 'cx' },138 { name: 'Cocos (Keeling) Islands',139 dialCode: '61',140 code: 'cc' },141 { name: 'Colombia',142 dialCode: '57',143 code: 'co' },144 { name: 'Comoros',145 dialCode: '269',146 code: 'km' },147 { name: 'Congo',148 dialCode: '242',149 code: 'cg' },150 {151 name: 'Congo, The Democratic Republic of the Congo',152 dialCode: '243',153 code: 'cd'154 },155 { name: 'Cook Islands',156 dialCode: '682',157 code: 'ck' },158 { name: 'Costa Rica',159 dialCode: '506',160 code: 'cr' },161 { name: 'Cote d\'Ivoire',162 dialCode: '225',163 code: 'ci' },164 { name: 'Croatia',165 dialCode: '385',166 code: 'hr' },167 { name: 'Cuba',168 dialCode: '53',169 code: 'cu' },170 { name: 'Cyprus',171 dialCode: '357',172 code: 'cy' },173 { name: 'Czech Republic',174 dialCode: '420',175 code: 'cz' },176 { name: 'Denmark',177 dialCode: '45',178 code: 'dk' },179 { name: 'Djibouti',180 dialCode: '253',181 code: 'dj' },182 { name: 'Dominica',183 dialCode: '1767',184 code: 'dm' },185 { name: 'Dominican Republic',186 dialCode: '1849',187 code: 'do' },188 { name: 'Ecuador',189 dialCode: '593',190 code: 'ec' },191 { name: 'Egypt',192 dialCode: '20',193 code: 'eg' },194 { name: 'El Salvador',195 dialCode: '503',196 code: 'sv' },197 { name: 'Equatorial Guinea',198 dialCode: '240',199 code: 'gq' },200 { name: 'Eritrea',201 dialCode: '291',202 code: 'er' },203 { name: 'Estonia',204 dialCode: '372',205 code: 'ee' },206 { name: 'Ethiopia',207 dialCode: '251',208 code: 'et' },209 { name: 'Falkland Islands (Malvinas)',210 dialCode: '500',211 code: 'fk' },212 { name: 'Faroe Islands',213 dialCode: '298',214 code: 'fo' },215 { name: 'Fiji',216 dialCode: '679',217 code: 'fj' },218 { name: 'Finland',219 dialCode: '358',220 code: 'fi' },221 { name: 'France',222 dialCode: '33',223 code: 'fr' },224 { name: 'French Guiana',225 dialCode: '594',226 code: 'gf' },227 { name: 'French Polynesia',228 dialCode: '689',229 code: 'pf' },230 { name: 'Gabon',231 dialCode: '241',232 code: 'ga' },233 { name: 'Gambia',234 dialCode: '220',235 code: 'gm' },236 { name: 'Georgia',237 dialCode: '995',238 code: 'ge' },239 { name: 'Germany',240 dialCode: '49',241 code: 'de' },242 { name: 'Ghana',243 dialCode: '233',244 code: 'gh' },245 { name: 'Gibraltar',246 dialCode: '350',247 code: 'gi' },248 { name: 'Greece',249 dialCode: '30',250 code: 'gr' },251 { name: 'Greenland',252 dialCode: '299',253 code: 'gl' },254 { name: 'Grenada',255 dialCode: '1473',256 code: 'gd' },257 { name: 'Guadeloupe',258 dialCode: '590',259 code: 'gp' },260 { name: 'Guam',261 dialCode: '1671',262 code: 'gu' },263 { name: 'Guatemala',264 dialCode: '502',265 code: 'gt' },266 { name: 'Guernsey',267 dialCode: '44',268 code: 'gg' },269 { name: 'Guinea',270 dialCode: '224',271 code: 'gn' },272 { name: 'Guinea-Bissau',273 dialCode: '245',274 code: 'gw' },275 { name: 'Guyana',276 dialCode: '595',277 code: 'gy' },278 { name: 'Haiti',279 dialCode: '509',280 code: 'ht' },281 { name: 'Holy See (Vatican City State)',282 dialCode: '379',283 code: 'va' },284 { name: 'Honduras',285 dialCode: '504',286 code: 'hn' },287 { name: 'Hong Kong',288 dialCode: '852',289 code: 'hk' },290 { name: 'Hungary',291 dialCode: '36',292 code: 'hu' },293 { name: 'Iceland',294 dialCode: '354',295 code: 'is' },296 { name: 'India',297 dialCode: '91',298 code: 'in' },299 { name: 'Indonesia',300 dialCode: '62',301 code: 'id' },302 {303 name: 'Iran, Islamic Republic of Persian Gulf',304 dialCode: '98',305 code: 'ir'306 },307 { name: 'Iraq',308 dialCode: '964',309 code: 'iq' },310 { name: 'Ireland',311 dialCode: '353',312 code: 'ie' },313 { name: 'Isle of Man',314 dialCode: '44',315 code: 'im' },316 { name: 'Israel',317 dialCode: '972',318 code: 'il' },319 { name: 'Italy',320 dialCode: '39',321 code: 'it' },322 { name: 'Jamaica',323 dialCode: '1876',324 code: 'jm' },325 { name: 'Japan',326 dialCode: '81',327 code: 'jp' },328 { name: 'Jersey',329 dialCode: '44',330 code: 'je' },331 { name: 'Jordan',332 dialCode: '962',333 code: 'jo' },334 { name: 'Kazakhstan',335 dialCode: '77',336 code: 'kz' },337 { name: 'Kenya',338 dialCode: '254',339 code: 'ke' },340 { name: 'Kiribati',341 dialCode: '686',342 code: 'ki' },343 {344 name: 'Korea, Democratic People\'s Republic of Korea',345 dialCode: '850',346 code: 'kp'347 },348 { name: 'Korea, Republic of South Korea',349 dialCode: '82',350 code: 'kr' },351 { name: 'Kuwait',352 dialCode: '965',353 code: 'kw' },354 { name: 'Kyrgyzstan',355 dialCode: '996',356 code: 'kg' },357 { name: 'Laos',358 dialCode: '856',359 code: 'la' },360 { name: 'Latvia',361 dialCode: '371',362 code: 'lv' },363 { name: 'Lebanon',364 dialCode: '961',365 code: 'lb' },366 { name: 'Lesotho',367 dialCode: '266',368 code: 'ls' },369 { name: 'Liberia',370 dialCode: '231',371 code: 'lr' },372 { name: 'Libyan Arab Jamahiriya',373 dialCode: '218',374 code: 'ly' },375 { name: 'Liechtenstein',376 dialCode: '423',377 code: 'li' },378 { name: 'Lithuania',379 dialCode: '370',380 code: 'lt' },381 { name: 'Luxembourg',382 dialCode: '352',383 code: 'lu' },384 { name: 'Macao',385 dialCode: '853',386 code: 'mo' },387 { name: 'Macedonia',388 dialCode: '389',389 code: 'mk' },390 { name: 'Madagascar',391 dialCode: '261',392 code: 'mg' },393 { name: 'Malawi',394 dialCode: '265',395 code: 'mw' },396 { name: 'Malaysia',397 dialCode: '60',398 code: 'my' },399 { name: 'Maldives',400 dialCode: '960',401 code: 'mv' },402 { name: 'Mali',403 dialCode: '223',404 code: 'ml' },405 { name: 'Malta',406 dialCode: '356',407 code: 'mt' },408 { name: 'Marshall Islands',409 dialCode: '692',410 code: 'mh' },411 { name: 'Martinique',412 dialCode: '596',413 code: 'mq' },414 { name: 'Mauritania',415 dialCode: '222',416 code: 'mr' },417 { name: 'Mauritius',418 dialCode: '230',419 code: 'mu' },420 { name: 'Mayotte',421 dialCode: '262',422 code: 'yt' },423 { name: 'Mexico',424 dialCode: '52',425 code: 'mx' },426 {427 name: 'Micronesia, Federated States of Micronesia',428 dialCode: '691',429 code: 'fm'430 },431 { name: 'Moldova',432 dialCode: '373',433 code: 'md' },434 { name: 'Monaco',435 dialCode: '377',436 code: 'mc' },437 { name: 'Mongolia',438 dialCode: '976',439 code: 'mn' },440 { name: 'Montenegro',441 dialCode: '382',442 code: 'me' },443 { name: 'Montserrat',444 dialCode: '1664',445 code: 'ms' },446 { name: 'Morocco',447 dialCode: '212',448 code: 'ma' },449 { name: 'Mozambique',450 dialCode: '258',451 code: 'mz' },452 { name: 'Myanmar',453 dialCode: '95',454 code: 'mm' },455 { name: 'Namibia',456 dialCode: '264',457 code: 'na' },458 { name: 'Nauru',459 dialCode: '674',460 code: 'nr' },461 { name: 'Nepal',462 dialCode: '977',463 code: 'np' },464 { name: 'Netherlands',465 dialCode: '31',466 code: 'nl' },467 { name: 'Netherlands Antilles',468 dialCode: '599',469 code: 'an' },470 { name: 'New Caledonia',471 dialCode: '687',472 code: 'nc' },473 { name: 'New Zealand',474 dialCode: '64',475 code: 'nz' },476 { name: 'Nicaragua',477 dialCode: '505',478 code: 'ni' },479 { name: 'Niger',480 dialCode: '227',481 code: 'ne' },482 { name: 'Nigeria',483 dialCode: '234',484 code: 'ng' },485 { name: 'Niue',486 dialCode: '683',487 code: 'nu' },488 { name: 'Norfolk Island',489 dialCode: '672',490 code: 'nf' },491 { name: 'Northern Mariana Islands',492 dialCode: '1670',493 code: 'mp' },494 { name: 'Norway',495 dialCode: '47',496 code: 'no' },497 { name: 'Oman',498 dialCode: '968',499 code: 'om' },500 { name: 'Pakistan',501 dialCode: '92',502 code: 'pk' },503 { name: 'Palau',504 dialCode: '680',505 code: 'pw' },506 { name: 'Palestinian Territory, Occupied',507 dialCode: '970',508 code: 'ps' },509 { name: 'Panama',510 dialCode: '507',511 code: 'pa' },512 { name: 'Papua New Guinea',513 dialCode: '675',514 code: 'pg' },515 { name: 'Paraguay',516 dialCode: '595',517 code: 'py' },518 { name: 'Peru',519 dialCode: '51',520 code: 'pe' },521 { name: 'Philippines',522 dialCode: '63',523 code: 'ph' },524 { name: 'Pitcairn',525 dialCode: '872',526 code: 'pn' },527 { name: 'Poland',528 dialCode: '48',529 code: 'pl' },530 { name: 'Portugal',531 dialCode: '351',532 code: 'pt' },533 { name: 'Puerto Rico',534 dialCode: '1939',535 code: 'pr' },536 { name: 'Qatar',537 dialCode: '974',538 code: 'qa' },539 { name: 'Romania',540 dialCode: '40',541 code: 'ro' },542 { name: 'Russia',543 dialCode: '7',544 code: 'ru' },545 { name: 'Rwanda',546 dialCode: '250',547 code: 'rw' },548 { name: 'Reunion',549 dialCode: '262',550 code: 're' },551 { name: 'Saint Barthelemy',552 dialCode: '590',553 code: 'bl' },554 {555 name: 'Saint Helena, Ascension and Tristan Da Cunha',556 dialCode: '290',557 code: 'sh'558 },559 { name: 'Saint Kitts and Nevis',560 dialCode: '1869',561 code: 'kn' },562 { name: 'Saint Lucia',563 dialCode: '1758',564 code: 'lc' },565 { name: 'Saint Martin',566 dialCode: '590',567 code: 'mf' },568 { name: 'Saint Pierre and Miquelon',569 dialCode: '508',570 code: 'pm' },571 { name: 'Saint Vincent and the Grenadines',572 dialCode: '1784',573 code: 'vc' },574 { name: 'Samoa',575 dialCode: '685',576 code: 'ws' },577 { name: 'San Marino',578 dialCode: '378',579 code: 'sm' },580 { name: 'Sao Tome and Principe',581 dialCode: '239',582 code: 'st' },583 { name: 'Saudi Arabia',584 dialCode: '966',585 code: 'sa' },586 { name: 'Senegal',587 dialCode: '221',588 code: 'sn' },589 { name: 'Serbia',590 dialCode: '381',591 code: 'rs' },592 { name: 'Seychelles',593 dialCode: '248',594 code: 'sc' },595 { name: 'Sierra Leone',596 dialCode: '232',597 code: 'sl' },598 { name: 'Singapore',599 dialCode: '65',600 code: 'sg' },601 { name: 'Slovakia',602 dialCode: '421',603 code: 'sk' },604 { name: 'Slovenia',605 dialCode: '386',606 code: 'si' },607 { name: 'Solomon Islands',608 dialCode: '677',609 code: 'sb' },610 { name: 'Somalia',611 dialCode: '252',612 code: 'so' },613 { name: 'South Africa',614 dialCode: '27',615 code: 'za' },616 { name: 'South Sudan',617 dialCode: '211',618 code: 'ss' },619 {620 name: 'South Georgia and the South Sandwich Islands',621 dialCode: '500',622 code: 'gs'623 },624 { name: 'Spain',625 dialCode: '34',626 code: 'es' },627 { name: 'Sri Lanka',628 dialCode: '94',629 code: 'lk' },630 { name: 'Sudan',631 dialCode: '249',632 code: 'sd' },633 { name: 'Suriname',634 dialCode: '597',635 code: 'sr' },636 { name: 'Svalbard and Jan Mayen',637 dialCode: '47',638 code: 'sj' },639 { name: 'Swaziland',640 dialCode: '268',641 code: 'sz' },642 { name: 'Sweden',643 dialCode: '46',644 code: 'se' },645 { name: 'Switzerland',646 dialCode: '41',647 code: 'ch' },648 { name: 'Syrian Arab Republic',649 dialCode: '963',650 code: 'sy' },651 { name: 'Taiwan',652 dialCode: '886',653 code: 'tw' },654 { name: 'Tajikistan',655 dialCode: '992',656 code: 'tj' },657 {658 name: 'Tanzania, United Republic of Tanzania',659 dialCode: '255',660 code: 'tz'661 },662 { name: 'Thailand',663 dialCode: '66',664 code: 'th' },665 { name: 'Timor-Leste',666 dialCode: '670',667 code: 'tl' },668 { name: 'Togo',669 dialCode: '228',670 code: 'tg' },671 { name: 'Tokelau',672 dialCode: '690',673 code: 'tk' },674 { name: 'Tonga',675 dialCode: '676',676 code: 'to' },677 { name: 'Trinidad and Tobago',678 dialCode: '1868',679 code: 'tt' },680 { name: 'Tunisia',681 dialCode: '216',682 code: 'tn' },683 { name: 'Turkey',684 dialCode: '90',685 code: 'tr' },686 { name: 'Turkmenistan',687 dialCode: '993',688 code: 'tm' },689 { name: 'Turks and Caicos Islands',690 dialCode: '1649',691 code: 'tc' },692 { name: 'Tuvalu',693 dialCode: '688',694 code: 'tv' },695 { name: 'Uganda',696 dialCode: '256',697 code: 'ug' },698 { name: 'Ukraine',699 dialCode: '380',700 code: 'ua' },701 { name: 'United Arab Emirates',702 dialCode: '971',703 code: 'ae' },704 { name: 'United Kingdom',705 dialCode: '44',706 code: 'gb' },707 { name: 'United States',708 dialCode: '1',709 code: 'us' },710 { name: 'Uruguay',711 dialCode: '598',712 code: 'uy' },713 { name: 'Uzbekistan',714 dialCode: '998',715 code: 'uz' },716 { name: 'Vanuatu',717 dialCode: '678',718 code: 'vu' },719 {720 name: 'Venezuela, Bolivarian Republic of Venezuela',721 dialCode: '58',722 code: 've'723 },724 { name: 'Vietnam',725 dialCode: '84',726 code: 'vn' },727 { name: 'Virgin Islands, British',728 dialCode: '1284',729 code: 'vg' },730 { name: 'Virgin Islands, U.S.',731 dialCode: '1340',732 code: 'vi' },733 { name: 'Wallis and Futuna',734 dialCode: '681',735 code: 'wf' },736 { name: 'Yemen',737 dialCode: '967',738 code: 'ye' },739 { name: 'Zambia',740 dialCode: '260',741 code: 'zm' },742 { name: 'Zimbabwe',743 dialCode: '263',744 code: 'zw' }745];746const countriesByCodeMap = countries.reduce((result, country) => {747 result[country.dialCode] = country;748 return result;749}, {});750/**751 * Map between country dial codes and country objects.752 *753 */754const codesByNumbersMap = countries.reduce((result, country) => {755 result[country.dialCode] = country.code;756 return result;757}, {});758/**759 * Returns the corresponding country code from a phone number.760 *761 * @param {string} phoneNumber - The phone number.762 * @returns {string}763 */764export function getCountryCodeFromPhone(phoneNumber: string): string {765 const number = phoneNumber.replace(/[+.\s]/g, '');766 for (let i = 4; i > 0; i--) {767 const prefix = number.slice(0, i);768 if (codesByNumbersMap[prefix]) {769 return codesByNumbersMap[prefix];770 }771 }772 return '';773}774/**775 * Returns the corresponding country for a text starting with the dial code.776 *777 * @param {string} text - The text containing the dial code.778 * @returns {Object}779 */780export function getCountryFromDialCodeText(text: string): Object {781 return (782 countriesByCodeMap[text.slice(0, 4)]783 || countriesByCodeMap[text.slice(0, 3)]784 || countriesByCodeMap[text.slice(0, 2)]785 || countriesByCodeMap[text.slice(0, 1)]786 || null787 );...

Full Screen

Full Screen

category_data.py

Source:category_data.py Github

copy

Full Screen

1#!/usr/bin/env python2# encoding: utf-83row_data = [4 {5 'sub_categorys': [6 {7 'sub_categorys': [8 {9 'code': 'yr',10 'name': '羊肉'11 },12 {13 'code': 'ql',14 'name': '禽类'15 },16 {17 'code': 'zr',18 'name': '猪肉'19 },20 {21 'code': 'nr',22 'name': '牛肉'23 }24 ],25 'code': 'jprl',26 'name': '精品肉类'27 },28 {29 'sub_categorys': [30 {31 'code': 'cb',32 'name': '参鲍'33 },34 {35 'code': 'yu',36 'name': '鱼'37 },38 {39 'code': 'xia',40 'name': '虾'41 },42 {43 'code': 'xb',44 'name': '蟹/贝'45 }46 ],47 'code': 'hxsc',48 'name': '海鲜水产'49 },50 {51 'sub_categorys': [52 {53 'code': 'xhd_xyd',54 'name': '松花蛋/咸鸭蛋'55 },56 {57 'code': 'jd',58 'name': '鸡蛋'59 }60 ],61 'code': 'dzp',62 'name': '蛋制品'63 },64 {65 'sub_categorys': [66 {67 'code': 'sc',68 'name': '生菜'69 },70 {71 'code': 'bc',72 'name': '菠菜'73 },74 {75 'code': 'yj',76 'name': '圆椒'77 },78 {79 'code': 'xlh',80 'name': '西兰花'81 }82 ],83 'code': 'ycl',84 'name': '叶菜类'85 },86 {87 'sub_categorys': [88 ],89 'code': 'gjl',90 'name': '根茎类'91 },92 {93 'sub_categorys': [94 ],95 'code': 'qgl',96 'name': '茄果类'97 },98 {99 'sub_categorys': [100 ],101 'code': 'jgl',102 'name': '菌菇类'103 },104 {105 'sub_categorys': [106 ],107 'code': 'jksx',108 'name': '进口生鲜'109 }110 ],111 'code': 'sxsp',112 'name': '生鲜食品'113 },114 {115 'sub_categorys': [116 {117 'sub_categorys': [118 {119 'code': 'wly',120 'name': '五粮液'121 },122 {123 'code': 'lzlj',124 'name': '泸州老窖'125 },126 {127 'code': 'mt',128 'name': '茅台'129 }130 ],131 'code': 'bk',132 'name': '白酒'133 },134 {135 'sub_categorys': [136 ],137 'code': 'ptj',138 'name': '葡萄酒'139 },140 {141 'sub_categorys': [142 ],143 'code': 'yj',144 'name': '洋酒'145 },146 {147 'sub_categorys': [148 ],149 'code': 'pj',150 'name': '啤酒'151 },152 {153 'sub_categorys': [154 {155 'code': 'qtpp',156 'name': '其他品牌'157 },158 {159 'code': 'hj',160 'name': '黄酒'161 },162 {163 'code': 'ysj',164 'name': '养生酒'165 }166 ],167 'code': 'qtjp',168 'name': '其他酒品'169 },170 {171 'sub_categorys': [172 ],173 'code': 'yls',174 'name': '饮料/水'175 },176 {177 'sub_categorys': [178 {179 'code': 'bld',180 'name': '白兰地'181 },182 {183 'code': 'wsj',184 'name': '威士忌'185 }186 ],187 'code': 'hj',188 'name': '红酒'189 }190 ],191 'code': 'jsyl',192 'name': '酒水饮料'193 },194 {195 'sub_categorys': [196 {197 'sub_categorys': [198 {199 'code': '其他食用油',200 'name': '其他食用油'201 },202 {203 'code': '菜仔油',204 'name': '菜仔油'205 },206 {207 'code': '花生油',208 'name': '花生油'209 },210 {211 'code': '橄榄油',212 'name': '橄榄油'213 },214 {215 'code': '礼盒',216 'name': '礼盒'217 }218 ],219 'code': '食用油',220 'name': '食用油'221 },222 {223 'sub_categorys': [224 {225 'code': '面粉/面条',226 'name': '面粉/面条'227 },228 {229 'code': '大米',230 'name': '大米'231 },232 {233 'code': '意大利面',234 'name': '意大利面'235 }236 ],237 'code': '米面杂粮',238 'name': '米面杂粮'239 },240 {241 'sub_categorys': [242 {243 'code': '调味油/汁',244 'name': '调味油/汁'245 },246 {247 'code': '酱油/醋',248 'name': '酱油/醋'249 }250 ],251 'code': '厨房调料',252 'name': '厨房调料'253 },254 {255 'sub_categorys': [256 ],257 'code': '南北干货',258 'name': '南北干货'259 },260 {261 'sub_categorys': [262 ],263 'code': '方便速食',264 'name': '方便速食'265 },266 {267 'sub_categorys': [268 ],269 'code': '调味品',270 'name': '调味品'271 }272 ],273 'code': '粮油副食',274 'name': '粮油副食'275 },276 {277 'sub_categorys': [278 {279 'sub_categorys': [280 {281 'code': '西红柿',282 'name': '西红柿'283 },284 {285 'code': '韭菜',286 'name': '韭菜'287 },288 {289 'code': '青菜',290 'name': '青菜'291 }292 ],293 'code': '有机蔬菜',294 'name': '有机蔬菜'295 },296 {297 'sub_categorys': [298 {299 'code': '甘蓝',300 'name': '甘蓝'301 },302 {303 'code': '胡萝卜',304 'name': '胡萝卜'305 },306 {307 'code': '黄瓜',308 'name': '黄瓜'309 }310 ],311 'code': '精选蔬菜',312 'name': '精选蔬菜'313 },314 {315 'sub_categorys': [316 {317 'code': '火龙果',318 'name': '火龙果'319 },320 {321 'code': '菠萝蜜',322 'name': '菠萝蜜'323 },324 {325 'code': '奇异果',326 'name': '奇异果'327 }328 ],329 'code': '进口水果',330 'name': '进口水果'331 },332 {333 'sub_categorys': [334 {335 'code': '水果礼盒',336 'name': '水果礼盒'337 },338 {339 'code': '苹果',340 'name': '苹果'341 },342 {343 'code': '雪梨',344 'name': '雪梨'345 }346 ],347 'code': '国产水果',348 'name': '国产水果'349 }350 ],351 'code': '蔬菜水果',352 'name': '蔬菜水果'353 },354 {355 'sub_categorys': [356 {357 'sub_categorys': [358 {359 'code': '果冻',360 'name': '果冻'361 },362 {363 'code': '枣类',364 'name': '枣类'365 },366 {367 'code': '蜜饯',368 'name': '蜜饯'369 },370 {371 'code': '肉类零食',372 'name': '肉类零食'373 },374 {375 'code': '坚果炒货',376 'name': '坚果炒货'377 }378 ],379 'code': '休闲零食',380 'name': '休闲零食'381 },382 {383 'sub_categorys': [384 {385 'code': '创意喜糖',386 'name': '创意喜糖'387 },388 {389 'code': '口香糖',390 'name': '口香糖'391 },392 {393 'code': '软糖',394 'name': '软糖'395 },396 {397 'code': '棒棒糖',398 'name': '棒棒糖'399 }400 ],401 'code': '糖果',402 'name': '糖果'403 },404 {405 'sub_categorys': [406 {407 'code': '夹心巧克力',408 'name': '夹心巧克力'409 },410 {411 'code': '白巧克力',412 'name': '白巧克力'413 },414 {415 'code': '松露巧克力',416 'name': '松露巧克力'417 },418 {419 'code': '黑巧克力',420 'name': '黑巧克力'421 }422 ],423 'code': '巧克力',424 'name': '巧克力'425 },426 {427 'sub_categorys': [428 {429 'code': '牛肉干',430 'name': '牛肉干'431 },432 {433 'code': '猪肉脯',434 'name': '猪肉脯'435 },436 {437 'code': '牛肉粒',438 'name': '牛肉粒'439 },440 {441 'code': '猪肉干',442 'name': '猪肉干'443 }444 ],445 'code': '肉干肉脯/豆干',446 'name': '肉干肉脯/豆干'447 },448 {449 'sub_categorys': [450 {451 'code': '鱿鱼足',452 'name': '鱿鱼足'453 },454 {455 'code': '鱿鱼丝',456 'name': '鱿鱼丝'457 },458 {459 'code': '墨鱼/乌贼',460 'name': '墨鱼/乌贼'461 },462 {463 'code': '鱿鱼仔',464 'name': '鱿鱼仔'465 },466 {467 'code': '鱿鱼片',468 'name': '鱿鱼片'469 }470 ],471 'code': '鱿鱼丝/鱼干',472 'name': '鱿鱼丝/鱼干'473 }474 ],475 'code': '休闲食品',476 'name': '休闲食品'477 },478 {479 'sub_categorys': [480 {481 'sub_categorys': [482 ],483 'code': '进口奶品',484 'name': '进口奶品'485 },486 {487 'sub_categorys': [488 ],489 'code': '国产奶品',490 'name': '国产奶品'491 },492 {493 'sub_categorys': [494 ],495 'code': '奶粉',496 'name': '奶粉'497 },498 {499 'sub_categorys': [500 ],501 'code': '有机奶',502 'name': '有机奶'503 },504 {505 'sub_categorys': [506 ],507 'code': '原料奶',508 'name': '原料奶'509 }510 ],511 'code': '奶类食品',512 'name': '奶类食品'513 },514 {515 'sub_categorys': [516 {517 'sub_categorys': [518 ],519 'code': '菌菇类',520 'name': '菌菇类'521 },522 {523 'sub_categorys': [524 ],525 'code': '腌干海产',526 'name': '腌干海产'527 },528 {529 'sub_categorys': [530 ],531 'code': '汤料',532 'name': '汤料'533 },534 {535 'sub_categorys': [536 ],537 'code': '豆类',538 'name': '豆类'539 },540 {541 'sub_categorys': [542 ],543 'code': '干菜/菜干',544 'name': '干菜/菜干'545 },546 {547 'sub_categorys': [548 ],549 'code': '干果/果干',550 'name': '干果/果干'551 },552 {553 'sub_categorys': [554 ],555 'code': '豆制品',556 'name': '豆制品'557 },558 {559 'sub_categorys': [560 ],561 'code': '腊味',562 'name': '腊味'563 }564 ],565 'code': '天然干货',566 'name': '天然干货'567 },568 {569 'sub_categorys': [570 {571 'sub_categorys': [572 ],573 'code': '白茶',574 'name': '白茶'575 },576 {577 'sub_categorys': [578 ],579 'code': '红茶',580 'name': '红茶'581 },582 {583 'sub_categorys': [584 ],585 'code': '绿茶',586 'name': '绿茶'587 }588 ],589 'code': '精选茗茶',590 'name': '精选茗茶'591 }...

Full Screen

Full Screen

ResourceScriptMapping.js

Source:ResourceScriptMapping.js Github

copy

Full Screen

1/*2 * Copyright (C) 2012 Google Inc. All rights reserved.3 *4 * Redistribution and use in source and binary forms, with or without5 * modification, are permitted provided that the following conditions are6 * met:7 *8 * * Redistributions of source code must retain the above copyright9 * notice, this list of conditions and the following disclaimer.10 * * Redistributions in binary form must reproduce the above11 * copyright notice, this list of conditions and the following disclaimer12 * in the documentation and/or other materials provided with the13 * distribution.14 * * Neither the name of Google Inc. nor the names of its15 * contributors may be used to endorse or promote products derived from16 * this software without specific prior written permission.17 *18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.29 */30/**31 * @constructor32 * @extends {WebInspector.Object}33 * @implements {WebInspector.SourceMapping}34 * @implements {WebInspector.UISourceCodeProvider}35 */36WebInspector.ResourceScriptMapping = function()37{38 this._rawSourceCodes = [];39 this._rawSourceCodeForScriptId = {};40 this._rawSourceCodeForURL = {};41 this._rawSourceCodeForDocumentURL = {};42 this._rawSourceCodeForUISourceCode = new Map();43}44WebInspector.ResourceScriptMapping.prototype = {45 /**46 * @param {DebuggerAgent.Location} rawLocation47 * @return {WebInspector.UILocation}48 */49 rawLocationToUILocation: function(rawLocation)50 {51 var rawSourceCode = this._rawSourceCodeForScriptId[rawLocation.scriptId];52 return rawSourceCode.rawLocationToUILocation(rawLocation);53 },54 /**55 * @param {WebInspector.UISourceCode} uiSourceCode56 * @param {number} lineNumber57 * @param {number} columnNumber58 * @return {DebuggerAgent.Location}59 */60 uiLocationToRawLocation: function(uiSourceCode, lineNumber, columnNumber)61 {62 var rawSourceCode = this._rawSourceCodeForUISourceCode.get(uiSourceCode);63 return rawSourceCode.uiLocationToRawLocation(uiSourceCode, lineNumber, columnNumber);64 },65 /**66 * @return {Array.<WebInspector.UISourceCode>}67 */68 uiSourceCodes: function()69 {70 var result = [];71 for (var i = 0; i < this._rawSourceCodes.length; ++i) {72 var uiSourceCode = this._rawSourceCodes[i].uiSourceCode();73 if (uiSourceCode)74 result.push(uiSourceCode);75 }76 return result;77 },78 /**79 * @param {WebInspector.Script} script80 */81 addScript: function(script)82 {83 var resource = null;84 var request = null;85 if (!script.isAnonymousScript()) {86 // First lookup the resource that has already been loaded.87 resource = WebInspector.resourceForURL(script.sourceURL);88 // Ignore resource in case it has not yet finished loading.89 if (resource && resource.request && !resource.request.finished)90 resource = null;91 // Only bind inline and standalone scripts.92 if (resource && !this._shouldBindScriptToContentProvider(script, resource))93 resource = null;94 if (!resource) {95 // When there is no resource, lookup in-flight requests.96 request = WebInspector.networkManager.inflightRequestForURL(script.sourceURL);97 // Only bind inline and standalone scripts.98 if (request && !this._shouldBindScriptToContentProvider(script, request))99 request = null;100 }101 }102 console.assert(!resource || !request);103 var isInlineScript = script.isInlineScript() && (request || resource);104 // If either of these exists, we bind script to the resource.105 if (isInlineScript) {106 var rawSourceCode = this._rawSourceCodeForDocumentURL[script.sourceURL];107 if (rawSourceCode) {108 rawSourceCode.addScript(script);109 this._bindScriptToRawSourceCode(script, rawSourceCode);110 return;111 }112 }113 var rawSourceCode = new WebInspector.RawSourceCode(script.scriptId, script, resource, request, this);114 this._rawSourceCodes.push(rawSourceCode);115 this._bindScriptToRawSourceCode(script, rawSourceCode);116 if (isInlineScript)117 this._rawSourceCodeForDocumentURL[script.sourceURL] = rawSourceCode;118 if (rawSourceCode.uiSourceCode())119 this._uiSourceCodeAdded(rawSourceCode, rawSourceCode.uiSourceCode());120 rawSourceCode.addEventListener(WebInspector.RawSourceCode.Events.UISourceCodeChanged, this._handleUISourceCodeChanged, this);121 },122 /**123 * @param {WebInspector.Script} script124 * @param {WebInspector.ContentProvider} contentProvider125 * @return {boolean}126 */127 _shouldBindScriptToContentProvider: function(script, contentProvider)128 {129 if (script.isInlineScript())130 return contentProvider.contentType() === WebInspector.resourceTypes.Document;131 return contentProvider.contentType() === WebInspector.resourceTypes.Script;132 },133 /**134 * @param {WebInspector.Event} event135 */136 _handleUISourceCodeChanged: function(event)137 {138 var rawSourceCode = /** @type {WebInspector.RawSourceCode} */ event.target;139 var uiSourceCode = /** @type {WebInspector.UISourceCode} */ event.data.uiSourceCode;140 var oldUISourceCode = /** @type {WebInspector.UISourceCode} */ event.data.oldUISourceCode;141 if (!oldUISourceCode)142 this._uiSourceCodeAdded(rawSourceCode, uiSourceCode);143 else144 this._uiSourceCodeReplaced(rawSourceCode, oldUISourceCode, uiSourceCode);145 },146 /**147 * @param {WebInspector.RawSourceCode} rawSourceCode148 * @paran {WebInspector.UISourceCode} uiSourceCode149 */150 _uiSourceCodeAdded: function(rawSourceCode, uiSourceCode)151 {152 this._rawSourceCodeForUISourceCode.put(uiSourceCode, rawSourceCode);153 this.dispatchEventToListeners(WebInspector.UISourceCodeProvider.Events.UISourceCodeAdded, uiSourceCode);154 },155 /**156 * @param {WebInspector.RawSourceCode} rawSourceCode157 * @param {WebInspector.UISourceCode} oldUISourceCode158 * @param {WebInspector.UISourceCode} uiSourceCode159 */160 _uiSourceCodeReplaced: function(rawSourceCode, oldUISourceCode, uiSourceCode)161 {162 this._rawSourceCodeForUISourceCode.remove(oldUISourceCode);163 this._rawSourceCodeForUISourceCode.put(uiSourceCode, rawSourceCode);164 for (var i = 0; i < rawSourceCode._scripts.length; ++i)165 rawSourceCode._scripts[i].setSourceMapping(this);166 var data = { oldUISourceCode: oldUISourceCode, uiSourceCode: uiSourceCode };167 this.dispatchEventToListeners(WebInspector.UISourceCodeProvider.Events.UISourceCodeReplaced, data);168 },169 /**170 * @param {WebInspector.RawSourceCode} rawSourceCode171 * @paran {WebInspector.UISourceCode} uiSourceCode172 */173 _uiSourceCodeRemoved: function(rawSourceCode, uiSourceCode)174 {175 this._rawSourceCodeForUISourceCode.remove(uiSourceCode);176 this.dispatchEventToListeners(WebInspector.UISourceCodeProvider.Events.UISourceCodeRemoved, uiSourceCode);177 },178 /**179 * @param {WebInspector.Script} script180 * @param {WebInspector.RawSourceCode} rawSourceCode181 */182 _bindScriptToRawSourceCode: function(script, rawSourceCode)183 {184 this._rawSourceCodeForScriptId[script.scriptId] = rawSourceCode;185 this._rawSourceCodeForURL[script.sourceURL] = rawSourceCode;186 script.setSourceMapping(this);187 },188 reset: function()189 {190 for (var i = 0; i < this._rawSourceCodes.length; ++i) {191 var rawSourceCode = this._rawSourceCodes[i];192 this._uiSourceCodeRemoved(rawSourceCode, rawSourceCode.uiSourceCode());193 rawSourceCode.removeAllListeners();194 }195 this._rawSourceCodes = [];196 this._rawSourceCodeForScriptId = {};197 this._rawSourceCodeForURL = {};198 this._rawSourceCodeForDocumentURL = {};199 this._rawSourceCodeForUISourceCode.clear();200 }201}...

Full Screen

Full Screen

s7_CommitMatcher.py

Source:s7_CommitMatcher.py Github

copy

Full Screen

1import os2import sys3import csv4from astextractor import ASTExtractor5from properties import dataFolderPath, ASTExtractorPath, ASTExtractorPropertiesPathDetailed6from sklearn.feature_extraction.text import TfidfVectorizer7from sklearn.metrics.pairwise import cosine_similarity8from treehelpers import ted_scores, find_additions_deletions9from texthelpers import set_max_int_for_csv, execute_model, model_exists, create_model, load_model10from xmlhelpers import user_code_to_ast11from s3_extract_commit_asts import get_difference_between_asts1213class CommitMatcher:14 def __init__(self):15 set_max_int_for_csv()16 lines = []17 with open(os.path.join(dataFolderPath, "rev_add_del_asts.csv"), 'r', encoding='utf-8') as infile:18 headers = {header: h for h, header in enumerate(next(infile).strip().split('\t'))}19 for l, row in enumerate(csv.reader(infile, dialect='excel', delimiter='\t')):20 if len(row) > len(headers):21 row = row[1:]22 lines.append(row)2324 self.messages = [line[headers['message']] for line in lines]25 self.methods_before = [line[headers['code_before']] for line in lines]26 self.methods_after = [line[headers['code_after']] for line in lines]27 self.methods_before_ast = [line[headers['code_before_ast']] for line in lines]28 self.methods_after_ast = [line[headers['code_after_ast']] for line in lines]29 self.code_deletions = [line[headers['code_deletions']] for line in lines]30 self.code_additions = [line[headers['code_additions']] for line in lines]31 self.code_deletions_ast = [line[headers['code_deletions_ast']] for line in lines]32 self.code_additions_ast = [line[headers['code_additions_ast']] for line in lines]3334 self.ast_extractor = ASTExtractor(ASTExtractorPath, ASTExtractorPropertiesPathDetailed)35 if not model_exists('tfidf_comments'):36 create_model('tfidf_comments', self.messages)37 self.comment_vectorizer = load_model('tfidf_comments')38 self.comment_tfidf_model = execute_model(self.comment_vectorizer, self.messages)3940 def message_score(self, message):41 try:42 comment_tfidf_model_doc = execute_model(self.comment_vectorizer, [message])43 message_score = cosine_similarity(self.comment_tfidf_model, comment_tfidf_model_doc)44 return [m[0] for m in message_score]45 except:46 sys.exit("There was an error with message score!")4748 def code_before_score(self, code_before):49 try:50 code_before_ast = user_code_to_ast(self.ast_extractor, code_before)51 befores = []52 befores.append(code_before_ast)53 for ast in self.methods_before_ast:54 befores.append(ast)55 sc = ted_scores(befores, 0)56 return sc[1:]57 except:58 sys.exit("There was an error with code before score!")5960 def code_after_score(self, code_after):61 try:62 code_after_ast = user_code_to_ast(self.ast_extractor, code_after)63 afters = []64 afters.append(code_after_ast)65 for ast in self.methods_after_ast:66 afters.append(ast)67 sc = ted_scores(afters, 0)68 return sc[1:]69 except:70 sys.exit("There was an error with code after score!")7172 def code_deletions_score(self, code_deletions, code_before, code_after):73 try:74 if(code_deletions != None):75 code_deletions_ast = user_code_to_ast(self.ast_extractor, code_deletions)76 deletions = []77 deletions.append(code_deletions_ast)78 for ast in self.code_deletions_ast:79 deletions.append(ast)80 sc = ted_scores(deletions, 0)81 return sc[1:]82 elif(code_before!=None and code_after!=None):83 deletions, additions = find_additions_deletions(code_before, code_after)84 code_before_ast = user_code_to_ast(self.ast_extractor, code_before)85 code_after_ast = user_code_to_ast(self.ast_extractor, code_after)86 _, code_deletions_ast = get_difference_between_asts(code_before_ast, code_after_ast, additions!='', deletions!='')8788 deletions = []89 deletions.append(code_deletions_ast)90 for ast in self.code_deletions_ast:91 deletions.append(ast)92 sc = ted_scores(deletions, 0)93 return sc[1:]94 else:95 sys.exit("You must provide either code deletions or code before and code after!")96 except:97 sys.exit("There was an error with code deletions score!")9899 def code_additions_score(self, code_additions, code_before, code_after):100 try:101 if(code_additions != None):102 code_additions_ast = user_code_to_ast(self.ast_extractor, code_additions)103 additions = []104 additions.append(code_additions_ast)105 for ast in self.code_additions_ast:106 additions.append(ast)107 sc = ted_scores(additions, 0)108 return sc[1:]109 elif(code_before!=None and code_after!=None):110 deletions, additions = find_additions_deletions(code_before, code_after)111 code_before_ast = user_code_to_ast(self.ast_extractor, code_before)112 code_after_ast = user_code_to_ast(self.ast_extractor, code_after)113 code_additions_ast, _ = get_difference_between_asts(code_before_ast, code_after_ast, additions!='', deletions!='')114115 additions = []116 additions.append(code_additions_ast)117 for ast in self.code_additions_ast:118 additions.append(ast)119 sc = ted_scores(additions, 0)120 return sc[1:]121 else:122 sys.exit("You must provide either code additions or code before and code after!")123 except:124 sys.exit("There was an error with code additions score!")125126 def search(self, message=None, code_before=None, code_after=None, code_deletions=None, code_additions=None, score_by={'message': False, 'code_before': False, 'code_after': False, 'code_deletions': False, 'code_additions': False}):127 results = []128 scores = [0 for m in self.messages]129 counter = 0130131 if(score_by.get('message')):132 if(message!=None):133 message_score = self.message_score(message)134 scores = [sum(values) for values in zip(scores, message_score)]135 counter += 1136 else:137 sys.exit("You must provide a message!")138 if(score_by.get('code_before')):139 if(code_before!=None):140 code_before_score = self.code_before_score(code_before)141 scores = [sum(values) for values in zip(scores, code_before_score)]142 counter += 1143 else:144 sys.exit("You must provide the code before!")145 if(score_by.get('code_after')):146 if(code_after != None):147 code_after_score = self.code_after_score(code_after)148 scores = [sum(values) for values in zip(scores, code_after_score)]149 counter += 1150 else:151 sys.exit("You must provide the code after!")152 if(score_by.get('code_deletions')):153 code_deletions_score = self.code_deletions_score(code_deletions, code_before, code_after)154 scores = [sum(values) for values in zip(scores, code_deletions_score)]155 counter += 1156 if(score_by.get('code_additions')):157 code_additions_score = self.code_additions_score(code_additions, code_before, code_after)158 scores = [sum(values) for values in zip(scores, code_additions_score)]159 counter += 1160 if(counter != 0):161 scores = [(value/counter) for value in scores]162163 for ind, m in enumerate(self.messages):164 results.append((m, self.methods_before[ind], self.methods_after[ind], self.code_deletions[ind], self.code_additions[ind], scores[ind]))165 results.sort(key=lambda rs: rs[5], reverse=True)166 ...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const strykerParent = require('stryker-parent');2const code = strykerParent.code;3console.log(code);4const strykerParent = require('stryker-parent');5const code = strykerParent.code;6console.log(code);7const strykerParent = require('stryker-parent');8const code = strykerParent.code;9console.log(code);10const strykerParent = require('stryker-parent');11const code = strykerParent.code;12console.log(code);13const strykerParent = require('stryker-parent');14const code = strykerParent.code;15console.log(code);16const strykerParent = require('stryker-parent');17const code = strykerParent.code;18console.log(code);19const strykerParent = require('stryker-parent');20const code = strykerParent.code;21console.log(code);22const strykerParent = require('stryker-parent');23const code = strykerParent.code;24console.log(code);25const strykerParent = require('stryker-parent');26const code = strykerParent.code;27console.log(code);28const strykerParent = require('stryker-parent');29const code = strykerParent.code;30console.log(code);31const strykerParent = require('stryker-parent');32const code = strykerParent.code;33console.log(code);34const strykerParent = require('stryker-parent');35const code = strykerParent.code;36console.log(code);

Full Screen

Using AI Code Generation

copy

Full Screen

1require('stryker-child').code();2require('stryker-parent').code();3require('stryker-child').code();4require('stryker-parent').code();5require('stryker-child').code();6require('stryker-parent').code();7require('stryker-child').code();8require('stryker-parent').code();9require('stryker-child').code();10require('stryker-parent').code();11require('stryker-child').code();

Full Screen

Using AI Code Generation

copy

Full Screen

1module.exports = {2 code: function() {3 }4}5module.exports = {6 code: function() {7 }8}

Full Screen

Using AI Code Generation

copy

Full Screen

1var strykerParent = require('stryker-parent');2var strykerCode = require('stryker-code');3var stryker = strykerParent(strykerCode);4var strykerParent = require('stryker-parent');5var strykerCode = require('stryker-code');6var stryker = strykerParent(strykerCode);7var strykerParent = require('stryker-parent');8var strykerCode = require('stryker-code');9var stryker = strykerParent(strykerCode);10var strykerParent = require('stryker-parent');11var strykerCode = require('stryker-code');12var stryker = strykerParent(strykerCode);13var strykerParent = require('stryker-parent');14var strykerCode = require('stryker-code');15var stryker = strykerParent(strykerCode);16var strykerParent = require('stryker-parent');17var strykerCode = require('stryker-code');18var stryker = strykerParent(strykerCode);19var strykerParent = require('stryker-parent');20var strykerCode = require('stryker-code');21var stryker = strykerParent(strykerCode);22var strykerParent = require('stryker-parent');23var strykerCode = require('stryker-code');24var stryker = strykerParent(strykerCode);25var strykerParent = require('stryker-parent');26var strykerCode = require('stryker-code');27var stryker = strykerParent(strykerCode);28var strykerParent = require('stryker-parent');29var strykerCode = require('stryker-code');30var stryker = strykerParent(strykerCode);

Full Screen

Using AI Code Generation

copy

Full Screen

1const code = require('stryker-parent').code;2console.log(code('Hello world!'));3const code = require('stryker-parent').code;4console.log(code('Hello world!'));5const code = require('stryker-parent').code;6console.log(code('Hello world!'));7const code = require('stryker-parent').code;8console.log(code('Hello world!'));9const code = require('stryker-parent').code;10console.log(code('Hello world!'));11const code = require('stryker-parent').code;12console.log(code('Hello world!'));13const code = require('stryker-parent').code;14console.log(code('Hello world!'));15const code = require('stryker-parent').code;16console.log(code('Hello world!'));17const code = require('stryker-parent').code;18console.log(code('Hello world!'));19const code = require('stryker-parent').code;20console.log(code('Hello world!'));21const code = require('stryker-parent').code;22console.log(code('Hello world!'));23const code = require('stryker-parent').code;24console.log(code('

Full Screen

Using AI Code Generation

copy

Full Screen

1const strykerParent = require('stryker-parent');2const strykerParentCode = strykerParent.code;3const strykerChild = require('stryker-child');4const strykerChildCode = strykerChild.code;5const strykerParent = require('stryker-parent');6const strykerParentCode = strykerParent.code;7const strykerChild = require('stryker-child');8const strykerChildCode = strykerChild.code;9const strykerParent = require('stryker-parent');10const strykerParentCode = strykerParent.code;11const strykerChild = require('stryker-child');12const strykerChildCode = strykerChild.code;13const strykerParent = require('stryker-parent');14const strykerParentCode = strykerParent.code;15const strykerChild = require('stryker-child');16const strykerChildCode = strykerChild.code;17const strykerParent = require('stryker-parent');18const strykerParentCode = strykerParent.code;19const strykerChild = require('stryker-child');20const strykerChildCode = strykerChild.code;21const strykerParent = require('stryker-parent');22const strykerParentCode = strykerParent.code;23const strykerChild = require('stryker-child');

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 stryker-parent 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