def __doGetResourceConfig(self): configs = ConfigManager \ .get(self.__resourceType.__name__.lower()) \ .get('resource') if isinstance(configs, types.ListType): config_items = [] i = 1 for item in configs: item_param = params.parseString(item) if len(configs) > 1: item_param.set_name(item_param.get_name() + str(i)) # TODO: implement creation params strategy config_items.append(item_param) i += 1 return config_items return params.parseString(configs)
def __xml2py(obj): """ Parse XML in to python entity """ if obj is not None and obj is not '': try: return params.parseString(obj, silence=True) except etree.XMLSyntaxError: # raised when server replies in non-XML format, # the motivation for this error is #915036 raise errors.FormatError return obj
def read_object(self): """If input was provided via stdin, then parse it and return a binding instance.""" stdin = self.context.terminal.stdin # REVISE: this is somewhat of a hack (this detects a '<<' redirect by # checking if stdin is a StringIO) if not hasattr(stdin, 'len'): return buf = stdin.read() try: obj = params.parseString(buf) except Exception: self.error('could not parse input') return obj
def __init__(self, response_code, response_reason, response_body): self.detail = None self.status = None self.reason = None detail = '' RESPONSE_FORMAT = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' RESPONSE_FAULT_BODY = '<fault>' APP_SERVER_RESPONSE_FORMAT = '<html><head><title>JBoss Web' # REST error response_text = response_body.decode("utf-8") if response_text.startswith(RESPONSE_FORMAT) and response_text.find(RESPONSE_FAULT_BODY) != -1: try: f_detail = params.parseString(response_body, silence=True) except: f_detail = '' if str != type(f_detail): if isinstance(f_detail, params.Action) and f_detail.fault is not None: detail = f_detail.fault.detail.lstrip() else: if f_detail and f_detail.detail: detail = f_detail.detail.lstrip() # engine returns can-do-action error messages with brackets if detail and detail.startswith('[') and detail.endswith(']'): detail = detail[1:len(detail) - 1] # application server error elif response_text.startswith(APP_SERVER_RESPONSE_FORMAT): detail = response_text start = detail.find('<h1>') end = detail.find('</h1>') if start != -1 and end != -1: detail = detail[start:end].replace('<h1>', '').replace('</h1>', '') if detail and detail.endswith(' - '): detail = detail[:len(detail) - 3] else: detail = '\n' + response_text if response_text else '' self.detail = detail self.reason = response_reason self.status = response_code Exception.__init__(self, '[ERROR]::oVirt API request failure.' + self.__str__())
def __produceParamsHolder(typ, item, **kwargs): """ Produces ParamsHolder and injects custom data @param item: item to process @param kwargs: keyword args @return: params holder """ params_holder = params.parseString(item) if type(params_holder) != typ: raise IncorrrectTypeError( typ.__name__, type(params_holder).__name__ ) # TODO: revisit if kwargs: for name, value in kwargs.items(): if name not in ConfigManager.INTERNAL_PROPERIES: setattr(params_holder, name, value) return params_holder