def quoteCommon(c): """ Apply common quotations to an element of a character or string. """ if c in escapes: return escapes[c] x = ord(c) category = unicodedb.category(x) if category[0] in "CZ": # Calculate an escape code. if x < 0x100: return u"\\x%s" % hex(x, 2) elif x < 0x10000: return u"\\u%s" % hex(x, 4) else: return u"\\U%s" % hex(x, 8) return c
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 getCategory(self): """ The Unicode category of this object's code point. """ return unicode(unicodedb.category(ord(self._c)))
def char_category(w_char): c = ord(w_char.value) cat = unicodedb.category(c) return values.W_Symbol.make(cat.lower())
def getCategory(self): return unicode(unicodedb.category(ord(self._c)))