Given a line of code, type_of_line() returns a string indicating
       what kind of code it is.
197577
def type_of_line(line):
    """"""

    if line_is_comment(line):
        return "comment"
    elif line_is_executable(line):
        return "exec_stmt"
    elif line_is_pgm_unit_end(line):
        return "pgm_unit_end"
    else:
        if line_is_pgm_unit_start(line):
            return "pgm_unit_start"
        else:
            return "other"
1152784
def find_by_ast(line, version_token="__version__"):  # type: (str,str) -> Optional[str]
    
    if not line:
        return ""
    # clean up line.
    simplified_line = simplify_line(line)

    if simplified_line.startswith(version_token):
        try:
            tree = ast.parse(simplified_line)  # type: Any
            if hasattr(tree.body[0].value, "s"):
                return unicode(tree.body[0].value.s)
            if hasattr(tree.body[0].value, "elts"):
                version_parts = []
                for elt in tree.body[0].value.elts:
                    if hasattr(elt, "n"):
                        version_parts.append(unicode(elt.n))
                    else:
                        version_parts.append(unicode(elt.s))
                return ".".join(version_parts)
            if hasattr(tree.body[0].value, "n"):
                return unicode(tree.body[0].value.n)
            # print(tree)
        except Exception:
            # raise
            return None

    return None
572986
def pycode(argcount,
           kwonlyargcount,
           nlocals,
           stacksize,
           flags,
           codestring,
           constants,
           names,
           varnames,
           filename,
           name,
           firstlineno,
           lnotab,
           freevars=(),
           cellvars=()):
    
    return CodeType(
        argcount,
        kwonlyargcount,
        nlocals,
        stacksize,
        flags,
        codestring,
        constants,
        names,
        varnames,
        filename,
        name,
        firstlineno,
        lnotab,
        freevars,
        cellvars,
    )
1267475
def _comment_type_from_line(line):
    
    regex = re.compile(r"^{0}".format(_ALL_COMMENT))
    match = regex.match(line)
    if match:
        return "{0} ".format(line[match.start():match.end()])

    raise RuntimeError("Unable to find comment header for {0}".format(line))
655891
def line_print(self):
        
        inv_types = {v: k for k, v in defines.Types.items()}

        if self._code is None:
            self._code = defines.Codes.EMPTY.number

        msg = "From {source}, To {destination}, {type}-{mid}, {code}-{token}, ["\
            .format(source=self._source, destination=self._destination, type=inv_types[self._type], mid=self._mid,
                    code=defines.Codes.LIST[self._code].name, token=self._token)
        for opt in self._options:
            msg += "{name}: {value}, ".format(name=opt.name, value=opt.value)
        msg += "]"
        if self.payload is not None:
            if isinstance(self.payload, dict):
                tmp = list(self.payload.values())[0][0:20]
            else:
                tmp = self.payload[0:20]
            msg += " {payload}...{length} bytes".format(payload=tmp, length=len(self.payload))
        else:
            msg += " No payload"
        return msg
218147
def is_type_text_string(obj):
    """"""
    if PY2:
        # Python 2
        return type(obj) in [str, unicode]
    else:
        # Python 3
        return type(obj) in [str, bytes]
1239107
@Nonnull
  public ELineType getLineType (final boolean bExtendedMode)
  {
    if (m_bIsEmpty)
      return ELineType.EMPTY;

    if (m_nLeading > 3)
      return ELineType.CODE;

    if (m_sValue.charAt (m_nLeading) == '#')
      return ELineType.HEADLINE;

    if (m_sValue.charAt (m_nLeading) == '>')
      return ELineType.BQUOTE;

    if (bExtendedMode)
    {
      if (m_sValue.length () - m_nLeading - m_nTrailing > 2 &&
          (m_sValue.charAt (m_nLeading) == '`' ||
           m_sValue.charAt (m_nLeading) == '~' ||
           m_sValue.charAt (m_nLeading) == '%'))
      {
        if (_countCharsStart ('`') >= 3)
          return ELineType.FENCED_CODE;

        if (_countCharsStart ('~') >= 3)
          return ELineType.FENCED_CODE;

        if (_countCharsStart ('%') >= 3)
          return ELineType.PLUGIN;
      }
    }

    if (m_sValue.length () - m_nLeading - m_nTrailing > 2 &&
        (m_sValue.charAt (m_nLeading) == '*' ||
         m_sValue.charAt (m_nLeading) == '-' ||
         m_sValue.charAt (m_nLeading) == '_'))
    {
      if (_countConsecutiveChars (m_sValue.charAt (m_nLeading)) >= 3)
        return ELineType.HR;
    }

    if (m_sValue.length () - m_nLeading >= 2 && m_sValue.charAt (m_nLeading + 1) == ' ')
    {
      switch (m_sValue.charAt (m_nLeading))
      {
        case '*':
        case '-':
        case '+':
          return ELineType.ULIST;
      }
    }

    if (m_sValue.length () - m_nLeading >= 3 && Character.isDigit (m_sValue.charAt (m_nLeading)))
    {
      int i = m_nLeading + 1;
      while (i < m_sValue.length () && Character.isDigit (m_sValue.charAt (i)))
        i++;
      if (i + 1 < m_sValue.length () && m_sValue.charAt (i) == '.' && m_sValue.charAt (i + 1) == ' ')
        return ELineType.OLIST;
    }

    if (m_sValue.charAt (m_nLeading) == '<')
    {
      final EHTMLElementType eType = _checkHTML ();
      if (eType == EHTMLElementType.TAG)
        return ELineType.XML;
      if (eType == EHTMLElementType.COMMENT)
        return ELineType.XML_COMMENT;
    }

    if (m_aNext != null && !m_aNext.m_bIsEmpty)
    {
      if (m_aNext.m_sValue.charAt (0) == '-' && m_aNext._countConsecutiveChars ('-') > 0)
        return ELineType.HEADLINE2;
      if (m_aNext.m_sValue.charAt (0) == '=' && m_aNext._countConsecutiveChars ('=') > 0)
        return ELineType.HEADLINE1;
    }

    return ELineType.OTHER;
  }
437991
def get_type_string(item):
    """"""
    if isinstance(item, DataFrame):
        return "DataFrame"
    if isinstance(item, Index):
        return type(item).__name__
    if isinstance(item, Series):
        return "Series"
    found = re.findall(r"<(?:type|class) '(\S*)'>",
                       to_text_string(type(item)))
    if found:
        return found[0]
1068730
public boolean isLineOfCode(final String line) {
        if (line.length() < getIndicatorAreaPos() + 1) {
            return false;
        }

        /* Remove white space lines */
        if (line.trim().length() == 0) {
            return false;
        }

        /* Remove comments and special lines */
        if (isComment(line)) {
            return false;
        }

        /*
         * If there is a single token on this line, make sure it is not a
         * compiler directive.
         */
        String[] tokens = line.trim().split("[\\s\\.]+");
        if (tokens.length == 1
                && COMPILER_DIRECTIVES.contains(tokens[0].toUpperCase(Locale
                        .getDefault()))) {
            return false;
        }

        return true;
    }
435172
def _decode_element(self, line):
        """"""
        if not self.encoding:
            return line
        if isinstance(line, str) and self.default_encoding:
            return line.decode(self.default_encoding)
        return line
484857
def is_code(self):
        """"""
        if self.cell_type == 'code':
            return True
        if self.cell_type == 'raw' and 'active' in self.metadata:
            return True
        return False
265510
def context(self, line):
        
        # XXX due to a limitation in Visitor,
        # non-python code after the last python code
        # in a file is not added to self.lines, so we
        # have to guard against IndexErrors.
        idx = line - 1
        if idx >= len(self.lines):
            return self.prefix
        return self.lines[idx]
404134
def get_line(self, text, on_unicode_error='strict'):
        

        def check(entry):
            if entry.find('\n') != -1:
                raise ValueError(
                    "get_line processes one line at a time (remove \'\\n\')"
                )
            entry += "\n"
            return entry

        if type(text) == list:
            text = [check(entry) for entry in text]
            return self.f.multilineGetLine(text, on_unicode_error)
        else:
            text = check(text)
            return self.f.getLine(text, on_unicode_error)
1162278
def _get_error(self, code, errors, indentation=0):
        
        # Init
        results = []
        lines = None
        if code is not None:
            lines = [line.strip() for line in code.split('\n')]

        for error in errors.split('\n'):
            # Strip; skip empy lines
            error = error.strip()
            if not error:
                continue
            # Separate line number from description (if we can)
            linenr, error = self._parse_error(error)
            if None in (linenr, lines):
                results.append('%s' % error)
            else:
                results.append('on line %i: %s' % (linenr, error))
                if linenr > 0 and linenr < len(lines):
                    results.append('  %s' % lines[linenr - 1])

        # Add indentation and return
        results = [' ' * indentation + r for r in results]
        return '\n'.join(results)
661300
def p_code(p):
    

    def asc(x):
        if len(x):
            return ord(x[0])

        return 0

    if p[2] is None:
        p[0] = None
        return

    if p[2].type_ != TYPE.string:
        api.errmsg.syntax_error_expected_string(p.lineno(1), TYPE.to_string(p[2].type_))
        p[0] = None
    else:
        p[0] = make_builtin(p.lineno(1), 'CODE', p[2], lambda x: asc(x), type_=TYPE.ubyte)
1025925
def _check_line_for_encoding(line):
    """"""
    i = 0
    for i in range(len(line)):
        if line[i] == b'#':
            break
        if line[i] not in b' \t\014':
            return None, False  # Not a comment, don't read the second line.
    return pytokenizer.match_encoding_declaration(line[i:]), True
161876
def find_type(self, txt):
        
        searchString = txt.upper()
        match = 'Unknown'
        for i in self.lst_type:
            if searchString in i:
                match = i
        return match