Exemple #1
0
    def quote(self):
        """
        A string quoting this object.

        'q'.quote() == "'q'"
        """

        return quoteChar(self._c)
Exemple #2
0
    def quote(self):
        """
        A string quoting this object.

        'q'.quote() == "'q'"
        """

        return quoteChar(self._c)
Exemple #3
0
def ensureByte(char):
    """
    Like chr(ord(char)), but throws on failure.
    """

    if not u'\x00' <= char <= u'\xff':
        raise userError(u"Unacceptable bytestring character: " +
                quoteChar(char))
    return chr(ord(char))
Exemple #4
0
    def recv(self, atom, args):
        if atom is ADD_1:
            other = unwrapInt(args[0])
            return self.withOffset(other)

        if atom is ASINTEGER_0:
            return IntObject(ord(self._c))

        if atom is ASSTRING_0:
            return StrObject(unicode(self._c))

        if atom is GETCATEGORY_0:
            return StrObject(unicode(unicodedb.category(ord(self._c))))

        if atom is MAX_1:
            other = unwrapChar(args[0])
            return self if self._c > other else args[0]

        if atom is MIN_1:
            other = unwrapChar(args[0])
            return self if self._c < other else args[0]

        if atom is NEXT_0:
            return self.withOffset(1)

        if atom is OP__CMP_1:
            return polyCmp(self._c, unwrapChar(args[0]))

        if atom is PREVIOUS_0:
            return self.withOffset(-1)

        if atom is QUOTE_0:
            return StrObject(quoteChar(self._c))

        if atom is SUBTRACT_1:
            other = unwrapInt(args[0])
            return self.withOffset(-other)

        raise Refused(self, atom, args)
Exemple #5
0
 def visitCharExpr(self, c, span):
     self.write(quoteChar(c[0]))
Exemple #6
0
 def toQuote(self):
     return quoteChar(self._c)
Exemple #7
0
 def visitCharExpr(self, c):
     self.write(quoteChar(c[0]))
Exemple #8
0
 def testCharNull(self):
     self.assertEqual(quoteChar(u'\x00'), u"'\\x00'")
Exemple #9
0
 def pretty(self, out):
     out.write(quoteChar(self._c[0]).encode("utf-8"))
Exemple #10
0
 def testCharSingleQuote(self):
     self.assertEqual(quoteChar(u"'"), u"'\\''")
Exemple #11
0
 def testChar(self):
     self.assertEqual(quoteChar(u'a'), u"'a'")
Exemple #12
0
 def testCharNull(self):
     self.assertEqual(quoteChar(u'\x00'), u"'\\x00'")
Exemple #13
0
 def testCharNewline(self):
     self.assertEqual(quoteChar(u'\n'), u"'\\n'")
Exemple #14
0
 def testCharSingleQuote(self):
     self.assertEqual(quoteChar(u"'"), u"'\\''")
Exemple #15
0
 def testChar(self):
     self.assertEqual(quoteChar(u'a'), u"'a'")
Exemple #16
0
 def toQuote(self):
     return quoteChar(self._c)
Exemple #17
0
 def pretty(self, out):
     out.write(quoteChar(self._c[0]).encode("utf-8"))
Exemple #18
0
 def testCharNewline(self):
     self.assertEqual(quoteChar(u'\n'), u"'\\n'")