3434# pylint: enable=import-error,no-name-in-module,ungrouped-imports
3535
3636
37+ from ._util import listify
38+ from ._rc import DEFAULT_CONFIGPATHS , open_bugzillarc
3739from .apiversion import __version__
3840from .bug import Bug , User
3941from .transport import BugzillaError , _BugzillaServerProxy , _RequestsTransport
@@ -105,30 +107,6 @@ def _build_cookiejar(cookiefile):
105107 cookiefile )
106108
107109
108- _default_configpaths = [
109- '/etc/bugzillarc' ,
110- '~/.bugzillarc' ,
111- '~/.config/python-bugzilla/bugzillarc' ,
112- ]
113-
114-
115- def _open_bugzillarc (configpaths = - 1 ):
116- if configpaths == - 1 :
117- configpaths = _default_configpaths [:]
118-
119- # pylint: disable=protected-access
120- configpaths = [os .path .expanduser (p ) for p in
121- Bugzilla ._listify (configpaths )]
122- # pylint: enable=protected-access
123- cfg = ConfigParser ()
124- read_files = cfg .read (configpaths )
125- if not read_files :
126- return
127-
128- log .info ("Found bugzillarc files: %s" , read_files )
129- return cfg
130-
131-
132110def _save_api_key (url , api_key ):
133111 """
134112 Save the API_KEY in the config file.
@@ -275,15 +253,6 @@ def fix_url(url):
275253 log .debug ("Generated fixed URL: %s" , newurl )
276254 return newurl
277255
278- @staticmethod
279- def _listify (val ):
280- if val is None :
281- return val
282- if isinstance (val , list ):
283- return val
284- return [val ]
285-
286-
287256 def __init__ (self , url = - 1 , user = None , password = None , cookiefile = - 1 ,
288257 sslverify = True , tokenfile = - 1 , use_creds = True , api_key = None ,
289258 cert = None , configpaths = - 1 , basic_auth = False ):
@@ -348,7 +317,7 @@ def __init__(self, url=-1, user=None, password=None, cookiefile=-1,
348317 if tokenfile == - 1 :
349318 tokenfile = _default_cache_location ("bugzillatoken" )
350319 if configpaths == - 1 :
351- configpaths = _default_configpaths [:]
320+ configpaths = DEFAULT_CONFIGPATHS [:]
352321
353322 log .debug ("Using tokenfile=%s" , tokenfile )
354323 self .cookiefile = cookiefile
@@ -512,7 +481,7 @@ def readconfig(self, configpath=None, overwrite=True):
512481 :param overwrite: If True, bugzillarc will clobber any already
513482 set self.user/password/api_key/cert value.
514483 """
515- cfg = _open_bugzillarc (configpath or self .configpath )
484+ cfg = open_bugzillarc (configpath or self .configpath )
516485 if not cfg :
517486 return
518487
@@ -826,9 +795,9 @@ def product_get(self, ids=None, names=None,
826795
827796 kwargs = {}
828797 if ids :
829- kwargs ["ids" ] = self . _listify (ids )
798+ kwargs ["ids" ] = listify (ids )
830799 if names :
831- kwargs ["names" ] = self . _listify (names )
800+ kwargs ["names" ] = listify (names )
832801 if include_fields :
833802 kwargs ["include_fields" ] = include_fields
834803 if exclude_fields :
@@ -1097,7 +1066,7 @@ def _getbugs(self, idlist, permissive,
10971066 # String aliases can be passed as well
10981067 idlist .append (i )
10991068
1100- extra_fields = self . _listify (extra_fields or [])
1069+ extra_fields = listify (extra_fields or [])
11011070 extra_fields += self ._getbug_extra_fields
11021071
11031072 getbugdata = {"ids" : idlist }
@@ -1122,7 +1091,7 @@ def _getbugs(self, idlist, permissive,
11221091 else :
11231092 # Need to map an alias
11241093 for valdict in bugdict .values ():
1125- if i in self . _listify (valdict .get ("alias" , None ) or []):
1094+ if i in listify (valdict .get ("alias" , None ) or []):
11261095 found = valdict
11271096 break
11281097
@@ -1243,8 +1212,8 @@ def build_query(self,
12431212
12441213 query = {
12451214 "alias" : alias ,
1246- "product" : self . _listify (product ),
1247- "component" : self . _listify (component ),
1215+ "product" : listify (product ),
1216+ "component" : listify (component ),
12481217 "version" : version ,
12491218 "id" : bug_id ,
12501219 "short_desc" : short_desc ,
@@ -1253,17 +1222,17 @@ def build_query(self,
12531222 "priority" : priority ,
12541223 "target_release" : target_release ,
12551224 "target_milestone" : target_milestone ,
1256- "tag" : self . _listify (tags ),
1225+ "tag" : listify (tags ),
12571226 "quicksearch" : quicksearch ,
12581227 "savedsearch" : savedsearch ,
12591228 "sharer_id" : savedsearch_sharer_id ,
12601229
12611230 # RH extensions... don't add any more. See comment below
1262- "sub_components" : self . _listify (sub_component ),
1231+ "sub_components" : listify (sub_component ),
12631232 }
12641233
12651234 def add_bool (bzkey , value , bool_id , booltype = None ):
1266- value = self . _listify (value )
1235+ value = listify (value )
12671236 if value is None :
12681237 return bool_id
12691238
@@ -1394,7 +1363,7 @@ def update_bugs(self, ids, updates):
13941363 build_update(), otherwise we cannot guarantee back compatibility.
13951364 """
13961365 tmp = updates .copy ()
1397- tmp ["ids" ] = self . _listify (ids )
1366+ tmp ["ids" ] = listify (ids )
13981367
13991368 return self ._proxy .Bug .update (tmp )
14001369
@@ -1404,12 +1373,12 @@ def update_tags(self, idlist, tags_add=None, tags_remove=None):
14041373 """
14051374 tags = {}
14061375 if tags_add :
1407- tags ["add" ] = self . _listify (tags_add )
1376+ tags ["add" ] = listify (tags_add )
14081377 if tags_remove :
1409- tags ["remove" ] = self . _listify (tags_remove )
1378+ tags ["remove" ] = listify (tags_remove )
14101379
14111380 d = {
1412- "ids" : self . _listify (idlist ),
1381+ "ids" : listify (idlist ),
14131382 "tags" : tags ,
14141383 }
14151384
@@ -1506,7 +1475,7 @@ def add_dict(key, add, remove, _set=None, convert=None):
15061475 return
15071476
15081477 def c (val ):
1509- val = self . _listify (val )
1478+ val = listify (val )
15101479 if convert :
15111480 val = [convert (v ) for v in val ]
15121481 return val
@@ -1548,7 +1517,7 @@ def c(val):
15481517 s ("whiteboard" , whiteboard )
15491518 s ("work_time" , work_time , float )
15501519 s ("flags" , flags )
1551- s ("comment_tags" , comment_tags , self . _listify )
1520+ s ("comment_tags" , comment_tags , listify )
15521521
15531522 add_dict ("blocks" , blocks_add , blocks_remove , blocks_set ,
15541523 convert = int )
@@ -1629,7 +1598,7 @@ def attachfile(self, idlist, attachfile, description, **kwargs):
16291598 data = data .encode (locale .getpreferredencoding ())
16301599 kwargs ['data' ] = Binary (data )
16311600
1632- kwargs ['ids' ] = self . _listify (idlist )
1601+ kwargs ['ids' ] = listify (idlist )
16331602
16341603 if 'file_name' not in kwargs and hasattr (f , "name" ):
16351604 kwargs ['file_name' ] = os .path .basename (f .name )
@@ -1697,13 +1666,13 @@ def get_attachments(self, ids, attachment_ids,
16971666 https://bugzilla.readthedocs.io/en/latest/api/core/v1/attachment.html#get-attachment
16981667 """
16991668 params = {
1700- "ids" : self . _listify (ids ) or [],
1701- "attachment_ids" : self . _listify (attachment_ids ) or [],
1669+ "ids" : listify (ids ) or [],
1670+ "attachment_ids" : listify (attachment_ids ) or [],
17021671 }
17031672 if include_fields :
1704- params ["include_fields" ] = self . _listify (include_fields )
1673+ params ["include_fields" ] = listify (include_fields )
17051674 if exclude_fields :
1706- params ["exclude_fields" ] = self . _listify (exclude_fields )
1675+ params ["exclude_fields" ] = listify (exclude_fields )
17071676
17081677 return self ._proxy .Bug .attachments (params )
17091678
@@ -1751,15 +1720,15 @@ def build_createbug(self,
17511720
17521721 localdict = {}
17531722 if blocks :
1754- localdict ["blocks" ] = self . _listify (blocks )
1723+ localdict ["blocks" ] = listify (blocks )
17551724 if cc :
1756- localdict ["cc" ] = self . _listify (cc )
1725+ localdict ["cc" ] = listify (cc )
17571726 if depends_on :
1758- localdict ["depends_on" ] = self . _listify (depends_on )
1727+ localdict ["depends_on" ] = listify (depends_on )
17591728 if groups :
1760- localdict ["groups" ] = self . _listify (groups )
1729+ localdict ["groups" ] = listify (groups )
17611730 if keywords :
1762- localdict ["keywords" ] = self . _listify (keywords )
1731+ localdict ["keywords" ] = listify (keywords )
17631732 if description :
17641733 localdict ["description" ] = description
17651734 if comment_private :
@@ -1845,11 +1814,11 @@ def _getusers(self, ids=None, names=None, match=None):
18451814 """
18461815 params = {}
18471816 if ids :
1848- params ['ids' ] = self . _listify (ids )
1817+ params ['ids' ] = listify (ids )
18491818 if names :
1850- params ['names' ] = self . _listify (names )
1819+ params ['names' ] = listify (names )
18511820 if match :
1852- params ['match' ] = self . _listify (match )
1821+ params ['match' ] = listify (match )
18531822 if not params :
18541823 raise BugzillaError ('_get() needs one of ids, '
18551824 ' names, or match kwarg.' )
@@ -1925,14 +1894,14 @@ def updateperms(self, user, action, groups):
19251894 :arg action: add, remove, or set
19261895 :arg groups: list of groups to be added to (i.e. ['fedora_contrib'])
19271896 """
1928- groups = self . _listify (groups )
1897+ groups = listify (groups )
19291898 if action == "rem" :
19301899 action = "remove"
19311900 if action not in ["add" , "remove" , "set" ]:
19321901 raise BugzillaError ("Unknown user permission action '%s'" % action )
19331902
19341903 update = {
1935- "names" : self . _listify (user ),
1904+ "names" : listify (user ),
19361905 "groups" : {
19371906 action : groups ,
19381907 }
0 commit comments