Skip to content

refactor: move the serialization implementation to method #313

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions cachecontrol/serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# SPDX-License-Identifier: Apache-2.0

import io
from typing import IO, TYPE_CHECKING, Any, Mapping, Optional
from typing import IO, TYPE_CHECKING, Any, Dict, Mapping, Optional, cast

import msgpack
from requests.structures import CaseInsensitiveDict
Expand All @@ -14,6 +14,8 @@


class Serializer(object):
serde_version = "4"

def dumps(
self,
request: "PreparedRequest",
Expand Down Expand Up @@ -54,7 +56,10 @@ def dumps(
header_value = str(header_value)
data["vary"][header] = header_value

return b",".join([b"cc=4", msgpack.dumps(data, use_bin_type=True)])
return b",".join([f"cc={self.serde_version}".encode(), self.serialize(data)])

def serialize(self, data: Dict[str, Any]) -> bytes:
return cast(bytes, msgpack.dumps(data, use_bin_type=True))

def loads(
self,
Expand Down
1 change: 1 addition & 0 deletions docs/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Unreleased
==========

* Support for old serialization formats has been removed.
* Move the serialization implementation into own method.

0.13.0
======
Expand Down