public static object reader(CodeContext /*!*/ context, [ParamDictionary] IDictionary <object, object> kwArgs, params object[] args) { object dialectObj = null; Dialect dialect = null; IEnumerator e = null; DialectRegistry dialects = GetDialects(context); if (args.Length < 1) { throw PythonOps.TypeError( "expected at least 1 arguments, got {0}", args.Length); } if (args.Length > 2) { throw PythonOps.TypeError( "expected at most 2 arguments, got {0}", args.Length); } if (!PythonOps.TryGetEnumerator(context, args[0], out e)) { throw PythonOps.TypeError("argument 1 must be an iterator"); } if (args.Length > 1) { dialectObj = args[1]; } if (dialectObj is string && !dialects.ContainsKey((string)dialectObj)) { throw MakeError("unknown dialect"); } else if (dialectObj is string) { dialect = dialects[(string)dialectObj]; dialectObj = dialect; } dialect = dialectObj != null? Dialect.Create(context, kwArgs, dialectObj) : Dialect.Create(context, kwArgs); return(new Reader(context, e, dialect)); }
public static void register_dialect(CodeContext /*!*/ context, [ParamDictionary] IDictionary <object, object> kwArgs, params object[] args) { string name = null; object dialectObj = null; Dialect dialect = null; if (args.Length < 1) { throw PythonOps.TypeError("expected at least 1 arguments, got {0}", args.Length); } if (args.Length > 2) { throw PythonOps.TypeError("expected at most 2 arguments, got {0}", args.Length); } name = args[0] as string; if (name == null) { throw PythonOps.TypeError( "dialect name must be a string or unicode"); } if (args.Length > 1) { dialectObj = args[1]; } dialect = (dialectObj != null) ? Dialect.Create(context, kwArgs, dialectObj) : Dialect.Create(context, kwArgs); if (dialect != null) { GetDialects(context)[name] = dialect; } }