Skip to content

Commit b57042d

Browse files
committed
bugzilla: Delete all non-public symbols from API import
Let's shake out any users that might be accessing stuff they shouldn't be accessing.
1 parent a35e7f5 commit b57042d

3 files changed

Lines changed: 35 additions & 44 deletions

File tree

bin/bugzilla

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from __future__ import print_function
1515

1616
import locale
17-
from logging import DEBUG, INFO, WARN, StreamHandler, Formatter
17+
from logging import getLogger, DEBUG, INFO, WARN, StreamHandler, Formatter
1818
import optparse
1919
import os
2020
import re
@@ -39,7 +39,7 @@ _is_unittest = bool(os.getenv("__BUGZILLA_UNITTEST"))
3939
cmdlist = ['login', 'new', 'query', 'modify', 'attach', 'info']
4040
format_field_re = re.compile("%{([a-z0-9_]+)(?::([^}]*))?}")
4141

42-
log = bugzilla.log
42+
log = getLogger(bugzilla.__name__)
4343
handler = StreamHandler(sys.stderr)
4444
handler.setFormatter(Formatter(
4545
"[%(asctime)s] %(levelname)s (%(module)s:%(lineno)d) %(message)s",

bugzilla/__init__.py

Lines changed: 32 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -26,31 +26,6 @@
2626
Bugzilla4, Bugzilla42, Bugzilla44,
2727
NovellBugzilla, RHBugzilla3, RHBugzilla4)
2828

29-
log = getLogger(__name__)
30-
31-
32-
def _getBugzillaClassForURL(url, sslverify):
33-
url = BugzillaBase.fix_url(url)
34-
log.debug("Detecting subclass for %s", url)
35-
s = ServerProxy(url, _RequestsTransport(url, sslverify=sslverify))
36-
37-
if "bugzilla.redhat.com" in url:
38-
log.info("Using RHBugzilla for URL containing bugzilla.redhat.com")
39-
return RHBugzilla
40-
if "bugzilla.novell.com" in url:
41-
log.info("Using NovellBugzilla for URL containing bugzilla.novell.com")
42-
return NovellBugzilla
43-
44-
# Check for a Red Hat extension
45-
try:
46-
log.debug("Checking for Red Hat Bugzilla extension")
47-
extensions = s.Bugzilla.extensions()
48-
if extensions.get('extensions', {}).get('RedHat', False):
49-
log.debug("Found RedHat bugzilla extension")
50-
return RHBugzilla
51-
except Fault:
52-
pass
53-
5429

5530
class Bugzilla(BugzillaBase):
5631
'''
@@ -60,31 +35,47 @@ class Bugzilla(BugzillaBase):
6035
def _init_class_from_url(self, url, sslverify):
6136
if url is None:
6237
raise TypeError("You must pass a valid bugzilla URL")
38+
url = RHBugzilla.fix_url(url)
39+
log.debug("Detecting subclass for %s", url)
40+
41+
if "bugzilla.redhat.com" in url:
42+
log.info("Using RHBugzilla for URL containing bugzilla.redhat.com")
43+
c = RHBugzilla
44+
else:
45+
# Check for a Red Hat extension
46+
s = ServerProxy(url, _RequestsTransport(url, sslverify=sslverify))
47+
try:
48+
extensions = s.Bugzilla.extensions()
49+
if extensions.get('extensions', {}).get('RedHat', False):
50+
log.debug("Found RedHat bugzilla extension")
51+
c = RHBugzilla
52+
except Fault:
53+
pass
6354

64-
c = _getBugzillaClassForURL(url, sslverify)
6555
if not c:
66-
return False
56+
return
6757

6858
self.__class__ = c
69-
log.info("Chose subclass %s v%s", c.__name__, c.version)
59+
log.info("Found subclass %s v%s", c.__name__, c.version)
7060
return True
7161

7262

73-
del(BugzillaBase)
74-
75-
# This is the list of possible Bugzilla instances an app can use,
76-
# bin/bugzilla used to use it for the --bztype field
77-
classlist = [
78-
"Bugzilla3", "Bugzilla32", "Bugzilla34", "Bugzilla36",
79-
"Bugzilla4", "Bugzilla42", "Bugzilla44",
80-
"RHBugzilla3", "RHBugzilla4", "RHBugzilla",
81-
"NovellBugzilla",
82-
]
83-
8463
# This is the public API. If you are explicitly instantiating any other
8564
# class, using some function, or poking into internal files, don't complain
8665
# if things break on you.
87-
__all__ = classlist + [
66+
__all__ = [
67+
"Bugzilla3", "Bugzilla32", "Bugzilla34", "Bugzilla36",
68+
"Bugzilla4", "Bugzilla42", "Bugzilla44",
69+
"NovellBugzilla",
70+
"RHBugzilla3", "RHBugzilla4", "RHBugzilla",
8871
'BugzillaError',
89-
'Bugzilla',
72+
'Bugzilla', "version",
9073
]
74+
75+
76+
# Clear all other locals() from the public API
77+
for __sym in locals().copy():
78+
if __sym.startswith("__") or __sym in __all__:
79+
continue
80+
locals().pop(__sym)
81+
locals().pop("__sym")

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[tox]
2-
envlist = py26,py27,py33,py34
2+
envlist = py27,py3
33

44
[testenv]
55
sitepackages = True

0 commit comments

Comments
 (0)