-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ENH: ease Permissions readability/writability #2397
Changes from 4 commits
c4164db
c95c4a0
8f53c26
8bf9c98
f6d8e20
312f92d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -122,7 +122,7 @@ | |
) | ||
|
||
OPTIONAL_READ_WRITE_FIELD = FieldFlag(0) | ||
ALL_DOCUMENT_PERMISSIONS = UserAccessPermissions((2**31 - 1) - 3) | ||
ALL_DOCUMENT_PERMISSIONS = UserAccessPermissions((2**32 - 1) - 3) | ||
|
||
|
||
class ObjectDeletionFlag(enum.IntFlag): | ||
|
@@ -1065,7 +1065,9 @@ | |
user_password: str, | ||
owner_password: Optional[str] = None, | ||
use_128bit: bool = True, | ||
permissions_flag: UserAccessPermissions = ALL_DOCUMENT_PERMISSIONS, | ||
permissions_flag: Union[ | ||
UserAccessPermissions, Dict[str, bool] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we really complicate this API further? We cannot we just provide a convenience method on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd also prefer not to add the string versions here. I regret adding them in the first place 🙈 |
||
] = ALL_DOCUMENT_PERMISSIONS, | ||
*, | ||
algorithm: Optional[str] = None, | ||
) -> None: | ||
|
@@ -1088,13 +1090,35 @@ | |
Bit position 3 is for printing, 4 is for modifying content, | ||
5 and 6 control annotations, 9 for form fields, | ||
10 for extraction of text and graphics. | ||
permissions can be provided as an integer or as a dictionary | ||
as provided by `PdfReader.decode_permissions()` | ||
algorithm: encrypt algorithm. Values maybe one of "RC4-40", "RC4-128", | ||
"AES-128", "AES-256-R5", "AES-256". If it's valid, | ||
`use_128bit` will be ignored. | ||
""" | ||
if owner_password is None: | ||
owner_password = user_password | ||
|
||
if isinstance(permissions_flag, dict): | ||
permissions = permissions_flag | ||
_flag = cast(int, ALL_DOCUMENT_PERMISSIONS) | ||
if not permissions.get("print", False): | ||
_flag -= 1 << 3 | ||
if not permissions.get("modify", False): | ||
_flag -= 1 << 4 | ||
if not permissions.get("copy", False): | ||
_flag -= 1 << 5 | ||
if not permissions.get("annotations", False): | ||
_flag -= 1 << 6 | ||
if not permissions.get("forms", False): | ||
_flag -= 1 << 9 | ||
if not permissions.get("accessability", False): | ||
_flag -= 1 << 10 | ||
if not permissions.get("assemble", False): | ||
_flag -= 1 << 11 | ||
if not permissions.get("print_high_quality", False): | ||
_flag -= 1 << 12 | ||
permissions_flag = cast(UserAccessPermissions, _flag) | ||
if algorithm is not None: | ||
try: | ||
alg = getattr(EncryptAlgorithm, algorithm.replace("-", "_")) | ||
|
+4 −14 | .github/workflows/json_consistency.py | |
+0 −4 | .gitignore | |
+0 −2 | 026-latex-multicolumn/Makefile | |
+ − | 026-latex-multicolumn/multicolumn.pdf | |
+0 −36 | 026-latex-multicolumn/multicolumn.tex | |
+0 −10 | files.json |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use
self._encryption.P
here?