changeset 1226:72f25d671368

memory (params): use more generic param attribute "constraint" instead of "min" and "max"
author souliane <souliane@mailoo.org>
date Mon, 06 Oct 2014 11:18:37 +0200
parents 82dabb442e2e
children 4da2e4d58bd0
files src/memory/params.py src/plugins/plugin_misc_imap.py src/plugins/plugin_misc_smtp.py src/plugins/plugin_xep_0065.py
diffstat 4 files changed, 22 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/src/memory/params.py	Sat Oct 04 10:26:10 2014 +0200
+++ b/src/memory/params.py	Mon Oct 06 11:18:37 2014 +0200
@@ -44,17 +44,17 @@
     <individual>
         <category name="General" label="%(category_general)s">
             <param name="Password" value="" type="password" />
-            <param name="%(history_param)s" label="%(label_history)s" value="20" min="0" max="100" type="int" security="0" />
+            <param name="%(history_param)s" label="%(history_label)s" value="20" constraint="0;100" type="int" security="0" />
         </category>
         <category name="Connection" label="%(category_connection)s">
             <param name="JabberID" value="name@example.org/SàT" type="string" />
             <param name="Password" value="" type="password" />
-            <param name="Priority" value="50" type="int" min="-128" max="127"/>
+            <param name="Priority" value="50" type="int" constraint="-128;127"/>
             <param name="%(force_server_param)s" value="" type="string" />
-            <param name="%(force_port_param)s" value="" type="int" min="80" max="65535" />
-            <param name="NewAccount" label="%(label_NewAccount)s" type="button" callback_id="registerNewAccount"/>
-            <param name="autoconnect" label="%(label_autoconnect)s" value="true" type="bool" />
-            <param name="autodisconnect" label="%(label_autodisconnect)s" value="false"  type="bool" />
+            <param name="%(force_port_param)s" value="" type="int" constraint="1;65535" />
+            <param name="NewAccount" label="%(new_account_label)s" type="button" callback_id="registerNewAccount"/>
+            <param name="autoconnect" label="%(autoconnect_label)s" value="true" type="bool" />
+            <param name="autodisconnect" label="%(autodisconnect_label)s" value="false"  type="bool" />
         </category>
         <category name="Misc" label="%(category_misc)s">
             <param name="Watched" value="test@Jabber.goffi.int" type="string" />
@@ -65,13 +65,13 @@
         'category_general': D_("General"),
         'category_connection': D_("Connection"),
         'history_param': C.HISTORY_LIMIT,
-        'label_history': D_('Chat history limit'),
-        'label_NewAccount': D_("Register new account"),
-        'label_autoconnect': D_('Connect on frontend startup'),
-        'label_autodisconnect': D_('Disconnect on frontend closure'),
-        'category_misc': D_("Misc"),
+        'history_label': D_('Chat history limit'),
         'force_server_param': C.FORCE_SERVER_PARAM,
         'force_port_param': C.FORCE_PORT_PARAM,
+        'new_account_label': D_("Register new account"),
+        'autoconnect_label': D_('Connect on frontend startup'),
+        'autodisconnect_label': D_('Disconnect on frontend closure'),
+        'category_misc': D_("Misc"),
     }
 
     def load_default_params(self):
@@ -755,10 +755,13 @@
                     log.debug(_("Trying to set parameter '%(param)s' in category '%(cat)s' with an non-integer value"
                                 % {'param': name, 'cat': category}))
                     return defer.succeed(None)
-                if node[1].hasAttribute("min"):
-                    value = str(max(int(value), int(node[1].getAttribute("min"))))
-                if node[1].hasAttribute("max"):
-                    value = str(min(int(value), int(node[1].getAttribute("max"))))
+                if node[1].hasAttribute("constraint"):
+                    constraint = node[1].getAttribute("constraint")
+                    try:
+                        min_, max_ = [int(limit) for limit in constraint.split(";")]
+                    except ValueError:
+                        raise exceptions.InternalError("Invalid integer parameter constraint: %s" % constraint)
+                    value = str(min(max(int(value), min_), max_))
 
         log.info(_("Setting parameter (%(category)s, %(name)s) = %(value)s") %
                  {'category': category, 'name': name, 'value': value if type_ != 'password' else '********'})
--- a/src/plugins/plugin_misc_imap.py	Sat Oct 04 10:26:10 2014 +0200
+++ b/src/plugins/plugin_misc_imap.py	Mon Oct 06 11:18:37 2014 +0200
@@ -51,7 +51,7 @@
     <params>
     <general>
     <category name="Mail Server">
-        <param name="IMAP Port" value="10143" type="int" min="143" max="65535" />
+        <param name="IMAP Port" value="10143" type="int" constraint="1;65535" />
     </category>
     </general>
     </params>
--- a/src/plugins/plugin_misc_smtp.py	Sat Oct 04 10:26:10 2014 +0200
+++ b/src/plugins/plugin_misc_smtp.py	Mon Oct 06 11:18:37 2014 +0200
@@ -51,7 +51,7 @@
     <params>
     <general>
     <category name="Mail Server">
-        <param name="SMTP Port" value="10125" type="int" min="25" max="65535" />
+        <param name="SMTP Port" value="10125" type="int" constraint="1;65535" />
     </category>
     </general>
     </params>
--- a/src/plugins/plugin_xep_0065.py	Sat Oct 04 10:26:10 2014 +0200
+++ b/src/plugins/plugin_xep_0065.py	Mon Oct 06 11:18:37 2014 +0200
@@ -444,14 +444,14 @@
     <general>
     <category name="File Transfer">
         <param name="IP" value='0.0.0.0' default_cb='yes' type="string" />
-        <param name="Port" value="28915" type="int" min="80" max="65535" />
+        <param name="Port" value="28915" type="int" constraint="1;65535" />
     </category>
     </general>
     <individual>
     <category name="File Transfer">
         <param name="Proxy" value="" type="string" />
         <param name="Proxy host" value="" type="string" />
-        <param name="Proxy port" value="" type="int" min="80" max="65535" />
+        <param name="Proxy port" value="" type="int" constraint="1;65535" />
     </category>
     </individual>
     </params>