Skip to content

Also flush on read() to not return cached data. - #68

Merged
rhempel merged 1 commit into
ev3dev:masterfrom
ensonic:master
Nov 6, 2015
Merged

rhempel merged 1 commit into
ev3dev:masterfrom
ensonic:master

Conversation

@ensonic

@ensonic ensonic commented Nov 5, 2015

Copy link
Copy Markdown
Contributor

Fixes issue #67

@ddemidov

ddemidov commented Nov 5, 2015

Copy link
Copy Markdown
Member

Did you also try to open files without buffering and get read of f.flush(), as @dlech suggested?

@ddemidov

ddemidov commented Nov 5, 2015

Copy link
Copy Markdown
Member

Sorry, you did exactly that.

rhempel added a commit that referenced this pull request Nov 6, 2015
Also flush on read() to not return cached data.
@rhempel
rhempel merged commit dced8aa into ev3dev:master Nov 6, 2015
@rhempel

rhempel commented Nov 6, 2015

Copy link
Copy Markdown
Member

Thanks!

@ddemidov

ddemidov commented Nov 6, 2015

Copy link
Copy Markdown
Member

This breakes python3 compatibility. The following error is raised:

  File "./tests/../ev3dev/core.py", line 61, in file_handle
    f = open(path, mode, 0)
ValueError: can't have unbuffered text I/O

We probably don't care about python3 compatibility, but its worth mentioning.

@rhempel

rhempel commented Nov 6, 2015

Copy link
Copy Markdown
Member

Can we fix this by opening in binary mode? I know attributes are text only, but it never really hurts to open in binary mode.

@ddemidov

ddemidov commented Nov 6, 2015

Copy link
Copy Markdown
Member

I tried just replacing modes with binary versions, and it did not work. The error is:

Traceback (most recent call last):
  File "./tests/api_tests.py", line 18, in test_device
    d = ev3dev.Device('tacho-motor', 'motor*', driver_name='lego-ev3-m-motor')
  File "./tests/../ev3dev/core.py", line 136, in __init__
    if all([self._matches(k, kwargs[k]) for k in kwargs]):
  File "./tests/../ev3dev/core.py", line 136, in <listcomp>
    if all([self._matches(k, kwargs[k]) for k in kwargs]):
  File "./tests/../ev3dev/core.py", line 159, in _matches
    return value.find(pattern) >= 0
TypeError: a bytes-like object is required, not 'str'

I guess we can fix this by explicitly converting strings to bytes and the other way around where appropriate, but I am not sure if this is the best way to go.

@ensonic

ensonic commented Nov 6, 2015

Copy link
Copy Markdown
Contributor Author

Yep, I think we need to do the conversion explicitly. I'll give it a try and send a new PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants