Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use long when setting REG_QWORD #50063

Merged
merged 3 commits into from Oct 25, 2018
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -767,6 +767,9 @@ def cast_vdata(vdata=None, vtype='REG_SZ'):
# Make sure REG_MULTI_SZ is a list of strings
elif vtype_value == win32con.REG_MULTI_SZ:
return [_to_unicode(i) for i in vdata]
# Make sure REG_QWORD is a 64 bit integer
elif vtype_value == win32con.REG_QWORD:
return vdata if six.PY3 else long(vdata) # pylint: disable=W1699
This conversation was marked as resolved by cachedout

This comment has been minimized.

Copy link
@rallytime

rallytime Oct 16, 2018

Contributor

What about using six.integer_types here?

Seems nicer that disabling the lint error.

https://pythonhosted.org/six/#six.integer_types

This comment has been minimized.

Copy link
@twangboy

twangboy Oct 16, 2018

Author Contributor

I tried that, but it seems to only be useful for detecting types not casting.

>>> from salt.ext import six
>>> long(7)
7L
>>> six.integer_types(7)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'tuple' object is not callable
>>> isinstance(7, six.integer_types)
True
>>> isinstance(7L, six.integer_types)
True
>>>

This comment has been minimized.

Copy link
@twangboy

twangboy Oct 16, 2018

Author Contributor

@rallytime You want I should add future as a dependency instead? That works and is quite clean.

This comment has been minimized.

Copy link
@rallytime

rallytime Oct 17, 2018

Contributor

Ah, right, OK. I think this is fine as-is. I'd rather not add the dependency. Your current check works.

# Everything else is int
else:
return int(vdata)
@@ -307,6 +307,74 @@ def test_set_value_unicode_value(self):
finally:
win_reg.delete_key_recursive(hive='HKLM', key=FAKE_KEY)

@destructiveTest
def test_set_value_reg_dword(self):
'''
Test the set_value function on a unicode value
'''
try:
self.assertTrue(
win_reg.set_value(
hive='HKLM',
key=FAKE_KEY,
vname='dword_value',
vdata=123,
vtype='REG_DWORD'
)
)
expected = {
'hive': 'HKLM',
'key': FAKE_KEY,
'success': True,
'vdata': 123,
'vname': 'dword_value',
'vtype': 'REG_DWORD'
}
self.assertEqual(
win_reg.read_value(
hive='HKLM',
key=FAKE_KEY,
vname='dword_value'
),
expected
)
finally:
win_reg.delete_key_recursive(hive='HKLM', key=FAKE_KEY)

@destructiveTest
def test_set_value_reg_qword(self):
'''
Test the set_value function on a unicode value
'''
try:
self.assertTrue(
win_reg.set_value(
hive='HKLM',
key=FAKE_KEY,
vname='qword_value',
vdata=123,
vtype='REG_QWORD'
)
)
expected = {
'hive': 'HKLM',
'key': FAKE_KEY,
'success': True,
'vdata': 123,
'vname': 'qword_value',
'vtype': 'REG_QWORD'
}
self.assertEqual(
win_reg.read_value(
hive='HKLM',
key=FAKE_KEY,
vname='qword_value'
),
expected
)
finally:
win_reg.delete_key_recursive(hive='HKLM', key=FAKE_KEY)

@destructiveTest
def test_delete_value(self):
'''
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.