idx int64 0 24.9k | question stringlengths 68 4.14k | target stringlengths 9 749 |
|---|---|---|
11,600 | def simulated_signature_script ( strict : true ) if public_key_hash_script? return Script . new << Script . simulated_signature ( hashtype : SIGHASH_ALL ) << Script . simulated_uncompressed_pubkey elsif public_key_script? return Script . new << Script . simulated_signature ( hashtype : SIGHASH_ALL ) elsif script_hash_s... | Returns a dummy script matching this script on the input with the same size as an intended signature script . Only a few standard script types are supported . Set strict to false to allow imprecise guess for P2SH script . Returns nil if could not determine a matching script . |
11,601 | def append_pushdata ( data , opcode : nil ) raise ArgumentError , "No data provided" if ! data encoded_pushdata = self . class . encode_pushdata ( data , opcode : opcode ) if ! encoded_pushdata raise ArgumentError , "Cannot encode pushdata with opcode #{opcode}" end @chunks << ScriptChunk . new ( encoded_pushdata ) ret... | Appends a pushdata opcode with the most compact encoding . Optional opcode may be equal to OP_PUSHDATA1 OP_PUSHDATA2 or OP_PUSHDATA4 . ArgumentError is raised if opcode does not represent a given data length . |
11,602 | def delete_opcode ( opcode ) @chunks = @chunks . inject ( [ ] ) do | list , chunk | list << chunk if chunk . opcode != opcode list end return self end | Removes all occurences of opcode . Typically it s OP_CODESEPARATOR . |
11,603 | def delete_pushdata ( pushdata ) @chunks = @chunks . inject ( [ ] ) do | list , chunk | list << chunk if chunk . pushdata != pushdata list end return self end | Removes all occurences of a given pushdata . |
11,604 | def find_and_delete ( subscript ) subscript . is_a? ( Script ) or raise ArgumentError , "Argument must be an instance of BTC::Script" subscriptsize = subscript . chunks . size buf = [ ] i = 0 result = Script . new chunks . each do | chunk | if chunk == subscript . chunks [ i ] buf << chunk i += 1 if i == subscriptsize ... | Removes chunks matching subscript byte - for - byte and returns a new script instance with subscript removed . So if pushdata items are encoded differently they won t match . Consensus - critical code . |
11,605 | def parse_assets_data ( data , offset : 0 ) v , len = WireFormat . read_uint8 ( data : data , offset : offset ) raise ArgumentError , "Invalid data: verified flag" if ! v asset_hash , len = WireFormat . read_string ( data : data , offset : len ) raise ArgumentError , "Invalid data: asset hash" if ! asset_hash value , l... | Returns total length read |
11,606 | def base58_from_data ( data ) raise ArgumentError , "Data is missing" if ! data leading_zeroes = 0 int = 0 base = 1 data . bytes . reverse_each do | byte | if byte == 0 leading_zeroes += 1 else leading_zeroes = 0 int += base * byte end base *= 256 end return ( "1" * leading_zeroes ) + base58_from_int ( int ) end | Converts binary string into its Base58 representation . If string is empty returns an empty string . If string is nil raises ArgumentError |
11,607 | def data_from_base58 ( string ) raise ArgumentError , "String is missing" if ! string int = int_from_base58 ( string ) bytes = [ ] while int > 0 remainder = int % 256 int = int / 256 bytes . unshift ( remainder ) end data = BTC :: Data . data_from_bytes ( bytes ) byte_for_1 = "1" . bytes . first BTC :: Data . ensure_as... | Converts binary string into its Base58 representation . If string is empty returns an empty string . If string is nil raises ArgumentError . |
11,608 | def compute_fee_for_transaction ( tx , fee_rate ) return fee if fee simulated_tx = tx . dup simulated_tx . inputs . each do | txin | txout_script = txin . transaction_output . script txin . signature_script = txout_script . simulated_signature_script ( strict : false ) || txout_script end return simulated_tx . compute_... | Helper to compute total fee for a given transaction . Simulates signatures to estimate final size . |
11,609 | def string_from_number ( number ) if @style == :btc number = number . to_i return "#{number / BTC::COIN}.#{'%08d' % [number % BTC::COIN]}" . gsub ( / / , "" ) . gsub ( / \. / , ".0" ) elsif @style == :btc_long number = number . to_i return "#{number / BTC::COIN}.#{'%08d' % [number % BTC::COIN]}" else raise "Not impleme... | Returns formatted string for an amount in satoshis . |
11,610 | def number_from_string ( string ) bd = BigDecimal . new ( string ) if @style == :btc || @style == :btc_long return ( bd * BTC :: COIN ) . to_i else raise "Not Implemented" end end | Returns amount of satoshis parsed from a formatted string according to style attribute . |
11,611 | def partial_verify_asset_transaction ( asset_transaction ) raise ArgumentError , "Asset Transaction is missing" if ! asset_transaction cache_transactions do if ! verify_issues ( asset_transaction ) return nil end if asset_transaction . transfer_outputs . size == 0 return [ ] end prev_unverified_atxs_by_hash = { } asset... | Returns a list of asset transactions remaining to verify . Returns an empty array if verification succeeded and there is nothing more to verify . Returns nil if verification failed . |
11,612 | def verify_issues ( asset_transaction ) previous_txout = nil asset_transaction . outputs . each do | aout | if ! aout . verified? if aout . value && aout . value > 0 if aout . issue? previous_txout ||= transaction_output_for_input ( asset_transaction . inputs [ 0 ] . transaction_input ) if ! previous_txout Diagnostics ... | Attempts to verify issues . Fetches parent transactions to determine AssetID . Returns true if verified all issue outputs . Returns false if previous tx defining AssetID is not found . |
11,613 | def target_from_bits ( bits ) exponent = ( ( bits >> 24 ) & 0xff ) mantissa = bits & 0x7fffff mantissa *= - 1 if ( bits & 0x800000 ) > 0 ( mantissa * ( 256 ** ( exponent - 3 ) ) ) . to_i end | Converts 32 - bit compact representation to a 256 - bit integer . int32 - > bigint |
11,614 | def hash_from_target ( target ) bytes = [ ] while target > 0 bytes << ( target % 256 ) target /= 256 end BTC :: Data . data_from_bytes ( bytes ) . ljust ( 32 , "\x00" . b ) end | Converts target integer to a binary 32 - byte hash . bigint - > hash256 |
11,615 | def print_addresses ( range : 0 .. 100 , network : BTC :: Network . mainnet , account : 0 ) kc = keychain . bip44_keychain ( network : network ) . bip44_account_keychain ( account ) puts "Addresses for account #{account} on #{network.name}" puts "Account xpub: #{kc.xpub}" puts "Account external xpub: #{kc.bip4... | For manual testing |
11,616 | def opcode_for_small_integer ( small_int ) raise ArgumentError , "small_int must not be nil" if ! small_int return OP_0 if small_int == 0 return OP_1NEGATE if small_int == - 1 if small_int >= 1 && small_int <= 16 return OP_1 + ( small_int - 1 ) end return OP_INVALIDOPCODE end | Returns OP_1NEGATE OP_0 .. OP_16 for ints from - 1 to 16 . Returns OP_INVALIDOPCODE for other ints . |
11,617 | def record ( & block ) recording_groups << Array . new last_group = nil begin yield ensure last_group = recording_groups . pop end last_group end | Begins recording of series of messages and returns all recorded events . If there is no record block on any level messages are not accumulated but only last_message is updated . Returns a list of all recorded messages . |
11,618 | def add_message ( message , info : nil ) self . last_message = message self . last_info = info self . last_item = Item . new ( message , info ) recording_groups . each do | group | group << Item . new ( message , info ) end @uniq_trace_streams . each do | stream | stream . puts message end return self end | Adds a diagnostic message . Use it to record warnings and reasons for errors . Do not use when the input is nil - code that have produced that nil could have already recorded a specific message for that . |
11,619 | def to_wif ( network : nil , public_key_compressed : nil ) BTC :: WIF . new ( private_key : self , network : network , public_key_compressed : public_key_compressed ) . to_s end | Converts binary string as a private key to a WIF Base58 format . |
11,620 | def restore ( shares ) prime = @order shares = shares . dup . uniq raise "No shares provided" if shares . size == 0 points = shares . map { | s | point_from_string ( s ) } ms = points . map { | p | p [ 0 ] } . uniq xs = points . map { | p | p [ 1 ] } . uniq raise "Shares do not use the same M value" if ms . size > 1 m ... | Transforms M 17 - byte binary strings into original secret 16 - byte binary string . Each share string must be well - formed . |
11,621 | def issue_asset ( source_script : nil , source_output : nil , amount : nil , script : nil , address : nil ) raise ArgumentError , "Either `source_script` or `source_output` must be specified" if ! source_script && ! source_output raise ArgumentError , "Both `source_script` and `source_output` cannot be specified" if so... | Adds an issuance of some assets . If script is specified it is used to create an intermediate base transaction . If output is specified it must be a valid spendable output with transaction_id and index . It can be regular TransactionOutput or verified AssetTransactionOutput . amount must be > 0 - number of units to be ... |
11,622 | def send_bitcoin ( output : nil , amount : nil , script : nil , address : nil ) if ! output raise ArgumentError , "Either `script` or `address` must be specified" if ! script && ! address raise ArgumentError , "Amount must be specified (>= 0)" if ( ! amount || amount < 0 ) script ||= address . public_address . script i... | Adds a normal payment output . Typically used for transfer |
11,623 | def handle_opcode ( interpreter : nil , opcode : nil ) return false if opcode != OP_CHECKLOCKTIMEVERIFY if interpreter . stack . size < 1 return interpreter . set_error ( SCRIPT_ERR_INVALID_STACK_OPERATION ) end locktime = interpreter . cast_to_number ( interpreter . stack . last , max_size : @locktime_max_size ) if lo... | Returns false if failed to execute the opcode . |
11,624 | def init_with_stream ( stream ) if stream . eof? raise ArgumentError , "Can't parse transaction input from stream because it is already closed." end if ! ( @previous_hash = stream . read ( 32 ) ) || @previous_hash . bytesize != 32 raise ArgumentError , "Failed to read 32-byte previous_hash from stream." end if ! ( @pre... | Initializes transaction input with its attributes . Every attribute has a valid default value . |
11,625 | def init_with_components ( version : CURRENT_VERSION , inputs : [ ] , outputs : [ ] , lock_time : 0 ) @version = version || CURRENT_VERSION @inputs = inputs || [ ] @outputs = outputs || [ ] @lock_time = lock_time || 0 @inputs . each_with_index do | txin , i | txin . transaction = self txin . index = i end @outputs . ea... | Initializes transaction with its attributes . Every attribute has a valid default value . |
11,626 | def add_input ( txin ) raise ArgumentError , "Input is missing" if ! txin if ! ( txin . transaction == nil || txin . transaction == self ) raise ArgumentError , "Can't add an input to a transaction when it references another transaction" end txin . transaction = self txin . index = @inputs . size @inputs << txin self e... | Adds another input to the transaction . |
11,627 | def data_from_hex ( hex_string ) raise ArgumentError , "Hex string is missing" if ! hex_string hex_string = hex_string . strip data = [ hex_string ] . pack ( HEX_PACK_CODE ) if hex_from_data ( data ) != hex_string . downcase raise FormatError , "Hex string is invalid: #{hex_string.inspect}" end return data end | Converts hexadecimal string to a binary data string . |
11,628 | def regenerate_keypair ( private_key , public_key_compressed : false ) autorelease do | pool | eckey = pool . new_ec_key priv_bn = pool . new_bn ( private_key ) pub_key = pool . new_ec_point EC_POINT_mul ( self . group , pub_key , priv_bn , nil , nil , pool . bn_ctx ) EC_KEY_set_private_key ( eckey , priv_bn ) EC_KEY_s... | Returns a pair of private key public key |
11,629 | def private_key_from_der_format ( der_key ) raise ArgumentError , "Missing DER private key" if ! der_key prepare_if_needed buf = FFI :: MemoryPointer . from_string ( der_key ) ec_key = d2i_ECPrivateKey ( nil , pointer_to_pointer ( buf ) , buf . size - 1 ) if ec_key . null? raise BTCError , "OpenSSL failed to create EC_... | extract private key from uncompressed DER format |
11,630 | def data_from_bn ( bn , min_length : nil , required_length : nil ) raise ArgumentError , "Missing big number" if ! bn length = BN_num_bytes ( bn ) buf = FFI :: MemoryPointer . from_string ( "\x00" * length ) BN_bn2bin ( bn , buf ) s = buf . read_string ( length ) s = s . rjust ( min_length , "\x00" ) if min_length if r... | Returns data from bignum |
11,631 | def encode_varint ( i ) raise ArgumentError , "int must be present" if ! i raise ArgumentError , "int must be non-negative" if i < 0 buf = if i < 0xfd [ i ] . pack ( "C" ) elsif i <= 0xffff [ 0xfd , i ] . pack ( "Cv" ) elsif i <= 0xffffffff [ 0xfe , i ] . pack ( "CV" ) elsif i <= 0xffffffffffffffff [ 0xff , i ] . pack ... | read_varint Encodes integer and returns its binary varint representation . |
11,632 | def write_varint ( i , data : nil , stream : nil ) buf = encode_varint ( i ) data << buf if data stream . write ( buf ) if stream buf end | Encodes integer and returns its binary varint representation . If data is given appends to a data . If stream is given writes to a stream . |
11,633 | def encode_string ( string ) raise ArgumentError , "String must be present" if ! string encode_varint ( string . bytesize ) + BTC :: Data . ensure_binary_encoding ( string ) end | Returns the binary representation of the var - length string . |
11,634 | def write_string ( string , data : nil , stream : nil ) raise ArgumentError , "String must be present" if ! string intbuf = write_varint ( string . bytesize , data : data , stream : stream ) stringbuf = BTC :: Data . ensure_binary_encoding ( string ) data << stringbuf if data stream . write ( stringbuf ) if stream intb... | Writes variable - length string to a data buffer or IO stream . If data is given appends to a data . If stream is given writes to a stream . Returns the binary representation of the var - length string . |
11,635 | def read_array ( data : nil , stream : nil , offset : 0 ) count , len = read_varint ( data : data , stream : stream , offset : offset ) return [ nil , len ] if ! count ( 0 ... count ) . map do | i | yield end end | Reads varint length prefix then calls the block appropriate number of times to read the items . Returns an array of items . |
11,636 | def encode_uleb128 ( value ) raise ArgumentError , "Signed integers are not supported" if value < 0 return "\x00" if value == 0 bytes = [ ] while value != 0 byte = value & 0b01111111 value >>= 7 if value != 0 byte |= 0b10000000 end bytes << byte end return BTC :: Data . data_from_bytes ( bytes ) end | Encodes an unsigned integer using LEB128 . |
11,637 | def write_uleb128 ( value , data : nil , stream : nil ) raise ArgumentError , "Integer must be present" if ! value buf = encode_uleb128 ( value ) data << buf if data stream . write ( buf ) if stream buf end | Writes an unsigned integer encoded in LEB128 to a data buffer or a stream . Returns LEB128 - encoded binary string . |
11,638 | def preferences ( group = nil ) preferences = preferences_group ( group ) unless preferences_group_loaded? ( group ) group_id , group_type = Preference . split_group ( group ) find_preferences ( :group_id => group_id , :group_type => group_type ) . each do | preference | preferences [ preference . name ] = preference .... | Finds all preferences including defaults for the current record . If looking up custom group preferences then this will include all default preferences within that particular group as well . |
11,639 | def preferred? ( name , group = nil ) name = name . to_s assert_valid_preference ( name ) value = preferred ( name , group ) preference_definitions [ name ] . query ( value ) end | Queries whether or not a value is present for the given preference . This is dependent on how the value is type - casted . |
11,640 | def preferred ( name , group = nil ) name = name . to_s assert_valid_preference ( name ) if preferences_group ( group ) . include? ( name ) value = preferences_group ( group ) [ name ] else group_id , group_type = Preference . split_group ( group ) preference = find_preferences ( :name => name , :group_id => group_id ,... | Gets the actual value stored for the given preference or the default value if nothing is present . |
11,641 | def preference_changes ( group = nil ) preferences_changed ( group ) . inject ( { } ) do | changes , preference | changes [ preference ] = preference_change ( preference , group ) changes end end | A map of the preferences that have changed in the current object . |
11,642 | def preference_was ( name , group ) preference_changed? ( name , group ) ? preferences_changed_group ( group ) [ name ] : preferred ( name , group ) end | Gets the last saved value for the given preference |
11,643 | def reset_preference! ( name , group ) write_preference ( name , preferences_changed_group ( group ) [ name ] , group ) if preference_changed? ( name , group ) end | Reverts any unsaved changes to the given preference |
11,644 | def preference_value_changed? ( name , old , value ) definition = preference_definitions [ name ] if definition . type == :integer && ( old . nil? || old == 0 ) value = nil if value . blank? else value = definition . type_cast ( value ) end old != value end | Determines whether the old value is different from the new value for the given preference . This will use the typecasted value to determine equality . |
11,645 | def find_preferences ( attributes ) if stored_preferences . loaded? stored_preferences . select do | preference | attributes . all? { | attribute , value | preference [ attribute ] == value } end else stored_preferences . find ( :all , :conditions => attributes ) end end | Finds all stored preferences with the given attributes . This will do a smart lookup by looking at the in - memory collection if it was eager - loaded . |
11,646 | def [] ( intfname ) introspect unless introspected ifc = @interfaces [ intfname ] raise DBus :: Error , "no such interface `#{intfname}' on object `#{@path}'" unless ifc ifc end | Retrieves an interface of the proxy object |
11,647 | def define_method_from_descriptor ( m ) m . params . each do | fpar | par = fpar . type Type :: Parser . new ( par ) . parse end singleton_class . class_eval do define_method m . name do | * args , & reply_handler | if m . params . size != args . size raise ArgumentError , "wrong number of arguments (#{args.size} for #... | Defines a method on the interface from the Method descriptor _m_ . |
11,648 | def define ( m ) if m . is_a? ( Method ) define_method_from_descriptor ( m ) elsif m . is_a? ( Signal ) define_signal_from_descriptor ( m ) end end | Defines a signal or method based on the descriptor _m_ . |
11,649 | def define_method ( methodname , prototype ) m = Method . new ( methodname ) m . from_prototype ( prototype ) define ( m ) end | Defines a proxied method on the interface . |
11,650 | def [] ( propname ) ret = object [ PROPERTY_INTERFACE ] . Get ( name , propname ) if @object . api . proxy_method_returns_array ret [ 0 ] else ret end end | Read a property . |
11,651 | def all_properties ret = object [ PROPERTY_INTERFACE ] . GetAll ( name ) if @object . api . proxy_method_returns_array ret [ 0 ] else ret end end | Read all properties at once as a hash . |
11,652 | def connect addresses = @address . split ";" worked = addresses . find do | a | transport , keyvaluestring = a . split ":" kv_list = keyvaluestring . split "," kv_hash = { } kv_list . each do | kv | key , escaped_value = kv . split "=" value = escaped_value . gsub ( / / ) { | _m | [ Regexp . last_match ( 1 ) ] . pack "... | Connect to the bus and initialize the connection . |
11,653 | def connect_to_tcp ( params ) if params . key? ( "host" ) && params . key? ( "port" ) begin @socket = TCPSocket . new ( params [ "host" ] , params [ "port" ] . to_i ) @socket . fcntl ( Fcntl :: F_SETFD , Fcntl :: FD_CLOEXEC ) init_connection @is_tcp = true rescue Exception => e puts "Oops:" , e puts "Error: Could not e... | Connect to a bus over tcp and initialize the connection . |
11,654 | def connect_to_unix ( params ) @socket = Socket . new ( Socket :: Constants :: PF_UNIX , Socket :: Constants :: SOCK_STREAM , 0 ) @socket . fcntl ( Fcntl :: F_SETFD , Fcntl :: FD_CLOEXEC ) if ! params [ "abstract" ] . nil? sockaddr = if HOST_END == LIL_END "\1\0\0#{params["abstract"]}" else "\0\1\0#{params["abstract"]}... | Connect to an abstract unix bus and initialize the connection . |
11,655 | def add_param ( type , val ) type = type . chr if type . is_a? ( Integer ) @signature += type . to_s @params << [ type , val ] end | Add a parameter _val_ of type _type_ to the message . |
11,656 | def marshall if @path == "/org/freedesktop/DBus/Local" raise InvalidDestinationName end params = PacketMarshaller . new @params . each do | param | params . append ( param [ 0 ] , param [ 1 ] ) end @body_length = params . packet . bytesize marshaller = PacketMarshaller . new marshaller . append ( Type :: BYTE , HOST_EN... | Marshall the message with its current set parameters and return it in a packet form . |
11,657 | def unmarshall_buffer ( buf ) buf = buf . dup endianness = if buf [ 0 ] == "l" LIL_END else BIG_END end pu = PacketUnmarshaller . new ( buf , endianness ) mdata = pu . unmarshall ( MESSAGE_SIGNATURE ) _ , @message_type , @flags , @protocol , @body_length , @serial , headers = mdata headers . each do | struct | case str... | Unmarshall a packet contained in the buffer _buf_ and set the parameters of the message object according the data found in the buffer . |
11,658 | def annotate_exception ( ex ) new_ex = ex . exception ( "#{ex}; caused by #{self}" ) new_ex . set_backtrace ( ex . backtrace ) new_ex end | Make a new exception from ex mark it as being caused by this message |
11,659 | def unmarshall ( signature , len = nil ) if ! len . nil? if @buffy . bytesize < @idx + len raise IncompleteBufferException end end sigtree = Type :: Parser . new ( signature ) . parse ret = [ ] sigtree . each do | elem | ret << do_parse ( elem ) end ret end | Create a new unmarshaller for the given data _buffer_ and _endianness_ . Unmarshall the buffer for a given _signature_ and length _len_ . Return an array of unmarshalled objects |
11,660 | def align ( a ) case a when 1 nil when 2 , 4 , 8 bits = a - 1 @idx = @idx + bits & ~ bits raise IncompleteBufferException if @idx > @buffy . bytesize else raise "Unsupported alignment #{a}" end end | Align the pointer index on a byte index of _a_ where a must be 1 2 4 or 8 . |
11,661 | def read ( nbytes ) raise IncompleteBufferException if @idx + nbytes > @buffy . bytesize ret = @buffy . slice ( @idx , nbytes ) @idx += nbytes ret end | Retrieve the next _nbytes_ number of bytes from the buffer . |
11,662 | def read_string align ( 4 ) str_sz = read ( 4 ) . unpack ( @uint32 ) [ 0 ] ret = @buffy . slice ( @idx , str_sz ) raise IncompleteBufferException if @idx + str_sz + 1 > @buffy . bytesize @idx += str_sz if @buffy [ @idx ] . ord != 0 raise InvalidPacketException , "String is not nul-terminated" end @idx += 1 ret end | Read the string length and string itself from the buffer . Return the string . |
11,663 | def read_signature str_sz = read ( 1 ) . unpack ( "C" ) [ 0 ] ret = @buffy . slice ( @idx , str_sz ) raise IncompleteBufferException if @idx + str_sz + 1 >= @buffy . bytesize @idx += str_sz if @buffy [ @idx ] . ord != 0 raise InvalidPacketException , "Type is not nul-terminated" end @idx += 1 ret end | Read the signature length and signature itself from the buffer . Return the signature . |
11,664 | def num_align ( n , a ) case a when 1 , 2 , 4 , 8 bits = a - 1 n + bits & ~ bits else raise "Unsupported alignment" end end | Create a new marshaller setting the current packet to the empty packet . Round _n_ up to the specified power of two _a_ |
11,665 | def array ( type ) align ( 4 ) sizeidx = @packet . bytesize @packet += "ABCD" align ( type . alignment ) contentidx = @packet . bytesize yield sz = @packet . bytesize - contentidx raise InvalidPacketException if sz > 67_108_864 @packet [ sizeidx ... sizeidx + 4 ] = [ sz ] . pack ( "L" ) end | Append the array type _type_ to the packet and allow for appending the child elements . |
11,666 | def object ( path , api : ApiOptions :: A0 ) node = get_node ( path , _create = true ) if node . object . nil? || node . object . api != api node . object = ProxyObject . new ( @bus , @name , path , api : api ) end node . object end | Retrieves an object at the given _path_ whose methods always return an array . |
11,667 | def get_node ( path , create = false ) n = @root path . sub ( %r{ } , "" ) . split ( "/" ) . each do | elem | if ! ( n [ elem ] ) return nil if ! create n [ elem ] = Node . new ( elem ) end n = n [ elem ] end if n . nil? DBus . logger . debug "Warning, unknown object #{path}" end n end | Get the object node corresponding to the given _path_ . if _create_ is true the the nodes in the path are created if they do not already exist . |
11,668 | def rec_introspect ( node , path ) xml = bus . introspect_data ( @name , path ) intfs , subnodes = IntrospectXMLParser . new ( xml ) . parse subnodes . each do | nodename | subnode = node [ nodename ] = Node . new ( nodename ) subpath = if path == "/" "/" + nodename else path + "/" + nodename end rec_introspect ( subno... | Perform a recursive retrospection on the given current _node_ on the given _path_ . |
11,669 | def to_xml xml = '<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN""http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd"><node>' each_pair do | k , _v | xml += "<node name=\"#{k}\" />" end if @object @object . intfs . each_pair do | _k , v | xml += %(<interface name="#{v.name}">\n)... | Create a new node with a given _name_ . Return an XML string representation of the node . It is shallow not recursing into subnodes |
11,670 | def glibize require "glib2" @channels ||= [ ] gio = GLib :: IOChannel . new ( @message_queue . socket . fileno ) @channels << gio gio . add_watch ( GLib :: IOChannel :: IN ) do | _c , _ch | dispatch_message_queue true end end | Tell a bus to register itself on the glib main loop |
11,671 | def request_service ( name ) proxy . RequestName ( name , NAME_FLAG_REPLACE_EXISTING ) do | rmsg , r | raise rmsg if rmsg . is_a? ( Error ) raise NameRequestError unless r == REQUEST_NAME_REPLY_PRIMARY_OWNER end @service = Service . new ( name , self ) @service end | Attempt to request a service _name_ . |
11,672 | def proxy if @proxy . nil? path = "/org/freedesktop/DBus" dest = "org.freedesktop.DBus" pof = DBus :: ProxyObjectFactory . new ( DBUSXMLINTRO , self , dest , path , api : ApiOptions :: A0 ) @proxy = pof . build [ "org.freedesktop.DBus" ] end @proxy end | Set up a ProxyObject for the bus itself since the bus is introspectable . |
11,673 | def add_match ( mr , & slot ) mrs = mr . to_s DBus . logger . debug "#{@signal_matchrules.size} rules, adding #{mrs.inspect}" unless @signal_matchrules . key? ( mrs ) DBus . logger . debug "Asked for a new match" proxy . AddMatch ( mrs ) end @signal_matchrules [ mrs ] = slot end | Asks bus to send us messages matching mr and execute slot when received |
11,674 | def send_hello m = Message . new ( DBus :: Message :: METHOD_CALL ) m . path = "/org/freedesktop/DBus" m . destination = "org.freedesktop.DBus" m . interface = "org.freedesktop.DBus" m . member = "Hello" send_sync ( m ) do | rmsg | @unique_name = rmsg . destination DBus . logger . debug "Got hello reply. Our unique_nam... | Send a hello messages to the bus to let it know we are here . |
11,675 | def run @buses . each_value do | b | while ( m = b . message_queue . message_from_buffer_nonblock ) b . process ( m ) end end while ! @quitting && ! @buses . empty? ready = IO . select ( @buses . keys , [ ] , [ ] , 5 ) next unless ready ready . first . each do | socket | b = @buses [ socket ] begin b . message_queue . ... | Run the main loop . This is a blocking call! |
11,676 | def authenticate Process . uid . to_s . split ( / / ) . map { | d | d . ord . to_s ( 16 ) } . join end | Performs the authentication . |
11,677 | def hex_decode ( encoded ) encoded . scan ( / / ) . map { | h | h . hex . chr } . join end | decode hex to plain |
11,678 | def authenticate if RbConfig :: CONFIG [ "target_os" ] =~ / / @socket . sendmsg ( 0 . chr , 0 , nil , [ :SOCKET , :SCM_CREDS , "" ] ) else @socket . write ( 0 . chr ) end next_authenticator @state = :Starting while @state != :Authenticated r = next_state return r if ! r end true end | Create a new authentication client . Start the authentication process . |
11,679 | def next_authenticator raise AuthenticationFailed if @auth_list . empty? @authenticator = @auth_list . shift . new auth_msg = [ "AUTH" , @authenticator . name , @authenticator . authenticate ] DBus . logger . debug "auth_msg: #{auth_msg.inspect}" send ( auth_msg ) rescue AuthenticationFailed @socket . close raise end | Try authentication using the next authenticator . |
11,680 | def validate_name ( name ) raise InvalidIntrospectionData if name . bytesize > 255 raise InvalidIntrospectionData if name =~ / \. / || name =~ / \. / raise InvalidIntrospectionData if name =~ / \. \. / raise InvalidIntrospectionData if name !~ / \. / name . split ( "." ) . each do | element | raise InvalidIntrospection... | Creates a new interface with a given _name_ . Validates a service _name_ . |
11,681 | def define ( m ) if m . is_a? ( Method ) @methods [ m . name . to_sym ] = m elsif m . is_a? ( Signal ) @signals [ m . name . to_sym ] = m end end | Helper method for defining a method _m_ . |
11,682 | def define_method ( id , prototype ) m = Method . new ( id ) m . from_prototype ( prototype ) define ( m ) end | Defines a method with name _id_ and a given _prototype_ in the interface . |
11,683 | def from_prototype ( prototype ) prototype . split ( / / ) . each do | arg | arg = arg . split ( " " ) raise InvalidClassDefinition if arg . size != 2 dir , arg = arg if arg =~ / / arg = arg . split ( ":" ) name , sig = arg else sig = arg end case dir when "in" add_fparam ( name , sig ) when "out" add_return ( name , s... | Add parameter types by parsing the given _prototype_ . |
11,684 | def to_xml xml = %(<method name="#{@name}">\n) @params . each do | param | name = param . name ? %(name="#{param.name}" ) : "" xml += %(<arg #{name}direction="in" type="#{param.type}"/>\n) end @rets . each do | param | name = param . name ? %(name="#{param.name}" ) : "" xml += %(<arg #{name}direction="out" type="#{para... | Return an XML string representation of the method interface elment . |
11,685 | def from_prototype ( prototype ) prototype . split ( / / ) . each do | arg | if arg =~ / / arg = arg . split ( ":" ) name , sig = arg else sig = arg end add_fparam ( name , sig ) end self end | Add parameter types based on the given _prototype_ . |
11,686 | def to_xml xml = %(<signal name="#{@name}">\n) @params . each do | param | name = param . name ? %(name="#{param.name}" ) : "" xml += %(<arg #{name}type="#{param.type}"/>\n) end xml += %(</signal>\n) xml end | Return an XML string representation of the signal interface elment . |
11,687 | def from_s ( str ) str . split ( "," ) . each do | eq | next unless eq =~ / / name = Regexp . last_match ( 1 ) val = Regexp . last_match ( 2 ) raise MatchRuleException , name unless FILTERS . member? ( name . to_sym ) method ( name + "=" ) . call ( val ) end self end | Parses a match rule string _s_ and sets the filters on the object . |
11,688 | def from_signal ( intf , signal ) signal = signal . name unless signal . is_a? ( String ) self . type = "signal" self . interface = intf . name self . member = signal self . path = intf . object . path self end | Sets the match rule to filter for the given _signal_ and the given interface _intf_ . |
11,689 | def match ( msg ) if @type if { Message :: SIGNAL => "signal" , Message :: METHOD_CALL => "method_call" , Message :: METHOD_RETURN => "method_return" , Message :: ERROR => "error" } [ msg . message_type ] != @type return false end end return false if @interface && @interface != msg . interface return false if @member &... | Determines whether a message _msg_ matches the match rule . |
11,690 | def button ( name , locator ) define_method ( name ) do ScreenObject :: AppElements :: Button . new ( locator ) . tap end define_method ( "#{name}?" ) do ScreenObject :: AppElements :: Button . new ( locator ) . exists? end define_method ( "#{name}_enabled?" ) do ScreenObject :: AppElements :: Button . new ( locator ) ... | Button class generates all the methods related to different operations that can be performed on the button . |
11,691 | def checkbox ( name , locator ) define_method ( "check_#{name}" ) do ScreenObject :: AppElements :: CheckBox . new ( locator ) . check end define_method ( "uncheck_#{name}" ) do ScreenObject :: AppElements :: CheckBox . new ( locator ) . uncheck end define_method ( "#{name}?" ) do ScreenObject :: AppElements :: CheckBo... | end of button class . Checkbox class generates all the methods related to different operations that can be performed on the check box on the screen . |
11,692 | def text ( name , locator ) define_method ( name ) do ScreenObject :: AppElements :: Text . new ( locator ) . tap end define_method ( "#{name}?" ) do ScreenObject :: AppElements :: Text . new ( locator ) . exists? end define_method ( "#{name}" ) do ScreenObject :: AppElements :: Text . new ( locator ) . click end defin... | Text class generates all the methods related to different operations that can be performed on the text object on the screen . |
11,693 | def text_field ( name , locator ) define_method ( "#{name}=" ) do | text | ScreenObject :: AppElements :: TextField . new ( locator ) . text = ( text ) end define_method ( "#{name}" ) do ScreenObject :: AppElements :: TextField . new ( locator ) . text end define_method ( "clear_#{name}" ) do ScreenObject :: AppElement... | text_field class generates all the methods related to different operations that can be performed on the text_field object on the screen . |
11,694 | def image ( name , locator ) define_method ( "#{name}?" ) do ScreenObject :: AppElements :: Image . new ( locator ) . exists? end define_method ( "#{name}" ) do ScreenObject :: AppElements :: Image . new ( locator ) . click end end | Image class generates all the methods related to different operations that can be performed on the image object on the screen . |
11,695 | def table ( name , locator ) define_method ( "#{name}_cell_count" ) do ScreenObject :: AppElements :: Table . new ( locator ) . cell_count end end | table class generates all the methods related to different operations that can be performed on the table object on the screen . |
11,696 | def __convert_value ( value ) case when value . kind_of? ( Hash ) Bag . new ( value , @__config ) when value . kind_of? ( Array ) value . map ( & self . method ( :__convert_value ) ) else value end end | This function change value convertible to Bag into actual Bag . This trick enable deeply using all Bag functionalities and also ensures at the same time a deeply preventive copy since a new instance is created for this nested structure . |
11,697 | def pull_requests ( repo_name ) org_name = org_name_from ( repo_name ) unless @block if @org_name == org_name print '-' else puts '' print "#{org_name} -" @org_name = org_name end end issues = @client . issues ( repo_name , creator : @login , state : 'open' ) . select { | issue | issue . pull_request } issues . concat ... | Use the issues api so specify the creator |
11,698 | def precipitation ( latitudes_longitudes_times , options = { } ) return if latitudes_longitudes_times . size % 3 != 0 params = [ ] latitudes_longitudes_times . each_slice ( 3 ) do | data | params << data . join ( ',' ) end response = Typhoeus :: Request . get ( "#{DARKSKY_API_URL}/precipitation/#{@api_key}/#{params.joi... | Returns forecasts for a collection of arbitrary points . |
11,699 | def interesting ( options = { } ) response = Typhoeus :: Request . get ( "#{DARKSKY_API_URL}/interesting/#{@api_key}" , DEFAULT_OPTIONS . dup . merge ( options ) ) JSON . parse ( response . body ) if response . code == 200 end | Returns a list of interesting storms happening right now . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.