if self.outputs is None:<EOL><INDENT>return set()<EOL><DEDENT>if not isinstance(self.outputs, (list, tuple)):<EOL><INDENT>raise TypeError("<STR_LIT>"<EOL>% str(type(self.outputs)))<EOL><DEDENT>ret_lst = []<EOL>for output in self.outputs:<EOL><INDENT>if not isinstance(output, (str, Stream)):<EOL><INDENT>raise TypeError("<STR_LIT>" % str(output))<EOL><DEDENT>ret_lst.append(Stream.DEFAULT_STREAM_ID if isinstance(output, str) else output.stream_id)<EOL><DEDENT>return set(ret_lst)<EOL>

Returns a set of output stream ids registered for this component


ret = {}<EOL>if self.inputs is None:<EOL><INDENT>return<EOL><DEDENT>if isinstance(self.inputs, dict):<EOL><INDENT>for key, grouping in self.inputs.items():<EOL><INDENT>if not Grouping.is_grouping_sane(grouping):<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>if isinstance(key, HeronComponentSpec):<EOL><INDENT>if key.name is None:<EOL><INDENT>raise RuntimeError("<STR_LIT>")<EOL><DEDENT>global_streamid = GlobalStreamId(key.name, Stream.DEFAULT_STREAM_ID)<EOL>ret[global_streamid] = grouping<EOL><DEDENT>elif isinstance(key, GlobalStreamId):<EOL><INDENT>ret[key] = grouping<EOL><DEDENT>else:<EOL><INDENT>raise ValueError("<STR_LIT>" % str(key))<EOL><DEDENT><DEDENT><DEDENT>elif isinstance(self.inputs, (list, tuple)):<EOL><INDENT>for input_obj in self.inputs:<EOL><INDENT>if isinstance(input_obj, HeronComponentSpec):<EOL><INDENT>if input_obj.name is None:<EOL><INDENT>raise RuntimeError("<STR_LIT>")<EOL><DEDENT>global_streamid = GlobalStreamId(input_obj.name, Stream.DEFAULT_STREAM_ID)<EOL>ret[global_streamid] = Grouping.SHUFFLE<EOL><DEDENT>elif isinstance(input_obj, GlobalStreamId):<EOL><INDENT>ret[input_obj] = Grouping.SHUFFLE<EOL><DEDENT>else:<EOL><INDENT>raise ValueError("<STR_LIT>" % str(input_obj))<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>raise TypeError("<STR_LIT>" % str(self.inputs))<EOL><DEDENT>return ret<EOL>

Sanitizes input fields and returns a map <GlobalStreamId -> Grouping>


def __init__(self, componentId, streamId):

if not isinstance(componentId, (str, HeronComponentSpec)):<EOL><INDENT>raise TypeError('<STR_LIT>')<EOL><DEDENT>if not isinstance(streamId, str):<EOL><INDENT>raise TypeError('<STR_LIT>')<EOL><DEDENT>self._component_id = componentId<EOL>self.stream_id = streamId<EOL>

:type componentId: str or HeronComponentSpec
:param componentId: component id from which the tuple is emitted, or HeronComponentSpec object.
:type streamId: str
:param streamId: stream id through which the tuple is transmitted


proto_config = topology_pb2.Config()<EOL>key = proto_config.kvs.add()<EOL>key.key = TOPOLOGY_COMPONENT_PARALLELISM<EOL>key.value = str(self.parallelism)<EOL>key.type = topology_pb2.ConfigValueType.Value("<STR_LIT>")<EOL>if self.custom_config is not None:<EOL><INDENT>sanitized = self._sanitize_config(self.custom_config)<EOL>for key, value in sanitized.items():<EOL><INDENT>if isinstance(value, str):<EOL><INDENT>kvs = proto_config.kvs.add()<EOL>kvs.key = key<EOL>kvs.value = value<EOL>kvs.type = topology_pb2.ConfigValueType.Value("<STR_LIT>")<EOL><DEDENT>else:<EOL><INDENT>kvs = proto_config.kvs.add()<EOL>kvs.key = key<EOL>kvs.serialized_value = default_serializer.serialize(value)<EOL>kvs.type = topology_pb2.ConfigValueType.Value("<STR_LIT>")<EOL><DEDENT><DEDENT><DEDENT>return proto_config<EOL>

Returns component-specific Config protobuf message

        It first adds ``topology.component.parallelism``, and is overriden by
        a user-defined component-specific configuration, specified by spec().


if self.outputs is None:<EOL><INDENT>return<EOL><DEDENT>output_map = self._sanitize_outputs()<EOL>for stream_id, out_fields in output_map.items():<EOL><INDENT>out_stream = spbl.outputs.add()<EOL>out_stream.stream.CopyFrom(self._get_stream_id(self.name, stream_id))<EOL>out_stream.schema.CopyFrom(self._get_stream_schema(out_fields))<EOL><DEDENT>

Adds outputs to a given protobuf Bolt or Spout message


bolt = topology_pb2.Bolt()<EOL>bolt.comp.CopyFrom(self._get_base_component())<EOL>self._add_in_streams(bolt)<EOL>self._add_out_streams(bolt)<EOL>return bolt<EOL>


stream_schema = topology_pb2.StreamSchema()<EOL>for field in fields:<EOL><INDENT>key = stream_schema.keys.add()<EOL>key.key = field<EOL>key.type = topology_pb2.Type.Value("<STR_LIT>")<EOL><DEDENT>return stream_schema<EOL>


if self.is_spout:<EOL><INDENT>return self._get_spout()<EOL><DEDENT>else:<EOL><INDENT>return self._get_bolt()<EOL><DEDENT>

Returns protobuf message (Spout or Bolt) of this component


self.delegate = delegate<EOL>self.logger = self.delegate.logger<EOL>

Initializes BaseComponent

        :param delegate: SpoutInstance or BoltInstance


pass<EOL>

Called in spout every time a tuple gets acked

        :param spout_ack_info: SpoutAckInfo object


pass<EOL>

Called in bolt every time a tuple gets failed

        :param bolt_fail_info: BoltFailInfo object


@abstractmethod<EOL><INDENT>def prepare(self, conf, context):<DEDENT>

pass<EOL>

Called after the spout/bolt's initialize() method is called

        :param conf: component-specific configuration passed to the topology
        :param context: topology context


pass<EOL>

Called in bolt every time a tuple gets executed

        :param bolt_execute_info: BoltExecuteInfo object


@classmethod<EOL><INDENT>def spec(cls, name=None, par=<NUM_LIT:1>, config=None, optional_outputs=None):<DEDENT>

python_class_path = "<STR_LIT>" % (cls.__module__, cls.__name__)<EOL>if hasattr(cls, '<STR_LIT>'):<EOL><INDENT>_outputs = copy.copy(cls.outputs)<EOL><DEDENT>else:<EOL><INDENT>_outputs = []<EOL><DEDENT>if optional_outputs is not None:<EOL><INDENT>assert isinstance(optional_outputs, (list, tuple))<EOL>for out in optional_outputs:<EOL><INDENT>assert isinstance(out, (str, Stream))<EOL>_outputs.append(out)<EOL><DEDENT><DEDENT>return HeronComponentSpec(name, python_class_path, is_spout=True, par=par,<EOL>inputs=None, outputs=_outputs, config=config)<EOL>

Register this spout to the topology and create ``HeronComponentSpec``

        The usage of this method is compatible with StreamParse API, although it does not create
        ``ShellBoltSpec`` but instead directly registers to a ``Topology`` class.

        This method takes an optional ``outputs`` argument for supporting dynamic output fields
        declaration. However, it is recommended that ``outputs`` should be declared as
        an attribute of your ``Spout`` subclass. Also, some ways of declaring inputs is not supported
        in this implementation; please read the documentation below.

        :type name: str
        :param name: Name of this spout.
        :type par: int
        :param par: Parallelism hint for this spout.
        :type config: dict
        :param config: Component-specific config settings.
        :type optional_outputs: list of (str or Stream) or tuple of (str or Stream)
        :param optional_outputs: Additional output fields for this spout. These fields are added to
                                 existing ``outputs`` class attributes of your spout.
                                 This is an optional argument, and exists only for supporting dynamic
                                 output field declaration.


pass<EOL>

Called when a spout has been deactivated

        next_tuple() will not be called while a spout is deactivated.
        The spout may or may not be reactivated in the future.


pass<EOL>

Determine that the tuple emitted by this spout with the tup_id has failed to be processed

        It is compatible with StreamParse API.

        The tuple emitted by this spout with the tup_id identifier has failed to be
        fully processed. Typically, an implementation of this method will put that
        message back on the queue to be replayed at a later time.

        *Should be implemented by a subclass.*

        :param tup_id: the ID of the HeronTuple that has failed either due to a bolt calling ``fail()``
                       or timeout


def __init__(self, fields=None, name=DEFAULT_STREAM_ID, direct=False):

if fields is None:<EOL><INDENT>fields = []<EOL><DEDENT>elif isinstance(fields, (list, tuple)):<EOL><INDENT>fields = list(fields)<EOL>for field in fields:<EOL><INDENT>if not isinstance(field, str):<EOL><INDENT>raise TypeError("<STR_LIT>" % str(field))<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>raise TypeError("<STR_LIT>" % str(fields))<EOL><DEDENT>self.fields = fields<EOL>if name is None:<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>elif isinstance(name, str):<EOL><INDENT>self.stream_id = name<EOL><DEDENT>else:<EOL><INDENT>raise TypeError("<STR_LIT>" % str(name))<EOL><DEDENT>if isinstance(direct, bool):<EOL><INDENT>self.direct = direct<EOL>if self.direct:<EOL><INDENT>raise NotImplementedError("<STR_LIT>")<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise TypeError("<STR_LIT>" % str(direct))<EOL><DEDENT>

:type fields: `list` or `tuple` of `str`
:param fields: field names for this stream
:type name: str
:param name: name of stream. Defaults to ``default``
:type direct: bool
:param direct: whether or not this stream is direct. Default is ``False``


if customgrouper is None:<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>if not isinstance(customgrouper, ICustomGrouping) and not isinstance(customgrouper, str):<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>serialized = default_serializer.serialize(customgrouper)<EOL>return cls.custom_serialized(serialized, is_java=False)<EOL>

Custom grouping from a given implementation of ICustomGrouping

        :param customgrouper: The ICustomGrouping implemention to use


pass<EOL>


def _make_skel_func(code, closures, base_globals=None):

closure = _reconstruct_closure(closures) if closures else None<EOL>if base_globals is None:<EOL><INDENT>base_globals = {}<EOL><DEDENT>base_globals['<STR_LIT>'] = __builtins__<EOL>return types.FunctionType(code, base_globals, None, None, closure)<EOL>

Creates a skeleton function object that contains just the provided
      code and the correct number of cells in func_closure.  All other
      func attributes (e.g. func_globals) are empty.


Pickler.save_string(self, str(obj))<EOL>


try:<EOL><INDENT>import StringIO as pystringIO <EOL><DEDENT>except ImportError:<EOL><INDENT>import io as pystringIO <EOL><DEDENT>if not hasattr(obj, '<STR_LIT:name>') or  not hasattr(obj, '<STR_LIT>'):<EOL><INDENT>raise pickle.PicklingError("<STR_LIT>")<EOL><DEDENT>if obj is sys.stdout:<EOL><INDENT>return self.save_reduce(getattr, (sys, '<STR_LIT>'), obj=obj)<EOL><DEDENT>if obj is sys.stderr:<EOL><INDENT>return self.save_reduce(getattr, (sys, '<STR_LIT>'), obj=obj)<EOL><DEDENT>if obj is sys.stdin:<EOL><INDENT>raise pickle.PicklingError("<STR_LIT>")<EOL><DEDENT>if  hasattr(obj, '<STR_LIT>') and obj.isatty():<EOL><INDENT>raise pickle.PicklingError("<STR_LIT>")<EOL><DEDENT>if '<STR_LIT:r>' not in obj.mode:<EOL><INDENT>raise pickle.PicklingError("<STR_LIT>")<EOL><DEDENT>name = obj.name<EOL>try:<EOL><INDENT>fsize = os.stat(name).st_size<EOL><DEDENT>except OSError:<EOL><INDENT>raise pickle.PicklingError("<STR_LIT>" % name)<EOL><DEDENT>if obj.closed:<EOL><INDENT>retval = pystringIO.StringIO("<STR_LIT>")<EOL>retval.close()<EOL><DEDENT>elif not fsize: <EOL><INDENT>retval = pystringIO.StringIO("<STR_LIT>")<EOL>try:<EOL><INDENT>tmpfile = file(name)<EOL>tst = tmpfile.read(<NUM_LIT:1>)<EOL><DEDENT>except IOError:<EOL><INDENT>raise pickle.PicklingError("<STR_LIT>" % name)<EOL><DEDENT>tmpfile.close()<EOL>if tst != '<STR_LIT>':<EOL><INDENT>raise pickle.PicklingError(<EOL>"<STR_LIT>" % name)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>tmpfile = file(name)<EOL>contents = tmpfile.read()<EOL>tmpfile.close()<EOL><DEDENT>except IOError:<EOL><INDENT>raise pickle.PicklingError("<STR_LIT>" % name)<EOL><DEDENT>retval = pystringIO.StringIO(contents)<EOL>curloc = obj.tell()<EOL>retval.seek(curloc)<EOL><DEDENT>retval.name = name<EOL>self.save(retval)<EOL>self.memoize(obj)<EOL>


out_names = cls._extract_code_globals_cache.get(co)<EOL>if out_names is None:<EOL><INDENT>try:<EOL><INDENT>names = co.co_names<EOL><DEDENT>except AttributeError:<EOL><INDENT>out_names = set()<EOL><DEDENT>else:<EOL><INDENT>out_names = set(names[oparg]<EOL>for op, oparg in _walk_global_ops(co))<EOL>if co.co_consts:<EOL><INDENT>for const in co.co_consts:<EOL><INDENT>if type(const) is types.CodeType: <EOL><INDENT>out_names |= cls.extract_code_globals(const)<EOL><DEDENT><DEDENT><DEDENT><DEDENT>cls._extract_code_globals_cache[co] = out_names<EOL><DEDENT>return out_names<EOL>

Find all globals names read or written to by codeblock co


def save_reduce(self, func, args, state=None, <EOL>listitems=None, dictitems=None, obj=None):

<EOL>if not isinstance(args, tuple):<EOL><INDENT>raise pickle.PicklingError("<STR_LIT>")<EOL><DEDENT>if not hasattr(func, '<STR_LIT>'):<EOL><INDENT>raise pickle.PicklingError("<STR_LIT>")<EOL><DEDENT>save = self.save<EOL>write = self.write<EOL>if self.proto >= <NUM_LIT:2> and getattr(func, "<STR_LIT>", "<STR_LIT>") == "<STR_LIT>":<EOL><INDENT>cls = args[<NUM_LIT:0>]<EOL>if not hasattr(cls, "<STR_LIT>"):<EOL><INDENT>raise pickle.PicklingError(<EOL>"<STR_LIT>")<EOL><DEDENT>if obj is not None and cls is not obj.__class__:<EOL><INDENT>raise pickle.PicklingError(<EOL>"<STR_LIT>")<EOL><DEDENT>args = args[<NUM_LIT:1>:]<EOL>save(cls)<EOL>if hasattr(obj, '<STR_LIT>'):<EOL><INDENT>transient = obj.__transient__<EOL>state = state.copy()<EOL>for k in list(state.keys()):<EOL><INDENT>if k in transient:<EOL><INDENT>del state[k]<EOL><DEDENT><DEDENT><DEDENT>save(args)<EOL>write(pickle.NEWOBJ)<EOL><DEDENT>else:<EOL><INDENT>save(func)<EOL>save(args)<EOL>write(pickle.REDUCE)<EOL><DEDENT>if obj is not None:<EOL><INDENT>self.memoize(obj)<EOL><DEDENT>if listitems is not None:<EOL><INDENT>self._batch_appends(listitems)<EOL><DEDENT>if dictitems is not None:<EOL><INDENT>self._batch_setitems(dictitems)<EOL><DEDENT>if state is not None:<EOL><INDENT>save(state)<EOL>write(pickle.BUILD)<EOL><DEDENT>

Modified to support __transient__ on new objects
        Change only affects protocol level 2 (which is always used by PiCloud


for macro in _CHECK_MACROS:<EOL><INDENT>i = line.find(macro)<EOL>if i >= <NUM_LIT:0>:<EOL><INDENT>matched = Match(r'<STR_LIT>' + macro + r'<STR_LIT>', line)<EOL>if not matched:<EOL><INDENT>continue<EOL><DEDENT>return (macro, len(matched.group(<NUM_LIT:1>)))<EOL><DEDENT><DEDENT>return (None, -<NUM_LIT:1>)<EOL>

Find a replaceable CHECK-like macro.

    Args:
      line: line to search on.
    Returns:
      (macro name, start position), or (None, -1) if no replaceable
      macro is found.


return self.stack and isinstance(self.stack[-<NUM_LIT:1>], _ExternCInfo)<EOL>

Check if we are currently one level inside an 'extern "C"' block.

        Returns:
          True if top of the stack is an extern block, False otherwise.


def CheckForNewlineAtEOF(filename, lines, error):

<EOL>if len(lines) < <NUM_LIT:3> or lines[-<NUM_LIT:2>]:<EOL><INDENT>error(filename, len(lines) - <NUM_LIT:2>, '<STR_LIT>', <NUM_LIT:5>,<EOL>'<STR_LIT>')<EOL><DEDENT>

Logs an error if there is no newline char at the end of the file.

    Args:
      filename: The name of the current file.
      lines: An array of strings, each representing a line of the file.
      error: The function to call with any errors found.


for category, count in sorted(iteritems(self.errors_by_category)):<EOL><INDENT>self.PrintInfo('<STR_LIT>' %<EOL>(category, count))<EOL><DEDENT>if self.error_count > <NUM_LIT:0>:<EOL><INDENT>self.PrintInfo('<STR_LIT>' % self.error_count)<EOL><DEDENT>

Print a summary of errors by category, and the total.


fileinfo_cc = FileInfo(filename_cc)<EOL>if not fileinfo_cc.Extension().lstrip('<STR_LIT:.>') in GetNonHeaderExtensions():<EOL><INDENT>return (False, '<STR_LIT>')<EOL><DEDENT>fileinfo_h = FileInfo(filename_h)<EOL>if not fileinfo_h.Extension().lstrip('<STR_LIT:.>') in GetHeaderExtensions():<EOL><INDENT>return (False, '<STR_LIT>')<EOL><DEDENT>filename_cc = filename_cc[:-(len(fileinfo_cc.Extension()))]<EOL>matched_test_suffix = Search(_TEST_FILE_SUFFIX, fileinfo_cc.BaseName())<EOL>if matched_test_suffix:<EOL><INDENT>filename_cc = filename_cc[:-len(matched_test_suffix.group(<NUM_LIT:1>))]<EOL><DEDENT>filename_cc = filename_cc.replace('<STR_LIT>', '<STR_LIT:/>')<EOL>filename_cc = filename_cc.replace('<STR_LIT>', '<STR_LIT:/>')<EOL>filename_h = filename_h[:-(len(fileinfo_h.Extension()))]<EOL>if filename_h.endswith('<STR_LIT>'):<EOL><INDENT>filename_h = filename_h[:-len('<STR_LIT>')]<EOL><DEDENT>filename_h = filename_h.replace('<STR_LIT>', '<STR_LIT:/>')<EOL>filename_h = filename_h.replace('<STR_LIT>', '<STR_LIT:/>')<EOL>files_belong_to_same_module = filename_cc.endswith(filename_h)<EOL>common_path = '<STR_LIT>'<EOL>if files_belong_to_same_module:<EOL><INDENT>common_path = filename_cc[:-len(filename_h)]<EOL><DEDENT>return files_belong_to_same_module, common_path<EOL>

Check if these two filenames belong to the same module.

    The concept of a 'module' here is a as follows:
    foo.h, foo-inl.h, foo.cc, foo_test.cc and foo_unittest.cc belong to the
    same 'module' if they are in the same directory.
    some/path/public/xyzzy and some/path/internal/xyzzy are also considered
    to belong to the same module here.

    If the filename_cc contains a longer path than the filename_h, for example,
    '/absolute/path/to/base/sysinfo.cc', and this file would include
    'base/sysinfo.h', this function also produces the prefix needed to open the
    header. This is used by the caller of this function to more robustly open the
    header file. We don't have access to the real include paths in this context,
    so we need this guesswork here.

    Known bugs: tools/base/bar.cc and base/bar.h belong to the same module
    according to this implementation. Because of this, this function gives
    some false positives. This should be sufficiently rare in practice.

    Args:
      filename_cc: is the path for the source (e.g. .cc) file
      filename_h: is the path for the header path

    Returns:
      Tuple with a bool and a string:
      bool: True if filename_cc and filename_h belong to the same module.
      string: the additional prefix needed to open the header file.


for i in range(len(self.stack), <NUM_LIT:0>, -<NUM_LIT:1>):<EOL><INDENT>classinfo = self.stack[i - <NUM_LIT:1>]<EOL>if isinstance(classinfo, _ClassInfo):<EOL><INDENT>return classinfo<EOL><DEDENT><DEDENT>return None<EOL>

Get class info on the top of the stack.

        Returns:
          A _ClassInfo object if we are inside a class, or None otherwise.


self.error_count += <NUM_LIT:1><EOL>if self.counting in ('<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>if self.counting != '<STR_LIT>':<EOL><INDENT>category = category.split('<STR_LIT:/>')[<NUM_LIT:0>]<EOL><DEDENT>if category not in self.errors_by_category:<EOL><INDENT>self.errors_by_category[category] = <NUM_LIT:0><EOL><DEDENT>self.errors_by_category[category] += <NUM_LIT:1><EOL><DEDENT>


Adds more filter overrides.

    Unlike _SetFilters, this function does not reset the current list of filters
    available.

    Args:
      filters: A string of comma-separated filters (eg "whitespace/indent").
               Each filter should start with + or -; else we die.


def CheckForNonConstReference(filename, clean_lines, linenum,<EOL>nesting_state, error):

<EOL>line = clean_lines.elided[linenum]<EOL>if '<STR_LIT:&>' not in line:<EOL><INDENT>return<EOL><DEDENT>if IsDerivedFunction(clean_lines, linenum):<EOL><INDENT>return<EOL><DEDENT>if IsOutOfLineMethodDefinition(clean_lines, linenum):<EOL><INDENT>return<EOL><DEDENT>if linenum > <NUM_LIT:1>:<EOL><INDENT>previous = None<EOL>if Match(r'<STR_LIT>', line):<EOL><INDENT>previous = Search(r'<STR_LIT>',<EOL>clean_lines.elided[linenum - <NUM_LIT:1>])<EOL><DEDENT>elif Match(r'<STR_LIT>', line):<EOL><INDENT>previous = Search(r'<STR_LIT>',<EOL>clean_lines.elided[linenum - <NUM_LIT:1>])<EOL><DEDENT>if previous:<EOL><INDENT>line = previous.group(<NUM_LIT:1>) + line.lstrip()<EOL><DEDENT>else:<EOL><INDENT>endpos = line.rfind('<STR_LIT:>>')<EOL>if endpos > -<NUM_LIT:1>:<EOL><INDENT>(_, startline, startpos) = ReverseCloseExpression(<EOL>clean_lines, linenum, endpos)<EOL>if startpos > -<NUM_LIT:1> and startline < linenum:<EOL><INDENT>line = '<STR_LIT>'<EOL>for i in xrange(startline, linenum + <NUM_LIT:1>):<EOL><INDENT>line += clean_lines.elided[i].strip()<EOL><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT>if (nesting_state.previous_stack_top and<EOL>not (isinstance(nesting_state.previous_stack_top, _ClassInfo) or<EOL>isinstance(nesting_state.previous_stack_top, _NamespaceInfo))):<EOL><INDENT>return<EOL><DEDENT>if linenum > <NUM_LIT:0>:<EOL><INDENT>for i in xrange(linenum - <NUM_LIT:1>, max(<NUM_LIT:0>, linenum - <NUM_LIT:10>), -<NUM_LIT:1>):<EOL><INDENT>previous_line = clean_lines.elided[i]<EOL>if not Search(r'<STR_LIT>', previous_line):<EOL><INDENT>break<EOL><DEDENT>if Match(r'<STR_LIT>', previous_line):<EOL><INDENT>return<EOL><DEDENT><DEDENT><DEDENT>if Search(r'<STR_LIT>', line):<EOL><INDENT>return<EOL><DEDENT>if IsInitializerList(clean_lines, linenum):<EOL><INDENT>return<EOL><DEDENT>whitelisted_functions = (r'<STR_LIT>'<EOL>r'<STR_LIT>'<EOL>r'<STR_LIT>'<EOL>r'<STR_LIT>')<EOL>if Search(whitelisted_functions, line):<EOL><INDENT>return<EOL><DEDENT>elif not Search(r'<STR_LIT>', line):<EOL><INDENT>for i in xrange(<NUM_LIT:2>):<EOL><INDENT>if (linenum > i and<EOL>Search(whitelisted_functions, clean_lines.elided[linenum - i - <NUM_LIT:1>])):<EOL><INDENT>return<EOL><DEDENT><DEDENT><DEDENT>decls = ReplaceAll(r'<STR_LIT>', '<STR_LIT:U+0020>', line)  <EOL>for parameter in re.findall(_RE_PATTERN_REF_PARAM, decls):<EOL><INDENT>if (not Match(_RE_PATTERN_CONST_REF_PARAM, parameter) and<EOL>not Match(_RE_PATTERN_REF_STREAM_PARAM, parameter)):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:2>,<EOL>'<STR_LIT>'<EOL>'<STR_LIT>' +<EOL>ReplaceAll('<STR_LIT>', '<STR_LIT:<>', parameter))<EOL><DEDENT><DEDENT>

Check for non-const references.

    Separate from CheckLanguage since it scans backwards from current
    line, instead of scanning forward.

    Args:
      filename: The name of the current file.
      clean_lines: A CleansedLines instance containing the file.
      linenum: The number of the line to check.
      nesting_state: A NestingState instance which maintains information about
                     the current stack of nested blocks being parsed.
      error: The function to call with any errors found.


abs_filename = os.path.abspath(filename)<EOL>cfg_filters = []<EOL>keep_looking = True<EOL>while keep_looking:<EOL><INDENT>abs_path, base_name = os.path.split(abs_filename)<EOL>if not base_name:<EOL><INDENT>break  <EOL><DEDENT>cfg_file = os.path.join(abs_path, "<STR_LIT>")<EOL>abs_filename = abs_path<EOL>if not os.path.isfile(cfg_file):<EOL><INDENT>continue<EOL><DEDENT>try:<EOL><INDENT>with open(cfg_file) as file_handle:<EOL><INDENT>for line in file_handle:<EOL><INDENT>line, _, _ = line.partition('<STR_LIT:#>')  <EOL>if not line.strip():<EOL><INDENT>continue<EOL><DEDENT>name, _, val = line.partition('<STR_LIT:=>')<EOL>name = name.strip()<EOL>val = val.strip()<EOL>if name == '<STR_LIT>':<EOL><INDENT>keep_looking = False<EOL><DEDENT>elif name == '<STR_LIT>':<EOL><INDENT>cfg_filters.append(val)<EOL><DEDENT>elif name == '<STR_LIT>':<EOL><INDENT>if base_name:<EOL><INDENT>pattern = re.compile(val)<EOL>if pattern.match(base_name):<EOL><INDENT>_cpplint_state.PrintInfo('<STR_LIT>'<EOL>'<STR_LIT>' %<EOL>(filename, cfg_file, base_name, val))<EOL>return False<EOL><DEDENT><DEDENT><DEDENT>elif name == '<STR_LIT>':<EOL><INDENT>global _line_length<EOL>try:<EOL><INDENT>_line_length = int(val)<EOL><DEDENT>except ValueError:<EOL><INDENT>_cpplint_state.PrintError('<STR_LIT>')<EOL><DEDENT><DEDENT>elif name == '<STR_LIT>':<EOL><INDENT>global _valid_extensions<EOL>try:<EOL><INDENT>extensions = [ext.strip() for ext in val.split('<STR_LIT:U+002C>')]<EOL>_valid_extensions = set(extensions)<EOL><DEDENT>except ValueError:<EOL><INDENT>sys.stderr.write('<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>' % (val,))<EOL><DEDENT><DEDENT>elif name == '<STR_LIT>':<EOL><INDENT>global _header_extensions<EOL>try:<EOL><INDENT>extensions = [ext.strip() for ext in val.split('<STR_LIT:U+002C>')]<EOL>_header_extensions = set(extensions)<EOL><DEDENT>except ValueError:<EOL><INDENT>sys.stderr.write('<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>' % (val,))<EOL><DEDENT><DEDENT>elif name == '<STR_LIT:root>':<EOL><INDENT>global _root<EOL>_root = val<EOL><DEDENT>else:<EOL><INDENT>_cpplint_state.PrintError(<EOL>'<STR_LIT>' %<EOL>(name, cfg_file))<EOL><DEDENT><DEDENT><DEDENT><DEDENT>except IOError:<EOL><INDENT>_cpplint_state.PrintError(<EOL>"<STR_LIT>" % cfg_file)<EOL>keep_looking = False<EOL><DEDENT><DEDENT>for cfg_filter in reversed(cfg_filters):<EOL><INDENT>_AddFilters(cfg_filter)<EOL><DEDENT>return True<EOL>

Loads the configuration files and processes the config overrides.

    Args:
      filename: The name of the file being processed by the linter.

    Returns:
      False if the current |filename| should not be processed further.


self.in_a_function = False<EOL>


<EOL>for i in xrange(linenum, max(-<NUM_LIT:1>, linenum - <NUM_LIT:10>), -<NUM_LIT:1>):<EOL><INDENT>match = Match(r'<STR_LIT>', clean_lines.elided[i])<EOL>if match:<EOL><INDENT>line, _, closing_paren = CloseExpression(<EOL>clean_lines, i, len(match.group(<NUM_LIT:1>)))<EOL>return (closing_paren >= <NUM_LIT:0> and<EOL>Search(r'<STR_LIT>', line[closing_paren:]))<EOL><DEDENT><DEDENT>return False<EOL>

Check if current line contains an inherited function.

    Args:
      clean_lines: A CleansedLines instance containing the file.
      linenum: The number of the line to check.
    Returns:
      True if current line contains a function with "override"
      virt-specifier.


def CheckForMultilineCommentsAndStrings(filename, clean_lines, linenum, error):

line = clean_lines.elided[linenum]<EOL>line = line.replace('<STR_LIT>', '<STR_LIT>')<EOL>if line.count('<STR_LIT>') > line.count('<STR_LIT>'):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:5>,<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>if (line.count('<STR_LIT:">') - line.count('<STR_LIT>')) % <NUM_LIT:2>:<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:5>,<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>

Logs an error if we see /* ... */ or "..." that extend past one line.

    /* ... */ comments are legit inside macros, for one line.
    Otherwise, we prefer // comments, so it's ok to warn about the
    other.  Likewise, it's ok for strings to extend across multiple
    lines, as long as a line continuation character (backslash)
    terminates each line. Although not currently prohibited by the C++
    style guide, it's ugly and unnecessary. We don't do well with either
    in this lint program, so we warn about both.

    Args:
      filename: The name of the current file.
      clean_lines: A CleansedLines instance containing the file.
      linenum: The number of the line to check.
      error: The function to call with any errors found.


line = line.replace(r'<STR_LIT:\\>', '<STR_LIT>')  <EOL>return ((line.count('<STR_LIT:">') - line.count(r'<STR_LIT>') - line.count("<STR_LIT>")) & <NUM_LIT:1>) == <NUM_LIT:1><EOL>

Does line terminate so, that the next symbol is in string constant.

    This function does not consider single-line nor multi-line comments.

    Args:
      line: is a partial line of code starting from the 0..n.

    Returns:
      True, if next character appended to 'line' is inside a
      string constant.


def CheckGlobalStatic(filename, clean_lines, linenum, error):

line = clean_lines.elided[linenum]<EOL>if linenum + <NUM_LIT:1> < clean_lines.NumLines() and not Search(r'<STR_LIT>', line):<EOL><INDENT>line += clean_lines.elided[linenum + <NUM_LIT:1>].strip()<EOL><DEDENT>match = Match(<EOL>r'<STR_LIT>'<EOL>r'<STR_LIT>',<EOL>line)<EOL>if (match and<EOL>not Search(r'<STR_LIT>', line) and<EOL>not Search(r'<STR_LIT>', line) and<EOL>not Match(r'<STR_LIT>', match.group(<NUM_LIT:4>))):<EOL><INDENT>if Search(r'<STR_LIT>', line):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:4>,<EOL>'<STR_LIT>'<EOL>'<STR_LIT>' %<EOL>(match.group(<NUM_LIT:1>), match.group(<NUM_LIT:2>) or '<STR_LIT>', match.group(<NUM_LIT:3>)))<EOL><DEDENT>else:<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:4>,<EOL>'<STR_LIT>')<EOL><DEDENT><DEDENT>if (Search(r'<STR_LIT>', line) or<EOL>Search(r'<STR_LIT>', line)):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:4>,<EOL>'<STR_LIT>')<EOL><DEDENT>

Check for unsafe global or static objects.

    Args:
      filename: The name of the current file.
      clean_lines: A CleansedLines instance containing the file.
      linenum: The number of the line to check.
      error: The function to call with any errors found.


def CheckSpacingForFunctionCall(filename, clean_lines, linenum, error):

line = clean_lines.elided[linenum]<EOL>fncall = line    <EOL>for pattern in (r'<STR_LIT>',<EOL>r'<STR_LIT>',<EOL>r'<STR_LIT>',<EOL>r'<STR_LIT>'):<EOL><INDENT>match = Search(pattern, line)<EOL>if match:<EOL><INDENT>fncall = match.group(<NUM_LIT:1>)    <EOL>break<EOL><DEDENT><DEDENT>if (  <EOL>not Search(r'<STR_LIT>',<EOL>fncall) and<EOL>not Search(r'<STR_LIT>', fncall) and<EOL>not Search(r'<STR_LIT>', fncall)):<EOL><INDENT>if Search(r'<STR_LIT>', fncall):      <EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:4>,<EOL>'<STR_LIT>')<EOL><DEDENT>elif Search(r'<STR_LIT>', fncall):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:2>,<EOL>'<STR_LIT>')<EOL><DEDENT>if (Search(r'<STR_LIT>', fncall) and<EOL>not Search(r'<STR_LIT>', fncall) and<EOL>not Search(r'<STR_LIT>', fncall) and<EOL>not Search(r'<STR_LIT>', fncall) and<EOL>not Search(r'<STR_LIT>', fncall)):<EOL><INDENT>if Search(r'<STR_LIT>', line):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:0>,<EOL>'<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:4>,<EOL>'<STR_LIT>')<EOL><DEDENT><DEDENT>if Search(r'<STR_LIT>', fncall):<EOL><INDENT>if Search(r'<STR_LIT>', fncall):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:2>,<EOL>'<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:2>,<EOL>'<STR_LIT>')<EOL><DEDENT><DEDENT><DEDENT>

Checks for the correctness of various spacing around function calls.

    Args:
      filename: The name of the current file.
      clean_lines: A CleansedLines instance containing the file.
      linenum: The number of the line to check.
      error: The function to call with any errors found.


googlename = self.RepositoryName()<EOL>project, rest = os.path.split(googlename)<EOL>return (project,) + os.path.splitext(rest)<EOL>

Splits the file into the directory, basename, and extension.

        For 'chrome/browser/browser.cc', Split() would
        return ('chrome/browser', 'browser', '.cc')

        Returns:
          A tuple of (directory, basename, extension).


<EOL>for i in xrange(linenum, max(-<NUM_LIT:1>, linenum - <NUM_LIT:10>), -<NUM_LIT:1>):<EOL><INDENT>if Match(r'<STR_LIT>', clean_lines.elided[i]):<EOL><INDENT>return Match(r'<STR_LIT>', clean_lines.elided[i]) is not None<EOL><DEDENT><DEDENT>return False<EOL>

Check if current line contains an out-of-line method definition.

    Args:
      clean_lines: A CleansedLines instance containing the file.
      linenum: The number of the line to check.
    Returns:
      True if current line contains an out-of-line method definition.


if pattern not in _regexp_compile_cache:<EOL><INDENT>_regexp_compile_cache[pattern] = sre_compile.compile(pattern)<EOL><DEDENT>return _regexp_compile_cache[pattern].sub(rep, s)<EOL>

Replaces instances of pattern in a string with a replacement.

    The compiled regex is kept in a cache shared by Match and Search.

    Args:
      pattern: regex pattern
      rep: replacement text
      s: search string

    Returns:
      string with replacements made (or original string if no replacements)


def CheckOperatorSpacing(filename, clean_lines, linenum, error):

line = clean_lines.elided[linenum]<EOL>while True:<EOL><INDENT>match = Match(r'<STR_LIT>', line)<EOL>if match:<EOL><INDENT>line = match.group(<NUM_LIT:1>) + ('<STR_LIT:_>' * len(match.group(<NUM_LIT:2>))) + match.group(<NUM_LIT:3>)<EOL><DEDENT>else:<EOL><INDENT>break<EOL><DEDENT><DEDENT>if ((Search(r'<STR_LIT>', line) or<EOL>Search(r'<STR_LIT>', line))<EOL>and not Search(r'<STR_LIT>', line)<EOL>and not Search(r'<STR_LIT>', line)<EOL>and not Search(r'<STR_LIT>', line)):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:4>,<EOL>'<STR_LIT>')<EOL><DEDENT>match = Search(r'<STR_LIT>', line)<EOL>if match:<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:3>,<EOL>'<STR_LIT>' % match.group(<NUM_LIT:1>))<EOL><DEDENT>elif not Match(r'<STR_LIT>', line):<EOL><INDENT>match = Match(r'<STR_LIT>', line)<EOL>if match:<EOL><INDENT>(_, _, end_pos) = CloseExpression(<EOL>clean_lines, linenum, len(match.group(<NUM_LIT:1>)))<EOL>if end_pos <= -<NUM_LIT:1>:<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:3>,<EOL>'<STR_LIT>')<EOL><DEDENT><DEDENT>match = Match(r'<STR_LIT>', line)<EOL>if match:<EOL><INDENT>(_, _, start_pos) = ReverseCloseExpression(<EOL>clean_lines, linenum, len(match.group(<NUM_LIT:1>)))<EOL>if start_pos <= -<NUM_LIT:1>:<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:3>,<EOL>'<STR_LIT>')<EOL><DEDENT><DEDENT><DEDENT>match = Search(r'<STR_LIT>', line)<EOL>if (match and not (match.group(<NUM_LIT:1>).isdigit() and match.group(<NUM_LIT:2>).isdigit()) and<EOL>not (match.group(<NUM_LIT:1>) == '<STR_LIT>' and match.group(<NUM_LIT:2>) == '<STR_LIT:;>')):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:3>,<EOL>'<STR_LIT>')<EOL><DEDENT>match = Search(r'<STR_LIT>', line)<EOL>if match:<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:3>,<EOL>'<STR_LIT>')<EOL><DEDENT>match = Search(r'<STR_LIT>', line)<EOL>if match:<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:4>,<EOL>'<STR_LIT>' % match.group(<NUM_LIT:1>))<EOL><DEDENT>

Checks for horizontal spacing around operators.

    Args:
      filename: The name of the current file.
      clean_lines: A CleansedLines instance containing the file.
      linenum: The number of the line to check.
      error: The function to call with any errors found.


expanded = set()<EOL>for filename in filenames:<EOL><INDENT>if not os.path.isdir(filename):<EOL><INDENT>expanded.add(filename)<EOL>continue<EOL><DEDENT>for root, _, files in os.walk(filename):<EOL><INDENT>for loopfile in files:<EOL><INDENT>fullname = os.path.join(root, loopfile)<EOL>if fullname.startswith('<STR_LIT:.>' + os.path.sep):<EOL><INDENT>fullname = fullname[len('<STR_LIT:.>' + os.path.sep):]<EOL><DEDENT>expanded.add(fullname)<EOL><DEDENT><DEDENT><DEDENT>filtered = []<EOL>for filename in expanded:<EOL><INDENT>if os.path.splitext(filename)[<NUM_LIT:1>][<NUM_LIT:1>:] in GetAllExtensions():<EOL><INDENT>filtered.append(filename)<EOL><DEDENT><DEDENT>return filtered<EOL>

Searches a list of filenames and replaces directories in the list with
    all files descending from those directories. Files with extensions not in
    the valid extensions list are excluded.

    Args:
      filenames: A list of files or directories

    Returns:
      A list of all files that are members of filenames or descended from a
      directory in filenames


def CheckCompletedBlocks(self, filename, error):

<EOL>for obj in self.stack:<EOL><INDENT>if isinstance(obj, _ClassInfo):<EOL><INDENT>error(filename, obj.starting_linenum, '<STR_LIT>', <NUM_LIT:5>,<EOL>'<STR_LIT>' %<EOL>obj.name)<EOL><DEDENT>elif isinstance(obj, _NamespaceInfo):<EOL><INDENT>error(filename, obj.starting_linenum, '<STR_LIT>', <NUM_LIT:5>,<EOL>'<STR_LIT>' %<EOL>obj.name)<EOL><DEDENT><DEDENT>

Checks that all classes and namespaces have been completely parsed.

        Call this when all lines in a file have been processed.
        Args:
          filename: The name of the current file.
          error: The function to call with any errors found.


def CheckInvalidIncrement(filename, clean_lines, linenum, error):

line = clean_lines.elided[linenum]<EOL>if _RE_PATTERN_INVALID_INCREMENT.match(line):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:5>,<EOL>'<STR_LIT>')<EOL><DEDENT>

Checks for invalid increment *count++.

    For example following function:
    void increment_counter(int* count) {
      *count++;
    }
    is invalid, because it effectively does count++, moving pointer, and should
    be replaced with ++*count, (*count)++ or *count += 1.

    Args:
      filename: The name of the current file.
      clean_lines: A CleansedLines instance containing the file.
      linenum: The number of the line to check.
      error: The function to call with any errors found.


return self.stack and self.stack[-<NUM_LIT:1>].inline_asm != _NO_ASM<EOL>

Check if we are currently one level inside an inline ASM block.

        Returns:
          True if the top of the stack is a block containing inline ASM.


_cpplint_state.SetCountingStyle(level)<EOL>


if pattern not in _regexp_compile_cache:<EOL><INDENT>_regexp_compile_cache[pattern] = sre_compile.compile(pattern)<EOL><DEDENT>return _regexp_compile_cache[pattern].search(s)<EOL>

Searches the string for the pattern, caching the compiled regexp.


def CheckForBadCharacters(filename, lines, error):

for linenum, line in enumerate(lines):<EOL><INDENT>if unicode_escape_decode('<STR_LIT>') in line:<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:5>,<EOL>'<STR_LIT>')<EOL><DEDENT>if '<STR_LIT>' in line:<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:5>, '<STR_LIT>')<EOL><DEDENT><DEDENT>

Logs an error for each line containing bad characters.

    Two kinds of bad characters:

    1. Unicode replacement characters: These indicate that either the file
    contained invalid UTF-8 (likely) or Unicode replacement characters (which
    it shouldn't).  Note that it's possible for this to throw off line
    numbering if the invalid UTF-8 occurred adjacent to a newline.

    2. NUL bytes.  These are problematic for some tools.

    Args:
      filename: The name of the current file.
      lines: An array of strings, each representing a line of the file.
      error: The function to call with any errors found.


return self.Split()[<NUM_LIT:1>]<EOL>

File base name - text after the final slash, before the final period.


def CheckForCopyright(filename, lines, error):

<EOL>for line in range(<NUM_LIT:1>, min(len(lines), <NUM_LIT:11>)):<EOL><INDENT>if re.search(r'<STR_LIT>', lines[line], re.I): break<EOL><DEDENT>else:                       <EOL><INDENT>error(filename, <NUM_LIT:0>, '<STR_LIT>', <NUM_LIT:5>,<EOL>'<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>

Logs an error if no Copyright message appears at the top of the file.


exclude_paths = [os.path.abspath(f) for f in _excludes]<EOL>return [f for f in filenames if os.path.abspath(f) not in exclude_paths]<EOL>

Filters out files listed in the --exclude command line switch. File paths
    in the switch are evaluated relative to the current working directory


if is_forward_declaration:<EOL><INDENT>return len(nesting_state.stack) >= <NUM_LIT:1> and (<EOL>isinstance(nesting_state.stack[-<NUM_LIT:1>], _NamespaceInfo))<EOL><DEDENT>return (len(nesting_state.stack) > <NUM_LIT:1> and<EOL>nesting_state.stack[-<NUM_LIT:1>].check_namespace_indentation and<EOL>isinstance(nesting_state.stack[-<NUM_LIT:2>], _NamespaceInfo))<EOL>

Checks that the new block is directly in a namespace.

    Args:
      nesting_state: The _NestingState object that contains info about our state.
      is_forward_declaration: If the class is a forward declared class.
    Returns:
      Whether or not the new block is directly in a namespace.


if Match(r'<STR_LIT>', line):<EOL><INDENT>self.pp_stack.append(_PreprocessorInfo(copy.deepcopy(self.stack)))<EOL><DEDENT>elif Match(r'<STR_LIT>', line):<EOL><INDENT>if self.pp_stack:<EOL><INDENT>if not self.pp_stack[-<NUM_LIT:1>].seen_else:<EOL><INDENT>self.pp_stack[-<NUM_LIT:1>].seen_else = True<EOL>self.pp_stack[-<NUM_LIT:1>].stack_before_else = copy.deepcopy(self.stack)<EOL><DEDENT>self.stack = copy.deepcopy(self.pp_stack[-<NUM_LIT:1>].stack_before_if)<EOL><DEDENT>else:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>elif Match(r'<STR_LIT>', line):<EOL><INDENT>if self.pp_stack:<EOL><INDENT>if self.pp_stack[-<NUM_LIT:1>].seen_else:<EOL><INDENT>self.stack = self.pp_stack[-<NUM_LIT:1>].stack_before_else<EOL><DEDENT>self.pp_stack.pop()<EOL><DEDENT>else:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>

Update preprocessor stack.

        We need to handle preprocessors due to classes like this:
          #ifdef SWIG
          struct ResultDetailsPageElementExtensionPoint {
          #else
          struct ResultDetailsPageElementExtensionPoint : public Extension {
          #endif

        We make the following assumptions (good enough for most files):
        - Preprocessor condition evaluates to true from #if up to first
          #else/#elif/#endif.

        - Preprocessor condition evaluates to false from #else/#elif up
          to #endif.  We still perform lint checks on these lines, but
          these do not affect nesting stack.

        Args:
          line: current line to check.


return _cpplint_state.filters<EOL>

Returns the module's list of output filters, as a list.


def CheckEnd(self, filename, clean_lines, linenum, error):

pass<EOL>

Run checks that applies to text after the closing brace.

        This is mostly used for checking end of namespace comments.

        Args:
          filename: The name of the current file.
          clean_lines: A CleansedLines instance containing the file.
          linenum: The number of the line to check.
          error: The function to call with any errors found.


return _IsSourceExtension(self.Extension()[<NUM_LIT:1>:])<EOL>


self.in_a_function = True<EOL>self.lines_in_function = <NUM_LIT:0><EOL>self.current_function = function_name<EOL>

Start analyzing function body.

        Args:
          function_name: The name of the function being tracked.


_error_suppressions.clear()<EOL>_global_error_suppressions.clear()<EOL>

Resets the set of NOLINT suppressions to empty.


def CheckStyle(filename, clean_lines, linenum, file_extension, nesting_state,<EOL>error):

<EOL>raw_lines = clean_lines.lines_without_raw_strings<EOL>line = raw_lines[linenum]<EOL>prev = raw_lines[linenum - <NUM_LIT:1>] if linenum > <NUM_LIT:0> else '<STR_LIT>'<EOL>if line.find('<STR_LIT:\t>') != -<NUM_LIT:1>:<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:1>,<EOL>'<STR_LIT>')<EOL><DEDENT>scope_or_label_pattern = r'<STR_LIT>'<EOL>classinfo = nesting_state.InnermostClass()<EOL>initial_spaces = <NUM_LIT:0><EOL>cleansed_line = clean_lines.elided[linenum]<EOL>while initial_spaces < len(line) and line[initial_spaces] == '<STR_LIT:U+0020>':<EOL><INDENT>initial_spaces += <NUM_LIT:1><EOL><DEDENT>if (not Search(r'<STR_LIT>', prev) and<EOL>(initial_spaces == <NUM_LIT:1> or initial_spaces == <NUM_LIT:3>) and<EOL>not Match(scope_or_label_pattern, cleansed_line) and<EOL>not (clean_lines.raw_lines[linenum] != line and<EOL>Match(r'<STR_LIT>', line))):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:3>,<EOL>'<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>if line and line[-<NUM_LIT:1>].isspace():<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:4>,<EOL>'<STR_LIT>')<EOL><DEDENT>is_header_guard = False<EOL>if file_extension in GetHeaderExtensions():<EOL><INDENT>cppvar = GetHeaderGuardCPPVariable(filename)<EOL>if (line.startswith('<STR_LIT>' % cppvar) or<EOL>line.startswith('<STR_LIT>' % cppvar) or<EOL>line.startswith('<STR_LIT>' % cppvar)):<EOL><INDENT>is_header_guard = True<EOL><DEDENT><DEDENT>if (not line.startswith('<STR_LIT>') and not is_header_guard and<EOL>not Match(r'<STR_LIT>', line) and<EOL>not Match(r'<STR_LIT>', line) and<EOL>not Match(r'<STR_LIT>', line) and<EOL>not Match(r'<STR_LIT>', line)):<EOL><INDENT>line_width = GetLineWidth(line)<EOL>if line_width > _line_length:<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:2>,<EOL>'<STR_LIT>' % _line_length)<EOL><DEDENT><DEDENT>if (cleansed_line.count('<STR_LIT:;>') > <NUM_LIT:1> and<EOL>not Match(r'<STR_LIT>',<EOL>line) and<EOL>cleansed_line.find('<STR_LIT>') == -<NUM_LIT:1> and<EOL>(GetPreviousNonBlankLine(clean_lines, linenum)[<NUM_LIT:0>].find('<STR_LIT>') == -<NUM_LIT:1> or<EOL>GetPreviousNonBlankLine(clean_lines, linenum)[<NUM_LIT:0>].find('<STR_LIT:;>') != -<NUM_LIT:1>) and<EOL>not ((cleansed_line.find('<STR_LIT>') != -<NUM_LIT:1> or<EOL>cleansed_line.find('<STR_LIT>') != -<NUM_LIT:1>) and<EOL>cleansed_line.find('<STR_LIT>') != -<NUM_LIT:1>)):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:0>,<EOL>'<STR_LIT>')<EOL><DEDENT>CheckBraces(filename, clean_lines, linenum, error)<EOL>CheckTrailingSemicolon(filename, clean_lines, linenum, error)<EOL>CheckEmptyBlockBody(filename, clean_lines, linenum, error)<EOL>CheckAccess(filename, clean_lines, linenum, nesting_state, error)<EOL>CheckSpacing(filename, clean_lines, linenum, nesting_state, error)<EOL>CheckOperatorSpacing(filename, clean_lines, linenum, error)<EOL>CheckParenthesisSpacing(filename, clean_lines, linenum, error)<EOL>CheckCommaSpacing(filename, clean_lines, linenum, error)<EOL>CheckBracesSpacing(filename, clean_lines, linenum, nesting_state, error)<EOL>CheckSpacingForFunctionCall(filename, clean_lines, linenum, error)<EOL>CheckCheck(filename, clean_lines, linenum, error)<EOL>CheckAltTokens(filename, clean_lines, linenum, error)<EOL>classinfo = nesting_state.InnermostClass()<EOL>if classinfo:<EOL><INDENT>CheckSectionSpacing(filename, clean_lines, classinfo, linenum, error)<EOL><DEDENT>

Checks rules from the 'C++ style rules' section of cppguide.html.

    Most of these rules are hard to test (naming, comment style), but we
    do what we can.  In particular we check for 2-space indents, line lengths,
    tab usage, spaces inside code, etc.

    Args:
      filename: The name of the current file.
      clean_lines: A CleansedLines instance containing the file.
      linenum: The number of the line to check.
      file_extension: The extension (without the dot) of the filename.
      nesting_state: A NestingState instance which maintains information about
                     the current stack of nested blocks being parsed.
      error: The function to call with any errors found.


return not line or line.isspace()<EOL>

Returns true if the given line is blank.

    We consider a line to be blank if the line is empty or consists of
    only white spaces.

    Args:
      line: A line of a string.

    Returns:
      True, if the given line is blank.


def CheckParenthesisSpacing(filename, clean_lines, linenum, error):

line = clean_lines.elided[linenum]<EOL>match = Search(r'<STR_LIT>', line)<EOL>if match:<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:5>,<EOL>'<STR_LIT>' % match.group(<NUM_LIT:1>))<EOL><DEDENT>match = Search(r'<STR_LIT>'<EOL>r'<STR_LIT>',<EOL>line)<EOL>if match:<EOL><INDENT>if len(match.group(<NUM_LIT:2>)) != len(match.group(<NUM_LIT:4>)):<EOL><INDENT>if not (match.group(<NUM_LIT:3>) == '<STR_LIT:;>' and<EOL>len(match.group(<NUM_LIT:2>)) == <NUM_LIT:1> + len(match.group(<NUM_LIT:4>)) or<EOL>not match.group(<NUM_LIT:2>) and Search(r'<STR_LIT>', line)):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:5>,<EOL>'<STR_LIT>' % match.group(<NUM_LIT:1>))<EOL><DEDENT><DEDENT>if len(match.group(<NUM_LIT:2>)) not in [<NUM_LIT:0>, <NUM_LIT:1>]:<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:5>,<EOL>'<STR_LIT>' %<EOL>match.group(<NUM_LIT:1>))<EOL><DEDENT><DEDENT>

Checks for horizontal spacing around parentheses.

    Args:
      filename: The name of the current file.
      clean_lines: A CleansedLines instance containing the file.
      linenum: The number of the line to check.
      error: The function to call with any errors found.


fullname = self.FullName()<EOL>if os.path.exists(fullname):<EOL><INDENT>project_dir = os.path.dirname(fullname)<EOL>if _repository:<EOL><INDENT>repo = FileInfo(_repository).FullName()<EOL>root_dir = project_dir<EOL>while os.path.exists(root_dir):<EOL><INDENT>if os.path.normcase(root_dir) == os.path.normcase(repo):<EOL><INDENT>return os.path.relpath(fullname, root_dir).replace('<STR_LIT:\\>', '<STR_LIT:/>')<EOL><DEDENT>one_up_dir = os.path.dirname(root_dir)<EOL>if one_up_dir == root_dir:<EOL><INDENT>break<EOL><DEDENT>root_dir = one_up_dir<EOL><DEDENT><DEDENT>if os.path.exists(os.path.join(project_dir, "<STR_LIT>")):<EOL><INDENT>root_dir = project_dir<EOL>one_up_dir = os.path.dirname(root_dir)<EOL>while os.path.exists(os.path.join(one_up_dir, "<STR_LIT>")):<EOL><INDENT>root_dir = os.path.dirname(root_dir)<EOL>one_up_dir = os.path.dirname(one_up_dir)<EOL><DEDENT>prefix = os.path.commonprefix([root_dir, project_dir])<EOL>return fullname[len(prefix) + <NUM_LIT:1>:]<EOL><DEDENT>root_dir = current_dir = os.path.dirname(fullname)<EOL>while current_dir != os.path.dirname(current_dir):<EOL><INDENT>if (os.path.exists(os.path.join(current_dir, "<STR_LIT>")) or<EOL>os.path.exists(os.path.join(current_dir, "<STR_LIT>")) or<EOL>os.path.exists(os.path.join(current_dir, "<STR_LIT>"))):<EOL><INDENT>root_dir = current_dir<EOL><DEDENT>current_dir = os.path.dirname(current_dir)<EOL><DEDENT>if (os.path.exists(os.path.join(root_dir, "<STR_LIT>")) or<EOL>os.path.exists(os.path.join(root_dir, "<STR_LIT>")) or<EOL>os.path.exists(os.path.join(root_dir, "<STR_LIT>"))):<EOL><INDENT>prefix = os.path.commonprefix([root_dir, project_dir])<EOL>return fullname[len(prefix) + <NUM_LIT:1>:]<EOL><DEDENT><DEDENT>return fullname<EOL>

r"""FullName after removing the local path to the repository.

        If we have a real absolute path name here we can try to do something smart:
        detecting the root of the checkout and truncating /path/to/checkout from
        the name so that we get header guards that don't include things like
        "C:\Documents and Settings\..." or "/home/username/..." in them and thus
        people on different computers who have checked the source out to different
        locations won't see bogus errors.


def FlagCxx14Features(filename, clean_lines, linenum, error):

line = clean_lines.elided[linenum]<EOL>include = Match(r'<STR_LIT>', line)<EOL>if include and include.group(<NUM_LIT:1>) in ('<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:5>,<EOL>('<STR_LIT>') % include.group(<NUM_LIT:1>))<EOL><DEDENT>

Flag those C++14 features that we restrict.

    Args:
      filename: The name of the current file.
      clean_lines: A CleansedLines instance containing the file.
      linenum: The number of the line to check.
      error: The function to call with any errors found.


def CheckSpacing(filename, clean_lines, linenum, nesting_state, error):

<EOL>raw = clean_lines.lines_without_raw_strings<EOL>line = raw[linenum]<EOL>if (IsBlankLine(line) and<EOL>not nesting_state.InNamespaceBody() and<EOL>not nesting_state.InExternC()):<EOL><INDENT>elided = clean_lines.elided<EOL>prev_line = elided[linenum - <NUM_LIT:1>]<EOL>prevbrace = prev_line.rfind('<STR_LIT:{>')<EOL>if prevbrace != -<NUM_LIT:1> and prev_line[prevbrace:].find('<STR_LIT:}>') == -<NUM_LIT:1>:<EOL><INDENT>exception = False<EOL>if Match(r'<STR_LIT>', prev_line):  <EOL><INDENT>search_position = linenum-<NUM_LIT:2><EOL>while (search_position >= <NUM_LIT:0><EOL>and Match(r'<STR_LIT>', elided[search_position])):<EOL><INDENT>search_position -= <NUM_LIT:1><EOL><DEDENT>exception = (search_position >= <NUM_LIT:0><EOL>and elided[search_position][:<NUM_LIT:5>] == '<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>exception = (Match(r'<STR_LIT>',<EOL>prev_line)<EOL>or Match(r'<STR_LIT>', prev_line))<EOL><DEDENT>if not exception:<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:2>,<EOL>'<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT><DEDENT>if linenum + <NUM_LIT:1> < clean_lines.NumLines():<EOL><INDENT>next_line = raw[linenum + <NUM_LIT:1>]<EOL>if (next_line<EOL>and Match(r'<STR_LIT>', next_line)<EOL>and next_line.find('<STR_LIT>') == -<NUM_LIT:1>):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:3>,<EOL>'<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT><DEDENT>matched = Match(r'<STR_LIT>', prev_line)<EOL>if matched:<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:3>,<EOL>'<STR_LIT>' % matched.group(<NUM_LIT:1>))<EOL><DEDENT><DEDENT>next_line_start = <NUM_LIT:0><EOL>if linenum + <NUM_LIT:1> < clean_lines.NumLines():<EOL><INDENT>next_line = raw[linenum + <NUM_LIT:1>]<EOL>next_line_start = len(next_line) - len(next_line.lstrip())<EOL><DEDENT>CheckComment(line, filename, linenum, next_line_start, error)<EOL>line = clean_lines.elided[linenum]<EOL>if Search(r'<STR_LIT>', line) and not Search(r'<STR_LIT>', line):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:5>,<EOL>'<STR_LIT>')<EOL><DEDENT>if (Search(r'<STR_LIT>', line) or<EOL>Search(r'<STR_LIT>', line)):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:2>,<EOL>'<STR_LIT>')<EOL><DEDENT>

Checks for the correctness of various spacing issues in the code.

    Things we check for: spaces around operators, spaces after
    if/for/while/switch, no spaces around parens in function calls, two
    spaces between code and comment, don't start a block with a blank
    line, don't end a function with a blank line, don't add a blank line
    after public/protected/private, don't have too many blank lines in a row.

    Args:
      filename: The name of the current file.
      clean_lines: A CleansedLines instance containing the file.
      linenum: The number of the line to check.
      nesting_state: A NestingState instance which maintains information about
                     the current stack of nested blocks being parsed.
      error: The function to call with any errors found.


return '<STR_LIT:/>'.join(self.Split()[<NUM_LIT:0>:<NUM_LIT:2>])<EOL>


line = clean_lines.raw_lines[linenum]<EOL>if (linenum - self.starting_linenum < <NUM_LIT:10><EOL>and not Match(r'<STR_LIT>', line)):<EOL><INDENT>return<EOL><DEDENT>if self.name:<EOL><INDENT>if not Match((r'<STR_LIT>' +<EOL>re.escape(self.name) + r'<STR_LIT>'),<EOL>line):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:5>,<EOL>'<STR_LIT>' %<EOL>self.name)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if not Match(r'<STR_LIT>', line):<EOL><INDENT>if Match(r'<STR_LIT>', line):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:5>,<EOL>'<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:5>,<EOL>'<STR_LIT>')<EOL><DEDENT><DEDENT><DEDENT>


def CheckMakePairUsesDeduction(filename, clean_lines, linenum, error):

line = clean_lines.elided[linenum]<EOL>match = _RE_PATTERN_EXPLICIT_MAKEPAIR.search(line)<EOL>if match:<EOL><INDENT>error(filename, linenum, '<STR_LIT>',<EOL><NUM_LIT:4>,  <EOL>'<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>

Check that make_pair's template arguments are deduced.

    G++ 4.6 in C++11 mode fails badly if make_pair's template arguments are
    specified explicitly, and such use isn't intended in any case.

    Args:
      filename: The name of the current file.
      clean_lines: A CleansedLines instance containing the file.
      linenum: The number of the line to check.
      error: The function to call with any errors found.


return _cpplint_state.verbose_level<EOL>


indent = Match(r'<STR_LIT>', line)<EOL>if indent:<EOL><INDENT>return len(indent.group(<NUM_LIT:1>))<EOL><DEDENT>else:<EOL><INDENT>return <NUM_LIT:0><EOL><DEDENT>

Return the number of leading spaces in line.

    Args:
      line: A string to check.

    Returns:
      An integer count of leading spaces, possibly zero.


def CheckVlogArguments(filename, clean_lines, linenum, error):

line = clean_lines.elided[linenum]<EOL>if Search(r'<STR_LIT>', line):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:5>,<EOL>'<STR_LIT>'<EOL>'<STR_LIT>')<EOL><DEDENT>

Checks that VLOG() is only used for defining a logging level.

    For example, VLOG(2) is correct. VLOG(INFO), VLOG(WARNING), VLOG(ERROR), and
    VLOG(FATAL) are not.

    Args:
      filename: The name of the current file.
      clean_lines: A CleansedLines instance containing the file.
      linenum: The number of the line to check.
      error: The function to call with any errors found.


def CheckPosixThreading(filename, clean_lines, linenum, error):

line = clean_lines.elided[linenum]<EOL>for single_thread_func, multithread_safe_func, pattern in _THREADING_LIST:<EOL><INDENT>if Search(pattern, line):<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:2>,<EOL>'<STR_LIT>' + multithread_safe_func +<EOL>'<STR_LIT>' + single_thread_func +<EOL>'<STR_LIT>')<EOL><DEDENT><DEDENT>

Checks for calls to thread-unsafe functions.

    Much code has been originally written without consideration of
    multi-threading. Also, engineers are relying on their old experience;
    they have learned posix before threading extensions were added. These
    tests guide the engineers to use thread-safe functions (when using
    posix directly).

    Args:
      filename: The name of the current file.
      clean_lines: A CleansedLines instance containing the file.
      linenum: The number of the line to check.
      error: The function to call with any errors found.


<EOL>filename = re.sub(r'<STR_LIT>', '<STR_LIT>', filename)<EOL>filename = re.sub(r'<STR_LIT>', r'<STR_LIT>', filename)<EOL>filename = filename.replace('<STR_LIT>', '<STR_LIT>').replace('<STR_LIT>', '<STR_LIT>')<EOL>fileinfo = FileInfo(filename)<EOL>file_path_from_root = fileinfo.RepositoryName()<EOL>if _root:<EOL><INDENT>suffix = os.sep<EOL>if suffix == '<STR_LIT:\\>':<EOL><INDENT>suffix += '<STR_LIT:\\>'<EOL><DEDENT>file_path_from_root = re.sub('<STR_LIT>' + _root + suffix, '<STR_LIT>', file_path_from_root)<EOL><DEDENT>return re.sub(r'<STR_LIT>', '<STR_LIT:_>', file_path_from_root).upper() + '<STR_LIT:_>'<EOL>

Returns the CPP variable that should be used as a header guard.

    Args:
      filename: The name of a C++ header file.

    Returns:
      The CPP variable that should be used as a header guard in the
      named file.


def InTemplateArgumentList(self, clean_lines, linenum, pos):

while linenum < clean_lines.NumLines():<EOL><INDENT>line = clean_lines.elided[linenum]<EOL>match = Match(r'<STR_LIT>', line[pos:])<EOL>if not match:<EOL><INDENT>linenum += <NUM_LIT:1><EOL>pos = <NUM_LIT:0><EOL>continue<EOL><DEDENT>token = match.group(<NUM_LIT:1>)<EOL>pos += len(match.group(<NUM_LIT:0>))<EOL>if token in ('<STR_LIT:{>', '<STR_LIT:}>', '<STR_LIT:;>'): return False<EOL>if token in ('<STR_LIT:>>', '<STR_LIT:=>', '<STR_LIT:[>', '<STR_LIT:]>', '<STR_LIT:.>'): return True<EOL>if token != '<STR_LIT:<>':<EOL><INDENT>pos += <NUM_LIT:1><EOL>if pos >= len(line):<EOL><INDENT>linenum += <NUM_LIT:1><EOL>pos = <NUM_LIT:0><EOL><DEDENT>continue<EOL><DEDENT>(_, end_line, end_pos) = CloseExpression(clean_lines, linenum, pos - <NUM_LIT:1>)<EOL>if end_pos < <NUM_LIT:0>:<EOL><INDENT>return False<EOL><DEDENT>linenum = end_line<EOL>pos = end_pos<EOL><DEDENT>return False<EOL>

Check if current position is inside template argument list.

        Args:
          clean_lines: A CleansedLines instance containing the file.
          linenum: The number of the line to check.
          pos: position just after the suspected template argument.
        Returns:
          True if (linenum, pos) is inside template arguments.


def CheckForFunctionLengths(filename, clean_lines, linenum,<EOL>function_state, error):

lines = clean_lines.lines<EOL>line = lines[linenum]<EOL>joined_line = '<STR_LIT>'<EOL>starting_func = False<EOL>regexp = r'<STR_LIT>'  <EOL>match_result = Match(regexp, line)<EOL>if match_result:<EOL><INDENT>function_name = match_result.group(<NUM_LIT:1>).split()[-<NUM_LIT:1>]<EOL>if function_name == '<STR_LIT>' or function_name == '<STR_LIT>' or (<EOL>not Match(r'<STR_LIT>', function_name)):<EOL><INDENT>starting_func = True<EOL><DEDENT><DEDENT>if starting_func:<EOL><INDENT>body_found = False<EOL>for start_linenum in range(linenum, clean_lines.NumLines()):<EOL><INDENT>start_line = lines[start_linenum]<EOL>joined_line += '<STR_LIT:U+0020>' + start_line.lstrip()<EOL>if Search(r'<STR_LIT>', start_line):  <EOL><INDENT>body_found = True<EOL>break                              <EOL><DEDENT>elif Search(r'<STR_LIT:{>', start_line):<EOL><INDENT>body_found = True<EOL>function = Search(r'<STR_LIT>', line).group(<NUM_LIT:1>)<EOL>if Match(r'<STR_LIT>', function):    <EOL><INDENT>parameter_regexp = Search(r'<STR_LIT>', joined_line)<EOL>if parameter_regexp:             <EOL><INDENT>function += parameter_regexp.group(<NUM_LIT:1>)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>function += '<STR_LIT>'<EOL><DEDENT>function_state.Begin(function)<EOL>break<EOL><DEDENT><DEDENT>if not body_found:<EOL><INDENT>error(filename, linenum, '<STR_LIT>', <NUM_LIT:5>,<EOL>'<STR_LIT>')<EOL><DEDENT><DEDENT>elif Match(r'<STR_LIT>', line):  <EOL><INDENT>function_state.Check(error, filename, linenum)<EOL>function_state.End()<EOL><DEDENT>elif not Match(r'<STR_LIT>', line):<EOL><INDENT>function_state.Count()<EOL><DEDENT>

Reports for long function bodies.

    For an overview why this is done, see:
    https://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Write_Short_Functions

    Uses a simplistic algorithm assuming other style guidelines
    (especially spacing) are followed.
    Only checks unindented functions, so class members are unchecked.
    Trivial bodies are unchecked, so constructors with huge initializer lists
    may be missed.
    Blank/comment lines are not counted so as to avoid encouraging the removal
    of vertical space and comments just to get through a lint check.
    NOLINT *on the last line of a function* disables this check.

    Args:
      filename: The name of the current file.
      clean_lines: A CleansedLines instance containing the file.
      linenum: The number of the line to check.
      function_state: Current function name and lines in body so far.
      error: The function to call with any errors found.


def Error(filename, linenum, category, confidence, message):

if _ShouldPrintError(category, confidence, linenum):<EOL><INDENT>_cpplint_state.IncrementErrorCount(category)<EOL>if _cpplint_state.output_format == '<STR_LIT>':<EOL><INDENT>_cpplint_state.PrintError('<STR_LIT>' % (<EOL>filename, linenum, message, category, confidence))<EOL><DEDENT>elif _cpplint_state.output_format == '<STR_LIT>':<EOL><INDENT>sys.stderr.write('<STR_LIT>' % (<EOL>filename, linenum, message, category, confidence))<EOL><DEDENT>elif _cpplint_state.output_format == '<STR_LIT>':<EOL><INDENT>_cpplint_state.AddJUnitFailure(filename, linenum, message, category,<EOL>confidence)<EOL><DEDENT>else:<EOL><INDENT>final_message = '<STR_LIT>' % (<EOL>filename, linenum, message, category, confidence)<EOL>sys.stderr.write(final_message)<EOL><DEDENT><DEDENT>

Logs the fact we've found a lint error.

    We log where the error was found, and also our confidence in the error,
    that is, how certain we are this is a legitimate style regression, and
    not a misidentification or a use that's sometimes justified.

    False positives can be suppressed by the use of
    "cpplint(category)"  comments on the offending line.  These are
    parsed into _error_suppressions.

    Args:
      filename: The name of the file containing the error.
      linenum: The number of the line containing the error.
      category: A string used to describe the "category" this bug
        falls under: "whitespace", say, or "runtime".  Categories
        may have a hierarchy separated by slashes: "whitespace/indent".
      confidence: A number from 1-5 representing a confidence score for
        the error, with 5 meaning that we are certain of the problem,
        and 1 meaning that it could be a legitimate construct.
      message: The error message.


commentpos = line.find('<STR_LIT>')<EOL>if commentpos != -<NUM_LIT:1> and not IsCppString(line[:commentpos]):<EOL><INDENT>line = line[:commentpos].rstrip()<EOL><DEDENT>return _RE_PATTERN_CLEANSE_LINE_C_COMMENTS.sub('<STR_LIT>', line)<EOL>

Removes //-comments and single-line C-style /* */ comments.

    Args:
      line: A line of C++ source.

    Returns:
      The line with single-line comments removed.


def Check(self, error, filename, linenum):

if not self.in_a_function:<EOL><INDENT>return<EOL><DEDENT>if Match(r'<STR_LIT>', self.current_function):<EOL><INDENT>base_trigger = self._TEST_TRIGGER<EOL><DEDENT>else:<EOL><INDENT>base_trigger = self._NORMAL_TRIGGER<EOL><DEDENT>trigger = base_trigger * <NUM_LIT:2>**_VerboseLevel()<EOL>if self.lines_in_function > trigger:<EOL><INDENT>error_level = int(math.log(self.lines_in_function / base_trigger, <NUM_LIT:2>))<EOL>if error_level > <NUM_LIT:5>:<EOL><INDENT>error_level = <NUM_LIT:5><EOL><DEDENT>error(filename, linenum, '<STR_LIT>', error_level,<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>'  % (<EOL>self.current_function, self.lines_in_function, trigger))<EOL><DEDENT>

Report if too many lines in function body.

        Args:
          error: The function to call with any errors found.
          filename: The name of the current file.
          linenum: The number of the line to check.


return self.stack and isinstance(self.stack[-<NUM_LIT:1>], _ClassInfo)<EOL>

Check if we are currently one level inside a class or struct declaration.

        Returns:
          True if top of the stack is a class/struct, False otherwise.


while lineix < len(lines):<EOL><INDENT>if lines[lineix].strip().startswith('<STR_LIT>'):<EOL><INDENT>if lines[lineix].strip().find('<STR_LIT>', <NUM_LIT:2>) < <NUM_LIT:0>:<EOL><INDENT>return lineix<EOL><DEDENT><DEDENT>lineix += <NUM_LIT:1><EOL><DEDENT>return len(lines)<EOL>

Find the beginning marker for a multiline comment.


self.error_count = <NUM_LIT:0><EOL>self.errors_by_category = {}<EOL>

Sets the module's error statistic back to zero.


def _IsType(clean_lines, nesting_state, expr):

<EOL>last_word = Match(r'<STR_LIT>', expr)<EOL>if last_word:<EOL><INDENT>token = last_word.group(<NUM_LIT:1>)<EOL><DEDENT>else:<EOL><INDENT>token = expr<EOL><DEDENT>if _TYPES.match(token):<EOL><INDENT>return True<EOL><DEDENT>typename_pattern = (r'<STR_LIT>' + re.escape(token) +<EOL>r'<STR_LIT>')<EOL>block_index = len(nesting_state.stack) - <NUM_LIT:1><EOL>while block_index >= <NUM_LIT:0>:<EOL><INDENT>if isinstance(nesting_state.stack[block_index], _NamespaceInfo):<EOL><INDENT>return False<EOL><DEDENT>last_line = nesting_state.stack[block_index].starting_linenum<EOL>next_block_start = <NUM_LIT:0><EOL>if block_index > <NUM_LIT:0>:<EOL><INDENT>next_block_start = nesting_state.stack[block_index - <NUM_LIT:1>].starting_linenum<EOL><DEDENT>first_line = last_line<EOL>while first_line >= next_block_start:<EOL><INDENT>if clean_lines.elided[first_line].find('<STR_LIT>') >= <NUM_LIT:0>:<EOL><INDENT>break<EOL><DEDENT>first_line -= <NUM_LIT:1><EOL><DEDENT>if first_line < next_block_start:<EOL><INDENT>block_index -= <NUM_LIT:1><EOL>continue<EOL><DEDENT>for i in xrange(first_line, last_line + <NUM_LIT:1>, <NUM_LIT:1>):<EOL><INDENT>if Search(typename_pattern, clean_lines.elided[i]):<EOL><INDENT>return True<EOL><DEDENT><DEDENT>block_index -= <NUM_LIT:1><EOL><DEDENT>return False<EOL>

Check if expression looks like a type name, returns true if so.

    Args:
      clean_lines: A CleansedLines instance containing the file.
      nesting_state: A NestingState instance which maintains information about
                     the current stack of nested blocks being parsed.
      expr: The expression to check.
    Returns:
      True, if token looks like a type.


return (not self.stack) or self.stack[-<NUM_LIT:1>].seen_open_brace<EOL>

Check if we have seen the opening brace for the innermost block.

        Returns:
          True if we have seen the opening brace, False if the innermost
          block is still expecting an opening brace.


def CheckBegin(self, filename, clean_lines, linenum, error):

pass<EOL>

Run checks that applies to text up to the opening brace.

        This is mostly for checking the text after the class identifier
        and the "{", usually where the base class is specified.  For other
        blocks, there isn't much to check, so we always pass.

        Args:
          filename: The name of the current file.
          clean_lines: A CleansedLines instance containing the file.
          linenum: The number of the line to check.
          error: The function to call with any errors found.


def get_http_response(self, server_host_port, path):

for _ in range(<NUM_LIT:0>, RETRY_ATTEMPTS):<EOL><INDENT>try:<EOL><INDENT>connection = HTTPConnection(server_host_port)<EOL>connection.request('<STR_LIT:GET>', path)<EOL>response = connection.getresponse()<EOL>return response<EOL><DEDENT>except Exception:<EOL><INDENT>time.sleep(RETRY_INTERVAL)<EOL>continue<EOL><DEDENT><DEDENT>raise status.TestFailure("<STR_LIT>" % RETRY_ATTEMPTS)<EOL>


try:<EOL><INDENT>if not os.path.exists(self.file_path):<EOL><INDENT>raise status.TestFailure("<STR_LIT>" % self.file_path)<EOL><DEDENT>else:<EOL><INDENT>with open(self.file_path, "<STR_LIT:r>") as expected_result_file:<EOL><INDENT>return expected_result_file.read().rstrip()<EOL><DEDENT><DEDENT><DEDENT>except Exception as e:<EOL><INDENT>raise status.TestFailure("<STR_LIT>" % self.file_path, e)<EOL><DEDENT>

Read expected result from the expected result file


actual_nodes = dict()<EOL>actual_links = dict()<EOL>for bolt in actual_results.topology.bolts:<EOL><INDENT>name = bolt.comp.name<EOL>if name not in actual_links:<EOL><INDENT>actual_links[name] = set()<EOL><DEDENT>for input in bolt.inputs:<EOL><INDENT>actual_links[name].add(input.stream.component_name)<EOL><DEDENT><DEDENT>for instance in actual_results.instances:<EOL><INDENT>name = instance.info.component_name<EOL>if name not in actual_nodes:<EOL><INDENT>actual_nodes[name] = <NUM_LIT:0><EOL><DEDENT>else:<EOL><INDENT>actual_nodes[name] += <NUM_LIT:1><EOL><DEDENT><DEDENT>return actual_nodes, actual_links<EOL>

Parse protobuf messege and generate actual_nodes and actual_links


expected_result = self.topology_structure_expected_results_handler.fetch_results()<EOL>actual_result = self.topology_structure_actual_results_handler.fetch_cur_pplan()<EOL>self.topology_structure_actual_results_handler.stop_state_mgr()<EOL>decoder = json.JSONDecoder(strict=False)<EOL>expected_results = decoder.decode(expected_result)<EOL>return self._compare(expected_results, actual_result)<EOL>

Checks the topology graph structure from zk with the expected results from local file


expected_nodes = dict()<EOL>expected_links = dict()<EOL>for bolt in expected_results["<STR_LIT>"]["<STR_LIT>"]:<EOL><INDENT>name = bolt["<STR_LIT>"]["<STR_LIT:name>"]<EOL>if name not in expected_links:<EOL><INDENT>expected_links[name] = set()<EOL><DEDENT>for input in bolt["<STR_LIT>"]:<EOL><INDENT>expected_links[name].add(input["<STR_LIT>"]["<STR_LIT>"])<EOL><DEDENT><DEDENT>for instance in expected_results["<STR_LIT>"]:<EOL><INDENT>name = instance["<STR_LIT:info>"]["<STR_LIT>"]<EOL>if name not in expected_nodes:<EOL><INDENT>expected_nodes[name] = <NUM_LIT:0><EOL><DEDENT>else:<EOL><INDENT>expected_nodes[name] += <NUM_LIT:1><EOL><DEDENT><DEDENT>return  expected_nodes, expected_links<EOL>

Parse JSON file and generate expected_nodes and expected_links


log.configure(level=logging.DEBUG)<EOL>conf_file = DEFAULT_TEST_CONF_FILE<EOL>conf_string = pkgutil.get_data(__name__, conf_file)<EOL>decoder = json.JSONDecoder(strict=False)<EOL>conf = decoder.decode(conf_string)<EOL>parser = argparse.ArgumentParser(description='<STR_LIT>')<EOL>parser.add_argument('<STR_LIT>', '<STR_LIT>', dest='<STR_LIT>',<EOL>default=conf['<STR_LIT>'])<EOL>parser.add_argument('<STR_LIT>', '<STR_LIT>', dest='<STR_LIT>')<EOL>parser.add_argument('<STR_LIT>', '<STR_LIT>', dest='<STR_LIT>', default=conf['<STR_LIT>'])<EOL>parser.add_argument('<STR_LIT>', '<STR_LIT>', dest='<STR_LIT>', default=conf['<STR_LIT>'])<EOL>parser.add_argument('<STR_LIT>', '<STR_LIT>', dest='<STR_LIT>', default=conf['<STR_LIT>'])<EOL>parser.add_argument('<STR_LIT>', '<STR_LIT>', dest='<STR_LIT>')<EOL>parser.add_argument('<STR_LIT>', '<STR_LIT>', dest='<STR_LIT>', type=int,<EOL>default=conf['<STR_LIT>'])<EOL>parser.add_argument('<STR_LIT>', '<STR_LIT>', dest='<STR_LIT>')<EOL>parser.add_argument('<STR_LIT>', '<STR_LIT>', dest='<STR_LIT>', default=None)<EOL>parser.add_argument('<STR_LIT>', '<STR_LIT>', dest='<STR_LIT>', default=None)<EOL>parser.add_argument('<STR_LIT>', '<STR_LIT>', dest='<STR_LIT>',<EOL>default=conf['<STR_LIT>'])<EOL>parser.add_argument('<STR_LIT>', '<STR_LIT>', dest='<STR_LIT>', default=<NUM_LIT:1>)<EOL>args, unknown_args = parser.parse_known_args()<EOL>if unknown_args:<EOL><INDENT>logging.error('<STR_LIT>', sys.argv[<NUM_LIT:0>], unknown_args[<NUM_LIT:0>])<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>tests_start_time = int(time.time())<EOL>run_tests(conf, args)<EOL>total = len(failures) + len(successes)<EOL>logging.info("<STR_LIT>" % (int(time.time()) - tests_start_time))<EOL>if not failures:<EOL><INDENT>logging.info("<STR_LIT>", len(successes))<EOL>for test in successes:<EOL><INDENT>logging.info("<STR_LIT>", ("<STR_LIT>" % test[<NUM_LIT:1>]).ljust(<NUM_LIT:8>), test[<NUM_LIT:0>])<EOL><DEDENT>sys.exit(<NUM_LIT:0>)<EOL><DEDENT>else:<EOL><INDENT>logging.error("<STR_LIT>", len(failures), total)<EOL>for test in failures:<EOL><INDENT>logging.error("<STR_LIT>", ("<STR_LIT>" % test[<NUM_LIT:1>]).ljust(<NUM_LIT:8>), test[<NUM_LIT:0>])<EOL><DEDENT>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>


log.configure(level=logging.DEBUG)<EOL>conf_file = DEFAULT_TEST_CONF_FILE<EOL>conf_string = pkgutil.get_data(__name__, conf_file)<EOL>decoder = json.JSONDecoder(strict=False)<EOL>conf = decoder.decode(conf_string)<EOL>args = dict()<EOL>home_directory = os.path.expanduser("<STR_LIT>")<EOL>args['<STR_LIT>'] = conf['<STR_LIT>']<EOL>args['<STR_LIT>'] = conf['<STR_LIT>']['<STR_LIT>']<EOL>args['<STR_LIT>'] = conf['<STR_LIT>']['<STR_LIT>']<EOL>args['<STR_LIT>'] = os.path.join(<EOL>home_directory,<EOL>"<STR_LIT>",<EOL>"<STR_LIT>",<EOL>conf['<STR_LIT>'],<EOL>getpass.getuser(),<EOL>args['<STR_LIT>']<EOL>)<EOL>args['<STR_LIT>'] = os.path.expanduser(conf['<STR_LIT>'])<EOL>args['<STR_LIT>'] = os.path.expanduser(conf['<STR_LIT>'])<EOL>args['<STR_LIT>'] = _random_port()<EOL>args['<STR_LIT>'] = os.path.join(args['<STR_LIT>'], conf['<STR_LIT>']['<STR_LIT>'])<EOL>args['<STR_LIT>'] = os.path.join(args['<STR_LIT>'], conf['<STR_LIT>']['<STR_LIT>'])<EOL>args['<STR_LIT>'] = conf['<STR_LIT>']<EOL>test_classes = TEST_CLASSES<EOL>if len(sys.argv) > <NUM_LIT:1>:<EOL><INDENT>first_arg = sys.argv[<NUM_LIT:1>]<EOL>class_tokens = first_arg.split("<STR_LIT:.>")<EOL>if first_arg == "<STR_LIT>" or len(class_tokens) < <NUM_LIT:2>:<EOL><INDENT>usage()<EOL><DEDENT>import importlib<EOL>package_tokens = class_tokens[:-<NUM_LIT:1>]<EOL>test_class = class_tokens[-<NUM_LIT:1>]<EOL>if len(package_tokens) == <NUM_LIT:1>: <EOL><INDENT>test_module = "<STR_LIT>" + package_tokens[<NUM_LIT:0>]<EOL><DEDENT>else:<EOL><INDENT>test_module = '<STR_LIT:.>'.join(package_tokens)<EOL><DEDENT>logging.info("<STR_LIT>", test_module)<EOL>logging.info("<STR_LIT>", test_class)<EOL>test_classes = [getattr(importlib.import_module(test_module), test_class)]<EOL><DEDENT>start_time = time.time()<EOL>(successes, failures) = run_tests(test_classes, args)<EOL>elapsed_time = time.time() - start_time<EOL>total = len(failures) + len(successes)<EOL>if not failures:<EOL><INDENT>logging.info("<STR_LIT>", len(successes))<EOL>logging.info("<STR_LIT>", elapsed_time)<EOL>sys.exit(<NUM_LIT:0>)<EOL><DEDENT>else:<EOL><INDENT>logging.error("<STR_LIT>", len(failures), total)<EOL>for test in failures:<EOL><INDENT>logging.error("<STR_LIT>", test)<EOL><DEDENT>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>


<EOL>processes = subprocess.check_output(['<STR_LIT>', '<STR_LIT>', '<STR_LIT>'])<EOL>processes = processes.split('<STR_LIT:\n>')<EOL>processes = processes[<NUM_LIT:1>:] <EOL>process_list = []<EOL>for process in processes:<EOL><INDENT>if process == '<STR_LIT>':<EOL><INDENT>continue<EOL><DEDENT>pretuple = process.split('<STR_LIT:U+0020>', <NUM_LIT:1>)<EOL>process_list.append(ProcessTuple(pretuple[<NUM_LIT:0>], pretuple[<NUM_LIT:1>]))<EOL><DEDENT>return process_list<EOL>

returns a list of process tuples (pid, cmd)
This only applies only for local scheduler as it uses the ps command
and assumes the topology will be running on different processes on same machine


expected_result = "<STR_LIT>"<EOL>actual_result = "<STR_LIT>"<EOL>retries_left = RETRY_COUNT<EOL>_sleep("<STR_LIT>" % self.testname, RETRY_INTERVAL)<EOL>while retries_left > <NUM_LIT:0>:<EOL><INDENT>retries_left -= <NUM_LIT:1><EOL>try:<EOL><INDENT>with open(self.params['<STR_LIT>'], '<STR_LIT:r>') as f:<EOL><INDENT>expected_result = f.read()<EOL><DEDENT>with open(self.params['<STR_LIT>'], '<STR_LIT:r>') as g:<EOL><INDENT>actual_result = g.read()<EOL><DEDENT><DEDENT>except Exception as e:<EOL><INDENT>message ="<STR_LIT>" % self.testname<EOL>if retries_left == <NUM_LIT:0>:<EOL><INDENT>raise status.TestFailure(message, e)<EOL><DEDENT>logging.error(message, e)<EOL><DEDENT>expected_sorted = sorted(expected_result.split('<STR_LIT:\n>'))<EOL>actual_sorted = sorted(actual_result.split('<STR_LIT:\n>'))<EOL>if expected_sorted == actual_sorted:<EOL><INDENT>break<EOL><DEDENT>if retries_left > <NUM_LIT:0>:<EOL><INDENT>expected_result = "<STR_LIT>"<EOL>actual_result = "<STR_LIT>"<EOL>expected_sorted = []<EOL>actual_sorted = []<EOL>logging.info("<STR_LIT>"+ "<STR_LIT>",<EOL>self.testname, RETRY_COUNT - retries_left, RETRY_COUNT, RETRY_INTERVAL)<EOL>time.sleep(RETRY_INTERVAL)<EOL><DEDENT><DEDENT>if actual_sorted == expected_sorted:<EOL><INDENT>success = status.TestSuccess(<EOL>"<STR_LIT>" % self.testname)<EOL>logging.info("<STR_LIT>", actual_sorted)<EOL>logging.info("<STR_LIT>", expected_sorted)<EOL>return success<EOL><DEDENT>else:<EOL><INDENT>failure = status.TestFailure(<EOL>"<STR_LIT>" % self.testname)<EOL>logging.info("<STR_LIT>", actual_sorted)<EOL>logging.info("<STR_LIT>", expected_sorted)<EOL>raise failure<EOL><DEDENT>

get actual and expected result.
        retry if results are not equal a predesignated amount of times


def emit(self, tup, tup_id=None, stream=Stream.DEFAULT_STREAM_ID,<EOL>direct_task=None, need_task_ids=None):

<EOL>self.tuples_to_complete += <NUM_LIT:1><EOL>if tup_id is None:<EOL><INDENT>Log.info("<STR_LIT>" % str(tup))<EOL>_tup_id = integ_const.INTEGRATION_TEST_MOCK_MESSAGE_ID<EOL><DEDENT>else:<EOL><INDENT>_tup_id = tup_id<EOL><DEDENT>super(IntegrationTestSpout, self).emit(tup, _tup_id, stream, direct_task, need_task_ids)<EOL>

Emits from this integration test spout

        Overriden method which will be called when user's spout calls emit()


def add_bolt(self, name, bolt_cls, par, inputs, config=None, optional_outputs=None):

assert isinstance(inputs, dict)<EOL>user_spec = bolt_cls.spec(name)<EOL>bolt_classpath = user_spec.python_class_path<EOL>if hasattr(bolt_cls, '<STR_LIT>'):<EOL><INDENT>user_outputs = bolt_cls.outputs<EOL><DEDENT>else:<EOL><INDENT>user_outputs = []<EOL><DEDENT>if optional_outputs is not None:<EOL><INDENT>user_outputs.extend(optional_outputs)<EOL><DEDENT>if config is None:<EOL><INDENT>_config = {}<EOL><DEDENT>else:<EOL><INDENT>_config = config<EOL><DEDENT>test_spec = IntegrationTestBolt.spec(name, par, inputs, _config,<EOL>user_bolt_classpath=bolt_classpath,<EOL>user_output_fields=user_outputs)<EOL>self.add_spec(test_spec)<EOL>self.bolts[name] = test_spec<EOL>return test_spec<EOL>

Add an integration_test bolt

        Only dict based inputs is supported


def _add_all_grouping(self, child, parent, stream_id):

<EOL>child_component_spec = self.bolts[child]<EOL>child_inputs = child_component_spec.inputs<EOL>if parent in self.bolts:<EOL><INDENT>parent_component_spec = self.bolts[parent]<EOL><DEDENT>else:<EOL><INDENT>parent_component_spec = self.spouts[parent]<EOL><DEDENT>if stream_id == Stream.DEFAULT_STREAM_ID:<EOL><INDENT>child_inputs[parent_component_spec] = Grouping.ALL<EOL><DEDENT>else:<EOL><INDENT>child_inputs[parent_component_spec[stream_id]] = Grouping.ALL<EOL><DEDENT>

Adds all grouping between child component and parent component with a given stream id

        :type child: str
        :param child: child's component name
        :type parent: str
        :param parent: parent's component name
        :type stream_id: str
        :param stream_id: stream id


topology = protoTopology.Topology()<EOL>topology.id = "<STR_LIT>"<EOL>topology.name = "<STR_LIT>"<EOL>stream1 = protoTopology.StreamId()<EOL>stream1.id = "<STR_LIT>"<EOL>stream1.component_name = "<STR_LIT>"<EOL>stream2 = protoTopology.StreamId()<EOL>stream2.id = "<STR_LIT>"<EOL>stream2.component_name = "<STR_LIT>"<EOL>stream3 = protoTopology.StreamId()<EOL>stream3.id = "<STR_LIT>"<EOL>stream3.component_name = "<STR_LIT>"<EOL>stream4 = protoTopology.StreamId()<EOL>stream4.id = "<STR_LIT>"<EOL>stream4.component_name = "<STR_LIT>"<EOL>spout1 = self.create_mock_spout("<STR_LIT>",<EOL>[stream1, stream2],<EOL>spout_parallelism)<EOL>topology.spouts.extend([spout1])<EOL>bolt1 = self.create_mock_bolt("<STR_LIT>",<EOL>[stream1],<EOL>[stream3],<EOL>bolt1_parallelism)<EOL>bolt2 = self.create_mock_bolt("<STR_LIT>",<EOL>[stream2],<EOL>[stream4],<EOL>bolt2_parallelism)<EOL>bolt3 = self.create_mock_bolt("<STR_LIT>",<EOL>[stream3, stream4],<EOL>[],<EOL>bolt3_parallelism)<EOL>topology.bolts.extend([bolt1, bolt2, bolt3])<EOL>return topology<EOL>

Medium topology is a three stage topology
with one spout, two mid stage bolts, and one
last stage bolt.
S -str1-> B1 -str3-> B3
S -str2-> B2 -str4-> B3


self.statemgr_config.set_state_locations(self.configs[STATEMGRS_KEY])<EOL>if EXTRA_LINKS_KEY in self.configs:<EOL><INDENT>for extra_link in self.configs[EXTRA_LINKS_KEY]:<EOL><INDENT>self.extra_links.append(self.validate_extra_link(extra_link))<EOL><DEDENT><DEDENT>


<EOL>valid_parameters = {<EOL>"<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": "<STR_LIT>",<EOL>"<STR_LIT>": "<STR_LIT:user>",<EOL>}<EOL>dummy_formatted_url = url_format<EOL>for key, value in valid_parameters.items():<EOL><INDENT>dummy_formatted_url = dummy_formatted_url.replace(key, value)<EOL><DEDENT>if '<STR_LIT:$>' in dummy_formatted_url:<EOL><INDENT>raise Exception("<STR_LIT>" % (url_format))<EOL><DEDENT>return url_format<EOL>


if self.physical_plan:<EOL><INDENT>return list(self.physical_plan.topology.spouts)<EOL><DEDENT>return []<EOL>

Returns a list of Spout (proto) messages


if not physical_plan:<EOL><INDENT>self.physical_plan = None<EOL>self.id = None<EOL><DEDENT>else:<EOL><INDENT>self.physical_plan = physical_plan<EOL>self.id = physical_plan.topology.id<EOL><DEDENT>self.trigger_watches()<EOL>


status = None<EOL>if self.physical_plan and self.physical_plan.topology:<EOL><INDENT>status = self.physical_plan.topology.state<EOL><DEDENT>if status == <NUM_LIT:1>:<EOL><INDENT>return "<STR_LIT>"<EOL><DEDENT>elif status == <NUM_LIT:2>:<EOL><INDENT>return "<STR_LIT>"<EOL><DEDENT>elif status == <NUM_LIT:3>:<EOL><INDENT>return "<STR_LIT>"<EOL><DEDENT>else:<EOL><INDENT>return "<STR_LIT>"<EOL><DEDENT>

Get the current state of this topology.
The state values are from the topology.proto
RUNNING = 1, PAUSED = 2, KILLED = 3
if the state is None "Unknown" is returned.


<EOL>Log.info("<STR_LIT>" + str(uid))<EOL>self.watches.pop(uid, None)<EOL>

Unregister the watch with the given UUID.


num = <NUM_LIT:0><EOL>components = self.spouts() + self.bolts()<EOL>for component in components:<EOL><INDENT>config = component.comp.config<EOL>for kvs in config.kvs:<EOL><INDENT>if kvs.key == api_constants.TOPOLOGY_COMPONENT_PARALLELISM:<EOL><INDENT>num += int(kvs.value)<EOL>break<EOL><DEDENT><DEDENT><DEDENT>return num<EOL>


if not execution_state:<EOL><INDENT>self.execution_state = None<EOL>self.cluster = None<EOL>self.environ = None<EOL><DEDENT>else:<EOL><INDENT>self.execution_state = execution_state<EOL>cluster, environ = self.get_execution_state_dc_environ(execution_state)<EOL>self.cluster = cluster<EOL>self.environ = environ<EOL>self.zone = cluster<EOL><DEDENT>self.trigger_watches()<EOL>


to_remove = []<EOL>for uid, callback in self.watches.items():<EOL><INDENT>try:<EOL><INDENT>callback(self)<EOL><DEDENT>except Exception as e:<EOL><INDENT>Log.error("<STR_LIT>" + str(e))<EOL>Log.debug(traceback.format_exc())<EOL>to_remove.append(uid)<EOL><DEDENT><DEDENT>for uid in to_remove:<EOL><INDENT>self.unregister_watch(uid)<EOL><DEDENT>

Call all the callbacks.
If any callback raises an Exception,
unregister the corresponding watch.


try:<EOL><INDENT>_, res = self._read_and_exec_opcode(ident=<NUM_LIT:0>)<EOL>position_bak = self.object_stream.tell()<EOL>the_rest = self.object_stream.read()<EOL>if len(the_rest):<EOL><INDENT>log_error("<STR_LIT>" % len(the_rest))<EOL>log_debug(self._create_hexdump(the_rest))<EOL><DEDENT>else:<EOL><INDENT>log_debug("<STR_LIT>")<EOL><DEDENT>self.object_stream.seek(position_bak)<EOL>return res<EOL><DEDENT>except Exception:<EOL><INDENT>self._oops_dump_state()<EOL>raise<EOL><DEDENT>


return self.classdesc<EOL>


Log.error("<STR_LIT:U+0020>" * (ident * <NUM_LIT:2>) + str(message))<EOL>


def do_classdesc(self, parent=None, ident=<NUM_LIT:0>):

<EOL>clazz = JavaClass()<EOL>log_debug("<STR_LIT>", ident)<EOL>ba = self._readString()<EOL>clazz.name = ba<EOL>log_debug("<STR_LIT>" % ba, ident)<EOL>(serialVersionUID, newHandle, classDescFlags) = self._readStruct("<STR_LIT>")<EOL>clazz.serialVersionUID = serialVersionUID<EOL>clazz.flags = classDescFlags<EOL>self._add_reference(clazz)<EOL>log_debug("<STR_LIT>" % (serialVersionUID, newHandle, classDescFlags), ident)<EOL>(length, ) = self._readStruct("<STR_LIT>")<EOL>log_debug("<STR_LIT>" % length, ident)<EOL>clazz.fields_names = []<EOL>clazz.fields_types = []<EOL>for _ in range(length):<EOL><INDENT>(typecode, ) = self._readStruct("<STR_LIT>")<EOL>field_name = self._readString()<EOL>field_type = None<EOL>field_type = self._convert_char_to_type(typecode)<EOL>if field_type == self.TYPE_ARRAY:<EOL><INDENT>_, field_type = self._read_and_exec_opcode(<EOL>ident=ident+<NUM_LIT:1>, expect=[self.TC_STRING, self.TC_REFERENCE])<EOL>assert isinstance(field_type, str)<EOL>


self.tracker = tracker<EOL>


try:<EOL><INDENT>cluster = self.get_argument_cluster()<EOL>role = self.get_argument_role()<EOL>environ = self.get_argument_environ()<EOL>topology_name = self.get_argument_topology()<EOL>instance = self.get_argument_instance()<EOL>topology_info = self.tracker.getTopologyInfo(topology_name, cluster, role, environ)<EOL>ret = yield self.getInstanceJstack(topology_info, instance)<EOL>self.write_success_response(ret)<EOL><DEDENT>except Exception as e:<EOL><INDENT>Log.debug(traceback.format_exc())<EOL>self.write_error_response(e)<EOL><DEDENT>


try:<EOL><INDENT>topology = self.get_argument(constants.PARAM_TOPOLOGY)<EOL>return topology<EOL><DEDENT>except tornado.web.MissingArgumentError as e:<EOL><INDENT>raise Exception(e.log_message)<EOL><DEDENT>

Helper function to get topology argument.
Raises exception if argument is missing.
Returns the topology argument.


try:<EOL><INDENT>starttime = self.get_argument(constants.PARAM_STARTTIME)<EOL>return starttime<EOL><DEDENT>except tornado.web.MissingArgumentError as e:<EOL><INDENT>raise Exception(e.log_message)<EOL><DEDENT>

Helper function to get starttime argument.
Raises exception if argument is missing.
Returns the starttime argument.


try:<EOL><INDENT>component = self.get_argument(constants.PARAM_COMPONENT)<EOL>return component<EOL><DEDENT>except tornado.web.MissingArgumentError as e:<EOL><INDENT>raise Exception(e.log_message)<EOL><DEDENT>

Helper function to get component argument.
Raises exception if argument is missing.
Returns the component argument.


try:<EOL><INDENT>endtime = self.get_argument(constants.PARAM_ENDTIME)<EOL>return endtime<EOL><DEDENT>except tornado.web.MissingArgumentError as e:<EOL><INDENT>raise Exception(e.log_message)<EOL><DEDENT>

Helper function to get endtime argument.
Raises exception if argument is missing.
Returns the endtime argument.


self.basehandler_starttime = time.time()<EOL>

Used for timing. Sets the basehandler_starttime to current time, and
is used when writing the response back.
Subclasses of BaseHandler must never use self.write, but instead use
self.write_error or self.write_result methods to correctly include
the timing.


def validateInterval(self, startTime, endTime):

start = int(startTime)<EOL>end = int(endTime)<EOL>if start > end:<EOL><INDENT>raise Exception("<STR_LIT>")<EOL><DEDENT>

Helper function to validate interval.
An interval is valid if starttime and endtime are integrals,
and starttime is less than the endtime.
Raises exception if interval is not valid.


try:<EOL><INDENT>return self.get_argument(constants.PARAM_CLUSTER)<EOL><DEDENT>except tornado.web.MissingArgumentError as e:<EOL><INDENT>raise Exception(e.log_message)<EOL><DEDENT>

Helper function to get request argument.
Raises exception if argument is missing.
Returns the cluster argument.


self.set_header("<STR_LIT>", "<STR_LIT:*>")<EOL>

Allow any domain to make queries to tracker.


try:<EOL><INDENT>return self.get_argument(constants.PARAM_ROLE, default=None)<EOL><DEDENT>except tornado.web.MissingArgumentError as e:<EOL><INDENT>raise Exception(e.log_message)<EOL><DEDENT>

Helper function to get request argument.
Raises exception if argument is missing.
Returns the role argument.


try:<EOL><INDENT>metricnames = self.get_arguments(constants.PARAM_METRICNAME)<EOL>if not metricnames:<EOL><INDENT>raise tornado.web.MissingArgumentError(constants.PARAM_METRICNAME)<EOL><DEDENT>return metricnames<EOL><DEDENT>except tornado.web.MissingArgumentError as e:<EOL><INDENT>raise Exception(e.log_message)<EOL><DEDENT>

Helper function to get metricname arguments.
Notice that it is get_argument"s" variation, which means that this can be repeated.
Raises exception if argument is missing.
Returns a list of metricname arguments


self.write(tornado.escape.json_encode(response))<EOL>self.set_header("<STR_LIT:Content-Type>", "<STR_LIT:application/json>")<EOL>


try:<EOL><INDENT>instance = self.get_argument(constants.PARAM_INSTANCE)<EOL>return instance<EOL><DEDENT>except tornado.web.MissingArgumentError as e:<EOL><INDENT>raise Exception(e.log_message)<EOL><DEDENT>

Helper function to get instance argument.
Raises exception if argument is missing.
Returns the instance argument.


try:<EOL><INDENT>cluster = self.get_argument_cluster()<EOL>role = self.get_argument_role()<EOL>environ = self.get_argument_environ()<EOL>topology_name = self.get_argument_topology()<EOL>container = self.get_argument(constants.PARAM_CONTAINER)<EOL>path = self.get_argument(constants.PARAM_PATH)<EOL>offset = self.get_argument_offset()<EOL>length = self.get_argument_length()<EOL>topology_info = self.tracker.getTopologyInfo(topology_name, cluster, role, environ)<EOL>stmgr_id = "<STR_LIT>" + container<EOL>stmgr = topology_info["<STR_LIT>"]["<STR_LIT>"][stmgr_id]<EOL>host = stmgr["<STR_LIT:host>"]<EOL>shell_port = stmgr["<STR_LIT>"]<EOL>file_data_url = "<STR_LIT>" %(host, shell_port, path, offset, length)<EOL>http_client = tornado.httpclient.AsyncHTTPClient()<EOL>response = yield http_client.fetch(file_data_url)<EOL>self.write_success_response(json.loads(response.body))<EOL>self.finish()<EOL><DEDENT>except Exception as e:<EOL><INDENT>Log.debug(traceback.format_exc())<EOL>self.write_error_response(e)<EOL><DEDENT>


try:<EOL><INDENT>cluster = self.get_argument_cluster()<EOL>role = self.get_argument_role()<EOL>environ = self.get_argument_environ()<EOL>topology_name = self.get_argument_topology()<EOL>topology_info = self.tracker.getTopologyInfo(topology_name, cluster, role, environ)<EOL>runtime_state = topology_info["<STR_LIT>"]<EOL>runtime_state["<STR_LIT>"] = topology_info["<STR_LIT>"]["<STR_LIT>"]<EOL>topology = self.tracker.getTopologyByClusterRoleEnvironAndName(<EOL>cluster, role, environ, topology_name)<EOL>reg_summary = yield tornado.gen.Task(self.getStmgrsRegSummary, topology.tmaster)<EOL>for stmgr, reg in reg_summary.items():<EOL><INDENT>runtime_state["<STR_LIT>"].setdefault(stmgr, {})["<STR_LIT>"] = reg<EOL><DEDENT>self.write_success_response(runtime_state)<EOL><DEDENT>except Exception as e:<EOL><INDENT>Log.debug(traceback.format_exc())<EOL>self.write_error_response(e)<EOL><DEDENT>


if not tmaster or not tmaster.host or not tmaster.stats_port:<EOL><INDENT>raise Exception("<STR_LIT>")<EOL><DEDENT>host = tmaster.host<EOL>port = tmaster.stats_port<EOL>metricRequest = tmaster_pb2.MetricRequest()<EOL>metricRequest.component_name = componentName<EOL>if len(instances) > <NUM_LIT:0>:<EOL><INDENT>for instance in instances:<EOL><INDENT>metricRequest.instance_id.append(instance)<EOL><DEDENT><DEDENT>for metricName in metricNames:<EOL><INDENT>metricRequest.metric.append(metricName)<EOL><DEDENT>metricRequest.interval = interval<EOL>metricRequestString = metricRequest.SerializeToString()<EOL>url = "<STR_LIT>".format(host, port)<EOL>request = tornado.httpclient.HTTPRequest(url,<EOL>body=metricRequestString,<EOL>method='<STR_LIT:POST>',<EOL>request_timeout=<NUM_LIT:5>)<EOL>Log.debug("<STR_LIT>")<EOL>Log.debug("<STR_LIT>" + url)<EOL>try:<EOL><INDENT>client = tornado.httpclient.AsyncHTTPClient()<EOL>result = yield client.fetch(request)<EOL>Log.debug("<STR_LIT>")<EOL><DEDENT>except tornado.httpclient.HTTPError as e:<EOL><INDENT>raise Exception(str(e))<EOL><DEDENT>responseCode = result.code<EOL>if responseCode >= <NUM_LIT>:<EOL><INDENT>message = "<STR_LIT>" + responseCode<EOL>Log.error(message)<EOL>raise Exception(message)<EOL><DEDENT>metricResponse = tmaster_pb2.MetricResponse()<EOL>metricResponse.ParseFromString(result.body)<EOL>if metricResponse.status.status == common_pb2.NOTOK:<EOL><INDENT>if metricResponse.status.HasField("<STR_LIT:message>"):<EOL><INDENT>Log.warn("<STR_LIT>", metricResponse.status.message)<EOL><DEDENT><DEDENT>ret = {}<EOL>ret["<STR_LIT>"] = metricResponse.interval<EOL>ret["<STR_LIT>"] = componentName<EOL>ret["<STR_LIT>"] = {}<EOL>for metric in metricResponse.metric:<EOL><INDENT>instance = metric.instance_id<EOL>for im in metric.metric:<EOL><INDENT>metricname = im.name<EOL>value = im.value<EOL>if metricname not in ret["<STR_LIT>"]:<EOL><INDENT>ret["<STR_LIT>"][metricname] = {}<EOL><DEDENT>ret["<STR_LIT>"][metricname][instance] = value<EOL><DEDENT><DEDENT>raise tornado.gen.Return(ret)<EOL>

Get the specified metrics for the given component name of this topology.
Returns the following dict on success:
{
  "metrics": {
    <metricname>: {
      <instance>: <numeric value>,
      <instance>: <numeric value>,
      ...
    }, ...
  },
  "interval": <numeric value>,
  "component": "..."
}

Raises exception on failure.


clusters = [statemgr.name for statemgr in self.tracker.state_managers]<EOL>self.write_success_response(clusters)<EOL>


self.tracker = tracker<EOL>


try:<EOL><INDENT>cluster = self.get_argument_cluster()<EOL>role = self.get_argument_role()<EOL>environ = self.get_argument_environ()<EOL>topology_name = self.get_argument_topology()<EOL>topology_info = self.tracker.getTopologyInfo(topology_name, cluster, role, environ)<EOL>execution_state = topology_info["<STR_LIT>"]<EOL>self.write_success_response(execution_state)<EOL><DEDENT>except Exception as e:<EOL><INDENT>Log.debug(traceback.format_exc())<EOL>self.write_error_response(e)<EOL><DEDENT>


try:<EOL><INDENT>cluster = self.get_argument_cluster()<EOL>role = self.get_argument_role()<EOL>environ = self.get_argument_environ()<EOL>topology_name = self.get_argument_topology()<EOL>topology_info = self.tracker.getTopologyInfo(topology_name, cluster, role, environ)<EOL>packing_plan = topology_info["<STR_LIT>"]<EOL>self.write_success_response(packing_plan)<EOL><DEDENT>except Exception as e:<EOL><INDENT>Log.debug(traceback.format_exc())<EOL>self.write_error_response(e)<EOL><DEDENT>


try:<EOL><INDENT>cluster = self.get_argument_cluster()<EOL>role = self.get_argument_role()<EOL>environ = self.get_argument_environ()<EOL>topology_name = self.get_argument_topology()<EOL>instance = self.get_argument_instance()<EOL>topology_info = self.tracker.getTopologyInfo(topology_name, cluster, role, environ)<EOL>ret = yield self.runInstanceJmap(topology_info, instance)<EOL>self.write_success_response(ret)<EOL><DEDENT>except Exception as e:<EOL><INDENT>Log.debug(traceback.format_exc())<EOL>self.write_error_response(e)<EOL><DEDENT>


@tornado.gen.coroutine<EOL><INDENT>def getComponentException(self, tmaster, component_name, instances=[], callback=None):<DEDENT>

if not tmaster or not tmaster.host or not tmaster.stats_port:<EOL><INDENT>return<EOL><DEDENT>exception_request = tmaster_pb2.ExceptionLogRequest()<EOL>exception_request.component_name = component_name<EOL>if len(instances) > <NUM_LIT:0>:<EOL><INDENT>exception_request.instances.extend(instances)<EOL><DEDENT>request_str = exception_request.SerializeToString()<EOL>port = str(tmaster.stats_port)<EOL>host = tmaster.host<EOL>url = "<STR_LIT>".format(host, port)<EOL>request = tornado.httpclient.HTTPRequest(url,<EOL>body=request_str,<EOL>method='<STR_LIT:POST>',<EOL>request_timeout=<NUM_LIT:5>)<EOL>Log.debug('<STR_LIT>', url)<EOL>try:<EOL><INDENT>client = tornado.httpclient.AsyncHTTPClient()<EOL>result = yield client.fetch(request)<EOL>Log.debug("<STR_LIT>")<EOL><DEDENT>except tornado.httpclient.HTTPError as e:<EOL><INDENT>raise Exception(str(e))<EOL><DEDENT>responseCode = result.code<EOL>if responseCode >= <NUM_LIT>:<EOL><INDENT>message = "<STR_LIT>" + responseCode<EOL>Log.error(message)<EOL>raise tornado.gen.Return({<EOL>"<STR_LIT:message>": message<EOL>})<EOL><DEDENT>exception_response = tmaster_pb2.ExceptionLogResponse()<EOL>exception_response.ParseFromString(result.body)<EOL>if exception_response.status.status == common_pb2.NOTOK:<EOL><INDENT>if exception_response.status.HasField("<STR_LIT:message>"):<EOL><INDENT>raise tornado.gen.Return({<EOL>"<STR_LIT:message>": exception_response.status.message<EOL>})<EOL><DEDENT><DEDENT>ret = []<EOL>for exception_log in exception_response.exceptions:<EOL><INDENT>ret.append({'<STR_LIT>': exception_log.hostname,<EOL>'<STR_LIT>': exception_log.instance_id,<EOL>'<STR_LIT>': exception_log.stacktrace,<EOL>'<STR_LIT>': exception_log.lasttime,<EOL>'<STR_LIT>': exception_log.firsttime,<EOL>'<STR_LIT:count>': str(exception_log.count),<EOL>'<STR_LIT>': exception_log.logging})<EOL><DEDENT>raise tornado.gen.Return(ret)<EOL>

Get all (last 1000) exceptions for 'component_name' of the topology.
Returns an Array of exception logs on success.
Returns json with message on failure.


<EOL>clusters = self.get_arguments(constants.PARAM_CLUSTER)<EOL>environs = self.get_arguments(constants.PARAM_ENVIRON)<EOL>role = self.get_argument_role()<EOL>ret = {}<EOL>topologies = self.tracker.topologies<EOL>for topology in topologies:<EOL><INDENT>cluster = topology.cluster<EOL>environ = topology.environ<EOL>if not cluster or not environ:<EOL><INDENT>continue<EOL><DEDENT>if clusters and cluster not in clusters:<EOL><INDENT>continue<EOL><DEDENT>if environs and environ not in environs:<EOL><INDENT>continue<EOL><DEDENT>if cluster not in ret:<EOL><INDENT>ret[cluster] = {}<EOL><DEDENT>if environ not in ret[cluster]:<EOL><INDENT>ret[cluster][environ] = {}<EOL><DEDENT>try:<EOL><INDENT>topology_info = self.tracker.getTopologyInfo(topology.name, cluster, role, environ)<EOL>if topology_info and "<STR_LIT>" in topology_info:<EOL><INDENT>ret[cluster][environ][topology.name] = topology_info["<STR_LIT>"]<EOL><DEDENT><DEDENT>except Exception:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>self.write_success_response(ret)<EOL>