def sfo_seek(interp, this, line_pos): if line_pos < 0: raise PHPException(k_LogicException.call_args( interp, [interp.space.wrap( "SplFileObject::seek(): Can't seek file %s " "to negative line %d" % (this.file_name, line_pos))])) this.w_res.seek_to_line(line_pos, this.flags & SFO_DROP_NEW_LINE)
def sfo_construct(interp, this, filename, open_mode='r', use_include_path=False, w_ctx=None): this.file_name = filename this.path_name = rpath.realpath(filename) this.delimiter = "," this.enclosure = '"' this.flags = 0 this.open_mode = open_mode this.use_include_path = use_include_path this.w_res = None this.max_line_len = 0 if w_ctx: if not interp.space.is_resource(w_ctx): raise PHPException(k_RuntimeException.call_args( interp, [interp.space.wrap( "SplFileObject::__construct() expects " "parameter 4 to be resource, %s given" % interp.space.get_type_name(w_ctx.tp).lower())])) assert filename is not None if os.path.isdir(filename): raise PHPException(k_LogicException.call_args( interp, [interp.space.wrap( "Cannot use SplFileObject with directories")])) try: this.w_res = _fopen(interp.space, filename, this.open_mode, use_include_path, w_ctx) if this.w_res == interp.space.w_False: raise PHPException(k_RuntimeException.call_args( interp, [interp.space.wrap( "SplFileObject::__construct(): Failed to open stream")])) except FopenError as e: raise PHPException(k_RuntimeException.call_args(interp, [interp.space.wrap(e.reasons.pop())]))
def sfo_construct(interp, this, filename, open_mode='r', use_include_path=False, w_ctx=None): this.file_name = filename this.path_name = rpath.realpath(filename) this.delimiter = "," this.enclosure = '"' this.flags = 0 this.open_mode = open_mode this.use_include_path = use_include_path this.w_res = None this.max_line_len = 0 if w_ctx: if not interp.space.is_resource(w_ctx): raise PHPException( k_RuntimeException.call_args(interp, [ interp.space.wrap( "SplFileObject::__construct() expects " "parameter 4 to be resource, %s given" % interp.space.get_type_name(w_ctx.tp).lower()) ])) assert filename is not None if os.path.isdir(filename): raise PHPException( k_LogicException.call_args(interp, [ interp.space.wrap("Cannot use SplFileObject with directories") ])) try: this.w_res = _fopen(interp.space, filename, this.open_mode, use_include_path, w_ctx) if this.w_res == interp.space.w_False: raise PHPException( k_RuntimeException.call_args(interp, [ interp.space.wrap( "SplFileObject::__construct(): Failed to open stream") ])) except FopenError as e: raise PHPException( k_RuntimeException.call_args(interp, [interp.space.wrap(e.reasons.pop())]))