Changeset b6a3161
- Timestamp:
- 05/09/2013 06:13:20 PM (12 years ago)
- Branches:
- 2.0.x, develop, master
- Children:
- 7424cf
- Parents:
- daba92
- git-author:
- Calum Lind <calumlind+deluge@gmail.com> (05/09/2013 05:41:30 PM)
- git-committer:
- Calum Lind <calumlind+deluge@gmail.com> (05/09/2013 06:13:20 PM)
- Location:
- deluge
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
deluge/config.py
rdaba92 rb6a3161 268 268 else: 269 269 return self.__config[key] 270 271 272 def get(self, key, default=None): 273 """ 274 Gets the value of item 'key' if key is in the config, else default. 275 If default is not given, it defaults to None, so that this method 276 never raises a KeyError. 277 278 :param key: the item for which you want it's value 279 :param default: the default value if key is missing 280 :return: the value of item 'key' or default 281 282 **Usage** 283 284 >>> config = Config("test.conf", defaults={"test": 5}) 285 >>> config.get("test", 10) 286 5 287 >>> config.get("bad_key", 10) 288 10 289 290 """ 291 try: 292 return self.get_item(key) 293 except KeyError: 294 return default 295 270 296 271 297 def __delitem__(self, key): -
deluge/core/core.py
rdaba92 rb6a3161 481 481 def get_config_value(self, key): 482 482 """Get the config value for key""" 483 try: 484 value = self.config[key] 485 except KeyError: 486 return None 487 488 return value 483 return self.config.get(key) 489 484 490 485 @export 491 486 def get_config_values(self, keys): 492 487 """Get the config values for the entered keys""" 493 config = {} 494 for key in keys: 495 try: 496 config[key] = self.config[key] 497 except KeyError: 498 pass 499 return config 488 return {(key, self.config.get(key)) for key in keys} 500 489 501 490 @export -
deluge/tests/test_config.py
rdaba92 rb6a3161 32 32 config["unicode"] = u"ÐÐÐÐÐЀÐÐЬÐЫ" 33 33 self.assertEquals(config["unicode"], u"ÐÐÐÐÐЀÐÐЬÐЫ") 34 34 35 35 config._save_timer.cancel() 36 37 def test_get(self): 38 config = Config("test.conf", config_dir=self.config_dir) 39 config["foo"] = 1 40 self.assertEquals(config.get("foo"), 1) 41 self.assertEquals(config.get("foobar"), None) 42 self.assertEquals(config.get("foobar", 2), 2) 43 config["foobar"] = 5 44 self.assertEquals(config.get("foobar", 2), 5) 36 45 37 46 def test_load(self):
Note:
See TracChangeset
for help on using the changeset viewer.