Skip to content

Commit 069a1b1

Browse files
author
rootware
committed
working refactor so far
1 parent dd74f02 commit 069a1b1

File tree

6 files changed

+38
-76
lines changed

6 files changed

+38
-76
lines changed

README.md

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -71,28 +71,6 @@ Redact using custom regex pattern
7171
pyredactkit -f file -c custom.json
7272
```
7373

74-
<!-- Install nltk data for redacting names
75-
76-
```bash
77-
python -c "import nltk
78-
import ssl
79-
80-
try:
81-
_create_unverified_https_context = ssl._create_unverified_context
82-
except AttributeError:
83-
pass
84-
else:
85-
ssl._create_default_https_context =_create_unverified_https_context
86-
87-
nltk.download('popular')"
88-
```
89-
90-
Redact names from a text file
91-
92-
```bash
93-
pyredactkit test.txt -t name
94-
``` -->
95-
9674
### Use from github source
9775

9876
Clone the repo

images/classes.png

-10.5 KB
Loading

pyredactkit/common_jobs.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
""" Common jobs class implementation """
2+
import mimetypes
3+
import os
4+
import sys
5+
import re
6+
import math
7+
import json
8+
import uuid
9+
10+
11+
class CommonJobs:
12+
"""Common Jobs class
13+
Class containing all methods to support redaction
14+
of sensitive data
15+
16+
Static variables:
17+
block (unicode string): To redact sensitive data
18+
"""
19+
20+
def __init__(self) -> None:
21+
"""
22+
Class Initialization
23+
Args:
24+
None
25+
26+
Returns:
27+
None
28+
"""
29+
return None
Lines changed: 6 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
""" Main redactor class implementation """
1+
""" Core redactor engine class implementation """
22

33
import mimetypes
44
import os
@@ -10,13 +10,13 @@
1010

1111
from pyredactkit.identifiers import Identifier
1212
id_object = Identifier()
13-
""" Main redactor library """
13+
""" Coreredactor library """
1414

1515

16-
class Redactor:
17-
"""Redactor class
16+
class CoreRedactorEngine:
17+
"""CoreRedactorEngine class
1818
Class containing all methods to support redaction
19-
of sensitive data
19+
of core sensitive data type
2020
2121
Static variables:
2222
block (unicode string): To redact sensitive data
@@ -34,52 +34,7 @@ def __init__(self) -> None:
3434
Returns:
3535
None
3636
"""
37-
self.__allowed_files__ = [
38-
"text/plain",
39-
"text/x-python",
40-
"application/json",
41-
"application/javascript",
42-
"text/html",
43-
"text/csv",
44-
"text/tab-separated-values",
45-
"text/css",
46-
"text/cache-manifest",
47-
"text/calendar",
48-
]
49-
50-
@staticmethod
51-
def check_file_type(file):
52-
"""Checks for the supplied file type
53-
Args:
54-
file (str): Filename of file to check
55-
Returns:
56-
mime (str): Mime type
57-
"""
58-
if not os.path.isfile(file):
59-
return (None, None)
60-
return mimetypes.guess_type(file)[0]
61-
62-
def get_allowed_files(self):
63-
"""Gets a list of allowed files
64-
Args:
65-
None
66-
Returns:
67-
allowed_file (list): List of allowed files
68-
"""
69-
return self.__allowed_files__
70-
71-
def allowed_file(self, file):
72-
"""Checks if supplied file is allowed
73-
Checks the supplied file to see if it is in the allowed_files list
74-
Args:
75-
file (str): File to check
76-
Returns:
77-
False: File not found / File type is not allowed
78-
True: File is allowed
79-
"""
80-
if not os.path.isfile(file):
81-
return False
82-
return mimetypes.guess_type(file)[0] in self.get_allowed_files()
37+
return None
8338

8439
def read_custom_patterns(self, custom_file) -> list:
8540
'''Load Rules

pyredactkit/pyredactkit.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55

66
import argparse
77

8-
from pyredactkit.redact import Redactor
8+
from pyredactkit.core_redactor import CoreRedactorEngine
99
from pyredactkit.unredact import Unredactor
1010
import os
1111
import glob
1212
import sys
1313

1414
# Creating instances of redact and unredact classes
15-
redact_obj = Redactor()
15+
redact_obj = CoreRedactorEngine()
1616
unredact_obj = Unredactor()
1717

1818

tests/test_redact.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import pytest
2-
from pyredactkit.redact import Redactor
2+
from pyredactkit.core_redactor import Redactor
33

44
data = """John, please get that article on www.linkedin.com to me by 5:00PM on Jan 9th 2012. 4:00 would be ideal, actually. If you have any questions, You can reach me at(519)-236-2723 or get in touch with my associate at [email protected]
55
this is my IP: 102.23.5.1

0 commit comments

Comments
 (0)