def quote(self): """ A string quoting this object. 'q'.quote() == "'q'" """ return quoteChar(self._c)
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))
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)
def visitCharExpr(self, c, span): self.write(quoteChar(c[0]))
def toQuote(self): return quoteChar(self._c)
def visitCharExpr(self, c): self.write(quoteChar(c[0]))
def testCharNull(self): self.assertEqual(quoteChar(u'\x00'), u"'\\x00'")
def pretty(self, out): out.write(quoteChar(self._c[0]).encode("utf-8"))
def testCharSingleQuote(self): self.assertEqual(quoteChar(u"'"), u"'\\''")
def testChar(self): self.assertEqual(quoteChar(u'a'), u"'a'")
def testCharNewline(self): self.assertEqual(quoteChar(u'\n'), u"'\\n'")