idx int64 0 252k | question stringlengths 48 5.28k | target stringlengths 5 1.23k |
|---|---|---|
235,700 | def get_tokens ( tu , extent ) : tokens_memory = POINTER ( Token ) ( ) tokens_count = c_uint ( ) conf . lib . clang_tokenize ( tu , extent , byref ( tokens_memory ) , byref ( tokens_count ) ) count = int ( tokens_count . value ) if count < 1 : return tokens_array = cast ( tokens_memory , POINTER ( Token * count ) ) . c... | Helper method to return all tokens in an extent . |
235,701 | def from_value ( value ) : result = TokenKind . _value_map . get ( value , None ) if result is None : raise ValueError ( 'Unknown TokenKind: %d' % value ) return result | Obtain a registered TokenKind instance from its value . |
235,702 | def register ( value , name ) : if value in TokenKind . _value_map : raise ValueError ( 'TokenKind already registered: %d' % value ) kind = TokenKind ( value , name ) TokenKind . _value_map [ value ] = kind setattr ( TokenKind , name , kind ) | Register a new TokenKind enumeration . |
235,703 | def canonical ( self ) : if not hasattr ( self , '_canonical' ) : self . _canonical = conf . lib . clang_getCanonicalCursor ( self ) return self . _canonical | Return the canonical Cursor corresponding to this Cursor . |
235,704 | def result_type ( self ) : if not hasattr ( self , '_result_type' ) : self . _result_type = conf . lib . clang_getResultType ( self . type ) return self . _result_type | Retrieve the Type of the result for this Cursor . |
235,705 | def underlying_typedef_type ( self ) : if not hasattr ( self , '_underlying_type' ) : assert self . kind . is_declaration ( ) self . _underlying_type = conf . lib . clang_getTypedefDeclUnderlyingType ( self ) return self . _underlying_type | Return the underlying type of a typedef declaration . |
235,706 | def enum_type ( self ) : if not hasattr ( self , '_enum_type' ) : assert self . kind == CursorKind . ENUM_DECL self . _enum_type = conf . lib . clang_getEnumDeclIntegerType ( self ) return self . _enum_type | Return the integer type of an enum declaration . |
235,707 | def enum_value ( self ) : if not hasattr ( self , '_enum_value' ) : assert self . kind == CursorKind . ENUM_CONSTANT_DECL underlying_type = self . type if underlying_type . kind == TypeKind . ENUM : underlying_type = underlying_type . get_declaration ( ) . enum_type if underlying_type . kind in ( TypeKind . CHAR_U , Ty... | Return the value of an enum constant . |
235,708 | def hash ( self ) : if not hasattr ( self , '_hash' ) : self . _hash = conf . lib . clang_hashCursor ( self ) return self . _hash | Returns a hash of the cursor as an int . |
235,709 | def semantic_parent ( self ) : if not hasattr ( self , '_semantic_parent' ) : self . _semantic_parent = conf . lib . clang_getCursorSemanticParent ( self ) return self . _semantic_parent | Return the semantic parent for this cursor . |
235,710 | def lexical_parent ( self ) : if not hasattr ( self , '_lexical_parent' ) : self . _lexical_parent = conf . lib . clang_getCursorLexicalParent ( self ) return self . _lexical_parent | Return the lexical parent for this cursor . |
235,711 | def referenced ( self ) : if not hasattr ( self , '_referenced' ) : self . _referenced = conf . lib . clang_getCursorReferenced ( self ) return self . _referenced | For a cursor that is a reference returns a cursor representing the entity that it references . |
235,712 | def brief_comment ( self ) : r = conf . lib . clang_Cursor_getBriefCommentText ( self ) if not r : return None return str ( r ) | Returns the brief comment text associated with that Cursor |
235,713 | def raw_comment ( self ) : r = conf . lib . clang_Cursor_getRawCommentText ( self ) if not r : return None return str ( r ) | Returns the raw comment text associated with that Cursor |
235,714 | def get_arguments ( self ) : num_args = conf . lib . clang_Cursor_getNumArguments ( self ) for i in xrange ( 0 , num_args ) : yield conf . lib . clang_Cursor_getArgument ( self , i ) | Return an iterator for accessing the arguments of this cursor . |
235,715 | def get_children ( self ) : def visitor ( child , parent , children ) : assert child != conf . lib . clang_getNullCursor ( ) child . _tu = self . _tu children . append ( child ) return 1 children = [ ] conf . lib . clang_visitChildren ( self , callbacks [ 'cursor_visit' ] ( visitor ) , children ) return iter ( children... | Return an iterator for accessing the children of this cursor . |
235,716 | def walk_preorder ( self ) : yield self for child in self . get_children ( ) : for descendant in child . walk_preorder ( ) : yield descendant | Depth - first preorder walk over the cursor and its descendants . |
235,717 | def is_anonymous ( self ) : if self . kind == CursorKind . FIELD_DECL : return self . type . get_declaration ( ) . is_anonymous ( ) return conf . lib . clang_Cursor_isAnonymous ( self ) | Check if the record is anonymous . |
235,718 | def argument_types ( self ) : class ArgumentsIterator ( collections . Sequence ) : def __init__ ( self , parent ) : self . parent = parent self . length = None def __len__ ( self ) : if self . length is None : self . length = conf . lib . clang_getNumArgTypes ( self . parent ) return self . length def __getitem__ ( sel... | Retrieve a container for the non - variadic arguments for this type . |
235,719 | def element_type ( self ) : result = conf . lib . clang_getElementType ( self ) if result . kind == TypeKind . INVALID : raise Exception ( 'Element type not available on this type.' ) return result | Retrieve the Type of elements within this Type . |
235,720 | def element_count ( self ) : result = conf . lib . clang_getNumElements ( self ) if result < 0 : raise Exception ( 'Type does not have elements.' ) return result | Retrieve the number of elements in this type . |
235,721 | def is_function_variadic ( self ) : assert self . kind == TypeKind . FUNCTIONPROTO return conf . lib . clang_isFunctionTypeVariadic ( self ) | Determine whether this function Type is a variadic function type . |
235,722 | def get_fields ( self ) : def visitor ( field , children ) : assert field != conf . lib . clang_getNullCursor ( ) field . _tu = self . _tu fields . append ( field ) return 1 fields = [ ] conf . lib . clang_Type_visitFields ( self , callbacks [ 'fields_visit' ] ( visitor ) , fields ) return iter ( fields ) | Return an iterator for accessing the fields of this type . |
235,723 | def parse ( self , path , args = None , unsaved_files = None , options = 0 ) : return TranslationUnit . from_source ( path , args , unsaved_files , options , self ) | Load the translation unit from the given source code file by running clang and generating the AST before loading . Additional command line parameters can be passed to clang via the args parameter . |
235,724 | def from_ast_file ( cls , filename , index = None ) : if index is None : index = Index . create ( ) ptr = conf . lib . clang_createTranslationUnit ( index , filename ) if not ptr : raise TranslationUnitLoadError ( filename ) return cls ( ptr = ptr , index = index ) | Create a TranslationUnit instance from a saved AST file . |
235,725 | def get_includes ( self ) : def visitor ( fobj , lptr , depth , includes ) : if depth > 0 : loc = lptr . contents includes . append ( FileInclusion ( loc . file , File ( fobj ) , loc , depth ) ) includes = [ ] conf . lib . clang_getInclusions ( self , callbacks [ 'translation_unit_includes' ] ( visitor ) , includes ) r... | Return an iterable sequence of FileInclusion objects that describe the sequence of inclusions in a translation unit . The first object in this sequence is always the input file . Note that this method will not recursively iterate over header files included through precompiled headers . |
235,726 | def get_location ( self , filename , position ) : f = self . get_file ( filename ) if isinstance ( position , int ) : return SourceLocation . from_offset ( self , f , position ) return SourceLocation . from_position ( self , f , position [ 0 ] , position [ 1 ] ) | Obtain a SourceLocation for a file in this translation unit . |
235,727 | def get_extent ( self , filename , locations ) : f = self . get_file ( filename ) if len ( locations ) < 2 : raise Exception ( 'Must pass object with at least 2 elements' ) start_location , end_location = locations if hasattr ( start_location , '__len__' ) : start_location = SourceLocation . from_position ( self , f , ... | Obtain a SourceRange from this translation unit . |
235,728 | def reparse ( self , unsaved_files = None , options = 0 ) : if unsaved_files is None : unsaved_files = [ ] unsaved_files_array = 0 if len ( unsaved_files ) : unsaved_files_array = ( _CXUnsavedFile * len ( unsaved_files ) ) ( ) for i , ( name , value ) in enumerate ( unsaved_files ) : if not isinstance ( value , str ) :... | Reparse an already parsed translation unit . |
235,729 | def save ( self , filename ) : options = conf . lib . clang_defaultSaveOptions ( self ) result = int ( conf . lib . clang_saveTranslationUnit ( self , filename , options ) ) if result != 0 : raise TranslationUnitSaveError ( result , 'Error saving TranslationUnit.' ) | Saves the TranslationUnit to a file . |
235,730 | def codeComplete ( self , path , line , column , unsaved_files = None , include_macros = False , include_code_patterns = False , include_brief_comments = False ) : options = 0 if include_macros : options += 1 if include_code_patterns : options += 2 if include_brief_comments : options += 4 if unsaved_files is None : uns... | Code complete in this translation unit . |
235,731 | def get_tokens ( self , locations = None , extent = None ) : if locations is not None : extent = SourceRange ( start = locations [ 0 ] , end = locations [ 1 ] ) return TokenGroup . get_tokens ( self , extent ) | Obtain tokens in this translation unit . |
235,732 | def name ( self ) : return str ( conf . lib . clang_getCString ( conf . lib . clang_getFileName ( self ) ) ) | Return the complete file and path name of the file . |
235,733 | def arguments ( self ) : length = conf . lib . clang_CompileCommand_getNumArgs ( self . cmd ) for i in xrange ( length ) : yield str ( conf . lib . clang_CompileCommand_getArg ( self . cmd , i ) ) | Get an iterable object providing each argument in the command line for the compiler invocation as a _CXString . |
235,734 | def fromDirectory ( buildDir ) : errorCode = c_uint ( ) try : cdb = conf . lib . clang_CompilationDatabase_fromDirectory ( buildDir , byref ( errorCode ) ) except CompilationDatabaseError as e : raise CompilationDatabaseError ( int ( errorCode . value ) , "CompilationDatabase loading failed" ) return cdb | Builds a CompilationDatabase from the database found in buildDir |
235,735 | def get_klass_parents ( gi_name ) : res = [ ] parents = __HIERARCHY_GRAPH . predecessors ( gi_name ) if not parents : return [ ] __get_parent_link_recurse ( parents [ 0 ] , res ) return res | Returns a sorted list of qualified symbols representing the parents of the klass - like symbol named gi_name |
235,736 | def get_klass_children ( gi_name ) : res = { } children = __HIERARCHY_GRAPH . successors ( gi_name ) for gi_name in children : ctype_name = ALL_GI_TYPES [ gi_name ] qs = QualifiedSymbol ( type_tokens = [ Link ( None , ctype_name , ctype_name ) ] ) qs . add_extension_attribute ( 'gi-extension' , 'type_desc' , SymbolType... | Returns a dict of qualified symbols representing the children of the klass - like symbol named gi_name |
235,737 | def cache_nodes ( gir_root , all_girs ) : ns_node = gir_root . find ( './{%s}namespace' % NS_MAP [ 'core' ] ) id_prefixes = ns_node . attrib [ '{%s}identifier-prefixes' % NS_MAP [ 'c' ] ] sym_prefixes = ns_node . attrib [ '{%s}symbol-prefixes' % NS_MAP [ 'c' ] ] id_key = '{%s}identifier' % NS_MAP [ 'c' ] for node in gi... | Identify and store all the gir symbols the symbols we will document may link to or be typed with |
235,738 | def type_description_from_node ( gi_node ) : ctype_name , gi_name , array_nesting = unnest_type ( gi_node ) cur_ns = get_namespace ( gi_node ) if ctype_name is not None : type_tokens = __type_tokens_from_cdecl ( ctype_name ) else : type_tokens = __type_tokens_from_gitype ( cur_ns , gi_name ) namespaced = '%s.%s' % ( cu... | Parse a typed node returns a usable description |
235,739 | def is_introspectable ( name , language ) : if name in FUNDAMENTALS [ language ] : return True if name not in __TRANSLATED_NAMES [ language ] : return False return True | Do not call this before caching the nodes |
235,740 | def get_markdown_files ( self , dir_ ) : md_files = OrderedSet ( ) for root , _ , files in os . walk ( dir_ ) : for name in files : split = os . path . splitext ( name ) if len ( split ) == 1 : continue if split [ 1 ] in ( '.markdown' , '.md' , '.yaml' ) : md_files . add ( os . path . join ( root , name ) ) return md_f... | Get all the markdown files in a folder recursively |
235,741 | def get ( self , key , default = None ) : if key in self . __cli : return self . __cli [ key ] if key in self . __config : return self . __config . get ( key ) if key in self . __defaults : return self . __defaults . get ( key ) return default | Get the value for key . |
235,742 | def get_index ( self , prefix = '' ) : if prefix : prefixed = '%s_index' % prefix else : prefixed = 'index' if prefixed in self . __cli and self . __cli [ prefixed ] : index = self . __cli . get ( prefixed ) from_conf = False else : index = self . __config . get ( prefixed ) from_conf = True return self . __abspath ( i... | Retrieve the absolute path to an index according to prefix . |
235,743 | def get_path ( self , key , rel_to_cwd = False , rel_to_conf = False ) : if key in self . __cli : path = self . __cli [ key ] from_conf = False else : path = self . __config . get ( key ) from_conf = True if not isinstance ( path , str ) : return None res = self . __abspath ( path , from_conf ) if rel_to_cwd : return o... | Retrieve a path from the config resolving it against the invokation directory or the configuration file directory depending on whether it was passed through the command - line or the configuration file . |
235,744 | def get_paths ( self , key ) : final_paths = [ ] if key in self . __cli : paths = self . __cli [ key ] or [ ] from_conf = False else : paths = self . __config . get ( key ) or [ ] from_conf = True for path in flatten_list ( paths ) : final_path = self . __abspath ( path , from_conf ) if final_path : final_paths . appen... | Same as ConfigParser . get_path for a list of paths . |
235,745 | def get_sources ( self , prefix = '' ) : prefix = prefix . replace ( '-' , '_' ) prefixed = '%s_sources' % prefix if prefixed in self . __cli : sources = self . __cli . get ( prefixed ) from_conf = False else : sources = self . __config . get ( prefixed ) from_conf = True if sources is None : return OrderedSet ( ) sour... | Retrieve a set of absolute paths to sources according to prefix |
235,746 | def get_dependencies ( self ) : all_deps = OrderedSet ( ) for key , _ in list ( self . __config . items ( ) ) : if key in self . __cli : continue if key . endswith ( 'sources' ) : all_deps |= self . get_sources ( key [ : len ( 'sources' ) * - 1 - 1 ] ) for key , _ in list ( self . __cli . items ( ) ) : if key . endswit... | Retrieve the set of all dependencies for a given configuration . |
235,747 | def dump ( self , conf_file = None ) : if conf_file : conf_dir = os . path . dirname ( conf_file ) if not conf_dir : conf_dir = self . __invoke_dir elif not os . path . exists ( conf_dir ) : os . makedirs ( conf_dir ) else : conf_dir = self . __conf_dir final_conf = { } for key , value in list ( self . __config . items... | Dump the possibly updated config to a file . |
235,748 | def _update_submodules ( repo_dir ) : subprocess . check_call ( "git submodule init" , cwd = repo_dir , shell = True ) subprocess . check_call ( "git submodule update --recursive" , cwd = repo_dir , shell = True ) | update submodules in a repo |
235,749 | def require_clean_submodules ( repo_root , submodules ) : for do_nothing in ( '-h' , '--help' , '--help-commands' , 'clean' , 'submodule' ) : if do_nothing in sys . argv : return status = _check_submodule_status ( repo_root , submodules ) if status == "missing" : print ( "checking out submodules for the first time" ) _... | Check on git submodules before distutils can do anything Since distutils cannot be trusted to update the tree after everything has been set in motion this is not a distutils command . |
235,750 | def symlink ( source , link_name ) : if os . path . islink ( link_name ) and os . readlink ( link_name ) == source : return os_symlink = getattr ( os , "symlink" , None ) if callable ( os_symlink ) : os_symlink ( source , link_name ) else : import ctypes csl = ctypes . windll . kernel32 . CreateSymbolicLinkW csl . argt... | Method to allow creating symlinks on Windows |
235,751 | def pkgconfig ( * packages , ** kw ) : config = kw . setdefault ( 'config' , { } ) optional_args = kw . setdefault ( 'optional' , '' ) flag_map = { 'include_dirs' : [ '--cflags-only-I' , 2 ] , 'library_dirs' : [ '--libs-only-L' , 2 ] , 'libraries' : [ '--libs-only-l' , 2 ] , 'extra_compile_args' : [ '--cflags-only-othe... | Query pkg - config for library compile and linking options . Return configuration in distutils Extension format . |
235,752 | def register_error_code ( code , exception_type , domain = 'core' ) : Logger . _error_code_to_exception [ code ] = ( exception_type , domain ) Logger . _domain_codes [ domain ] . add ( code ) | Register a new error code |
235,753 | def register_warning_code ( code , exception_type , domain = 'core' ) : Logger . _warning_code_to_exception [ code ] = ( exception_type , domain ) Logger . _domain_codes [ domain ] . add ( code ) | Register a new warning code |
235,754 | def _log ( code , message , level , domain ) : entry = LogEntry ( level , domain , code , message ) Logger . journal . append ( entry ) if Logger . silent : return if level >= Logger . _verbosity : _print_entry ( entry ) | Call this to add an entry in the journal |
235,755 | def error ( code , message , ** kwargs ) : assert code in Logger . _error_code_to_exception exc_type , domain = Logger . _error_code_to_exception [ code ] exc = exc_type ( message , ** kwargs ) Logger . _log ( code , exc . message , ERROR , domain ) raise exc | Call this to raise an exception and have it stored in the journal |
235,756 | def warn ( code , message , ** kwargs ) : if code in Logger . _ignored_codes : return assert code in Logger . _warning_code_to_exception exc_type , domain = Logger . _warning_code_to_exception [ code ] if domain in Logger . _ignored_domains : return level = WARNING if Logger . fatal_warnings : level = ERROR exc = exc_t... | Call this to store a warning in the journal . |
235,757 | def debug ( message , domain ) : if domain in Logger . _ignored_domains : return Logger . _log ( None , message , DEBUG , domain ) | Log debugging information |
235,758 | def info ( message , domain ) : if domain in Logger . _ignored_domains : return Logger . _log ( None , message , INFO , domain ) | Log simple info |
235,759 | def get_issues ( ) : issues = [ ] for entry in Logger . journal : if entry . level >= WARNING : issues . append ( entry ) return issues | Get actual issues in the journal . |
235,760 | def reset ( ) : Logger . journal = [ ] Logger . fatal_warnings = False Logger . _ignored_codes = set ( ) Logger . _ignored_domains = set ( ) Logger . _verbosity = 2 Logger . _last_checkpoint = 0 | Resets Logger to its initial state |
235,761 | def walk ( self , action , user_data = None ) : action ( self . index_file , self . __root , 0 , user_data ) self . __do_walk ( self . __root , 1 , action , user_data ) | Walk the hierarchy applying action to each filename . |
235,762 | def parse ( self , filename ) : with io . open ( filename , 'r' , encoding = 'utf-8' ) as _ : lines = _ . readlines ( ) all_source_files = set ( ) source_map = { } lineno = 0 root = None index = None cur_level = - 1 parent_queue = [ ] for line in lines : try : level , line = dedent ( line ) if line . startswith ( '#' )... | Parse a sitemap file . |
235,763 | def parse_comment ( self , comment , filename , lineno , endlineno , include_paths = None , stripped = False ) : if not stripped and not self . __validate_c_comment ( comment . strip ( ) ) : return None title_offset = 0 column_offset = 0 raw_comment = comment if not stripped : try : while comment [ column_offset * - 1 ... | Returns a Comment given a string |
235,764 | def comment_to_ast ( self , comment , link_resolver ) : assert comment is not None text = comment . description if ( self . remove_xml_tags or comment . filename in self . gdbus_codegen_sources ) : text = re . sub ( '<.*?>' , '' , text ) if self . escape_html : text = cgi . escape ( text ) ast , diagnostics = cmark . g... | Given a gtk - doc comment string returns an opaque PyCapsule containing the document root . |
235,765 | def ast_to_html ( self , ast , link_resolver ) : out , _ = cmark . ast_to_html ( ast , link_resolver ) return out | See the documentation of to_ast for more information . |
235,766 | def translate_comment ( self , comment , link_resolver ) : out = u'' self . translate_tags ( comment , link_resolver ) ast = self . comment_to_ast ( comment , link_resolver ) out += self . ast_to_html ( ast , link_resolver ) return out | Given a gtk - doc comment string returns the comment translated to the desired format . |
235,767 | def comment_from_tag ( tag ) : if not tag : return None comment = Comment ( name = tag . name , meta = { 'description' : tag . description } , annotations = tag . annotations ) return comment | Convenience function to create a full - fledged comment for a given tag for example it is convenient to assign a Comment to a ReturnValueSymbol . |
235,768 | def decoder ( data ) : def next_byte ( _it , start , count ) : try : return next ( _it ) [ 1 ] except StopIteration : raise UnicodeDecodeError ( NAME , data , start , start + count , "incomplete byte sequence" ) it = iter ( enumerate ( data ) ) for i , d in it : if d == 0x00 : raise UnicodeDecodeError ( NAME , data , i... | This generator processes a sequence of bytes in Modified UTF - 8 encoding and produces a sequence of unicode string characters . |
235,769 | def decode_modified_utf8 ( data , errors = "strict" ) : value , length = u"" , 0 it = iter ( decoder ( data ) ) while True : try : value += next ( it ) length += 1 except StopIteration : break except UnicodeDecodeError as e : if errors == "strict" : raise e elif errors == "ignore" : pass elif errors == "replace" : valu... | Decodes a sequence of bytes to a unicode text and length using Modified UTF - 8 . This function is designed to be used with Python codecs module . |
235,770 | def apply ( self , byte , value , data , i , count ) : if byte & self . mask == self . value : value <<= self . bits value |= byte & self . mask2 else : raise UnicodeDecodeError ( NAME , data , i , i + count , "invalid {}-byte sequence" . format ( self . count ) ) return value | Apply mask compare to expected value shift and return result . Eventually this could become a reduce function . |
235,771 | def load ( file_object , * transformers , ** kwargs ) : ignore_remaining_data = kwargs . get ( "ignore_remaining_data" , False ) marshaller = JavaObjectUnmarshaller ( file_object , kwargs . get ( "use_numpy_arrays" , False ) ) for transformer in transformers : marshaller . add_transformer ( transformer ) marshaller . a... | Deserializes Java primitive data and objects serialized using ObjectOutputStream from a file - like object . |
235,772 | def loads ( string , * transformers , ** kwargs ) : ignore_remaining_data = kwargs . get ( "ignore_remaining_data" , False ) return load ( BytesIO ( string ) , * transformers , ignore_remaining_data = ignore_remaining_data ) | Deserializes Java objects and primitive data serialized using ObjectOutputStream from a string . |
235,773 | def read ( data , fmt_str ) : size = struct . calcsize ( fmt_str ) return struct . unpack ( fmt_str , data [ : size ] ) , data [ size : ] | Reads input bytes and extract the given structure . Returns both the read elements and the remaining data |
235,774 | def flags ( flags ) : names = sorted ( descr for key , descr in OpCodeDebug . STREAM_CONSTANT . items ( ) if key & flags ) return ", " . join ( names ) | Returns the names of the class description flags found in the given integer |
235,775 | def _readStreamHeader ( self ) : ( magic , version ) = self . _readStruct ( ">HH" ) if magic != self . STREAM_MAGIC or version != self . STREAM_VERSION : raise IOError ( "The stream is not java serialized object. " "Invalid stream header: {0:04X}{1:04X}" . format ( magic , version ) ) | Reads the magic header of a Java serialization stream |
235,776 | def _read_and_exec_opcode ( self , ident = 0 , expect = None ) : position = self . object_stream . tell ( ) ( opid , ) = self . _readStruct ( ">B" ) log_debug ( "OpCode: 0x{0:X} -- {1} (at offset 0x{2:X})" . format ( opid , OpCodeDebug . op_id ( opid ) , position ) , ident , ) if expect and opid not in expect : raise I... | Reads the next opcode and executes its handler |
235,777 | def do_string ( self , parent = None , ident = 0 ) : log_debug ( "[string]" , ident ) ba = JavaString ( self . _readString ( ) ) self . _add_reference ( ba , ident ) return ba | Handles a TC_STRING opcode |
235,778 | def do_array ( self , parent = None , ident = 0 ) : log_debug ( "[array]" , ident ) _ , classdesc = self . _read_and_exec_opcode ( ident = ident + 1 , expect = ( self . TC_CLASSDESC , self . TC_PROXYCLASSDESC , self . TC_NULL , self . TC_REFERENCE , ) , ) array = JavaArray ( classdesc ) self . _add_reference ( array , ... | Handles a TC_ARRAY opcode |
235,779 | def do_reference ( self , parent = None , ident = 0 ) : ( handle , ) = self . _readStruct ( ">L" ) log_debug ( "## Reference handle: 0x{0:X}" . format ( handle ) , ident ) ref = self . references [ handle - self . BASE_REFERENCE_IDX ] log_debug ( "###-> Type: {0} - Value: {1}" . format ( type ( ref ) , ref ) , ident ) ... | Handles a TC_REFERENCE opcode |
235,780 | def do_enum ( self , parent = None , ident = 0 ) : enum = JavaEnum ( ) _ , classdesc = self . _read_and_exec_opcode ( ident = ident + 1 , expect = ( self . TC_CLASSDESC , self . TC_PROXYCLASSDESC , self . TC_NULL , self . TC_REFERENCE , ) , ) enum . classdesc = classdesc self . _add_reference ( enum , ident ) _ , enumC... | Handles a TC_ENUM opcode |
235,781 | def _create_hexdump ( src , start_offset = 0 , length = 16 ) : FILTER = "" . join ( ( len ( repr ( chr ( x ) ) ) == 3 ) and chr ( x ) or "." for x in range ( 256 ) ) pattern = "{{0:04X}} {{1:<{0}}} {{2}}\n" . format ( length * 3 ) src = to_str ( src , "latin-1" ) result = [ ] for i in range ( 0 , len ( src ) , lengt... | Prepares an hexadecimal dump string |
235,782 | def _convert_char_to_type ( self , type_char ) : typecode = type_char if type ( type_char ) is int : typecode = chr ( type_char ) if typecode in self . TYPECODES_LIST : return typecode else : raise RuntimeError ( "Typecode {0} ({1}) isn't supported." . format ( type_char , typecode ) ) | Ensures a read character is a typecode . |
235,783 | def _add_reference ( self , obj , ident = 0 ) : log_debug ( "## New reference handle 0x{0:X}: {1} -> {2}" . format ( len ( self . references ) + self . BASE_REFERENCE_IDX , type ( obj ) . __name__ , repr ( obj ) , ) , ident , ) self . references . append ( obj ) | Adds a read reference to the marshaler storage |
235,784 | def _oops_dump_state ( self , ignore_remaining_data = False ) : log_error ( "==Oops state dump" + "=" * ( 30 - 17 ) ) log_error ( "References: {0}" . format ( self . references ) ) log_error ( "Stream seeking back at -16 byte (2nd line is an actual position!):" ) self . object_stream . seek ( - 16 , os . SEEK_CUR ) pos... | Log a deserialization error |
235,785 | def dump ( self , obj ) : self . references = [ ] self . object_obj = obj self . object_stream = BytesIO ( ) self . _writeStreamHeader ( ) self . writeObject ( obj ) return self . object_stream . getvalue ( ) | Dumps the given object in the Java serialization format |
235,786 | def writeObject ( self , obj ) : log_debug ( "Writing object of type {0}" . format ( type ( obj ) . __name__ ) ) if isinstance ( obj , JavaArray ) : self . write_array ( obj ) elif isinstance ( obj , JavaEnum ) : self . write_enum ( obj ) elif isinstance ( obj , JavaObject ) : self . write_object ( obj ) elif isinstanc... | Appends an object to the serialization stream |
235,787 | def _writeString ( self , obj , use_reference = True ) : string = to_bytes ( obj , "utf-8" ) if use_reference and isinstance ( obj , JavaString ) : try : idx = self . references . index ( obj ) except ValueError : self . references . append ( obj ) logging . debug ( "*** Adding ref 0x%X for string: %s" , len ( self . r... | Appends a string to the serialization stream |
235,788 | def write_string ( self , obj , use_reference = True ) : if use_reference and isinstance ( obj , JavaString ) : try : idx = self . references . index ( obj ) except ValueError : self . _writeStruct ( ">B" , 1 , ( self . TC_STRING , ) ) self . _writeString ( obj , use_reference ) else : logging . debug ( "*** Reusing re... | Writes a Java string with the TC_STRING type marker |
235,789 | def write_enum ( self , obj ) : self . _writeStruct ( ">B" , 1 , ( self . TC_ENUM , ) ) try : idx = self . references . index ( obj ) except ValueError : self . references . append ( obj ) logging . debug ( "*** Adding ref 0x%X for enum: %s" , len ( self . references ) - 1 + self . BASE_REFERENCE_IDX , obj , ) self . w... | Writes an Enum value |
235,790 | def write_blockdata ( self , obj , parent = None ) : if type ( obj ) is str : obj = to_bytes ( obj , "latin-1" ) length = len ( obj ) if length <= 256 : self . _writeStruct ( ">B" , 1 , ( self . TC_BLOCKDATA , ) ) self . _writeStruct ( ">B" , 1 , ( length , ) ) else : self . _writeStruct ( ">B" , 1 , ( self . TC_BLOCKD... | Appends a block of data to the serialization stream |
235,791 | def write_object ( self , obj , parent = None ) : for transformer in self . object_transformers : tmp_object = transformer . transform ( obj ) if tmp_object is not obj : obj = tmp_object break self . _writeStruct ( ">B" , 1 , ( self . TC_OBJECT , ) ) cls = obj . get_class ( ) self . write_classdesc ( cls ) self . refer... | Writes an object header to the serialization stream |
235,792 | def write_class ( self , obj , parent = None ) : self . _writeStruct ( ">B" , 1 , ( self . TC_CLASS , ) ) self . write_classdesc ( obj ) | Writes a class to the stream |
235,793 | def write_classdesc ( self , obj , parent = None ) : if obj not in self . references : self . references . append ( obj ) logging . debug ( "*** Adding ref 0x%X for classdesc %s" , len ( self . references ) - 1 + self . BASE_REFERENCE_IDX , obj . name , ) self . _writeStruct ( ">B" , 1 , ( self . TC_CLASSDESC , ) ) sel... | Writes a class description |
235,794 | def write_array ( self , obj ) : classdesc = obj . get_class ( ) self . _writeStruct ( ">B" , 1 , ( self . TC_ARRAY , ) ) self . write_classdesc ( classdesc ) self . _writeStruct ( ">i" , 1 , ( len ( obj ) , ) ) self . references . append ( obj ) logging . debug ( "*** Adding ref 0x%X for array []" , len ( self . refer... | Writes a JavaArray |
235,795 | def _write_value ( self , field_type , value ) : if len ( field_type ) > 1 : field_type = field_type [ 0 ] if field_type == self . TYPE_BOOLEAN : self . _writeStruct ( ">B" , 1 , ( 1 if value else 0 , ) ) elif field_type == self . TYPE_BYTE : self . _writeStruct ( ">b" , 1 , ( value , ) ) elif field_type == self . TYPE... | Writes an item of an array |
235,796 | def _convert_type_to_char ( self , type_char ) : typecode = type_char if type ( type_char ) is int : typecode = chr ( type_char ) if typecode in self . TYPECODES_LIST : return ord ( typecode ) elif len ( typecode ) > 1 : if typecode [ 0 ] == "L" : return ord ( self . TYPE_OBJECT ) elif typecode [ 0 ] == "[" : return or... | Converts the given type code to an int |
235,797 | def create ( self , classdesc , unmarshaller = None ) : try : mapped_type = self . TYPE_MAPPER [ classdesc . name ] except KeyError : return JavaObject ( ) else : log_debug ( "---" ) log_debug ( classdesc . name ) log_debug ( "---" ) java_object = mapped_type ( unmarshaller ) log_debug ( ">>> java_object: {0}" . format... | Transforms a deserialized Java object into a Python object |
235,798 | def mnl_simulate ( data , coeff , numalts , GPU = False , returnprobs = True ) : logger . debug ( 'start: MNL simulation with len(data)={} and numalts={}' . format ( len ( data ) , numalts ) ) atype = 'numpy' if not GPU else 'cuda' data = np . transpose ( data ) coeff = np . reshape ( np . array ( coeff ) , ( 1 , len (... | Get the probabilities for each chooser choosing between numalts alternatives . |
235,799 | def mnl_estimate ( data , chosen , numalts , GPU = False , coeffrange = ( - 3 , 3 ) , weights = None , lcgrad = False , beta = None ) : logger . debug ( 'start: MNL fit with len(data)={} and numalts={}' . format ( len ( data ) , numalts ) ) atype = 'numpy' if not GPU else 'cuda' numvars = data . shape [ 1 ] numobs = da... | Calculate coefficients of the MNL model . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.