Ejemplo n.º 1
0
    def call(self):
        if not len(self.args):
            self.write('printf: usage: printf [-v var] format [arguments]\n')
        else:
            if '-v' not in self.args and len(self.args) < 2:
                # replace r'\\x' with r'\x'
                s = ''.join(self.args[0]).replace('\\\\x', '\\x')

                # replace single character escape \x0 with \x00
                s = re.sub(r'(?<=\\)x([0-9a-fA-F])(?=\\|\"|\'|\s|$)', r'x0\g<1>', s)

                # strip single and double quotes
                s = s.strip('\"\'')

                # if the string ends with \c escape, strip it
                if s.endswith('\\c'):
                    s = s[:-2]

                self.write(codecs.escape_devode(s)[0])
Ejemplo n.º 2
0
    def call(self):
        if not len(self.args):
            self.write('printf: usage: printf [-v var] format [arguments]\n')
        else:
            if '-v' not in self.args and len(self.args) < 2:
                # replace r'\\x' with r'\x'
                s = ''.join(self.args[0]).replace('\\\\x', '\\x')

                # replace single character escape \x0 with \x00
                s = re.sub(r'(?<=\\)x([0-9a-fA-F])(?=\\|\"|\'|\s|$)', r'x0\g<1>', s)

                # strip single and double quotes
                s = s.strip('\"\'')

                # if the string ends with \c escape, strip it
                if s.endswith('\\c'):
                    s = s[:-2]

                self.write(codecs.escape_devode(s)[0])