Revert "Merged all Chromoting Host code into remoting_core.dll (Windows)."
[chromium-blink-merge.git] / native_client_sdk / src / build_tools / sdk_tools / config.py
blobe35e7d5e56725e09b026161da2caddc93a678547
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 import json
6 import logging
7 import urlparse
9 SOURCE_WHITELIST = [
10 'http://localhost/', # For testing.
11 'https://commondatastorage.googleapis.com/nativeclient-mirror/nacl/nacl_sdk',
14 def IsSourceValid(url):
15 # E1101: Instance of 'ParseResult' has no 'scheme' member
16 # pylint: disable=E1101
18 given = urlparse.urlparse(url)
19 for allowed_url in SOURCE_WHITELIST:
20 allowed = urlparse.urlparse(allowed_url)
21 if (given.scheme == allowed.scheme and
22 given.hostname == allowed.hostname and
23 given.path.startswith(allowed.path)):
24 return True
25 return False
28 class Config(dict):
29 def __init__(self, data=None):
30 dict.__init__(self)
31 if data:
32 self.update(data)
33 else:
34 self.sources = []
36 def ToJson(self):
37 return json.dumps(self, sort_keys=False, indent=2)
39 def __getattr__(self, name):
40 return self.__getitem__(name)
42 def __setattr__(self, name, value):
43 return self.__setitem__(name, value)
45 def AddSource(self, source):
46 if not IsSourceValid(source):
47 logging.warn('Only whitelisted sources are allowed. Ignoring \"%s\".' % (
48 source,))
49 return
51 if source in self.sources:
52 logging.info('Source \"%s\" already in Config.' % (source,))
53 return
54 self.sources.append(source)
56 def RemoveSource(self, source):
57 if source not in self.sources:
58 logging.warn('Source \"%s\" not in Config.' % (source,))
59 return
60 self.sources.remove(source)
62 def RemoveAllSources(self):
63 if not self.sources:
64 logging.info('No sources to remove.')
65 return
66 self.sources = []