Beispiel #1
0
    def unichr_impl(cp):

        if not isinstance(cp, int):
            raise TypeError('must be int, not %s' % type(c).__name__)
        if cp < 0x10000:
            return _chr(cp)
        hi, lo = divmod(cp - 0x10000, 0x400)
        hi += 0xd800
        lo += 0xdc00
        if 0xd800 <= hi < 0xdc00 and 0xdc00 <= lo < 0xe000:
            return _chr(hi) + _chr(lo)
        raise ValueError('illeagal code point')
Beispiel #2
0
 def unichr_impl(cp):
     
     if not isinstance(cp, int):
         raise TypeError('must be int, not %s' % type(c).__name__)
     if cp < 0x10000:
         return _chr(cp)
     hi, lo = divmod(cp-0x10000, 0x400)
     hi += 0xd800
     lo += 0xdc00
     if 0xd800 <= hi < 0xdc00 and 0xdc00 <= lo < 0xe000:
         return _chr(hi)+_chr(lo)
     raise ValueError('illeagal code point')
Beispiel #3
0
 def _read_string(self):
     pos = self.data.tell()
     src, value = [self._read_literal('"')], []
     try:
         while True:
             ch = self._read()
             src.append(ch)
             if ch == '\\':
                 ch = self._read()
                 src.append(ch)
                 if ch in self.ESCAPE_SEQUENCES:
                     value.append(self.ESCAPE_SEQUENCES[ch])
                 elif ch == 'u':
                     n = 0
                     for i in range(4):
                         ch = self._read()
                         src.append(ch)
                         n = 16 * n + int(ch, 16)
                     value.append(_chr(n))
                 else:
                     raise UnexpectedCharacter(ch)
             elif ch == '"':
                 break
             else:
                 value.append(ch)
     except AwaitingData:
         self.data.seek(pos)
         raise AwaitingData()
     return "".join(src), "".join(value)
Beispiel #4
0
 def _read_string(self):
     pos = self.data.tell()
     src, value = [self._read_literal('"')], []
     try:
         while True:
             ch = self._read()
             src.append(ch)
             if ch == '\\':
                 ch = self._read()
                 src.append(ch)
                 if ch in self.ESCAPE_SEQUENCES:
                     value.append(self.ESCAPE_SEQUENCES[ch])
                 elif ch == 'u':
                     n = 0
                     for i in range(4):
                         ch = self._read()
                         src.append(ch)
                         n = 16 * n + int(ch, 16)
                     value.append(_chr(n))
                 else:
                     raise UnexpectedCharacter(ch)
             elif ch == '"':
                 break
             else:
                 value.append(ch)
     except AwaitingData:
         self.data.seek(pos)
         raise AwaitingData()
     return "".join(src), "".join(value)
Beispiel #5
0
    def EscapeState(self):
        if self.token[:1] == "t":
            value = "\t" + self.token[1:]
        elif self.token[:1] == "n":
            value = "\n" + self.token[1:]
        elif self.token[:1] == "b":
            value = "\b" + self.token[1:]
        elif self.token[:1] == "f":
            value = "\f" + self.token[1:]
        elif self.token[:1] == "r":
            value = "\r" + self.token[1:]
        elif self.token[:1] == "u":
            value = _chr(int(self.token[1:5], 16)) + self.token[5:]
        else:
            value = self.token

        self.buf_append(value)
        self.state = self.before
Beispiel #6
0
    def EscapeState(self):
        if self.token[:1] == "t":
            value = "\t" + self.token[1:]
        elif self.token[:1] == "n":
            value = "\n" + self.token[1:]
        elif self.token[:1] == "b":
            value = "\b" + self.token[1:]
        elif self.token[:1] == "f":
            value = "\f" + self.token[1:]
        elif self.token[:1] == "r":
            value = "\r" + self.token[1:]
        elif self.token[:1] == "u":
            value = _chr(int(self.token[1:5], 16)) + self.token[5:]
        else:
            value = self.token

        self.buf_append(value)
        self.state = self.before
Beispiel #7
0
 def _read_string(self):
     self.__text.mark()
     try:
         src, value = [self._read_literal('"')], []
         while True:
             chunk = self.__text.read_until_any(('"', '\\'))
             src.append(chunk)
             value.append(chunk[:-1])
             if chunk.endswith('\\'):
                 ch = self.__text.read()
                 src.append(ch)
                 if ch in '"/\\':
                     value.append(ch)
                 elif ch == 'b':
                     value.append('\b')
                 elif ch == 'f':
                     value.append('\f')
                 elif ch == 'n':
                     value.append('\n')
                 elif ch == 'r':
                     value.append('\r')
                 elif ch == 't':
                     value.append('\t')
                 elif ch == 'u':
                     n = 0
                     for i in range(4):
                         ch = self.__text.read()
                         src.append(ch)
                         n = 16 * n + int(ch, 16)
                     value.append(_chr(n))
                 else:
                     raise UnexpectedCharacter(ch)
             else:
                 return "".join(src), "".join(value)
     except AwaitingData:
         self.__text.undo()
         raise
Beispiel #8
0
 def _read_string(self):
     self.__text.mark()
     try:
         src, value = [self._read_literal('"')], []
         while True:
             chunk = self.__text.read_until_any(('"', '\\'))
             src.append(chunk)
             value.append(chunk[:-1])
             if chunk.endswith('\\'):
                 ch = self.__text.read()
                 src.append(ch)
                 if ch in '"/\\':
                     value.append(ch)
                 elif ch == 'b':
                     value.append('\b')
                 elif ch == 'f':
                     value.append('\f')
                 elif ch == 'n':
                     value.append('\n')
                 elif ch == 'r':
                     value.append('\r')
                 elif ch == 't':
                     value.append('\t')
                 elif ch == 'u':
                     n = 0
                     for i in range(4):
                         ch = self.__text.read()
                         src.append(ch)
                         n = 16 * n + int(ch, 16)
                     value.append(_chr(n))
                 else:
                     raise UnexpectedCharacter(ch)
             else:
                 return "".join(src), "".join(value)
     except AwaitingData:
         self.__text.undo()
         raise
Beispiel #9
0
 def unichr_impl(cp):
     return _chr(cp)
Beispiel #10
0
 def unichr_impl(cp):
     return _chr(cp)