Skip to content
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

Pcapreader() does not work with PosixPath and WindowsPath fix #3596 #3597

Closed
wants to merge 1 commit into from

Conversation

tanwirahmad
Copy link

Pcapreader() works fine even if the provided filename is in PosixPath or WindowsPath type. Fix #3596

I don't know if this PR requires unit tests. If it does, then please guide me where they can be added.

Copy link
Member

@p-l- p-l- left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this fix. I think we can (should?) use os.PathLike here. What do you think?

scapy/utils.py Outdated Show resolved Hide resolved
scapy/utils.py Outdated Show resolved Hide resolved
scapy/utils.py Outdated Show resolved Hide resolved
@tanwirahmad
Copy link
Author

I didn't know about os.PathLike. It makes perfect sense!

@tanwirahmad tanwirahmad marked this pull request as ready for review May 5, 2022 18:58
Copy link
Member

@p-l- p-l- left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK now the return type has changed, since filename might be an os.PathLike object. Also it seems that you have to specify something like PathLike[Any] (meaning either PathLike[str] or PathLike[bytes]).

@p-l-
Copy link
Member

p-l- commented May 6, 2022

Anyway, not sure it was a good idea after all, since Python 2.7 lacks os.PathLike... Sorry about that :-/

@tanwirahmad tanwirahmad requested a review from p-l- May 6, 2022 12:05
@codecov
Copy link

codecov bot commented May 6, 2022

Codecov Report

Merging #3597 (4b1e061) into master (53c764d) will increase coverage by 0.02%.
The diff coverage is 100.00%.

❗ Current head 4b1e061 differs from pull request most recent head 4f39755. Consider uploading reports for the commit 4f39755 to get more accurate results

@@            Coverage Diff             @@
##           master    #3597      +/-   ##
==========================================
+ Coverage   86.19%   86.21%   +0.02%     
==========================================
  Files         284      296      +12     
  Lines       64874    67082    +2208     
==========================================
+ Hits        55915    57832    +1917     
- Misses       8959     9250     +291     
Impacted Files Coverage Δ
scapy/libs/six.py 70.55% <100.00%> (+0.17%) ⬆️
scapy/utils.py 77.27% <100.00%> (+0.44%) ⬆️
scapy/__init__.py 74.54% <0.00%> (-8.48%) ⬇️
scapy/layers/ntlm.py 44.76% <0.00%> (-5.40%) ⬇️
scapy/layers/dhcp.py 82.67% <0.00%> (-4.61%) ⬇️
scapy/layers/smb.py 32.37% <0.00%> (-2.12%) ⬇️
scapy/layers/sctp.py 95.12% <0.00%> (-1.57%) ⬇️
scapy/layers/tls/crypto/cipher_block.py 96.24% <0.00%> (-1.42%) ⬇️
scapy/contrib/automotive/scanner/enumerator.py 90.93% <0.00%> (-1.33%) ⬇️
scapy/automaton.py 74.23% <0.00%> (-1.30%) ⬇️
... and 169 more

@p-l-
Copy link
Member

p-l- commented May 6, 2022

Sorry, I think it is better to come back to your first option, it was better since it would have worked with Python 2 directly, am I wrong?

@gpotter2
Copy link
Member

gpotter2 commented May 9, 2022

Unsure this PR is really necessary: there are quite a few ways to get the full absolute path from the Path... object :/

@tanwirahmad
Copy link
Author

@gpotter2 The purpose of this PR is to support os.PathLike objects for Pcapreader(). IMHO, they are more useful than strings based paths.

@p-l- My first option would not have worked for Python 2 because the pathlib library was added in Python 3.4

scapy/utils.py Outdated Show resolved Hide resolved
@p-l-
Copy link
Member

p-l- commented May 10, 2022

@gpotter2 your call

scapy/utils.py Outdated Show resolved Hide resolved
@tanwirahmad tanwirahmad requested a review from p-l- July 20, 2022 12:16
@p-l- p-l- requested a review from gpotter2 July 26, 2022 19:43
Copy link
Member

@gpotter2 gpotter2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • PR doesn't pass both PEP8 and Mypy tests
  • I said scapy.compat, not scapy.libs.six because we regularly update it so any changes in there would be lost.
  • PR is wrong because:
    • filename = fname is wrong in case of an os.PathLike... it's not the filename anymore
    • you can't just change the return type of filename to Union[...] just to make it pass the tests, you need to actually fix it

@gpotter2
Copy link
Member

(As for the doc build failure: sphinx-doc/sphinx#10710)

@guedou
Copy link
Member

guedou commented Jul 27, 2022

I am unsure this PR is necessary.

@gpotter2
Copy link
Member

I kinda agree. Are we really going to update every function in Scapy to support path stuff, when in one call you can get the absolute path

@guedou guedou closed this Oct 8, 2022
@guedou
Copy link
Member

guedou commented Oct 8, 2022

I am closing this PR as Scapy maintainers seem that it is not necessary.

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.

Pcapreader() does not work with PosixPath from Python's pathlib
4 participants