Skip to content
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

DOC: Small modification of error message #2956

Merged
merged 4 commits into from
Nov 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 22 additions & 22 deletions pypdf/generic/_viewerpref.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,24 @@


class ViewerPreferences(DictionaryObject):
def _get_bool(self, key: str, deft: Optional[BooleanObject]) -> BooleanObject:
return self.get(key, deft)
def _get_bool(self, key: str, default: Optional[BooleanObject]) -> BooleanObject:
return self.get(key, default)

def _set_bool(self, key: str, v: bool) -> None:
self[NameObject(key)] = BooleanObject(v is True)

def _get_name(self, key: str, deft: Optional[NameObject]) -> Optional[NameObject]:
return self.get(key, deft)
def _get_name(self, key: str, default: Optional[NameObject]) -> Optional[NameObject]:
return self.get(key, default)

def _set_name(self, key: str, lst: List[str], v: NameObject) -> None:
if v[0] != "/":
raise ValueError(f"{v} is not starting with '/'")
raise ValueError(f"{v} does not start with '/'")
if lst != [] and v not in lst:
raise ValueError(f"{v} is not par of acceptable values")
raise ValueError(f"{v} is an unacceptable value")
self[NameObject(key)] = NameObject(v)

def _get_arr(self, key: str, deft: Optional[List[Any]]) -> NumberObject:
return self.get(key, None if deft is None else ArrayObject(deft))
def _get_arr(self, key: str, default: Optional[List[Any]]) -> NumberObject:
return self.get(key, None if default is None else ArrayObject(default))

def _set_arr(self, key: str, v: Optional[ArrayObject]) -> None:
if v is None:
Expand All @@ -69,8 +69,8 @@ def _set_arr(self, key: str, v: Optional[ArrayObject]) -> None:
raise ValueError("ArrayObject is expected")
self[NameObject(key)] = v

def _get_int(self, key: str, deft: Optional[NumberObject]) -> NumberObject:
return self.get(key, deft)
def _get_int(self, key: str, default: Optional[NumberObject]) -> NumberObject:
return self.get(key, default)

def _set_int(self, key: str, v: int) -> None:
self[NameObject(key)] = NumberObject(v)
Expand All @@ -80,46 +80,46 @@ def PRINT_SCALING(self) -> NameObject:
return NameObject("/PrintScaling")

def __new__(cls: Any, value: Any = None) -> "ViewerPreferences":
def _add_prop_bool(key: str, deft: Optional[BooleanObject]) -> property:
def _add_prop_bool(key: str, default: Optional[BooleanObject]) -> property:
return property(
lambda self: self._get_bool(key, deft),
lambda self: self._get_bool(key, default),
lambda self, v: self._set_bool(key, v),
None,
f"""
Returns/Modify the status of {key}, Returns {deft} if not defined
Returns/Modify the status of {key}, Returns {default} if not defined
""",
)

def _add_prop_name(
key: str, lst: List[str], deft: Optional[NameObject]
key: str, lst: List[str], default: Optional[NameObject]
) -> property:
return property(
lambda self: self._get_name(key, deft),
lambda self: self._get_name(key, default),
lambda self, v: self._set_name(key, lst, v),
None,
f"""
Returns/Modify the status of {key}, Returns {deft} if not defined.
Returns/Modify the status of {key}, Returns {default} if not defined.
Acceptable values: {lst}
""",
)

def _add_prop_arr(key: str, deft: Optional[ArrayObject]) -> property:
def _add_prop_arr(key: str, default: Optional[ArrayObject]) -> property:
return property(
lambda self: self._get_arr(key, deft),
lambda self: self._get_arr(key, default),
lambda self, v: self._set_arr(key, v),
None,
f"""
Returns/Modify the status of {key}, Returns {deft} if not defined
Returns/Modify the status of {key}, Returns {default} if not defined
""",
)

def _add_prop_int(key: str, deft: Optional[int]) -> property:
def _add_prop_int(key: str, default: Optional[int]) -> property:
return property(
lambda self: self._get_int(key, deft),
lambda self: self._get_int(key, default),
lambda self, v: self._set_int(key, v),
None,
f"""
Returns/Modify the status of {key}, Returns {deft} if not defined
Returns/Modify the status of {key}, Returns {default} if not defined
""",
)

Expand Down
Loading