def OnUri(type_info): return { "type": "string", "pattern": "^{}$".format( RegularExpression.PythonToJavaScript( RegularExpressionVisitor().Accept(type_info)[0])) }
def OnGuid(type_info): return textwrap.dedent( """\ <xsd:restriction base="xsd:string"> <xsd:pattern value="{}" /> </xsd:restriction> """, ).format( RegularExpression.PythonToJavaScript( RegularExpressionVisitor().Accept(type_info)[0]))
def OnString(type_info): result = {"type": "string"} if type_info.ValidationExpression is not None: validation = RegularExpression.PythonToJavaScript( type_info.ValidationExpression) if validation[0] != "^": validation = "^{}".format(validation) if validation[-1] != "$": validation = "{}$".format(validation) result["pattern"] = validation else: if type_info.MinLength not in [0, None]: result["minLength"] = type_info.MinLength if type_info.MaxLength: result["maxLength"] = type_info.MaxLength return result
def OnString(type_info): if type_info.ValidationExpression: return [ RegularExpression.PythonToJavaScript(type_info.ValidationExpression), ] if type_info.MinLength in [ 0, None ] and type_info.MaxLength is None: return [ ".*", ] if type_info.MinLength == 1 and type_info.MaxLength is None: return [ ".+", ] assert type_info.MinLength is not None if type_info.MaxLength is None: return [ ".{%d}.*" % type_info.MinLength, ] if type_info.MinLength == type_info.MaxLength: return [ ".{%d}" % type_info.MinLength, ] assert type_info.MaxLength is not None return [ ".{%d,%d}" % (type_info.MinLength, type_info.MaxLength), ]
def OnString(type_info): restrictions = OrderedDict() if type_info.ValidationExpression is not None: restrictions["pattern"] = RegularExpression.PythonToJavaScript( type_info.ValidationExpression) else: if type_info.MinLength not in [None, 0]: restrictions["minLength"] = type_info.MinLength if type_info.MaxLength is not None: restrictions["maxLength"] = type_info.MaxLength if not restrictions: return "xsd:string" return textwrap.dedent( """\ <xsd:restriction base="xsd:string"> {} </xsd:restriction> """, ).format("\n".join([ ' <xsd:{} value="{}" />'.format(k, v) for k, v in six.iteritems(restrictions) ]))