public static string EnumKey(object key, int index) { HKEYType rootKey = GetRootKey(key); if (index >= rootKey.key.SubKeyCount) { throw PythonExceptions.CreateThrowable(PythonExceptions.WindowsError, PythonExceptions._WindowsError.ERROR_BAD_COMMAND, "No more data is available"); } return(rootKey.key.GetSubKeyNames()[index]); }
public RegistryKey GetKey() { lock (this) { if (key == null) { throw PythonExceptions.CreateThrowable(PythonExceptions.OSError, "key has been closed"); } return(key); } }
public static void excepthookImpl(CodeContext /*!*/ context, object exctype, object value, object traceback) { PythonContext pc = context.LanguageContext; PythonOps.PrintWithDest( context, pc.SystemStandardError, pc.FormatException(PythonExceptions.ToClr(value)) ); }
internal static X509Certificate2 ReadCertificate(CodeContext context, string filename) { string[] lines; try { lines = File.ReadAllLines(filename); } catch (IOException) { throw PythonExceptions.CreateThrowable(SSLError(context), "Can't open file ", filename); } X509Certificate2 cert = null; RSACryptoServiceProvider key = null; try { for (int i = 0; i < lines.Length; i++) { if (lines[i] == "-----BEGIN CERTIFICATE-----") { var certStr = ReadToEnd(lines, ref i, "-----END CERTIFICATE-----"); try { cert = new X509Certificate2(Convert.FromBase64String(certStr.ToString())); } catch (Exception e) { throw ErrorDecoding(context, filename, e); } } else if (lines[i] == "-----BEGIN RSA PRIVATE KEY-----") { var keyStr = ReadToEnd(lines, ref i, "-----END RSA PRIVATE KEY-----"); try { var keyBytes = Convert.FromBase64String(keyStr.ToString()); key = ParsePkcs1DerEncodedPrivateKey(context, filename, keyBytes); } catch (Exception e) { throw ErrorDecoding(context, filename, e); } } } } catch (InvalidOperationException e) { throw ErrorDecoding(context, filename, e.Message); } if (cert != null) { if (key != null) { try { cert.PrivateKey = key; } catch (CryptographicException e) { throw ErrorDecoding(context, filename, "cert and private key are incompatible", e); } } return(cert); } throw ErrorDecoding(context, filename, "certificate not found"); }
public void release(CodeContext /*!*/ context) { if (Interlocked.Exchange <Thread>(ref curHolder, null) == null) { throw PythonExceptions.CreateThrowable((PythonType)PythonContext.GetContext(context).GetModuleState("threaderror"), "lock isn't held", null); } if (blockEvent != null) { // if this isn't set yet we race, it's handled in Acquire() blockEvent.Set(); } }
private CultureInfo LocaleToCulture(CodeContext /*!*/ context, string locale) { if (locale == "C") { return(PythonContext.CCulture); } locale = locale.Replace('_', '-'); try { return(StringUtils.GetCultureInfo(locale)); } catch (ArgumentException) { throw PythonExceptions.CreateThrowable(_localeerror(context), String.Format("unknown locale: {0}", locale)); } }
public static string EnumKey(object key, int index) { HKEYType rootKey = GetRootKey(key); int len = 257; // maximum key name length is 256 StringBuilder name = new StringBuilder(len); int ret = RegEnumKeyEx(rootKey.GetKey().Handle, index, name, ref len, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero); if (ret != ERROR_SUCCESS) { Debug.Assert(ret == ERROR_NO_MORE_ITEMS); throw PythonExceptions.CreateThrowable(PythonExceptions.OSError, PythonExceptions._OSError.ERROR_BAD_COMMAND, "No more data is available", null, PythonExceptions._OSError.ERROR_BAD_COMMAND); } return(name.ToString()); }
public static void EnableReflectionKey(object key) { HKEYType rootKey = GetRootKey(key); if (!Environment.Is64BitOperatingSystem) { throw new NotImplementedException("not implemented on this platform"); } int dwRet = RegEnableReflectionKey(rootKey.GetKey().Handle); if (dwRet != ERROR_SUCCESS) { throw PythonExceptions.CreateThrowable(PythonExceptions.OSError, dwRet); } }
public static void DeleteKeyEx(object key, string sub_key, int access = KEY_WOW64_64KEY, int reserved = 0) { HKEYType rootKey = GetRootKey(key); if (key is BigInteger && string.IsNullOrEmpty(sub_key)) { throw new InvalidCastException("DeleteKeyEx() argument 2 must be string, not None"); } int result = RegDeleteKeyEx(rootKey.GetKey().Handle, sub_key, access, reserved); if (result != ERROR_SUCCESS) { throw PythonExceptions.CreateThrowable(PythonExceptions.OSError, result); } }
public static void excepthookImpl(CodeContext /*!*/ context, object exctype, object value, object traceback) { PythonContext pc = context.LanguageContext; var exc = PythonExceptions.ToClr(value); if (exc is null) { throw PythonOps.TypeError($"Exception expected for {nameof(value)}, {PythonTypeOps.GetName(value)} found"); } PythonOps.PrintWithDest( context, pc.SystemStandardError, pc.FormatException(PythonExceptions.ToClr(value)) ); }
public static bool QueryReflectionKey(object key) { HKEYType rootKey = GetRootKey(key); bool isDisabled; if (!Environment.Is64BitOperatingSystem) { throw new NotImplementedException("not implemented on this platform"); } int dwRet = RegQueryReflectionKey(rootKey.GetKey().Handle, out isDisabled); if (dwRet != ERROR_SUCCESS) { throw PythonExceptions.CreateThrowable(PythonExceptions.WindowsError, dwRet); } return(isDisabled); }
public static PythonTuple EnumValue(object key, int index) { HKEYType rootKey = GetRootKey(key); if (index >= rootKey.GetKey().ValueCount) { throw PythonExceptions.CreateThrowable(PythonExceptions.WindowsError, PythonExceptions._WindowsError.ERROR_BAD_COMMAND, "No more data is available"); } var nativeRootKey = rootKey.GetKey(); string valueName = nativeRootKey.GetValueNames()[index]; int valueKind; object value; QueryValueExImpl(nativeRootKey, valueName, out valueKind, out value); return(PythonTuple.MakeTuple(valueName, value, valueKind)); }
public static HKEYType ConnectRegistry(string computerName, BigInteger key) { if (string.IsNullOrEmpty(computerName)) { computerName = string.Empty; } RegistryKey newKey; try { newKey = RegistryKey.OpenRemoteBaseKey(MapSystemKey(key), computerName); }catch (IOException ioe) { throw PythonExceptions.CreateThrowable(PythonExceptions.WindowsError, PythonExceptions._WindowsError.ERROR_BAD_NETPATH, ioe.Message); } catch (Exception e) { throw new ExternalException(e.Message); } return(new HKEYType(newKey)); }
public static HKEYType OpenKey(object key, string subKeyName, int reserved, int mask) { HKEYType rootKey = GetRootKey(key); RegistryKey newKey = null; // I'm assuming that the masks that CPy uses are the same as the Win32 API one mentioned here- // http://msdn2.microsoft.com/en-us/library/ms724878(VS.85).aspx // KEY_WRITE is a combination of KEY_SET_VALUE and KEY_CREATE_SUB_KEY. We'll open with write access // if any of this is set. // KEY_READ is a combination of KEY_QUERY_VALUE, KEY_ENUMERATE_SUB_KEYS and KEY_NOTIFY. We'll open // with read access for all of these. try { if ((mask & KEY_SET_VALUE) == KEY_SET_VALUE || (mask & KEY_CREATE_SUB_KEY) == KEY_CREATE_SUB_KEY) { newKey = rootKey.key.OpenSubKey(subKeyName, true); } else if ((mask & KEY_QUERY_VALUE) == KEY_QUERY_VALUE || (mask & KEY_ENUMERATE_SUB_KEYS) == KEY_ENUMERATE_SUB_KEYS || (mask & KEY_NOTIFY) == KEY_NOTIFY) { newKey = rootKey.key.OpenSubKey(subKeyName, false); } else { throw new Win32Exception("Unexpected mode"); } } catch (SecurityException) { throw PythonExceptions.CreateThrowable(PythonExceptions.WindowsError, PythonExceptions._WindowsError.ERROR_ACCESS_DENIED, "Access is denied"); } if (newKey == null) { throw PythonExceptions.CreateThrowable(PythonExceptions.WindowsError, PythonExceptions._WindowsError.ERROR_FILE_NOT_FOUND, "The system cannot find the file specified"); } return(new HKEYType(newKey)); }
public void do_handshake() { try { // make sure the remote side hasn't shutdown before authenticating so we don't // hang if we're in blocking mode. #pragma warning disable 219 // unused variable int available = _socket._socket.Available; #pragma warning restore 219 } catch (SocketException) { throw PythonExceptions.CreateThrowable(PythonExceptions.OSError, "socket closed before handshake"); } EnsureSslStream(true); var enabledSslProtocols = GetProtocolType(_protocol); try { if (_serverSide) { _sslStream.AuthenticateAsServer(_cert, _certsMode == PythonSsl.CERT_REQUIRED, enabledSslProtocols, false); } else { var collection = new X509CertificateCollection(); if (_cert != null) { collection.Add(_cert); } _sslStream.AuthenticateAsClient(_serverHostName ?? _socket._hostName, collection, enabledSslProtocols, false); } } catch (AuthenticationException e) { ((IDisposable)_socket._socket).Dispose(); throw PythonExceptions.CreateThrowable(PythonSsl.SSLError(_context), "errors while performing handshake: ", e.ToString()); } if (_validationFailure != null) { throw _validationFailure; } }
public static PythonTuple EnumValue(object key, int index) { HKEYType rootKey = GetRootKey(key); if (index >= rootKey.GetKey().ValueCount) { throw PythonExceptions.CreateThrowable(PythonExceptions.OSError, PythonExceptions._OSError.ERROR_BAD_COMMAND, "No more data is available", null, PythonExceptions._OSError.ERROR_BAD_COMMAND); } var nativeRootKey = rootKey.GetKey(); string valueName = nativeRootKey.GetValueNames()[index]; // it looks like nativeRootKey.Handle fails on HKEY_PERFORMANCE_DATA so manually create the handle instead var handle = rootKey.hkey == HKEY_PERFORMANCE_DATA ? new SafeRegistryHandle(new IntPtr(unchecked ((int)0x80000004)), true) : nativeRootKey.Handle; int valueKind; object value; QueryValueExImpl(handle, valueName, out valueKind, out value); return(PythonTuple.MakeTuple(valueName, value, valueKind)); }
public static Bytes byteswap(CodeContext /*!*/ context, [NotNone] IBufferProtocol fragment, int width) { if (width < 1 || width > 4) { throw PythonExceptions.CreateThrowable(error(context), "Size should be 1, 2, 3 or 4"); } using var buffer = fragment.GetBuffer(); if (buffer.NumBytes() % width != 0) { throw PythonExceptions.CreateThrowable(error(context), "not a whole number of frames"); } var array = buffer.ToArray(); if (width == 2) { for (var i = 0; i < array.Length; i += width) { array.ByteSwap(i, i + 1); } } else if (width == 3) { for (var i = 0; i < array.Length; i += width) { array.ByteSwap(i, i + 2); } } else if (width == 4) { for (var i = 0; i < array.Length; i += width) { array.ByteSwap(i, i + 3); array.ByteSwap(i + 1, i + 2); } } return(Bytes.Make(array)); }
public string GetLocale(CodeContext /*!*/ context, int category) { switch ((LocaleCategories)category) { case LocaleCategories.All: if (Collate == CType && Collate == Time && Collate == Monetary && Collate == Numeric) { // they're all the same, return only 1 name goto case LocaleCategories.Collate; } // return them all... return(String.Format("LC_COLLATE={0};LC_CTYPE={1};LC_MONETARY={2};LC_NUMERIC={3};LC_TIME={4}", GetLocale(context, LC_COLLATE), GetLocale(context, LC_CTYPE), GetLocale(context, LC_MONETARY), GetLocale(context, LC_NUMERIC), GetLocale(context, LC_TIME))); case LocaleCategories.Collate: return(CultureToName(Collate)); case LocaleCategories.CType: return(CultureToName(CType)); case LocaleCategories.Time: return(CultureToName(Time)); case LocaleCategories.Monetary: return(CultureToName(Monetary)); case LocaleCategories.Numeric: return(CultureToName(Numeric)); default: throw PythonExceptions.CreateThrowable(_localeerror(context), "unknown locale category"); } }
public static PythonTuple CreateProcess( CodeContext context, string applicationName, string commandLineArgs, object pSec /*subprocess.py passes None*/, object tSec /*subprocess.py passes None*/, int?bInheritHandles, uint?dwCreationFlags, object lpEnvironment, string lpCurrentDirectory, object lpStartupInfo /* subprocess.py passes STARTUPINFO*/) { object dwFlags = PythonOps.GetBoundAttr(context, lpStartupInfo, "dwFlags"); //public Int32 dwFlags; object hStdInput = PythonOps.GetBoundAttr(context, lpStartupInfo, "hStdInput"); //public IntPtr hStdInput; object hStdOutput = PythonOps.GetBoundAttr(context, lpStartupInfo, "hStdOutput"); //public IntPtr hStdOutput; object hStdError = PythonOps.GetBoundAttr(context, lpStartupInfo, "hStdError"); //public IntPtr hStdError; object wShowWindow = PythonOps.GetBoundAttr(context, lpStartupInfo, "wShowWindow"); //Int16 wShowWindow; Int32 dwFlagsInt32 = dwFlags != null?Converter.ConvertToInt32(dwFlags) : 0; IntPtr hStdInputIntPtr = hStdInput != null ? new IntPtr(Converter.ConvertToInt32(hStdInput)) : IntPtr.Zero; IntPtr hStdOutputIntPtr = hStdOutput != null ? new IntPtr(Converter.ConvertToInt32(hStdOutput)) : IntPtr.Zero; IntPtr hStdErrorIntPtr = hStdError != null ? new IntPtr(Converter.ConvertToInt32(hStdError)) : IntPtr.Zero; Int16 wShowWindowInt16 = wShowWindow != null?Converter.ConvertToInt16(wShowWindow) : (short)0; STARTUPINFO startupInfo = new STARTUPINFO(); startupInfo.dwFlags = dwFlagsInt32; startupInfo.hStdInput = hStdInputIntPtr; startupInfo.hStdOutput = hStdOutputIntPtr; startupInfo.hStdError = hStdErrorIntPtr; startupInfo.wShowWindow = wShowWindowInt16; // No special security SECURITY_ATTRIBUTES pSecSA = new SECURITY_ATTRIBUTES(); pSecSA.nLength = Marshal.SizeOf(pSecSA); SECURITY_ATTRIBUTES tSecSA = new SECURITY_ATTRIBUTES(); tSecSA.nLength = Marshal.SizeOf(tSecSA); if (pSec != null) { /* If pSec paseed in from Python is not NULL * there needs to be some conversion done here...*/ } if (tSec != null) { /* If tSec paseed in from Python is not NULL * there needs to be some conversion done here...*/ } // If needed convert lpEnvironment Dictionary to lpEnvironmentIntPtr string lpEnvironmentStr = EnvironmentToNative(context, lpEnvironment); PROCESS_INFORMATION lpProcessInformation = new PROCESS_INFORMATION(); bool result = CreateProcessPI( String.IsNullOrEmpty(applicationName) ? null : applicationName /*applicationNameHelper*//*processStartInfo.FileName*/, String.IsNullOrEmpty(commandLineArgs) ? null : commandLineArgs /*commandLineArgsHelper*//*processStartInfo.Arguments*/, ref pSecSA, ref tSecSA, bInheritHandles.HasValue && bInheritHandles.Value > 0 ? true : false, dwCreationFlags.HasValue ? dwCreationFlags.Value : 0, lpEnvironmentStr, lpCurrentDirectory, ref startupInfo, out lpProcessInformation); if (!result) { int error = Marshal.GetLastWin32Error(); throw PythonExceptions.CreateThrowable(PythonExceptions.WindowsError, error, FormatError(error)); } IntPtr hp = lpProcessInformation.hProcess; IntPtr ht = lpProcessInformation.hThread; int pid = lpProcessInformation.dwProcessId; int tid = lpProcessInformation.dwThreadId; return(PythonTuple.MakeTuple( new PythonSubprocessHandle(hp, true), new PythonSubprocessHandle(ht), pid, tid)); }
private static Exception WindowsError(int code) { string message = CTypes.FormatError(code); return(PythonExceptions.CreateThrowable(PythonExceptions.WindowsError, code, message)); }
private static Exception Incomplete(CodeContext /*!*/ context, params object[] args) { return(PythonExceptions.CreateThrowable((PythonType)context.LanguageContext.GetModuleState(_IncompleteKey), args)); }
private static Exception MakeException(CodeContext /*!*/ context, object value) { return(PythonExceptions.CreateThrowable((PythonType)PythonContext.GetContext(context).GetModuleState("selecterror"), value)); }
private static void QueryValueExImpl(SafeRegistryHandle handle, string valueName, out int valueKind, out object value) { valueName = valueName ?? ""; // it looks like RegQueryValueEx can fail with null, use empty string instead valueKind = 0; int dwRet; byte[] data = new byte[128]; uint length = (uint)data.Length; // query the size first, reading the data as we query... dwRet = RegQueryValueEx(handle, valueName, IntPtr.Zero, out valueKind, data, ref length); while (dwRet == ERROR_MORE_DATA) { data = new byte[data.Length * 2]; length = (uint)data.Length; dwRet = RegQueryValueEx(handle, valueName, IntPtr.Zero, out valueKind, data, ref length); } if (dwRet == PythonExceptions._OSError.ERROR_FILE_NOT_FOUND) { throw PythonExceptions.CreateThrowable(PythonExceptions.OSError, PythonExceptions._OSError.ERROR_FILE_NOT_FOUND, "The system cannot find the file specified", null, PythonExceptions._OSError.ERROR_FILE_NOT_FOUND); } if (dwRet != ERROR_SUCCESS) { throw PythonExceptions.CreateThrowable(PythonExceptions.OSError, dwRet); } // convert the result into a Python object switch (valueKind) { case REG_MULTI_SZ: PythonList list = new PythonList(); int curIndex = 0; while (curIndex < length) { for (int dataIndex = curIndex; dataIndex < length; dataIndex += 2) { if (data[dataIndex] == 0 && data[dataIndex + 1] == 0) { // got a full string list.Add(ExtractString(data, curIndex, dataIndex)); curIndex = dataIndex + 2; if (curIndex + 2 <= length && data[curIndex] == 0 && data[curIndex + 1] == 0) { // double null terminated curIndex = data.Length; break; } } } if (curIndex != data.Length) { // not null terminated list.Add(ExtractString(data, curIndex, data.Length)); } } value = list; break; case REG_BINARY: var tight_fit_data = new byte[length]; for (int i = 0; i < length; i++) { tight_fit_data[i] = data[i]; } value = length == 0 ? null : new Bytes(tight_fit_data); break; case REG_EXPAND_SZ: case REG_SZ: if (length >= 2 && data[length - 1] == 0 && data[length - 2] == 0) { value = ExtractString(data, 0, (int)length - 2); } else { value = ExtractString(data, 0, (int)length); } break; case REG_DWORD: if (BitConverter.IsLittleEndian) { value = (uint)((data[3] << 24) | (data[2] << 16) | (data[1] << 8) | data[0]); } else { value = (uint)((data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3]); } break; default: value = null; break; } }
public static HKEYType OpenKey(object key, string subKeyName, [DefaultParameterValue(0)] int res, [DefaultParameterValue(KEY_READ)] int sam) { HKEYType rootKey = GetRootKey(key); RegistryKey newKey = null; // I'm assuming that the masks that CPy uses are the same as the Win32 API one mentioned here- // http://msdn2.microsoft.com/en-us/library/ms724878(VS.85).aspx // KEY_WRITE is a combination of KEY_SET_VALUE and KEY_CREATE_SUB_KEY. We'll open with write access // if any of this is set. // KEY_READ is a combination of KEY_QUERY_VALUE, KEY_ENUMERATE_SUB_KEYS and KEY_NOTIFY. We'll open // with read access for all of these. var nativeRootKey = rootKey.GetKey(); try { if ((sam & KEY_SET_VALUE) == KEY_SET_VALUE || (sam & KEY_CREATE_SUB_KEY) == KEY_CREATE_SUB_KEY) { if (res != 0) { #if NETSTANDARD newKey = nativeRootKey.OpenSubKey(subKeyName, (RegistryRights)res); #else newKey = nativeRootKey.OpenSubKey(subKeyName, RegistryKeyPermissionCheck.Default, (RegistryRights)res); #endif } else { newKey = nativeRootKey.OpenSubKey(subKeyName, true); } } else if ((sam & KEY_QUERY_VALUE) == KEY_QUERY_VALUE || (sam & KEY_ENUMERATE_SUB_KEYS) == KEY_ENUMERATE_SUB_KEYS || (sam & KEY_NOTIFY) == KEY_NOTIFY) { if (res != 0) { #if NETSTANDARD newKey = nativeRootKey.OpenSubKey(subKeyName, (RegistryRights)res); #else newKey = nativeRootKey.OpenSubKey(subKeyName, RegistryKeyPermissionCheck.ReadSubTree, (RegistryRights)res); #endif } else { newKey = nativeRootKey.OpenSubKey(subKeyName, false); } } else { throw new Win32Exception("Unexpected mode"); } } catch (SecurityException) { throw PythonExceptions.CreateThrowable(PythonExceptions.WindowsError, PythonExceptions._WindowsError.ERROR_ACCESS_DENIED, "Access is denied"); } if (newKey == null) { throw PythonExceptions.CreateThrowable(PythonExceptions.WindowsError, PythonExceptions._WindowsError.ERROR_FILE_NOT_FOUND, "The system cannot find the file specified"); } return(new HKEYType(newKey)); }
private static Exception WindowsError(int code) { return(PythonExceptions.CreateThrowable(PythonExceptions.OSError, code, FormatError(code))); }
private static void AddFilename(CodeContext context, string name, Exception ioe) { var pyExcep = PythonExceptions.ToPython(ioe); PythonOps.SetAttr(context, pyExcep, "filename", name); }
private static Exception ErrorDecoding(CodeContext context, params object[] args) { return(PythonExceptions.CreateThrowable(SSLError(context), ArrayUtils.Insert("Error decoding PEM-encoded file ", args))); }
private static Exception Error(CodeContext /*!*/ context, params object[] args) { return(PythonExceptions.CreateThrowable((PythonType)PythonContext.GetContext(context).GetModuleState(_ErrorKey), args)); }
public static void warn_explicit(CodeContext context, object message, PythonType category, string filename, int lineno, string module = null, PythonDictionary registry = null, object module_globals = null) { PythonContext pContext = context.LanguageContext; PythonDictionary fields = (PythonDictionary)pContext.GetModuleState(_keyFields); object warnings = pContext.GetWarningsModule(); PythonExceptions.BaseException msg; string text; // message text if (string.IsNullOrEmpty(module)) { module = (filename == null || filename == "") ? "<unknown>" : filename; if (module.EndsWith(".py")) { module = module.Substring(0, module.Length - 3); } } if (registry == null) { registry = new PythonDictionary(); } if (PythonOps.IsInstance(message, PythonExceptions.Warning)) { msg = (PythonExceptions.BaseException)message; text = msg.ToString(); category = DynamicHelpers.GetPythonType(msg); } else { text = message.ToString(); msg = PythonExceptions.CreatePythonThrowable(category, message.ToString()); } PythonTuple key = PythonTuple.MakeTuple(text, category, lineno); if (registry.ContainsKey(key)) { return; } string action = Converter.ConvertToString(fields[_keyDefaultAction]); PythonTuple last_filter = null; bool loop_break = false; List filters = (List)fields[_keyFilters]; if (warnings != null) { filters = PythonOps.GetBoundAttr(context, warnings, "filters") as List; if (filters == null) { throw PythonOps.ValueError("_warnings.filters must be a list"); } } foreach (PythonTuple filter in filters) { last_filter = filter; action = (string)filter._data[0]; PythonRegex.RE_Pattern fMsg = (PythonRegex.RE_Pattern)filter._data[1]; PythonType fCat = (PythonType)filter._data[2]; PythonRegex.RE_Pattern fMod = (PythonRegex.RE_Pattern)filter._data[3]; int fLno; if (filter._data[4] is int) { fLno = (int)filter._data[4]; } else { fLno = (Extensible <int>)filter._data[4]; } if ((fMsg == null || fMsg.match(text) != null) && category.IsSubclassOf(fCat) && (fMod == null || fMod.match(module) != null) && (fLno == 0 || fLno == lineno)) { loop_break = true; break; } } if (!loop_break) { action = Converter.ConvertToString(fields[_keyDefaultAction]); } switch (action) { case "ignore": registry.Add(key, 1); return; case "error": throw msg.GetClrException(); case "once": registry.Add(key, 1); PythonTuple onceKey = PythonTuple.MakeTuple(text, category); PythonDictionary once_reg = (PythonDictionary)fields[_keyOnceRegistry]; if (once_reg.ContainsKey(onceKey)) { return; } once_reg.Add(key, 1); break; case "always": break; case "module": registry.Add(key, 1); PythonTuple altKey = PythonTuple.MakeTuple(text, category, 0); if (registry.ContainsKey(altKey)) { return; } registry.Add(altKey, 1); break; case "default": registry.Add(key, 1); break; default: throw PythonOps.RuntimeError("Unrecognized action ({0}) in warnings.filters:\n {1}", action, last_filter); } if (warnings != null) { object show_fxn = PythonOps.GetBoundAttr(context, warnings, "showwarning"); if (show_fxn != null) { PythonCalls.Call( context, show_fxn, msg, category, filename, lineno, null, null); } else { showwarning(context, msg, category, filename, lineno, null, null); } } else { showwarning(context, msg, category, filename, lineno, null, null); } }
private void ValidationError(object reason) { _validationFailure = PythonExceptions.CreateThrowable(PythonSsl.SSLError(_context), "errors while validating certificate chain: ", reason.ToString()); }