本文整理汇总了C#中PythonLanguageVersion类的典型用法代码示例。如果您正苦于以下问题:C# PythonLanguageVersion类的具体用法?C# PythonLanguageVersion怎么用?C# PythonLanguageVersion使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PythonLanguageVersion类属于命名空间,在下文中一共展示了PythonLanguageVersion类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
}
开发者ID:wenh123,项目名称:PTVS,代码行数:30,代码来源:PythonPaths.cs
示例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();
}
}
开发者ID:zooba,项目名称:PTVS,代码行数:31,代码来源:ImportCoverageCommand.cs
示例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";
}
开发者ID:omnimark,项目名称:PTVS,代码行数:30,代码来源:PythonKeywords.cs
示例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);
}
开发者ID:omnimark,项目名称:PTVS,代码行数:12,代码来源:PythonKeywords.cs
示例5: PythonAst
public PythonAst(Statement body, int[] lineLocations, PythonLanguageVersion langVersion) {
if (body == null) {
throw new ArgumentNullException("body");
}
_langVersion = langVersion;
_body = body;
_lineLocations = lineLocations;
}
开发者ID:omnimark,项目名称:PTVS,代码行数:8,代码来源:PythonAst.cs
示例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;
}
开发者ID:omnimark,项目名称:PTVS,代码行数:13,代码来源:RenameVariableRequestView.cs
示例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();
}
开发者ID:wenh123,项目名称:PTVS,代码行数:14,代码来源:PythonClassifier.cs
示例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;
}
开发者ID:wenh123,项目名称:PTVS,代码行数:12,代码来源:RenameVariableUserInput.cs
示例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);
}
开发者ID:RussBaz,项目名称:PTVS,代码行数:12,代码来源:MutateStdLibTest.cs
示例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);
}
开发者ID:jsschultz,项目名称:PTVS,代码行数:13,代码来源:AstPythonModule.cs
示例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);
}
}
}
开发者ID:KevinH-MS,项目名称:PTVS,代码行数:19,代码来源:PythonProcess.cs
示例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;
}
开发者ID:omnimark,项目名称:PTVS,代码行数:21,代码来源:Parser.cs
示例13: AttachRepl
public static PythonProcess AttachRepl(Stream stream, int pid, PythonLanguageVersion version, PythonDebugOptions debugOptions = PythonDebugOptions.None) {
return new PythonProcess(stream, pid, version, debugOptions);
}
开发者ID:KevinH-MS,项目名称:PTVS,代码行数:3,代码来源:PythonProcess.cs
示例14: PythonRemoteProcess
private PythonRemoteProcess(int pid, Uri uri, PythonLanguageVersion langVer)
: base(pid, langVer) {
Uri = uri;
ParseQueryString();
}
开发者ID:omnimark,项目名称:PTVS,代码行数:5,代码来源:PythonRemoteProcess.cs
示例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);
}
开发者ID:sadapple,项目名称:PTVS,代码行数:74,代码来源:ParserRoundTripTest.cs
示例16: TestOneFile
private static void TestOneFile(string filename, PythonLanguageVersion version) {
var originalText = File.ReadAllText(filename);
TestOneString(version, originalText);
}
开发者ID:sadapple,项目名称:PTVS,代码行数:5,代码来源:ParserRoundTripTest.cs
示例17: GetAssignments
private string[] GetAssignments(string testCase, PythonLanguageVersion version) {
var ast = Parser.CreateParser(new StringReader(testCase), version).ParseFile();
var walker = new TestAssignmentWalker();
ast.Walk(walker);
return walker._names.ToArray();
}
开发者ID:RussBaz,项目名称:PTVS,代码行数:6,代码来源:ExtractMethodTests.cs
示例18: Parse
public static void Parse(this IPythonProjectEntry entry, PythonLanguageVersion version, string code) {
using (var parser = Parser.CreateParser(new StringReader(code), version)) {
entry.UpdateTree(parser.ParseFile(), null);
}
}
开发者ID:omnimark,项目名称:PTVS,代码行数:5,代码来源:PythonTestExtensions.cs
示例19: StartCrossThreadAnalysisCalls
private IEnumerable<Task> StartCrossThreadAnalysisCalls(
CancellationToken cancel,
PythonLanguageVersion version
) {
var fact = InterpreterFactoryCreator.CreateAnalysisInterpreterFactory(version.ToVersion());
var state = PythonAnalyzer.CreateSynchronously(fact);
const string testCode = @"from mod{0:000} import test_func as other_test_func, MyClass as other_mc
c = None
def test_func(a, b={1}()):
'''My test function'''
globals c
a = b
a = {1}(a)
b = other_test_func(a)
c = other_mc.fn(b)
return b
class MyClass:
fn = test_func
my_test_func = test_func
my_test_func = other_test_func
my_test_func('abc')
mc = MyClass()
mc.fn([])
";
var entries = Enumerable.Range(0, 100)
.Select(i => {
var entry = state.AddModule(string.Format("mod{0:000}", i), string.Format("mod{0:000}.py", i));
entry.ParseFormat(PythonLanguageVersion.V34, testCode, i + 1, PythonTypes[i % PythonTypes.Count]);
return entry;
})
.ToList();
// One analysis before we start
foreach (var e in entries) {
e.Analyze(cancel, true);
}
state.AnalyzeQueuedEntries(cancel);
// Repeatedly re-analyse the code
yield return Task.Run(() => {
var rnd = new Random();
while (!cancel.IsCancellationRequested) {
var shufEntries = entries
.Select(e => Tuple.Create(rnd.Next(), e))
.OrderBy(t => t.Item1)
.Take(entries.Count / 2)
.Select(t => t.Item2)
.ToList();
foreach (var e in shufEntries) {
e.Analyze(cancel, true);
}
state.AnalyzeQueuedEntries(cancel);
Console.WriteLine("Analysis complete");
Thread.Sleep(1000);
}
}, cancel);
// Repeatedly re-parse the code
yield return Task.Run(() => {
var rnd = new Random();
while (!cancel.IsCancellationRequested) {
var shufEntries = entries
.Select((e, i) => Tuple.Create(rnd.Next(), e, i))
.OrderBy(t => t.Item1)
.Take(entries.Count / 4)
.ToList();
foreach (var t in shufEntries) {
var i = t.Item3;
t.Item2.ParseFormat(PythonLanguageVersion.V34, testCode, i + 1, PythonTypes[i % PythonTypes.Count]);
}
Thread.Sleep(1000);
}
}, cancel);
// Repeatedly request signatures
yield return Task.Run(() => {
var entry = entries[1];
while (!cancel.IsCancellationRequested) {
var sigs = entry.Analysis.GetSignaturesByIndex("my_test_func", 0).ToList();
if (sigs.Any()) {
AssertUtil.ContainsExactly(
sigs.Select(s => s.Name),
"test_func"
);
foreach (var s in sigs) {
AssertUtil.ContainsExactly(s.Parameters.Select(p => p.Name), "a", "b");
}
}
}
}, cancel);
//.........这里部分代码省略.........
开发者ID:RussBaz,项目名称:PTVS,代码行数:101,代码来源:ThreadingTest.cs
示例20: CreateParser
public static Parser CreateParser(TextReader reader, PythonLanguageVersion version, ParserOptions parserOptions) {
if (reader == null) {
throw new ArgumentNullException("reader");
}
var options = parserOptions ?? ParserOptions.Default;
Parser parser = null;
var tokenizer = new Tokenizer(
version, options.ErrorSink,
(options.Verbatim ? TokenizerOptions.Verbatim : TokenizerOptions.None) | TokenizerOptions.GroupingRecovery,
(span, text) => options.RaiseProcessComment(parser, new CommentEventArgs(span, text)));
tokenizer.Initialize(null, reader, SourceLocation.MinValue);
tokenizer.IndentationInconsistencySeverity = options.IndentationInconsistencySeverity;
parser = new Parser(
tokenizer,
options.ErrorSink ?? ErrorSink.Null,
version,
options.Verbatim,
options.BindReferences,
options.PrivatePrefix
) { _sourceReader = reader };
return parser;
}
开发者ID:omnimark,项目名称:PTVS,代码行数:25,代码来源:Parser.cs
注:本文中的PythonLanguageVersion类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论