Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
assert dsym['cpuName'] == 'any'
assert dsym['headers'] == {
'Content-Type': 'text/x-proguard+plain'}
assert dsym['objectName'] == 'proguard-mapping'
assert dsym['sha1'] == 'e6d3c5185dac63eddfdc1a5edfffa32d46103b44'
assert dsym['symbolType'] == 'proguard'
assert dsym['uuid'] == '6dc7fdb0-d2fb-4c8e-9d6b-bb1aa98929b1'
# Test download
response = self.client.get(url + "?id=" + download_id)
assert response.status_code == 200, response.content
assert response.get(
'Content-Disposition') == 'attachment; filename="' + PROGUARD_UUID + '.txt"'
assert response.get(
'Content-Length') == text_type(len(PROGUARD_SOURCE))
assert response.get('Content-Type') == 'application/octet-stream'
assert PROGUARD_SOURCE == BytesIO(
b"".join(response.streaming_content)).getvalue()
# Login user with no permissions
user_no_permission = self.create_user('baz@localhost', username='baz')
self.login_as(user=user_no_permission)
response = self.client.get(url + "?id=" + download_id)
assert response.status_code == 403, response.content
# Try to delete with no permissions
response = self.client.delete(url + "?id=" + download_id)
assert response.status_code == 403, response.content
# Login again with permissions
self.login_as(user=self.user)
def print_tracebacks(self, label, items):
problem_color = {
"ERROR": "error",
"FAIL": "failure"
}[label]
for item in items:
test, trace = item
desc = test.shortDescription() or six.text_type(test)
self.stream.writeln("=" * 70)
self.stream.writeln("%s: %s" % (
self.color[problem_color](label),
self.identifier(desc, bold=True),
))
self.stream.writeln("-" * 70)
# format_exception() is...very odd re: how it breaks into lines.
trace = "".join(format_exception(trace)).split("\n")
self.print_colorized_traceback(trace)
def create_user_logon_session(self, username, password, domain='.',
load_profile=True):
token = wintypes.HANDLE()
ret_val = advapi32.LogonUserW(six.text_type(username),
six.text_type(domain),
six.text_type(password), 2, 0,
ctypes.byref(token))
if not ret_val:
raise exception.WindowsCloudbaseInitException(
"User logon failed: %r")
if load_profile:
pi = Win32_PROFILEINFO()
pi.dwSize = ctypes.sizeof(Win32_PROFILEINFO)
pi.lpUserName = six.text_type(username)
ret_val = userenv.LoadUserProfileW(token, ctypes.byref(pi))
if not ret_val:
kernel32.CloseHandle(token)
raise exception.WindowsCloudbaseInitException(
"Cannot load user profile: %r")
return token
def _validate(self):
"""Run the validators found in self._defaults on all the corresponding values."""
errors = []
for k in self._defaults.keys():
try:
validator = self._defaults[k]['validator']
if validator is not None:
self[k] = validator(self[k])
except ValueError as e:
errors.append(u'\t{}: {}'.format(k, six.text_type(e)))
if errors:
raise ValueError(
u'Invalid config values were set: \n{}'.format(u'\n'.join(errors)))
The main difference from gettext.install() is that we allow
overriding the default localedir (e.g. /usr/share/locale) using
a translation-domain-specific environment variable (e.g.
NOVA_LOCALEDIR).
Note that to enable lazy translation, enable_lazy must be
called.
:param domain: the translation domain
"""
from six import moves
tf = TranslatorFactory(domain)
moves.builtins.__dict__['_'] = tf.primary
class Message(six.text_type):
"""A Message object is a unicode object that can be translated.
Translation of Message is done explicitly using the translate() method.
For all non-translation intents and purposes, a Message is simply unicode,
and can be treated as such.
"""
def __new__(cls, msgid, msgtext=None, params=None,
domain='zaqar', *args):
"""Create a new Message object.
In order for translation to work gettext requires a message ID, this
msgid will be used as the base unicode text. It is also possible
for the msgid and the base unicode text to be different by passing
the msgtext parameter.
"""
full_key = ""
if reg_key.hive:
full_key += reg_key.hive.value + "\\"
if reg_key.key:
full_key += reg_key.key.value
cybox_reg["key"] = full_key
else:
error("windows-registry-key is required to have a key property", 608)
if reg_key.values:
cybox_reg["values"] = []
for v in reg_key.values:
reg_value = {}
if hasattr(v, "data") and v.data:
reg_value["data"] = text_type(v.data)
if hasattr(v, "name") and v.name:
reg_value["name"] = text_type(v.name)
if hasattr(v, "datatype") and v.datatype:
reg_value["data_type"] = text_type(v.datatype)
cybox_reg["values"].append(reg_value)
if reg_key.modified_time:
if get_option_value("spec_version") == "2.0":
cybox_reg["modified"] = convert_timestamp_to_string(reg_key.modified_time.value)
else:
cybox_reg["modified_time"] = convert_timestamp_to_string(reg_key.modified_time.value)
finish_sco(cybox_reg, reg_key.parent.id_)
if reg_key.creator_username:
user_obj = create_base_sco("user-account", other_properties={"user_id": text_type(reg_key.creator_username)})
finish_sco(user_obj, None)
if get_option_value("spec_version") == "2.0":
result = dict()
result["0"] = cybox_reg
if user_obj:
def __init__(self, color, *args, **kwargs):
logging.Formatter.__init__(self, *args, **kwargs)
self._color = color
if color:
fg_color = (
curses.tigetstr("setaf") or curses.tigetstr("setf") or ""
)
if (3, 0) < sys.version_info < (3, 2, 3):
fg_color = six.text_type(fg_color, "ascii")
self._colors = {
logging.DEBUG: six.text_type(
curses.tparm(fg_color, 4), "ascii"
), # Blue
logging.INFO: six.text_type(
curses.tparm(fg_color, 2), "ascii"
), # Green
logging.WARNING: six.text_type(
curses.tparm(fg_color, 3), "ascii"
), # Yellow
logging.ERROR: six.text_type(
curses.tparm(fg_color, 1), "ascii"
), # Red
}
self._normal = six.text_type(curses.tigetstr("sgr0"), "ascii")
def __init__(self, data):
self.data = data
# Validate the first tuple only.
if len(self.data):
assert isinstance(self.data[0][0], six.text_type)
assert isinstance(self.data[0][1], six.text_type)
def convert_hashes(hashes):
hash_dict = {}
for h in hashes:
if getattr(h, "simple_hash_value"):
hash_value = h.simple_hash_value
else:
hash_value = h.fuzzy_hash_value
if text_type(h.type_).startswith("SHA"):
hash_type = "'" + "SHA" + "-" + text_type(h.type_)[3:] + "'"
elif text_type(h.type_) == "SSDEEP":
hash_type = text_type(h.type_).lower()
else:
hash_type = text_type(h.type_)
hash_dict[hash_type] = hash_value.value
return hash_dict
flash_cache_capable = pool['flashCacheCapable']
pool_ssc_info[self.FLASH_CACHE_UQ_SPEC] = (
six.text_type(flash_cache_capable).lower())
# Data Assurance is not compatible with some backend types
da_capable = pool['dataAssuranceCapable'] and (
self._is_data_assurance_supported())
pool_ssc_info[self.DA_UQ_SPEC] = (
six.text_type(da_capable).lower())
pool_ssc_info[self.RAID_UQ_SPEC] = (
self.SSC_RAID_TYPE_MAPPING.get(pool['raidLevel'], 'unknown'))
pool_ssc_info[self.THIN_UQ_SPEC] = (
six.text_type(pool['thinProvisioningCapable']).lower())
if pool['pool'].get("driveMediaType") == 'ssd':
pool_ssc_info[self.DISK_TYPE_UQ_SPEC] = 'SSD'
else:
pool_ssc_info[self.DISK_TYPE_UQ_SPEC] = (
self.SSC_DISK_TYPE_MAPPING.get(
pool['pool'].get('drivePhysicalType'), 'unknown'))
self._ssc_stats = ssc_stats