File tree Expand file tree Collapse file tree 8 files changed +34
-17
lines changed
include/boost/python/converter Expand file tree Collapse file tree 8 files changed +34
-17
lines changed Original file line number Diff line number Diff line change @@ -29,6 +29,15 @@ <h2 align="center">News/Change Log</h2>
2929 < hr >
3030
3131 < dl class ="page-index ">
32+ < dt > 8 Sept 2004</ dt >
33+
34+ < dd >
35+ < ul >
36+ Support for Python's Bool type, thanks to < a
37+ mailto ="dholth-at-fastmail.fm "> Daniel Holth</ a > .
38+ </ ul >
39+ </ dd >
40+
3241 < dt > 11 Sept 2003</ dt >
3342
3443 < dd >
Original file line number Diff line number Diff line change @@ -91,8 +91,12 @@ namespace detail
9191 : ::PyInt_FromLong(x))
9292
9393// Bool is not signed.
94+ #if PY_VERSION_HEX >= 0x02030000
95+ BOOST_PYTHON_TO_PYTHON_BY_VALUE (bool , ::PyBool_FromLong(x))
96+ #else
9497BOOST_PYTHON_TO_PYTHON_BY_VALUE (bool , ::PyInt_FromLong(x))
95-
98+ #endif
99+
96100// note: handles signed char and unsigned char, but not char (see below)
97101BOOST_PYTHON_TO_INT (char )
98102
Original file line number Diff line number Diff line change @@ -91,7 +91,7 @@ struct X {
9191 {}
9292
9393 X (std::string s, bool b)
94- : state(" Got exactly two arguments from constructor: string(%s); bool(%s); " % make_tuple(s, b))
94+ : state(" Got exactly two arguments from constructor: string(%s); bool(%s); " % make_tuple(s, b* 1 ))
9595 {}
9696
9797 object
@@ -114,19 +114,19 @@ struct X {
114114 object
115115 foo (int a, bool b=false ) const
116116 {
117- return " int(%s); bool(%s); " % make_tuple (a, b);
117+ return " int(%s); bool(%s); " % make_tuple (a, b* 1 );
118118 }
119119
120120 object
121121 foo (std::string a, bool b=false ) const
122122 {
123- return " string(%s); bool(%s); " % make_tuple (a, b);
123+ return " string(%s); bool(%s); " % make_tuple (a, b* 1 );
124124 }
125125
126126 object
127127 foo (list a, list b, bool c=false ) const
128128 {
129- return " list(%s); list(%s); bool(%s); " % make_tuple (a, b, c);
129+ return " list(%s); list(%s); bool(%s); " % make_tuple (a, b, c* 1 );
130130 }
131131
132132 object
Original file line number Diff line number Diff line change 22# Software License, Version 1.0. (See accompanying
33# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
44"""
5- >>> False = 0 # Python 2.2 needs these
6- >>> True = 1
5+ # Use builtin True/False when available:
6+ >>> try:
7+ ... assert(True == 1)
8+ ... except:
9+ ... True = 1
10+ ... False = 0
711
812>>> from defaults_ext import *
913>>> bar(1)
Original file line number Diff line number Diff line change @@ -67,8 +67,9 @@ void test_templates(object print)
6767 print (tmp.get (44 ));
6868 print (tmp);
6969 print (tmp.get (2 ," default" ));
70- print (tmp.has_key (key));
7170 print (tmp.setdefault (3 ," default" ));
71+
72+ assert (!tmp.has_key (key));
7273 // print(tmp[3]);
7374}
7475
Original file line number Diff line number Diff line change 2626None
2727{1.5: 13, 1: 'a test string'}
2828default
29- 0
3029default
3130"""
3231
Original file line number Diff line number Diff line change @@ -24,8 +24,10 @@ void work_with_string(object print)
2424 print (data.count (" t" ));
2525 print (data.encode (" utf-8" ));
2626 print (data.decode (" utf-8" ));
27- print (data.endswith (" xx" ));
28- print (data.startswith (" test" ));
27+
28+ assert (!data.endswith (" xx" ));
29+ assert (!data.startswith (" test" ));
30+
2931 print (data.splitlines ());
3032 print (data.strip ());
3133 print (data.swapcase ());
@@ -51,8 +53,10 @@ void work_with_string(object print)
5153 print (data.replace (" demo" ,std::string (" blabla" )));
5254 print (data.rfind (" i" ,5 ));
5355 print (data.rindex (" i" ,5 ));
54- print (data.startswith (" asdf" ));
55- print (data.endswith (" asdf" ));
56+
57+ assert (!data.startswith (" asdf" ));
58+ assert (!data.endswith (" asdf" ));
59+
5660 print (data.translate (str (' a' )*256 ));
5761
5862
Original file line number Diff line number Diff line change 16162
1717this is a demo string
1818this is a demo string
19- 0
20- 0
2119['this is a demo string']
2220this is a demo string
2321THIS IS A DEMO STRING
3634this is a blabla string
373518
383618
39- 0
40- 0
4137aaaaaaaaaaaaaaaaaaaaa
4238"""
4339
You can’t perform that action at this time.
0 commit comments