Converts reference to :class:`Path <pathlib.Path>`

        :raise ValueError: If ``reference`` can't be converted to :class:`Path <pathlib.Path>`.
19252
def validate_reference(self, reference: ReferenceDefinitionType) -> Optional[Path]:
        
        if reference is not None:
            if isinstance(reference, bytes):
                reference = reference.decode("utf-8")
            try:
                return Path(reference)
            except TypeError:
                raise ValueError(f"Can't convert reference path {reference} to a pathlib.Path")

        return None
795555
def convert(self, value, *args, **kwargs):  # pylint: disable=arguments-differ
        """"""
        value = os.path.expanduser(value)
        return super(ExpandPath, self).convert(value, *args, **kwargs)
556115
def changeTo(self, path):
        '''
        '''
        dictionary = DictSingle(Pair('PATH', StringSingle(path)))
        self.value = [dictionary]
567028
def path(cls, name, type_=Type.String, description=None, default=None,
             minimum=None, maximum=None, enum=None, **options):
        
        if minimum is not None and maximum is not None and minimum > maximum:
            raise ValueError("Minimum must be less than or equal to the maximum.")
        return cls(name, In.Path, type_, None, description,
                   default=default, minimum=minimum, maximum=maximum,
                   enum=enum, required=True, **options)
253474
def load_class(path):
    
    class_data = path.split(".")
    if len(class_data) < 2:
        raise ValueError(
            "You need to pass a valid path like mymodule.provider_class")
    module_path = ".".join(class_data[:-1])
    class_str = class_data[-1]
    module = importlib.import_module(module_path)
    return getattr(module, class_str)
763031
def from_file(cls, path):

        

        with open(path, 'r', errors='replace') as f:
            return cls(f.read())
1078273
def from_path(cls, path: pathlib.Path) -> 'Entity':
        
        if path.is_file():
            return File.from_path(path)
        return Directory.from_path(path)
79692
def require_remote_ref_path(func):
    """"""

    def wrapper(self, *args):
        if not self.is_remote():
            raise ValueError("ref path does not point to a remote reference: %s" % self.path)
        return func(self, *args)
    # END wrapper
    wrapper.__name__ = func.__name__
    return wrapper
352635
def path_to_reference(path):
    """"""

    # By default JSON decodes strings as unicode. The Python __import__ does
    # not like that choice. So we'll just cast all function paths to a string.
    # NOTE: that there is no corresponding unit test for the classmethod
    # version of this problem.  It only impacts importing modules.
    path = str(path)

    if '.' not in path:
        try:
            return globals()["__builtins__"][path]
        except KeyError:
            try:
                return getattr(globals()["__builtins__"], path)
            except AttributeError:
                pass

        try:
            return globals()[path]
        except KeyError:
            pass

        raise errors.BadObjectPathError(
            'Unable to find function "%s".' % (path,))

    module_path, function_name = path.rsplit('.', 1)

    try:
        module = __import__(name=module_path,
                            fromlist=[function_name])
    except ImportError:
        module_path, class_name = module_path.rsplit('.', 1)

        module = __import__(name=module_path, fromlist=[class_name])
        module = getattr(module, class_name)

    try:
        return getattr(module, function_name)
    except AttributeError:
        raise errors.BadObjectPathError(
            'Unable to find function "%s".' % (path,))
301488
def _absolute_path(path, relative_to=None):
    '''
    
    '''

    if path and os.path.isabs(path):
        return path
    if path and relative_to is not None:
        _abspath = os.path.join(relative_to, path)
        if os.path.isfile(_abspath):
            log.debug(
                'Relative path \'%s\' converted to existing absolute path '
                '\'%s\'', path, _abspath
            )
            return _abspath
    return path
1306162
def path(self, path: str):
        

        path = path if path else ''
        self.pathName = os.path.join(path, self.name)
432251
def to_child_field(cls):
    

    class ChildConverter(object):

        def __init__(self, cls):
            self._cls = cls

        @property
        def cls(self):
            return resolve_class(self._cls)

        def __call__(self, value):
            try:
                # Issue #33: if value is the class and callable, then invoke
                if value == self._cls and callable(value):
                    value = value()

                return to_model(self.cls, value)
            except ValueError as e:
                error_msg = CHILD_ERROR_MSG.format(value, self.cls, str(e))
                raise ValueError(error_msg)

    return ChildConverter(cls)
1190358
def joinpath(self, *args):
        
        return self.__class__(os.path.join(self, *args))
869792
def _get_from_path(import_path):
    # type: (str) -> Callable
    
    module_name, obj_name = import_path.rsplit('.', 1)
    module = import_module(module_name)
    return getattr(module, obj_name)
1359309
def p_type_ref(self, p):
        ''
        p[0] = AstTypeRef(
            path=self.path,
            lineno=p.lineno(1),
            lexpos=p.lexpos(1),
            name=p[1],
            args=p[2],
            nullable=p[3],
            ns=None,
        )
189987
def do_reference(self, parent=None, ident=0):
        
        (handle,) = self._readStruct(">L")
        log_debug("## Reference handle: 0x{0:X}".format(handle), ident)
        ref = self.references[handle - self.BASE_REFERENCE_IDX]
        log_debug("###-> Type: {0} - Value: {1}".format(type(ref), ref), ident)
        return ref
1087212
def _resolve_path(obj, path=None):
        
        if path:
            for attr_name in path.split('__'):
                obj = getattr(obj, attr_name)
        return obj