예제 #1
0
파일: php_dir.py 프로젝트: youaani/hippyvm
def dir(interp, directory, w_ctx=None):
    space = interp.space

    if w_ctx:
        if not interp.space.is_resource(w_ctx):
            interp.warn("dir() expects parameter 2 to be resource, %s given" %
                        interp.space.get_type_name(w_ctx.tp).lower())
            return interp.space.w_Null

    if directory == '':
        return interp.space.w_False

    if not os.path.isdir(directory):
        warn_str = "dir(" + directory + \
                   "): failed to open dir: No such file or directory"
        interp.warn(warn_str)
        return interp.space.w_False

    w_directory = W_Directory(k_Directory, [])
    w_directory.path = space.newstr(directory)

    w_handle = W_DirResource(space, directory)
    w_handle.open()
    w_directory.handle = w_handle

    return w_directory
예제 #2
0
파일: spl.py 프로젝트: CodeOps/hippyvm
def di_construct(interp, this, path):
    if path == "":
        raise PHPException(k_RuntimeException.call_args(
            interp, [interp.space.wrap(
                "Directory name must not be empty.")]))
    this.path = path
    this.file_name = path
    this.index = 0
    if not os.path.isdir(path):
        raise PHPException(k_UnexpectedValueException.call_args(
            interp, [interp.space.wrap(
                "DirectoryIterator::__construct(%s): failed to open dir: No "
                "such file or directory" % path)]))
    try:
        w_dir = W_DirResource(interp.space, path)
        w_dir_res = w_dir.open()
        if not isinstance(w_dir_res, W_DirResource):
            raise OSError   # rare case, but annotation fix
        this.w_dir_res = w_dir_res
        this.path_name = _di_pathname(this)
    except OSError:
        raise PHPException(k_RuntimeException.call_args(
            interp, [interp.space.wrap(
                "DirectoryIterator::__construct(): error while opening stream"
            )]))
예제 #3
0
def dir(interp, directory, w_ctx=None):
    space = interp.space

    if w_ctx:
        if not interp.space.is_resource(w_ctx):
            interp.warn("dir() expects parameter 2 to be resource, %s given"
                    % interp.space.get_type_name(w_ctx.tp).lower())
            return interp.space.w_Null

    if directory == '':
        return interp.space.w_False

    if not os.path.isdir(directory):
        warn_str = "dir(" + directory + \
                   "): failed to open dir: No such file or directory"
        interp.warn(warn_str)
        return interp.space.w_False

    w_directory = W_Directory(k_Directory, [])
    w_directory.path = space.newstr(directory)

    w_handle = W_DirResource(space, directory)
    w_handle.open()
    w_directory.handle = w_handle

    return w_directory
예제 #4
0
def di_construct(interp, this, path):
    if path == "":
        raise PHPException(k_RuntimeException.call_args(
            interp, [interp.space.wrap(
                "Directory name must not be empty."
                )]))
    this.path = path
    this.file_name = path
    this.index = 0
    if not os.path.isdir(path):
        raise PHPException(k_UnexpectedValueException.call_args(
            interp, [interp.space.wrap(
                "DirectoryIterator::__construct(%s): failed to open dir: No "
                "such file or directory" % path)]))
    try:
        w_dir = W_DirResource(interp.space, path)
        w_dir_res = w_dir.open()
        if not isinstance(w_dir_res, W_DirResource):
            raise OSError   # rare case, but annotation fix
        this.w_dir_res = w_dir_res
        this.path_name = _di_pathname(this)
    except OSError:
        raise PHPException(k_RuntimeException.call_args(
            interp, [interp.space.wrap(
                "DirectoryIterator::__construct(): error while opening stream"
                )]))
예제 #5
0
파일: spl.py 프로젝트: youaani/hippyvm
def rdi_construct(interp,
                  this,
                  path,
                  flags=FI_KEY_AS_PATHNAME | FI_CURRENT_AS_FILEINFO):
    if not os.path.isdir(path):
        raise PHPException(
            k_UnexpectedValueException.call_args(interp, [
                interp.space.wrap(
                    "RecursiveDirectoryIterator::__construct(%s): failed to open dir: No "
                    "such file or directory" % path)
            ]))
    this.flags = flags
    this.path = path
    this.file_name = path
    this.index = 0
    try:
        w_dir = W_DirResource(interp.space, path, this.flags & FI_SKIP_DOTS)
        w_dir_res = w_dir.open()
        if not isinstance(w_dir_res, W_DirResource):
            raise OSError
        this.w_dir_res = w_dir_res
        this.path_name = _di_pathname(this)
    except OSError:
        raise PHPException(
            k_RuntimeException.call_args(interp, [
                interp.space.wrap(
                    "RecursiveDirectoryIterator::__construct(): error while opening stream"
                )
            ]))
예제 #6
0
파일: spl.py 프로젝트: CodeOps/hippyvm
def rdi_construct(interp, this, path, flags=
        FI_KEY_AS_PATHNAME | FI_CURRENT_AS_FILEINFO):
    if not os.path.isdir(path):
        raise PHPException(k_UnexpectedValueException.call_args(
            interp, [interp.space.wrap(
                "RecursiveDirectoryIterator::__construct(%s): failed to open dir: No "
                "such file or directory" % path)]))
    this.flags = flags
    this.path = path
    this.file_name = path
    this.index = 0
    try:
        w_dir = W_DirResource(interp.space, path, this.flags & FI_SKIP_DOTS)
        w_dir_res = w_dir.open()
        if not isinstance(w_dir_res, W_DirResource):
            raise OSError
        this.w_dir_res = w_dir_res
        this.path_name = _di_pathname(this)
    except OSError:
        raise PHPException(k_RuntimeException.call_args(
            interp, [interp.space.wrap(
                "RecursiveDirectoryIterator::__construct(): error while opening stream"
                )]))