summaryrefslogtreecommitdiff
path: root/src/config.py
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2013-03-04 00:23:58 +0100
committermathieui <mathieui@mathieui.net>2013-03-04 00:23:58 +0100
commit1e9e2112f73fc3f2e6552158e57d6a623749eb75 (patch)
treea1ce204099f06fcf69a9a66710e9e0eb3890763e /src/config.py
parent4be111b63ebf8ba0be6b12b3e370deaf5a45180f (diff)
downloadpoezio-1e9e2112f73fc3f2e6552158e57d6a623749eb75.tar.gz
poezio-1e9e2112f73fc3f2e6552158e57d6a623749eb75.tar.bz2
poezio-1e9e2112f73fc3f2e6552158e57d6a623749eb75.tar.xz
poezio-1e9e2112f73fc3f2e6552158e57d6a623749eb75.zip
Fix #2126 (per-server configuration sections)
(also move replace_key_with_bound() to core.py, to prevent having common.py depending of config.py)
Diffstat (limited to 'src/config.py')
-rw-r--r--src/config.py19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/config.py b/src/config.py
index 88ba38c9..e3c93f29 100644
--- a/src/config.py
+++ b/src/config.py
@@ -16,6 +16,7 @@ from configparser import RawConfigParser, NoOptionError, NoSectionError
from os import environ, makedirs, path
from shutil import copy2
from args import parse_args
+from common import safeJID
class Config(RawConfigParser):
@@ -62,7 +63,7 @@ class Config(RawConfigParser):
"""
return self.get(option, default, section).lower()
- def get_by_tabname(self, option, default, tabname, fallback=True):
+ def get_by_tabname(self, option, default, tabname, fallback=True, fallback_server=True):
"""
Try to get the value for the option. First we look in
a section named `tabname`, if the option is not present
@@ -73,11 +74,27 @@ class Config(RawConfigParser):
if option in self.options(tabname):
# We go the tab-specific option
return self.get(option, default, tabname)
+ if fallback_server:
+ return self.get_by_servname(tabname, option, default, fallback)
if fallback:
# We fallback to the global option
return self.get(option, default)
return default
+ def get_by_servname(self, jid, option, default, fallback=True):
+ """
+ Try to get the value of an option for a server
+ """
+ server = safeJID(jid).server
+ if server:
+ server = '@' + server
+ if server in self.sections() and option in self.options(server):
+ return self.get(option, default, server)
+ if fallback:
+ return self.get(option, default)
+ return default
+
+
def __get(self, option, section=DEFSECTION):
"""
facility for RawConfigParser.get