Skip to content
Open
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
8 changes: 3 additions & 5 deletions RMS/ImgurUpload.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@

from __future__ import print_function, division, absolute_import

# Imgur RMS client ID
CLIENT_ID = "ca85d1ed0b3fa85"


import base64
import json

Expand All @@ -18,6 +14,7 @@




def imgurUpload(file_path, image_data=None):
""" Upload the given image to Imgur.

Expand All @@ -44,7 +41,8 @@ def imgurUpload(file_path, image_data=None):


# Upload the image
headers = {'Authorization': 'Client-ID ' + CLIENT_ID}
client_id = os.environ.get('IMGUR_CLIENT_ID', 'ca85d1ed0b3fa85')
headers = {'Authorization': 'Client-ID ' + client_id}
data = {'image': b64_image, 'title': 'test'} # create a dictionary.

request = urllib2.Request(url="https://api.imgur.com/3/upload.json",
Expand Down
23 changes: 22 additions & 1 deletion RMS/Pickling.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,27 @@
from RMS.Misc import mkdirP


class RestrictedUnpickler(pickle.Unpickler):
"""Restricted unpickler that only allows safe built-in types."""

SAFE_BUILTINS = {
'builtins',
}

def find_class(self, module, name):
# Only allow safe built-in types, block everything else
if module not in self.SAFE_BUILTINS:
raise pickle.UnpicklingError(
"global '%s.%s' is forbidden" % (module, name)
)
return super(RestrictedUnpickler, self).find_class(module, name)


def restricted_loads(s, **kwargs):
"""Load a pickle with restricted unpickler for safety."""
return RestrictedUnpickler(s, **kwargs).load()




def savePickle(obj, dir_path, file_name):
Expand Down Expand Up @@ -50,7 +71,7 @@ def loadPickle(dir_path, file_name):

# Python 3
else:
return pickle.load(f, encoding='latin1')
return restricted_loads(f, encoding='latin1')

except (IOError, EOFError, TypeError, KeyError, pickle.UnpicklingError):

Expand Down