/
service.py
133 lines (101 loc) · 3.5 KB
/
service.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
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
124
125
126
127
128
129
130
131
132
133
"""The base hosting service class and associated definitions.
This is pending deprecation. Consumers should update their imports to use
the classes in :py:mod:`reviewboard.hostingsvcs.base`.
It includes compatibility imports for:
.. autosummary::
:nosignatures:
~reviewboard.hostingsvcs.base.client.HostingServiceClient
~reviewboard.hostingsvcs.base.hosting_service.BaseHostingService
~reviewboard.hostingsvcs.base.http.HostingServiceHTTPRequest
~reviewboard.hostingsvcs.base.http.HostingServiceHTTPResponse
~reviewboard.hostingsvcs.base.repository.RemoteRepository
"""
from __future__ import annotations
import logging
from typing import List, Optional, Type
from reviewboard.hostingsvcs.base import (
BaseHostingService as HostingService,
HostingServiceClient,
HostingServiceHTTPRequest,
HostingServiceHTTPResponse,
hosting_service_registry)
from reviewboard.hostingsvcs.base.registry import HostingServiceRegistry
logger = logging.getLogger(__name__)
def get_hosting_services() -> List[Type[HostingService]]:
"""Return the list of hosting services.
Returns:
list:
The :py:class:`~reviewboard.hostingsvcs.base.BaseHostingService`
subclasses.
"""
return list(hosting_service_registry)
def get_hosting_service(
name: str,
) -> Optional[Type[HostingService]]:
"""Return the hosting service with the given name.
If the hosting service is not found, None will be returned.
Args:
name (str):
The ID of the hosting service.
Returns:
type:
The hosting service class, or ``None`` if not found.
"""
return hosting_service_registry.get_hosting_service(name)
def register_hosting_service(
name: str,
cls: Type[HostingService],
) -> None:
"""Register a custom hosting service class.
A name can only be registered once. A KeyError will be thrown if attempting
to register a second time.
Args:
name (str):
The name of the hosting service.
If the hosting service already has an ID assigned as
:py:attr:`BaseHostingService.hosting_service_id
<reviewboard.hostingsvcs.base.BaseHostingService.
hosting_service_id>`, that value should be passed. Note that this
will also override any existing ID on the service.
cls (type):
The hosting service class.
This must be a subclass of
:py:class:`~reviewboard.hostingsvcs.base.BaseHostingService`.
"""
cls.hosting_service_id = name
hosting_service_registry.register(cls)
def unregister_hosting_service(
name: str,
) -> None:
"""Unregister a previously registered hosting service.
Args:
name (str):
The name of the hosting service.
"""
hosting_service_registry.unregister_by_id(name)
#: Legacy name for HostingServiceHTTPRequest
#:
#: Deprecated:
#: 4.0:
#: This has been replaced by :py:class:`~reviewboard.hostingsvcs.
#: base.http.HostingServiceHTTPRequest`.
URLRequest = HostingServiceHTTPRequest
__all__ = [
'HostingService',
'HostingServiceClient',
'HostingServiceHTTPRequest',
'HostingServiceHTTPResponse',
'HostingServiceRegistry',
'URLRequest',
'get_hosting_service',
'get_hosting_services',
'register_hosting_service',
'unregister_hosting_service',
]
__autodoc_excludes__ = [
'HostingService',
'HostingServiceClient',
'HostingServiceHTTPRequest',
'HostingServiceHTTPResponse',
'HostingServiceRegistry',
]