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.
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
)):
29 def __init__(self
, data
=None):
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\".' % (
51 if source
in self
.sources
:
52 logging
.info('Source \"%s\" already in Config.' % (source
,))
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
,))
60 self
.sources
.remove(source
)
62 def RemoveAllSources(self
):
64 logging
.info('No sources to remove.')