pseek 2.5.2__tar.gz → 2.5.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pseek
3
- Version: 2.5.2
3
+ Version: 2.5.3
4
4
  Summary: Pseek is a Python library to search files, folders, and text
5
5
  Author-email: Arian <ariannasiri86@gmail.com>
6
6
  License-Expression: MIT
@@ -1,17 +1,10 @@
1
- import mmap
2
- import click
1
+ import mmap, click, io
3
2
  from pathlib import Path
4
3
  from .utils import compile_regex, get_archive_path_size, try_decode, get_path_suffix
5
4
  from .parser import parse_query_expression, TermNode, highlight_text
6
5
  from concurrent.futures import ThreadPoolExecutor
7
- import zipfile
8
- import py7zr
9
- import tarfile
10
- import gzip
11
- import bz2
12
- import lzma
13
- import rarfile
14
- import io
6
+ # Archive modules
7
+ import zipfile, py7zr, tarfile, gzip, bz2, lzma, rarfile
15
8
 
16
9
  # Archive extensions that are allowed
17
10
  ARCHIVE_EXTS = ('zip', 'rar', '7z', 'tar', 'tar.gz', 'tar.bz2', 'tar.xz', 'gz', 'bz2', 'xz')
@@ -124,7 +117,8 @@ class Search:
124
117
  return False
125
118
 
126
119
  def extract_names_from_archive(self, file_path: Path, search_type: str,
127
- file_bytes: bytes = None, parent_label: str = ''):
120
+ file_bytes: bytes = None, parent_label: str = '',
121
+ depth: int = None):
128
122
  """
129
123
  Recursively extract files and directories name from archive files.
130
124
  Supports nested archives like a.zip::b.7z::c.txt.
@@ -134,6 +128,7 @@ class Search:
134
128
  search_type (str): search type ( file / directory )
135
129
  file_bytes (bytes | None): optional byte data if already read (for recursion)
136
130
  parent_label (str): string for nested archive tracking like a.zip::b.7z::file.txt
131
+ depth (int): the depth value that is returned recursively
137
132
 
138
133
  Yields:
139
134
  (str, Path): tuple of parent label and file or directory name
@@ -141,6 +136,8 @@ class Search:
141
136
 
142
137
  file_ext = get_path_suffix(file_path)
143
138
  label_prefix = (parent_label + str(file_path) + '::') if parent_label else '::'
139
+ if depth is None:
140
+ depth = self.depth
144
141
 
145
142
  try:
146
143
  # Decide the stream source: from disk or memory
@@ -162,14 +159,15 @@ class Search:
162
159
  yield label_prefix, name
163
160
 
164
161
  # At each recursion, subtract 1 from depth if it's set
165
- new_depth = None if self.depth is None else self.depth - 1
162
+ new_depth = None if depth is None else depth - 1
166
163
  # Check if this is a nested archive
167
164
  if get_path_suffix(name) in ARCHIVE_EXTS[:-3] and (new_depth is None or new_depth >= 0):
168
165
  yield from self.extract_names_from_archive(
169
166
  name,
170
167
  search_type,
171
168
  f.read(info),
172
- label_prefix
169
+ label_prefix,
170
+ new_depth
173
171
  )
174
172
  # Handle 7Z archives
175
173
  elif file_ext == '7z':
@@ -185,7 +183,7 @@ class Search:
185
183
  ):
186
184
  yield label_prefix, name
187
185
 
188
- new_depth = None if self.depth is None else self.depth - 1
186
+ new_depth = None if depth is None else depth - 1
189
187
  if get_path_suffix(name) in ARCHIVE_EXTS[:-3] and (new_depth is None or new_depth >= 0):
190
188
  file_data = z.read([info.filename]).get(info.filename)
191
189
  if file_data is None:
@@ -195,7 +193,8 @@ class Search:
195
193
  name,
196
194
  search_type,
197
195
  file_data.read(),
198
- label_prefix
196
+ label_prefix,
197
+ new_depth
199
198
  )
200
199
  # Handle TAR and compressed TAR formats
201
200
  elif file_ext in ('tar', 'tar.gz', 'tar.bz2', 'tar.xz'):
@@ -219,7 +218,7 @@ class Search:
219
218
  ):
220
219
  yield label_prefix, name
221
220
 
222
- new_depth = None if self.depth is None else self.depth - 1
221
+ new_depth = None if depth is None else depth - 1
223
222
  if get_path_suffix(name) in ARCHIVE_EXTS[:-3] and (new_depth is None or new_depth >= 0):
224
223
  f = tf.extractfile(member)
225
224
  if f is None:
@@ -229,12 +228,14 @@ class Search:
229
228
  name,
230
229
  search_type,
231
230
  f.read(),
232
- label_prefix
231
+ label_prefix,
232
+ new_depth
233
233
  )
234
234
  except Exception:
235
235
  return # silently skip invalid archives
236
236
 
237
- def extract_text_from_archive(self, file_path: Path, file_bytes: bytes = None, parent_label: str = ''):
237
+ def extract_text_from_archive(self, file_path: Path, file_bytes: bytes = None,
238
+ parent_label: str = '', depth: int = None):
238
239
  """
239
240
  Recursively extract (path_label, text_content) from any archive file.
240
241
  Supports nested archives like a.zip::b.7z::c.txt.
@@ -243,6 +244,7 @@ class Search:
243
244
  file_path (Path): the archive file path
244
245
  file_bytes (bytes | None): optional byte data if already read (for recursion)
245
246
  parent_label (str): string for nested archive tracking like a.zip::b.7z::file.txt
247
+ depth (int): the depth value that is returned recursively
246
248
 
247
249
  Yields:
248
250
  (str, str): tuple of full virtual path and decoded content text
@@ -250,6 +252,8 @@ class Search:
250
252
 
251
253
  file_ext = get_path_suffix(file_path)
252
254
  label_prefix = (parent_label + str(file_path) + '::') if parent_label else '::'
255
+ if depth is None:
256
+ depth = self.depth
253
257
 
254
258
  try:
255
259
  # Decide the stream source: from disk or memory
@@ -263,11 +267,11 @@ class Search:
263
267
  file_name = Path(info.filename)
264
268
  data = f.read(info)
265
269
  # At each recursion, subtract 1 from depth if it's set
266
- new_depth = None if self.depth is None else self.depth - 1
270
+ new_depth = None if depth is None else depth - 1
267
271
 
268
272
  # Check if this is a nested archive
269
273
  if get_path_suffix(file_name) in ARCHIVE_EXTS and (new_depth is None or new_depth >= 0):
270
- yield from self.extract_text_from_archive(file_name, data, label_prefix)
274
+ yield from self.extract_text_from_archive(file_name, data, label_prefix, new_depth)
271
275
  else:
272
276
  if self.archive_should_skip(
273
277
  file_name,
@@ -291,10 +295,10 @@ class Search:
291
295
 
292
296
  file_name = Path(info.filename)
293
297
  data = file_data.read()
294
- new_depth = None if self.depth is None else self.depth - 1
298
+ new_depth = None if depth is None else depth - 1
295
299
 
296
300
  if get_path_suffix(file_name) in ARCHIVE_EXTS and (new_depth is None or new_depth >= 0):
297
- yield from self.extract_text_from_archive(file_name, data, label_prefix)
301
+ yield from self.extract_text_from_archive(file_name, data, label_prefix, new_depth)
298
302
  else:
299
303
  if self.archive_should_skip(
300
304
  file_name,
@@ -325,10 +329,10 @@ class Search:
325
329
 
326
330
  file_name = Path(member.name)
327
331
  data = f.read()
328
- new_depth = None if self.depth is None else self.depth - 1
332
+ new_depth = None if depth is None else depth - 1
329
333
 
330
334
  if get_path_suffix(file_name) in ARCHIVE_EXTS and (new_depth is None or new_depth >= 0):
331
- yield from self.extract_text_from_archive(file_name, data, label_prefix)
335
+ yield from self.extract_text_from_archive(file_name, data, label_prefix, new_depth)
332
336
  else:
333
337
  if self.archive_should_skip(
334
338
  file_name,
@@ -431,7 +435,7 @@ class Search:
431
435
 
432
436
  count = pattern.count_matches(line) if isinstance(pattern, TermNode) else 0
433
437
  # Highlight the matching parts in green
434
- highlighted = highlight_text(pattern, line, self.fuzzy)
438
+ highlighted = highlight_text(pattern, line.strip(), self.fuzzy)
435
439
  # Show a note if the pattern repeats 3 or more times
436
440
  count_query = f' - Repeated {count} times' if count >= 3 else ''
437
441
  # Format the output line with line number and highlighted matches
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pseek
3
- Version: 2.5.2
3
+ Version: 2.5.3
4
4
  Summary: Pseek is a Python library to search files, folders, and text
5
5
  Author-email: Arian <ariannasiri86@gmail.com>
6
6
  License-Expression: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "pseek"
7
- version = "2.5.2"
7
+ version = "2.5.3"
8
8
  description = "Pseek is a Python library to search files, folders, and text"
9
9
  readme = "README.md"
10
10
  license = "MIT"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes