Exemplo n.º 1
0
        internal static void showwarning(CodeContext context, object message, PythonType category, string filename, int lineno, object file = null, string line = null)
        {
            string text = formatwarning(message, category, filename, lineno, line);

            try {
                if (file == null)
                {
                    PythonContext pContext = context.LanguageContext;
                    PythonFile    stderr   = pContext.GetSystemStateValue("stderr") as PythonFile;
                    if (stderr != null)
                    {
                        stderr.write(text);
                    }
                    else
                    {
                        // use CLR stderr if python's is unavailable
                        Console.Error.Write(text);
                    }
                }
                else
                {
                    if (file is PythonFile)
                    {
                        ((PythonFile)file).write(text);
                    }
                    else if (file is TextWriter)
                    {
                        ((TextWriter)file).Write(text);
                    } // unrecognized file type - warning is lost
                }
            } catch (IOException) {
                // invalid file - warning is lost
            }
        }
Exemplo n.º 2
0
        public static void dump(object value, PythonFile /*!*/ file, int version)
        {
            if (file == null)
            {
                throw PythonOps.TypeError("expected file, found None");
            }

            file.write(dumps(value, version));
        }
Exemplo n.º 3
0
        static void ret_LogEntryAdded(PythonFile file, object sender, Logger.LogEntryAddedEventArgs e)
        {
            string text = e.LogEntry.Text;

            if (e.LogEntry.ExceptionObject != null)
            {
                text = e.LogEntry.ExceptionObject.ToString();
            }

            file.write(String.Format("[{0}] {1} {2}: {3}\n", e.LogEntry.EntryType, e.LogEntry.Timestamp, e.LogEntry.SourceName, text));
        }
Exemplo n.º 4
0
 IC_PyFile_WriteString(string s, IntPtr filePtr)
 {
     try
     {
         PythonFile file = (PythonFile)this.Retrieve(filePtr);
         file.write(s);
         return(0);
     }
     catch (Exception e)
     {
         this.LastException = e;
         return(-1);
     }
 }
Exemplo n.º 5
0
 IC_PyFile_WriteObject(IntPtr objPtr, IntPtr filePtr, int use_str)
 {
     try
     {
         object obj = this.Retrieve(objPtr);
         string s;
         if (use_str % 2 == 1)
         {
             s = (string)PythonCalls.Call(Builtin.str, new object[] { obj });
         }
         else
         {
             s = (string)Builtin.repr(this.scratchContext, obj);
         }
         PythonFile file = (PythonFile)this.Retrieve(filePtr);
         file.write(s);
         return(0);
     }
     catch (Exception e)
     {
         this.LastException = e;
         return(-1);
     }
 }