Skip to content

Commit

Permalink
Fix for option --csv (#29)
Browse files Browse the repository at this point in the history
* importlib_resources does not provide read_text anymore from python3.9 :/

* Bump version

* Fix mypy

---------

Co-authored-by: tristanlatr <tristanlatr@users.noreply.github.com>
  • Loading branch information
tristanlatr and tristanlatr committed Jan 29, 2024
1 parent 255ae2a commit d54f92c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
2 changes: 1 addition & 1 deletion burpa/__version__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__author__ = 'Adel "0x4d31" Karimi, and other contributors'
__version__ = '0.3.11'
__version__ = '0.3.12'
4 changes: 2 additions & 2 deletions burpa/_burpa.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
from ._burp_commander import BurpCommander
from ._error import BurpaError
from ._utils import (get_valid_filename, parse_commas_separated_str, ensure_scheme,
parse_targets, setup_logger, perform, is_timenow_between, strip_tags)
parse_targets, setup_logger, perform, is_timenow_between, strip_tags, read_text)
from .__version__ import __version__, __author__

###################################################
Expand Down Expand Up @@ -671,7 +671,7 @@ def generate_csv(io: TextIO, issues: List[Dict[str, Any]], report_datetime:str)
return

# Add CWE information
jsondata = json.loads(importlib_resources.read_text('burpa', 'issue_defs.json'))
jsondata = json.loads(read_text('burpa', 'issue_defs.json'))

for i in issues:
# Discard request/response data.
Expand Down
31 changes: 29 additions & 2 deletions burpa/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
import sys
import concurrent.futures
from datetime import datetime, time
from typing import Any, Callable, Dict, Iterable, Iterator, List, Optional, Tuple
from typing import Any, Callable, Dict, Iterable, Iterator, List, Optional, TextIO, Tuple
from importlib_resources import files

def get_valid_filename(s: str) -> str:
'''Return the given string converted to a string that can be used for a clean filename. Stolen from Django, I think.'''
Expand Down Expand Up @@ -128,7 +129,7 @@ def get_version(s:str) -> Tuple[int, ...]:
Parse a version string like <major>.<minor>.<micro> into a tuple of ints.
"""
parts = s.strip().split('.')
intparts = []
intparts: 'list[int]' = []

for p in parts:
try:
Expand All @@ -153,6 +154,32 @@ def get_version(s:str) -> Tuple[int, ...]:
def strip_tags(html:str) -> str:
return _tag.sub('', html)

def open_text(
package: str,
resource: str,
encoding: str = 'utf-8',
errors: str = 'strict',
) -> TextIO:
"""Return a file-like object opened for text reading of the resource."""
return (files(package) / resource).open( # type:ignore
'r', encoding=encoding, errors=errors
)


def read_text(
package: str,
resource: str,
encoding: str = 'utf-8',
errors: str = 'strict',
) -> str:
"""Return the decoded string of the resource.
The decoding-related arguments have the same semantics as those of
bytes.decode().
"""
with open_text(package, resource, encoding, errors) as fp:
return fp.read()

if __name__ == "__main__":

assert get_version("2.2.0") == (2,2,0)
Expand Down

0 comments on commit d54f92c

Please sign in to comment.