Repository navigation
Expand file tree
/
Copy pathImplementation.cs
More file actions
99 lines (85 loc) · 3.45 KB
/
Copy pathImplementation.cs
File metadata and controls
99 lines (85 loc) · 3.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
using System.Linq;
using IronPython.Runtime.Operations;
namespace IronPython.Runtime {
[PythonHidden, PythonType("sys.implementation")]
public class Implementation {
internal static readonly string _Name = "IronPython";
internal static readonly string _name = _Name.ToLowerInvariant();
internal static readonly VersionInfo _version = new VersionInfo();
internal static readonly int _hexversion = _version.GetHexVersion();
public readonly string cache_tag = null;
public readonly string name = _name;
public readonly VersionInfo version = _version;
public readonly int hexversion = _hexversion;
public string __repr__(CodeContext context) {
var attrs = from attr in PythonOps.GetAttrNames(context, this)
where !attr.ToString().StartsWith("_")
select string.Format("{0}={1}",
attr,
PythonOps.Repr(context, PythonOps.GetBoundAttr(context, this, attr.ToString()))
);
return string.Format("{0}({1})",
PythonOps.GetPythonTypeName(this),
string.Join(",", attrs.ToArray())
);
}
}
[PythonType("sys.version_info")]
public class VersionInfo : PythonTuple {
public readonly int major;
public readonly int minor;
public readonly int micro;
public readonly string releaselevel;
public readonly int serial;
private VersionInfo(int major, int minor, int micro, string releaselevel, int serial)
: base(new object[] { major, minor, micro, releaselevel, serial }) {
this.major = major;
this.minor = minor;
this.micro = micro;
this.releaselevel = releaselevel;
this.serial = serial;
}
internal VersionInfo()
: this(CurrentVersion.Major,
CurrentVersion.Minor,
CurrentVersion.Micro,
CurrentVersion.ReleaseLevel,
CurrentVersion.ReleaseSerial) {}
public override string __repr__(CodeContext context) {
return string.Format("sys.version_info(major={0}, minor={1}, micro={2}, releaselevel='{3}', serial={4})",
major, minor, micro, releaselevel, serial);
}
internal int GetHexVersion() {
int hexlevel = 0;
switch(releaselevel) {
case "alpha":
hexlevel = 0xA;
break;
case "beta":
hexlevel = 0xB;
break;
case "candidate":
hexlevel = 0xC;
break;
case "final":
hexlevel = 0xF;
break;
}
return (major << 24) |
(minor << 16) |
(micro << 8) |
(hexlevel << 4) |
(serial << 0);
}
internal string GetVersionString(string _initialVersionString) {
var version = string.Format("{0}.{1}.{2}{4}{5} ({3})",
major,
minor,
micro,
_initialVersionString,
releaselevel != "final" ? CurrentVersion.ShortReleaseLevel : "",
releaselevel != "final" ? serial.ToString() : "");
return version;
}
}
}