File: serialize.py

package info (click to toggle)
python-jsonpath 2.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,028 kB
  • sloc: python: 9,473; makefile: 6
file content (13 lines) | stat: -rw-r--r-- 360 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
"""Helper functions for serializing compiled JSONPath queries."""

import json


def canonical_string(value: str) -> str:
    """Return _value_ as a canonically formatted string literal."""
    single_quoted = (
        json.dumps(value, ensure_ascii=False)[1:-1]
        .replace('\\"', '"')
        .replace("'", "\\'")
    )
    return f"'{single_quoted}'"