Skip to content

Commit

Permalink
feat: enhance pass add_file function to accept bytes or BufferedReader
Browse files Browse the repository at this point in the history
  • Loading branch information
NafieAlhilaly committed Jul 15, 2022
1 parent a288f59 commit 0db31eb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
19 changes: 13 additions & 6 deletions wallet/Pass.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import decimal
import hashlib
from io import BytesIO, FileIO
from io import BytesIO, BufferedReader
import json
import subprocess
import zipfile
Expand Down Expand Up @@ -39,7 +39,7 @@ def __init__(
foreground_color: Optional[str] = None,
label_color: Optional[str] = None,
logo_text: Optional[str] = None,
barcode: Optional[Barcode] = None,
barcodes: Optional[Barcode] = None,
show_strip_img: bool = False,
web_service_url: str = None,
authentication_token: str = None,
Expand Down Expand Up @@ -130,8 +130,10 @@ def __init__(
self.foregroundColor = foreground_color
self.labelColor = label_color
self.logoText = logo_text
self.barcode = barcode
self.barcodes = []
if barcodes:
self.barcodes = [*barcodes]
else:
self.barcodes = []
self.suppressStripShine = show_strip_img

# Web Service Keys
Expand All @@ -151,13 +153,18 @@ def __init__(

self.passInformation = pass_information

def add_file(self, name: str, file_handle: FileIO):
def add_file(
self, name: str, file_handle: Union[BufferedReader, bytes]
) -> None:
"""
Add new file to the pass files
:params name: String name
:params file_handle: File Handle
"""
self._files[name] = file_handle.read()
if type(file_handle) == bytes:
self._files[name] = file_handle
elif type(file_handle) == BufferedReader:
self._files[name] = file_handle.read()

def create(
self,
Expand Down
1 change: 0 additions & 1 deletion wallet/test/test_pass.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ def test_add_bad_files_to_pass():

def test_create_pass_json():
pass_as_json = pass_file._create_pass_json()
print(pass_as_json)
assert pass_as_json == pass_file_as_json


Expand Down

0 comments on commit 0db31eb

Please sign in to comment.