Skip to content

http

Implementation of HTTP custom list store

HttpCustomListEntryMapper

Bases: CustomListEntryMapper

HTTP mapper for the custom list resource.

Source code in mlte/store/custom_list/underlying/http.py
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
class HttpCustomListEntryMapper(CustomListEntryMapper):
    """HTTP mapper for the custom list resource."""

    def __init__(self, storage: HttpResourceStorage) -> None:
        self.storage = storage
        """The HTTP storage access."""

    def create(
        self,
        new_entry: CustomListEntryModel,
        list_name: Optional[CustomListName] = None,
    ) -> CustomListEntryModel:
        list_name = self._check_valid_custom_list(list_name)
        response = self.storage.post(
            json=new_entry.to_json(), groups=_list_group(list_name)
        )
        return CustomListEntryModel(**response)

    def read(
        self, entry_name: str, list_name: Optional[CustomListName] = None
    ) -> CustomListEntryModel:
        list_name = self._check_valid_custom_list(list_name)
        response = self.storage.get(
            id=entry_name, groups=_list_group(list_name)
        )
        return CustomListEntryModel(**response)

    def list(self, list_name: Optional[CustomListName] = None) -> list[str]:
        list_name = self._check_valid_custom_list(list_name)
        response = self.storage.get(id=list_name)
        list_details = typing.cast(list[dict[str, str]], response)
        name_list = [entry["name"] for entry in list_details]
        return name_list

    def edit(
        self,
        updated_entry: CustomListEntryModel,
        list_name: Optional[CustomListName] = None,
    ) -> CustomListEntryModel:
        list_name = self._check_valid_custom_list(list_name)
        response = self.storage.put(
            json=updated_entry.to_json(), groups=_list_group(list_name)
        )
        return CustomListEntryModel(**response)

    def delete(
        self, entry_name: str, list_name: Optional[CustomListName] = None
    ) -> CustomListEntryModel:
        list_name = self._check_valid_custom_list(list_name)
        response = self.storage.delete(
            id=entry_name, groups=_list_group(list_name)
        )
        return CustomListEntryModel(**response)

storage = storage instance-attribute

The HTTP storage access.

HttpCustomListStore

Bases: CustomListStore

A http implementation of the MLTE custom list store.

Source code in mlte/store/custom_list/underlying/http.py
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
class HttpCustomListStore(CustomListStore):
    """A http implementation of the MLTE custom list store."""

    def __init__(
        self, *, uri: StoreURI, client: Optional[OAuthHttpClient] = None
    ) -> None:
        super().__init__(uri=uri)

        self.storage = HttpResourceStorage(
            uri=uri, resource_type=ResourceType.CUSTOM_LIST, client=client
        )
        """HTTP storage."""

    def session(self) -> CustomListStoreSession:
        """
        Return a session handle for the store instance.
        :return: The session handle
        """
        return HttpCustomListStoreSession(storage=self.storage)

storage = HttpResourceStorage(uri=uri, resource_type=(ResourceType.CUSTOM_LIST), client=client) instance-attribute

HTTP storage.

session()

Return a session handle for the store instance.

Returns:

Type Description
CustomListStoreSession

The session handle

Source code in mlte/store/custom_list/underlying/http.py
39
40
41
42
43
44
def session(self) -> CustomListStoreSession:
    """
    Return a session handle for the store instance.
    :return: The session handle
    """
    return HttpCustomListStoreSession(storage=self.storage)

HttpCustomListStoreSession

Bases: CustomListStoreSession

An HTTP implementation of the MLTE custom list store session.

Source code in mlte/store/custom_list/underlying/http.py
52
53
54
55
56
57
58
59
60
61
62
63
class HttpCustomListStoreSession(CustomListStoreSession):
    """An HTTP implementation of the MLTE custom list store session."""

    def __init__(self, *, storage: HttpResourceStorage) -> None:
        self.storage = storage
        """HTTP storage."""

        self.custom_list_entry_mapper = HttpCustomListEntryMapper(storage)

    def close(self):
        # No closing needed
        pass

storage = storage instance-attribute

HTTP storage.