Is this text, as a whole, a Python script? (as opposed to shell/bat/etc.
353273
def is_python_script(script_text, filename):
    
    if filename.endswith('.py') or filename.endswith('.pyw'):
        return True  # extension says it's Python
    if is_python(script_text, filename):
        return True  # it's syntactically valid Python
    if script_text.startswith('#!'):
        # It begins with a '#!' line, so check if 'python' is in it somewhere
        return 'python' in script_text.splitlines()[0].lower()

    return False
743584
def script(self):
        """"""
        self.shebang_header = self.shebang_headers[self.language]
        self.slurm_header   = [self.slurm_headers[k]['tag'] % v for k,v in self.slurm_params.items()]
        self.script_header  = self.script_headers[self.language]
        self.script_footer  = self.script_footers[self.language]
        return '\n'.join(flatter([self.shebang_header,
                                  self.slurm_header,
                                  self.script_header,
                                  self.command,
                                  self.script_footer]))
804335
def script(self):
        
        script_item = [subtag for subtag in self.subtags if subtag.type == 'script']

        return script_item[0] if len(script_item) > 0 else None
1032508
def text_of(relpath):
    
    thisdir = os.path.dirname(__file__)
    file_path = os.path.join(thisdir, os.path.normpath(relpath))
    with open(file_path) as f:
        text = f.read()
    return text
337409
def is_command(self, text: str) -> bool:
        
        if text[0] in self.shebangs:
            return True

        return False
750786
def split_python_text_into_lines(text):
    
    #import jedi
    #script = jedi.Script(text, line=1, column=None, path='')
    def parentesis_are_balanced(line):
        """
        helper

        References:
            http://stackoverflow.com/questions/18007995/recursive-paren-balance
        """
        def balanced(str_, i=0, cnt=0, left='(', right=')'):
            if i == len(str_):
                return cnt == 0
            if cnt < 0:
                return False
            if str_[i] == left:
                return  balanced(str_, i + 1, cnt + 1)
            elif str_[i] == right:
                return  balanced(str_, i + 1, cnt - 1)
            return balanced(str_, i + 1, cnt)
        return balanced(line)

    lines = text.split('\n')
    new_lines = []
    current_line = ''
    for line in lines:
        current_line += line
        if parentesis_are_balanced(current_line):
            new_lines.append(current_line)
            current_line = ''
    return lines
581738
def commandline_text(bytestring):
    ''
    if six.PY3:
        return bytestring
    unicode_string = bytestring.decode(sys.getfilesystemencoding())
    return unicode_string
686835
def text(self, prompt, default=None):
        """"""
        prompt = prompt if prompt is not None else 'Enter some text'
        prompt += " [{0}]: ".format(default) if default is not None else ': '
        return self.input(curry(filter_text, default=default), prompt)
7516
def _looks_like_script(self, path):
        
        fp = open(path, 'rb')
        try:
            sample = fp.read(512).decode('latin-1')
            return not set(sample).difference(string.printable)
        finally:
            fp.close()
655128
def text(self):
        
        out = []
        out.extend(x.text for x in self.types.values())
        out.extend(x.text for x in self.enums.values())
        out.extend('extern {0};'.format(x.text)
                   for x in self.commands.values())
        return '\n'.join(out)
1236138
def echo(text, silent=False, newline=True):
    

    if silent:
        return
    print(text) if newline else sys.stdout.write(text)
620364
def text(self):
        """"""
        if isinstance(self.source, str):
            return self.source
        else:
            return self.source()
346293
def message_about_scripts_not_on_PATH(scripts):
    # type: (Sequence[str]) -> Optional[str]
    
    if not scripts:
        return None

    # Group scripts by the path they were installed in
    grouped_by_dir = collections.defaultdict(set)  # type: Dict[str, set]
    for destfile in scripts:
        parent_dir = os.path.dirname(destfile)
        script_name = os.path.basename(destfile)
        grouped_by_dir[parent_dir].add(script_name)

    # We don't want to warn for directories that are on PATH.
    not_warn_dirs = [
        os.path.normcase(i).rstrip(os.sep) for i in
        os.environ.get("PATH", "").split(os.pathsep)
    ]
    # If an executable sits with sys.executable, we don't warn for it.
    #     This covers the case of venv invocations without activating the venv.
    executable_loc = os.environ.get("PIP_PYTHON_PATH", sys.executable)
    not_warn_dirs.append(os.path.normcase(os.path.dirname(executable_loc)))
    warn_for = {
        parent_dir: scripts for parent_dir, scripts in grouped_by_dir.items()
        if os.path.normcase(parent_dir) not in not_warn_dirs
    }
    if not warn_for:
        return None

    # Format a message
    msg_lines = []
    for parent_dir, scripts in warn_for.items():
        scripts = sorted(scripts)
        if len(scripts) == 1:
            start_text = "script {} is".format(scripts[0])
        else:
            start_text = "scripts {} are".format(
                ", ".join(scripts[:-1]) + " and " + scripts[-1]
            )

        msg_lines.append(
            "The {} installed in '{}' which is not on PATH."
            .format(start_text, parent_dir)
        )

    last_line_fmt = (
        "Consider adding {} to PATH or, if you prefer "
        "to suppress this warning, use --no-warn-script-location."
    )
    if len(msg_lines) == 1:
        msg_lines.append(last_line_fmt.format("this directory"))
    else:
        msg_lines.append(last_line_fmt.format("these directories"))

    # Returns the formatted multiline message
    return "\n".join(msg_lines)
155846
def is_quote_artifact(orig_text, span):
    """"""
    res = False
    cursor = re.finditer(r'("|\')[^ .,:;?!()*+-].*?("|\')', orig_text)

    for item in cursor:
        if item.span()[1] == span[1]:
            res = True

    return res
31525
def format_raw_script(raw_script):
    
    if six.PY2:
        script = ' '.join(arg.decode('utf-8') for arg in raw_script)
    else:
        script = ' '.join(raw_script)

    return script.strip()
255956
def run(self, text):
        
        for regex in self.regexes:
            text = regex.sub(self.repl, text)
        return text
580957
def do_pyscript(self, args: argparse.Namespace) -> bool:
        """"""
        script_path = os.path.expanduser(args.script_path)
        py_return = False

        # Save current command line arguments
        orig_args = sys.argv

        try:
            # Overwrite sys.argv to allow the script to take command line arguments
            sys.argv = [script_path] + args.script_arguments

            # Run the script - use repr formatting to escape things which
            # need to be escaped to prevent issues on Windows
            py_return = self.do_py("run({!r})".format(script_path))

        except KeyboardInterrupt:
            pass

        finally:
            # Restore command line arguments to original state
            sys.argv = orig_args

        return py_return