camera-claim-audit 0.1.0__py3-none-any.whl

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.
@@ -0,0 +1,2 @@
1
+ """Static documentation and device evidence audit."""
2
+ __version__ = '0.1.0'
@@ -0,0 +1,43 @@
1
+ import argparse
2
+ import json
3
+ import sys
4
+ from . import __version__
5
+ from .audit import audit
6
+
7
+
8
+ class Parser(argparse.ArgumentParser):
9
+ def error(self, message):
10
+ self.print_usage(sys.stderr)
11
+ self.exit(1, self.prog + ': error: ' + message + '\n')
12
+
13
+
14
+ def main(argv=None):
15
+ parser = Parser(description='Audit documented local device image intake against static source evidence.')
16
+ parser.add_argument('root')
17
+ parser.add_argument('--json', action='store_true')
18
+ parser.add_argument('--verbose', action='store_true')
19
+ parser.add_argument('--ignore', action='append', default=[])
20
+ parser.add_argument('--fail-on', choices=['HIGH', 'MEDIUM'], default='HIGH')
21
+ parser.add_argument('--version', action='version', version=__version__)
22
+ args = parser.parse_args(argv)
23
+ try:
24
+ result = audit(args.root, args.ignore)
25
+ except (OSError, ValueError, UnicodeError) as exc:
26
+ print(str(exc), file=sys.stderr)
27
+ return 1
28
+ failed = any(f['severity'] == 'HIGH' or args.fail_on == 'MEDIUM' for f in result['findings'])
29
+ result['verdict'] = 'FAIL' if failed else 'PASS'
30
+ if args.json:
31
+ print(json.dumps(result))
32
+ else:
33
+ print(result['verdict'])
34
+ for finding in result['findings']:
35
+ print('{severity} {rule}: {message}'.format(**finding))
36
+ if args.verbose:
37
+ print('Evidence: ' + ', '.join(result['evidence']))
38
+ print('Test evidence: ' + ', '.join(result['test_evidence']))
39
+ return 2 if failed else 0
40
+
41
+
42
+ if __name__ == '__main__':
43
+ sys.exit(main())
@@ -0,0 +1,125 @@
1
+ """Offline AST inspection. Audited source is never executed."""
2
+ import ast
3
+ import fnmatch
4
+ import re
5
+ from pathlib import Path
6
+ from .phrases import CAMERA, NOCAMERA
7
+
8
+
9
+ def normalize(text):
10
+ return re.sub(r'\s+', ' ', text.lower().replace("n't", ' not').replace('-', ' ')).strip()
11
+
12
+
13
+ def claims(text):
14
+ lines = []
15
+ fence = None
16
+ for line in text.splitlines():
17
+ marker = re.match(r'^\s{0,3}(`{3,}|~{3,})', line)
18
+ if marker:
19
+ token = marker.group(1)
20
+ if fence is None:
21
+ fence = token
22
+ elif token[0] == fence[0] and len(token) >= len(fence):
23
+ fence = None
24
+ lines.append('')
25
+ elif fence is None:
26
+ lines.append(line)
27
+ positive = negative = False
28
+ for paragraph in re.split(r'\n\s*\n', '\n'.join(lines)):
29
+ paragraph = normalize(paragraph)
30
+ for phrase in sorted(NOCAMERA, key=len, reverse=True):
31
+ paragraph, count = re.subn(r'\b' + re.escape(phrase) + r'\b', ' ', paragraph)
32
+ negative |= bool(count)
33
+ positive |= any(re.search(r'\b' + re.escape(p) + r'\b', paragraph) for p in CAMERA)
34
+ return positive, negative
35
+
36
+
37
+ def dotted(node):
38
+ if isinstance(node, ast.Name):
39
+ return node.id
40
+ if isinstance(node, ast.Attribute):
41
+ base = dotted(node.value)
42
+ return base + '.' + node.attr if base else ''
43
+ return ''
44
+
45
+
46
+ def evidence(source):
47
+ try:
48
+ tree = ast.parse(source)
49
+ except SyntaxError:
50
+ return False
51
+ aliases = {}
52
+ providers = ('cv2', 'picamera2', 'picamera')
53
+ for node in ast.walk(tree):
54
+ if isinstance(node, ast.Import):
55
+ for item in node.names:
56
+ if item.name.split('.')[0] in providers:
57
+ aliases[item.asname or item.name.split('.')[0]] = item.name if item.asname else item.name.split('.')[0]
58
+ elif isinstance(node, ast.ImportFrom) and node.level == 0 and node.module:
59
+ if node.module.split('.')[0] in providers:
60
+ for item in node.names:
61
+ aliases[item.asname or item.name] = node.module + '.' + item.name
62
+
63
+ def creation(node):
64
+ if not isinstance(node, ast.Call):
65
+ return None
66
+ path = dotted(node.func).split('.')
67
+ resolved = aliases.get(path[0], '')
68
+ if not resolved:
69
+ return None
70
+ path = (resolved + ('.' + '.'.join(path[1:]) if len(path) > 1 else '')).split('.')
71
+ provider, name = path[0], path[-1]
72
+ if provider == 'cv2' and name == 'VideoCapture':
73
+ if node.args and isinstance(node.args[0], ast.Constant) and isinstance(node.args[0].value, str):
74
+ return None
75
+ return provider
76
+ if (provider, name) in {('picamera2', 'Picamera2'), ('picamera', 'PiCamera')}:
77
+ return provider
78
+ return None
79
+
80
+ bindings = {}
81
+ for node in ast.walk(tree):
82
+ if isinstance(node, ast.Assign):
83
+ provider = creation(node.value)
84
+ for target in node.targets:
85
+ key = dotted(target)
86
+ if isinstance(target, ast.Name) or (isinstance(target, ast.Attribute) and isinstance(target.value, ast.Name) and target.value.id == 'self'):
87
+ if provider:
88
+ bindings[key] = provider
89
+ methods = {'cv2': {'read'}, 'picamera2': {'capture_file', 'capture_array', 'capture_image', 'capture_buffer', 'capture_metadata'}, 'picamera': {'capture', 'start_recording'}}
90
+ for node in ast.walk(tree):
91
+ if isinstance(node, ast.Call) and isinstance(node.func, ast.Attribute):
92
+ provider = creation(node.func.value) or bindings.get(dotted(node.func.value))
93
+ if provider and node.func.attr in methods[provider]:
94
+ return True
95
+ return False
96
+
97
+
98
+ def audit(root, ignores=()):
99
+ root = Path(root)
100
+ if not root.is_dir() or not root.stat().st_mode & 0o444 or not root.stat().st_mode & 0o111:
101
+ raise ValueError('Root must be a readable directory')
102
+ positive = negative = False
103
+ production, testing = [], []
104
+ excluded = {'fixtures', 'docs', 'examples'}
105
+ for path in sorted(root.rglob('*')):
106
+ relative = path.relative_to(root)
107
+ if path.is_symlink() or any(parent.is_symlink() for parent in path.parents if parent != root) or not path.is_file():
108
+ continue
109
+ if any(fnmatch.fnmatch(relative.as_posix(), pattern) for pattern in ignores):
110
+ continue
111
+ if path.suffix.lower() == '.md' and (relative.as_posix() == 'README.md' or 'docs' in relative.parts[:-1]):
112
+ pos, neg = claims(path.read_text(encoding='utf-8'))
113
+ positive |= pos
114
+ negative |= neg
115
+ if path.suffix != '.py' or excluded.intersection(relative.parts[:-1]):
116
+ continue
117
+ test = 'tests' in relative.parts[:-1] or path.name.startswith('test_') or path.name.endswith('_test.py')
118
+ if evidence(path.read_text(encoding='utf-8')):
119
+ (testing if test else production).append(relative.as_posix())
120
+ findings = []
121
+ if positive and not production:
122
+ findings.append({'rule': 'documented-camera-claim-false', 'severity': 'MEDIUM' if testing else 'HIGH', 'message': 'Documented device intake lacks production capture evidence.'})
123
+ if negative and production:
124
+ findings.append({'rule': 'documented-no-camera-claim-false', 'severity': 'HIGH', 'message': 'Documented absence conflicts with production capture evidence.'})
125
+ return {'findings': findings, 'evidence': production, 'test_evidence': testing, 'claims': {'camera': positive, 'no_camera': negative}}
@@ -0,0 +1,2 @@
1
+ CAMERA = ('captures photos from your camera', 'capture photos from your camera', 'captures images from your camera', 'capture images from your camera', 'takes photos with your camera', 'take photos with your camera', 'takes pictures with your camera', 'take pictures with your camera', 'captures video from your camera', 'capture video from your camera', 'records video from your camera', 'record video from your camera', 'captures webcam video', 'capture webcam video', 'captures webcam images', 'capture webcam images', 'takes webcam photos', 'take webcam photos', 'supports camera capture', 'camera capture support', 'camera photo capture', 'camera video capture', 'webcam capture support', 'supports webcam capture', 'camera input support', 'uses your camera to capture', 'captures from your camera', 'capture from your camera', 'records from your camera', 'record from your camera')
2
+ NOCAMERA = ('does not capture photos from your camera', 'does not capture images from your camera', 'does not take photos with your camera', 'does not capture video from your camera', 'does not record video from your camera', 'does not capture from your camera', 'does not record from your camera', 'does not use your camera', 'does not access your camera', 'camera capture not supported', 'webcam capture not supported', 'camera input not supported', 'no camera capture', 'no webcam capture', 'without camera capture', 'without webcam capture', 'no camera input', 'no camera access')
@@ -0,0 +1,61 @@
1
+ Metadata-Version: 2.4
2
+ Name: camera-claim-audit
3
+ Version: 0.1.0
4
+ Summary: Offline static audit of documented local device image intake
5
+ License-Expression: MIT
6
+ Requires-Python: >=3.9
7
+ Description-Content-Type: text/markdown
8
+ License-File: LICENSE
9
+ Dynamic: license-file
10
+
11
+ # camera-claim-audit
12
+
13
+ An offline static auditor for documentation about local device image capture
14
+ and attached imaging device intake. Source is parsed, never imported or run.
15
+ No runtime dependencies are required. Requires Python 3.9 or later.
16
+
17
+ Install and run:
18
+
19
+ ```sh
20
+ python3 -m pip install .
21
+ camera-claim-audit /path/to/project
22
+ python3 -m camera_claim_audit /path/to/project --json --verbose
23
+ python3 -m unittest discover
24
+ ```
25
+
26
+ Root README.md and Markdown beneath any docs path component supply claims.
27
+ Fenced blocks are excluded; inline code counts. Matching lowercases text,
28
+ expands negative contractions, replaces hyphens with spaces, and joins lines
29
+ within paragraphs. Exact word-boundary templates alone count; negative spans
30
+ are removed first. Bare device nouns and instructions to the user do not count.
31
+ Screen grabs, audio, speech, key input, clipboard operations and network sends
32
+ are outside this audit's scope.
33
+
34
+ Production evidence requires a provider-resolved cv2 VideoCapture device read,
35
+ a bound picamera2 Picamera2 capture method, or a bound legacy picamera PiCamera
36
+ capture or recording method. Plain assignments, self attributes and chained
37
+ calls are recognized per module. A string first argument to VideoCapture is a
38
+ file source. Object construction alone is insufficient. Tests, fixtures, docs,
39
+ examples and symlinks are excluded from production evidence. Evidence solely
40
+ in tests produces MEDIUM. Missing positive evidence and contradictory negative
41
+ documentation produce HIGH, at most one finding per family. Without source,
42
+ a positive assertion fails and a negative assertion passes. Without claims,
43
+ the result passes regardless of source evidence.
44
+
45
+ Options: --json emits structured findings and evidence; --verbose shows source
46
+ paths; repeat --ignore GLOB to exclude relative paths; --fail-on HIGH is the
47
+ default, while --fail-on MEDIUM also fails on test-only evidence. --version
48
+ prints 0.1.0. Exit codes are 0 for passing the threshold, 2 for findings meeting
49
+ the threshold, and 1 for invalid usage or unreadable roots. MEDIUM findings
50
+ remain visible even when the verdict is PASS.
51
+
52
+ ## Limitations
53
+
54
+ Only the fixed templates in the package phrase table are recognized. This is
55
+ static evidence, not a hardware or runtime guarantee. Scope and control flow
56
+ are not modeled; bindings and imports are tracked per module. Dynamic imports,
57
+ wrapper functions, cross-module receivers, assignment aliases and shell imaging
58
+ helpers (ffmpeg, fswebcam, imagesnap) are not resolved. Strings, comments,
59
+ docstrings, file loaders, screen grabs, display and save operations alone are
60
+ insufficient. Environment files are never opened. Invalid source syntax supplies
61
+ no evidence. Ignore patterns use relative paths and standard glob matching.
@@ -0,0 +1,10 @@
1
+ camera_claim_audit/__init__.py,sha256=7YmqGx4N-nzoUDnyexkY0EiyvNnTSclqH-p0B49VZ1I,76
2
+ camera_claim_audit/__main__.py,sha256=o8Q9MhCwUrFwk-ArOBTY8dCNaEfais5Csknk1cYPzok,1565
3
+ camera_claim_audit/audit.py,sha256=sjT1DRZHmzBgLFtXguPWu2i_aT7VT15Ac95JVgFQZa0,5599
4
+ camera_claim_audit/phrases.py,sha256=prMQuWY1pyv5ZOpBtEKbX8RlXPqy7dnDp4HFbLX9p78,1473
5
+ camera_claim_audit-0.1.0.dist-info/licenses/LICENSE,sha256=MPua7yJra1Q8rAzMyQt6QI8tlr5wDM3qYWbF3XRZq7o,1088
6
+ camera_claim_audit-0.1.0.dist-info/METADATA,sha256=fQM0g-ssWf9WVQ0lN8ESmAjgke_WKDzZaRuGho9R9y0,3012
7
+ camera_claim_audit-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
8
+ camera_claim_audit-0.1.0.dist-info/entry_points.txt,sha256=9VYCuhe1VWTAJatSB00om0ddDYAyoLIReN6_MBiaBKc,72
9
+ camera_claim_audit-0.1.0.dist-info/top_level.txt,sha256=5AUCFSJEXelGNunudFv0KHjrlIpdHmxA8qxi9ikhXU0,19
10
+ camera_claim_audit-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ camera-claim-audit = camera_claim_audit.__main__:main
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 camera-claim-audit contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ camera_claim_audit