Exemplo n.º 1
0
        private static string ValidateString(object str, string param)
        {
            if (str is string)
            {
                return(str as string);
            }

            ExtensibleString es = str as ExtensibleString;

            if (es != null)
            {
                return(es.Value);
            }

            throw Ops.TypeError("expected string for parameter '{0}' but got '{1}'", param, Ops.GetDynamicType(str).__name__);
        }
Exemplo n.º 2
0
 public static object __new__(CodeContext context, [NotNull] PythonType cls, [NotNull] ExtensibleString @string)
 {
     if (cls == TypeCache.Bytes)
     {
         if (TryInvokeBytesOperator(context, @string, out Bytes? res))
         {
             return(res);
         }
         else
         {
             throw PythonOps.TypeError("string argument without an encoding");
         }
     }
     else
     {
         return(cls.CreateInstance(context, __new__(context, TypeCache.Bytes, @string)));
     }
 }
Exemplo n.º 3
0
        private static string ValidatePattern(object pattern)
        {
            if (pattern is string)
            {
                return(pattern as string);
            }

            ExtensibleString es = pattern as ExtensibleString;

            if (es != null)
            {
                return(es.Value);
            }

            RE_Pattern rep = pattern as RE_Pattern;

            if (rep != null)
            {
                return(rep.pre.UserPattern);
            }

            throw Ops.TypeError("pattern must be a string or compiled pattern");
        }