def _xml_ele_to_obj(cls, xml_ele): kwargs = { 'username': xml_ele.get('username'), 'updated': xml_ele.get('updated'), 'created': xml_ele.get('created'), 'email': xml_ele.get('email'), 'domainId': xml_ele.get('domainId'), 'defaultRegion': xml_ele.get('defaultRegion'), 'password': xml_ele.get('password'), 'name': xml_ele.get('name'), 'display_name': xml_ele.get('display-name') } try: kwargs['id'] = int(xml_ele.get('id')) except (ValueError, TypeError): kwargs['id'] = xml_ele.get('id') if xml_ele.get('enabled') is not None: kwargs['enabled'] = json.loads(xml_ele.get('enabled').lower()) roles = xml_ele.find('roles') if roles is not None: #if roles is not a list it is a single element with a list of #role elements roles = roles.findall('role') if roles is not None: kwargs['roles'] = Roles._xml_list_to_obj(roles) return User(**kwargs)
def _xml_ele_to_obj(cls, xml_ele): kwargs = { "username": xml_ele.get("username"), "updated": xml_ele.get("updated"), "created": xml_ele.get("created"), "email": xml_ele.get("email"), "domainId": xml_ele.get("domainId"), "defaultRegion": xml_ele.get("defaultRegion"), "password": xml_ele.get("password"), "name": xml_ele.get("name"), "display_name": xml_ele.get("display-name"), } try: kwargs["id"] = int(xml_ele.get("id")) except (ValueError, TypeError): kwargs["id"] = xml_ele.get("id") if xml_ele.get("enabled") is not None: kwargs["enabled"] = json.loads(xml_ele.get("enabled").lower()) roles = xml_ele.find("roles") if roles is not None: # if roles is not a list it is a single element with a list of # role elements roles = roles.findall("role") if roles is not None: kwargs["roles"] = Roles._xml_list_to_obj(roles) return User(**kwargs)
def _dict_to_obj(cls, json_dict): if "RAX-AUTH:defaultRegion" in json_dict: json_dict["defaultRegion"] = json_dict["RAX-AUTH:defaultRegion"] del json_dict["RAX-AUTH:defaultRegion"] if "RAX-AUTH:domainId" in json_dict: json_dict["domainId"] = json_dict["RAX-AUTH:domainId"] del json_dict["RAX-AUTH:domainId"] if "OS-KSADM:password" in json_dict: json_dict["password"] = json_dict["OS-KSADM:password"] del json_dict["OS-KSADM:password"] if "display-name" in json_dict: json_dict["display_name"] = json_dict["display-name"] del json_dict["display-name"] if "roles" in json_dict: json_dict["roles"] = Roles._list_to_obj(json_dict["roles"]) return User(**json_dict)
def _xml_ele_to_obj(cls, xml_ele): kwargs = {'username': xml_ele.get('username'), 'updated': xml_ele.get('updated'), 'created': xml_ele.get('created'), 'email': xml_ele.get('email'), 'domainId': xml_ele.get('domainId'), 'defaultRegion': xml_ele.get('defaultRegion'), 'password': xml_ele.get('password'), 'name': xml_ele.get('name'), 'display_name': xml_ele.get('display-name')} try: kwargs['id'] = int(xml_ele.get('id')) except (ValueError, TypeError): kwargs['id'] = xml_ele.get('id') if xml_ele.get('enabled') is not None: kwargs['enabled'] = json.loads(xml_ele.get('enabled').lower()) roles = xml_ele.find(Roles.ROOT_TAG) if roles is not None: #if roles is not a list it is a single element with a list of #role elements roles = roles.findall(Role.ROOT_TAG) if roles is not None: kwargs['roles'] = Roles._xml_list_to_obj(roles) return User(**kwargs)