idx
int64
0
63k
question
stringlengths
61
4.03k
target
stringlengths
6
1.23k
49,700
def get_transaction ( cls , txid ) : for api_call in cls . GET_TX_MAIN : try : return api_call ( txid ) except cls . IGNORED_ERRORS : pass raise ConnectionError ( 'All APIs are unreachable.' )
Gets the full transaction details .
49,701
def get_tx_amount ( cls , txid , txindex ) : for api_call in cls . GET_TX_AMOUNT_MAIN : try : return api_call ( txid , txindex ) except cls . IGNORED_ERRORS : pass raise ConnectionError ( 'All APIs are unreachable.' )
Gets the amount of a given transaction output .
49,702
def get_fee ( speed = FEE_SPEED_MEDIUM ) : if speed == FEE_SPEED_FAST : return DEFAULT_FEE_FAST elif speed == FEE_SPEED_MEDIUM : return DEFAULT_FEE_MEDIUM elif speed == FEE_SPEED_SLOW : return DEFAULT_FEE_SLOW else : raise ValueError ( 'Invalid speed argument.' )
Gets the recommended satoshi per byte fee .
49,703
def find_binutils_libs ( self , libdir , lib_ext ) : bfd_expr = re . compile ( "(lib(?:bfd)|(?:opcodes))(.*?)\%s" % lib_ext ) libs = { } for root , dirs , files in os . walk ( libdir ) : for f in files : m = bfd_expr . search ( f ) if m : lib , version = m . groups ( ) fp = os . path . join ( root , f ) if version in l...
Find Binutils libraries .
49,704
def generate_source_files ( self ) : from pybfd . gen_supported_disasm import get_supported_architectures , get_supported_machines , generate_supported_architectures_source , generate_supported_disassembler_header , gen_supported_archs libs_dirs = [ os . path . dirname ( lib ) for lib in self . libs ] libopcodes = [ li...
Genertate source files to be used during the compile process of the extension module . This is better than just hardcoding the values on python files because header definitions might change along differente Binutils versions and we ll be able to catch the changes and keep the correct values .
49,705
def _darwin_current_arch ( self ) : if sys . platform == "darwin" : if sys . maxsize > 2 ** 32 : return platform . mac_ver ( ) [ 2 ] else : return platform . processor ( )
Add Mac OS X support .
49,706
def init_parser ( ) : usage = "Usage: %(prog)s <option(s)> <file(s)>" description = " Display information from object <file(s)>.\n" description += " At least one of the following switches must be given:" parser = ArgumentParser ( usage = usage , description = description , add_help = False ) group = parser . add_mutual...
Initialize option parser .
49,707
def dump ( self , src , length = 16 , start = 0 , preffix = "" ) : FILTER = "" . join ( [ ( len ( repr ( chr ( x ) ) ) == 3 ) and chr ( x ) or '.' for x in xrange ( 256 ) ] ) result = list ( ) for i in xrange ( 0 , len ( src ) , length ) : s = src [ i : i + length ] hexa = " " . join ( [ "%02X" % ord ( x ) for x in s ]...
Dump the specified buffer in hex + ASCII format .
49,708
def content ( self ) : return _bfd . section_get_content ( self . bfd , self . _ptr , 0 , self . size )
Return the entire section content .
49,709
def get_content ( self , offset , size ) : return _bfd . section_get_content ( self . bfd , self . _ptr , offset , size )
Return the specified number of bytes from the current section .
49,710
def main ( ) : test_targets = ( [ ARCH_I386 , MACH_I386_I386_INTEL_SYNTAX , ENDIAN_MONO , "\x55\x89\xe5\xE8\xB8\xFF\xFF\xFF" , 0x1000 ] , [ ARCH_I386 , MACH_X86_64_INTEL_SYNTAX , ENDIAN_MONO , "\x55\x48\x89\xe5\xE8\xA3\xFF\xFF\xFF" , 0x1000 ] , [ ARCH_ARM , MACH_ARM_2 , ENDIAN_LITTLE , "\x04\xe0\x2d\xe5\xED\xFF\xFF\xEB...
Test case for simple opcode disassembly .
49,711
def initialize_bfd ( self , abfd ) : self . _ptr = _opcodes . initialize_bfd ( abfd . _ptr ) if self . architecture == ARCH_I386 : if abfd . arch_size == 32 : self . machine = MACH_I386_I386_INTEL_SYNTAX elif abfd . arch_size == 64 : self . machine = MACH_X86_64_INTEL_SYNTAX
Initialize underlying libOpcodes library using BFD .
49,712
def initialize_non_bfd ( self , architecture = None , machine = None , endian = ENDIAN_UNKNOWN ) : if None in [ architecture , machine , endian ] : return self . architecture = architecture self . machine = machine self . endian = endian
Initialize underlying libOpcodes library not using BFD .
49,713
def initialize_smart_disassemble ( self , data , start_address = 0 ) : _opcodes . initialize_smart_disassemble ( self . _ptr , data , start_address )
Set the binary buffer to disassemble with other related information ready for an instruction by instruction disassembly session .
49,714
def print_single_instruction_callback ( self , address , size , branch_delay_insn , insn_type , target , target2 , disassembly ) : print "0x%X SZ=%d BD=%d IT=%d\t%s" % ( address , size , branch_delay_insn , insn_type , disassembly ) return PYBFD_DISASM_CONTINUE
Callack on each disassembled instruction to print its information .
49,715
def disassemble ( self , data , start_address = 0 ) : return _opcodes . disassemble ( self . _ptr , data , start_address )
Return a list containing the virtual memory address instruction length and disassembly code for the given binary buffer .
49,716
def open ( self , _file , target = DEFAULT_TARGET ) : self . close ( ) if type ( _file ) is FileType : filename = _file . name if islink ( filename ) : raise BfdException ( "Symlinks file-descriptors are not valid" ) try : self . _ptr = _bfd . fdopenr ( filename , target , dup ( _file . fileno ( ) ) ) except Exception ...
Open the existing file for reading .
49,717
def __populate_archive_files ( self ) : self . archive_files = [ ] for _ptr in _bfd . archive_list_files ( self . _ptr ) : try : self . archive_files . append ( Bfd ( _ptr ) ) except BfdException , err : pass
Store the list of files inside an archive file .
49,718
def archive_filenames ( self ) : try : return _bfd . archive_list_filenames ( self . _ptr ) except TypeError , err : raise BfdException ( err )
Return the list of files inside an archive file .
49,719
def file_format_name ( self ) : try : return BfdFormatNamesLong [ self . file_format ] except IndexError , err : raise BfdException ( "Invalid format specified (%d)" % self . file_format )
Return the current format name of the open bdf .
49,720
def __populate_sections ( self ) : if not self . _ptr : raise BfdException ( "BFD not initialized" ) for section in _bfd . get_sections_list ( self . _ptr ) : try : bfd_section = BfdSection ( self . _ptr , section ) self . _sections [ bfd_section . name ] = bfd_section except BfdSectionException , err : pass
Get a list of the section present in the bfd to populate our internal list .
49,721
def __populate_symbols ( self ) : if not self . _ptr : raise BfdException ( "BFD not initialized" ) try : symbols = _bfd . get_symbols ( self . _ptr ) sections = { } for section in self . sections : sections [ self . sections [ section ] . index ] = self . sections [ section ] for symbol in symbols : symbol_section_ind...
Get a list of the symbols present in the bfd to populate our internal list .
49,722
def close ( self ) : if self . _ptr : try : _bfd . close ( self . _ptr ) except TypeError , err : raise BfdException ( "Unable to close bfd (%s)" % err ) finally : self . _ptr = None
Close any existing BFD structure before open a new one .
49,723
def filename ( self ) : if not self . _ptr : raise BfdException ( "BFD not initialized" ) return _bfd . get_bfd_attribute ( self . _ptr , BfdAttributes . FILENAME )
Return the filename of the BFD file being processed .
49,724
def cacheable ( self ) : if not self . _ptr : raise BfdException ( "BFD not initialized" ) return _bfd . get_bfd_attribute ( self . _ptr , BfdAttributes . CACHEABLE )
Return the cacheable attribute of the BFD file being processed .
49,725
def format ( self ) : if not self . _ptr : raise BfdException ( "BFD not initialized" ) return _bfd . get_bfd_attribute ( self . _ptr , BfdAttributes . FORMAT )
Return the format attribute of the BFD file being processed .
49,726
def target ( self ) : if not self . _ptr : raise BfdException ( "BFD not initialized" ) return _bfd . get_bfd_attribute ( self . _ptr , BfdAttributes . TARGET )
Return the target of the BFD file being processed .
49,727
def machine ( self ) : if not self . _ptr : raise BfdException ( "BFD not initialized" ) return _bfd . get_bfd_attribute ( self . _ptr , BfdAttributes . FLAVOUR )
Return the flavour attribute of the BFD file being processed .
49,728
def family_coff ( self ) : if not self . _ptr : raise BfdException ( "BFD not initialized" ) return _bfd . get_bfd_attribute ( self . _ptr , BfdAttributes . FAMILY_COFF )
Return the family_coff attribute of the BFD file being processed .
49,729
def big_endian ( self ) : if not self . _ptr : raise BfdException ( "BFD not initialized" ) return _bfd . get_bfd_attribute ( self . _ptr , BfdAttributes . IS_BIG_ENDIAN )
Return the big endian attribute of the BFD file being processed .
49,730
def little_endian ( self ) : if not self . _ptr : raise BfdException ( "BFD not initialized" ) return _bfd . get_bfd_attribute ( self . _ptr , BfdAttributes . IS_LITTLE_ENDIAN )
Return the little_endian attribute of the BFD file being processed .
49,731
def header_big_endian ( self ) : if not self . _ptr : raise BfdException ( "BFD not initialized" ) return _bfd . get_bfd_attribute ( self . _ptr , BfdAttributes . HEADER_BIG_ENDIAN )
Return the header_big_endian attribute of the BFD file being processed .
49,732
def header_little_endian ( self ) : if not self . _ptr : raise BfdException ( "BFD not initialized" ) return _bfd . get_bfd_attribute ( self . _ptr , BfdAttributes . HEADER_LITTLE_ENDIAN )
Return the header_little_endian attribute of the BFD file being processed .
49,733
def file_flags ( self ) : if not self . _ptr : raise BfdException ( "BFD not initialized" ) return _bfd . get_bfd_attribute ( self . _ptr , BfdAttributes . FILE_FLAGS )
Return the file flags attribute of the BFD file being processed .
49,734
def file_flags ( self , _file_flags ) : if not self . _ptr : raise BfdException ( "BFD not initialized" ) return _bfd . set_file_flags ( self . _ptr , _file_flags )
Set the new file flags attribute of the BFD file being processed .
49,735
def applicable_file_flags ( self ) : if not self . _ptr : raise BfdException ( "BFD not initialized" ) return _bfd . get_bfd_attribute ( self . _ptr , BfdAttributes . APPLICABLE_FILE_FLAGS )
Return the applicable file flags attribute of the BFD file being processed .
49,736
def my_archieve ( self ) : if not self . _ptr : raise BfdException ( "BFD not initialized" ) return _bfd . get_bfd_attribute ( self . _ptr , BfdAttributes . MY_ARCHIEVE )
Return the my archieve attribute of the BFD file being processed .
49,737
def has_map ( self ) : if not self . _ptr : raise BfdException ( "BFD not initialized" ) return _bfd . get_bfd_attribute ( self . _ptr , BfdAttributes . HAS_MAP )
Return the has map attribute of the BFD file being processed .
49,738
def is_thin_archieve ( self ) : if not self . _ptr : raise BfdException ( "BFD not initialized" ) return _bfd . get_bfd_attribute ( self . _ptr , BfdAttributes . IS_THIN_ARCHIEVE )
Return the is thin archieve attribute of the BFD file being processed .
49,739
def has_gap_in_elf_shndx ( self ) : if not self . _ptr : raise BfdException ( "BFD not initialized" ) return _bfd . get_bfd_attribute ( self . _ptr , BfdAttributes . HAS_GAP_IN_ELF_SHNDX )
Return the has gap in elf shndx attribute of the BFD file being processed .
49,740
def valid_reloction_types ( self ) : if not self . _ptr : raise BfdException ( "BFD not initialized" ) return _bfd . get_bfd_attribute ( self . _ptr , BfdAttributes . VALID_RELOC_TYPES )
Return the valid_reloc_types attribute of the BFD file being processed .
49,741
def user_data ( self ) : if not self . _ptr : raise BfdException ( "BFD not initialized" ) return _bfd . get_bfd_attribute ( self . _ptr , BfdAttributes . USRDATA )
Return the usrdata attribute of the BFD file being processed .
49,742
def start_address ( self ) : if not self . _ptr : raise BfdException ( "BFD not initialized" ) return _bfd . get_bfd_attribute ( self . _ptr , BfdAttributes . START_ADDRESS )
Return the start address attribute of the BFD file being processed .
49,743
def symbols_count ( self ) : if not self . _ptr : raise BfdException ( "BFD not initialized" ) return _bfd . get_bfd_attribute ( self . _ptr , BfdAttributes . SYMCOUNT )
Return the symcount attribute of the BFD file being processed .
49,744
def out_symbols ( self ) : if not self . _ptr : raise BfdException ( "BFD not initialized" ) return _bfd . get_bfd_attribute ( self . _ptr , BfdAttributes . OUTSYMBOLS )
Return the out symbols attribute of the BFD file being processed .
49,745
def sections_count ( self ) : if not self . _ptr : raise BfdException ( "BFD not initialized" ) return _bfd . get_bfd_attribute ( self . _ptr , BfdAttributes . COUNT_SECTIONS )
Return the sections_count attribute of the BFD file being processed .
49,746
def dynamic_symbols_count ( self ) : if not self . _ptr : raise BfdException ( "BFD not initialized" ) return _bfd . get_bfd_attribute ( self . _ptr , BfdAttributes . DYNAMIC_SYMCOUNT )
Return the dynamic symbols count attribute of the BFD file being processed .
49,747
def symbol_leading_char ( self ) : if not self . _ptr : raise BfdException ( "BFD not initialized" ) return _bfd . get_bfd_attribute ( self . _ptr , BfdAttributes . SYMBOL_LEADING_CHAR )
Return the symbol leading char attribute of the BFD file being processed .
49,748
def arch_size ( self ) : if not self . _ptr : raise BfdException ( "BFD not initialized" ) try : return _bfd . get_arch_size ( self . _ptr ) except Exception , err : raise BfdException ( "Unable to determine architeure size." )
Return the architecure size in bits .
49,749
def display_matrix ( self , matrix , interval = 2.0 , brightness = 1.0 , fading = False , ignore_duplicates = False ) : self . _matrix_writer . write ( matrix = matrix , interval = interval , brightness = brightness , fading = fading , ignore_duplicates = ignore_duplicates )
Displays an LED matrix on Nuimo s LED matrix display .
49,750
def get_asn_origin_whois ( self , asn_registry = 'radb' , asn = None , retry_count = 3 , server = None , port = 43 ) : try : if server is None : server = ASN_ORIGIN_WHOIS [ asn_registry ] [ 'server' ] conn = socket . socket ( socket . AF_INET , socket . SOCK_STREAM ) conn . settimeout ( self . timeout ) log . debug ( '...
The function for retrieving CIDR info for an ASN via whois .
49,751
def get_http_json ( self , url = None , retry_count = 3 , rate_limit_timeout = 120 , headers = None ) : if headers is None : headers = { 'Accept' : 'application/rdap+json' } try : log . debug ( 'HTTP query for {0} at {1}' . format ( self . address_str , url ) ) conn = Request ( url , headers = headers ) data = self . o...
The function for retrieving a json result via HTTP .
49,752
def get_host ( self , retry_count = 3 ) : try : default_timeout_set = False if not socket . getdefaulttimeout ( ) : socket . setdefaulttimeout ( self . timeout ) default_timeout_set = True log . debug ( 'Host query for {0}' . format ( self . address_str ) ) ret = socket . gethostbyaddr ( self . address_str ) if default...
The function for retrieving host information for an IP address .
49,753
def get_http_raw ( self , url = None , retry_count = 3 , headers = None , request_type = 'GET' , form_data = None ) : if headers is None : headers = { 'Accept' : 'text/html' } enc_form_data = None if form_data : enc_form_data = urlencode ( form_data ) try : enc_form_data = bytes ( enc_form_data , encoding = 'ascii' ) e...
The function for retrieving a raw HTML result via HTTP .
49,754
def generate_output ( line = '0' , short = None , name = None , value = None , is_parent = False , colorize = True ) : output = '{0}{1}{2}{3}{4}{5}{6}{7}\n' . format ( LINES [ '{0}{1}' . format ( line , 'C' if colorize else '' ) ] if ( line in LINES . keys ( ) ) else '' , COLOR_DEPTH [ line ] if ( colorize and line in ...
The function for formatting CLI output results .
49,755
def generate_output_header ( self , query_type = 'RDAP' ) : output = '\n{0}{1}{2} query for {3}:{4}\n\n' . format ( ANSI [ 'ul' ] , ANSI [ 'b' ] , query_type , self . obj . address_str , ANSI [ 'end' ] ) return output
The function for generating the CLI output header .
49,756
def generate_output_newline ( self , line = '0' , colorize = True ) : return generate_output ( line = line , is_parent = True , colorize = colorize )
The function for generating a CLI output new line .
49,757
def generate_output_asn ( self , json_data = None , hr = True , show_name = False , colorize = True ) : if json_data is None : json_data = { } keys = { 'asn' , 'asn_cidr' , 'asn_country_code' , 'asn_date' , 'asn_registry' , 'asn_description' } . intersection ( json_data ) output = '' for key in keys : output += generat...
The function for generating CLI output ASN results .
49,758
def generate_output_entities ( self , json_data = None , hr = True , show_name = False , colorize = True ) : output = '' short = HR_RDAP [ 'entities' ] [ '_short' ] if hr else 'entities' name = HR_RDAP [ 'entities' ] [ '_name' ] if ( hr and show_name ) else None output += generate_output ( line = '0' , short = short , ...
The function for generating CLI output RDAP entity results .
49,759
def generate_output_events ( self , source , key , val , line = '2' , hr = True , show_name = False , colorize = True ) : output = generate_output ( line = line , short = HR_RDAP [ source ] [ key ] [ '_short' ] if hr else key , name = HR_RDAP [ source ] [ key ] [ '_name' ] if ( hr and show_name ) else None , is_parent ...
The function for generating CLI output RDAP events results .
49,760
def generate_output_list ( self , source , key , val , line = '2' , hr = True , show_name = False , colorize = True ) : output = generate_output ( line = line , short = HR_RDAP [ source ] [ key ] [ '_short' ] if hr else key , name = HR_RDAP [ source ] [ key ] [ '_name' ] if ( hr and show_name ) else None , is_parent = ...
The function for generating CLI output RDAP list results .
49,761
def generate_output_notices ( self , source , key , val , line = '1' , hr = True , show_name = False , colorize = True ) : output = generate_output ( line = line , short = HR_RDAP [ source ] [ key ] [ '_short' ] if hr else key , name = HR_RDAP [ source ] [ key ] [ '_name' ] if ( hr and show_name ) else None , is_parent...
The function for generating CLI output RDAP notices results .
49,762
def generate_output_network ( self , json_data = None , hr = True , show_name = False , colorize = True ) : if json_data is None : json_data = { } output = generate_output ( line = '0' , short = HR_RDAP [ 'network' ] [ '_short' ] if hr else 'network' , name = HR_RDAP [ 'network' ] [ '_name' ] if ( hr and show_name ) el...
The function for generating CLI output RDAP network results .
49,763
def generate_output_whois_nets ( self , json_data = None , hr = True , show_name = False , colorize = True ) : if json_data is None : json_data = { } output = generate_output ( line = '0' , short = HR_WHOIS [ 'nets' ] [ '_short' ] if hr else 'nets' , name = HR_WHOIS [ 'nets' ] [ '_name' ] if ( hr and show_name ) else N...
The function for generating CLI output Legacy Whois networks results .
49,764
def generate_output_nir ( self , json_data = None , hr = True , show_name = False , colorize = True ) : if json_data is None : json_data = { } output = generate_output ( line = '0' , short = HR_WHOIS_NIR [ 'nets' ] [ '_short' ] if hr else 'nir_nets' , name = HR_WHOIS_NIR [ 'nets' ] [ '_name' ] if ( hr and show_name ) e...
The function for generating CLI output NIR network results .
49,765
def parse_fields_whois ( self , response ) : try : temp = response . split ( '|' ) ret = { 'asn_registry' : temp [ 4 ] . strip ( ' \n' ) } if ret [ 'asn_registry' ] not in self . rir_whois . keys ( ) : raise ASNRegistryError ( 'ASN registry {0} is not known.' . format ( ret [ 'asn_registry' ] ) ) ret [ 'asn' ] = temp [...
The function for parsing ASN fields from a whois response .
49,766
def parse_fields_http ( self , response , extra_org_map = None ) : org_map = self . org_map . copy ( ) try : org_map . update ( extra_org_map ) except ( TypeError , ValueError , IndexError , KeyError ) : pass try : asn_data = { 'asn_registry' : None , 'asn' : None , 'asn_cidr' : None , 'asn_country_code' : None , 'asn_...
The function for parsing ASN fields from a http response .
49,767
def get_nets_radb ( self , response , is_http = False ) : nets = [ ] if is_http : regex = r'route(?:6)?:[^\S\n]+(?P<val>.+?)<br>' else : regex = r'^route(?:6)?:[^\S\n]+(?P<val>.+|.+)$' for match in re . finditer ( regex , response , re . MULTILINE ) : try : net = copy . deepcopy ( BASE_NET ) net [ 'cidr' ] = match . gr...
The function for parsing network blocks from ASN origin data .
49,768
def get_nets_jpnic ( self , response ) : nets = [ ] for match in re . finditer ( r'^.*?(\[Network Number\])[^\S\n]+.+?>(?P<val>.+?)</A>$' , response , re . MULTILINE ) : try : net = copy . deepcopy ( BASE_NET ) tmp = ip_network ( match . group ( 2 ) ) try : network_address = tmp . network_address except AttributeError ...
The function for parsing network blocks from jpnic whois data .
49,769
def get_contact ( self , response = None , nir = None , handle = None , retry_count = 3 , dt_format = None ) : if response or nir == 'krnic' : contact_response = response else : contact_response = self . _net . get_http_raw ( url = str ( NIR_WHOIS [ nir ] [ 'url' ] ) . format ( handle ) , retry_count = retry_count , he...
The function for retrieving and parsing NIR whois data based on NIR_WHOIS contact_fields .
49,770
def _parse_address ( self , val ) : ret = { 'type' : None , 'value' : None } try : ret [ 'type' ] = val [ 1 ] [ 'type' ] except ( KeyError , ValueError , TypeError ) : pass try : ret [ 'value' ] = val [ 1 ] [ 'label' ] except ( KeyError , ValueError , TypeError ) : ret [ 'value' ] = '\n' . join ( val [ 3 ] ) . strip ( ...
The function for parsing the vcard address .
49,771
def _parse_phone ( self , val ) : ret = { 'type' : None , 'value' : None } try : ret [ 'type' ] = val [ 1 ] [ 'type' ] except ( IndexError , KeyError , ValueError , TypeError ) : pass ret [ 'value' ] = val [ 3 ] . strip ( ) try : self . vars [ 'phone' ] . append ( ret ) except AttributeError : self . vars [ 'phone' ] =...
The function for parsing the vcard phone numbers .
49,772
def _parse_email ( self , val ) : ret = { 'type' : None , 'value' : None } try : ret [ 'type' ] = val [ 1 ] [ 'type' ] except ( KeyError , ValueError , TypeError ) : pass ret [ 'value' ] = val [ 3 ] . strip ( ) try : self . vars [ 'email' ] . append ( ret ) except AttributeError : self . vars [ 'email' ] = [ ] self . v...
The function for parsing the vcard email addresses .
49,773
def parse ( self ) : keys = { 'fn' : self . _parse_name , 'kind' : self . _parse_kind , 'adr' : self . _parse_address , 'tel' : self . _parse_phone , 'email' : self . _parse_email , 'role' : self . _parse_role , 'title' : self . _parse_title } for val in self . vcard : try : parser = keys . get ( val [ 0 ] ) parser ( v...
The function for parsing the vcard to the vars dictionary .
49,774
def ipv4_lstrip_zeros ( address ) : obj = address . strip ( ) . split ( '.' ) for x , y in enumerate ( obj ) : obj [ x ] = y . split ( '/' ) [ 0 ] . lstrip ( '0' ) if obj [ x ] in [ '' , None ] : obj [ x ] = '0' return '.' . join ( obj )
The function to strip leading zeros in each octet of an IPv4 address .
49,775
def get_countries ( is_legacy_xml = False ) : countries = { } if sys . platform == 'win32' and getattr ( sys , 'frozen' , False ) : data_dir = path . dirname ( sys . executable ) else : data_dir = path . dirname ( __file__ ) if is_legacy_xml : log . debug ( 'Opening country code legacy XML: {0}' . format ( str ( data_d...
The function to generate a dictionary containing ISO_3166 - 1 country codes to names .
49,776
def unique_everseen ( iterable , key = None ) : seen = set ( ) seen_add = seen . add if key is None : for element in filterfalse ( seen . __contains__ , iterable ) : seen_add ( element ) yield element else : for element in iterable : k = key ( element ) if k not in seen : seen_add ( k ) yield element
The generator to list unique elements preserving the order . Remember all elements ever seen . This was taken from the itertools recipes .
49,777
def get_nets_arin ( self , response ) : nets = [ ] pattern = re . compile ( r'^NetRange:[^\S\n]+(.+)$' , re . MULTILINE ) temp = pattern . search ( response ) net_range = None net_range_start = None if temp is not None : net_range = temp . group ( 1 ) . strip ( ) net_range_start = temp . start ( ) for match in re . fin...
The function for parsing network blocks from ARIN whois data .
49,778
def get_nets_lacnic ( self , response ) : nets = [ ] for match in re . finditer ( r'^(inetnum|inet6num|route):[^\S\n]+(.+?,[^\S\n].+|.+)$' , response , re . MULTILINE ) : try : net = copy . deepcopy ( BASE_NET ) net_range = match . group ( 2 ) . strip ( ) try : net [ 'range' ] = net [ 'range' ] = '{0} - {1}' . format (...
The function for parsing network blocks from LACNIC whois data .
49,779
def get_nets_other ( self , response ) : nets = [ ] for match in re . finditer ( r'^(inetnum|inet6num|route):[^\S\n]+((.+?)[^\S\n]-[^\S\n](.+)|' '.+)$' , response , re . MULTILINE ) : try : net = copy . deepcopy ( BASE_NET ) net_range = match . group ( 2 ) . strip ( ) try : net [ 'range' ] = net [ 'range' ] = '{0} - {1...
The function for parsing network blocks from generic whois data .
49,780
def convert_default ( self , field , ** params ) : for klass , ma_field in self . TYPE_MAPPING : if isinstance ( field , klass ) : return ma_field ( ** params ) return fields . Raw ( ** params )
Return raw field .
49,781
def make_instance ( self , data ) : if not self . opts . model : return data if self . instance is not None : for key , value in data . items ( ) : setattr ( self . instance , key , value ) return self . instance return self . opts . model ( ** data )
Build object from data .
49,782
def _extract ( self , stim ) : props = [ ( e . text , e . onset , e . duration ) for e in stim . elements ] vals , onsets , durations = map ( list , zip ( * props ) ) return ExtractorResult ( vals , stim , self , [ 'word' ] , onsets , durations )
Returns all words .
49,783
def get_filename ( self ) : if self . filename is None or not os . path . exists ( self . filename ) : tf = tempfile . mktemp ( ) + self . _default_file_extension self . save ( tf ) yield tf os . remove ( tf ) else : yield self . filename
Return the source filename of the current Stim .
49,784
def get_stim ( self , type_ , return_all = False ) : if isinstance ( type_ , string_types ) : type_ = _get_stim_class ( type_ ) matches = [ ] for s in self . elements : if isinstance ( s , type_ ) : if not return_all : return s matches . append ( s ) if not matches : return [ ] if return_all else None return matches
Returns component elements of the specified type .
49,785
def has_types ( self , types , all_ = True ) : func = all if all_ else any return func ( [ self . get_stim ( t ) for t in listify ( types ) ] )
Check whether the current component list matches all Stim types in the types argument .
49,786
def save ( self , path ) : self . clip . write_audiofile ( path , fps = self . sampling_rate )
Save clip data to file .
49,787
def get_converter ( in_type , out_type , * args , ** kwargs ) : convs = pliers . converters . __all__ out_type = listify ( out_type ) [ : : - 1 ] default_convs = config . get_option ( 'default_converters' ) for ot in out_type : conv_str = '%s->%s' % ( in_type . __name__ , ot . __name__ ) if conv_str in default_convs : ...
Scans the list of available Converters and returns an instantiation of the first one whose input and output types match those passed in .
49,788
def create_graph ( ) : with tf . gfile . FastGFile ( os . path . join ( FLAGS . model_dir , 'classify_image_graph_def.pb' ) , 'rb' ) as f : graph_def = tf . GraphDef ( ) graph_def . ParseFromString ( f . read ( ) ) _ = tf . import_graph_def ( graph_def , name = '' )
Creates a graph from saved GraphDef file and returns a saver .
49,789
def run_inference_on_image ( image ) : if not tf . gfile . Exists ( image ) : tf . logging . fatal ( 'File does not exist %s' , image ) image_data = tf . gfile . FastGFile ( image , 'rb' ) . read ( ) create_graph ( ) with tf . Session ( ) as sess : softmax_tensor = sess . graph . get_tensor_by_name ( 'softmax:0' ) pred...
Runs inference on an image .
49,790
def load ( self , label_lookup_path , uid_lookup_path ) : if not tf . gfile . Exists ( uid_lookup_path ) : tf . logging . fatal ( 'File does not exist %s' , uid_lookup_path ) if not tf . gfile . Exists ( label_lookup_path ) : tf . logging . fatal ( 'File does not exist %s' , label_lookup_path ) proto_as_ascii_lines = t...
Loads a human readable English name for each softmax node .
49,791
def fetch_dictionary ( name , url = None , format = None , index = 0 , rename = None , save = True , force_retrieve = False ) : file_path = os . path . join ( _get_dictionary_path ( ) , name + '.csv' ) if not force_retrieve and os . path . exists ( file_path ) : df = pd . read_csv ( file_path ) index = datasets [ name ...
Retrieve a dictionary of text norms from the web or local storage .
49,792
def _to_df ( self , result , handle_annotations = None ) : annotations = result . _data if handle_annotations == 'first' : annotations = [ annotations [ 0 ] ] face_results = [ ] for i , annotation in enumerate ( annotations ) : data_dict = { } for field , val in annotation . items ( ) : if 'Confidence' in field : data_...
Converts a Google API Face JSON response into a Pandas Dataframe .
49,793
def correlation_matrix ( df ) : columns = df . columns . tolist ( ) corr = pd . DataFrame ( np . corrcoef ( df , rowvar = 0 ) , columns = columns , index = columns ) return corr
Returns a pandas DataFrame with the pair - wise correlations of the columns .
49,794
def eigenvalues ( df ) : corr = np . corrcoef ( df , rowvar = 0 ) eigvals = np . linalg . eigvals ( corr ) return pd . Series ( eigvals , df . columns , name = 'Eigenvalue' )
Returns a pandas Series with eigenvalues of the correlation matrix .
49,795
def condition_indices ( df ) : eigvals = eigenvalues ( df ) cond_idx = np . sqrt ( eigvals . max ( ) / eigvals ) return pd . Series ( cond_idx , df . columns , name = 'Condition index' )
Returns a pandas Series with condition indices of the df columns .
49,796
def mahalanobis_distances ( df , axis = 0 ) : df = df . transpose ( ) if axis == 1 else df means = df . mean ( ) try : inv_cov = np . linalg . inv ( df . cov ( ) ) except LinAlgError : return pd . Series ( [ np . NAN ] * len ( df . index ) , df . index , name = 'Mahalanobis' ) dists = [ ] for i , sample in df . iterrow...
Returns a pandas Series with Mahalanobis distances for each sample on the axis .
49,797
def summary ( self , stdout = True , plot = False ) : if stdout : print ( 'Collinearity summary:' ) print ( pd . concat ( [ self . results [ 'Eigenvalues' ] , self . results [ 'ConditionIndices' ] , self . results [ 'VIFs' ] , self . results [ 'CorrelationMatrix' ] ] , axis = 1 ) ) print ( 'Outlier summary:' ) print ( ...
Displays diagnostics to the user
49,798
def add_nodes ( self , nodes , parent = None , mode = 'horizontal' ) : for n in nodes : node_args = self . _parse_node_args ( n ) if mode == 'horizontal' : self . add_node ( parent = parent , ** node_args ) elif mode == 'vertical' : parent = self . add_node ( parent = parent , return_node = True , ** node_args ) else :...
Adds one or more nodes to the current graph .
49,799
def add_node ( self , transformer , name = None , children = None , parent = None , parameters = { } , return_node = False ) : node = Node ( transformer , name , ** parameters ) self . nodes [ node . id ] = node if parent is None : self . roots . append ( node ) else : parent = self . nodes [ parent . id ] parent . add...
Adds a node to the current graph .