parseur.utils ============= .. py:module:: parseur.utils Attributes ---------- .. autoapisummary:: parseur.utils.ABSOLUTE_URL_FIELDS Classes ------- .. autoapisummary:: parseur.utils.ISODateJSONEncoder Functions --------- .. autoapisummary:: parseur.utils.resolve_absolute_urls parseur.utils.to_json Module Contents --------------- .. py:data:: ABSOLUTE_URL_FIELDS .. py:function:: resolve_absolute_urls(obj) .. py:class:: ISODateJSONEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None) Bases: :py:obj:`json.JSONEncoder` JSON Encoder that converts datetime and date objects to ISO 8601 strings. .. py:method:: default(obj) Implement this method in a subclass such that it returns a serializable object for ``o``, or calls the base implementation (to raise a ``TypeError``). For example, to support arbitrary iterators, you could implement default like this:: def default(self, o): try: iterable = iter(o) except TypeError: pass else: return list(iterable) # Let the base class default method raise the TypeError return JSONEncoder.default(self, o) .. py:function:: to_json(data, indent=2, sort_keys=True, ensure_ascii=False) Serialize a Python object to a JSON-formatted string with ISO datetime support. This function uses the custom ISODateJSONEncoder to automatically convert datetime.datetime objects to ISO 8601 strings. :param data: The data to serialize (dict, list, etc.). :param indent: Number of spaces to indent in the output JSON. Default is 2. :param sort_keys: Whether to sort the dictionary keys in the output. Default is True. :param ensure_ascii: Whether to escape non-ASCII characters. Default is False. :return: A JSON-formatted string.