Convert string to kafka broker_id.
777332
def convert_to_broker_id(string):
    """"""
    error_msg = 'Positive integer or -1 required, {string} given.'.format(string=string)
    try:
        value = int(string)
    except ValueError:
        raise argparse.ArgumentTypeError(error_msg)
    if value <= 0 and value != -1:
        raise argparse.ArgumentTypeError(error_msg)
    return value
494531
def to_kaf(self):
        
        if self.type == 'NAF':
            ##convert all the properties
            for node in self.node.findall('properties/property'):
                node.set('pid',node.get('id'))
                del node.attrib['id']
745728
def from_payload(self, payload):
        """"""
        self.node_id = payload[0]
        self.name = bytes_to_string(payload[1:65])
343820
def to_s
      string =  "Execution ID:      #{@id}\n"
      string << "Name:              #{@name}\n"
      string << "Workflow ID:       #{@workflow_id}\n"
      string << "State:             #{@state}\n"
      string << "Start Date:        #{Time.at(@start_date / 1000)}\n"
      string << "End Date:          #{end_date.nil? ? '' : Time.at(@end_date / 1000)}\n"
      string << "Started By:        #{@started_by}\n"
      string << "Content Exception: #{@content_exception}\n" unless @content_exception.nil?
      string << "\nInput Parameters:\n"
      @input_parameters.each_value { |wf_param| string << " #{wf_param}" if wf_param.set? } if @input_parameters.size > 0
      string << "\nOutput Parameters:" << "\n"
      @output_parameters.each_value { |wf_param| string << " #{wf_param}" } if @output_parameters.size > 0
      string
    end
1014709
private static String getServerIdString(String id) {

        if (id.contains(CmsADEManager.CLIENT_ID_SEPERATOR)) {
            id = id.substring(0, id.indexOf(CmsADEManager.CLIENT_ID_SEPERATOR));
        }
        return id;
    }
192097
def handle_to_uuid(handle, services):
    """"""

    for service in services.values():
        for char_uuid, char_def in service['characteristics'].items():
            if char_def['handle'] == handle:
                return char_uuid

    raise ValueError("Handle not found in GATT table")
351529
def _parse_signature(stream):
    """"""
    p = {'type': 'signature'}

    to_hash = io.BytesIO()
    with stream.capture(to_hash):
        p['version'] = stream.readfmt('B')
        p['sig_type'] = stream.readfmt('B')
        p['pubkey_alg'] = stream.readfmt('B')
        p['hash_alg'] = stream.readfmt('B')
        p['hashed_subpackets'] = parse_subpackets(stream)

    # https://tools.ietf.org/html/rfc4880#section-5.2.4
    tail_to_hash = b'\x04\xff' + struct.pack('>L', to_hash.tell())

    p['_to_hash'] = to_hash.getvalue() + tail_to_hash

    p['unhashed_subpackets'] = parse_subpackets(stream)
    embedded = list(_parse_embedded_signatures(p['unhashed_subpackets']))
    if embedded:
        log.debug('embedded sigs: %s', embedded)
        p['embedded'] = embedded

    p['hash_prefix'] = stream.readfmt('2s')
    if p['pubkey_alg'] in ECDSA_ALGO_IDS:
        p['sig'] = (parse_mpi(stream), parse_mpi(stream))
    elif p['pubkey_alg'] in RSA_ALGO_IDS:  # RSA
        p['sig'] = (parse_mpi(stream),)
    elif p['pubkey_alg'] == DSA_ALGO_ID:
        p['sig'] = (parse_mpi(stream), parse_mpi(stream))
    else:
        log.error('unsupported public key algo: %d', p['pubkey_alg'])

    assert not stream.read()
    return p
414423
def from_hostname(cls, hostname):
        """"""
        result = cls.list({'hostname': str(hostname)})
        if result:
            return result[0]['id']
361878
static String parseRoleIdentifier(final String trackingId)
	{
		if (StringUtil.isNullOrWhiteSpace(trackingId) || !trackingId.contains(TRACKING_ID_TOKEN_SEPARATOR))
		{
			return null;
		}

		return trackingId.substring(trackingId.indexOf(TRACKING_ID_TOKEN_SEPARATOR));
	}
497777
def _get_conn(self, host, port, afi):
        """"""
        host_key = (host, port)
        if host_key not in self._conns:
            self._conns[host_key] = BrokerConnection(
                host, port, afi,
                request_timeout_ms=self.timeout * 1000,
                client_id=self.client_id
            )

        conn = self._conns[host_key]
        if not conn.connect_blocking(self.timeout):
            conn.close()
            raise KafkaConnectionError("%s:%s (%s)" % (host, port, afi))
        return conn
965944
@Override
    protected String consumeIdentifier( DdlTokenStream tokens ) throws ParsingException {
        Position startPosition = tokens.nextPosition();
        String id = super.consumeIdentifier(tokens);
        if (!tokens.hasNext()) return id;
        Position nextPosition = tokens.nextPosition();

        while (((nextPosition.getIndexInContent() - startPosition.getIndexInContent() - id.length()) == 0)) {
            // allowed symbols in an identifier: underscore, dollar sign, pound sign, at sign
            if (tokens.matches(DdlTokenizer.SYMBOL)) {
                if (tokens.matches('$') || tokens.matches('#') || tokens.matches('@')) {
                    id += tokens.consume(); // consume symbol
                } else {
                    break; // not a valid ID symbol
                }
            } else {
                id += tokens.consume(); // consume text
            }

            nextPosition = tokens.nextPosition();
        }

        return id;
    }
462174
public static String threadIdToString(int threadId) {
        StringBuffer buffer = new StringBuffer(8);

        // pad the HexString ThreadId so that it is always 8 characters long.
        for (int shift = 7; shift >= 0; shift--) {
            buffer.append(hexChars[(threadId >> (shift << 2)) & 0xF]);
        }

        return buffer.toString();
    }
703032
def container_instance_from_string(id):
    """"""
    try:
        service, instance = id.rsplit('_', 1)
        instance = int(instance)
    except (TypeError, ValueError):
        raise context.ValueError("Invalid container id %r" % id)
    return _proto.ContainerInstance(service_name=service, instance=instance)
201790
def id_to_name(id):
    
    name = pdgid_names.get(id)
    if not name:
        name = repr(id)
    return name
407710
def handle(self, key, value):
        '''
        
        '''
        # the master dict to return
        master = {}
        master['uuid'] = value
        master['total_pending'] = 0
        master['server_time'] = int(self.get_current_time())

        # break down key
        elements = key.split(":")
        dict = {}
        dict['spiderid'] = elements[1]
        dict['appid'] = elements[2]

        # log we received the info message
        extras = self.get_log_dict('info', dict['appid'],
                                   dict['spiderid'], master['uuid'])

        if len(elements) == 4:
            dict['crawlid'] = elements[3]
            extras = self.get_log_dict('info', dict['appid'],
                                       dict['spiderid'], master['uuid'],
                                       elements[3])
        self.logger.info('Received info request', extra=extras)

        # generate the information requested
        if 'crawlid' in dict:
            master = self._build_crawlid_info(master, dict)
        else:
            master = self._build_appid_info(master, dict)

        if self._send_to_kafka(master):
            extras['success'] = True
            self.logger.info('Sent info to kafka', extra=extras)
        else:
            extras['success'] = False
            self.logger.error('Failed to send info to kafka',
                              extra=extras)
100532
def convert_catalog_id_to_object_id_string(catalog_id):
    

    if not isinstance(catalog_id, Id):
        raise TypeError('input needs to be an Id')
    seed_str = catalog_id.get_identifier() + catalog_id.get_authority() + '000000000000'
    try:
        seed_str = str.encode(seed_str[:12])
    except TypeError:
        # sometimes unicode is returned, in which case Python 2 can't handle it
        seed_str = seed_str[:12]
    seed_str = binascii.hexlify(seed_str)
    try:
        # python 3
        seed_str = str(seed_str, 'utf8')
    except TypeError:
        # python 2
        seed_str = str(seed_str)
    return seed_str
1339136
private static String CertificateIDToString(CertificateID certificateID)
  {
    return String.format("CertID. NameHash: %s, KeyHash: %s, Serial Number: %s",
                         byteToHexString(certificateID.getIssuerNameHash()),
                         byteToHexString(certificateID.getIssuerKeyHash()),
                         MessageFormat.format("{0,number,#}",
                                              certificateID.getSerialNumber()));

  }