Esempio n. 1
0
 def destructor(self):
     assert isinstance(self, W_File)
     try:
         self.direct_close()
     except StreamErrors, e:
         operr = wrap_streamerror(self.space, e, self.w_name)
         raise operr
Esempio n. 2
0
 def destructor(self):
     assert isinstance(self, W_File)
     try:
         self.direct_close()
     except StreamErrors, e:
         operr = wrap_streamerror(self.space, e, self.w_name)
         raise operr
Esempio n. 3
0
def get_file(space, w_file, filename, filemode):
    if space.is_none(w_file):
        try:
            return streamio.open_file_as_stream(filename, filemode)
        except StreamErrors, e:
            # XXX this is not quite the correct place, but it will do for now.
            # XXX see the issue which I'm sure exists already but whose number
            # XXX I cannot find any more...
            raise wrap_streamerror(space, e)
Esempio n. 4
0
def get_file(space, w_file, filename, filemode):
    if w_file is None or space.is_w(w_file, space.w_None):
        try:
            return streamio.open_file_as_stream(filename, filemode)
        except StreamErrors, e:
            # XXX this is not quite the correct place, but it will do for now.
            # XXX see the issue which I'm sure exists already but whose number
            # XXX I cannot find any more...
            raise wrap_streamerror(space, e)
Esempio n. 5
0
 def do_write(self, data):
     """
     An interface for direct interp-level usage of W_Stream,
     e.g. from interp_marshal.py.
     NOTE: this assumes that the stream lock is already acquired.
     """
     try:
         self.stream.write(data)
     except StreamErrors, e:
         raise wrap_streamerror(self.space, e)
Esempio n. 6
0
 def do_write(self, data):
     """
     An interface for direct interp-level usage of W_Stream,
     e.g. from interp_marshal.py.
     NOTE: this assumes that the stream lock is already acquired.
     """
     try:
         self.stream.write(data)
     except StreamErrors, e:
         raise wrap_streamerror(self.space, e)
Esempio n. 7
0
 def stream_read(self, n):
     """
     An interface for direct interp-level usage of W_AbstractStream,
     e.g. from interp_marshal.py.
     NOTE: this assumes that the stream lock is already acquired.
     Like os.read(), this can return less than n bytes.
     """
     try:
         return self.stream.read(n)
     except StreamErrors, e:
         raise wrap_streamerror(self.space, e)
Esempio n. 8
0
 def stream_read(self, n):
     """
     An interface for direct interp-level usage of W_AbstractStream,
     e.g. from interp_marshal.py.
     NOTE: this assumes that the stream lock is already acquired.
     Like os.read(), this can return less than n bytes.
     """
     try:
         return self.stream.read(n)
     except StreamErrors, e:
         raise wrap_streamerror(self.space, e)
Esempio n. 9
0
def get_file(space, w_file, filename, filemode):
    if space.is_none(w_file):
        try:
            return streamio.open_file_as_stream(filename, filemode)
        except streamio.StreamErrors as e:
            # XXX this is not quite the correct place, but it will do for now.
            # XXX see the issue which I'm sure exists already but whose number
            # XXX I cannot find any more...
            raise wrap_streamerror(space, e)
    else:
        w_iobase = space.interp_w(W_IOBase, w_file)
        # XXX: not all W_IOBase have a fileno method: in that case, we should
        # probably raise a TypeError?
        fd = space.int_w(space.call_method(w_iobase, 'fileno'))
        return streamio.fdopen_as_stream(fd, filemode)
Esempio n. 10
0
 def _finalize_(self):
     # assume that the file and stream objects are only visible in the
     # thread that runs _finalize_, so no race condition should be
     # possible and no locking is done here.
     if self.stream is None:
         return
     if self.space.sys.track_resources:
         w_repr = self.space.repr(self)
         str_repr = self.space.text_w(w_repr)
         w_msg = self.space.newtext("WARNING: unclosed file: " + str_repr)
         self.space.resource_warning(w_msg, self.w_tb)
     #
     try:
         self.direct_close()
     except StreamErrors as e:
         operr = wrap_streamerror(self.space, e, self.w_name)
         raise operr
Esempio n. 11
0
 def _finalize_(self):
     # assume that the file and stream objects are only visible in the
     # thread that runs _finalize_, so no race condition should be
     # possible and no locking is done here.
     if self.stream is None:
         return
     if self.space.sys.track_resources:
         w_repr = self.space.repr(self)
         str_repr = self.space.str_w(w_repr)
         w_msg = self.space.wrap("WARNING: unclosed file: " + str_repr)
         self.space.resource_warning(w_msg, self.w_tb)
     #
     try:
         self.direct_close()
     except StreamErrors as e:
         operr = wrap_streamerror(self.space, e, self.w_name)
         raise operr
Esempio n. 12
0
def _wrap_close(space, stream):
    """stream.close(), but raising app-level exceptions"""
    try:
        stream.close()
    except StreamErrors as e:
        raise wrap_streamerror(space, e)
Esempio n. 13
0
def _wrap_readall(space, stream):
    """stream.readall(), but raising app-level exceptions"""
    try:
        return stream.readall()
    except StreamErrors as e:
        raise wrap_streamerror(space, e)
Esempio n. 14
0
def _wrap_r_long(space, stream):
    """like _r_long(), but raising app-level exceptions"""
    try:
        return _r_long(stream)
    except StreamErrors as e:
        raise wrap_streamerror(space, e)
Esempio n. 15
0
 def file_fdopen(self, fd, mode="r", buffering=-1):
     try:
         self.direct_fdopen(fd, mode, buffering)
     except StreamErrors, e:
         raise wrap_streamerror(self.space, e, self.w_name)
Esempio n. 16
0
 def file_fdopen(self, fd, mode="r", buffering=-1):
     try:
         self.direct_fdopen(fd, mode, buffering)
     except StreamErrors, e:
         raise wrap_streamerror(self.space, e, self.w_name)