Skip to content

Commit

Permalink
issue #83: moved logic to convert bytes to str to Resource instead of…
Browse files Browse the repository at this point in the history
… in Insert's init
  • Loading branch information
SibrenJacobs committed Jun 2, 2022
1 parent bc573cc commit 0dffc0e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cloudofficeprint/elements/elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,7 @@ class Insert(Property):
"""

def __init__(self, name: str, value: Resource):
super().__init__(name, value.base64 if isinstance(value, RawResource) else value.data)
super().__init__(name, value.as_string)

@property
def available_tags(self) -> FrozenSet[str]:
Expand Down
12 changes: 12 additions & 0 deletions cloudofficeprint/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ def data(self) -> Union[str, bytes]:
"""
return self._data

@property
def as_string(self) -> str:
"""The string representation of the data contained in this Resource.
Returns:
str: the string representation of the data contained in this Resource.
"""
if isinstance(self.data, str):
return self.data
elif isinstance(self.data, bytes):
return file_utils.raw_to_base64(self.data)

@property
def template_json(self) -> str:
"""Get the JSON representation when used as a template.
Expand Down

0 comments on commit 0dffc0e

Please sign in to comment.