-
Notifications
You must be signed in to change notification settings - Fork 272
On windows, check if the file is opened in binary mode #369
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -197,6 +197,8 @@ class Writer(object): | |
| """ | ||
|
|
||
| def __init__(self, fileobj, snaplen=1500, linktype=DLT_EN10MB, nano=False): | ||
| if fileobj.mode != 'wb': | ||
| raise ValueError('PCAP file not in binary mode (rb)') | ||
| self.__f = fileobj | ||
| self._precision = 9 if nano else 6 | ||
| magic = TCPDUMP_MAGIC_NANO if nano else TCPDUMP_MAGIC | ||
|
|
@@ -240,6 +242,9 @@ class Reader(object): | |
|
|
||
| def __init__(self, fileobj): | ||
| self.name = getattr(fileobj, 'name', '<%s>' % fileobj.__class__.__name__) | ||
| if sys.platform.startswith('win'): | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So do we want to just check 'rb' mode for all platforms? |
||
| if fileobj.mode != 'rb': | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. both mode checks feel a bit too restrictive (but make complete sense at the same time..). I personally would go with smth like
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just noticed that i did not account for append modes, your suggestion takes care of that too. |
||
| raise ValueError('PCAP file (%s) not opened in binary mode (rb)'%self.name) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pep8 |
||
| self.__f = fileobj | ||
| buf = self.__f.read(FileHdr.__hdr_len__) | ||
| self.__fh = FileHdr(buf) | ||
|
|
||
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.
add a check for Windows, same as below?
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.
Oops! yes, thanks for catching