This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from contextlib import contextmanager | |
from functools import wraps | |
@contextmanager | |
def enter_stage(message): | |
# Start stage | |
print("Start '{0}' stage".format(message)) | |
try: | |
yield |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pickle | |
class MyClass(object): | |
pass | |
def test(obj): | |
# add a custom attribute | |
obj.some_attribute=42 | |
print "reduce=",obj.__reduce__() # doesn't include the attribute... | |
o=pickle.loads(pickle.dumps(obj, protocol=pickle.HIGHEST_PROTOCOL)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import print_function | |
def raiser(): | |
print('raising an exception') | |
raise Exception() # unreported exception here | |
if __name__ == '__main__': | |
try: | |
raiser() | |
except Exception: # but is handled here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## -- Procedural functions (function) work. --- | |
a = App.TypedEvent[object]() | |
def test(s): | |
print s | |
a.removeHandler(test) | |
a.addHandler(test) | |
a.addHandler(test) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using IronPython.Hosting; | |
using Microsoft.Scripting; | |
using Microsoft.Scripting.Hosting; | |
namespace IronPythonTest | |
{ | |
class Program | |
{ | |
static void Main(string[] args) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: _struct.cs | |
=================================================================== | |
--- _struct.cs (revision 16090) | |
+++ _struct.cs (working copy) | |
@@ -95,7 +95,11 @@ | |
_formatString = fmt; | |
Struct s; | |
- if (_cache.TryGetValue(_formatString, out s)) { | |
+ bool cached; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import unittest | |
from System import InvalidOperationException | |
class Issue(unittest.TestCase): | |
def test_assertRaises(self): | |
with self.assertRaises(InvalidOperationException): | |
raise InvalidOperationException('assertRaises should catch this') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
assert unicode('Foo') == u'Foo' | |
assert unicode(u'Foo') == u'Foo' | |
assert unicode(u'é') == u'é' | |
unicode_reference = unicode | |
assert unicode_reference('Foo') == u'Foo' | |
assert unicode_reference(u'Foo') == u'Foo' | |
assert unicode_reference(u'é') == u'é' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import unittest | |
from xml.sax.saxutils import XMLGenerator | |
from StringIO import StringIO | |
class TestXmlGenerator(unittest.TestCase): | |
def test_encoding(self): | |
input = u'hyv\xe4' | |
output = StringIO() | |
XMLGenerator(output, encoding='UTF-8').characters(input) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Desc(object): | |
def __init__(self, key): | |
self.key = key | |
def __get__(self, instance, owner): | |
print "__get__ (%s): instance='%s'; owner='%s'" % (self.key, instance, owner) | |
return self | |
def __set__(self, instance, value): | |
print "__set__ (%s): instance='%s'; value='%s'" % (self.key, instance, value) |