How to use the pprofile.BaseLineIterator function in pprofile

To help you get started, we’ve selected a few pprofile examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vpelletier / pprofile / pprofile.py View on Github external
def __iter__(self):
        return self

    def next(self):
        lineno = self._lineno
        self._lineno += 1
        return lineno, self._getline(self._filename, lineno, self._global_dict)

if sys.version_info < (3, ):
    import codecs
    # Find coding specification (see PEP-0263)
    _matchCoding = re.compile(
        r'^[ \t\f]*#.*?coding[:=][ \t]*([-_.a-zA-Z0-9]+)',
    ).match
    class LineIterator(BaseLineIterator):
        _encoding = None

        def __init__(self, *args, **kw):
            super(LineIterator, self).__init__(*args, **kw)
            # Identify encoding.
            first_line = self._getline(self._filename, 1, self._global_dict)
            if isinstance(first_line, bytes):
                # BOM - python2 only detects the (discouraged) UTF-8 BOM
                if first_line.startswith(codecs.BOM_UTF8):
                    self._encoding = 'utf-8'
                else:
                    # PEP-0263: "the first or second line must match [_matchCoding]"
                    match = _matchCoding(first_line)
                    if match is None:
                        match = _matchCoding(
                            self._getline(self._filename, 2, self._global_dict),