// ps1 and ps2 are set by PythonContext and only on the initial load public static void setdefaultencoding(CodeContext context, object name) { if (name == null) { throw PythonOps.TypeError("name cannot be None"); } if (!(name is string strName)) { throw PythonOps.TypeError("name must be a string"); } PythonContext pc = context.LanguageContext; Encoding enc; if (!StringOps.TryGetEncoding(strName, out enc)) { throw PythonOps.LookupError("'{0}' does not match any available encodings", strName); } pc.SetDefaultEncoding(enc); }
// ps1 and ps2 are set by PythonContext and only on the initial load public static void setdefaultencoding(CodeContext context, object name) { if (name == null) { throw PythonOps.TypeError("name cannot be None"); } string strName = name as string; if (strName == null) { throw PythonOps.TypeError("name must be a string"); } PythonContext pc = PythonContext.GetContext(context); Encoding enc; if (!StringOps.TryGetEncoding(strName, out enc)) { throw PythonOps.LookupError("'{0}' does not match any available encodings", strName); } pc.DefaultEncoding = enc; }
private object setdefaultencodingImpl(object name) { if (name == null) { throw Ops.TypeError("name cannot be None"); } string strName = name as string; if (strName == null) { throw Ops.TypeError("name must be a string"); } Encoding enc; if (!StringOps.TryGetEncoding(this, strName, out enc)) { throw Ops.LookupError("'{0}' does not match any available encodings", strName); } DefaultEncoding = enc; __dict__.Remove(SymbolTable.SetDefaultEncoding); return(null); }
public static PythonTuple utf_8_decode(CodeContext context, [BytesConversion] IList <byte> input, string errors = "strict", bool final = false) { StringOps.TryGetEncoding("utf-8", out Encoding encoding); // no preamble skipping return(DoDecode(context, "utf-8", encoding, input, errors, final).ToPythonTuple()); }