Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def value_from_raw(self, raw):
if raw.value is None:
return raw.missing_value('Missing boolean')
val = bool_from_string(raw.value.strip().lower())
if val is None:
return raw.bad_value('Bad boolean value')
return val
def get_server(self, name, public=False):
"""Looks up a server info by name."""
info = self.values['SERVERS'].get(name)
if info is None:
return None
target = info.get('target')
if target is None:
return None
if public:
target = secure_url(target)
return ServerInfo(
id=name,
name_i18n=get_i18n_block(info, 'name'),
target=target,
enabled=bool_from_string(info.get('enabled'), True),
default=bool_from_string(info.get('default'), False)
)
def get_server(self, name, public=False):
"""Looks up a server info by name."""
info = self.values['SERVERS'].get(name)
if info is None or 'target' not in info:
return None
info = info.copy()
target = info.pop('target')
if public:
target = secure_url(target)
return ServerInfo(
id=name,
name_i18n=get_i18n_block(info, 'name', pop=True),
target=target,
enabled=bool_from_string(info.pop('enabled', None), True),
default=bool_from_string(info.pop('default', None), False),
extra=info
)
def get_server(self, name, public=False):
"""Looks up a server info by name."""
info = self.values['SERVERS'].get(name)
if info is None:
return None
target = info.get('target')
if target is None:
return None
if public:
target = secure_url(target)
return ServerInfo(
id=name,
name_i18n=get_i18n_block(info, 'name'),
target=target,
enabled=bool_from_string(info.get('enabled'), True),
default=bool_from_string(info.get('default'), False)
)
def get_server(self, name, public=False):
"""Looks up a server info by name."""
info = self.values['SERVERS'].get(name)
if info is None or 'target' not in info:
return None
info = info.copy()
target = info.pop('target')
if public:
target = secure_url(target)
return ServerInfo(
id=name,
name_i18n=get_i18n_block(info, 'name', pop=True),
target=target,
enabled=bool_from_string(info.pop('enabled', None), True),
default=bool_from_string(info.pop('default', None), False),
extra=info
)
def to_json(self, pad, record=None, alt=PRIMARY_ALT):
return {
'name': self.name,
'label': self.label,
'label_i18n': self.label_i18n,
'hide_label': bool_from_string(self.options.get('hide_label'),
default=False),
'description_i18n': self.description_i18n,
'type': self.type.to_json(pad, record, alt),
'default': self.default,
}
def ignore_missing(self):
return bool_from_string(self.get_config().get("ignore_missing"), False)
def to_json(self, pad, record=None, alt=PRIMARY_ALT):
return {
'name': self.name,
'label': self.label,
'label_i18n': self.label_i18n,
'hide_label': bool_from_string(self.options.get('hide_label'),
default=False),
'description_i18n': self.description_i18n,
'type': self.type.to_json(pad, record, alt),
'default': self.default,
}
def value_from_raw(self, raw):
if raw.value is None:
return raw.missing_value('Missing boolean')
val = bool_from_string(raw.value.strip().lower())
if val is None:
return raw.bad_value('Bad boolean value')
return val
def get_server(self, name, public=False):
"""Looks up a server info by name."""
info = self.values['SERVERS'].get(name)
if info is None or 'target' not in info:
return None
info = info.copy()
target = info.pop('target')
if public:
target = secure_url(target)
return ServerInfo(
id=name,
name_i18n=get_i18n_block(info, 'name', pop=True),
target=target,
enabled=bool_from_string(info.pop('enabled', None), True),
default=bool_from_string(info.pop('default', None), False),
extra=info
)