correct remarks from #481

This commit is contained in:
Alexandre Petitjean 2013-07-29 22:22:28 +02:00
parent de80c33753
commit 05733cf844
4 changed files with 29 additions and 12 deletions

View File

@ -33,10 +33,12 @@ class SpotifySessionManager(process.BaseThread, PyspotifySessionManager):
self.cache_location = config['spotify']['cache_dir']
self.settings_location = config['spotify']['cache_dir']
# Add proxy port only if available
full_proxy = config['proxy']['hostname']
if 'port' in config['proxy']:
full_proxy = full_proxy + ':' + str(config['proxy']['port'])
full_proxy = ''
if config['proxy']['hostname']:
full_proxy = config['proxy']['hostname']
# Add proxy port only if available
if config['proxy']['port']:
full_proxy = full_proxy + ':' + str(config['proxy']['port'])
PyspotifySessionManager.__init__(
self, config['spotify']['username'], config['spotify']['password'],

View File

@ -29,7 +29,7 @@ _proxy_schema = ConfigSchema('proxy')
_proxy_schema['hostname'] = Hostname(optional=True)
_proxy_schema['username'] = String(optional=True)
_proxy_schema['password'] = Secret(optional=True)
_proxy_schema['port'] = Port(optional=True)
_proxy_schema['port'] = Port()
# NOTE: if multiple outputs ever comes something like LogLevelConfigSchema
#_outputs_schema = config.AudioOutputConfigSchema()

View File

@ -16,4 +16,4 @@ output = autoaudiosink
hostname =
username =
password =
port =
port =

View File

@ -117,10 +117,7 @@ class Integer(ConfigValue):
self._choices = choices
def deserialize(self, value):
try:
value = int(value)
except:
value = 0
value = int(value)
validators.validate_choice(value, self._choices)
validators.validate_minimum(value, self._minimum)
validators.validate_maximum(value, self._maximum)
@ -225,11 +222,29 @@ class Port(Integer):
allocate a port for us.
"""
# TODO: consider probing if port is free or not?
def __init__(self, choices=None, optional=False):
self._required = not optional
def __init__(self, choices=None):
super(Port, self).__init__(
minimum=0, maximum=2 ** 16 - 1, choices=choices)
def deserialize(self, value):
# in case of no value is given, just return nothing
if not len(value):
return value
# now we can try to convert
try:
value = int(value)
except ValueError:
try:
value = socket.getservbyname(value, 'tcp')
except socket.error:
raise ValueError('must be a valid port number')
else:
validators.validate_choice(value, self._choices)
validators.validate_minimum(value, self._minimum)
validators.validate_maximum(value, self._maximum)
return value
class Path(ConfigValue):
"""File system path