Beispiel #1
0
    def test_get_creds_from_string(self):
        self.assertEqual(get_creds_from_string(''), UncCredentials(None, None))
        self.assertEqual(get_creds_from_string('user'),
                         UncCredentials('user', None))
        self.assertEqual(get_creds_from_string('user'),
                         UncCredentials('user', None))

        self.assertEqual(get_creds_from_string(':""'),
                         UncCredentials(None, '""'))
        self.assertEqual(get_creds_from_string('::'),
                         UncCredentials(None, ':'))
        self.assertEqual(get_creds_from_string(':pass'),
                         UncCredentials(None, 'pass'))

        self.assertEqual(get_creds_from_string('user:'******'user', ''))
        self.assertEqual(get_creds_from_string('user:pass'),
                         UncCredentials('user', 'pass'))
        self.assertEqual(get_creds_from_string('user::'),
                         UncCredentials('user', ':'))
def get_unc_directory_from_string(string):
    """
    Parses a string from `UncDirectory`'s `get_auth_path` method and returns a new `UncDirectory`
    object based on it. This may raise any errors that can be raised by `UncDirectory`'s
    constructor.
    """
    creds = None
    path = string

    if '@\\\\' in string:
        creds_part, path_part = string.rsplit(r'@\\', 1)  # Always split on the last `@\\` in case
                                                          # the password contains it.
        path = r'\\' + path_part
        creds = get_creds_from_string(creds_part)

    return UncDirectory(path, creds)
def get_unc_directory_from_string(string):
    """
    Parses a string from `UncDirectory`'s `get_auth_path` method and returns a new `UncDirectory`
    object based on it. This may raise any errors that can be raised by `UncDirectory`'s
    constructor.
    """
    creds = None
    path = string

    if '@\\\\' in string:
        creds_part, path_part = string.rsplit(
            r'@\\', 1)  # Always split on the last `@\\` in case
        # the password contains it.
        path = r'\\' + path_part
        creds = get_creds_from_string(creds_part)

    return UncDirectory(path, creds)