VirusTotal / yara-python

The Python interface for YARA
http://virustotal.github.io/yara/
Apache License 2.0
659 stars 179 forks source link

Handle pathlib Input #100

Closed utkonos closed 5 years ago

utkonos commented 5 years ago

When using a pathlib object for the file location, the match method throws an exception:

import pathlib
target = pathlib.Path().home().joinpath('Desktop').joinpath('sample.exe')
matches = rules.match(target)

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-6-176665853c8b> in <module>
----> 1 matches = rules.match(target)

TypeError: argument 1 must be str, not PosixPath
utkonos commented 5 years ago

Python 3.7.2 and yara-python 3.8.1

wxsBSD commented 5 years ago

I haven’t used pathlib much but I’m pretty sure there’s a way to convert it to a string. I don’t see any value in supporting this. Strings are universal.

wxsBSD commented 5 years ago

Oops, hit the button too early. The added complexity here isn’t worth the benefit. Just convert it to a string when you pass it in.

utkonos commented 5 years ago

Fair enough. I have been using pathlib everywhere in my code since the standard modules all began supporting it. Now I notice when 3rd party modules don't support it. Converting it to a string is fine.