(self, fullname)
return code_object
Concrete implementation of InspectLoader.get_code.

        Reading of bytecode requires path_stats to be implemented. To write
        bytecode, set_data must also be implemented.
Concrete implementation of InspectLoader.get_code.
Concrete implementation of InspectLoader . get_code .
def get_code(self, fullname):
        """Concrete implementation of InspectLoader.get_code.

        Reading of bytecode requires path_stats to be implemented. To write
        bytecode, set_data must also be implemented.

        """
        source_path = self.get_filename(fullname)
        source_mtime = None
        source_bytes = None
        source_hash = None
        hash_based = False
        check_source = True
        try:
            bytecode_path = cache_from_source(source_path)
        except NotImplementedError:
            bytecode_path = None
        else:
            try:
                st = self.path_stats(source_path)
            except OSError:
                pass
            else:
                source_mtime = int(st['mtime'])
                try:
                    data = self.get_data(bytecode_path)
                except OSError:
                    pass
                else:
                    exc_details = {
                        'name': fullname,
                        'path': bytecode_path,
                    }
                    try:
                        flags = _classify_pyc(data, fullname, exc_details)
                        bytes_data = memoryview(data)[16:]
                        hash_based = flags & 0b1 != 0
                        if hash_based:
                            check_source = flags & 0b10 != 0
                            if (_imp.check_hash_based_pycs != 'never' and
                                (check_source or
                                 _imp.check_hash_based_pycs == 'always')):
                                source_bytes = self.get_data(source_path)
                                source_hash = _imp.source_hash(
                                    _RAW_MAGIC_NUMBER,
                                    source_bytes,
                                )
                                _validate_hash_pyc(data, source_hash, fullname,
                                                   exc_details)
                        else:
                            _validate_timestamp_pyc(
                                data,
                                source_mtime,
                                st['size'],
                                fullname,
                                exc_details,
                            )
                    except (ImportError, EOFError):
                        pass
                    else:
                        _bootstrap._verbose_message('{} matches {}', bytecode_path,
                                                    source_path)
                        return _compile_bytecode(bytes_data, name=fullname,
                                                 bytecode_path=bytecode_path,
                                                 source_path=source_path)
        if source_bytes is None:
            source_bytes = self.get_data(source_path)
        code_object = self.source_to_code(source_bytes, source_path)
        _bootstrap._verbose_message('code object from {}', source_path)
        if (not sys.dont_write_bytecode and bytecode_path is not None and
                source_mtime is not None):
            if hash_based:
                if source_hash is None:
                    source_hash = _imp.source_hash(source_bytes)
                data = _code_to_hash_pyc(code_object, source_hash, check_source)
            else:
                data = _code_to_timestamp_pyc(code_object, source_mtime,
                                              len(source_bytes))
            try:
                self._cache_bytecode(source_path, bytecode_path, data)
            except NotImplementedError:
                pass
        return code_object
def get_code ( self , fullname ) : source_path = self . get_filename ( fullname ) source_mtime = None source_bytes = None source_hash = None hash_based = False check_source = True try : bytecode_path = cache_from_source ( source_path ) except NotImplementedError : bytecode_path = None else : try : st = self . path_stats ( source_path ) except OSError : pass else : source_mtime = int ( st [ 'mtime' ] ) try : data = self . get_data ( bytecode_path ) except OSError : pass else : exc_details = { 'name' : fullname , 'path' : bytecode_path , } try : flags = _classify_pyc ( data , fullname , exc_details ) bytes_data = memoryview ( data ) [ 16 : ] hash_based = flags & 0b1 != 0 if hash_based : check_source = flags & 0b10 != 0 if ( _imp . check_hash_based_pycs != 'never' and ( check_source or _imp . check_hash_based_pycs == 'always' ) ) : source_bytes = self . get_data ( source_path ) source_hash = _imp . source_hash ( _RAW_MAGIC_NUMBER , source_bytes , ) _validate_hash_pyc ( data , source_hash , fullname , exc_details ) else : _validate_timestamp_pyc ( data , source_mtime , st [ 'size' ] , fullname , exc_details , ) except ( ImportError , EOFError ) : pass else : _bootstrap . _verbose_message ( '{} matches {}' , bytecode_path , source_path ) return _compile_bytecode ( bytes_data , name = fullname , bytecode_path = bytecode_path , source_path = source_path ) if source_bytes is None : source_bytes = self . get_data ( source_path ) code_object = self . source_to_code ( source_bytes , source_path ) _bootstrap . _verbose_message ( 'code object from {}' , source_path ) if ( not sys . dont_write_bytecode and bytecode_path is not None and source_mtime is not None ) : if hash_based : if source_hash is None : source_hash = _imp . source_hash ( source_bytes ) data = _code_to_hash_pyc ( code_object , source_hash , check_source ) else : data = _code_to_timestamp_pyc ( code_object , source_mtime , len ( source_bytes ) ) try : self . _cache_bytecode ( source_path , bytecode_path , data ) except NotImplementedError : pass return code_object