예제 #1
0
파일: base.py 프로젝트: rrei/plumbum
def shquote(text):
    """Quotes the given text with shell escaping (assumes as syntax similar to ``sh``)"""
    if not text:
        return "''"
    text = six.str(text)
    if not text:
        return "''"
    for c in text:
        if c not in _safechars:
            break
    else:
        return text
    if "'" not in text:
        return "'" + text + "'"
    res = six.str("").join((six.str('\\' + c) if c in _funnychars else c) for c in text)
    return six.str('"') + res + six.str('"')
예제 #2
0
파일: base.py 프로젝트: MemberA2600/Boo-T
def shquote(text):
    """Quotes the given text with shell escaping (assumes as syntax similar to ``sh``)"""
    text = six.str(text)
    if sys.version_info >= (3, 3):
        return shlex.quote(text)
    else:
        import pipes
        return pipes.quote(text)
예제 #3
0
파일: base.py 프로젝트: rrei/plumbum
 def formulate(self, level = 0, args = ()):
     argv = [six.str(self.executable)]
     for a in args:
         if a is None:
             continue
         if isinstance(a, BaseCommand):
             if level >= self.QUOTE_LEVEL:
                 argv.extend(shquote_list(a.formulate(level + 1)))
             else:
                 argv.extend(a.formulate(level + 1))
         elif isinstance(a, (list, tuple)):
             argv.extend(shquote(b) if level >= self.QUOTE_LEVEL else six.str(b) for b in a)
         else:
             argv.append(shquote(a) if level >= self.QUOTE_LEVEL else six.str(a))
     # if self.custom_encoding:
     #    argv = [a.encode(self.custom_encoding) for a in argv if isinstance(a, six.string_types)]
     return argv
예제 #4
0
def shquote(text):
    """Quotes the given text with shell escaping (assumes as syntax similar to ``sh``)"""
    if not text:
        return "''"
    text = six.str(text)
    if not text:
        return "''"
    for c in text:
        if c not in _safechars:
            break
    else:
        return text
    if "'" not in text:
        return "'" + text + "'"
    res = six.str("").join(
        (six.str('\\' + c) if c in _funnychars else c) for c in text)
    return six.str('"') + res + six.str('"')
예제 #5
0
    def test_runfile_rich(self):
        import stat, os

        name = self.richstr + six.str("_program")
        with open(name, 'w') as f:
            f.write("#!/usr/bin/env python\nprint('yes')")

        st = os.stat(name)
        os.chmod(name, st.st_mode | stat.S_IEXEC)

        assert "yes" in local[local.cwd / name]()
예제 #6
0
    def test_runfile_rich(self):
        import stat, os

        name = self.richstr + six.str("_program")
        with open(name, 'w') as f:
            f.write("#!{}\nprint('yes')".format(sys.executable))

        st = os.stat(name)
        os.chmod(name, st.st_mode | stat.S_IEXEC)

        assert "yes" in local[local.cwd / name]()
예제 #7
0
 def formulate(self, level=0, args=()):
     argv = [six.str(self.executable)]
     for a in args:
         if a is None:
             continue
         if isinstance(a, BaseCommand):
             if level >= self.QUOTE_LEVEL:
                 argv.extend(shquote_list(a.formulate(level + 1)))
             else:
                 argv.extend(a.formulate(level + 1))
         elif isinstance(a, (list, tuple)):
             argv.extend(
                 shquote(b) if level >= self.QUOTE_LEVEL else six.str(b)
                 for b in a)
         else:
             argv.append(
                 shquote(a) if level >= self.QUOTE_LEVEL else six.str(a))
     # if self.custom_encoding:
     #    argv = [a.encode(self.custom_encoding) for a in argv if isinstance(a, six.string_types)]
     return argv