From ac9be780cffc20b43260fe6720358c39f96e6b58 Mon Sep 17 00:00:00 2001 From: Andrew Resch Date: Mon, 3 Aug 2009 20:27:03 +0000 Subject: [PATCH] Revert 5619 Fix find_json_objects when there is a newline at the end of the string Add test for find_json_objects --- deluge/config.py | 9 ++++----- tests/test_config.py | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/deluge/config.py b/deluge/config.py index 1ee6da63f..d2bd71b5a 100644 --- a/deluge/config.py +++ b/deluge/config.py @@ -72,7 +72,6 @@ import shutil import os import deluge.common -import deluge.configmanager from deluge.log import LOG as log json = deluge.common.json @@ -115,9 +114,9 @@ def find_json_objects(s): opens += 1 elif c == "}": opens -= 1 - if opens == 0: - objects.append((start, index+offset+1)) - start = index + offset + 1 + if opens == 0: + objects.append((start, index+offset+1)) + start = index + offset + 1 return objects @@ -153,7 +152,7 @@ class Config(object): if config_dir: self.__config_file = os.path.join(config_dir, filename) else: - self.__config_file = deluge.configmanager.get_config_dir(filename) + self.__config_file = deluge.common.get_default_config_dir(filename) self.load() diff --git a/tests/test_config.py b/tests/test_config.py index 51a34423b..f29ceae6f 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -96,4 +96,19 @@ class ConfigTestCase(unittest.TestCase): from twisted.internet import reactor d = deferLater(reactor, 7, check_config, config) return d + + def test_find_json_objects(self): + s = """{ + "file": 1, + "format": 1 +}{ + "ssl": true, + "enabled": false, + "port": 8115 +}\n""" + from deluge.config import find_json_objects + + objects = find_json_objects(s) + self.assertEquals(len(objects), 2) +