Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def name(self, name):
self._validate_type('name', name, string_types)
self._name = name
def handle_value(k):
is_zero_dim_ndarray = isinstance(k, np.ndarray) and k.ndim == 0
if isinstance(k, six.string_types):
return k
elif isinstance(k, Iterable) and not is_zero_dim_ndarray:
return '"[%s]"' % (', '.join(map(str, k)))
else:
return k
""" Returns the list of features that are enabled for the user.
Args:
user_id: ID for user.
attributes: Dict representing user attributes.
Returns:
A list of the keys of the features that are enabled for the user.
"""
enabled_features = []
if not self.is_valid:
self.logger.error(enums.Errors.INVALID_OPTIMIZELY.format('get_enabled_features'))
return enabled_features
if not isinstance(user_id, string_types):
self.logger.error(enums.Errors.INVALID_INPUT.format('user_id'))
return enabled_features
if not self._validate_user_inputs(attributes):
return enabled_features
project_config = self.config_manager.get_config()
if not project_config:
self.logger.error(enums.Errors.INVALID_PROJECT_CONFIG.format('get_enabled_features'))
return enabled_features
for feature in project_config.feature_key_map.values():
if self.is_feature_enabled(feature.key, user_id, attributes):
enabled_features.append(feature.key)
return enabled_features
def validate(self, instance, value):
"""Check shape and dtype of vector
validate also coerces the vector from valid strings (these
include ZERO, X, Y, Z, -X, -Y, -Z, EAST, WEST, NORTH, SOUTH, UP,
and DOWN) and scales it to the given length.
"""
if isinstance(value, string_types):
if value.upper() not in VECTOR_DIRECTIONS:
self.error(instance, value)
value = VECTOR_DIRECTIONS[value.upper()]
return super(Vector3, self).validate(instance, value)
def __getitem__(self, key):
out = copy.copy(self)
# return a child, and adjust the data so that only the corresponding
# column is returned
if isinstance(key, string_types):
try:
col = list(self.template._all_keys()).index(key)
except ValueError:
raise KeyError(key)
out.level += 1
out.template = out.template[key]
out.imap.append(deep_map(operator.itemgetter(col), out.level))
# return a new sequence with the selected children
elif isinstance(key, list):
cols = [list(self.template.keys()).index(k) for k in key]
out.template._visible_keys = key
out.imap.append(deep_map(
lambda row: tuple(row[i] for i in cols), out.level+1))
# slice the data
def normalize_column_name(name):
"""Check if a string is a reasonable thing to use as a column name."""
if not isinstance(name, string_types):
raise ValueError('%r is not a valid column name.' % name)
name = name.strip()
if not len(name) or '.' in name or '-' in name:
raise ValueError('%r is not a valid column name.' % name)
return name
def get_image_name(self, files):
"""Get the image name based on options
If the `standard` option that is an optional package
the a custom image will be created.
"""
image = 'php'
standard = self.options.get('standard', None)
if not standard or standard not in OPTIONAL_PACKAGES:
return image
if not isinstance(standard, six.string_types):
error = IssueComment(
u'The `phpcs.standard` option must be a string got `{}` instead.'.format(
standard.__class__.__name__
)
)
self.problems.add(error)
return image
container_name = docker.generate_container_name('phpcs-', files)
if self.custom_image is None:
log.info('Installing phpcs package into %s', container_name)
docker.run(
image,
['phpcs-install', OPTIONAL_PACKAGES[standard].package],
source_dir=self.base_path,
def is_ignored_message(record):
if record.levelno < logging.WARNING:
return False
for prefix in IGNORED_MESSAGE_PREFIXES:
if isinstance(record.msg, string_types) and record.msg.startswith(prefix):
return True
return False
def _pad_pin(pin):
if not isinstance(pin, six.string_types):
raise ValueError("PIN of wrong type, expecting %s" % six.string_types)
if len(pin) < 4:
raise ValueError("PIN must be >= 4 characters")
pin = pin.encode("utf8").ljust(64, b"\0")
pin += b"\0" * (-(len(pin) - 16) % 16)
if len(pin) > 255:
raise ValueError("PIN must be <= 255 bytes")
return pin
if permitted_auth_types_cnt == 0:
# Decode the reason why the request failed
reason_len_raw = recv(compute_sock, 4)
reason_len = struct.unpack('!I', reason_len_raw)[0]
reason = recv(compute_sock, reason_len)
tenant_sock.sendall(auth.AUTH_STATUS_FAIL +
reason_len_raw + reason)
raise exception.SecurityProxyNegotiationFailed(reason=reason)
f = recv(compute_sock, permitted_auth_types_cnt)
permitted_auth_types = []
for auth_type in f:
if isinstance(auth_type, six.string_types):
auth_type = ord(auth_type)
permitted_auth_types.append(auth_type)
LOG.debug("The server sent security types %s", permitted_auth_types)
# Negotiate security with client before we say "ok" to the server
# send 1:[None]
tenant_sock.sendall(auth.AUTH_STATUS_PASS +
six.int2byte(auth.AuthType.NONE))
client_auth = six.byte2int(recv(tenant_sock, 1))
if client_auth != auth.AuthType.NONE:
self._fail(tenant_sock, compute_sock,
_("Only the security type None (%d) is supported") %
auth.AuthType.NONE)