本文整理汇总了C#中PythonLanguageVersion类的典型用法代码示例。如果您正苦于以下问题:C# PythonLanguageVersion类的具体用法?C# PythonLanguageVersion怎么用?C# PythonLanguageVersion使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PythonLanguageVersion类属于命名空间,在下文中一共展示了PythonLanguageVersion类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetCPythonVersion
private static PythonVersion GetCPythonVersion(PythonLanguageVersion version) {
foreach (var baseKey in new[] { Registry.LocalMachine, Registry.CurrentUser }) {
using (var python = baseKey.OpenSubKey(PythonCorePath)) {
var res = TryGetCPythonPath(version, python);
if (res != null) {
return res;
}
}
}
if (Environment.Is64BitOperatingSystem) {
foreach (var baseHive in new[] { RegistryHive.LocalMachine, RegistryHive.CurrentUser }) {
var python64 = RegistryKey.OpenBaseKey(baseHive, RegistryView.Registry64).OpenSubKey(PythonCorePath);
var res = TryGetCPythonPath(version, python64);
if (res != null) {
return res;
}
}
}
var path = "C:\\Python" + version.ToString().Substring(1) + "\\python.exe";
var arch = Microsoft.PythonTools.Analysis.NativeMethods.GetBinaryType(path);
if (arch == ProcessorArchitecture.X86) {
return new PythonVersion(path, version, CPythonGuid);
} else if (arch == ProcessorArchitecture.Amd64) {
return new PythonVersion(path, version, CPython64Guid);
} else {
return null;
}
}
示例2: ConvertCoveragePy
private void ConvertCoveragePy(string inputFile, string outputFile, PythonLanguageVersion? version) {
var baseDir = Path.GetDirectoryName(inputFile);
using (FileStream tmp = new FileStream(inputFile, FileMode.Open))
using (FileStream outp = new FileStream(outputFile, FileMode.Create)) {
// Read in the data from coverage.py's XML file
CoverageFileInfo[] fileInfo = new CoveragePyConverter(baseDir, tmp).Parse();
// Discover what version we should use for this if one hasn't been provided...
if (version == null) {
foreach (var file in fileInfo) {
var project = _serviceProvider.GetProjectFromFile(file.Filename);
if (project != null) {
version = project.ActiveInterpreter.Configuration.Version.ToLanguageVersion();
break;
}
}
}
if (version == null) {
var interpreters = _serviceProvider.GetComponentModel().GetService<IInterpreterOptionsService>();
version = interpreters?.DefaultInterpreter.Configuration.Version.ToLanguageVersion()
?? PythonLanguageVersion.None;
}
// Convert that into offsets within the actual code
var covInfo = Import(fileInfo, version.Value);
// Then export as .coveragexml
new CoverageExporter(outp, covInfo).Export();
}
}
示例3: Expression
/// <summary>
/// Returns a sequence of all keywords usable in an expression in a
/// particular version of Python.
/// </summary>
public static IEnumerable<string> Expression(PythonLanguageVersion version = PythonLanguageVersion.None) {
yield return "and";
yield return "as";
if (version.IsNone() || version >= PythonLanguageVersion.V35) {
yield return "await";
}
yield return "else";
if (version.IsNone() || version.Is3x()) {
yield return "False";
}
yield return "for";
if (version.IsNone() || version >= PythonLanguageVersion.V33) {
yield return "from";
}
yield return "if";
yield return "in";
yield return "is";
yield return "lambda";
yield return "None";
yield return "not";
yield return "or";
if (version.IsNone() || version.Is3x()) {
yield return "True";
}
yield return "yield";
}
示例4: IsOnlyStatementKeyword
/// <summary>
/// Returns true if the specified identifier is a statement keyword and
/// never an expression in a particular version of Python.
/// </summary>
public static bool IsOnlyStatementKeyword(
string keyword,
PythonLanguageVersion version = PythonLanguageVersion.None
) {
return Statement(version)
.Except(Expression(version))
.Contains(keyword, StringComparer.Ordinal);
}
示例5: PythonAst
public PythonAst(Statement body, int[] lineLocations, PythonLanguageVersion langVersion) {
if (body == null) {
throw new ArgumentNullException("body");
}
_langVersion = langVersion;
_body = body;
_lineLocations = lineLocations;
}
示例6: RenameVariableRequestView
/// <summary>
/// Create a RenameVariableRequestView with default values.
/// </summary>
public RenameVariableRequestView(string originalName, PythonLanguageVersion languageVersion) {
_originalName = originalName;
_languageVersion = languageVersion;
//_name = null;
// Access properties rather than underlying variables to ensure dependent properties
// are also updated.
Name = _originalName;
_previewChanges = true;
}
示例7: PythonClassifier
private static Dictionary<PythonLanguageVersion, Tokenizer> _tokenizers; // tokenizer for each version, shared between all buffers
internal PythonClassifier(PythonClassifierProvider provider, ITextBuffer buffer) {
buffer.Changed += BufferChanged;
buffer.ContentTypeChanged += BufferContentTypeChanged;
_tokenCache = new TokenCache();
_provider = provider;
_buffer = buffer;
var analyzer = _buffer.GetAnalyzer(provider._serviceProvider);
Debug.Assert(analyzer != null);
_version = analyzer.InterpreterFactory.GetLanguageVersion();
}
示例8: GetRenameInfo
public RenameVariableRequest GetRenameInfo(string originalName, PythonLanguageVersion languageVersion) {
var requestView = new RenameVariableRequestView(originalName, languageVersion);
LoadPreferences(requestView);
var dialog = new RenameVariableDialog(requestView);
bool res = dialog.ShowModal() ?? false;
if (res) {
SavePreferences(requestView);
return requestView.GetRequest();
}
return null;
}
示例9: TestOneFileMutated
private static void TestOneFileMutated(string filename, PythonLanguageVersion version, Random random) {
var originalText = File.ReadAllText(filename);
int start = random.Next(originalText.Length);
int end = random.Next(originalText.Length);
int realStart = Math.Min(start, end);
int length = Math.Max(start, end) - Math.Min(start, end);
//Console.WriteLine("Removing {1} chars at {0}", realStart, length);
originalText = originalText.Substring(realStart, length);
ParserRoundTripTest.TestOneString(version, originalText);
}
示例10: FromStream
public static IPythonModule FromStream(
IPythonInterpreter interpreter,
Stream sourceFile,
string fileName,
PythonLanguageVersion langVersion
) {
PythonAst ast;
using (var parser = Parser.CreateParser(sourceFile, langVersion)) {
ast = parser.ParseFile();
}
return new AstPythonModule(interpreter, ast, fileName);
}
示例11: PythonProcess
private PythonProcess(int pid, PythonDebugOptions debugOptions) {
_pid = pid;
_process = Process.GetProcessById(pid);
_process.EnableRaisingEvents = true;
_process.Exited += new EventHandler(_process_Exited);
ListenForConnection();
using (var result = DebugAttach.AttachAD7(pid, DebugConnectionListener.ListenerPort, _processGuid, debugOptions.ToString())) {
if (result.Error != ConnErrorMessages.None) {
throw new ConnectionException(result.Error);
}
_langVersion = (PythonLanguageVersion)result.LanguageVersion;
if (!result.AttachDone.WaitOne(20000)) {
throw new ConnectionException(ConnErrorMessages.TimeOut);
}
}
}
示例12: Parser
private Parser(Tokenizer tokenizer, ErrorSink errorSink, PythonLanguageVersion langVersion, bool verbatim, bool bindRefs, string privatePrefix) {
Contract.Assert(tokenizer != null);
Contract.Assert(errorSink != null);
tokenizer.ErrorSink = new TokenizerErrorSink(this);
_tokenizer = tokenizer;
_errors = errorSink;
_langVersion = langVersion;
_verbatim = verbatim;
_bindReferences = bindRefs;
if (langVersion.Is3x()) {
// 3.x always does true division and absolute import
_languageFeatures |= FutureOptions.TrueDivision | FutureOptions.AbsoluteImports;
}
Reset(FutureOptions.None);
_privatePrefix = privatePrefix;
}
示例13: AttachRepl
public static PythonProcess AttachRepl(Stream stream, int pid, PythonLanguageVersion version, PythonDebugOptions debugOptions = PythonDebugOptions.None) {
return new PythonProcess(stream, pid, version, debugOptions);
}
示例14: PythonRemoteProcess
private PythonRemoteProcess(int pid, Uri uri, PythonLanguageVersion langVer)
: base(pid, langVer) {
Uri = uri;
ParseQueryString();
}
示例15: TestOneString
internal static void TestOneString(PythonLanguageVersion version, string originalText, CodeFormattingOptions format = null, string expected = null, bool recurse = true) {
bool hadExpected = true;
if (expected == null) {
expected = originalText;
hadExpected = false;
}
var parser = Parser.CreateParser(new StringReader(originalText), version, new ParserOptions() { Verbatim = true });
var ast = parser.ParseFile();
string output;
try {
if (format == null) {
output = ast.ToCodeString(ast);
} else {
output = ast.ToCodeString(ast, format);
}
} catch(Exception e) {
Console.WriteLine("Failed to convert to code: {0}\r\n{1}", originalText, e);
Assert.Fail();
return;
}
const int contextSize = 50;
for (int i = 0; i < expected.Length && i < output.Length; i++) {
if (expected[i] != output[i]) {
// output some context
StringBuilder x = new StringBuilder();
StringBuilder y = new StringBuilder();
StringBuilder z = new StringBuilder();
for (int j = Math.Max(0, i - contextSize); j < Math.Min(Math.Max(expected.Length, output.Length), i + contextSize); j++) {
if (j < expected.Length) {
x.AppendRepr(expected[j]);
}
if (j < output.Length) {
y.AppendRepr(output[j]);
}
if (j == i) {
z.Append("^");
} else {
z.Append(" ");
}
}
Console.WriteLine("Mismatch context at {0}:", i);
Console.WriteLine("Expected: {0}", x.ToString());
Console.WriteLine("Got : {0}", y.ToString());
Console.WriteLine("Differs : {0}", z.ToString());
if (recurse) {
// Try and automatically get a minimal repro if we can...
if (!hadExpected) {
try {
for (int j = i; j >= 0; j--) {
TestOneString(version, originalText.Substring(j), format, null, false);
}
} catch {
}
}
} else {
Console.WriteLine("-----");
Console.WriteLine(expected);
Console.WriteLine("-----");
}
Assert.AreEqual(expected[i], output[i], String.Format("Characters differ at {0}, got {1}, expected {2}", i, output[i], expected[i]));
}
}
if (expected.Length != output.Length) {
Console.WriteLine("Original: {0}", expected.ToString());
Console.WriteLine("New : {0}", output.ToString());
}
Assert.AreEqual(expected.Length, output.Length);
}