PageRenderTime 42ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/IronPython_2_0/Src/IronPythonConsole/Console.cs

#
C# | 76 lines | 46 code | 13 blank | 17 comment | 4 complexity | 5776adeb54477c2608af8d2c65bc2b4c MD5 | raw file
Possible License(s): GPL-2.0, MPL-2.0-no-copyleft-exception, CPL-1.0, CC-BY-SA-3.0, BSD-3-Clause, ISC, AGPL-3.0, LGPL-2.1, Apache-2.0
  1. /* ****************************************************************************
  2. *
  3. * Copyright (c) Microsoft Corporation.
  4. *
  5. * This source code is subject to terms and conditions of the Microsoft Public License. A
  6. * copy of the license can be found in the License.html file at the root of this distribution. If
  7. * you cannot locate the Microsoft Public License, please send an email to
  8. * ironpy@microsoft.com. By using this source code in any fashion, you are agreeing to be bound
  9. * by the terms of the Microsoft Public License.
  10. *
  11. * You must not remove this notice, or any other, from this software.
  12. *
  13. *
  14. * ***************************************************************************/
  15. using System; using Microsoft;
  16. using System.Text;
  17. using IronPython.Hosting;
  18. using IronPython.Runtime;
  19. using Microsoft.Scripting.Hosting;
  20. using Microsoft.Scripting.Hosting.Shell;
  21. using Microsoft.Scripting.Utils;
  22. using System.Diagnostics;
  23. using System.Reflection.Emit;
  24. internal sealed class PythonConsoleHost : ConsoleHost {
  25. protected override Type Provider {
  26. get { return typeof(PythonContext); }
  27. }
  28. protected override CommandLine/*!*/ CreateCommandLine() {
  29. return new PythonCommandLine();
  30. }
  31. protected override OptionsParser/*!*/ CreateOptionsParser() {
  32. return new PythonOptionsParser();
  33. }
  34. protected override LanguageSetup/*!*/ CreateLanguageSetup() {
  35. return Python.CreateLanguageSetup(null);
  36. }
  37. protected override string/*!*/ GetHelp() {
  38. StringBuilder sb = new StringBuilder();
  39. sb.AppendLine(PythonCommandLine.GetLogoDisplay());
  40. PrintLanguageHelp(sb);
  41. sb.AppendLine();
  42. return sb.ToString();
  43. }
  44. protected override void ParseHostOptions(string/*!*/[]/*!*/ args) {
  45. // Python doesn't want any of the DLR base options.
  46. foreach (string s in args) {
  47. Options.IgnoredArgs.Add(s);
  48. }
  49. }
  50. [STAThread]
  51. public static int Main(string[] args) {
  52. // Work around issue w/ pydoc - piping to more doesn't work so
  53. // instead indicate that we're a dumb terminal
  54. if (Environment.GetEnvironmentVariable("TERM") == null) {
  55. Environment.SetEnvironmentVariable("TERM", "dumb");
  56. }
  57. if (typeof(DynamicMethod).GetConstructor(new Type[] { typeof(string), typeof(Type), typeof(Type[]), typeof(bool) }) == null) {
  58. Console.WriteLine("IronPython requires .NET 2.0 SP1 or later to run.");
  59. Environment.Exit(1);
  60. }
  61. return new PythonConsoleHost().Run(args);
  62. }
  63. }