Invokes the Protocol Compiler to generate a _pb2.py from the given
  .proto file.  Does nothing if the output already exists and is newer than
  the input.
327103
def generate_proto(source, require = True):
  """"""

  if not require and not os.path.exists(source):
    return

  output = source.replace(".proto", "_pb2.py").replace("../src/", "")

  if (not os.path.exists(output) or
      (os.path.exists(source) and
       os.path.getmtime(source) > os.path.getmtime(output))):
    print("Generating %s..." % output)

    if not os.path.exists(source):
      sys.stderr.write("Can't find required file: %s\n" % source)
      sys.exit(-1)

    if protoc is None:
      sys.stderr.write(
          "protoc is not installed nor found in ../src.  Please compile it "
          "or install the binary package.\n")
      sys.exit(-1)

    protoc_command = [ protoc, "-I../src", "-I.", "--python_out=.", source ]
    if subprocess.call(protoc_command) != 0:
      sys.exit(-1)
664947
def to_protobuf(self):
        
        key = _entity_pb2.Key()
        key.partition_id.project_id = self.project

        if self.namespace:
            key.partition_id.namespace_id = self.namespace

        for item in self.path:
            element = key.path.add()
            if "kind" in item:
                element.kind = item["kind"]
            if "id" in item:
                element.id = item["id"]
            if "name" in item:
                element.name = item["name"]

        return key
501355
def generate(args=None, namespace=None, file=None):
    
    if hasattr(args, 'split'):
        args = args.split()
    args = parser.parse_args(args, namespace)
    set_logging(args)
    logging.info(str(args))
    if args.dialect in ('pg', 'pgsql', 'postgres'):
        args.dialect = 'postgresql'
    if args.dialect.startswith('dj'):
        args.dialect = 'django'
    elif args.dialect.startswith('sqla'):
        args.dialect = 'sqlalchemy'

    if args.dialect not in dialect_names:
        raise NotImplementedError('First arg must be one of: %s' % ", ".join(dialect_names))
    if args.dialect == 'sqlalchemy':
        print(sqla_head, file=file)
    for datafile in args.datafile:
        if is_sqlalchemy_url.search(datafile):
            table_names_for_insert = []
            for tbl in sqlalchemy_table_sources(datafile):
                t = generate_one(tbl, args, table_name=tbl.generator.name, file=file)
                if t.data:
                    table_names_for_insert.append(tbl.generator.name)
            if args.inserts and args.dialect == 'sqlalchemy':
                print(sqla_inserter_call(table_names_for_insert), file=file)
            if t and args.inserts:
                for seq_update in emit_db_sequence_updates(t.source.db_engine):
                    if args.dialect == 'sqlalchemy':
                        print('    conn.execute("%s")' % seq_update, file=file)
                    elif args.dialect == 'postgresql':
                        print(seq_update, file=file)
        else:
            generate_one(datafile, args, file=file)
1276015
def make_pkh_output_script(pubkey, witness=False):
    '''
    
    '''
    if witness and not riemann.network.SEGWIT:
        raise ValueError(
            'Network {} does not support witness scripts.'
            .format(riemann.get_current_network_name()))

    output_script = bytearray()

    if type(pubkey) is not bytearray and type(pubkey) is not bytes:
        raise ValueError('Unknown pubkey format. '
                         'Expected bytes. Got: {}'.format(type(pubkey)))

    pubkey_hash = utils.hash160(pubkey)

    if witness:
        output_script.extend(riemann.network.P2WPKH_PREFIX)
        output_script.extend(pubkey_hash)
    else:
        output_script.extend(b'\x76\xa9\x14')  # OP_DUP OP_HASH160 PUSH14
        output_script.extend(pubkey_hash)
        output_script.extend(b'\x88\xac')  # OP_EQUALVERIFY OP_CHECKSIG
    return output_script
182943
def attach_protocol(self, proto):
        
        if self._protocol is not None:
            raise RuntimeError("Already have a protocol.")
        # make sure we have nothing in self.unsaved
        self.save()
        self.__dict__['_protocol'] = proto

        # FIXME some of this is duplicated from ctor
        del self.__dict__['_accept_all_']
        self.__dict__['post_bootstrap'] = defer.Deferred()
        if proto.post_bootstrap:
            proto.post_bootstrap.addCallback(self.bootstrap)
        return self.__dict__['post_bootstrap']
1304372
function ProtoReader(data, zeroCopy) {
  if (!(this instanceof ProtoReader))
    return new ProtoReader(data, zeroCopy);

  BufferReader.call(this, data, zeroCopy);
}
361223
def create_instance(self, name, template, args=None, labels=None):
        
        req = rest_pb2.CreateInstanceRequest()
        req.name = name
        req.template = template
        if args:
            for k in args:
                req.templateArgs[k] = args[k]
        if labels:
            for k in labels:
                req.labels[k] = labels[k]
        url = '/instances'
        self.post_proto(url, data=req.SerializeToString())
12102
def _execute(self, ifile, process):
        
        if self._protocol_version == 2:
            result = self._read_chunk(ifile)

            if not result:
                return

            metadata, body = result
            action = getattr(metadata, 'action', None)

            if action != 'execute':
                raise RuntimeError('Expected execute action, not {}'.format(action))

        self._record_writer.write_records(self.generate())
        self.finish()
951276
def __run_blast(blast_command, input_file, *args, **kwargs):
    '''
    
    '''

    # XXX: Eventually, translate results on the fly as requested? Or
    #      just always use our parsed object?
    if 'outfmt' in kwargs:
        raise Exception('Use of the -outfmt option is not supported')

    num_processes = kwargs.get(
        'pb_num_processes', os.sysconf('SC_NPROCESSORS_ONLN'))
    fields = kwargs.get('pb_fields', DEFAULT_HIT_FIELDS)

    blast_args = [blast_command]
    blast_args += ['-outfmt', '7 {}'.format(' '.join(fields))]
    for a in args:
        blast_args += ['-' + a]
    for k, v in kwargs.iteritems():
        if not k.startswith('pb_'):
            blast_args += ['-' + k, str(v)]

    popens = []
    for _ in range(num_processes):
        popens.append(
            subprocess.Popen(
                args=blast_args, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
                stderr=None, close_fds=True))

    try:
        for r in __run_blast_select_loop(input_file, popens, fields):
            yield r
    finally:
        for p in popens:
            if p.poll() is None:
                p.terminate()
            p.wait()
368277
def new_protocol(self, protocol_name):
        
        if self._protocol_in_progress:
            raise Exception('Can not start a new protocol definition in middle of old.')
        if protocol_name in self._protocols:
            raise Exception('Protocol %s already defined' % protocol_name)
        self._init_new_message_stack(Protocol(protocol_name, library=self))
        self._protocol_in_progress = True
632640
def _serialize(proto):  # type: (Union[bytes, google.protobuf.message.Message]) -> bytes
    '''
    
    '''
    if isinstance(proto, bytes):
        return proto
    elif hasattr(proto, 'SerializeToString') and callable(proto.SerializeToString):
        result = proto.SerializeToString()
        return result
    else:
        raise ValueError('No SerializeToString method is detected. '
                         'neither proto is a str.\ntype is {}'.format(type(proto)))
852014
def invoke(self):
        
        # flush to ensure external process can see flags as they currently
        # are, and write flags (flush releases lock)
        unitdata.kv().flush()
        subprocess.check_call([self._filepath, '--invoke', self._test_output], env=os.environ)
619282
def generate_binary(outputfname, format_, progname='', binary_files=None, headless_binary_files=None):
    
    global AUTORUN_ADDR

    org, binary = MEMORY.dump()
    if gl.has_errors:
        return

    if binary_files is None:
        binary_files = []

    if headless_binary_files is None:
        headless_binary_files = []

    bin_blocks = []
    for fname in binary_files:
        with api.utils.open_file(fname) as f:
            bin_blocks.append((os.path.basename(fname), f.read()))

    headless_bin_blocks = []
    for fname in headless_binary_files:
        with api.utils.open_file(fname) as f:
            headless_bin_blocks.append(f.read())

    if AUTORUN_ADDR is None:
        AUTORUN_ADDR = org

    if not progname:
        progname = os.path.basename(outputfname)[:10]

    if OPTIONS.use_loader.value:
        import basic  # Minimalist basic tokenizer

        program = basic.Basic()
        if org > 16383:  # Only for zx48k: CLEAR if below 16383
            program.add_line([['CLEAR', org - 1]])
        program.add_line([['LOAD', '""', program.token('CODE')]])

        if OPTIONS.autorun.value:
            program.add_line([['RANDOMIZE', program.token('USR'), AUTORUN_ADDR]])
        else:
            program.add_line([['REM'], ['RANDOMIZE', program.token('USR'), AUTORUN_ADDR]])

    if format_ in ('tap', 'tzx'):
        t = {'tap': outfmt.TAP, 'tzx': outfmt.TZX}[format_]()

        if OPTIONS.use_loader.value:
            t.save_program('loader', program.bytes, line=1)  # Put line 0 to protect against MERGE

        t.save_code(progname, org, binary)
        for name, block in bin_blocks:
            t.save_code(name, 0, block)
        for block in headless_bin_blocks:
            t.standard_block(block)

        t.dump(outputfname)

    else:
        with open(outputfname, 'wb') as f:
            f.write(bytearray(binary))
930251
def write(self, proto):
    
    regionImpl = proto.regionImpl.as_struct(self.getSchema())
    self.writeToProto(regionImpl)
1107599
def _generate_rpc_method(self, method):
        '''
        
        '''
        def _(**kwargs):
            '''
            always use named arguments
            '''
            msg_id = self.get_unique_msg_id()
            params = encode_data(kwargs)
            payload = {
                'method': method,
                'params': params,
                'jsonrpc': '2.0',
                'id': msg_id
            }
            response = requests.post(self.url, data=json.dumps(payload), headers=self.headers).json()
            if ('error' in response):
                if response['error']['code'] == JSONRPC_NO_RESULT:
                    return None
                raise Exception('Got error from RPC server when called "%s" error: %s' % (method, response['error']))
            if 'result' in response:
                result = decode_data(response['result'])
                return result
        return _
1323756
def convert_protodef_to_editable(proto):
    
    class Editable(object):
        def __init__(self, prot):
            self.kind = type(prot)
            self.name = prot.name
            self.comment = ""
            self.options = dict([(key.name, value) for (key, value) in prot.options.ListFields()])
            if isinstance(prot, EnumDescriptorProto):
                self.value = [convert_protodef_to_editable(x) for x in prot.value]
            elif isinstance(prot, DescriptorProto):
                self.field = [convert_protodef_to_editable(x) for x in prot.field]
                self.enum_type = [convert_protodef_to_editable(x) for x in prot.enum_type]
                self.nested_type = prot.nested_type
                self.oneof_decl = prot.oneof_decl
            elif isinstance(prot, EnumValueDescriptorProto):
                self.number = prot.number
            elif isinstance(prot, FieldDescriptorProto):
                if prot.type in [11, 14]:
                    self.ref_type = prot.type_name[1:]
                self.type = prot.type
                self.label = prot.label
            elif isinstance(prot, ServiceDescriptorProto):
                self.method = [convert_protodef_to_editable(x) for x in prot.method]
            elif isinstance(prot, MethodDescriptorProto):
                self.input_type = prot.input_type
                self.output_type = prot.output_type
            else:
                raise Exception, type(prot)

    return Editable(proto)
1121281
public final void generate(Resource input, IFileSystemAccess2 fsa, IGeneratorContext context) {
		try {
			beforeGenerate(input, fsa, context);
			doGenerate(input, fsa, context);
		} finally {
			afterGenerate(input, fsa, context);
		}
	}