#!/usr/local/bin/python class operation_status: """ Collection of standard codes and format ofr operationstatus """ success = 0 access = 1 busy= 2 unsupp = 3 bad_param = 4 internal = 5 partial = 6 no_target = 7 federant = 8 code_str = { success: "Success", access : "Access Denied", busy : "Resource busy, try again later", unsupp : "Operation not supported", bad_param: "Bad parameter for operation", internal : "Internal Error", partial: "Partial Embedding", no_target: "No such target", federant: "Federant Error", } str_code = dict([ (v, k) for k, v in code_str.iteritems() ]) def __init__(self, target, code=None, description=None): self.target = target self.code = code if description is not None: self.description = description elif code in operation_status.code_str: self.description = operation_status.code_str[code] else: self.description = None def to_dict(self): rv = { 'target': self.target, 'code': self.code, } if self.description is not None: rv['description'] = self.description return rv