def __init__(self, path, creds=None):
        """
        Returns a new `UncDirectory` class.
        `path` must be a UNC directory path. If `path` cannot be construed as a valid UNC path,
               this will raise an `InvalidUncPathError`.
        `creds` may be `None` or a `UncCrednetials` object. If `None`, then the UNC directory
                must not require authentication to be connected. Otherwise, `creds` will be used
                for authentication.

        If only the first positional argument is provided and it is already an instance of the
        `UncDirectory` class (either directly or by inheritance), this constructor will clone
        it and create a new `UncDirectory` object with the same properties. Note that the clone
        is a "shallow" clone. Both the original `UncDirectory` object and its clone will use the
        same `UncCredentials` object if it was provided.
        """

        if creds is None and isinstance(path, UncDirectory):
            new_path = path._path
            new_creds = path._creds
        else:
            new_path = path
            new_creds = creds

        cleaned_path = clean_unc_path(new_path)
        if is_valid_unc_path(cleaned_path):
            self._path = cleaned_path
            self._creds = new_creds if new_creds and not new_creds.is_empty(
            ) else None
        else:
            raise InvalidUncPathError(new_path)
示例#2
0
    def __init__(self, path, creds=None):
        """
        Returns a new `UncDirectory` class.
        `path` must be a UNC directory path. If `path` cannot be construed as a valid UNC path,
               this will raise an `InvalidUncPathError`.
        `creds` may be `None` or a `UncCrednetials` object. If `None`, then the UNC directory
                must not require authentication to be connected. Otherwise, `creds` will be used
                for authentication.

        If only the first positional argument is provided and it is already an instance of the
        `UncDirectory` class (either directly or by inheritance), this constructor will clone
        it and create a new `UncDirectory` object with the same properties. Note that the clone
        is a "shallow" clone. Both the original `UncDirectory` object and its clone will use the
        same `UncCredentials` object if it was provided.
        """

        if creds is None and isinstance(path, UncDirectory):
            new_path = path._path
            new_creds = path._creds
        else:
            new_path = path
            new_creds = creds

        cleaned_path = clean_unc_path(new_path)
        if is_valid_unc_path(cleaned_path):
            self._path = cleaned_path
            self._creds = new_creds if new_creds and not new_creds.is_empty() else None
        else:
            raise InvalidUncPathError(new_path)
示例#3
0
 def test_invalid(self):
     self.assertFalse(V.is_valid_unc_path(''))
     self.assertFalse(V.is_valid_unc_path('    '))
     self.assertFalse(V.is_valid_unc_path(r'\\'))
     self.assertFalse(V.is_valid_unc_path(r'  \\a'))
     self.assertFalse(V.is_valid_unc_path(r'\\a  '))
     self.assertFalse(V.is_valid_unc_path(r'\\\a'))
     self.assertFalse(V.is_valid_unc_path(r'C:\path'))
     self.assertFalse(V.is_valid_unc_path(r'\\<a>'))
def is_unc_directory_string(string):
    """
    Returns `True` when `string` represents a `UncDirectory` as defined by `UncDirectory`'s
    `get_auth_path` method or `False` otherwise.
    """
    cleaned_string = clean_unc_path(string)
    return (is_valid_unc_path(cleaned_string)
            or ('@\\\\' in cleaned_string
                and len(cleaned_string.partition('@\\\\')[2]) > 0))
示例#5
0
def is_unc_directory_string(string):
    """
    Returns `True` when `string` represents a `UncDirectory` as defined by `UncDirectory`'s
    `get_auth_path` method or `False` otherwise.
    """
    cleaned_string = clean_unc_path(string)
    return (is_valid_unc_path(cleaned_string)
            or ('@\\\\' in cleaned_string
               and len(cleaned_string.partition('@\\\\')[2]) > 0))
示例#6
0
 def test_valid(self):
     self.assertTrue(V.is_valid_unc_path(r'\\a'))
     self.assertTrue(V.is_valid_unc_path(r'\\a\b\c'))
     self.assertTrue(V.is_valid_unc_path(r'\\ABC\\'))