예제 #1
0
    def test_sanitize_file_name(self):
        self.assertEqual(S.sanitize_unc_path(''), '')
        self.assertEqual(S.sanitize_unc_path('abcABC'), 'abcABC')
        self.assertEqual(S.sanitize_unc_path(r'<>"/|?*'), '')
        self.assertEqual(S.sanitize_unc_path('\0\1\2\3\4\30\31'), '')

        self.assertEqual(S.sanitize_file_name(r'C:\a valid\folder'), r'Ca validfolder')
        self.assertEqual(S.sanitize_file_name(r':\\'), r'')
    def test_sanitize_file_name(self):
        self.assertEqual(S.sanitize_unc_path(''), '')
        self.assertEqual(S.sanitize_unc_path('abcABC'), 'abcABC')
        self.assertEqual(S.sanitize_unc_path(r'<>"/|?*'), '')
        self.assertEqual(S.sanitize_unc_path('\0\1\2\3\4\30\31'), '')

        self.assertEqual(S.sanitize_file_name(r'C:\a valid\folder'),
                         r'Ca validfolder')
        self.assertEqual(S.sanitize_file_name(r':\\'), r'')
def is_valid_unc_path(string):
    """
    Valid UNC paths are at least three characters long, begin with exactly two backslashes, do not
    start or end with whitepsace, and do not contain certain invalid characters
    (see `sanitize_unc_path`).
    """
    return (len(string) > 2
            and len(take_while(lambda c: c == '\\', string)) == 2
            and string == string.strip()
            and string == sanitize_unc_path(string))
예제 #4
0
    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')
예제 #5
0
    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')