• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

crashvb / docker-registry-client-async / 4006410034

pending completion
4006410034

Pull #32

github

GitHub
Merge 4001ff095 into 58922d658
Pull Request #32: Fixed image resolution for familiar references

1 of 1 new or added line in 1 file covered. (100.0%)

541 of 757 relevant lines covered (71.47%)

2.14 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/docker_registry_client_async/jsonbytes.py
1
#!/usr/bin/env python
2

3
"""
3✔
4
JSON without canonicalization really bytes ;)
5
"""
6

7
import json
3✔
8

9
from copy import deepcopy
3✔
10

11
import canonicaljson
3✔
12

13
from .formattedsha256 import FormattedSHA256
3✔
14

15

16
class JsonBytes:
3✔
17
    """
18
    Abstract base class to canonicalize JSON and track the bytes representation.
19
    """
20

21
    def __init__(self, _bytes: bytes):
3✔
22
        """
23
        Args:
24
            _bytes: The raw bytes value.
25
        """
26
        self.bytes = self.json = None
3✔
27
        self._set_bytes(_bytes)
3✔
28

29
    def __bytes__(self):
3✔
30
        return self.get_bytes()
3✔
31

32
    def __str__(self):
3✔
33
        return self.get_bytes().decode("utf-8")
3✔
34

35
    def _set_bytes(self, _bytes: bytes):
3✔
36
        """
37
        Assigns the raw bytes and updates the internal JSON object.
38

39
        Args:
40
            _bytes: The raw bytes value.
41
        """
42
        self.bytes = _bytes
3✔
43
        self.json = json.loads(self.bytes)
3✔
44

45
    def _set_json(self, _json):
3✔
46
        """
47
        Assigns the internal JSON object and updates the raw bytes value.
48

49
        Args:
50
            _json: The internal JSON object.
51
        """
52
        self.json = _json
3✔
53
        self.bytes = canonicaljson.encode_canonical_json(self.json)
3✔
54

55
    def clone(self):
3✔
56
        """
57
        Initializes an returns a copy of this instance.
58

59
        Returns: A copy of this instance.
60
        """
61
        return deepcopy(self)
3✔
62

63
    def get_bytes(self) -> bytes:
3✔
64
        """
65
        Retrieves the raw image bytes.
66

67
        Returns:
68
            The raw image bytes.
69
        """
70
        return self.bytes
3✔
71

72
    def get_digest(self) -> FormattedSHA256:
3✔
73
        """
74
        Retrieves the SHA256 digest value of the raw bytes value.
75

76
        Returns:
77
            The SHA256 digest value of the raw image bytes.
78
        """
79
        return FormattedSHA256.calculate(self.get_bytes())
3✔
80

81
    def get_json(self):
3✔
82
        """
83
        Retrieves the image bytes in JSON form.
84

85
        Returns:
86
            The image bytes in JSON form.
87
        """
88
        return deepcopy(self.json)
3✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc