Code Duplication    Length = 29-29 lines in 2 locations

lagom/integrations/starlette.py 2 locations

@@ 195-223 (lines=29) @@
192
193
        return HTTPEndpointProxy
194
195
    @staticmethod
196
    def create_websocket_endpoint_proxy(
197
        endpoint_cls: Type[WebSocketEndpoint],
198
        partial_provider: Callable,
199
        request_singletons: List[Type],
200
    ) -> Type[WebSocketEndpoint]:
201
        """Create a subclass of Starlette's WebSocketEndpoint which injects dependencies
202
        into relevant methods on the user's `endpoint_cls` subclass of WebSocketEndpoint
203
204
        :param endpoint_cls:
205
        :param partial_provider:
206
        :param request_singletons:
207
        """
208
209
        class WebSocketEndpointProxy(WebSocketEndpoint):
210
            def __init__(self, scope, receive, send):
211
                super().__init__(scope, receive, send)
212
                self.endpoint = endpoint_cls(scope, receive, send)
213
214
            def __getattribute__(self, name: str):
215
                if name in OVERRIDE_WEBSOCKET_METHODS:
216
                    endpoint_instance = object.__getattribute__(self, "endpoint")
217
                    endpoint_method = getattr(endpoint_instance, name)
218
219
                    return partial_provider(endpoint_method, shared=request_singletons)
220
221
                return object.__getattribute__(self, name)
222
223
        return WebSocketEndpointProxy
224
@@ 165-193 (lines=29) @@
162
                endpoint, partial_provider, self._request_singletons
163
            )
164
165
    @staticmethod
166
    def create_http_endpoint_proxy(
167
        endpoint_cls: Type[HTTPEndpoint],
168
        partial_provider: Callable,
169
        request_singletons: List[Type],
170
    ) -> Type[HTTPEndpoint]:
171
        """Create a subclass of Starlette's HTTPEndpoint which injects dependencies
172
        into HTTP-method-named methods on the user's `endpoint_cls` subclass of HTTPEndpoint
173
174
        :param endpoint_cls:
175
        :param partial_provider:
176
        :param request_singletons:
177
        """
178
179
        class HTTPEndpointProxy(HTTPEndpoint):
180
            def __init__(self, scope, receive, send):
181
                super().__init__(scope, receive, send)
182
                self.endpoint = endpoint_cls(scope, receive, send)
183
184
            def __getattribute__(self, name: str):
185
                if name in OVERRIDE_HTTP_METHODS:
186
                    endpoint_instance = object.__getattribute__(self, "endpoint")
187
                    endpoint_method = getattr(endpoint_instance, name)
188
189
                    return partial_provider(endpoint_method, shared=request_singletons)
190
191
                return object.__getattribute__(self, name)
192
193
        return HTTPEndpointProxy
194
195
    @staticmethod
196
    def create_websocket_endpoint_proxy(