def __init__(self, cls_or_instance, **kwargs): super(Dict, self).__init__(**kwargs) error_msg = ("The type of the dict elements must be a subclass of " "flask_restful.fields.Raw") if isinstance(cls_or_instance, type): if not issubclass(cls_or_instance, Raw): raise MarshallingException(error_msg) self.container = cls_or_instance() else: if not isinstance(cls_or_instance, Raw): raise MarshallingException(error_msg) self.container = cls_or_instance
def format(self, value): try: if value is None: return self.default return str(uuid.UUID(value)) except ValueError as ve: raise MarshallingException(ve)
def format(self, value): query = request.args.get('query') count = value.count(query) value = value.replace(query,'<strong style="color:red">'+query+'</strong>',count) try: return six.text_type(value) except ValueError as ve: raise MarshallingException(ve)
def format(self, value): try: data = binary_type(value, 'utf8') with BytesIO(data) as d, MRVread(d) as m: structure = next(m) except (TypeError, StopIteration) as ve: raise MarshallingException(ve) return structure
def format(self, value): planns_all = PlanMedicine.query.filter_by(planid=value).all() fmt_value = "" for p in planns_all: medicine_name = Medicine.query.filter_by(id=p.medicineid).first().name fmt_value += "%s "%medicine_name try: return six.text_type(fmt_value) except ValueError as ve: raise MarshallingException(ve)
def format(self, value): v = String.format(self, value) if (v is None or 0 == len(str(v))): error_msg = ("Int list in len(0).") raise MarshallingException(error_msg) if (not isinstance(v, str)): error_msg = ("Int list NOT in string type.") raise MarshallingException(error_msg) v_list = [] for v_s in v.split(","): try: v_list.append(int(v_s)) except Exception: error_msg = ( "Int list items(seperated with ',') NOT in int type.") raise MarshallingException(error_msg) return v_list
def format(self, value): v = String.format(self, value) if (isinstance(v, dict)): return v try: json.loads(v) except Exception: msg = ("DictStr[%s] format ERROR" % (v)) raise MarshallingException(msg) return v
def format(self, value): v = String.format(self, value) try: dt = datetime.strptime(v, "%Y-%m-%d %H:%M:%S") dt = dt except Exception: try: dt = datetime.strptime(v, "%Y-%m-%dT%H:%M:%S") dt = dt except Exception: error_msg = ("Datetime[%s] format ERROR type." % (v)) raise MarshallingException(error_msg) v = v.replace("T", " ") return v
def format(self, value): try: mt = _type(value) except ValueError as ve: raise MarshallingException(ve) return mt
def format(self, key): try: return key.public_hex except ValueError as ve: raise MarshallingException(ve)
def format(self, value): try: return value.hex() except ValueError as ve: raise MarshallingException(ve)
def format(self, v): if (v is None or 0 == len(str(v))): error_msg = ("Input string empty.") raise MarshallingException(error_msg) return v