Permalink
Browse files

Merge pull request #1 from IronLanguages/master

Sync with ironlanguages-main
  • Loading branch information...
2 parents 9cc3a68 + 86ecdd1 commit 3456c1de2ee94513d562e013d488af391f525702 @gglresearchanddevelopment committed Dec 17, 2015
Showing with 2,529 additions and 1,172 deletions.
  1. +1 −1 External.LCA_RESTRICTED/Languages/IronPython/27/Lib/pdb.py
  2. +27 −0 External.LCA_RESTRICTED/Languages/IronPython/27/Lib/test/test_pdb.py
  3. +0 −6 External.LCA_RESTRICTED/Languages/IronPython/27/Lib/test/test_zipimport.py
  4. +11 −1 Languages/IronPython/IronPython.Modules/ModuleOps.cs
  5. +2 −1 Languages/IronPython/IronPython.Modules/_codecs.cs
  6. +3 −2 Languages/IronPython/IronPython.Modules/_csv.cs
  7. +16 −8 Languages/IronPython/IronPython.Modules/_struct.cs
  8. +8 −7 Languages/IronPython/IronPython.Modules/_subprocess.cs
  9. +41 −38 Languages/IronPython/IronPython.Modules/datetime.cs
  10. +3 −1 Languages/IronPython/IronPython.Modules/mmap.cs
  11. +19 −9 Languages/IronPython/IronPython.Modules/nt.cs
  12. +1 −1 Languages/IronPython/IronPython.Modules/thread.cs
  13. +41 −17 Languages/IronPython/IronPython.Modules/time.cs
  14. +2 −2 Languages/IronPython/IronPython.Modules/zipimport.cs
  15. +3 −0 Languages/IronPython/IronPython/Compiler/Ast/MemberExpression.cs
  16. +2 −0 Languages/IronPython/IronPython/Compiler/Parser.cs
  17. +424 −424 Languages/IronPython/IronPython/Resources.Designer.cs
  18. +1 −1 Languages/IronPython/IronPython/Resources.resx
  19. +2 −2 Languages/IronPython/IronPython/Runtime/Binding/PythonProtocol.Operations.cs
  20. +26 −2 Languages/IronPython/IronPython/Runtime/ClrModule.cs
  21. +9 −9 Languages/IronPython/IronPython/Runtime/CommonDictionaryStorage.cs
  22. +9 −9 Languages/IronPython/IronPython/Runtime/DictionaryOps.cs
  23. +2 −1 Languages/IronPython/IronPython/Runtime/Exceptions/PythonExceptions.cs
  24. +3 −0 Languages/IronPython/IronPython/Runtime/List.cs
  25. +14 −1 Languages/IronPython/IronPython/Runtime/Operations/PythonOps.cs
  26. +1 −1 Languages/IronPython/IronPython/Runtime/Operations/StringOps.cs
  27. +0 −2 Languages/IronPython/IronPython/Runtime/PythonContext.cs
  28. +7 −7 Languages/IronPython/IronPython/Runtime/PythonDictionary.cs
  29. +3 −0 Languages/IronPython/IronPython/Runtime/PythonTuple.cs
  30. +0 −3 Languages/IronPython/IronPython/Runtime/Slice.cs
  31. +2 −1 Languages/IronPython/IronPython/Runtime/Types/DocBuilder.cs
  32. +6 −0 Languages/IronPython/IronPythonCompiler/App.config
  33. +291 −0 Languages/IronPython/IronPythonCompiler/Config.cs
  34. +76 −0 Languages/IronPython/IronPythonCompiler/ConsoleOps.cs
  35. +79 −0 Languages/IronPython/IronPythonCompiler/IronPythonCompiler.csproj
  36. +242 −0 Languages/IronPython/IronPythonCompiler/Program.cs
  37. +21 −0 Languages/IronPython/IronPythonCompiler/Properties/AssemblyInfo.cs
  38. BIN Languages/IronPython/IronPythonConsole/ipy.ico
  39. +29 −0 Languages/IronPython/Tests/modules/misc/ctypes_test.py
  40. +14 −0 Languages/IronPython/Tests/modules/system_related/nt_test.py
  41. +27 −1 Languages/IronPython/Tests/test_ast.py
  42. +140 −0 Languages/IronPython/Tests/test_datetime.py
  43. +21 −1 Languages/IronPython/Tests/test_dict.py
  44. +70 −0 Languages/IronPython/Tests/test_struct.py
  45. +16 −0 Languages/IronPython/Tests/test_unicode.py
  46. +30 −20 Languages/Ruby/Libraries/Builtins/FileOps.cs
  47. +36 −0 Languages/Ruby/Libraries/Initializers.Generated.cs
  48. +80 −43 Languages/Ruby/Libraries/Zlib/zlib.cs
  49. +9 −1 Languages/Ruby/Ruby/Builtins/RubyEncoding.cs
  50. +72 −13 Languages/Ruby/Ruby/Runtime/IOWrapper.cs
  51. +3 −5 Makefile
  52. +4 −0 Runtime/Microsoft.Dynamic/Utils/StringUtils.cs
  53. +11 −0 Scripts/Bat/Dev.bat
  54. +2 −2 Solutions/Build.IronPython.proj
  55. +4 −4 Solutions/Common.proj
  56. +563 −525 Solutions/IronPython.sln
  57. BIN Util/IKVM/IKVM.Reflection.dll
@@ -1229,7 +1229,7 @@ def _runscript(self, filename):
self._wait_for_mainpyfile = 1
self.mainpyfile = self.canonic(filename)
self._user_requested_quit = 0
- statement = 'execfile( "%s")' % filename
+ statement = 'execfile(%r)' % filename
self.run(statement)
# Simplified interface
@@ -3,6 +3,9 @@
import imp
import sys
+import os
+import unittest
+import subprocess
from test import test_support
# This little helper class is essential for testing pdb under doctest.
@@ -277,6 +280,29 @@ def test_pdb_continue_in_bottomframe():
4
"""
+class Tester7750(unittest.TestCase):
+ # if the filename has something that resolves to a python
+ # escape character (such as \t), it will fail
+ test_fn = '.\\test7750.py'
+
+ msg = "issue7750 only applies when os.sep is a backslash"
+ @unittest.skipUnless(os.path.sep == '\\', msg)
+ def test_issue7750(self):
+ with open(self.test_fn, 'w') as f:
+ f.write('print("hello world")')
+ cmd = [sys.executable, '-m', 'pdb', self.test_fn,]
+ proc = subprocess.Popen(cmd,
+ stdout=subprocess.PIPE,
+ stdin=subprocess.PIPE,
+ stderr=subprocess.STDOUT,
+ )
+ stdout, stderr = proc.communicate('quit\n')
+ self.assertNotIn('IOError', stdout, "pdb munged the filename")
+
+ def tearDown(self):
+ if os.path.isfile(self.test_fn):
+ os.remove(self.test_fn)
+
def test_main():
from test import test_pdb
@@ -285,3 +311,4 @@ def test_main():
if __name__ == '__main__':
test_main()
+ unittest.main()
@@ -404,12 +404,6 @@ def testTraceback(self):
class CompressedZipImportTestCase(UncompressedZipImportTestCase):
compression = ZIP_DEFLATED
- @unittest.skipIf(sys.platform == 'cli', 'Issue: http://ironpython.codeplex.com/workitem/31976')
- def testEmptyPy(self):
- # we are overriding this method because the compressed version does not work
- pass
-
-
class BadFileZipImportTestCase(unittest.TestCase):
def assertZipFailure(self, filename):
self.assertRaises(zipimport.ZipImportError,
@@ -155,12 +155,18 @@ public static partial class ModuleOps {
return null;
}
+ private static readonly byte[] FakeZeroLength = { 42 };
+
public static byte[] TryCheckBytes(object o) {
Bytes bytes = o as Bytes;
if (bytes != null) {
+ if (bytes._bytes.Length == 0) {
+ // OpCodes.Ldelema refuses to get address of empty array
+ // So we feed it with a fake one (cp34892)
+ return FakeZeroLength;
+ }
return bytes._bytes;
}
-
return null;
}
@@ -303,6 +309,10 @@ public static partial class ModuleOps {
return new IntPtr((long)(BigInteger)value);
}
+ if (value is Int64) {
+ return new IntPtr((Int64) value);
+ }
+
if (value == null) {
return IntPtr.Zero;
}
@@ -151,7 +151,8 @@ public class EncodingMap {
if (errors == "strict" && isDecode) {
throw PythonOps.UnicodeDecodeError("'charmap' codec can't decode characters at index {0} because charmap maps to None", i);
} else if (!isDecode) {
- throw PythonOps.UnicodeEncodeError("'charmap' codec can't encode characters at index {0} because charmap maps to None", i);
+ throw PythonOps.UnicodeEncodeError("charmap", input[i], i,
+ "'charmap' codec can't encode characters at index {0} because charmap maps to None", i);
}
res.Append("\ufffd");
} else if (val is string) {
@@ -321,11 +321,12 @@ private Dialect()
{
string dialectName = (string)dialect;
if (dialects.ContainsKey(dialectName))
- return dialects[dialectName];
+ dialect = dialects[dialectName];
else
throw MakeError("unknown dialect");
}
- else if (dialect is Dialect &&
+
+ if (dialect is Dialect &&
delimiter == null &&
doublequote == null &&
escapechar == null &&
@@ -669,42 +669,50 @@ private struct Format {
}
[Documentation("Return string containing values v1, v2, ... packed according to fmt.")]
- public static string/*!*/ pack(CodeContext/*!*/ context, [NotNull]string fmt/*!*/, params object[] values) {
+ public static string/*!*/ pack(CodeContext/*!*/ context, [BytesConversion][NotNull]string fmt/*!*/, params object[] values)
+ {
return GetStructFromCache(context, fmt).pack(context, values);
}
[Documentation("Pack the values v1, v2, ... according to fmt.\nWrite the packed bytes into the writable buffer buf starting at offset.")]
- public static void pack_into(CodeContext/*!*/ context, [NotNull]string/*!*/ fmt, [NotNull]ArrayModule.array/*!*/ buffer, int offset, params object[] args) {
+ public static void pack_into(CodeContext/*!*/ context, [BytesConversion][NotNull]string/*!*/ fmt, [NotNull]ArrayModule.array/*!*/ buffer, int offset, params object[] args)
+ {
GetStructFromCache(context, fmt).pack_into(context, buffer, offset, args);
}
[Documentation("Unpack the string containing packed C structure data, according to fmt.\nRequires len(string) == calcsize(fmt).")]
- public static PythonTuple/*!*/ unpack(CodeContext/*!*/ context, [NotNull]string/*!*/ fmt, [NotNull]string/*!*/ @string) {
+ public static PythonTuple/*!*/ unpack(CodeContext/*!*/ context, [BytesConversion][NotNull]string/*!*/ fmt, [BytesConversion][NotNull]string/*!*/ @string)
+ {
return GetStructFromCache(context, fmt).unpack(context, @string);
}
[Documentation("Unpack the string containing packed C structure data, according to fmt.\nRequires len(string) == calcsize(fmt).")]
- public static PythonTuple/*!*/ unpack(CodeContext/*!*/ context, [NotNull]string/*!*/ fmt, [NotNull]ArrayModule.array/*!*/ buffer) {
+ public static PythonTuple/*!*/ unpack(CodeContext/*!*/ context, [BytesConversion][NotNull]string/*!*/ fmt, [NotNull]ArrayModule.array/*!*/ buffer)
+ {
return GetStructFromCache(context, fmt).unpack(context, buffer);
}
[Documentation("Unpack the string containing packed C structure data, according to fmt.\nRequires len(string) == calcsize(fmt).")]
- public static PythonTuple/*!*/ unpack(CodeContext/*!*/ context, [NotNull]string fmt/*!*/, [NotNull]PythonBuffer/*!*/ buffer) {
+ public static PythonTuple/*!*/ unpack(CodeContext/*!*/ context, [BytesConversion][NotNull]string fmt/*!*/, [NotNull]PythonBuffer/*!*/ buffer)
+ {
return GetStructFromCache(context, fmt).unpack(context, buffer);
}
[Documentation("Unpack the buffer, containing packed C structure data, according to\nfmt, starting at offset. Requires len(buffer[offset:]) >= calcsize(fmt).")]
- public static PythonTuple/*!*/ unpack_from(CodeContext/*!*/ context, [NotNull]string fmt/*!*/, [NotNull]ArrayModule.array/*!*/ buffer, [DefaultParameterValue(0)] int offset) {
+ public static PythonTuple/*!*/ unpack_from(CodeContext/*!*/ context, [BytesConversion][NotNull]string fmt/*!*/, [NotNull]ArrayModule.array/*!*/ buffer, [DefaultParameterValue(0)] int offset)
+ {
return GetStructFromCache(context, fmt).unpack_from(context, buffer, offset);
}
[Documentation("Unpack the buffer, containing packed C structure data, according to\nfmt, starting at offset. Requires len(buffer[offset:]) >= calcsize(fmt).")]
- public static PythonTuple/*!*/ unpack_from(CodeContext/*!*/ context, [NotNull]string fmt/*!*/, [NotNull]string/*!*/ buffer, [DefaultParameterValue(0)] int offset) {
+ public static PythonTuple/*!*/ unpack_from(CodeContext/*!*/ context, [BytesConversion][NotNull]string fmt/*!*/, [BytesConversion][NotNull]string/*!*/ buffer, [DefaultParameterValue(0)] int offset)
+ {
return GetStructFromCache(context, fmt).unpack_from(context, buffer, offset);
}
[Documentation("Unpack the buffer, containing packed C structure data, according to\nfmt, starting at offset. Requires len(buffer[offset:]) >= calcsize(fmt).")]
- public static PythonTuple/*!*/ unpack_from(CodeContext/*!*/ context, [NotNull]string fmt/*!*/, [NotNull]PythonBuffer/*!*/ buffer, [DefaultParameterValue(0)] int offset) {
+ public static PythonTuple/*!*/ unpack_from(CodeContext/*!*/ context, [BytesConversion][NotNull]string fmt/*!*/, [NotNull]PythonBuffer/*!*/ buffer, [DefaultParameterValue(0)] int offset)
+ {
return GetStructFromCache(context, fmt).unpack_from(context, buffer, offset);
}
@@ -76,7 +76,7 @@ public static class PythonSubprocess {
object tSec /*subprocess.py passes None*/,
int? bInheritHandles,
uint? dwCreationFlags,
- PythonDictionary lpEnvironment,
+ object lpEnvironment,
string lpCurrentDirectory,
object lpStartupInfo /* subprocess.py passes STARTUPINFO*/) {
@@ -116,8 +116,8 @@ public static class PythonSubprocess {
* there needs to be some conversion done here...*/
}
- // If needed convert lpEnvironment Dictonary to lpEnvironmentIntPtr
- string lpEnvironmentStr = EnvironmentToNative(lpEnvironment);
+ // If needed convert lpEnvironment Dictionary to lpEnvironmentIntPtr
+ string lpEnvironmentStr = EnvironmentToNative(context, lpEnvironment);
PROCESS_INFORMATION lpProcessInformation = new PROCESS_INFORMATION();
bool result = CreateProcessPI(
@@ -147,12 +147,13 @@ public static class PythonSubprocess {
pid, tid);
}
- private static string EnvironmentToNative(PythonDictionary lpEnvironment) {
- if (lpEnvironment == null) {
+ private static string EnvironmentToNative(CodeContext context, object environment) {
+ if (environment == null) {
return null;
}
- StringBuilder res = new StringBuilder();
- foreach (var keyValue in lpEnvironment) {
+ var dict = environment as PythonDictionary ?? new PythonDictionary(context, environment);
+ var res = new StringBuilder();
+ foreach (var keyValue in dict) {
res.Append(keyValue.Key);
res.Append('=');
res.Append(keyValue.Value);
@@ -367,6 +367,10 @@ internal enum InputKind { Year, Month, Day, Hour, Minute, Second, Microsecond }
return false;
}
+ internal static int CastToInt(object o) {
+ return o is BigInteger ? (int)(BigInteger)o : (int)o;
+ }
+
[PythonType]
public class date : ICodeFormattable {
internal DateTime _dateTime;
@@ -481,9 +485,9 @@ public class date : ICodeFormattable {
if (strVal == null) continue;
switch (strVal) {
- case "year": year2 = PythonContext.GetContext(context).ConvertToInt32(kvp.Value); break;
- case "month": month2 = PythonContext.GetContext(context).ConvertToInt32(kvp.Value); break;
- case "day": day2 = PythonContext.GetContext(context).ConvertToInt32(kvp.Value); break;
+ case "year": year2 = CastToInt(kvp.Value); break;
+ case "month": month2 = CastToInt(kvp.Value); break;
+ case "day": day2 = CastToInt(kvp.Value); break;
default: throw PythonOps.TypeError("{0} is an invalid keyword argument for this function", kvp.Key);
}
}
@@ -802,24 +806,25 @@ public datetime(DateTime dt)
}
_lostMicroseconds = _lostMicroseconds % 1000;
}
- }
-
- // other constructors, all class methods:
+ }
+
+ // other constructors, all class methods:
+ public static object now([DefaultParameterValue(null)]tzinfo tz) {
+ if (tz != null) {
+ return tz.fromutc(new datetime(DateTime.UtcNow, 0, tz));
+ } else {
+ return new datetime(DateTime.Now, 0, null);
+ }
+ }
+
+ public static object utcnow() {
+ return new datetime(DateTime.UtcNow, 0, null);
+ }
+
+
public new static object today() {
return new datetime(DateTime.Now, 0, null);
- }
-
- public static object now([DefaultParameterValue(null)]tzinfo tz) {
- if (tz != null) {
- return tz.fromutc(new datetime(DateTime.UtcNow, 0, tz));
- } else {
- return new datetime(DateTime.Now, 0, null);
- }
- }
-
- public static object utcnow() {
- return new datetime(DateTime.UtcNow, 0, null);
- }
+ }
public static object fromtimestamp(double timestamp, [DefaultParameterValue(null)] tzinfo tz) {
DateTime dt = PythonTime.TimestampToDateTime(timestamp);
@@ -950,25 +955,25 @@ public datetime(DateTime dt)
switch (key) {
case "year":
- lyear = (int)kvp.Value;
+ lyear = CastToInt(kvp.Value);
break;
case "month":
- lmonth = (int)kvp.Value;
+ lmonth = CastToInt(kvp.Value);
break;
case "day":
- lday = (int)kvp.Value;
+ lday = CastToInt(kvp.Value);
break;
case "hour":
- lhour = (int)kvp.Value;
+ lhour = CastToInt(kvp.Value);
break;
case "minute":
- lminute = (int)kvp.Value;
+ lminute = CastToInt(kvp.Value);
break;
case "second":
- lsecond = (int)kvp.Value;
+ lsecond = CastToInt(kvp.Value);
break;
case "microsecond":
- lmicrosecond = (int)kvp.Value;
+ lmicrosecond = CastToInt(kvp.Value);
break;
case "tzinfo":
tz = kvp.Value as tzinfo;
@@ -1101,15 +1106,12 @@ public datetime(DateTime dt)
}
public override string strftime(CodeContext/*!*/ context, string dateFormat) {
- return PythonTime.strftime(context, dateFormat, _dateTime, _lostMicroseconds);
+ return PythonTime.strftime(context, dateFormat, _dateTime, microsecond);
}
public static datetime strptime(CodeContext/*!*/ context, string date_string, string format) {
- var res = PythonTime.strptime(context, date_string, format) as PythonTuple;
- if(res == null)
- throw PythonOps.ValueError("time.strptime returned an invalid value.");
-
- return new datetime((int)res[0], (int)res[1], (int)res[2], (int)res[3], (int)res[4], (int)res[5], 0, null);
+ var packed = PythonTime._strptime(context, date_string, format);
+ return new datetime((DateTime)packed[0]);
}
#region IRichComparable Members
@@ -1145,8 +1147,9 @@ public datetime(DateTime dt)
#region ICodeFormattable Members
public override string/*!*/ __repr__(CodeContext/*!*/ context) {
- StringBuilder sb = new StringBuilder();
- sb.AppendFormat("datetime.datetime({0}, {1}, {2}, {3}, {4}",
+ StringBuilder sb = new StringBuilder();
+ // TODO: need to determine how to get the actual class name if a derived type (CP21478)
+ sb.AppendFormat("datetime.datetime({0}, {1}, {2}, {3}, {4}",
InternalDateTime.Year,
InternalDateTime.Month,
InternalDateTime.Day,
@@ -1316,16 +1319,16 @@ public class time : ICodeFormattable {
switch (key) {
case "hour":
- lhour = (int)kvp.Value;
+ lhour = CastToInt(kvp.Value);
break;
case "minute":
- lminute = (int)kvp.Value;
+ lminute = CastToInt(kvp.Value);
break;
case "second":
- lsecond = (int)kvp.Value;
+ lsecond = CastToInt(kvp.Value);
break;
case "microsecond":
- lmicrosecond = (int)kvp.Value;
+ lmicrosecond = CastToInt(kvp.Value);
break;
case "tzinfo":
tz = kvp.Value as tzinfo;
@@ -47,7 +47,9 @@ public static class MmapModule {
private const int SEEK_END = 2;
public static readonly int ALLOCATIONGRANULARITY = GetAllocationGranularity();
- public static readonly int PAGESIZE = System.Environment.SystemPageSize;
+ public static readonly int PAGESIZE = System.Environment.SystemPageSize;
+
+ public static readonly string __doc__ = null;
private static readonly object _mmapErrorKey = new object();
Oops, something went wrong.

0 comments on commit 3456c1d

Please sign in to comment.