|
23 | 23 | from configparser import SafeConfigParser |
24 | 24 | from http.cookiejar import LoadError, LWPCookieJar, MozillaCookieJar |
25 | 25 | from urllib.parse import urlparse, parse_qsl |
26 | | - from xmlrpc.client import Binary, Fault |
| 26 | + from xmlrpc.client import Binary, Fault, ServerProxy |
27 | 27 | else: |
28 | 28 | from ConfigParser import SafeConfigParser |
29 | 29 | from cookielib import LoadError, LWPCookieJar, MozillaCookieJar |
30 | 30 | from urlparse import urlparse, parse_qsl |
31 | | - from xmlrpclib import Binary, Fault |
| 31 | + from xmlrpclib import Binary, Fault, ServerProxy |
32 | 32 |
|
33 | 33 |
|
34 | 34 | from .apiversion import __version__ |
@@ -242,15 +242,7 @@ def __init__(self, url=None, user=None, password=None, cookiefile=-1, |
242 | 242 | False to disable SSL verification, but it can also be a path |
243 | 243 | to file or directory for custom certs. |
244 | 244 | """ |
245 | | - # Hook to allow Bugzilla autodetection without weirdly overriding |
246 | | - # __init__ |
247 | | - if self._init_class_from_url(url, sslverify): |
248 | | - kwargs = locals().copy() |
249 | | - del(kwargs["self"]) |
250 | | - |
251 | | - # pylint: disable=non-parent-init-called |
252 | | - self.__class__.__init__(self, **kwargs) |
253 | | - return |
| 245 | + self._init_class_from_url(url, sslverify) |
254 | 246 |
|
255 | 247 | # Settings the user might want to tweak |
256 | 248 | self.user = user or '' |
@@ -278,12 +270,45 @@ def __init__(self, url=None, user=None, password=None, cookiefile=-1, |
278 | 270 | if url: |
279 | 271 | self.connect(url) |
280 | 272 |
|
| 273 | + self._init_class_state() |
| 274 | + |
281 | 275 | def _init_class_from_url(self, url, sslverify): |
282 | 276 | """ |
283 | | - Hook used by the Bugzilla() autodetect class to work its magic |
| 277 | + Detect if we should use RHBugzilla class, and if so, set it |
| 278 | + """ |
| 279 | + from bugzilla import RHBugzilla |
| 280 | + if url is None: |
| 281 | + return |
| 282 | + |
| 283 | + url = self.fix_url(url) |
| 284 | + log.debug("Detecting subclass for %s", url) |
| 285 | + |
| 286 | + c = None |
| 287 | + if "bugzilla.redhat.com" in url: |
| 288 | + log.info("Using RHBugzilla for URL containing bugzilla.redhat.com") |
| 289 | + c = RHBugzilla |
| 290 | + else: |
| 291 | + # Check for a Red Hat extension |
| 292 | + s = ServerProxy(url, _RequestsTransport(url, sslverify=sslverify)) |
| 293 | + try: |
| 294 | + extensions = s.Bugzilla.extensions() |
| 295 | + if extensions.get('extensions', {}).get('RedHat', False): |
| 296 | + log.debug("Found RedHat bugzilla extension") |
| 297 | + c = RHBugzilla |
| 298 | + except Fault: |
| 299 | + pass |
| 300 | + |
| 301 | + if not c: |
| 302 | + return |
| 303 | + |
| 304 | + self.__class__ = c |
| 305 | + log.info("Found subclass %s", c.__name__) |
| 306 | + |
| 307 | + def _init_class_state(self): |
| 308 | + """ |
| 309 | + Hook for subclasses to do any __init__ time setup |
284 | 310 | """ |
285 | | - ignore = url |
286 | | - ignore = sslverify |
| 311 | + pass |
287 | 312 |
|
288 | 313 | def _init_field_aliases(self): |
289 | 314 | # List of field aliases. Maps old style RHBZ parameter |
|
0 commit comments