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

Use with statements for handling files #34

Merged
merged 2 commits into from
Jul 27, 2021
Merged
Show file tree
Hide file tree
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
6 changes: 4 additions & 2 deletions SimpleMDMpy/Apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ def create_app(self, name=None, app_store_id=None, bundle_id=None, binary=None):
elif bundle_id:
data['bundle_id'] = bundle_id
elif binary:
files['binary'] = open(binary, 'rb')
with open(binary, 'rb') as f:
files['binary'] = f
return self._post_data(self.url, data, files)

def update_app(self, app_id, binary=None, name=None):
Expand All @@ -40,7 +41,8 @@ def update_app(self, app_id, binary=None, name=None):
if name:
data['name'] = name
if binary:
files['binary'] = open(binary, 'rb')
with open(binary, 'rb') as f:
files['binary'] = f
return self._patch_data(url, data, files)

def delete_app(self, app_id):
Expand Down
7 changes: 5 additions & 2 deletions SimpleMDMpy/CustomConfigurationProfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ def create_profile(self, name, mobileconfig, user_scope=None, attribute_support=
"""upload a config file"""
url = self.url
data = {'name': name}
files = {'mobileconfig': open(mobileconfig, 'rb')}
with open(mobileconfig, 'rb') as f:
mobileconfig_contents = f
files = {'mobileconfig': mobileconfig_contents}
if user_scope:
data['user_scope'] = user_scope
if attribute_support:
Expand All @@ -36,7 +38,8 @@ def update_profile(self, profile_id, name=None, mobileconfig=None, # pylint: dis
if name:
data['name'] = name
if mobileconfig:
files['mobileconfig'] = open(mobileconfig, 'rb')
with open(mobileconfig, 'rb') as f:
files['mobileconfig'] = f
if user_scope:
data['user_scope'] = user_scope
if attribute_support:
Expand Down
4 changes: 3 additions & 1 deletion SimpleMDMpy/PushCertificate.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ def getpush_certificate(self):
def update_certificate(self, file, apple_id):
"""Upload a new certificate and replace the
existing certificate for your account."""
files = {'file': open(file, 'rb')}
with open(file, 'rb')} as f:
cert_contents = f
files = {'file': cert_contents}
data = {}
if apple_id:
data["apple_id"] = apple_id
Expand Down