"""Jira utils used internally."""from__future__importannotationsimportthreadingimportwarningsfromtypingimportAny,castfromrequestsimportResponsefromrequests.structuresimportCaseInsensitiveDictas_CaseInsensitiveDictfromjira.resilientsessionimportraise_on_error
[docs]classCaseInsensitiveDict(_CaseInsensitiveDict):"""A case-insensitive ``dict``-like object. DEPRECATED: use requests.structures.CaseInsensitiveDict directly. Implements all methods and operations of ``collections.MutableMapping`` as well as dict's ``copy``. Also provides ``lower_items``. All keys are expected to be strings. The structure remembers the case of the last key to be set, and ``iter(instance)``, ``keys()``, ``items()``, ``iterkeys()`` will contain case-sensitive keys. However, querying and contains testing is case insensitive:: cid = CaseInsensitiveDict() cid['Accept'] = 'application/json' cid['accept'] == 'application/json' # True list(cid) == ['Accept'] # True For example, ``headers['content-encoding']`` will return the value of a ``'Content-Encoding'`` response header, regardless of how the header name was originally stored. If the constructor, ``.update``, or equality comparison operations are given keys that have equal ``.lower()`` s, the behavior is undefined. """
[docs]defjson_loads(resp:Response|None)->Any:"""Attempts to load json the result of a response. Args: resp (Optional[Response]): The Response object Raises: JIRAError: via :py:func:`jira.resilientsession.raise_on_error` Returns: Union[List[Dict[str, Any]], Dict[str, Any]]: the json """raise_on_error(resp)# if 'resp' is None, will raise an error hereresp=cast(Response,resp)# tell mypy only Response-like are heretry:returnresp.json()exceptValueError:# json.loads() fails with empty bodiesifnotresp.text:return{}raise
[docs]defremove_empty_attributes(data:dict[str,Any])->dict[str,Any]:"""A convenience function to remove key/value pairs with `None` for a value. Args: data: A dictionary. Returns: Dict[str, Any]: A dictionary with no `None` key/value pairs. """return{key:valforkey,valindata.items()ifvalisnotNone}