Coverage for /Library/Python/2.7/site-packages/PyYAML-3.10-py2.7-macosx-10.8-intel.egg/yaml/reader : 64%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# This module contains abstractions for the input stream. You don't have to # looks further, there are no pretty code. # # We define two classes here. # # Mark(source, line, column) # It's just a record and its only use is producing nice error messages. # Parser does not use it for any other purposes. # # Reader(source, data) # Reader determines the encoding of `data` and converts it to unicode. # Reader provides the following methods and attributes: # reader.peek(length=1) - return the next `length` characters # reader.forward(length=1) - move the current position to `length` characters. # reader.index - the number of the current character. # reader.line, stream.column - the line and the column of the current character.
self.name = name self.character = character self.position = position self.encoding = encoding self.reason = reason
if isinstance(self.character, str): return "'%s' codec can't decode byte #x%02x: %s\n" \ " in \"%s\", position %d" \ % (self.encoding, ord(self.character), self.reason, self.name, self.position) else: return "unacceptable character #x%04x: %s\n" \ " in \"%s\", position %d" \ % (self.character, self.reason, self.name, self.position)
# Reader: # - determines the data encoding and converts it to unicode, # - checks if characters are in allowed range, # - adds '\0' to the end.
# Reader accepts # - a `str` object, # - a `unicode` object, # - a file-like object with its `read` method returning `str`, # - a file-like object with its `read` method returning `unicode`.
# Yeah, it's ugly and slow.
self.name = "<unicode string>" self.check_printable(stream) self.buffer = stream+u'\0' else: self.stream = stream self.name = getattr(stream, 'name', "<file>") self.eof = False self.raw_buffer = '' self.determine_encoding()
except IndexError: self.update(index+1) return self.buffer[self.pointer+index]
self.update(length)
or (ch == u'\r' and self.buffer[self.pointer] != u'\n'):
self.buffer, self.pointer) else: return Mark(self.name, self.index, self.line, self.column, None, None)
self.update_raw() self.raw_decode = codecs.utf_16_le_decode self.encoding = 'utf-16-le' self.raw_decode = codecs.utf_16_be_decode self.encoding = 'utf-16-be' else:
character = match.group() position = self.index+(len(self.buffer)-self.pointer)+match.start() raise ReaderError(self.name, position, ord(character), 'unicode', "special characters are not allowed")
self.update_raw() 'strict', self.eof) except UnicodeDecodeError, exc: character = exc.object[exc.start] if self.stream is not None: position = self.stream_pointer-len(self.raw_buffer)+exc.start else: position = exc.start raise ReaderError(self.name, position, character, exc.encoding, exc.reason) else: data = self.raw_buffer converted = len(data)
data = self.stream.read(size) if data: self.raw_buffer += data self.stream_pointer += len(data) else: self.eof = True
#try: # import psyco # psyco.bind(Reader) #except ImportError: # pass
|