Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def mount_options(self, device):
return match_config(self.filters, device, 'options', None)
def ignore_device(self, device):
return match_config(self.filters, device, 'ignore', False)
def test_timeout(self):
"""The cached password expires after the specified timeout."""
device = TestDev('ALPHA')
password = '{<}hëllo ωορλδ!{>}'
cache = PasswordCache(1)
cache[device] = password
self.assertEqual(cache[device], password)
time.sleep(1.5)
with self.assertRaises(KeyError):
_ = cache[device]
def test_update(self):
device = TestDev('DELTA')
password = '{<}hëllo ωορλδ!{>}'
cache = PasswordCache(0)
cache[device] = password
self.assertEqual(cache[device], password)
cache[device] = password * 2
self.assertEqual(cache[device], password*2)
del cache[device]
with self.assertRaises(KeyError):
_ = cache[device]
def test_touch(self):
"""Key access refreshes the timeout."""
device = TestDev('BETA')
password = '{<}hëllo ωορλδ!{>}'
cache = PasswordCache(3)
cache[device] = password
time.sleep(2)
self.assertEqual(cache[device], password)
time.sleep(2)
self.assertEqual(cache[device], password)
time.sleep(4)
with self.assertRaises(KeyError):
_ = cache[device]
def test_revoke(self):
"""A key can be deleted manually."""
device = TestDev('GAMMA')
password = '{<}hëllo ωορλδ!{>}'
cache = PasswordCache(0)
cache[device] = password
self.assertEqual(cache[device], password)
del cache[device]
with self.assertRaises(KeyError):
_ = cache[device]
def device_id(self):
"""
Return a unique and persistent identifier for the device.
This is the basename (last path component) of the symlink in
`/dev/disk/by-id/`.
"""
if self.is_block:
for filename in self._P.Block.Symlinks:
parts = decode_ay(filename).split('/')
if parts[-2] == 'by-id':
return parts[-1]
elif self.is_drive:
return self._assocdrive._P.Drive.Id
return ''
'password_cache': False,
'notify_command': None,
})
option_rules = extend(_EntryPoint.option_rules, {
'automount': Switch('automount'),
'notify': Switch('notify'),
'tray': Choice({
'--tray': True,
'--no-tray': False,
'--smart-tray': 'auto'}),
'menu': Value('--menu'),
'appindicator': Switch('appindicator'),
'file_manager': OptionalValue('--file-manager'),
'password_prompt': OptionalValue('--password-prompt'),
'password_cache': OptionalValue('--password-cache'),
'notify_command': OptionalValue('--notify-command'),
})
def _init(self):
import udiskie.prompt
config = self.config
options = self.options
# prepare mounter object
prompt = udiskie.prompt.password(options['password_prompt'])
browser = udiskie.prompt.browser(options['file_manager'])
terminal = udiskie.prompt.browser(options['terminal'])
cache = None
'notify_command': None,
})
option_rules = extend(_EntryPoint.option_rules, {
'automount': Switch('automount'),
'notify': Switch('notify'),
'tray': Choice({
'--tray': True,
'--no-tray': False,
'--smart-tray': 'auto'}),
'menu': Value('--menu'),
'appindicator': Switch('appindicator'),
'file_manager': OptionalValue('--file-manager'),
'password_prompt': OptionalValue('--password-prompt'),
'password_cache': OptionalValue('--password-cache'),
'notify_command': OptionalValue('--notify-command'),
})
def _init(self):
import udiskie.prompt
config = self.config
options = self.options
# prepare mounter object
prompt = udiskie.prompt.password(options['password_prompt'])
browser = udiskie.prompt.browser(options['file_manager'])
terminal = udiskie.prompt.browser(options['terminal'])
cache = None
try:
'terminal': '',
'password_prompt': 'builtin:gui',
'password_cache': False,
'notify_command': None,
})
option_rules = extend(_EntryPoint.option_rules, {
'automount': Switch('automount'),
'notify': Switch('notify'),
'tray': Choice({
'--tray': True,
'--no-tray': False,
'--smart-tray': 'auto'}),
'menu': Value('--menu'),
'appindicator': Switch('appindicator'),
'file_manager': OptionalValue('--file-manager'),
'password_prompt': OptionalValue('--password-prompt'),
'password_cache': OptionalValue('--password-cache'),
'notify_command': OptionalValue('--notify-command'),
})
def _init(self):
import udiskie.prompt
config = self.config
options = self.options
# prepare mounter object
prompt = udiskie.prompt.password(options['password_prompt'])
browser = udiskie.prompt.browser(options['file_manager'])
terminal = udiskie.prompt.browser(options['terminal'])