23 __all__ = [
'Reader',
'ReaderError']
25 from error
import YAMLError, Mark
33 codecs.utf_8_decode(
'',
'strict',
False)
34 from codecs
import utf_8_decode, utf_16_le_decode, utf_16_be_decode
39 if not finish
and len(data) % 2 == 1:
41 return codecs.utf_16_le_decode(data, errors)
44 if not finish
and len(data) % 2 == 1:
46 return codecs.utf_16_be_decode(data, errors)
56 while count < 5
and count <
len(data) \
57 and '\x80' <= data[-count-1] <=
'\xBF':
59 if count < 5
and count <
len(data) \
60 and '\xC0' <= data[-count-1] <=
'\xFD':
61 data = data[:-count-1]
62 return codecs.utf_8_decode(data, errors)
66 def __init__(self, name, position, character, encoding, reason):
75 return "'%s' codec can't decode byte #x%02x: %s\n" \
76 " in \"%s\", position %d" \
80 return "unacceptable character #x%04x: %s\n" \
81 " in \"%s\", position %d" \
112 if isinstance(stream, unicode):
113 self.
name =
"<unicode string>"
115 self.
buffer = stream+
u'\0'
116 elif isinstance(stream, str):
117 self.
name =
"<string>"
122 self.
name = getattr(stream,
'name',
"<file>")
146 if ch
in u'\n\x85\u2028\u2029' \
150 elif ch !=
u'\uFEFF':
166 if self.raw_buffer.startswith(codecs.BOM_UTF16_LE):
169 elif self.raw_buffer.startswith(codecs.BOM_UTF16_BE):
177 NON_PRINTABLE = re.compile(
u'[^\x09\x0A\x0D\x20-\x7E\x85\xA0-\uD7FF\uE000-\uFFFD]')
179 match = self.NON_PRINTABLE.search(data)
181 character = match.group()
184 'unicode',
"special characters are not allowed")
198 except UnicodeDecodeError, exc:
199 character = exc.object[exc.start]
200 if self.
stream is not None:
205 exc.encoding, exc.reason)
208 converted =
len(data)
218 data = self.stream.read(size)
Fstring::size_type len(Fstring const &s)
Length.