MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / _parse_hstore

Function _parse_hstore

lib/sqlalchemy/dialects/postgresql/hstore.py:345–384  ·  view source on GitHub ↗

Parse an hstore from its literal string representation. Attempts to approximate PG's hstore input parsing rules as closely as possible. Although currently this is not strictly necessary, since the current implementation of hstore's output syntax is stricter than what it accepts as i

(hstore_str)

Source from the content-addressed store, hash-verified

343
344
345def _parse_hstore(hstore_str):
346 """Parse an hstore from its literal string representation.
347
348 Attempts to approximate PG's hstore input parsing rules as closely as
349 possible. Although currently this is not strictly necessary, since the
350 current implementation of hstore's output syntax is stricter than what it
351 accepts as input, the documentation makes no guarantees that will always
352 be the case.
353
354
355
356 """
357 result = {}
358 pos = 0
359 pair_match = HSTORE_PAIR_RE.match(hstore_str)
360
361 while pair_match is not None:
362 key = pair_match.group("key").replace(r"\"", '"').replace("\\\\", "\\")
363 if pair_match.group("value_null"):
364 value = None
365 else:
366 value = (
367 pair_match.group("value")
368 .replace(r"\"", '"')
369 .replace("\\\\", "\\")
370 )
371 result[key] = value
372
373 pos += pair_match.end()
374
375 delim_match = HSTORE_DELIMITER_RE.match(hstore_str[pos:])
376 if delim_match is not None:
377 pos += delim_match.end()
378
379 pair_match = HSTORE_PAIR_RE.match(hstore_str[pos:])
380
381 if pos != len(hstore_str):
382 raise ValueError(_parse_error(hstore_str, pos))
383
384 return result
385
386
387def _serialize_hstore(val):

Callers 1

processMethod · 0.85

Calls 3

_parse_errorFunction · 0.85
matchMethod · 0.45
replaceMethod · 0.45

Tested by

no test coverage detected