-
Notifications
You must be signed in to change notification settings - Fork 52
WIP: implement stream in cwrap (Scheduled for 2.2) #1362
base: master
Are you sure you want to change the base?
Conversation
python/python/cwrap/stream.py
Outdated
TYPE_NAME = "stream" | ||
|
||
_fopen = LibcPrototype("void* fopen(char*, char*)") | ||
_fread = LibcPrototype("int fread(void*, int, int, stream)") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These int
values should be size_t
.
Now - this is ambitious; but would of course be extremely cool if it worked out! |
python/python/cwrap/stream.py
Outdated
while True: | ||
ch = self.read(1) | ||
out += ch | ||
if ch == '\n': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess Python has some platform dependent newline encoding somewhere.
python/python/cwrap/stream.py
Outdated
raise IOError('File "%s" is closed.' % self._fname) | ||
|
||
def read(self, size=-1): | ||
self._ass_open() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hahahaha!
python/python/cwrap/stream.py
Outdated
self._mode = mode | ||
self._fname = fname | ||
|
||
self.closed = False # A closed file cannot be used for further I/O |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be prefixed with _
and then have a read only property for closed?
python/python/cwrap/stream.py
Outdated
|
||
def _bytemode(self): | ||
return 'b' in self._mode | ||
def _textmode(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some space please.
python/python/cwrap/stream.py
Outdated
return self._fwrite(np_arr.ctypes.data, 1, len(np_arr), self) | ||
|
||
def close(self): | ||
print('%s.close()' % self) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Debug?
python/python/cwrap/stream.py
Outdated
return 'b' not in self._mode | ||
|
||
def _writable(self): | ||
for m in 'wa+': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return any(m in self._mode for m in 'rw+')
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return any(m in self._mode for m in 'wa+')
Possible alternative based on fd: http://stackoverflow.com/questions/23008895/is-it-possible-to-rescue-file-descriptor-from-file |
Thanks, yes, this implementation needs to be thoroughly discussed. Will the example you linked to have the seek synchronized? One of the main issues is the problem of synchronizing the stream positions, and it doesn't seem like that example handles that. |
* readline and with statement * yield operator * bytes mode * assert_open_function * tests
No description provided.