Skip to content

Instantly share code, notes, and snippets.

@linzino7
Forked from housemeow/function exception.py
Created February 26, 2018 06:57
Show Gist options
  • Save linzino7/d409f2ce77c27e2365524ba0b13c81cd to your computer and use it in GitHub Desktop.
Save linzino7/d409f2ce77c27e2365524ba0b13c81cd to your computer and use it in GitHub Desktop.
class Command:
def redo(self, **kwargs):
abstract
def undo(self, **kwargs);
abstract
class UploadImgurCommand extend Command:
def redo(self, **kwargs):
image = kwargs['image'];
try:
return imgurApi.upload(image);
catch Exception as ex:
throw ex;
def undo(self, **kwargs):
whatever
class InsertToMangoCommand extend Command:
def redo(self, **kwargs):
image_url = kwargs['image_url']
try:
return mongoApi.insert(image_url);
catch Exception as ex:
throw ex;
class YourApplication:
def upload_image(self, image):
command_classes = [UploadImgurCommand, InsertToMangoCommand];
args = { image: image }
command_index = 1
for command_class in command_classes:
command = command_class(args);
try:
args = command.redo(args)
catch Exception as ex:
whatever
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment