Skip to content
This repository has been archived by the owner on Sep 14, 2018. It is now read-only.

Commit

Permalink
Updates for .NET Core (#1465)
Browse files Browse the repository at this point in the history
* Updates for .NET Core

* Get more tests passing on .NET Core
  • Loading branch information
slozier authored and slide committed Oct 14, 2016
1 parent f2ef516 commit 473fc03
Show file tree
Hide file tree
Showing 32 changed files with 192 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,8 @@ class pywintypes:
elif mono:
_has_poll = False
import clr
if clr.IsNetStandard:
clr.AddReference("System.Diagnostics.Process")
from System.Diagnostics import Process
from System.IO import MemoryStream
else:
Expand Down
23 changes: 19 additions & 4 deletions Languages/IronPython/IronPython.Modules/_sha256.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@ namespace IronPython.Modules {
public static class PythonSha256 {
[ThreadStatic]
private static SHA256 _hasher256;

#if !NETSTANDARD
[ThreadStatic]
private static SHA224 _hasher224;
#endif

private const int blockSize = 64;

Expand All @@ -52,12 +55,14 @@ private static SHA256 GetHasherSHA256() {
return _hasher256;
}

# if !NETSTANDARD
private static SHA224 GetHasherSHA224() {
if (_hasher224 == null) {
_hasher224 = new SHA224();
}
return _hasher224;
}
#endif

public static Sha256Object sha256(object data) {
return new Sha256Object(data);
Expand Down Expand Up @@ -119,7 +124,16 @@ object ICloneable.Clone() {
public const int digestsize = 32;
public const string name = "SHA256";
}


#if NETSTANDARD
public static Sha256Object sha224(object data) {
throw new NotImplementedException();
}

public static Sha256Object sha224() {
throw new NotImplementedException();
}
#else
public static Sha224Object sha224(object data) {
return new Sha224Object(data);
}
Expand Down Expand Up @@ -180,10 +194,10 @@ object ICloneable.Clone() {
public const int digestsize = 28;
public const string name = "SHA224";
}
#endif
}



#if !NETSTANDARD
[PythonHidden]
public class SHA224 : HashAlgorithm {
private const int BLOCK_SIZE_BYTES = 64;
Expand Down Expand Up @@ -402,7 +416,8 @@ private uint Sig1(uint x) {
^ ((x >> 11) | (x << 21))
^ ((x >> 25) | (x << 7));
}
}
}
#endif

public class HashBase {
internal byte[] _bytes;
Expand Down
11 changes: 8 additions & 3 deletions Languages/IronPython/IronPython.Modules/_ssl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,11 @@ public static List enum_certificates(string store_name) {

} finally {
if(store != null) {
#if NETSTANDARD
store.Dispose();
#else
store.Close();
#endif
}
}
return new List();
Expand All @@ -339,7 +343,11 @@ public static List enum_crls(string store_name) {

} finally {
if (store != null) {
#if NETSTANDARD
store.Dispose();
#else
store.Close();
#endif
}
}
return new List();
Expand Down Expand Up @@ -735,9 +743,6 @@ private static Exception ErrorDecoding(CodeContext context, params object[] args
private const int SSL_VERIFY_FAIL_IF_NO_PEER_CERT = 0x02;
private const int SSL_VERIFY_CLIENT_ONCE = 0x04;




#endregion
}
}
Expand Down
4 changes: 2 additions & 2 deletions Languages/IronPython/IronPython.Modules/nt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
using Microsoft.Scripting.Math;
#endif

#if NETSTANDARD1_6
#if NETCOREAPP1_0
using Environment = System.FakeEnvironment;
#endif

Expand Down Expand Up @@ -1791,7 +1791,7 @@ private static bool TryGetExecutableCommand(string command, out string baseComma
return true;
}

#if !NETSTANDARD1_6
#if !NETCOREAPP1_0
// TODO: need revisit
string sysdir = System.Environment.GetFolderPath(System.Environment.SpecialFolder.System);
foreach (string suffix in new string[] { string.Empty, ".com", ".exe", "cmd", ".bat" }) {
Expand Down
2 changes: 1 addition & 1 deletion Languages/IronPython/IronPython.Modules/signal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
using Microsoft.Scripting.Runtime;
using Microsoft.Scripting.Utils;

#if NETSTANDARD1_6
#if NETCOREAPP1_0
using Environment = System.FakeEnvironment;
#endif

Expand Down
21 changes: 14 additions & 7 deletions Languages/IronPython/IronPython.Modules/socket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
using SpecialNameAttribute = System.Runtime.CompilerServices.SpecialNameAttribute;
using Microsoft.Scripting.Utils;

#if NETSTANDARD1_6
#if NETCOREAPP1_0
using Environment = System.FakeEnvironment;
#endif

Expand Down Expand Up @@ -2660,16 +2660,23 @@ internal bool CertValidationCallbackRequired(object sender, X509Certificate cert

private void ValidateCertificate(X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) {
chain = new X509Chain();
#if NETSTANDARD
// missing the X509Certificate2.ctor(X509Certificate) in .NET Core 1.0
chain.ChainPolicy.ExtraStore.AddRange(_certCollection);
chain.Build((X509Certificate2)certificate);
#else
X509Certificate2Collection certificates = new X509Certificate2Collection();
foreach(object cert in _certCollection) {
if(cert is X509Certificate) {
certificates.Add(new X509Certificate2((X509Certificate)cert));
} else if(cert is X509Certificate2) {
foreach (object cert in _certCollection) {
if (cert is X509Certificate2) {
certificates.Add((X509Certificate2)cert);
}
else if (cert is X509Certificate) {
certificates.Add(new X509Certificate2((X509Certificate)cert));
}
}
chain.ChainPolicy.ExtraStore.AddRange(certificates);
chain.Build(new X509Certificate2(certificate));
#endif
if (chain.ChainStatus.Length > 0) {
foreach (var elem in chain.ChainStatus) {
if (elem.Status == X509ChainStatusFlags.UntrustedRoot) {
Expand Down Expand Up @@ -2711,7 +2718,7 @@ public void do_handshake() {
try {
if (_serverSide) {
#if NETSTANDARD
_sslStream.AuthenticateAsServerAsync(_cert, _certsMode == PythonSsl.CERT_REQUIRED, SslProtocols.Default, false).Wait();
_sslStream.AuthenticateAsServerAsync(_cert, _certsMode == PythonSsl.CERT_REQUIRED, SslProtocols.Tls12 | SslProtocols.Tls11 | SslProtocols.Tls, false).Wait();
#else
_sslStream.AuthenticateAsServer(_cert, _certsMode == PythonSsl.CERT_REQUIRED, SslProtocols.Default, false);
#endif
Expand All @@ -2723,7 +2730,7 @@ public void do_handshake() {
collection.Add(_cert);
}
#if NETSTANDARD
_sslStream.AuthenticateAsClientAsync(_socket._hostName, collection, SslProtocols.Default, false).Wait();
_sslStream.AuthenticateAsClientAsync(_socket._hostName, collection, SslProtocols.Tls12 | SslProtocols.Tls11 | SslProtocols.Tls, false).Wait();
#else
_sslStream.AuthenticateAsClient(_socket._hostName, collection, SslProtocols.Default, false);
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
using System.IO.IsolatedStorage;
#endif

#if NETSTANDARD1_6
#if NETCOREAPP1_0
using Environment = System.FakeEnvironment;
#endif

Expand Down
11 changes: 8 additions & 3 deletions Languages/IronPython/IronPython/Lib/iptest/test_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,20 @@
is_ironpython = is_silverlight or is_cli
is_cpython = sys.platform == 'win32' or sys.platform == 'posix'
is_posix = sys.platform == 'posix'
is_netstandard = False

if is_ironpython:
#We'll use System, if available, to figure out more info on the test
#environment later
import System
import clr
is_posix = sys.platform == 'posix' or System.Environment.OSVersion.Platform == System.PlatformID.Unix
is_netstandard = clr.IsNetStandard
if is_netstandard:
clr.AddReference("Microsoft.Scripting")
is_posix = System.FakeEnvironment.OSVersion.Platform == System.PlatformID.Unix
else:
is_posix = sys.platform == 'posix' or System.Environment.OSVersion.Platform == System.PlatformID.Unix

is_netstandard = is_ironpython and clr.IsNetStandard

#--The bittedness of the Python implementation
is_cli32, is_cli64 = False, False
Expand Down Expand Up @@ -109,7 +114,7 @@
is_vista = True

is_win7 = False
if is_ironpython: #TODO - what about CPython?
if is_ironpython and not is_posix: #TODO - what about CPython?
is_win7 = System.Environment.OSVersion.Version.Major==6 and System.Environment.OSVersion.Version.Minor==1

#------------------------------------------------------------------------------
2 changes: 1 addition & 1 deletion Languages/IronPython/IronPython/Modules/sys.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
using IronPython.Runtime.Types;
using Microsoft.Scripting.Utils;

#if NETSTANDARD1_6
#if NETCOREAPP1_0
using Environment = System.FakeEnvironment;
#endif

Expand Down
78 changes: 78 additions & 0 deletions Languages/IronPython/IronPython/Runtime/EncodingInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#if NETSTANDARD

namespace System.Text
{
using System;
using System.Text;


[Serializable]
public sealed class EncodingInfo
{
int iCodePage; // Code Page #
String strEncodingName; // Short name (web name)
String strDisplayName; // Full localized name

internal EncodingInfo(int codePage, string name, string displayName)
{
this.iCodePage = codePage;
this.strEncodingName = name;
this.strDisplayName = displayName;
}


public int CodePage
{
get
{
return iCodePage;
}
}


public String Name
{
get
{
return strEncodingName;
}
}


public String DisplayName
{
get
{
return strDisplayName;
}
}


public Encoding GetEncoding()
{
return Encoding.GetEncoding(this.iCodePage);
}

public override bool Equals(Object value)
{
EncodingInfo that = value as EncodingInfo;
if (that != null)
{
return (this.CodePage == that.CodePage);
}
return (false);
}

public override int GetHashCode()
{
return this.CodePage;
}

}
}

#endif
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if NETSTANDARD1_6
#if NETCOREAPP1_0

namespace System {
[Serializable]
Expand Down
2 changes: 1 addition & 1 deletion Languages/IronPython/IronPython/Runtime/PythonContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
using Debugging = Microsoft.Scripting.Debugging;
using PyAst = IronPython.Compiler.Ast;

#if NETSTANDARD1_6
#if NETCOREAPP1_0
using Environment = System.FakeEnvironment;
#endif

Expand Down
2 changes: 1 addition & 1 deletion Languages/IronPython/IronPython/Runtime/PythonFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
using Microsoft.Scripting.Math;
#endif

#if NETSTANDARD1_6
#if NETCOREAPP1_0
using Environment = System.FakeEnvironment;
#endif

Expand Down
Loading

0 comments on commit 473fc03

Please sign in to comment.