summary refs log tree commit diff
diff options
context:
space:
mode:
authorMark Haines <mark.haines@matrix.org>2015-04-30 16:04:02 +0100
committerMark Haines <mark.haines@matrix.org>2015-04-30 16:04:02 +0100
commit74aaacf82aa6b592b100f8b930938e67bfd99000 (patch)
treea9de859c637a0829489cb1820078a384cb5ba739
parentAdd a random string to the auto generated key id (diff)
downloadsynapse-74aaacf82aa6b592b100f8b930938e67bfd99000.tar.xz
Don't break when sizes or durations are given as integers
-rwxr-xr-xdemo/start.sh6
-rw-r--r--synapse/config/_base.py21
2 files changed, 15 insertions, 12 deletions
diff --git a/demo/start.sh b/demo/start.sh
index ef4be2d5ff..75ff9861d8 100755
--- a/demo/start.sh
+++ b/demo/start.sh
@@ -26,9 +26,9 @@ for port in 8080 8081 8082; do
 
     https_port=$((port + 400))
     mkdir -p demo/$port
-    pushd demo/$port
+#    pushd demo/$port
 
-    rm $DIR/etc/$port.config
+    #rm $DIR/etc/$port.config
     python -m synapse.app.homeserver \
         --generate-config \
         -H "localhost:$https_port" \
@@ -39,7 +39,7 @@ for port in 8080 8081 8082; do
         -D \
         -vv \
 
-    popd
+ #   popd
 done
 
 cd "$CWD"
diff --git a/synapse/config/_base.py b/synapse/config/_base.py
index d98b6aaedf..e0c203cb1f 100644
--- a/synapse/config/_base.py
+++ b/synapse/config/_base.py
@@ -27,30 +27,33 @@ class ConfigError(Exception):
 class Config(object):
 
     @staticmethod
-    def parse_size(string):
+    def parse_size(value):
+        if isinstance(value, int) or isinstance(value, long):
+            return value
         sizes = {"K": 1024, "M": 1024 * 1024}
         size = 1
-        suffix = string[-1]
+        suffix = value[-1]
         if suffix in sizes:
-            string = string[:-1]
+            value = value[:-1]
             size = sizes[suffix]
-        return int(string) * size
+        return int(value) * size
 
     @staticmethod
-    def parse_duration(string):
+    def parse_duration(value):
+        if isinstance(value, int) or isinstance(value, long):
+            return value
         second = 1000
         hour = 60 * 60 * second
         day = 24 * hour
         week = 7 * day
         year = 365 * day
-
         sizes = {"s": second, "h": hour, "d": day, "w": week, "y": year}
         size = 1
-        suffix = string[-1]
+        suffix = value[-1]
         if suffix in sizes:
-            string = string[:-1]
+            value = value[:-1]
             size = sizes[suffix]
-        return int(string) * size
+        return int(value) * size
 
     @staticmethod
     def abspath(file_path):