def _get_connection_command(self, username=None, password=None): """ Returns the Windows command to be used to connect this UNC directory. `username` and/or `password` are used as credentials if they are supplied. """ device_str = ' "{0}"'.format(self.disk_drive) if self.disk_drive else '' password_str = ' "{0}"'.format(S.sanitize_for_shell(password)) if password else '' user_str = ' /USER:"******"'.format(S.sanitize_username(username)) if username else '' return 'NET USE{device} "{path}"{password}{user} /PERSISTENT:{persistent}'.format( device=device_str, path=S.sanitize_unc_path(self.get_path()), password=password_str, user=user_str, persistent='YES' if self.disk_drive and self.persistent else 'NO')
def _get_connection_command(self, username=None, password=None): """ Returns the Windows command to be used to connect this UNC directory. `username` and/or `password` are used as credentials if they are supplied. """ device_str = ' "{0}"'.format( self.disk_drive) if self.disk_drive else '' password_str = ' "{0}"'.format( S.sanitize_for_shell(password)) if password else '' user_str = ' /USER:"******"'.format( S.sanitize_username(username)) if username else '' return 'NET USE{device} "{path}"{password}{user} /PERSISTENT:{persistent}'.format( device=device_str, path=S.sanitize_unc_path(self.get_path()), password=password_str, user=user_str, persistent='YES' if self.disk_drive and self.persistent else 'NO')
def test_sanitize_for_shell(self): self.assertEqual(S.sanitize_for_shell(''), '') self.assertEqual(S.sanitize_for_shell('abcABC'), 'abcABC') self.assertEqual(S.sanitize_for_shell('"'), r'\"') self.assertEqual(S.sanitize_for_shell('abc"""'), r'abc\"\"\"')