pseek 3.6.1__tar.gz → 3.6.2__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: 3.6.1
3
+ Version: 3.6.2
4
4
  Classifier: Development Status :: 5 - Production/Stable
5
5
  Classifier: Environment :: Console
6
6
  Classifier: Intended Audience :: Developers
@@ -30,22 +30,16 @@ def get_archive_path_size(info, file_type: str) -> int:
30
30
  def archive_should_skip(path_info: Path, config, p_size: float, file_ext, is_dir=False):
31
31
  """Check whether the file/directory inside archive files should be skipped based on various filters"""
32
32
 
33
- if (config.arc_include and not any(path_info.is_relative_to(inc) for inc in config.arc_include)) \
33
+ path_info_str = str(path_info)
34
+ return (config.arc_include and not any(path_info.is_relative_to(inc) for inc in config.arc_include)) \
34
35
  or (config.arc_exclude and any(path_info.is_relative_to(exc) for exc in config.arc_exclude)) \
35
36
  or (config.arc_ext and file_ext not in config.arc_ext) \
36
37
  or (config.arc_exc_ext and file_ext in config.arc_exc_ext) \
37
38
  or (config.arc_size and (is_dir or not any(
38
39
  minimum <= p_size <= maximum
39
40
  for minimum, maximum in config.arc_size
40
- ))):
41
- return True
42
-
43
- if config.re_include:
44
- return not config.re_include.search(str(path_info))
45
- if config.re_exclude:
46
- return config.re_exclude.search(str(path_info)) is not None
47
-
48
- return False
41
+ ))) or (config.re_include and not config.re_include.search(path_info_str)) \
42
+ or (config.re_exclude and config.re_exclude.search(path_info_str) is not None)
49
43
 
50
44
 
51
45
  def extract_names_from_archive(file_path: Path, config, depth: int = -1,
@@ -78,8 +72,8 @@ def extract_names_from_archive(file_path: Path, config, depth: int = -1,
78
72
  with opener(file_stream) as f:
79
73
  for info in f.infolist():
80
74
  name = Path(info.filename)
81
- new_path_ext = get_path_suffix(name)
82
75
  is_dir = info.is_dir()
76
+ new_path_ext = get_path_suffix(name, is_dir)
83
77
 
84
78
  if not archive_should_skip(
85
79
  name,
@@ -105,8 +99,8 @@ def extract_names_from_archive(file_path: Path, config, depth: int = -1,
105
99
  with py7zr.SevenZipFile(file_stream, mode='r') as z:
106
100
  for info in z.list():
107
101
  name = Path(info.filename)
108
- new_path_ext = get_path_suffix(name)
109
102
  is_dir = info.is_directory
103
+ new_path_ext = get_path_suffix(name, is_dir)
110
104
 
111
105
  if not archive_should_skip(
112
106
  name,
@@ -143,8 +137,8 @@ def extract_names_from_archive(file_path: Path, config, depth: int = -1,
143
137
  with tarfile.open(fileobj=file_stream, mode=mode) as tf:
144
138
  for member in tf.getmembers():
145
139
  name = Path(member.name)
146
- new_path_ext = get_path_suffix(name)
147
140
  is_dir = member.isdir()
141
+ new_path_ext = get_path_suffix(name, is_dir)
148
142
 
149
143
  if not archive_should_skip(
150
144
  name,
@@ -203,10 +197,10 @@ def extract_text_from_archive(file_path: Path, config, depth: int = -1,
203
197
  for info in f.infolist():
204
198
  if info.is_dir():
205
199
  continue
206
-
200
+
207
201
  file_name = Path(info.filename)
208
202
  new_path_ext = get_path_suffix(file_name)
209
-
203
+
210
204
  if archive_should_skip(
211
205
  file_name,
212
206
  config,
@@ -243,7 +237,7 @@ def extract_text_from_archive(file_path: Path, config, depth: int = -1,
243
237
 
244
238
  file_name = Path(info.filename)
245
239
  new_path_ext = get_path_suffix(file_name)
246
-
240
+
247
241
  if archive_should_skip(
248
242
  file_name,
249
243
  config,
@@ -282,7 +276,7 @@ def extract_text_from_archive(file_path: Path, config, depth: int = -1,
282
276
 
283
277
  file_name = Path(member.name)
284
278
  new_path_ext = get_path_suffix(file_name)
285
-
279
+
286
280
  if archive_should_skip(
287
281
  file_name,
288
282
  config,
@@ -306,41 +306,50 @@ def search_content(config, matches: dict, pattern, binary_pattern,
306
306
  return
307
307
 
308
308
  collector = ContextCollector(config.context)
309
- # Memory-map the file for efficient access
310
- with open(p, 'rb') as f, mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ) as mm:
311
- head = mm[:8192]
312
- if is_binary(head) or (binary_pattern and not content_contains(mm, binary_pattern)):
313
- return
309
+ try:
310
+ # Memory-map the file for efficient access
311
+ with open(p, 'rb') as f, mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ) as mm:
312
+ head = mm[:8192]
313
+ if is_binary(head) or (binary_pattern and not content_contains(mm, binary_pattern)):
314
+ return
314
315
 
315
- mm.seek(0) # Move the cursor to the beginning of the file
316
+ mm.seek(0) # Move the cursor to the beginning of the file
316
317
 
317
- # Iterate over each line in the file
318
- for num, line in enumerate(iter(mm.readline, b''), 1):
319
- try:
320
- line_decoded = line.decode('utf-8').rstrip('\r\n')
321
- except UnicodeDecodeError:
322
- # Skip lines that can't be decoded
323
- continue
318
+ # Iterate over each line in the file
319
+ for num, line in enumerate(iter(mm.readline, b''), 1):
320
+ if binary_pattern and not content_contains(line, binary_pattern):
321
+ continue
324
322
 
325
- matched = pattern is None or pattern.evaluate(line_decoded)
323
+ try:
324
+ line_decoded = line.decode('utf-8').rstrip('\r\n')
325
+ except UnicodeDecodeError:
326
+ # Skip lines that can't be decoded
327
+ continue
326
328
 
327
- # Avoid searching through the entire file content if the paths-only flag is True
328
- if config.paths_only and matched:
329
- add_result(
330
- matches,
331
- result_queue,
332
- 'content',
333
- ContentResult(path=path_str),
334
- result_lock
335
- )
336
- return
329
+ matched = pattern is None or pattern.evaluate(line_decoded)
337
330
 
338
- line_instance = Line(num, line_decoded)
331
+ # Avoid searching through the entire file content if the paths-only flag is True
332
+ if config.paths_only and matched:
333
+ add_result(
334
+ matches,
335
+ result_queue,
336
+ 'content',
337
+ ContentResult(path=path_str),
338
+ result_lock
339
+ )
340
+ return
339
341
 
340
- if matched:
341
- line_instance.matches = find_matches(pattern, line_decoded)
342
+ if not any(config.context) and not matched:
343
+ continue
344
+
345
+ line_instance = Line(num, line_decoded)
346
+
347
+ if matched:
348
+ line_instance.matches = find_matches(pattern, line_decoded)
342
349
 
343
- collector.process(line_instance, matched)
350
+ collector.process(line_instance, matched)
351
+ except OSError:
352
+ return
344
353
 
345
354
  groups = collector.finish()
346
355
  if groups:
@@ -24,13 +24,19 @@ def compile_regex(txt, flags=0) -> re.Pattern | None:
24
24
  raise click.exceptions.Exit(1)
25
25
 
26
26
 
27
- def get_path_suffix(path: Path | str) -> str:
27
+ def get_path_suffix(path: Path | str, is_dir: bool | None = None) -> str:
28
28
  """ If multiple file suffixes are valid, return them, otherwise return only the last suffix """
29
29
  if isinstance(path, str):
30
30
  path = Path(path)
31
31
 
32
- if path.is_dir():
33
- return None
32
+ # The paths within archive aren't physical paths,
33
+ # so we need to determine is_dir from their metadata.
34
+ if is_dir is not None:
35
+ if is_dir:
36
+ return None
37
+ else:
38
+ if path.is_dir():
39
+ return None
34
40
 
35
41
  suffixes = ''.join(path.suffixes)[1:].lower()
36
42
 
@@ -4,7 +4,7 @@ build-backend = "maturin"
4
4
 
5
5
  [project]
6
6
  name = "pseek"
7
- version = "3.6.1"
7
+ version = "3.6.2"
8
8
  description = "Pseek is a Python CLI toolkit 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
File without changes
File without changes
File without changes
File without changes