MCPcopy Create free account
hub / github.com/apache/thrift / readJSONString

Method readJSONString

lib/py/src/protocol/TJSONProtocol.py:272–322  ·  view source on GitHub ↗
(self, skipContext)

Source from the content-addressed store, hash-verified

270 return chr(codepoint)
271
272 def readJSONString(self, skipContext):
273 highSurrogate = None
274 string = []
275 if skipContext is False:
276 self.context.read()
277 self.readJSONSyntaxChar(QUOTE)
278 while True:
279 character = self.reader.read()
280 if character == QUOTE:
281 break
282 if ord(character) == ESCSEQ0:
283 character = self.reader.read()
284 if ord(character) == ESCSEQ1:
285 character = self.trans.read(4).decode('ascii')
286 codeunit = int(character, 16)
287 if self._isHighSurrogate(codeunit):
288 if highSurrogate:
289 raise TProtocolException(
290 TProtocolException.INVALID_DATA,
291 "Expected low surrogate char")
292 highSurrogate = codeunit
293 continue
294 elif self._isLowSurrogate(codeunit):
295 if not highSurrogate:
296 raise TProtocolException(
297 TProtocolException.INVALID_DATA,
298 "Expected high surrogate char")
299 character = self._toChar(highSurrogate, codeunit)
300 highSurrogate = None
301 else:
302 character = self._toChar(codeunit)
303 else:
304 if character not in ESCAPE_CHARS:
305 raise TProtocolException(
306 TProtocolException.INVALID_DATA,
307 "Expected control char")
308 character = ESCAPE_CHARS[character]
309 elif character in ESCAPE_CHAR_VALS:
310 raise TProtocolException(TProtocolException.INVALID_DATA,
311 "Unescaped control char")
312 else:
313 utf8_bytes = bytearray([ord(character)])
314 while ord(self.reader.peek()) >= 0x80:
315 utf8_bytes.append(ord(self.reader.read()))
316 character = utf8_bytes.decode('utf-8')
317 string.append(character)
318
319 if highSurrogate:
320 raise TProtocolException(TProtocolException.INVALID_DATA,
321 "Expected low surrogate char")
322 return ''.join(string)
323
324 def isJSONNumeric(self, character):
325 return (True if NUMERIC_CHAR.find(character) != - 1 else False)

Callers 2

readJSONDoubleMethod · 0.95
readJSONBase64Method · 0.95

Calls 10

readJSONSyntaxCharMethod · 0.95
_isHighSurrogateMethod · 0.95
_isLowSurrogateMethod · 0.95
_toCharMethod · 0.95
TProtocolExceptionClass · 0.70
readMethod · 0.65
decodeMethod · 0.45
peekMethod · 0.45
appendMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected