rubyfox-server 2.3.0.pre2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/.rvmrc +1 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +23 -0
- data/Rakefile +1 -0
- data/bin/smartfox +7 -0
- data/lib/rubyfox/server/cli.rb +59 -0
- data/lib/rubyfox/server/data/config/.keep +0 -0
- data/lib/rubyfox/server/data/config/_backups/.keep +0 -0
- data/lib/rubyfox/server/data/config/ascii/boot.txt +5 -0
- data/lib/rubyfox/server/data/config/ascii/ready.txt +9 -0
- data/lib/rubyfox/server/data/config/core.xml +44 -0
- data/lib/rubyfox/server/data/config/crossdomain.xml +10 -0
- data/lib/rubyfox/server/data/config/descriptors/.keep +0 -0
- data/lib/rubyfox/server/data/config/descriptors/config_room.txt +323 -0
- data/lib/rubyfox/server/data/config/descriptors/config_server.txt +621 -0
- data/lib/rubyfox/server/data/config/descriptors/config_zone.txt +1021 -0
- data/lib/rubyfox/server/data/config/descriptors/runtime_game.txt +63 -0
- data/lib/rubyfox/server/data/config/descriptors/runtime_room.txt +377 -0
- data/lib/rubyfox/server/data/config/descriptors/runtime_user.txt +589 -0
- data/lib/rubyfox/server/data/config/descriptors/runtime_zone.txt +354 -0
- data/lib/rubyfox/server/data/config/jetty/.keep +0 -0
- data/lib/rubyfox/server/data/config/jetty/jetty.xml +214 -0
- data/lib/rubyfox/server/data/config/jetty/realm.properties +21 -0
- data/lib/rubyfox/server/data/config/jetty/webdefault.xml +410 -0
- data/lib/rubyfox/server/data/config/log4j.properties +75 -0
- data/lib/rubyfox/server/data/config/myprop.properties +5 -0
- data/lib/rubyfox/server/data/config/server.xml +65 -0
- data/lib/rubyfox/server/data/config/templates/sfs2x.unix.txt +12 -0
- data/lib/rubyfox/server/data/config/templates/sfs2x.windows.txt +1 -0
- data/lib/rubyfox/server/data/config/templates/vmoptions.txt +3 -0
- data/lib/rubyfox/server/data/config/wordsFile.txt +13 -0
- data/lib/rubyfox/server/data/data/bannedusers/.keep +0 -0
- data/lib/rubyfox/server/data/data/bannedusers/users.bin +0 -0
- data/lib/rubyfox/server/data/data/buddylists/.keep +0 -0
- data/lib/rubyfox/server/data/data/buddylists/BasicExamples/7364666773646667 +0 -0
- data/lib/rubyfox/server/data/extensions/.keep +0 -0
- data/lib/rubyfox/server/data/extensions/__lib__/.keep +0 -0
- data/lib/rubyfox/server/data/lib/Jetty/.keep +0 -0
- data/lib/rubyfox/server/data/lib/Jetty/ant-1.6.5.jar +0 -0
- data/lib/rubyfox/server/data/lib/Jetty/core-3.1.1.jar +0 -0
- data/lib/rubyfox/server/data/lib/Jetty/jetty-6.1.26.jar +0 -0
- data/lib/rubyfox/server/data/lib/Jetty/jetty-util-6.1.26.jar +0 -0
- data/lib/rubyfox/server/data/lib/Jetty/jsp-2.1-glassfish-2.1.v20091210.jar +0 -0
- data/lib/rubyfox/server/data/lib/Jetty/jsp-2.1-jetty-6.1.26.jar +0 -0
- data/lib/rubyfox/server/data/lib/Jetty/jsp-api-2.1-glassfish-2.1.v20091210.jar +0 -0
- data/lib/rubyfox/server/data/lib/Jetty/servlet-api-2.5-20081211.jar +0 -0
- data/lib/rubyfox/server/data/lib/Lib/BaseHTTPServer.py +484 -0
- data/lib/rubyfox/server/data/lib/Lib/CGIHTTPServer.py +325 -0
- data/lib/rubyfox/server/data/lib/Lib/ConfigParser.py +472 -0
- data/lib/rubyfox/server/data/lib/Lib/Cookie.py +742 -0
- data/lib/rubyfox/server/data/lib/Lib/HTMLParser.py +383 -0
- data/lib/rubyfox/server/data/lib/Lib/MimeWriter.py +181 -0
- data/lib/rubyfox/server/data/lib/Lib/Queue.py +151 -0
- data/lib/rubyfox/server/data/lib/Lib/SimpleHTTPServer.py +198 -0
- data/lib/rubyfox/server/data/lib/Lib/SimpleXMLRPCServer.py +274 -0
- data/lib/rubyfox/server/data/lib/Lib/SocketServer.py +576 -0
- data/lib/rubyfox/server/data/lib/Lib/StringIO.py +239 -0
- data/lib/rubyfox/server/data/lib/Lib/UserDict$py.class +0 -0
- data/lib/rubyfox/server/data/lib/Lib/UserDict.py +60 -0
- data/lib/rubyfox/server/data/lib/Lib/UserList.py +94 -0
- data/lib/rubyfox/server/data/lib/Lib/UserString.py +182 -0
- data/lib/rubyfox/server/data/lib/Lib/__future__$py.class +0 -0
- data/lib/rubyfox/server/data/lib/Lib/__future__.py +104 -0
- data/lib/rubyfox/server/data/lib/Lib/aifc.py +961 -0
- data/lib/rubyfox/server/data/lib/Lib/anydbm.py +86 -0
- data/lib/rubyfox/server/data/lib/Lib/atexit.py +50 -0
- data/lib/rubyfox/server/data/lib/Lib/base64.py +77 -0
- data/lib/rubyfox/server/data/lib/Lib/bdb.py +563 -0
- data/lib/rubyfox/server/data/lib/Lib/binhex.py +531 -0
- data/lib/rubyfox/server/data/lib/Lib/bisect.py +78 -0
- data/lib/rubyfox/server/data/lib/Lib/calendar.py +246 -0
- data/lib/rubyfox/server/data/lib/Lib/cgi.py +1040 -0
- data/lib/rubyfox/server/data/lib/Lib/chunk.py +167 -0
- data/lib/rubyfox/server/data/lib/Lib/cmd.py +336 -0
- data/lib/rubyfox/server/data/lib/Lib/code$py.class +0 -0
- data/lib/rubyfox/server/data/lib/Lib/code.py +311 -0
- data/lib/rubyfox/server/data/lib/Lib/codecs$py.class +0 -0
- data/lib/rubyfox/server/data/lib/Lib/codecs.py +636 -0
- data/lib/rubyfox/server/data/lib/Lib/codeop$py.class +0 -0
- data/lib/rubyfox/server/data/lib/Lib/codeop.py +131 -0
- data/lib/rubyfox/server/data/lib/Lib/colorsys.py +123 -0
- data/lib/rubyfox/server/data/lib/Lib/commands.py +84 -0
- data/lib/rubyfox/server/data/lib/Lib/compileall.py +148 -0
- data/lib/rubyfox/server/data/lib/Lib/copy.py +330 -0
- data/lib/rubyfox/server/data/lib/Lib/copy_reg$py.class +0 -0
- data/lib/rubyfox/server/data/lib/Lib/copy_reg.py +78 -0
- data/lib/rubyfox/server/data/lib/Lib/datetime$py.class +0 -0
- data/lib/rubyfox/server/data/lib/Lib/datetime.py +2007 -0
- data/lib/rubyfox/server/data/lib/Lib/dbexts.py +726 -0
- data/lib/rubyfox/server/data/lib/Lib/difflib.py +1088 -0
- data/lib/rubyfox/server/data/lib/Lib/dircache.py +44 -0
- data/lib/rubyfox/server/data/lib/Lib/doctest.py +1173 -0
- data/lib/rubyfox/server/data/lib/Lib/dospath.py +341 -0
- data/lib/rubyfox/server/data/lib/Lib/dumbdbm.py +170 -0
- data/lib/rubyfox/server/data/lib/Lib/email/Charset.py +393 -0
- data/lib/rubyfox/server/data/lib/Lib/email/Encoders.py +94 -0
- data/lib/rubyfox/server/data/lib/Lib/email/Errors.py +26 -0
- data/lib/rubyfox/server/data/lib/Lib/email/Generator.py +378 -0
- data/lib/rubyfox/server/data/lib/Lib/email/Header.py +515 -0
- data/lib/rubyfox/server/data/lib/Lib/email/Iterators.py +25 -0
- data/lib/rubyfox/server/data/lib/Lib/email/MIMEAudio.py +71 -0
- data/lib/rubyfox/server/data/lib/Lib/email/MIMEBase.py +24 -0
- data/lib/rubyfox/server/data/lib/Lib/email/MIMEImage.py +45 -0
- data/lib/rubyfox/server/data/lib/Lib/email/MIMEMessage.py +32 -0
- data/lib/rubyfox/server/data/lib/Lib/email/MIMEMultipart.py +37 -0
- data/lib/rubyfox/server/data/lib/Lib/email/MIMENonMultipart.py +24 -0
- data/lib/rubyfox/server/data/lib/Lib/email/MIMEText.py +45 -0
- data/lib/rubyfox/server/data/lib/Lib/email/Message.py +837 -0
- data/lib/rubyfox/server/data/lib/Lib/email/Parser.py +292 -0
- data/lib/rubyfox/server/data/lib/Lib/email/Utils.py +340 -0
- data/lib/rubyfox/server/data/lib/Lib/email/__init__.py +72 -0
- data/lib/rubyfox/server/data/lib/Lib/email/_compat21.py +69 -0
- data/lib/rubyfox/server/data/lib/Lib/email/_compat22.py +70 -0
- data/lib/rubyfox/server/data/lib/Lib/email/_parseaddr.py +480 -0
- data/lib/rubyfox/server/data/lib/Lib/email/base64MIME.py +184 -0
- data/lib/rubyfox/server/data/lib/Lib/email/quopriMIME.py +323 -0
- data/lib/rubyfox/server/data/lib/Lib/email/test/__init__.py +2 -0
- data/lib/rubyfox/server/data/lib/Lib/email/test/data/PyBanner048.gif +0 -0
- data/lib/rubyfox/server/data/lib/Lib/email/test/data/audiotest.au +0 -0
- data/lib/rubyfox/server/data/lib/Lib/email/test/data/msg_01.txt +19 -0
- data/lib/rubyfox/server/data/lib/Lib/email/test/data/msg_02.txt +135 -0
- data/lib/rubyfox/server/data/lib/Lib/email/test/data/msg_03.txt +16 -0
- data/lib/rubyfox/server/data/lib/Lib/email/test/data/msg_04.txt +37 -0
- data/lib/rubyfox/server/data/lib/Lib/email/test/data/msg_05.txt +28 -0
- data/lib/rubyfox/server/data/lib/Lib/email/test/data/msg_06.txt +33 -0
- data/lib/rubyfox/server/data/lib/Lib/email/test/data/msg_07.txt +83 -0
- data/lib/rubyfox/server/data/lib/Lib/email/test/data/msg_08.txt +24 -0
- data/lib/rubyfox/server/data/lib/Lib/email/test/data/msg_09.txt +24 -0
- data/lib/rubyfox/server/data/lib/Lib/email/test/data/msg_10.txt +32 -0
- data/lib/rubyfox/server/data/lib/Lib/email/test/data/msg_11.txt +7 -0
- data/lib/rubyfox/server/data/lib/Lib/email/test/data/msg_12.txt +36 -0
- data/lib/rubyfox/server/data/lib/Lib/email/test/data/msg_13.txt +94 -0
- data/lib/rubyfox/server/data/lib/Lib/email/test/data/msg_14.txt +23 -0
- data/lib/rubyfox/server/data/lib/Lib/email/test/data/msg_15.txt +52 -0
- data/lib/rubyfox/server/data/lib/Lib/email/test/data/msg_16.txt +123 -0
- data/lib/rubyfox/server/data/lib/Lib/email/test/data/msg_17.txt +12 -0
- data/lib/rubyfox/server/data/lib/Lib/email/test/data/msg_18.txt +6 -0
- data/lib/rubyfox/server/data/lib/Lib/email/test/data/msg_19.txt +43 -0
- data/lib/rubyfox/server/data/lib/Lib/email/test/data/msg_20.txt +22 -0
- data/lib/rubyfox/server/data/lib/Lib/email/test/data/msg_21.txt +20 -0
- data/lib/rubyfox/server/data/lib/Lib/email/test/data/msg_22.txt +46 -0
- data/lib/rubyfox/server/data/lib/Lib/email/test/data/msg_23.txt +8 -0
- data/lib/rubyfox/server/data/lib/Lib/email/test/data/msg_24.txt +10 -0
- data/lib/rubyfox/server/data/lib/Lib/email/test/data/msg_25.txt +117 -0
- data/lib/rubyfox/server/data/lib/Lib/email/test/data/msg_26.txt +45 -0
- data/lib/rubyfox/server/data/lib/Lib/email/test/data/msg_27.txt +15 -0
- data/lib/rubyfox/server/data/lib/Lib/email/test/data/msg_28.txt +25 -0
- data/lib/rubyfox/server/data/lib/Lib/email/test/data/msg_29.txt +22 -0
- data/lib/rubyfox/server/data/lib/Lib/email/test/data/msg_30.txt +23 -0
- data/lib/rubyfox/server/data/lib/Lib/email/test/data/msg_31.txt +15 -0
- data/lib/rubyfox/server/data/lib/Lib/email/test/data/msg_32.txt +14 -0
- data/lib/rubyfox/server/data/lib/Lib/email/test/data/msg_33.txt +29 -0
- data/lib/rubyfox/server/data/lib/Lib/email/test/data/msg_34.txt +19 -0
- data/lib/rubyfox/server/data/lib/Lib/email/test/data/msg_35.txt +4 -0
- data/lib/rubyfox/server/data/lib/Lib/email/test/test_email.py +2718 -0
- data/lib/rubyfox/server/data/lib/Lib/email/test/test_email_codecs.py +68 -0
- data/lib/rubyfox/server/data/lib/Lib/email/test/test_email_torture.py +136 -0
- data/lib/rubyfox/server/data/lib/Lib/encodings/__init__$py.class +0 -0
- data/lib/rubyfox/server/data/lib/Lib/encodings/__init__.py +97 -0
- data/lib/rubyfox/server/data/lib/Lib/encodings/aliases$py.class +0 -0
- data/lib/rubyfox/server/data/lib/Lib/encodings/aliases.py +115 -0
- data/lib/rubyfox/server/data/lib/Lib/encodings/ascii.py +35 -0
- data/lib/rubyfox/server/data/lib/Lib/encodings/base64_codec.py +62 -0
- data/lib/rubyfox/server/data/lib/Lib/encodings/charmap.py +51 -0
- data/lib/rubyfox/server/data/lib/Lib/encodings/cp037.py +280 -0
- data/lib/rubyfox/server/data/lib/Lib/encodings/cp1006.py +138 -0
- data/lib/rubyfox/server/data/lib/Lib/encodings/cp1026.py +280 -0
- data/lib/rubyfox/server/data/lib/Lib/encodings/cp1140.py +45 -0
- data/lib/rubyfox/server/data/lib/Lib/encodings/cp1250.py +123 -0
- data/lib/rubyfox/server/data/lib/Lib/encodings/cp1251.py +157 -0
- data/lib/rubyfox/server/data/lib/Lib/encodings/cp1252.py +76 -0
- data/lib/rubyfox/server/data/lib/Lib/encodings/cp1253.py +151 -0
- data/lib/rubyfox/server/data/lib/Lib/encodings/cp1254.py +82 -0
- data/lib/rubyfox/server/data/lib/Lib/encodings/cp1255.py +143 -0
- data/lib/rubyfox/server/data/lib/Lib/encodings/cp1256.py +129 -0
- data/lib/rubyfox/server/data/lib/Lib/encodings/cp1257.py +131 -0
- data/lib/rubyfox/server/data/lib/Lib/encodings/cp1258.py +90 -0
- data/lib/rubyfox/server/data/lib/Lib/encodings/cp424.py +280 -0
- data/lib/rubyfox/server/data/lib/Lib/encodings/cp437.py +172 -0
- data/lib/rubyfox/server/data/lib/Lib/encodings/cp500.py +280 -0
- data/lib/rubyfox/server/data/lib/Lib/encodings/cp737.py +172 -0
- data/lib/rubyfox/server/data/lib/Lib/encodings/cp775.py +172 -0
- data/lib/rubyfox/server/data/lib/Lib/encodings/cp850.py +172 -0
- data/lib/rubyfox/server/data/lib/Lib/encodings/cp852.py +172 -0
- data/lib/rubyfox/server/data/lib/Lib/encodings/cp855.py +172 -0
- data/lib/rubyfox/server/data/lib/Lib/encodings/cp856.py +172 -0
- data/lib/rubyfox/server/data/lib/Lib/encodings/cp857.py +171 -0
- data/lib/rubyfox/server/data/lib/Lib/encodings/cp860.py +172 -0
- data/lib/rubyfox/server/data/lib/Lib/encodings/cp861.py +172 -0
- data/lib/rubyfox/server/data/lib/Lib/encodings/cp862.py +172 -0
- data/lib/rubyfox/server/data/lib/Lib/encodings/cp863.py +172 -0
- data/lib/rubyfox/server/data/lib/Lib/encodings/cp864.py +170 -0
- data/lib/rubyfox/server/data/lib/Lib/encodings/cp865.py +172 -0
- data/lib/rubyfox/server/data/lib/Lib/encodings/cp866.py +172 -0
- data/lib/rubyfox/server/data/lib/Lib/encodings/cp869.py +172 -0
- data/lib/rubyfox/server/data/lib/Lib/encodings/cp874.py +171 -0
- data/lib/rubyfox/server/data/lib/Lib/encodings/cp875.py +281 -0
- data/lib/rubyfox/server/data/lib/Lib/encodings/hex_codec.py +62 -0
- data/lib/rubyfox/server/data/lib/Lib/encodings/iso8859_1.py +44 -0
- data/lib/rubyfox/server/data/lib/Lib/encodings/iso8859_10.py +90 -0
- data/lib/rubyfox/server/data/lib/Lib/encodings/iso8859_13.py +100 -0
- data/lib/rubyfox/server/data/lib/Lib/encodings/iso8859_14.py +75 -0
- data/lib/rubyfox/server/data/lib/Lib/encodings/iso8859_15.py +52 -0
- data/lib/rubyfox/server/data/lib/Lib/encodings/iso8859_2.py +101 -0
- data/lib/rubyfox/server/data/lib/Lib/encodings/iso8859_3.py +79 -0
- data/lib/rubyfox/server/data/lib/Lib/encodings/iso8859_4.py +94 -0
- data/lib/rubyfox/server/data/lib/Lib/encodings/iso8859_5.py +138 -0
- data/lib/rubyfox/server/data/lib/Lib/encodings/iso8859_6.py +137 -0
- data/lib/rubyfox/server/data/lib/Lib/encodings/iso8859_7.py +124 -0
- data/lib/rubyfox/server/data/lib/Lib/encodings/iso8859_8.py +112 -0
- data/lib/rubyfox/server/data/lib/Lib/encodings/iso8859_9.py +50 -0
- data/lib/rubyfox/server/data/lib/Lib/encodings/koi8_r.py +172 -0
- data/lib/rubyfox/server/data/lib/Lib/encodings/koi8_u.py +54 -0
- data/lib/rubyfox/server/data/lib/Lib/encodings/latin_1.py +35 -0
- data/lib/rubyfox/server/data/lib/Lib/encodings/mac_cyrillic.py +167 -0
- data/lib/rubyfox/server/data/lib/Lib/encodings/mac_greek.py +170 -0
- data/lib/rubyfox/server/data/lib/Lib/encodings/mac_iceland.py +166 -0
- data/lib/rubyfox/server/data/lib/Lib/encodings/mac_latin2.py +170 -0
- data/lib/rubyfox/server/data/lib/Lib/encodings/mac_roman.py +167 -0
- data/lib/rubyfox/server/data/lib/Lib/encodings/mac_turkish.py +167 -0
- data/lib/rubyfox/server/data/lib/Lib/encodings/mbcs.py +36 -0
- data/lib/rubyfox/server/data/lib/Lib/encodings/quopri_codec.py +58 -0
- data/lib/rubyfox/server/data/lib/Lib/encodings/raw_unicode_escape.py +30 -0
- data/lib/rubyfox/server/data/lib/Lib/encodings/rot_13.py +105 -0
- data/lib/rubyfox/server/data/lib/Lib/encodings/undefined.py +34 -0
- data/lib/rubyfox/server/data/lib/Lib/encodings/unicode_escape.py +30 -0
- data/lib/rubyfox/server/data/lib/Lib/encodings/unicode_internal.py +30 -0
- data/lib/rubyfox/server/data/lib/Lib/encodings/utf_16.py +61 -0
- data/lib/rubyfox/server/data/lib/Lib/encodings/utf_16_be.py +31 -0
- data/lib/rubyfox/server/data/lib/Lib/encodings/utf_16_le.py +31 -0
- data/lib/rubyfox/server/data/lib/Lib/encodings/utf_7.py +27 -0
- data/lib/rubyfox/server/data/lib/Lib/encodings/utf_8$py.class +0 -0
- data/lib/rubyfox/server/data/lib/Lib/encodings/utf_8.py +31 -0
- data/lib/rubyfox/server/data/lib/Lib/encodings/uu_codec.py +112 -0
- data/lib/rubyfox/server/data/lib/Lib/encodings/zlib_codec.py +63 -0
- data/lib/rubyfox/server/data/lib/Lib/fileinput.py +349 -0
- data/lib/rubyfox/server/data/lib/Lib/fnmatch.py +107 -0
- data/lib/rubyfox/server/data/lib/Lib/formatter.py +454 -0
- data/lib/rubyfox/server/data/lib/Lib/fpformat.py +142 -0
- data/lib/rubyfox/server/data/lib/Lib/ftplib.py +804 -0
- data/lib/rubyfox/server/data/lib/Lib/getopt.py +143 -0
- data/lib/rubyfox/server/data/lib/Lib/glob.py +56 -0
- data/lib/rubyfox/server/data/lib/Lib/gopherlib.py +205 -0
- data/lib/rubyfox/server/data/lib/Lib/gzip.py +390 -0
- data/lib/rubyfox/server/data/lib/Lib/hmac.py +99 -0
- data/lib/rubyfox/server/data/lib/Lib/htmlentitydefs.py +257 -0
- data/lib/rubyfox/server/data/lib/Lib/htmllib.py +475 -0
- data/lib/rubyfox/server/data/lib/Lib/httplib.py +1238 -0
- data/lib/rubyfox/server/data/lib/Lib/imaplib.py +1208 -0
- data/lib/rubyfox/server/data/lib/Lib/imghdr.py +154 -0
- data/lib/rubyfox/server/data/lib/Lib/inspect$py.class +0 -0
- data/lib/rubyfox/server/data/lib/Lib/inspect.py +787 -0
- data/lib/rubyfox/server/data/lib/Lib/isql.py +238 -0
- data/lib/rubyfox/server/data/lib/Lib/javaos$py.class +0 -0
- data/lib/rubyfox/server/data/lib/Lib/javaos.py +395 -0
- data/lib/rubyfox/server/data/lib/Lib/javapath$py.class +0 -0
- data/lib/rubyfox/server/data/lib/Lib/javapath.py +349 -0
- data/lib/rubyfox/server/data/lib/Lib/javashell.py +194 -0
- data/lib/rubyfox/server/data/lib/Lib/jreload.py +119 -0
- data/lib/rubyfox/server/data/lib/Lib/jxxload_help/DiscardHelp.java +59 -0
- data/lib/rubyfox/server/data/lib/Lib/jxxload_help/JavaLoaderFactory.java +9 -0
- data/lib/rubyfox/server/data/lib/Lib/jxxload_help/PackageManager.java +58 -0
- data/lib/rubyfox/server/data/lib/Lib/jxxload_help/PathVFS.java +98 -0
- data/lib/rubyfox/server/data/lib/Lib/jxxload_help/PathVFSJavaLoader.java +49 -0
- data/lib/rubyfox/server/data/lib/Lib/keyword.py +97 -0
- data/lib/rubyfox/server/data/lib/Lib/linecache$py.class +0 -0
- data/lib/rubyfox/server/data/lib/Lib/linecache.py +101 -0
- data/lib/rubyfox/server/data/lib/Lib/macpath.py +242 -0
- data/lib/rubyfox/server/data/lib/Lib/macurl2path.py +95 -0
- data/lib/rubyfox/server/data/lib/Lib/mailbox.py +313 -0
- data/lib/rubyfox/server/data/lib/Lib/mailcap.py +255 -0
- data/lib/rubyfox/server/data/lib/Lib/markupbase.py +317 -0
- data/lib/rubyfox/server/data/lib/Lib/marshal.py +315 -0
- data/lib/rubyfox/server/data/lib/Lib/mhlib.py +1003 -0
- data/lib/rubyfox/server/data/lib/Lib/mimetools.py +226 -0
- data/lib/rubyfox/server/data/lib/Lib/mimetypes.py +435 -0
- data/lib/rubyfox/server/data/lib/Lib/mimify.py +464 -0
- data/lib/rubyfox/server/data/lib/Lib/multifile.py +160 -0
- data/lib/rubyfox/server/data/lib/Lib/mutex.py +51 -0
- data/lib/rubyfox/server/data/lib/Lib/netrc.py +108 -0
- data/lib/rubyfox/server/data/lib/Lib/nntplib.py +575 -0
- data/lib/rubyfox/server/data/lib/Lib/ntpath.py +482 -0
- data/lib/rubyfox/server/data/lib/Lib/nturl2path.py +66 -0
- data/lib/rubyfox/server/data/lib/Lib/pawt/__init__.py +35 -0
- data/lib/rubyfox/server/data/lib/Lib/pawt/colors.py +144 -0
- data/lib/rubyfox/server/data/lib/Lib/pawt/swing.py +42 -0
- data/lib/rubyfox/server/data/lib/Lib/pdb.py +979 -0
- data/lib/rubyfox/server/data/lib/Lib/pickle.py +990 -0
- data/lib/rubyfox/server/data/lib/Lib/pipes.py +297 -0
- data/lib/rubyfox/server/data/lib/Lib/popen2.py +304 -0
- data/lib/rubyfox/server/data/lib/Lib/poplib.py +335 -0
- data/lib/rubyfox/server/data/lib/Lib/posixfile.py +240 -0
- data/lib/rubyfox/server/data/lib/Lib/posixpath.py +414 -0
- data/lib/rubyfox/server/data/lib/Lib/pprint.py +310 -0
- data/lib/rubyfox/server/data/lib/Lib/profile.py +556 -0
- data/lib/rubyfox/server/data/lib/Lib/pstats.py +641 -0
- data/lib/rubyfox/server/data/lib/Lib/pyclbr.py +337 -0
- data/lib/rubyfox/server/data/lib/Lib/quopri.py +237 -0
- data/lib/rubyfox/server/data/lib/Lib/random$py.class +0 -0
- data/lib/rubyfox/server/data/lib/Lib/random.py +779 -0
- data/lib/rubyfox/server/data/lib/Lib/re$py.class +0 -0
- data/lib/rubyfox/server/data/lib/Lib/re.py +11 -0
- data/lib/rubyfox/server/data/lib/Lib/reconvert.py +192 -0
- data/lib/rubyfox/server/data/lib/Lib/reindex$py.class +0 -0
- data/lib/rubyfox/server/data/lib/Lib/repr.py +95 -0
- data/lib/rubyfox/server/data/lib/Lib/rfc822.py +1010 -0
- data/lib/rubyfox/server/data/lib/Lib/sched.py +106 -0
- data/lib/rubyfox/server/data/lib/Lib/select.py +211 -0
- data/lib/rubyfox/server/data/lib/Lib/servlet-api-2.5-20081211.jar +0 -0
- data/lib/rubyfox/server/data/lib/Lib/setsfactory.py +10 -0
- data/lib/rubyfox/server/data/lib/Lib/sfs2x-lms.jar +0 -0
- data/lib/rubyfox/server/data/lib/Lib/sgmllib.py +516 -0
- data/lib/rubyfox/server/data/lib/Lib/shelve.py +158 -0
- data/lib/rubyfox/server/data/lib/Lib/shlex.py +209 -0
- data/lib/rubyfox/server/data/lib/Lib/shutil$py.class +0 -0
- data/lib/rubyfox/server/data/lib/Lib/shutil.py +138 -0
- data/lib/rubyfox/server/data/lib/Lib/site.py +263 -0
- data/lib/rubyfox/server/data/lib/Lib/smtplib.py +729 -0
- data/lib/rubyfox/server/data/lib/Lib/sndhdr.py +228 -0
- data/lib/rubyfox/server/data/lib/Lib/socket.py +902 -0
- data/lib/rubyfox/server/data/lib/Lib/sre$py.class +0 -0
- data/lib/rubyfox/server/data/lib/Lib/sre.py +311 -0
- data/lib/rubyfox/server/data/lib/Lib/sre_compile$py.class +0 -0
- data/lib/rubyfox/server/data/lib/Lib/sre_compile.py +455 -0
- data/lib/rubyfox/server/data/lib/Lib/sre_constants$py.class +0 -0
- data/lib/rubyfox/server/data/lib/Lib/sre_constants.py +259 -0
- data/lib/rubyfox/server/data/lib/Lib/sre_parse$py.class +0 -0
- data/lib/rubyfox/server/data/lib/Lib/sre_parse.py +738 -0
- data/lib/rubyfox/server/data/lib/Lib/stat$py.class +0 -0
- data/lib/rubyfox/server/data/lib/Lib/stat.py +86 -0
- data/lib/rubyfox/server/data/lib/Lib/string$py.class +0 -0
- data/lib/rubyfox/server/data/lib/Lib/string.py +437 -0
- data/lib/rubyfox/server/data/lib/Lib/symbol.py +95 -0
- data/lib/rubyfox/server/data/lib/Lib/telnetlib.py +662 -0
- data/lib/rubyfox/server/data/lib/Lib/tempfile.py +255 -0
- data/lib/rubyfox/server/data/lib/Lib/test/Graph.py +62 -0
- data/lib/rubyfox/server/data/lib/Lib/test/README +372 -0
- data/lib/rubyfox/server/data/lib/Lib/test/__init__.py +1 -0
- data/lib/rubyfox/server/data/lib/Lib/test/audiotest.au +0 -0
- data/lib/rubyfox/server/data/lib/Lib/test/autotest.py +6 -0
- data/lib/rubyfox/server/data/lib/Lib/test/badsyntax_future3.py +10 -0
- data/lib/rubyfox/server/data/lib/Lib/test/badsyntax_future4.py +10 -0
- data/lib/rubyfox/server/data/lib/Lib/test/badsyntax_future5.py +12 -0
- data/lib/rubyfox/server/data/lib/Lib/test/badsyntax_future6.py +10 -0
- data/lib/rubyfox/server/data/lib/Lib/test/badsyntax_future7.py +11 -0
- data/lib/rubyfox/server/data/lib/Lib/test/badsyntax_nocaret.py +2 -0
- data/lib/rubyfox/server/data/lib/Lib/test/blob.jar +0 -0
- data/lib/rubyfox/server/data/lib/Lib/test/bugs/bugs100.py +139 -0
- data/lib/rubyfox/server/data/lib/Lib/test/bugs/bugs101.py +57 -0
- data/lib/rubyfox/server/data/lib/Lib/test/bugs/jdkbugs.py +10 -0
- data/lib/rubyfox/server/data/lib/Lib/test/bugs/pr101.py +59 -0
- data/lib/rubyfox/server/data/lib/Lib/test/bugs/pr104.py +9 -0
- data/lib/rubyfox/server/data/lib/Lib/test/bugs/pr112.py +14 -0
- data/lib/rubyfox/server/data/lib/Lib/test/bugs/pr119.py +16 -0
- data/lib/rubyfox/server/data/lib/Lib/test/bugs/pr127.py +10 -0
- data/lib/rubyfox/server/data/lib/Lib/test/bugs/pr133/__init__.py +1 -0
- data/lib/rubyfox/server/data/lib/Lib/test/bugs/pr133/test.py +2 -0
- data/lib/rubyfox/server/data/lib/Lib/test/bugs/pr133.py +12 -0
- data/lib/rubyfox/server/data/lib/Lib/test/bugs/pr134.py +9 -0
- data/lib/rubyfox/server/data/lib/Lib/test/bugs/pr139.py +7 -0
- data/lib/rubyfox/server/data/lib/Lib/test/bugs/pr142.py +1 -0
- data/lib/rubyfox/server/data/lib/Lib/test/bugs/pr144.py +2 -0
- data/lib/rubyfox/server/data/lib/Lib/test/bugs/pr148.py +2 -0
- data/lib/rubyfox/server/data/lib/Lib/test/bugs/pr149.py +7 -0
- data/lib/rubyfox/server/data/lib/Lib/test/bugs/pr155.py +13 -0
- data/lib/rubyfox/server/data/lib/Lib/test/bugs/pr170.py +7 -0
- data/lib/rubyfox/server/data/lib/Lib/test/bugs/pr171.py +9 -0
- data/lib/rubyfox/server/data/lib/Lib/test/bugs/pr174.py +9 -0
- data/lib/rubyfox/server/data/lib/Lib/test/bugs/pr178.py +10 -0
- data/lib/rubyfox/server/data/lib/Lib/test/bugs/pr183.py +5 -0
- data/lib/rubyfox/server/data/lib/Lib/test/bugs/pr186.py +10 -0
- data/lib/rubyfox/server/data/lib/Lib/test/bugs/pr191.py +5 -0
- data/lib/rubyfox/server/data/lib/Lib/test/bugs/pr192.py +81 -0
- data/lib/rubyfox/server/data/lib/Lib/test/bugs/pr195.py +11 -0
- data/lib/rubyfox/server/data/lib/Lib/test/bugs/pr208.py +26 -0
- data/lib/rubyfox/server/data/lib/Lib/test/bugs/pr233.py +8 -0
- data/lib/rubyfox/server/data/lib/Lib/test/bugs/pr234.py +16 -0
- data/lib/rubyfox/server/data/lib/Lib/test/bugs/pr235.py +14 -0
- data/lib/rubyfox/server/data/lib/Lib/test/bugs/pr239.py +6 -0
- data/lib/rubyfox/server/data/lib/Lib/test/bugs/pr241.py +16 -0
- data/lib/rubyfox/server/data/lib/Lib/test/bugs/pr242.py +12 -0
- data/lib/rubyfox/server/data/lib/Lib/test/data/PyBanner048.gif +0 -0
- data/lib/rubyfox/server/data/lib/Lib/test/data/msg_01.txt +19 -0
- data/lib/rubyfox/server/data/lib/Lib/test/data/msg_02.txt +135 -0
- data/lib/rubyfox/server/data/lib/Lib/test/data/msg_03.txt +16 -0
- data/lib/rubyfox/server/data/lib/Lib/test/data/msg_04.txt +37 -0
- data/lib/rubyfox/server/data/lib/Lib/test/data/msg_05.txt +28 -0
- data/lib/rubyfox/server/data/lib/Lib/test/data/msg_06.txt +33 -0
- data/lib/rubyfox/server/data/lib/Lib/test/data/msg_07.txt +83 -0
- data/lib/rubyfox/server/data/lib/Lib/test/data/msg_08.txt +24 -0
- data/lib/rubyfox/server/data/lib/Lib/test/data/msg_09.txt +24 -0
- data/lib/rubyfox/server/data/lib/Lib/test/data/msg_10.txt +32 -0
- data/lib/rubyfox/server/data/lib/Lib/test/data/msg_11.txt +7 -0
- data/lib/rubyfox/server/data/lib/Lib/test/data/msg_12.txt +36 -0
- data/lib/rubyfox/server/data/lib/Lib/test/data/msg_13.txt +94 -0
- data/lib/rubyfox/server/data/lib/Lib/test/data/msg_14.txt +23 -0
- data/lib/rubyfox/server/data/lib/Lib/test/data/msg_15.txt +52 -0
- data/lib/rubyfox/server/data/lib/Lib/test/data/msg_16.txt +123 -0
- data/lib/rubyfox/server/data/lib/Lib/test/data/msg_17.txt +12 -0
- data/lib/rubyfox/server/data/lib/Lib/test/data/msg_18.txt +6 -0
- data/lib/rubyfox/server/data/lib/Lib/test/data/msg_19.txt +43 -0
- data/lib/rubyfox/server/data/lib/Lib/test/data/msg_20.txt +22 -0
- data/lib/rubyfox/server/data/lib/Lib/test/data/msg_21.txt +22 -0
- data/lib/rubyfox/server/data/lib/Lib/test/data/msg_22.txt +46 -0
- data/lib/rubyfox/server/data/lib/Lib/test/data/msg_23.txt +8 -0
- data/lib/rubyfox/server/data/lib/Lib/test/double_const.py +30 -0
- data/lib/rubyfox/server/data/lib/Lib/test/greyrgb.uue +1547 -0
- data/lib/rubyfox/server/data/lib/Lib/test/javatests/AnonInner.java +20 -0
- data/lib/rubyfox/server/data/lib/Lib/test/javatests/Foo.java +3 -0
- data/lib/rubyfox/server/data/lib/Lib/test/javatests/JOverload.java +132 -0
- data/lib/rubyfox/server/data/lib/Lib/test/javatests/ListTest.java +638 -0
- data/lib/rubyfox/server/data/lib/Lib/test/javatests/SubFoo.java +3 -0
- data/lib/rubyfox/server/data/lib/Lib/test/javatests/TestSupport.java +49 -0
- data/lib/rubyfox/server/data/lib/Lib/test/javatests/__init__.py +0 -0
- data/lib/rubyfox/server/data/lib/Lib/test/jser2_classes.py +47 -0
- data/lib/rubyfox/server/data/lib/Lib/test/output/test_MimeWriter +110 -0
- data/lib/rubyfox/server/data/lib/Lib/test/output/test_array +4 -0
- data/lib/rubyfox/server/data/lib/Lib/test/output/test_asynchat +3 -0
- data/lib/rubyfox/server/data/lib/Lib/test/output/test_augassign +51 -0
- data/lib/rubyfox/server/data/lib/Lib/test/output/test_binascii +29 -0
- data/lib/rubyfox/server/data/lib/Lib/test/output/test_builtin +53 -0
- data/lib/rubyfox/server/data/lib/Lib/test/output/test_cfgparser +9 -0
- data/lib/rubyfox/server/data/lib/Lib/test/output/test_cgi +29 -0
- data/lib/rubyfox/server/data/lib/Lib/test/output/test_charmapcodec +16 -0
- data/lib/rubyfox/server/data/lib/Lib/test/output/test_class +101 -0
- data/lib/rubyfox/server/data/lib/Lib/test/output/test_coercion +1054 -0
- data/lib/rubyfox/server/data/lib/Lib/test/output/test_compare +101 -0
- data/lib/rubyfox/server/data/lib/Lib/test/output/test_compile +7 -0
- data/lib/rubyfox/server/data/lib/Lib/test/output/test_cookie +32 -0
- data/lib/rubyfox/server/data/lib/Lib/test/output/test_exceptions +52 -0
- data/lib/rubyfox/server/data/lib/Lib/test/output/test_extcall +112 -0
- data/lib/rubyfox/server/data/lib/Lib/test/output/test_frozen +4 -0
- data/lib/rubyfox/server/data/lib/Lib/test/output/test_future +9 -0
- data/lib/rubyfox/server/data/lib/Lib/test/output/test_gettext +46 -0
- data/lib/rubyfox/server/data/lib/Lib/test/output/test_global +5 -0
- data/lib/rubyfox/server/data/lib/Lib/test/output/test_grammar +66 -0
- data/lib/rubyfox/server/data/lib/Lib/test/output/test_httplib +10 -0
- data/lib/rubyfox/server/data/lib/Lib/test/output/test_janoninner +5 -0
- data/lib/rubyfox/server/data/lib/Lib/test/output/test_javalist +6 -0
- data/lib/rubyfox/server/data/lib/Lib/test/output/test_jbasic +13 -0
- data/lib/rubyfox/server/data/lib/Lib/test/output/test_jser +12 -0
- data/lib/rubyfox/server/data/lib/Lib/test/output/test_jsubclass +5 -0
- data/lib/rubyfox/server/data/lib/Lib/test/output/test_linuxaudiodev +7 -0
- data/lib/rubyfox/server/data/lib/Lib/test/output/test_longexp +2 -0
- data/lib/rubyfox/server/data/lib/Lib/test/output/test_math +26 -0
- data/lib/rubyfox/server/data/lib/Lib/test/output/test_md5 +9 -0
- data/lib/rubyfox/server/data/lib/Lib/test/output/test_methods +6 -0
- data/lib/rubyfox/server/data/lib/Lib/test/output/test_mimetools +5 -0
- data/lib/rubyfox/server/data/lib/Lib/test/output/test_mmap +34 -0
- data/lib/rubyfox/server/data/lib/Lib/test/output/test_new +7 -0
- data/lib/rubyfox/server/data/lib/Lib/test/output/test_nis +2 -0
- data/lib/rubyfox/server/data/lib/Lib/test/output/test_opcodes +4 -0
- data/lib/rubyfox/server/data/lib/Lib/test/output/test_openpty +2 -0
- data/lib/rubyfox/server/data/lib/Lib/test/output/test_operations +28 -0
- data/lib/rubyfox/server/data/lib/Lib/test/output/test_pkg +45 -0
- data/lib/rubyfox/server/data/lib/Lib/test/output/test_poll +17 -0
- data/lib/rubyfox/server/data/lib/Lib/test/output/test_popen2 +9 -0
- data/lib/rubyfox/server/data/lib/Lib/test/output/test_posixpath +2 -0
- data/lib/rubyfox/server/data/lib/Lib/test/output/test_pow +17 -0
- data/lib/rubyfox/server/data/lib/Lib/test/output/test_profile +17 -0
- data/lib/rubyfox/server/data/lib/Lib/test/output/test_pty +3 -0
- data/lib/rubyfox/server/data/lib/Lib/test/output/test_pwd +7 -0
- data/lib/rubyfox/server/data/lib/Lib/test/output/test_pyexpat +110 -0
- data/lib/rubyfox/server/data/lib/Lib/test/output/test_re +15 -0
- data/lib/rubyfox/server/data/lib/Lib/test/output/test_regex +29 -0
- data/lib/rubyfox/server/data/lib/Lib/test/output/test_rgbimg +2 -0
- data/lib/rubyfox/server/data/lib/Lib/test/output/test_richcmp +187 -0
- data/lib/rubyfox/server/data/lib/Lib/test/output/test_rotor +5 -0
- data/lib/rubyfox/server/data/lib/Lib/test/output/test_scope +24 -0
- data/lib/rubyfox/server/data/lib/Lib/test/output/test_signal +2 -0
- data/lib/rubyfox/server/data/lib/Lib/test/output/test_string +18 -0
- data/lib/rubyfox/server/data/lib/Lib/test/output/test_thread +4 -0
- data/lib/rubyfox/server/data/lib/Lib/test/output/test_threadedtempfile +5 -0
- data/lib/rubyfox/server/data/lib/Lib/test/output/test_time +9 -0
- data/lib/rubyfox/server/data/lib/Lib/test/output/test_tokenize +648 -0
- data/lib/rubyfox/server/data/lib/Lib/test/output/test_types +15 -0
- data/lib/rubyfox/server/data/lib/Lib/test/output/test_ucn +7 -0
- data/lib/rubyfox/server/data/lib/Lib/test/output/test_unicode +21 -0
- data/lib/rubyfox/server/data/lib/Lib/test/output/test_unicode_file +2 -0
- data/lib/rubyfox/server/data/lib/Lib/test/output/test_unicodedata +5 -0
- data/lib/rubyfox/server/data/lib/Lib/test/output/test_unpack +15 -0
- data/lib/rubyfox/server/data/lib/Lib/test/output/test_urlparse +47 -0
- data/lib/rubyfox/server/data/lib/Lib/test/output/test_winreg +3 -0
- data/lib/rubyfox/server/data/lib/Lib/test/output/test_winsound +2 -0
- data/lib/rubyfox/server/data/lib/Lib/test/output/test_xreadline +4 -0
- data/lib/rubyfox/server/data/lib/Lib/test/pickletester.py +285 -0
- data/lib/rubyfox/server/data/lib/Lib/test/pydocfodder.py +210 -0
- data/lib/rubyfox/server/data/lib/Lib/test/pystone.py +252 -0
- data/lib/rubyfox/server/data/lib/Lib/test/re_tests.py +590 -0
- data/lib/rubyfox/server/data/lib/Lib/test/regex_tests.py +287 -0
- data/lib/rubyfox/server/data/lib/Lib/test/regrtest.py +1096 -0
- data/lib/rubyfox/server/data/lib/Lib/test/reperf.py +23 -0
- data/lib/rubyfox/server/data/lib/Lib/test/sortperf.py +141 -0
- data/lib/rubyfox/server/data/lib/Lib/test/string_tests.py +265 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test.xml +115 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test.xml.out +115 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_MimeWriter.py +170 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_SimpleXMLRPCServer.py +88 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_StringIO.py +113 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test___all__.py +158 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test___future__.py +59 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_al.py +23 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_array.py +438 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_asynchat.py +58 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_atexit.py +66 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_audioop.py +264 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_augassign.py +261 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_b1.py +632 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_b2.py +365 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_base64.py +53 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_bastion.py +3 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_binascii.py +119 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_binhex.py +50 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_binop.py +328 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_bisect.py +127 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_bsddb.py +76 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_bufio.py +60 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_bugfixes.py +31 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_builtin.py +13 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_calendar.py +61 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_call.py +131 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_capi.py +16 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_cd.py +26 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_cfgparser.py +284 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_cgi.py +188 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_charmapcodec.py +43 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_cl.py +78 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_class.py +317 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_cmath.py +35 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_codecs.py +31 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_codeop.py +190 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_coercion.py +118 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_commands.py +52 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_compare.py +56 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_compile.py +129 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_complex.py +68 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_contains.py +133 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_cookie.py +47 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_copy_reg.py +30 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_cpickle.py +81 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_crypt.py +11 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_curses.py +210 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_datetime.py +2958 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_dbm.py +43 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_descr.py +4094 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_descrtut.py +501 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_difflib.py +2 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_dircache.py +74 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_dl.py +33 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_doctest.py +2 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_doctest2.py +108 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_dospath.py +61 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_dumbdbm.py +79 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_email.py +13 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_email_codecs.py +11 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_enumerate.py +150 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_errno.py +49 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_exceptions.py +206 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_extcall.py +268 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_fcntl.py +53 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_file.py +63 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_fileinput.py +159 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_fnmatch.py +46 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_fork1.py +75 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_format.py +218 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_fpformat.py +75 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_frozen.py +26 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_funcattrs.py +384 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_future.py +47 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_future1.py +11 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_future2.py +10 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_future3.py +11 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_gc.py +346 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_gdbm.py +46 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_generators.py +1385 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_getargs.py +26 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_getopt.py +110 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_gettext.py +200 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_gl.py +150 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_glob.py +115 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_global.py +51 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_grammar.py +732 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_grp.py +27 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_gzip.py +82 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_hash.py +36 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_hmac.py +108 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_hotshot.py +117 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_htmllib.py +42 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_htmlparser.py +294 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_httplib.py +58 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_imageop.py +171 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_imgfile.py +116 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_import.py +71 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_importhooks.py +215 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_inspect.py +365 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_iter.py +784 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_janoninner.py +15 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_javalist.py +53 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_javashell.py +182 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_jbasic.py +119 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_joverload.py +138 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_jreload.py +33 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_jser.py +57 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_jser2.py +93 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_jsubclass.py +49 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_jy_compile.py +168 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_jy_generators.py +165 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_jy_internals.py +130 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_largefile.py +169 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_linuxaudiodev.py +89 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_locale.py +44 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_long.py +445 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_long_future.py +55 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_long_int_args.py +61 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_longexp.py +16 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_mailbox.py +113 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_marshal.py +44 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_math.py +153 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_md5.py +30 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_methods.py +62 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_mhlib.py +353 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_mimetools.py +18 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_mimetypes.py +59 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_minidom.py +648 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_mmap.py +317 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_module.py +77 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_multifile.py +66 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_mutants.py +285 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_netrc.py +42 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_new.py +108 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_nis.py +32 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_ntpath.py +114 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_opcodes.py +65 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_openpty.py +21 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_operations.py +475 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_operator.py +218 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_os.py +187 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_parser.py +383 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_pep247.py +50 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_pickle.py +40 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_pkg.py +259 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_pkgimport.py +84 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_poll.py +3 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_popen2.py +72 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_posixpath.py +40 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_pow.py +107 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_pprint.py +104 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_profile.py +86 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_profilehooks.py +360 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_pty.py +98 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_pwd.py +71 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_pyclbr.py +154 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_pyexpat.py +202 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_queue.py +158 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_quopri.py +157 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_random.py +19 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_re.py +304 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_regex.py +113 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_repr.py +278 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_rfc822.py +211 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_rgbimg.py +63 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_richcmp.py +261 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_rotor.py +28 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_sax.py +727 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_scope.py +530 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_select.py +228 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_select_new.py +229 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_sets.py +793 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_sgmllib.py +314 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_sha.py +52 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_signal.py +66 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_socket.py +1116 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_socket_ssl.py +27 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_socketserver.py +165 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_sre.py +434 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_str2unicode.py +90 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_strftime.py +146 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_string.py +223 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_strop.py +133 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_struct.py +441 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_structseq.py +28 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_subclasses.py +204 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_sunaudiodev.py +28 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_sundry.py +102 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_support.py +265 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_symtable.py +8 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_tempfile.py +10 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_thread.py +116 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_threaded_import.py +56 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_threadedtempfile.py +86 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_threading.py +55 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_time.py +47 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_timing.py +21 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_tokenize.py +9 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_trace.py +219 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_traceback.py +49 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_types.py +762 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_ucn.py +113 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_unary.py +58 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_unicode.py +815 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_unicode_file.py +95 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_unicodedata.py +125 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_unpack.py +105 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_urllib.py +109 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_urllib2.py +31 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_urlparse.py +94 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_userdict.py +120 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_userlist.py +269 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_userstring.py +43 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_uu.py +158 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_wave.py +34 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_weakref.py +573 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_winreg.py +151 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_winsound.py +6 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_xmllib.py +35 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_xmlrpc.py +37 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_xreadline.py +43 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_zipfile.py +78 -0
- data/lib/rubyfox/server/data/lib/Lib/test/test_zlib.py +482 -0
- data/lib/rubyfox/server/data/lib/Lib/test/testall.py +43 -0
- data/lib/rubyfox/server/data/lib/Lib/test/testcodec.py +48 -0
- data/lib/rubyfox/server/data/lib/Lib/test/testimg.uue +1170 -0
- data/lib/rubyfox/server/data/lib/Lib/test/testimgr.uue +1170 -0
- data/lib/rubyfox/server/data/lib/Lib/test/testrgb.uue +971 -0
- data/lib/rubyfox/server/data/lib/Lib/test/tokenize_tests.py +175 -0
- data/lib/rubyfox/server/data/lib/Lib/test/whrandom.py +96 -0
- data/lib/rubyfox/server/data/lib/Lib/test/zxjdbc/dbextstest.py +266 -0
- data/lib/rubyfox/server/data/lib/Lib/test/zxjdbc/jndi.py +33 -0
- data/lib/rubyfox/server/data/lib/Lib/test/zxjdbc/runner.py +204 -0
- data/lib/rubyfox/server/data/lib/Lib/test/zxjdbc/sptest.py +227 -0
- data/lib/rubyfox/server/data/lib/Lib/test/zxjdbc/test.xml +363 -0
- data/lib/rubyfox/server/data/lib/Lib/test/zxjdbc/test_zxjdbc_dbapi20.py +26 -0
- data/lib/rubyfox/server/data/lib/Lib/test/zxjdbc/zxtest.py +1242 -0
- data/lib/rubyfox/server/data/lib/Lib/this.py +28 -0
- data/lib/rubyfox/server/data/lib/Lib/threading.py +698 -0
- data/lib/rubyfox/server/data/lib/Lib/token$py.class +0 -0
- data/lib/rubyfox/server/data/lib/Lib/token.py +140 -0
- data/lib/rubyfox/server/data/lib/Lib/tokenize$py.class +0 -0
- data/lib/rubyfox/server/data/lib/Lib/tokenize.py +287 -0
- data/lib/rubyfox/server/data/lib/Lib/traceback$py.class +0 -0
- data/lib/rubyfox/server/data/lib/Lib/traceback.py +301 -0
- data/lib/rubyfox/server/data/lib/Lib/tzparse.py +98 -0
- data/lib/rubyfox/server/data/lib/Lib/unittest.py +723 -0
- data/lib/rubyfox/server/data/lib/Lib/urllib.py +1465 -0
- data/lib/rubyfox/server/data/lib/Lib/urllib2.py +1144 -0
- data/lib/rubyfox/server/data/lib/Lib/urlparse.py +276 -0
- data/lib/rubyfox/server/data/lib/Lib/user.py +45 -0
- data/lib/rubyfox/server/data/lib/Lib/uu.py +195 -0
- data/lib/rubyfox/server/data/lib/Lib/warnings$py.class +0 -0
- data/lib/rubyfox/server/data/lib/Lib/warnings.py +258 -0
- data/lib/rubyfox/server/data/lib/Lib/weakref.py +280 -0
- data/lib/rubyfox/server/data/lib/Lib/whichdb.py +87 -0
- data/lib/rubyfox/server/data/lib/Lib/whrandom.py +140 -0
- data/lib/rubyfox/server/data/lib/Lib/xdrlib.py +285 -0
- data/lib/rubyfox/server/data/lib/Lib/xml/FtCore.py +58 -0
- data/lib/rubyfox/server/data/lib/Lib/xml/Uri.py +380 -0
- data/lib/rubyfox/server/data/lib/Lib/xml/__init__.py +41 -0
- data/lib/rubyfox/server/data/lib/Lib/xml/dom/MessageSource.py +54 -0
- data/lib/rubyfox/server/data/lib/Lib/xml/dom/NodeFilter.py +27 -0
- data/lib/rubyfox/server/data/lib/Lib/xml/dom/__init__.py +232 -0
- data/lib/rubyfox/server/data/lib/Lib/xml/dom/domreg.py +99 -0
- data/lib/rubyfox/server/data/lib/Lib/xml/dom/minicompat.py +184 -0
- data/lib/rubyfox/server/data/lib/Lib/xml/dom/minidom.py +1943 -0
- data/lib/rubyfox/server/data/lib/Lib/xml/dom/pulldom.py +350 -0
- data/lib/rubyfox/server/data/lib/Lib/xml/dom/xmlbuilder.py +388 -0
- data/lib/rubyfox/server/data/lib/Lib/xml/sax/__init__.py +102 -0
- data/lib/rubyfox/server/data/lib/Lib/xml/sax/_exceptions.py +127 -0
- data/lib/rubyfox/server/data/lib/Lib/xml/sax/drivers2/__init__.py +1 -0
- data/lib/rubyfox/server/data/lib/Lib/xml/sax/drivers2/drv_javasax.py +333 -0
- data/lib/rubyfox/server/data/lib/Lib/xml/sax/handler.py +345 -0
- data/lib/rubyfox/server/data/lib/Lib/xml/sax/saxlib.py +430 -0
- data/lib/rubyfox/server/data/lib/Lib/xml/sax/saxutils.py +813 -0
- data/lib/rubyfox/server/data/lib/Lib/xml/sax/xmlreader.py +378 -0
- data/lib/rubyfox/server/data/lib/Lib/xmllib.py +926 -0
- data/lib/rubyfox/server/data/lib/Lib/xmlrpclib.py +1019 -0
- data/lib/rubyfox/server/data/lib/Lib/zipfile.py +586 -0
- data/lib/rubyfox/server/data/lib/Lib/zlib.py +156 -0
- data/lib/rubyfox/server/data/lib/boot.jar +0 -0
- data/lib/rubyfox/server/data/lib/cachedir/.keep +0 -0
- data/lib/rubyfox/server/data/lib/commons-beanutils-1.7.0.jar +0 -0
- data/lib/rubyfox/server/data/lib/commons-collections-3.2.1.jar +0 -0
- data/lib/rubyfox/server/data/lib/commons-dbcp-1.4.jar +0 -0
- data/lib/rubyfox/server/data/lib/commons-io-1.4.jar +0 -0
- data/lib/rubyfox/server/data/lib/commons-lang-2.4.jar +0 -0
- data/lib/rubyfox/server/data/lib/commons-logging-1.1.1.jar +0 -0
- data/lib/rubyfox/server/data/lib/commons-pool-1.5.4.jar +0 -0
- data/lib/rubyfox/server/data/lib/commons-vfs-1.0.jar +0 -0
- data/lib/rubyfox/server/data/lib/ezmorph-1.0.6.jar +0 -0
- data/lib/rubyfox/server/data/lib/httpclient-4.0.3.jar +0 -0
- data/lib/rubyfox/server/data/lib/httpcore-4.0.1.jar +0 -0
- data/lib/rubyfox/server/data/lib/imap.jar +0 -0
- data/lib/rubyfox/server/data/lib/jconsole/COPYING.txt +504 -0
- data/lib/rubyfox/server/data/lib/jconsole/bug_test_case.py +49 -0
- data/lib/rubyfox/server/data/lib/jconsole/console$py.class +0 -0
- data/lib/rubyfox/server/data/lib/jconsole/console.py +439 -0
- data/lib/rubyfox/server/data/lib/jconsole/history$py.class +0 -0
- data/lib/rubyfox/server/data/lib/jconsole/history.py +82 -0
- data/lib/rubyfox/server/data/lib/jconsole/history_test_case.py +133 -0
- data/lib/rubyfox/server/data/lib/jconsole/introspect$py.class +0 -0
- data/lib/rubyfox/server/data/lib/jconsole/introspect.py +373 -0
- data/lib/rubyfox/server/data/lib/jconsole/introspect_test_case.py +19 -0
- data/lib/rubyfox/server/data/lib/jconsole/issue_17_test_case.py +36 -0
- data/lib/rubyfox/server/data/lib/jconsole/jintrospect$py.class +0 -0
- data/lib/rubyfox/server/data/lib/jconsole/jintrospect.py +316 -0
- data/lib/rubyfox/server/data/lib/jconsole/jintrospect_test_case.py +107 -0
- data/lib/rubyfox/server/data/lib/jconsole/popup$py.class +0 -0
- data/lib/rubyfox/server/data/lib/jconsole/popup.py +178 -0
- data/lib/rubyfox/server/data/lib/jconsole/run_tests.py +8 -0
- data/lib/rubyfox/server/data/lib/jconsole/static_test_case.py +36 -0
- data/lib/rubyfox/server/data/lib/jconsole/testcase.py +38 -0
- data/lib/rubyfox/server/data/lib/jconsole/tip$py.class +0 -0
- data/lib/rubyfox/server/data/lib/jconsole/tip.py +47 -0
- data/lib/rubyfox/server/data/lib/jmx-util-1.2.3.jar +0 -0
- data/lib/rubyfox/server/data/lib/joda-time-1.6.jar +0 -0
- data/lib/rubyfox/server/data/lib/js.jar +0 -0
- data/lib/rubyfox/server/data/lib/json-lib-2.2.3-jdk15.jar +0 -0
- data/lib/rubyfox/server/data/lib/jython.jar +0 -0
- data/lib/rubyfox/server/data/lib/log4j-1.2.15.jar +0 -0
- data/lib/rubyfox/server/data/lib/logs-backup-app.jar +0 -0
- data/lib/rubyfox/server/data/lib/mailapi.jar +0 -0
- data/lib/rubyfox/server/data/lib/pop3.jar +0 -0
- data/lib/rubyfox/server/data/lib/scala-library.jar +0 -0
- data/lib/rubyfox/server/data/lib/sfs2x-admin.jar +0 -0
- data/lib/rubyfox/server/data/lib/sfs2x-core.jar +0 -0
- data/lib/rubyfox/server/data/lib/sfs2x-util.jar +0 -0
- data/lib/rubyfox/server/data/lib/sfs2x.jar +0 -0
- data/lib/rubyfox/server/data/lib/slf4j-api-1.5.10.jar +0 -0
- data/lib/rubyfox/server/data/lib/slf4j-log4j12.jar +0 -0
- data/lib/rubyfox/server/data/lib/smtp.jar +0 -0
- data/lib/rubyfox/server/data/lib/terracotta-api-1.1.1.jar +0 -0
- data/lib/rubyfox/server/data/lib/ws-engine.jar +0 -0
- data/lib/rubyfox/server/data/lib/xpp3_min-1.1.4c.jar +0 -0
- data/lib/rubyfox/server/data/lib/xstream-1.3.1.jar +0 -0
- data/lib/rubyfox/server/data/logs/.keep +0 -0
- data/lib/rubyfox/server/data/logs/bluebox/.keep +0 -0
- data/lib/rubyfox/server/data/logs/boot/.keep +0 -0
- data/lib/rubyfox/server/data/logs/http/.keep +0 -0
- data/lib/rubyfox/server/data/logs/smartfox.log +295 -0
- data/lib/rubyfox/server/data/root/.keep +0 -0
- data/lib/rubyfox/server/data/root/_css_/default.css +170 -0
- data/lib/rubyfox/server/data/root/_css_/reset.css +49 -0
- data/lib/rubyfox/server/data/root/_images_/background_gradient.png +0 -0
- data/lib/rubyfox/server/data/root/_images_/background_logo.png +0 -0
- data/lib/rubyfox/server/data/root/_images_/favicon.png +0 -0
- data/lib/rubyfox/server/data/root/_images_/logo_smartfoxserver.png +0 -0
- data/lib/rubyfox/server/data/root/admin/.keep +0 -0
- data/lib/rubyfox/server/data/root/admin/AdminTool.html +108 -0
- data/lib/rubyfox/server/data/root/admin/AdminTool.swf +0 -0
- data/lib/rubyfox/server/data/root/admin/ReleaseNotes.txt +29 -0
- data/lib/rubyfox/server/data/root/admin/assets/icons/tabs/adobeFlashPlayer.png +0 -0
- data/lib/rubyfox/server/data/root/admin/assets/icons/tabs/advanced.png +0 -0
- data/lib/rubyfox/server/data/root/admin/assets/icons/tabs/banManager.png +0 -0
- data/lib/rubyfox/server/data/root/admin/assets/icons/tabs/bannedIPs.png +0 -0
- data/lib/rubyfox/server/data/root/admin/assets/icons/tabs/bannedUsernames.png +0 -0
- data/lib/rubyfox/server/data/root/admin/assets/icons/tabs/bookmarks.png +0 -0
- data/lib/rubyfox/server/data/root/admin/assets/icons/tabs/bootLog.png +0 -0
- data/lib/rubyfox/server/data/root/admin/assets/icons/tabs/buddyList.png +0 -0
- data/lib/rubyfox/server/data/root/admin/assets/icons/tabs/buddyProperties.png +0 -0
- data/lib/rubyfox/server/data/root/admin/assets/icons/tabs/connection.png +0 -0
- data/lib/rubyfox/server/data/root/admin/assets/icons/tabs/databaseManager.png +0 -0
- data/lib/rubyfox/server/data/root/admin/assets/icons/tabs/floodFilter.png +0 -0
- data/lib/rubyfox/server/data/root/admin/assets/icons/tabs/gameSettings.png +0 -0
- data/lib/rubyfox/server/data/root/admin/assets/icons/tabs/general.png +0 -0
- data/lib/rubyfox/server/data/root/admin/assets/icons/tabs/globalServerStatus.png +0 -0
- data/lib/rubyfox/server/data/root/admin/assets/icons/tabs/iPFilter.png +0 -0
- data/lib/rubyfox/server/data/root/admin/assets/icons/tabs/jVMSettings.png +0 -0
- data/lib/rubyfox/server/data/root/admin/assets/icons/tabs/logsDownload.png +0 -0
- data/lib/rubyfox/server/data/root/admin/assets/icons/tabs/mailer.png +0 -0
- data/lib/rubyfox/server/data/root/admin/assets/icons/tabs/permissionsAndEvents.png +0 -0
- data/lib/rubyfox/server/data/root/admin/assets/icons/tabs/privilegeManager.png +0 -0
- data/lib/rubyfox/server/data/root/admin/assets/icons/tabs/remoteAdmin.png +0 -0
- data/lib/rubyfox/server/data/root/admin/assets/icons/tabs/roomExtension.png +0 -0
- data/lib/rubyfox/server/data/root/admin/assets/icons/tabs/roomVariables.png +0 -0
- data/lib/rubyfox/server/data/root/admin/assets/icons/tabs/roomsAndGroups.png +0 -0
- data/lib/rubyfox/server/data/root/admin/assets/icons/tabs/runtimeLog.png +0 -0
- data/lib/rubyfox/server/data/root/admin/assets/icons/tabs/runtimeRoomSettings.png +0 -0
- data/lib/rubyfox/server/data/root/admin/assets/icons/tabs/runtimeUserSettings.png +0 -0
- data/lib/rubyfox/server/data/root/admin/assets/icons/tabs/runtimeZoneSettings.png +0 -0
- data/lib/rubyfox/server/data/root/admin/assets/icons/tabs/systemQueueStatus.png +0 -0
- data/lib/rubyfox/server/data/root/admin/assets/icons/tabs/userManagement.png +0 -0
- data/lib/rubyfox/server/data/root/admin/assets/icons/tabs/userVariables.png +0 -0
- data/lib/rubyfox/server/data/root/admin/assets/icons/tabs/usersTraffic.png +0 -0
- data/lib/rubyfox/server/data/root/admin/assets/icons/tabs/webServer.png +0 -0
- data/lib/rubyfox/server/data/root/admin/assets/icons/tabs/wordsFilter.png +0 -0
- data/lib/rubyfox/server/data/root/admin/assets/icons/tabs/zoneExtension.png +0 -0
- data/lib/rubyfox/server/data/root/admin/index.html +108 -0
- data/lib/rubyfox/server/data/root/admin/modules/BanManager/BanManager.swf +0 -0
- data/lib/rubyfox/server/data/root/admin/modules/BanManager/icon.png +0 -0
- data/lib/rubyfox/server/data/root/admin/modules/BlueBoxMonitor/BlueBoxMonitor.swf +0 -0
- data/lib/rubyfox/server/data/root/admin/modules/BlueBoxMonitor/icon.png +0 -0
- data/lib/rubyfox/server/data/root/admin/modules/LicenseManager/LicenseManager.swf +0 -0
- data/lib/rubyfox/server/data/root/admin/modules/LicenseManager/icon.png +0 -0
- data/lib/rubyfox/server/data/root/admin/modules/LogViewer/LogViewer.swf +0 -0
- data/lib/rubyfox/server/data/root/admin/modules/LogViewer/icon.png +0 -0
- data/lib/rubyfox/server/data/root/admin/modules/RuntimeStatistics/RuntimeStatistics.swf +0 -0
- data/lib/rubyfox/server/data/root/admin/modules/RuntimeStatistics/icon.png +0 -0
- data/lib/rubyfox/server/data/root/admin/modules/ServerConfigurator/ServerConfigurator.swf +0 -0
- data/lib/rubyfox/server/data/root/admin/modules/ServerConfigurator/icon.png +0 -0
- data/lib/rubyfox/server/data/root/admin/modules/ZoneConfigurator/ZoneConfigurator.swf +0 -0
- data/lib/rubyfox/server/data/root/admin/modules/ZoneConfigurator/icon.png +0 -0
- data/lib/rubyfox/server/data/root/admin/modules/ZoneMonitor/ZoneMonitor.swf +0 -0
- data/lib/rubyfox/server/data/root/admin/modules/ZoneMonitor/icon.png +0 -0
- data/lib/rubyfox/server/data/root/admin/modules/config.xml +12 -0
- data/lib/rubyfox/server/data/root/admin/playerProductInstall.swf +0 -0
- data/lib/rubyfox/server/data/root/admin/swfobject.js +777 -0
- data/lib/rubyfox/server/data/root/crossdomain.xml +6 -0
- data/lib/rubyfox/server/data/root/index.html +63 -0
- data/lib/rubyfox/server/data/sfs2x-service +435 -0
- data/lib/rubyfox/server/data/sfs2x-service.vmoptions +5 -0
- data/lib/rubyfox/server/data/sfs2x.sh +12 -0
- data/lib/rubyfox/server/data/www/.keep +0 -0
- data/lib/rubyfox/server/data/www/BlueBox.war +0 -0
- data/lib/rubyfox/server/data/www/root/_css_/default.css +170 -0
- data/lib/rubyfox/server/data/www/root/_css_/reset.css +49 -0
- data/lib/rubyfox/server/data/www/root/_images_/background_gradient.png +0 -0
- data/lib/rubyfox/server/data/www/root/_images_/background_logo.png +0 -0
- data/lib/rubyfox/server/data/www/root/_images_/favicon.png +0 -0
- data/lib/rubyfox/server/data/www/root/_images_/logo_smartfoxserver.png +0 -0
- data/lib/rubyfox/server/data/www/root/admin/.keep +0 -0
- data/lib/rubyfox/server/data/www/root/admin/AdminTool.html +108 -0
- data/lib/rubyfox/server/data/www/root/admin/AdminTool.swf +0 -0
- data/lib/rubyfox/server/data/www/root/admin/ReleaseNotes.txt +63 -0
- data/lib/rubyfox/server/data/www/root/admin/assets/icons/tabs/adobeFlashPlayer.png +0 -0
- data/lib/rubyfox/server/data/www/root/admin/assets/icons/tabs/advanced.png +0 -0
- data/lib/rubyfox/server/data/www/root/admin/assets/icons/tabs/banManager.png +0 -0
- data/lib/rubyfox/server/data/www/root/admin/assets/icons/tabs/bannedIPs.png +0 -0
- data/lib/rubyfox/server/data/www/root/admin/assets/icons/tabs/bannedUsernames.png +0 -0
- data/lib/rubyfox/server/data/www/root/admin/assets/icons/tabs/bookmarks.png +0 -0
- data/lib/rubyfox/server/data/www/root/admin/assets/icons/tabs/bootLog.png +0 -0
- data/lib/rubyfox/server/data/www/root/admin/assets/icons/tabs/buddyList.png +0 -0
- data/lib/rubyfox/server/data/www/root/admin/assets/icons/tabs/buddyProperties.png +0 -0
- data/lib/rubyfox/server/data/www/root/admin/assets/icons/tabs/connection.png +0 -0
- data/lib/rubyfox/server/data/www/root/admin/assets/icons/tabs/databaseManager.png +0 -0
- data/lib/rubyfox/server/data/www/root/admin/assets/icons/tabs/floodFilter.png +0 -0
- data/lib/rubyfox/server/data/www/root/admin/assets/icons/tabs/gameSettings.png +0 -0
- data/lib/rubyfox/server/data/www/root/admin/assets/icons/tabs/general.png +0 -0
- data/lib/rubyfox/server/data/www/root/admin/assets/icons/tabs/globalServerStatus.png +0 -0
- data/lib/rubyfox/server/data/www/root/admin/assets/icons/tabs/hTML5WebSockets.png +0 -0
- data/lib/rubyfox/server/data/www/root/admin/assets/icons/tabs/iPFilter.png +0 -0
- data/lib/rubyfox/server/data/www/root/admin/assets/icons/tabs/jVMSettings.png +0 -0
- data/lib/rubyfox/server/data/www/root/admin/assets/icons/tabs/logsDownload.png +0 -0
- data/lib/rubyfox/server/data/www/root/admin/assets/icons/tabs/mailer.png +0 -0
- data/lib/rubyfox/server/data/www/root/admin/assets/icons/tabs/permissionsAndEvents.png +0 -0
- data/lib/rubyfox/server/data/www/root/admin/assets/icons/tabs/privilegeManager.png +0 -0
- data/lib/rubyfox/server/data/www/root/admin/assets/icons/tabs/remoteAdmin.png +0 -0
- data/lib/rubyfox/server/data/www/root/admin/assets/icons/tabs/roomExtension.png +0 -0
- data/lib/rubyfox/server/data/www/root/admin/assets/icons/tabs/roomVariables.png +0 -0
- data/lib/rubyfox/server/data/www/root/admin/assets/icons/tabs/roomsAndGroups.png +0 -0
- data/lib/rubyfox/server/data/www/root/admin/assets/icons/tabs/runtimeLog.png +0 -0
- data/lib/rubyfox/server/data/www/root/admin/assets/icons/tabs/runtimeRoomSettings.png +0 -0
- data/lib/rubyfox/server/data/www/root/admin/assets/icons/tabs/runtimeUserSettings.png +0 -0
- data/lib/rubyfox/server/data/www/root/admin/assets/icons/tabs/runtimeZoneSettings.png +0 -0
- data/lib/rubyfox/server/data/www/root/admin/assets/icons/tabs/systemQueueStatus.png +0 -0
- data/lib/rubyfox/server/data/www/root/admin/assets/icons/tabs/userManagement.png +0 -0
- data/lib/rubyfox/server/data/www/root/admin/assets/icons/tabs/userVariables.png +0 -0
- data/lib/rubyfox/server/data/www/root/admin/assets/icons/tabs/usersTraffic.png +0 -0
- data/lib/rubyfox/server/data/www/root/admin/assets/icons/tabs/webServer.png +0 -0
- data/lib/rubyfox/server/data/www/root/admin/assets/icons/tabs/wordsFilter.png +0 -0
- data/lib/rubyfox/server/data/www/root/admin/assets/icons/tabs/zoneExtension.png +0 -0
- data/lib/rubyfox/server/data/www/root/admin/index.html +108 -0
- data/lib/rubyfox/server/data/www/root/admin/modules/BanManager/BanManager.swf +0 -0
- data/lib/rubyfox/server/data/www/root/admin/modules/BanManager/icon.png +0 -0
- data/lib/rubyfox/server/data/www/root/admin/modules/BlueBoxMonitor/BlueBoxMonitor.swf +0 -0
- data/lib/rubyfox/server/data/www/root/admin/modules/BlueBoxMonitor/icon.png +0 -0
- data/lib/rubyfox/server/data/www/root/admin/modules/Dashboard/Dashboard.swf +0 -0
- data/lib/rubyfox/server/data/www/root/admin/modules/Dashboard/icon.png +0 -0
- data/lib/rubyfox/server/data/www/root/admin/modules/LicenseManager/LicenseManager.swf +0 -0
- data/lib/rubyfox/server/data/www/root/admin/modules/LicenseManager/icon.png +0 -0
- data/lib/rubyfox/server/data/www/root/admin/modules/LogViewer/LogViewer.swf +0 -0
- data/lib/rubyfox/server/data/www/root/admin/modules/LogViewer/icon.png +0 -0
- data/lib/rubyfox/server/data/www/root/admin/modules/RuntimeStatistics/RuntimeStatistics.swf +0 -0
- data/lib/rubyfox/server/data/www/root/admin/modules/RuntimeStatistics/icon.png +0 -0
- data/lib/rubyfox/server/data/www/root/admin/modules/ServerConfigurator/ServerConfigurator.swf +0 -0
- data/lib/rubyfox/server/data/www/root/admin/modules/ServerConfigurator/icon.png +0 -0
- data/lib/rubyfox/server/data/www/root/admin/modules/ZoneConfigurator/ZoneConfigurator.swf +0 -0
- data/lib/rubyfox/server/data/www/root/admin/modules/ZoneConfigurator/icon.png +0 -0
- data/lib/rubyfox/server/data/www/root/admin/modules/ZoneMonitor/ZoneMonitor.swf +0 -0
- data/lib/rubyfox/server/data/www/root/admin/modules/ZoneMonitor/icon.png +0 -0
- data/lib/rubyfox/server/data/www/root/admin/modules/config.xml +12 -0
- data/lib/rubyfox/server/data/www/root/admin/playerProductInstall.swf +0 -0
- data/lib/rubyfox/server/data/www/root/admin/swfobject.js +777 -0
- data/lib/rubyfox/server/data/www/root/crossdomain.xml +6 -0
- data/lib/rubyfox/server/data/www/root/examples/.keep +0 -0
- data/lib/rubyfox/server/data/www/root/examples/index.html +43 -0
- data/lib/rubyfox/server/data/www/root/index.html +63 -0
- data/lib/rubyfox/server/data/zones/.keep +0 -0
- data/lib/rubyfox/server/environment.rb +31 -0
- data/lib/rubyfox/server/version.rb +5 -0
- data/lib/rubyfox/server.rb +9 -0
- data/rubyfox-server.gemspec +22 -0
- metadata +1076 -0
@@ -0,0 +1,4094 @@
|
|
1
|
+
# Test enhancements related to descriptors and new-style classes
|
2
|
+
|
3
|
+
# modified from CPython version by:
|
4
|
+
# - removed the tests classmethods_in_c, staticmethods_in_c, spamlists, and spamdicts which
|
5
|
+
# depend on the c extension module xxsubtype
|
6
|
+
# - merged code from the pypy version of this script to run all tests instead of stopping
|
7
|
+
# at the first failure
|
8
|
+
# - allow specific tests to be run by specifying them on the command line
|
9
|
+
|
10
|
+
from test.test_support import verify, vereq, verbose, TestFailed, TESTFN, get_original_stdout
|
11
|
+
from copy import deepcopy
|
12
|
+
import warnings
|
13
|
+
|
14
|
+
warnings.filterwarnings("ignore",
|
15
|
+
r'complex divmod\(\), // and % are deprecated$',
|
16
|
+
DeprecationWarning, r'(<string>|%s)$' % __name__)
|
17
|
+
|
18
|
+
def veris(a, b):
|
19
|
+
if a is not b:
|
20
|
+
raise TestFailed, "%r is %r" % (a, b)
|
21
|
+
|
22
|
+
def testunop(a, res, expr="len(a)", meth="__len__"):
|
23
|
+
if verbose: print "checking", expr
|
24
|
+
dict = {'a': a}
|
25
|
+
vereq(eval(expr, dict), res)
|
26
|
+
t = type(a)
|
27
|
+
m = getattr(t, meth)
|
28
|
+
while meth not in t.__dict__:
|
29
|
+
t = t.__bases__[0]
|
30
|
+
vereq(m, t.__dict__[meth])
|
31
|
+
vereq(m(a), res)
|
32
|
+
bm = getattr(a, meth)
|
33
|
+
vereq(bm(), res)
|
34
|
+
|
35
|
+
def testbinop(a, b, res, expr="a+b", meth="__add__"):
|
36
|
+
if verbose: print "checking", expr
|
37
|
+
dict = {'a': a, 'b': b}
|
38
|
+
|
39
|
+
# XXX Hack so this passes before 2.3 when -Qnew is specified.
|
40
|
+
if meth == "__div__" and 1/2 == 0.5:
|
41
|
+
meth = "__truediv__"
|
42
|
+
|
43
|
+
vereq(eval(expr, dict), res)
|
44
|
+
t = type(a)
|
45
|
+
m = getattr(t, meth)
|
46
|
+
while meth not in t.__dict__:
|
47
|
+
t = t.__bases__[0]
|
48
|
+
vereq(m, t.__dict__[meth])
|
49
|
+
vereq(m(a, b), res)
|
50
|
+
bm = getattr(a, meth)
|
51
|
+
vereq(bm(b), res)
|
52
|
+
|
53
|
+
def testternop(a, b, c, res, expr="a[b:c]", meth="__getslice__"):
|
54
|
+
if verbose: print "checking", expr
|
55
|
+
dict = {'a': a, 'b': b, 'c': c}
|
56
|
+
vereq(eval(expr, dict), res)
|
57
|
+
t = type(a)
|
58
|
+
m = getattr(t, meth)
|
59
|
+
while meth not in t.__dict__:
|
60
|
+
t = t.__bases__[0]
|
61
|
+
vereq(m, t.__dict__[meth])
|
62
|
+
vereq(m(a, b, c), res)
|
63
|
+
bm = getattr(a, meth)
|
64
|
+
vereq(bm(b, c), res)
|
65
|
+
|
66
|
+
def testsetop(a, b, res, stmt="a+=b", meth="__iadd__"):
|
67
|
+
if verbose: print "checking", stmt
|
68
|
+
dict = {'a': deepcopy(a), 'b': b}
|
69
|
+
exec stmt in dict
|
70
|
+
vereq(dict['a'], res)
|
71
|
+
t = type(a)
|
72
|
+
m = getattr(t, meth)
|
73
|
+
while meth not in t.__dict__:
|
74
|
+
t = t.__bases__[0]
|
75
|
+
vereq(m, t.__dict__[meth])
|
76
|
+
dict['a'] = deepcopy(a)
|
77
|
+
m(dict['a'], b)
|
78
|
+
vereq(dict['a'], res)
|
79
|
+
dict['a'] = deepcopy(a)
|
80
|
+
bm = getattr(dict['a'], meth)
|
81
|
+
bm(b)
|
82
|
+
vereq(dict['a'], res)
|
83
|
+
|
84
|
+
def testset2op(a, b, c, res, stmt="a[b]=c", meth="__setitem__"):
|
85
|
+
if verbose: print "checking", stmt
|
86
|
+
dict = {'a': deepcopy(a), 'b': b, 'c': c}
|
87
|
+
exec stmt in dict
|
88
|
+
vereq(dict['a'], res)
|
89
|
+
t = type(a)
|
90
|
+
m = getattr(t, meth)
|
91
|
+
while meth not in t.__dict__:
|
92
|
+
t = t.__bases__[0]
|
93
|
+
vereq(m, t.__dict__[meth])
|
94
|
+
dict['a'] = deepcopy(a)
|
95
|
+
m(dict['a'], b, c)
|
96
|
+
vereq(dict['a'], res)
|
97
|
+
dict['a'] = deepcopy(a)
|
98
|
+
bm = getattr(dict['a'], meth)
|
99
|
+
bm(b, c)
|
100
|
+
vereq(dict['a'], res)
|
101
|
+
|
102
|
+
def testset3op(a, b, c, d, res, stmt="a[b:c]=d", meth="__setslice__"):
|
103
|
+
if verbose: print "checking", stmt
|
104
|
+
dict = {'a': deepcopy(a), 'b': b, 'c': c, 'd': d}
|
105
|
+
exec stmt in dict
|
106
|
+
vereq(dict['a'], res)
|
107
|
+
t = type(a)
|
108
|
+
while meth not in t.__dict__:
|
109
|
+
t = t.__bases__[0]
|
110
|
+
m = getattr(t, meth)
|
111
|
+
vereq(m, t.__dict__[meth])
|
112
|
+
dict['a'] = deepcopy(a)
|
113
|
+
m(dict['a'], b, c, d)
|
114
|
+
vereq(dict['a'], res)
|
115
|
+
dict['a'] = deepcopy(a)
|
116
|
+
bm = getattr(dict['a'], meth)
|
117
|
+
bm(b, c, d)
|
118
|
+
vereq(dict['a'], res)
|
119
|
+
|
120
|
+
def class_docstrings():
|
121
|
+
class Classic:
|
122
|
+
"A classic docstring."
|
123
|
+
vereq(Classic.__doc__, "A classic docstring.")
|
124
|
+
vereq(Classic.__dict__['__doc__'], "A classic docstring.")
|
125
|
+
|
126
|
+
class Classic2:
|
127
|
+
pass
|
128
|
+
verify(Classic2.__doc__ is None)
|
129
|
+
|
130
|
+
class NewStatic(object):
|
131
|
+
"Another docstring."
|
132
|
+
vereq(NewStatic.__doc__, "Another docstring.")
|
133
|
+
vereq(NewStatic.__dict__['__doc__'], "Another docstring.")
|
134
|
+
|
135
|
+
class NewStatic2(object):
|
136
|
+
pass
|
137
|
+
verify(NewStatic2.__doc__ is None)
|
138
|
+
|
139
|
+
class NewDynamic(object):
|
140
|
+
"Another docstring."
|
141
|
+
vereq(NewDynamic.__doc__, "Another docstring.")
|
142
|
+
vereq(NewDynamic.__dict__['__doc__'], "Another docstring.")
|
143
|
+
|
144
|
+
class NewDynamic2(object):
|
145
|
+
pass
|
146
|
+
verify(NewDynamic2.__doc__ is None)
|
147
|
+
|
148
|
+
def lists():
|
149
|
+
if verbose: print "Testing list operations..."
|
150
|
+
testbinop([1], [2], [1,2], "a+b", "__add__")
|
151
|
+
testbinop([1,2,3], 2, 1, "b in a", "__contains__")
|
152
|
+
testbinop([1,2,3], 4, 0, "b in a", "__contains__")
|
153
|
+
testbinop([1,2,3], 1, 2, "a[b]", "__getitem__")
|
154
|
+
testternop([1,2,3], 0, 2, [1,2], "a[b:c]", "__getslice__")
|
155
|
+
testsetop([1], [2], [1,2], "a+=b", "__iadd__")
|
156
|
+
testsetop([1,2], 3, [1,2,1,2,1,2], "a*=b", "__imul__")
|
157
|
+
testunop([1,2,3], 3, "len(a)", "__len__")
|
158
|
+
testbinop([1,2], 3, [1,2,1,2,1,2], "a*b", "__mul__")
|
159
|
+
testbinop([1,2], 3, [1,2,1,2,1,2], "b*a", "__rmul__")
|
160
|
+
testset2op([1,2], 1, 3, [1,3], "a[b]=c", "__setitem__")
|
161
|
+
testset3op([1,2,3,4], 1, 3, [5,6], [1,5,6,4], "a[b:c]=d", "__setslice__")
|
162
|
+
|
163
|
+
def dicts():
|
164
|
+
if verbose: print "Testing dict operations..."
|
165
|
+
testbinop({1:2}, {2:1}, -1, "cmp(a,b)", "__cmp__")
|
166
|
+
testbinop({1:2,3:4}, 1, 1, "b in a", "__contains__")
|
167
|
+
testbinop({1:2,3:4}, 2, 0, "b in a", "__contains__")
|
168
|
+
testbinop({1:2,3:4}, 1, 2, "a[b]", "__getitem__")
|
169
|
+
d = {1:2,3:4}
|
170
|
+
l1 = []
|
171
|
+
for i in d.keys(): l1.append(i)
|
172
|
+
l = []
|
173
|
+
for i in iter(d): l.append(i)
|
174
|
+
vereq(l, l1)
|
175
|
+
l = []
|
176
|
+
for i in d.__iter__(): l.append(i)
|
177
|
+
vereq(l, l1)
|
178
|
+
l = []
|
179
|
+
for i in dict.__iter__(d): l.append(i)
|
180
|
+
vereq(l, l1)
|
181
|
+
d = {1:2, 3:4}
|
182
|
+
testunop(d, 2, "len(a)", "__len__")
|
183
|
+
vereq(eval(repr(d), {}), d)
|
184
|
+
vereq(eval(d.__repr__(), {}), d)
|
185
|
+
testset2op({1:2,3:4}, 2, 3, {1:2,2:3,3:4}, "a[b]=c", "__setitem__")
|
186
|
+
|
187
|
+
def dict_constructor():
|
188
|
+
if verbose:
|
189
|
+
print "Testing dict constructor ..."
|
190
|
+
d = dict()
|
191
|
+
vereq(d, {})
|
192
|
+
d = dict({})
|
193
|
+
vereq(d, {})
|
194
|
+
d = dict({1: 2, 'a': 'b'})
|
195
|
+
vereq(d, {1: 2, 'a': 'b'})
|
196
|
+
vereq(d, dict(d.items()))
|
197
|
+
vereq(d, dict(d.iteritems()))
|
198
|
+
d = dict({'one':1, 'two':2})
|
199
|
+
vereq(d, dict(one=1, two=2))
|
200
|
+
vereq(d, dict(**d))
|
201
|
+
vereq(d, dict({"one": 1}, two=2))
|
202
|
+
vereq(d, dict([("two", 2)], one=1))
|
203
|
+
vereq(d, dict([("one", 100), ("two", 200)], **d))
|
204
|
+
verify(d is not dict(**d))
|
205
|
+
for badarg in 0, 0L, 0j, "0", [0], (0,):
|
206
|
+
try:
|
207
|
+
dict(badarg)
|
208
|
+
except TypeError:
|
209
|
+
pass
|
210
|
+
except ValueError:
|
211
|
+
if badarg == "0":
|
212
|
+
# It's a sequence, and its elements are also sequences (gotta
|
213
|
+
# love strings <wink>), but they aren't of length 2, so this
|
214
|
+
# one seemed better as a ValueError than a TypeError.
|
215
|
+
pass
|
216
|
+
else:
|
217
|
+
raise TestFailed("no TypeError from dict(%r)" % badarg)
|
218
|
+
else:
|
219
|
+
raise TestFailed("no TypeError from dict(%r)" % badarg)
|
220
|
+
|
221
|
+
try:
|
222
|
+
dict({}, {})
|
223
|
+
except TypeError:
|
224
|
+
pass
|
225
|
+
else:
|
226
|
+
raise TestFailed("no TypeError from dict({}, {})")
|
227
|
+
|
228
|
+
class Mapping:
|
229
|
+
# Lacks a .keys() method; will be added later.
|
230
|
+
dict = {1:2, 3:4, 'a':1j}
|
231
|
+
|
232
|
+
try:
|
233
|
+
dict(Mapping())
|
234
|
+
except TypeError:
|
235
|
+
pass
|
236
|
+
else:
|
237
|
+
raise TestFailed("no TypeError from dict(incomplete mapping)")
|
238
|
+
|
239
|
+
Mapping.keys = lambda self: self.dict.keys()
|
240
|
+
Mapping.__getitem__ = lambda self, i: self.dict[i]
|
241
|
+
d = dict(Mapping())
|
242
|
+
vereq(d, Mapping.dict)
|
243
|
+
|
244
|
+
# Init from sequence of iterable objects, each producing a 2-sequence.
|
245
|
+
class AddressBookEntry:
|
246
|
+
def __init__(self, first, last):
|
247
|
+
self.first = first
|
248
|
+
self.last = last
|
249
|
+
def __iter__(self):
|
250
|
+
return iter([self.first, self.last])
|
251
|
+
|
252
|
+
d = dict([AddressBookEntry('Tim', 'Warsaw'),
|
253
|
+
AddressBookEntry('Barry', 'Peters'),
|
254
|
+
AddressBookEntry('Tim', 'Peters'),
|
255
|
+
AddressBookEntry('Barry', 'Warsaw')])
|
256
|
+
vereq(d, {'Barry': 'Warsaw', 'Tim': 'Peters'})
|
257
|
+
|
258
|
+
d = dict(zip(range(4), range(1, 5)))
|
259
|
+
vereq(d, dict([(i, i+1) for i in range(4)]))
|
260
|
+
|
261
|
+
# Bad sequence lengths.
|
262
|
+
for bad in [('tooshort',)], [('too', 'long', 'by 1')]:
|
263
|
+
try:
|
264
|
+
dict(bad)
|
265
|
+
except ValueError:
|
266
|
+
pass
|
267
|
+
else:
|
268
|
+
raise TestFailed("no ValueError from dict(%r)" % bad)
|
269
|
+
|
270
|
+
def test_dir():
|
271
|
+
if verbose:
|
272
|
+
print "Testing dir() ..."
|
273
|
+
junk = 12
|
274
|
+
vereq(dir(), ['junk'])
|
275
|
+
del junk
|
276
|
+
|
277
|
+
# Just make sure these don't blow up!
|
278
|
+
for arg in 2, 2L, 2j, 2e0, [2], "2", u"2", (2,), {2:2}, type, test_dir:
|
279
|
+
dir(arg)
|
280
|
+
|
281
|
+
# Try classic classes.
|
282
|
+
class C:
|
283
|
+
Cdata = 1
|
284
|
+
def Cmethod(self): pass
|
285
|
+
|
286
|
+
cstuff = ['Cdata', 'Cmethod', '__doc__', '__module__']
|
287
|
+
vereq(dir(C), cstuff)
|
288
|
+
verify('im_self' in dir(C.Cmethod))
|
289
|
+
|
290
|
+
c = C() # c.__doc__ is an odd thing to see here; ditto c.__module__.
|
291
|
+
vereq(dir(c), cstuff)
|
292
|
+
|
293
|
+
c.cdata = 2
|
294
|
+
c.cmethod = lambda self: 0
|
295
|
+
vereq(dir(c), cstuff + ['cdata', 'cmethod'])
|
296
|
+
verify('im_self' in dir(c.Cmethod))
|
297
|
+
|
298
|
+
class A(C):
|
299
|
+
Adata = 1
|
300
|
+
def Amethod(self): pass
|
301
|
+
|
302
|
+
astuff = ['Adata', 'Amethod'] + cstuff
|
303
|
+
vereq(dir(A), astuff)
|
304
|
+
verify('im_self' in dir(A.Amethod))
|
305
|
+
a = A()
|
306
|
+
vereq(dir(a), astuff)
|
307
|
+
verify('im_self' in dir(a.Amethod))
|
308
|
+
a.adata = 42
|
309
|
+
a.amethod = lambda self: 3
|
310
|
+
vereq(dir(a), astuff + ['adata', 'amethod'])
|
311
|
+
|
312
|
+
# The same, but with new-style classes. Since these have object as a
|
313
|
+
# base class, a lot more gets sucked in.
|
314
|
+
def interesting(strings):
|
315
|
+
return [s for s in strings if not s.startswith('_')]
|
316
|
+
|
317
|
+
class C(object):
|
318
|
+
Cdata = 1
|
319
|
+
def Cmethod(self): pass
|
320
|
+
|
321
|
+
cstuff = ['Cdata', 'Cmethod']
|
322
|
+
vereq(interesting(dir(C)), cstuff)
|
323
|
+
|
324
|
+
c = C()
|
325
|
+
vereq(interesting(dir(c)), cstuff)
|
326
|
+
verify('im_self' in dir(C.Cmethod))
|
327
|
+
|
328
|
+
c.cdata = 2
|
329
|
+
c.cmethod = lambda self: 0
|
330
|
+
vereq(interesting(dir(c)), cstuff + ['cdata', 'cmethod'])
|
331
|
+
verify('im_self' in dir(c.Cmethod))
|
332
|
+
|
333
|
+
class A(C):
|
334
|
+
Adata = 1
|
335
|
+
def Amethod(self): pass
|
336
|
+
|
337
|
+
astuff = ['Adata', 'Amethod'] + cstuff
|
338
|
+
vereq(interesting(dir(A)), astuff)
|
339
|
+
verify('im_self' in dir(A.Amethod))
|
340
|
+
a = A()
|
341
|
+
vereq(interesting(dir(a)), astuff)
|
342
|
+
a.adata = 42
|
343
|
+
a.amethod = lambda self: 3
|
344
|
+
vereq(interesting(dir(a)), astuff + ['adata', 'amethod'])
|
345
|
+
verify('im_self' in dir(a.Amethod))
|
346
|
+
|
347
|
+
# Try a module subclass.
|
348
|
+
from types import ModuleType
|
349
|
+
class M(ModuleType):
|
350
|
+
pass
|
351
|
+
minstance = M("m")
|
352
|
+
minstance.b = 2
|
353
|
+
minstance.a = 1
|
354
|
+
names = [x for x in dir(minstance) if x not in ["__name__", "__doc__"]]
|
355
|
+
vereq(names, ['a', 'b'])
|
356
|
+
|
357
|
+
class M2(M):
|
358
|
+
def getdict(self):
|
359
|
+
return "Not a dict!"
|
360
|
+
__dict__ = property(getdict)
|
361
|
+
|
362
|
+
m2instance = M2("m2")
|
363
|
+
m2instance.b = 2
|
364
|
+
m2instance.a = 1
|
365
|
+
vereq(m2instance.__dict__, "Not a dict!")
|
366
|
+
try:
|
367
|
+
dir(m2instance)
|
368
|
+
except TypeError:
|
369
|
+
pass
|
370
|
+
|
371
|
+
# Two essentially featureless objects, just inheriting stuff from
|
372
|
+
# object.
|
373
|
+
vereq(dir(None), dir(Ellipsis))
|
374
|
+
|
375
|
+
# Nasty test case for proxied objects
|
376
|
+
class Wrapper(object):
|
377
|
+
def __init__(self, obj):
|
378
|
+
self.__obj = obj
|
379
|
+
def __repr__(self):
|
380
|
+
return "Wrapper(%s)" % repr(self.__obj)
|
381
|
+
def __getitem__(self, key):
|
382
|
+
return Wrapper(self.__obj[key])
|
383
|
+
def __len__(self):
|
384
|
+
return len(self.__obj)
|
385
|
+
def __getattr__(self, name):
|
386
|
+
return Wrapper(getattr(self.__obj, name))
|
387
|
+
|
388
|
+
class C(object):
|
389
|
+
def __getclass(self):
|
390
|
+
return Wrapper(type(self))
|
391
|
+
__class__ = property(__getclass)
|
392
|
+
|
393
|
+
dir(C()) # This used to segfault
|
394
|
+
|
395
|
+
binops = {
|
396
|
+
'add': '+',
|
397
|
+
'sub': '-',
|
398
|
+
'mul': '*',
|
399
|
+
'div': '/',
|
400
|
+
'mod': '%',
|
401
|
+
'divmod': 'divmod',
|
402
|
+
'pow': '**',
|
403
|
+
'lshift': '<<',
|
404
|
+
'rshift': '>>',
|
405
|
+
'and': '&',
|
406
|
+
'xor': '^',
|
407
|
+
'or': '|',
|
408
|
+
'cmp': 'cmp',
|
409
|
+
'lt': '<',
|
410
|
+
'le': '<=',
|
411
|
+
'eq': '==',
|
412
|
+
'ne': '!=',
|
413
|
+
'gt': '>',
|
414
|
+
'ge': '>=',
|
415
|
+
}
|
416
|
+
|
417
|
+
for name, expr in binops.items():
|
418
|
+
if expr.islower():
|
419
|
+
expr = expr + "(a, b)"
|
420
|
+
else:
|
421
|
+
expr = 'a %s b' % expr
|
422
|
+
binops[name] = expr
|
423
|
+
|
424
|
+
unops = {
|
425
|
+
'pos': '+',
|
426
|
+
'neg': '-',
|
427
|
+
'abs': 'abs',
|
428
|
+
'invert': '~',
|
429
|
+
'int': 'int',
|
430
|
+
'long': 'long',
|
431
|
+
'float': 'float',
|
432
|
+
'oct': 'oct',
|
433
|
+
'hex': 'hex',
|
434
|
+
}
|
435
|
+
|
436
|
+
for name, expr in unops.items():
|
437
|
+
if expr.islower():
|
438
|
+
expr = expr + "(a)"
|
439
|
+
else:
|
440
|
+
expr = '%s a' % expr
|
441
|
+
unops[name] = expr
|
442
|
+
|
443
|
+
def numops(a, b, skip=[]):
|
444
|
+
dict = {'a': a, 'b': b}
|
445
|
+
for name, expr in binops.items():
|
446
|
+
if name not in skip:
|
447
|
+
name = "__%s__" % name
|
448
|
+
if hasattr(a, name):
|
449
|
+
res = eval(expr, dict)
|
450
|
+
testbinop(a, b, res, expr, name)
|
451
|
+
for name, expr in unops.items():
|
452
|
+
if name not in skip:
|
453
|
+
name = "__%s__" % name
|
454
|
+
if hasattr(a, name):
|
455
|
+
res = eval(expr, dict)
|
456
|
+
testunop(a, res, expr, name)
|
457
|
+
|
458
|
+
def ints():
|
459
|
+
if verbose: print "Testing int operations..."
|
460
|
+
numops(100, 3)
|
461
|
+
# The following crashes in Python 2.2
|
462
|
+
vereq((1).__nonzero__(), 1)
|
463
|
+
vereq((0).__nonzero__(), 0)
|
464
|
+
# This returns 'NotImplemented' in Python 2.2
|
465
|
+
class C(int):
|
466
|
+
def __add__(self, other):
|
467
|
+
return NotImplemented
|
468
|
+
vereq(C(5L), 5)
|
469
|
+
try:
|
470
|
+
C() + ""
|
471
|
+
except TypeError:
|
472
|
+
pass
|
473
|
+
else:
|
474
|
+
raise TestFailed, "NotImplemented should have caused TypeError"
|
475
|
+
import sys
|
476
|
+
try:
|
477
|
+
C(sys.maxint+1)
|
478
|
+
except OverflowError:
|
479
|
+
pass
|
480
|
+
else:
|
481
|
+
raise TestFailed, "should have raised OverflowError"
|
482
|
+
try:
|
483
|
+
foo = int(None)
|
484
|
+
except TypeError:
|
485
|
+
pass
|
486
|
+
else:
|
487
|
+
raise TestFailed, "should have raised TypeError"
|
488
|
+
try:
|
489
|
+
foo = C(None)
|
490
|
+
except TypeError:
|
491
|
+
pass
|
492
|
+
else:
|
493
|
+
raise TestFailed, "should have raised TypeError"
|
494
|
+
|
495
|
+
def longs():
|
496
|
+
if verbose: print "Testing long operations..."
|
497
|
+
numops(100L, 3L)
|
498
|
+
|
499
|
+
def floats():
|
500
|
+
if verbose: print "Testing float operations..."
|
501
|
+
numops(100.0, 3.0)
|
502
|
+
|
503
|
+
def complexes():
|
504
|
+
if verbose: print "Testing complex operations..."
|
505
|
+
numops(100.0j, 3.0j, skip=['lt', 'le', 'gt', 'ge', 'int', 'long', 'float'])
|
506
|
+
class Number(complex):
|
507
|
+
__slots__ = ['prec']
|
508
|
+
def __new__(cls, *args, **kwds):
|
509
|
+
result = complex.__new__(cls, *args)
|
510
|
+
result.prec = kwds.get('prec', 12)
|
511
|
+
return result
|
512
|
+
def __repr__(self):
|
513
|
+
prec = self.prec
|
514
|
+
if self.imag == 0.0:
|
515
|
+
return "%.*g" % (prec, self.real)
|
516
|
+
if self.real == 0.0:
|
517
|
+
return "%.*gj" % (prec, self.imag)
|
518
|
+
return "(%.*g+%.*gj)" % (prec, self.real, prec, self.imag)
|
519
|
+
__str__ = __repr__
|
520
|
+
|
521
|
+
a = Number(3.14, prec=6)
|
522
|
+
vereq(`a`, "3.14")
|
523
|
+
vereq(a.prec, 6)
|
524
|
+
|
525
|
+
a = Number(a, prec=2)
|
526
|
+
vereq(`a`, "3.1")
|
527
|
+
vereq(a.prec, 2)
|
528
|
+
|
529
|
+
a = Number(234.5)
|
530
|
+
vereq(`a`, "234.5")
|
531
|
+
vereq(a.prec, 12)
|
532
|
+
|
533
|
+
def pydicts():
|
534
|
+
if verbose: print "Testing Python subclass of dict..."
|
535
|
+
verify(issubclass(dict, dict))
|
536
|
+
verify(isinstance({}, dict))
|
537
|
+
d = dict()
|
538
|
+
vereq(d, {})
|
539
|
+
verify(d.__class__ is dict)
|
540
|
+
verify(isinstance(d, dict))
|
541
|
+
class C(dict):
|
542
|
+
state = -1
|
543
|
+
def __init__(self, *a, **kw):
|
544
|
+
if a:
|
545
|
+
vereq(len(a), 1)
|
546
|
+
self.state = a[0]
|
547
|
+
if kw:
|
548
|
+
for k, v in kw.items(): self[v] = k
|
549
|
+
def __getitem__(self, key):
|
550
|
+
return self.get(key, 0)
|
551
|
+
def __setitem__(self, key, value):
|
552
|
+
verify(isinstance(key, type(0)))
|
553
|
+
dict.__setitem__(self, key, value)
|
554
|
+
def setstate(self, state):
|
555
|
+
self.state = state
|
556
|
+
def getstate(self):
|
557
|
+
return self.state
|
558
|
+
verify(issubclass(C, dict))
|
559
|
+
a1 = C(12)
|
560
|
+
vereq(a1.state, 12)
|
561
|
+
a2 = C(foo=1, bar=2)
|
562
|
+
vereq(a2[1] == 'foo' and a2[2], 'bar')
|
563
|
+
a = C()
|
564
|
+
vereq(a.state, -1)
|
565
|
+
vereq(a.getstate(), -1)
|
566
|
+
a.setstate(0)
|
567
|
+
vereq(a.state, 0)
|
568
|
+
vereq(a.getstate(), 0)
|
569
|
+
a.setstate(10)
|
570
|
+
vereq(a.state, 10)
|
571
|
+
vereq(a.getstate(), 10)
|
572
|
+
vereq(a[42], 0)
|
573
|
+
a[42] = 24
|
574
|
+
vereq(a[42], 24)
|
575
|
+
if verbose: print "pydict stress test ..."
|
576
|
+
N = 50
|
577
|
+
for i in range(N):
|
578
|
+
a[i] = C()
|
579
|
+
for j in range(N):
|
580
|
+
a[i][j] = i*j
|
581
|
+
for i in range(N):
|
582
|
+
for j in range(N):
|
583
|
+
vereq(a[i][j], i*j)
|
584
|
+
|
585
|
+
def pylists():
|
586
|
+
if verbose: print "Testing Python subclass of list..."
|
587
|
+
class C(list):
|
588
|
+
def __getitem__(self, i):
|
589
|
+
return list.__getitem__(self, i) + 100
|
590
|
+
def __getslice__(self, i, j):
|
591
|
+
return (i, j)
|
592
|
+
a = C()
|
593
|
+
a.extend([0,1,2])
|
594
|
+
vereq(a[0], 100)
|
595
|
+
vereq(a[1], 101)
|
596
|
+
vereq(a[2], 102)
|
597
|
+
vereq(a[100:200], (100,200))
|
598
|
+
|
599
|
+
def metaclass():
|
600
|
+
if verbose: print "Testing __metaclass__..."
|
601
|
+
class C:
|
602
|
+
__metaclass__ = type
|
603
|
+
def __init__(self):
|
604
|
+
self.__state = 0
|
605
|
+
def getstate(self):
|
606
|
+
return self.__state
|
607
|
+
def setstate(self, state):
|
608
|
+
self.__state = state
|
609
|
+
a = C()
|
610
|
+
vereq(a.getstate(), 0)
|
611
|
+
a.setstate(10)
|
612
|
+
vereq(a.getstate(), 10)
|
613
|
+
class D:
|
614
|
+
class __metaclass__(type):
|
615
|
+
def myself(cls): return cls
|
616
|
+
vereq(D.myself(), D)
|
617
|
+
d = D()
|
618
|
+
verify(d.__class__ is D)
|
619
|
+
class M1(type):
|
620
|
+
def __new__(cls, name, bases, dict):
|
621
|
+
dict['__spam__'] = 1
|
622
|
+
return type.__new__(cls, name, bases, dict)
|
623
|
+
class C:
|
624
|
+
__metaclass__ = M1
|
625
|
+
vereq(C.__spam__, 1)
|
626
|
+
c = C()
|
627
|
+
vereq(c.__spam__, 1)
|
628
|
+
|
629
|
+
class _instance(object):
|
630
|
+
pass
|
631
|
+
class M2(object):
|
632
|
+
def __new__(cls, name, bases, dict):
|
633
|
+
self = object.__new__(cls)
|
634
|
+
self.name = name
|
635
|
+
self.bases = bases
|
636
|
+
self.dict = dict
|
637
|
+
return self
|
638
|
+
__new__ = staticmethod(__new__)
|
639
|
+
def __call__(self):
|
640
|
+
it = _instance()
|
641
|
+
# Early binding of methods
|
642
|
+
for key in self.dict:
|
643
|
+
if key.startswith("__"):
|
644
|
+
continue
|
645
|
+
setattr(it, key, self.dict[key].__get__(it, self))
|
646
|
+
return it
|
647
|
+
class C:
|
648
|
+
__metaclass__ = M2
|
649
|
+
def spam(self):
|
650
|
+
return 42
|
651
|
+
vereq(C.name, 'C')
|
652
|
+
vereq(C.bases, ())
|
653
|
+
verify('spam' in C.dict)
|
654
|
+
c = C()
|
655
|
+
vereq(c.spam(), 42)
|
656
|
+
|
657
|
+
# More metaclass examples
|
658
|
+
|
659
|
+
class autosuper(type):
|
660
|
+
# Automatically add __super to the class
|
661
|
+
# This trick only works for dynamic classes
|
662
|
+
def __new__(metaclass, name, bases, dict):
|
663
|
+
cls = super(autosuper, metaclass).__new__(metaclass,
|
664
|
+
name, bases, dict)
|
665
|
+
# Name mangling for __super removes leading underscores
|
666
|
+
while name[:1] == "_":
|
667
|
+
name = name[1:]
|
668
|
+
if name:
|
669
|
+
name = "_%s__super" % name
|
670
|
+
else:
|
671
|
+
name = "__super"
|
672
|
+
setattr(cls, name, super(cls))
|
673
|
+
return cls
|
674
|
+
class A:
|
675
|
+
__metaclass__ = autosuper
|
676
|
+
def meth(self):
|
677
|
+
return "A"
|
678
|
+
class B(A):
|
679
|
+
def meth(self):
|
680
|
+
return "B" + self.__super.meth()
|
681
|
+
class C(A):
|
682
|
+
def meth(self):
|
683
|
+
return "C" + self.__super.meth()
|
684
|
+
class D(C, B):
|
685
|
+
def meth(self):
|
686
|
+
return "D" + self.__super.meth()
|
687
|
+
vereq(D().meth(), "DCBA")
|
688
|
+
class E(B, C):
|
689
|
+
def meth(self):
|
690
|
+
return "E" + self.__super.meth()
|
691
|
+
vereq(E().meth(), "EBCA")
|
692
|
+
|
693
|
+
class autoproperty(type):
|
694
|
+
# Automatically create property attributes when methods
|
695
|
+
# named _get_x and/or _set_x are found
|
696
|
+
def __new__(metaclass, name, bases, dict):
|
697
|
+
hits = {}
|
698
|
+
for key, val in dict.iteritems():
|
699
|
+
if key.startswith("_get_"):
|
700
|
+
key = key[5:]
|
701
|
+
get, set = hits.get(key, (None, None))
|
702
|
+
get = val
|
703
|
+
hits[key] = get, set
|
704
|
+
elif key.startswith("_set_"):
|
705
|
+
key = key[5:]
|
706
|
+
get, set = hits.get(key, (None, None))
|
707
|
+
set = val
|
708
|
+
hits[key] = get, set
|
709
|
+
for key, (get, set) in hits.iteritems():
|
710
|
+
dict[key] = property(get, set)
|
711
|
+
return super(autoproperty, metaclass).__new__(metaclass,
|
712
|
+
name, bases, dict)
|
713
|
+
class A:
|
714
|
+
__metaclass__ = autoproperty
|
715
|
+
def _get_x(self):
|
716
|
+
return -self.__x
|
717
|
+
def _set_x(self, x):
|
718
|
+
self.__x = -x
|
719
|
+
a = A()
|
720
|
+
verify(not hasattr(a, "x"))
|
721
|
+
a.x = 12
|
722
|
+
vereq(a.x, 12)
|
723
|
+
vereq(a._A__x, -12)
|
724
|
+
|
725
|
+
class multimetaclass(autoproperty, autosuper):
|
726
|
+
# Merge of multiple cooperating metaclasses
|
727
|
+
pass
|
728
|
+
class A:
|
729
|
+
__metaclass__ = multimetaclass
|
730
|
+
def _get_x(self):
|
731
|
+
return "A"
|
732
|
+
class B(A):
|
733
|
+
def _get_x(self):
|
734
|
+
return "B" + self.__super._get_x()
|
735
|
+
class C(A):
|
736
|
+
def _get_x(self):
|
737
|
+
return "C" + self.__super._get_x()
|
738
|
+
class D(C, B):
|
739
|
+
def _get_x(self):
|
740
|
+
return "D" + self.__super._get_x()
|
741
|
+
vereq(D().x, "DCBA")
|
742
|
+
|
743
|
+
# Make sure type(x) doesn't call x.__class__.__init__
|
744
|
+
class T(type):
|
745
|
+
counter = 0
|
746
|
+
def __init__(self, *args):
|
747
|
+
T.counter += 1
|
748
|
+
class C:
|
749
|
+
__metaclass__ = T
|
750
|
+
vereq(T.counter, 1)
|
751
|
+
a = C()
|
752
|
+
vereq(type(a), C)
|
753
|
+
vereq(T.counter, 1)
|
754
|
+
|
755
|
+
class C(object): pass
|
756
|
+
c = C()
|
757
|
+
try: c()
|
758
|
+
except TypeError: pass
|
759
|
+
else: raise TestFailed, "calling object w/o call method should raise TypeError"
|
760
|
+
|
761
|
+
def pymods():
|
762
|
+
if verbose: print "Testing Python subclass of module..."
|
763
|
+
log = []
|
764
|
+
from types import ModuleType as MT
|
765
|
+
class MM(MT):
|
766
|
+
def __init__(self, name):
|
767
|
+
MT.__init__(self, name)
|
768
|
+
def __getattribute__(self, name):
|
769
|
+
log.append(("getattr", name))
|
770
|
+
return MT.__getattribute__(self, name)
|
771
|
+
def __setattr__(self, name, value):
|
772
|
+
log.append(("setattr", name, value))
|
773
|
+
MT.__setattr__(self, name, value)
|
774
|
+
def __delattr__(self, name):
|
775
|
+
log.append(("delattr", name))
|
776
|
+
MT.__delattr__(self, name)
|
777
|
+
a = MM("a")
|
778
|
+
a.foo = 12
|
779
|
+
x = a.foo
|
780
|
+
del a.foo
|
781
|
+
vereq(log, [("setattr", "foo", 12),
|
782
|
+
("getattr", "foo"),
|
783
|
+
("delattr", "foo")])
|
784
|
+
|
785
|
+
def multi():
|
786
|
+
if verbose: print "Testing multiple inheritance..."
|
787
|
+
class C(object):
|
788
|
+
def __init__(self):
|
789
|
+
self.__state = 0
|
790
|
+
def getstate(self):
|
791
|
+
return self.__state
|
792
|
+
def setstate(self, state):
|
793
|
+
self.__state = state
|
794
|
+
a = C()
|
795
|
+
vereq(a.getstate(), 0)
|
796
|
+
a.setstate(10)
|
797
|
+
vereq(a.getstate(), 10)
|
798
|
+
class D(dict, C):
|
799
|
+
def __init__(self):
|
800
|
+
type({}).__init__(self)
|
801
|
+
C.__init__(self)
|
802
|
+
d = D()
|
803
|
+
vereq(d.keys(), [])
|
804
|
+
d["hello"] = "world"
|
805
|
+
vereq(d.items(), [("hello", "world")])
|
806
|
+
vereq(d["hello"], "world")
|
807
|
+
vereq(d.getstate(), 0)
|
808
|
+
d.setstate(10)
|
809
|
+
vereq(d.getstate(), 10)
|
810
|
+
vereq(D.__mro__, (D, dict, C, object))
|
811
|
+
|
812
|
+
# SF bug #442833
|
813
|
+
class Node(object):
|
814
|
+
def __int__(self):
|
815
|
+
return int(self.foo())
|
816
|
+
def foo(self):
|
817
|
+
return "23"
|
818
|
+
class Frag(Node, list):
|
819
|
+
def foo(self):
|
820
|
+
return "42"
|
821
|
+
vereq(Node().__int__(), 23)
|
822
|
+
vereq(int(Node()), 23)
|
823
|
+
vereq(Frag().__int__(), 42)
|
824
|
+
vereq(int(Frag()), 42)
|
825
|
+
|
826
|
+
# MI mixing classic and new-style classes.
|
827
|
+
|
828
|
+
class A:
|
829
|
+
x = 1
|
830
|
+
|
831
|
+
class B(A):
|
832
|
+
pass
|
833
|
+
|
834
|
+
class C(A):
|
835
|
+
x = 2
|
836
|
+
|
837
|
+
class D(B, C):
|
838
|
+
pass
|
839
|
+
vereq(D.x, 1)
|
840
|
+
|
841
|
+
# Classic MRO is preserved for a classic base class.
|
842
|
+
class E(D, object):
|
843
|
+
pass
|
844
|
+
vereq(E.__mro__, (E, D, B, A, C, object))
|
845
|
+
vereq(E.x, 1)
|
846
|
+
|
847
|
+
# But with a mix of classic bases, their MROs are combined using
|
848
|
+
# new-style MRO.
|
849
|
+
class F(B, C, object):
|
850
|
+
pass
|
851
|
+
vereq(F.__mro__, (F, B, C, A, object))
|
852
|
+
vereq(F.x, 2)
|
853
|
+
|
854
|
+
# Try something else.
|
855
|
+
class C:
|
856
|
+
def cmethod(self):
|
857
|
+
return "C a"
|
858
|
+
def all_method(self):
|
859
|
+
return "C b"
|
860
|
+
|
861
|
+
class M1(C, object):
|
862
|
+
def m1method(self):
|
863
|
+
return "M1 a"
|
864
|
+
def all_method(self):
|
865
|
+
return "M1 b"
|
866
|
+
|
867
|
+
vereq(M1.__mro__, (M1, C, object))
|
868
|
+
m = M1()
|
869
|
+
vereq(m.cmethod(), "C a")
|
870
|
+
vereq(m.m1method(), "M1 a")
|
871
|
+
vereq(m.all_method(), "M1 b")
|
872
|
+
|
873
|
+
class D(C):
|
874
|
+
def dmethod(self):
|
875
|
+
return "D a"
|
876
|
+
def all_method(self):
|
877
|
+
return "D b"
|
878
|
+
|
879
|
+
class M2(D, object):
|
880
|
+
def m2method(self):
|
881
|
+
return "M2 a"
|
882
|
+
def all_method(self):
|
883
|
+
return "M2 b"
|
884
|
+
|
885
|
+
vereq(M2.__mro__, (M2, D, C, object))
|
886
|
+
m = M2()
|
887
|
+
vereq(m.cmethod(), "C a")
|
888
|
+
vereq(m.dmethod(), "D a")
|
889
|
+
vereq(m.m2method(), "M2 a")
|
890
|
+
vereq(m.all_method(), "M2 b")
|
891
|
+
|
892
|
+
class M3(M1, M2, object):
|
893
|
+
def m3method(self):
|
894
|
+
return "M3 a"
|
895
|
+
def all_method(self):
|
896
|
+
return "M3 b"
|
897
|
+
vereq(M3.__mro__, (M3, M1, M2, D, C, object))
|
898
|
+
m = M3()
|
899
|
+
vereq(m.cmethod(), "C a")
|
900
|
+
vereq(m.dmethod(), "D a")
|
901
|
+
vereq(m.m1method(), "M1 a")
|
902
|
+
vereq(m.m2method(), "M2 a")
|
903
|
+
vereq(m.m3method(), "M3 a")
|
904
|
+
vereq(m.all_method(), "M3 b")
|
905
|
+
|
906
|
+
class Classic:
|
907
|
+
pass
|
908
|
+
try:
|
909
|
+
class New(Classic):
|
910
|
+
__metaclass__ = type
|
911
|
+
except TypeError:
|
912
|
+
pass
|
913
|
+
else:
|
914
|
+
raise TestFailed, "new class with only classic bases - shouldn't be"
|
915
|
+
|
916
|
+
def diamond():
|
917
|
+
if verbose: print "Testing multiple inheritance special cases..."
|
918
|
+
class A(object):
|
919
|
+
def spam(self): return "A"
|
920
|
+
vereq(A().spam(), "A")
|
921
|
+
class B(A):
|
922
|
+
def boo(self): return "B"
|
923
|
+
def spam(self): return "B"
|
924
|
+
vereq(B().spam(), "B")
|
925
|
+
vereq(B().boo(), "B")
|
926
|
+
class C(A):
|
927
|
+
def boo(self): return "C"
|
928
|
+
vereq(C().spam(), "A")
|
929
|
+
vereq(C().boo(), "C")
|
930
|
+
class D(B, C): pass
|
931
|
+
vereq(D().spam(), "B")
|
932
|
+
vereq(D().boo(), "B")
|
933
|
+
vereq(D.__mro__, (D, B, C, A, object))
|
934
|
+
class E(C, B): pass
|
935
|
+
vereq(E().spam(), "B")
|
936
|
+
vereq(E().boo(), "C")
|
937
|
+
vereq(E.__mro__, (E, C, B, A, object))
|
938
|
+
# MRO order disagreement
|
939
|
+
try:
|
940
|
+
class F(D, E): pass
|
941
|
+
except TypeError:
|
942
|
+
pass
|
943
|
+
else:
|
944
|
+
raise TestFailed, "expected MRO order disagreement (F)"
|
945
|
+
try:
|
946
|
+
class G(E, D): pass
|
947
|
+
except TypeError:
|
948
|
+
pass
|
949
|
+
else:
|
950
|
+
raise TestFailed, "expected MRO order disagreement (G)"
|
951
|
+
|
952
|
+
|
953
|
+
# see thread python-dev/2002-October/029035.html
|
954
|
+
def ex5():
|
955
|
+
if verbose: print "Testing ex5 from C3 switch discussion..."
|
956
|
+
class A(object): pass
|
957
|
+
class B(object): pass
|
958
|
+
class C(object): pass
|
959
|
+
class X(A): pass
|
960
|
+
class Y(A): pass
|
961
|
+
class Z(X,B,Y,C): pass
|
962
|
+
vereq(Z.__mro__, (Z, X, B, Y, A, C, object))
|
963
|
+
|
964
|
+
# see "A Monotonic Superclass Linearization for Dylan",
|
965
|
+
# by Kim Barrett et al. (OOPSLA 1996)
|
966
|
+
def monotonicity():
|
967
|
+
if verbose: print "Testing MRO monotonicity..."
|
968
|
+
class Boat(object): pass
|
969
|
+
class DayBoat(Boat): pass
|
970
|
+
class WheelBoat(Boat): pass
|
971
|
+
class EngineLess(DayBoat): pass
|
972
|
+
class SmallMultihull(DayBoat): pass
|
973
|
+
class PedalWheelBoat(EngineLess,WheelBoat): pass
|
974
|
+
class SmallCatamaran(SmallMultihull): pass
|
975
|
+
class Pedalo(PedalWheelBoat,SmallCatamaran): pass
|
976
|
+
|
977
|
+
vereq(PedalWheelBoat.__mro__,
|
978
|
+
(PedalWheelBoat, EngineLess, DayBoat, WheelBoat, Boat,
|
979
|
+
object))
|
980
|
+
vereq(SmallCatamaran.__mro__,
|
981
|
+
(SmallCatamaran, SmallMultihull, DayBoat, Boat, object))
|
982
|
+
|
983
|
+
vereq(Pedalo.__mro__,
|
984
|
+
(Pedalo, PedalWheelBoat, EngineLess, SmallCatamaran,
|
985
|
+
SmallMultihull, DayBoat, WheelBoat, Boat, object))
|
986
|
+
|
987
|
+
# see "A Monotonic Superclass Linearization for Dylan",
|
988
|
+
# by Kim Barrett et al. (OOPSLA 1996)
|
989
|
+
def consistency_with_epg():
|
990
|
+
if verbose: print "Testing consistentcy with EPG..."
|
991
|
+
class Pane(object): pass
|
992
|
+
class ScrollingMixin(object): pass
|
993
|
+
class EditingMixin(object): pass
|
994
|
+
class ScrollablePane(Pane,ScrollingMixin): pass
|
995
|
+
class EditablePane(Pane,EditingMixin): pass
|
996
|
+
class EditableScrollablePane(ScrollablePane,EditablePane): pass
|
997
|
+
|
998
|
+
vereq(EditableScrollablePane.__mro__,
|
999
|
+
(EditableScrollablePane, ScrollablePane, EditablePane,
|
1000
|
+
Pane, ScrollingMixin, EditingMixin, object))
|
1001
|
+
|
1002
|
+
mro_err_msg = """Cannot create a consistent method resolution
|
1003
|
+
order (MRO) for bases """
|
1004
|
+
|
1005
|
+
def mro_disagreement():
|
1006
|
+
if verbose: print "Testing error messages for MRO disagreement..."
|
1007
|
+
def raises(exc, expected, callable, *args):
|
1008
|
+
try:
|
1009
|
+
callable(*args)
|
1010
|
+
except exc, msg:
|
1011
|
+
if not str(msg).startswith(expected):
|
1012
|
+
raise TestFailed, "Message %r, expected %r" % (str(msg),
|
1013
|
+
expected)
|
1014
|
+
else:
|
1015
|
+
raise TestFailed, "Expected %s" % exc
|
1016
|
+
class A(object): pass
|
1017
|
+
class B(A): pass
|
1018
|
+
class C(object): pass
|
1019
|
+
# Test some very simple errors
|
1020
|
+
raises(TypeError, "duplicate base class A",
|
1021
|
+
type, "X", (A, A), {})
|
1022
|
+
raises(TypeError, mro_err_msg,
|
1023
|
+
type, "X", (A, B), {})
|
1024
|
+
raises(TypeError, mro_err_msg,
|
1025
|
+
type, "X", (A, C, B), {})
|
1026
|
+
# Test a slightly more complex error
|
1027
|
+
class GridLayout(object): pass
|
1028
|
+
class HorizontalGrid(GridLayout): pass
|
1029
|
+
class VerticalGrid(GridLayout): pass
|
1030
|
+
class HVGrid(HorizontalGrid, VerticalGrid): pass
|
1031
|
+
class VHGrid(VerticalGrid, HorizontalGrid): pass
|
1032
|
+
raises(TypeError, mro_err_msg,
|
1033
|
+
type, "ConfusedGrid", (HVGrid, VHGrid), {})
|
1034
|
+
|
1035
|
+
def objects():
|
1036
|
+
if verbose: print "Testing object class..."
|
1037
|
+
a = object()
|
1038
|
+
vereq(a.__class__, object)
|
1039
|
+
vereq(type(a), object)
|
1040
|
+
b = object()
|
1041
|
+
verify(a is not b)
|
1042
|
+
verify(not hasattr(a, "foo"))
|
1043
|
+
try:
|
1044
|
+
a.foo = 12
|
1045
|
+
except (AttributeError, TypeError):
|
1046
|
+
pass
|
1047
|
+
else:
|
1048
|
+
verify(0, "object() should not allow setting a foo attribute")
|
1049
|
+
verify(not hasattr(object(), "__dict__"))
|
1050
|
+
|
1051
|
+
class Cdict(object):
|
1052
|
+
pass
|
1053
|
+
x = Cdict()
|
1054
|
+
vereq(x.__dict__, {})
|
1055
|
+
x.foo = 1
|
1056
|
+
vereq(x.foo, 1)
|
1057
|
+
vereq(x.__dict__, {'foo': 1})
|
1058
|
+
|
1059
|
+
def slots():
|
1060
|
+
if verbose: print "Testing __slots__..."
|
1061
|
+
class C0(object):
|
1062
|
+
__slots__ = []
|
1063
|
+
x = C0()
|
1064
|
+
verify(not hasattr(x, "__dict__"))
|
1065
|
+
verify(not hasattr(x, "foo"))
|
1066
|
+
|
1067
|
+
class C1(object):
|
1068
|
+
__slots__ = ['a']
|
1069
|
+
x = C1()
|
1070
|
+
verify(not hasattr(x, "__dict__"))
|
1071
|
+
verify(not hasattr(x, "a"))
|
1072
|
+
x.a = 1
|
1073
|
+
vereq(x.a, 1)
|
1074
|
+
x.a = None
|
1075
|
+
veris(x.a, None)
|
1076
|
+
del x.a
|
1077
|
+
verify(not hasattr(x, "a"))
|
1078
|
+
|
1079
|
+
class C3(object):
|
1080
|
+
__slots__ = ['a', 'b', 'c']
|
1081
|
+
x = C3()
|
1082
|
+
verify(not hasattr(x, "__dict__"))
|
1083
|
+
verify(not hasattr(x, 'a'))
|
1084
|
+
verify(not hasattr(x, 'b'))
|
1085
|
+
verify(not hasattr(x, 'c'))
|
1086
|
+
x.a = 1
|
1087
|
+
x.b = 2
|
1088
|
+
x.c = 3
|
1089
|
+
vereq(x.a, 1)
|
1090
|
+
vereq(x.b, 2)
|
1091
|
+
vereq(x.c, 3)
|
1092
|
+
|
1093
|
+
class C4(object):
|
1094
|
+
"""Validate name mangling"""
|
1095
|
+
__slots__ = ['__a']
|
1096
|
+
def __init__(self, value):
|
1097
|
+
self.__a = value
|
1098
|
+
def get(self):
|
1099
|
+
return self.__a
|
1100
|
+
x = C4(5)
|
1101
|
+
verify(not hasattr(x, '__dict__'))
|
1102
|
+
verify(not hasattr(x, '__a'))
|
1103
|
+
vereq(x.get(), 5)
|
1104
|
+
try:
|
1105
|
+
x.__a = 6
|
1106
|
+
except AttributeError:
|
1107
|
+
pass
|
1108
|
+
else:
|
1109
|
+
raise TestFailed, "Double underscored names not mangled"
|
1110
|
+
|
1111
|
+
# Make sure slot names are proper identifiers
|
1112
|
+
try:
|
1113
|
+
class C(object):
|
1114
|
+
__slots__ = [None]
|
1115
|
+
except TypeError:
|
1116
|
+
pass
|
1117
|
+
else:
|
1118
|
+
raise TestFailed, "[None] slots not caught"
|
1119
|
+
try:
|
1120
|
+
class C(object):
|
1121
|
+
__slots__ = ["foo bar"]
|
1122
|
+
except TypeError:
|
1123
|
+
pass
|
1124
|
+
else:
|
1125
|
+
raise TestFailed, "['foo bar'] slots not caught"
|
1126
|
+
try:
|
1127
|
+
class C(object):
|
1128
|
+
__slots__ = ["foo\0bar"]
|
1129
|
+
except TypeError:
|
1130
|
+
pass
|
1131
|
+
else:
|
1132
|
+
raise TestFailed, "['foo\\0bar'] slots not caught"
|
1133
|
+
try:
|
1134
|
+
class C(object):
|
1135
|
+
__slots__ = ["1"]
|
1136
|
+
except TypeError:
|
1137
|
+
pass
|
1138
|
+
else:
|
1139
|
+
raise TestFailed, "['1'] slots not caught"
|
1140
|
+
try:
|
1141
|
+
class C(object):
|
1142
|
+
__slots__ = [""]
|
1143
|
+
except TypeError:
|
1144
|
+
pass
|
1145
|
+
else:
|
1146
|
+
raise TestFailed, "[''] slots not caught"
|
1147
|
+
class C(object):
|
1148
|
+
__slots__ = ["a", "a_b", "_a", "A0123456789Z"]
|
1149
|
+
|
1150
|
+
# Test leaks
|
1151
|
+
class Counted(object):
|
1152
|
+
counter = 0 # counts the number of instances alive
|
1153
|
+
def __init__(self):
|
1154
|
+
Counted.counter += 1
|
1155
|
+
def __del__(self):
|
1156
|
+
Counted.counter -= 1
|
1157
|
+
class C(object):
|
1158
|
+
__slots__ = ['a', 'b', 'c']
|
1159
|
+
x = C()
|
1160
|
+
x.a = Counted()
|
1161
|
+
x.b = Counted()
|
1162
|
+
x.c = Counted()
|
1163
|
+
vereq(Counted.counter, 3)
|
1164
|
+
del x
|
1165
|
+
vereq(Counted.counter, 0)
|
1166
|
+
class D(C):
|
1167
|
+
pass
|
1168
|
+
x = D()
|
1169
|
+
x.a = Counted()
|
1170
|
+
x.z = Counted()
|
1171
|
+
vereq(Counted.counter, 2)
|
1172
|
+
del x
|
1173
|
+
vereq(Counted.counter, 0)
|
1174
|
+
class E(D):
|
1175
|
+
__slots__ = ['e']
|
1176
|
+
x = E()
|
1177
|
+
x.a = Counted()
|
1178
|
+
x.z = Counted()
|
1179
|
+
x.e = Counted()
|
1180
|
+
vereq(Counted.counter, 3)
|
1181
|
+
del x
|
1182
|
+
vereq(Counted.counter, 0)
|
1183
|
+
|
1184
|
+
# Test cyclical leaks [SF bug 519621]
|
1185
|
+
class F(object):
|
1186
|
+
__slots__ = ['a', 'b']
|
1187
|
+
log = []
|
1188
|
+
s = F()
|
1189
|
+
s.a = [Counted(), s]
|
1190
|
+
vereq(Counted.counter, 1)
|
1191
|
+
s = None
|
1192
|
+
import gc
|
1193
|
+
gc.collect()
|
1194
|
+
vereq(Counted.counter, 0)
|
1195
|
+
|
1196
|
+
# Test lookup leaks [SF bug 572567]
|
1197
|
+
import sys,gc
|
1198
|
+
class G(object):
|
1199
|
+
def __cmp__(self, other):
|
1200
|
+
return 0
|
1201
|
+
g = G()
|
1202
|
+
orig_objects = len(gc.get_objects())
|
1203
|
+
for i in xrange(10):
|
1204
|
+
g==g
|
1205
|
+
new_objects = len(gc.get_objects())
|
1206
|
+
vereq(orig_objects, new_objects)
|
1207
|
+
class H(object):
|
1208
|
+
__slots__ = ['a', 'b']
|
1209
|
+
def __init__(self):
|
1210
|
+
self.a = 1
|
1211
|
+
self.b = 2
|
1212
|
+
def __del__(self):
|
1213
|
+
assert self.a == 1
|
1214
|
+
assert self.b == 2
|
1215
|
+
|
1216
|
+
save_stderr = sys.stderr
|
1217
|
+
sys.stderr = sys.stdout
|
1218
|
+
h = H()
|
1219
|
+
try:
|
1220
|
+
del h
|
1221
|
+
finally:
|
1222
|
+
sys.stderr = save_stderr
|
1223
|
+
|
1224
|
+
def slotspecials():
|
1225
|
+
if verbose: print "Testing __dict__ and __weakref__ in __slots__..."
|
1226
|
+
|
1227
|
+
class D(object):
|
1228
|
+
__slots__ = ["__dict__"]
|
1229
|
+
a = D()
|
1230
|
+
verify(hasattr(a, "__dict__"))
|
1231
|
+
verify(not hasattr(a, "__weakref__"))
|
1232
|
+
a.foo = 42
|
1233
|
+
vereq(a.__dict__, {"foo": 42})
|
1234
|
+
|
1235
|
+
class W(object):
|
1236
|
+
__slots__ = ["__weakref__"]
|
1237
|
+
a = W()
|
1238
|
+
verify(hasattr(a, "__weakref__"))
|
1239
|
+
verify(not hasattr(a, "__dict__"))
|
1240
|
+
try:
|
1241
|
+
a.foo = 42
|
1242
|
+
except AttributeError:
|
1243
|
+
pass
|
1244
|
+
else:
|
1245
|
+
raise TestFailed, "shouldn't be allowed to set a.foo"
|
1246
|
+
|
1247
|
+
class C1(W, D):
|
1248
|
+
__slots__ = []
|
1249
|
+
a = C1()
|
1250
|
+
verify(hasattr(a, "__dict__"))
|
1251
|
+
verify(hasattr(a, "__weakref__"))
|
1252
|
+
a.foo = 42
|
1253
|
+
vereq(a.__dict__, {"foo": 42})
|
1254
|
+
|
1255
|
+
class C2(D, W):
|
1256
|
+
__slots__ = []
|
1257
|
+
a = C2()
|
1258
|
+
verify(hasattr(a, "__dict__"))
|
1259
|
+
verify(hasattr(a, "__weakref__"))
|
1260
|
+
a.foo = 42
|
1261
|
+
vereq(a.__dict__, {"foo": 42})
|
1262
|
+
|
1263
|
+
# MRO order disagreement
|
1264
|
+
#
|
1265
|
+
# class C3(C1, C2):
|
1266
|
+
# __slots__ = []
|
1267
|
+
#
|
1268
|
+
# class C4(C2, C1):
|
1269
|
+
# __slots__ = []
|
1270
|
+
|
1271
|
+
def dynamics():
|
1272
|
+
if verbose: print "Testing class attribute propagation..."
|
1273
|
+
class D(object):
|
1274
|
+
pass
|
1275
|
+
class E(D):
|
1276
|
+
pass
|
1277
|
+
class F(D):
|
1278
|
+
pass
|
1279
|
+
D.foo = 1
|
1280
|
+
vereq(D.foo, 1)
|
1281
|
+
# Test that dynamic attributes are inherited
|
1282
|
+
vereq(E.foo, 1)
|
1283
|
+
vereq(F.foo, 1)
|
1284
|
+
# Test dynamic instances
|
1285
|
+
class C(object):
|
1286
|
+
pass
|
1287
|
+
a = C()
|
1288
|
+
verify(not hasattr(a, "foobar"))
|
1289
|
+
C.foobar = 2
|
1290
|
+
vereq(a.foobar, 2)
|
1291
|
+
C.method = lambda self: 42
|
1292
|
+
vereq(a.method(), 42)
|
1293
|
+
C.__repr__ = lambda self: "C()"
|
1294
|
+
vereq(repr(a), "C()")
|
1295
|
+
C.__int__ = lambda self: 100
|
1296
|
+
vereq(int(a), 100)
|
1297
|
+
vereq(a.foobar, 2)
|
1298
|
+
verify(not hasattr(a, "spam"))
|
1299
|
+
def mygetattr(self, name):
|
1300
|
+
if name == "spam":
|
1301
|
+
return "spam"
|
1302
|
+
raise AttributeError
|
1303
|
+
C.__getattr__ = mygetattr
|
1304
|
+
vereq(a.spam, "spam")
|
1305
|
+
a.new = 12
|
1306
|
+
vereq(a.new, 12)
|
1307
|
+
def mysetattr(self, name, value):
|
1308
|
+
if name == "spam":
|
1309
|
+
raise AttributeError
|
1310
|
+
return object.__setattr__(self, name, value)
|
1311
|
+
C.__setattr__ = mysetattr
|
1312
|
+
try:
|
1313
|
+
a.spam = "not spam"
|
1314
|
+
except AttributeError:
|
1315
|
+
pass
|
1316
|
+
else:
|
1317
|
+
verify(0, "expected AttributeError")
|
1318
|
+
vereq(a.spam, "spam")
|
1319
|
+
class D(C):
|
1320
|
+
pass
|
1321
|
+
d = D()
|
1322
|
+
d.foo = 1
|
1323
|
+
vereq(d.foo, 1)
|
1324
|
+
|
1325
|
+
# Test handling of int*seq and seq*int
|
1326
|
+
class I(int):
|
1327
|
+
pass
|
1328
|
+
vereq("a"*I(2), "aa")
|
1329
|
+
vereq(I(2)*"a", "aa")
|
1330
|
+
vereq(2*I(3), 6)
|
1331
|
+
vereq(I(3)*2, 6)
|
1332
|
+
vereq(I(3)*I(2), 6)
|
1333
|
+
|
1334
|
+
# Test handling of long*seq and seq*long
|
1335
|
+
class L(long):
|
1336
|
+
pass
|
1337
|
+
vereq("a"*L(2L), "aa")
|
1338
|
+
vereq(L(2L)*"a", "aa")
|
1339
|
+
vereq(2*L(3), 6)
|
1340
|
+
vereq(L(3)*2, 6)
|
1341
|
+
vereq(L(3)*L(2), 6)
|
1342
|
+
|
1343
|
+
# Test comparison of classes with dynamic metaclasses
|
1344
|
+
class dynamicmetaclass(type):
|
1345
|
+
pass
|
1346
|
+
class someclass:
|
1347
|
+
__metaclass__ = dynamicmetaclass
|
1348
|
+
verify(someclass != object)
|
1349
|
+
|
1350
|
+
def errors():
|
1351
|
+
if verbose: print "Testing errors..."
|
1352
|
+
|
1353
|
+
try:
|
1354
|
+
class C(list, dict):
|
1355
|
+
pass
|
1356
|
+
except TypeError:
|
1357
|
+
pass
|
1358
|
+
else:
|
1359
|
+
verify(0, "inheritance from both list and dict should be illegal")
|
1360
|
+
|
1361
|
+
try:
|
1362
|
+
class C(object, None):
|
1363
|
+
pass
|
1364
|
+
except TypeError:
|
1365
|
+
pass
|
1366
|
+
else:
|
1367
|
+
verify(0, "inheritance from non-type should be illegal")
|
1368
|
+
class Classic:
|
1369
|
+
pass
|
1370
|
+
|
1371
|
+
try:
|
1372
|
+
class C(type(len)):
|
1373
|
+
pass
|
1374
|
+
except TypeError:
|
1375
|
+
pass
|
1376
|
+
else:
|
1377
|
+
verify(0, "inheritance from CFunction should be illegal")
|
1378
|
+
|
1379
|
+
try:
|
1380
|
+
class C(object):
|
1381
|
+
__slots__ = 1
|
1382
|
+
except TypeError:
|
1383
|
+
pass
|
1384
|
+
else:
|
1385
|
+
verify(0, "__slots__ = 1 should be illegal")
|
1386
|
+
|
1387
|
+
try:
|
1388
|
+
class C(object):
|
1389
|
+
__slots__ = [1]
|
1390
|
+
except TypeError:
|
1391
|
+
pass
|
1392
|
+
else:
|
1393
|
+
verify(0, "__slots__ = [1] should be illegal")
|
1394
|
+
|
1395
|
+
def classmethods():
|
1396
|
+
if verbose: print "Testing class methods..."
|
1397
|
+
class C(object):
|
1398
|
+
def foo(*a): return a
|
1399
|
+
goo = classmethod(foo)
|
1400
|
+
c = C()
|
1401
|
+
vereq(C.goo(1), (C, 1))
|
1402
|
+
vereq(c.goo(1), (C, 1))
|
1403
|
+
vereq(c.foo(1), (c, 1))
|
1404
|
+
class D(C):
|
1405
|
+
pass
|
1406
|
+
d = D()
|
1407
|
+
vereq(D.goo(1), (D, 1))
|
1408
|
+
vereq(d.goo(1), (D, 1))
|
1409
|
+
vereq(d.foo(1), (d, 1))
|
1410
|
+
vereq(D.foo(d, 1), (d, 1))
|
1411
|
+
# Test for a specific crash (SF bug 528132)
|
1412
|
+
def f(cls, arg): return (cls, arg)
|
1413
|
+
ff = classmethod(f)
|
1414
|
+
vereq(ff.__get__(0, int)(42), (int, 42))
|
1415
|
+
vereq(ff.__get__(0)(42), (int, 42))
|
1416
|
+
|
1417
|
+
# Test super() with classmethods (SF bug 535444)
|
1418
|
+
veris(C.goo.im_self, C)
|
1419
|
+
veris(D.goo.im_self, D)
|
1420
|
+
veris(super(D,D).goo.im_self, D)
|
1421
|
+
veris(super(D,d).goo.im_self, D)
|
1422
|
+
vereq(super(D,D).goo(), (D,))
|
1423
|
+
vereq(super(D,d).goo(), (D,))
|
1424
|
+
|
1425
|
+
# Verify that argument is checked for callability (SF bug 753451)
|
1426
|
+
try:
|
1427
|
+
classmethod(1).__get__(1)
|
1428
|
+
except TypeError:
|
1429
|
+
pass
|
1430
|
+
else:
|
1431
|
+
raise TestFailed, "classmethod should check for callability"
|
1432
|
+
|
1433
|
+
def staticmethods():
|
1434
|
+
if verbose: print "Testing static methods..."
|
1435
|
+
class C(object):
|
1436
|
+
def foo(*a): return a
|
1437
|
+
goo = staticmethod(foo)
|
1438
|
+
c = C()
|
1439
|
+
vereq(C.goo(1), (1,))
|
1440
|
+
vereq(c.goo(1), (1,))
|
1441
|
+
vereq(c.foo(1), (c, 1,))
|
1442
|
+
class D(C):
|
1443
|
+
pass
|
1444
|
+
d = D()
|
1445
|
+
vereq(D.goo(1), (1,))
|
1446
|
+
vereq(d.goo(1), (1,))
|
1447
|
+
vereq(d.foo(1), (d, 1))
|
1448
|
+
vereq(D.foo(d, 1), (d, 1))
|
1449
|
+
|
1450
|
+
def classic():
|
1451
|
+
if verbose: print "Testing classic classes..."
|
1452
|
+
class C:
|
1453
|
+
def foo(*a): return a
|
1454
|
+
goo = classmethod(foo)
|
1455
|
+
c = C()
|
1456
|
+
vereq(C.goo(1), (C, 1))
|
1457
|
+
vereq(c.goo(1), (C, 1))
|
1458
|
+
vereq(c.foo(1), (c, 1))
|
1459
|
+
class D(C):
|
1460
|
+
pass
|
1461
|
+
d = D()
|
1462
|
+
vereq(D.goo(1), (D, 1))
|
1463
|
+
vereq(d.goo(1), (D, 1))
|
1464
|
+
vereq(d.foo(1), (d, 1))
|
1465
|
+
vereq(D.foo(d, 1), (d, 1))
|
1466
|
+
class E: # *not* subclassing from C
|
1467
|
+
foo = C.foo
|
1468
|
+
vereq(E().foo, C.foo) # i.e., unbound
|
1469
|
+
verify(repr(C.foo.__get__(C())).startswith("<bound method "))
|
1470
|
+
|
1471
|
+
def compattr():
|
1472
|
+
if verbose: print "Testing computed attributes..."
|
1473
|
+
class C(object):
|
1474
|
+
class computed_attribute(object):
|
1475
|
+
def __init__(self, get, set=None, delete=None):
|
1476
|
+
self.__get = get
|
1477
|
+
self.__set = set
|
1478
|
+
self.__delete = delete
|
1479
|
+
def __get__(self, obj, type=None):
|
1480
|
+
return self.__get(obj)
|
1481
|
+
def __set__(self, obj, value):
|
1482
|
+
return self.__set(obj, value)
|
1483
|
+
def __delete__(self, obj):
|
1484
|
+
return self.__delete(obj)
|
1485
|
+
def __init__(self):
|
1486
|
+
self.__x = 0
|
1487
|
+
def __get_x(self):
|
1488
|
+
x = self.__x
|
1489
|
+
self.__x = x+1
|
1490
|
+
return x
|
1491
|
+
def __set_x(self, x):
|
1492
|
+
self.__x = x
|
1493
|
+
def __delete_x(self):
|
1494
|
+
del self.__x
|
1495
|
+
x = computed_attribute(__get_x, __set_x, __delete_x)
|
1496
|
+
a = C()
|
1497
|
+
vereq(a.x, 0)
|
1498
|
+
vereq(a.x, 1)
|
1499
|
+
a.x = 10
|
1500
|
+
vereq(a.x, 10)
|
1501
|
+
vereq(a.x, 11)
|
1502
|
+
del a.x
|
1503
|
+
vereq(hasattr(a, 'x'), 0)
|
1504
|
+
|
1505
|
+
def newslot():
|
1506
|
+
if verbose: print "Testing __new__ slot override..."
|
1507
|
+
class C(list):
|
1508
|
+
def __new__(cls):
|
1509
|
+
self = list.__new__(cls)
|
1510
|
+
self.foo = 1
|
1511
|
+
return self
|
1512
|
+
def __init__(self):
|
1513
|
+
self.foo = self.foo + 2
|
1514
|
+
a = C()
|
1515
|
+
vereq(a.foo, 3)
|
1516
|
+
verify(a.__class__ is C)
|
1517
|
+
class D(C):
|
1518
|
+
pass
|
1519
|
+
b = D()
|
1520
|
+
vereq(b.foo, 3)
|
1521
|
+
verify(b.__class__ is D)
|
1522
|
+
|
1523
|
+
def altmro():
|
1524
|
+
if verbose: print "Testing mro() and overriding it..."
|
1525
|
+
class A(object):
|
1526
|
+
def f(self): return "A"
|
1527
|
+
class B(A):
|
1528
|
+
pass
|
1529
|
+
class C(A):
|
1530
|
+
def f(self): return "C"
|
1531
|
+
class D(B, C):
|
1532
|
+
pass
|
1533
|
+
vereq(D.mro(), [D, B, C, A, object])
|
1534
|
+
vereq(D.__mro__, (D, B, C, A, object))
|
1535
|
+
vereq(D().f(), "C")
|
1536
|
+
|
1537
|
+
class PerverseMetaType(type):
|
1538
|
+
def mro(cls):
|
1539
|
+
L = type.mro(cls)
|
1540
|
+
L.reverse()
|
1541
|
+
return L
|
1542
|
+
class X(D,B,C,A):
|
1543
|
+
__metaclass__ = PerverseMetaType
|
1544
|
+
vereq(X.__mro__, (object, A, C, B, D, X))
|
1545
|
+
vereq(X().f(), "A")
|
1546
|
+
|
1547
|
+
def overloading():
|
1548
|
+
if verbose: print "Testing operator overloading..."
|
1549
|
+
|
1550
|
+
class B(object):
|
1551
|
+
"Intermediate class because object doesn't have a __setattr__"
|
1552
|
+
|
1553
|
+
class C(B):
|
1554
|
+
|
1555
|
+
def __getattr__(self, name):
|
1556
|
+
if name == "foo":
|
1557
|
+
return ("getattr", name)
|
1558
|
+
else:
|
1559
|
+
raise AttributeError
|
1560
|
+
def __setattr__(self, name, value):
|
1561
|
+
if name == "foo":
|
1562
|
+
self.setattr = (name, value)
|
1563
|
+
else:
|
1564
|
+
return B.__setattr__(self, name, value)
|
1565
|
+
def __delattr__(self, name):
|
1566
|
+
if name == "foo":
|
1567
|
+
self.delattr = name
|
1568
|
+
else:
|
1569
|
+
return B.__delattr__(self, name)
|
1570
|
+
|
1571
|
+
def __getitem__(self, key):
|
1572
|
+
return ("getitem", key)
|
1573
|
+
def __setitem__(self, key, value):
|
1574
|
+
self.setitem = (key, value)
|
1575
|
+
def __delitem__(self, key):
|
1576
|
+
self.delitem = key
|
1577
|
+
|
1578
|
+
def __getslice__(self, i, j):
|
1579
|
+
return ("getslice", i, j)
|
1580
|
+
def __setslice__(self, i, j, value):
|
1581
|
+
self.setslice = (i, j, value)
|
1582
|
+
def __delslice__(self, i, j):
|
1583
|
+
self.delslice = (i, j)
|
1584
|
+
|
1585
|
+
a = C()
|
1586
|
+
vereq(a.foo, ("getattr", "foo"))
|
1587
|
+
a.foo = 12
|
1588
|
+
vereq(a.setattr, ("foo", 12))
|
1589
|
+
del a.foo
|
1590
|
+
vereq(a.delattr, "foo")
|
1591
|
+
|
1592
|
+
vereq(a[12], ("getitem", 12))
|
1593
|
+
a[12] = 21
|
1594
|
+
vereq(a.setitem, (12, 21))
|
1595
|
+
del a[12]
|
1596
|
+
vereq(a.delitem, 12)
|
1597
|
+
|
1598
|
+
vereq(a[0:10], ("getslice", 0, 10))
|
1599
|
+
a[0:10] = "foo"
|
1600
|
+
vereq(a.setslice, (0, 10, "foo"))
|
1601
|
+
del a[0:10]
|
1602
|
+
vereq(a.delslice, (0, 10))
|
1603
|
+
|
1604
|
+
def methods():
|
1605
|
+
if verbose: print "Testing methods..."
|
1606
|
+
class C(object):
|
1607
|
+
def __init__(self, x):
|
1608
|
+
self.x = x
|
1609
|
+
def foo(self):
|
1610
|
+
return self.x
|
1611
|
+
c1 = C(1)
|
1612
|
+
vereq(c1.foo(), 1)
|
1613
|
+
class D(C):
|
1614
|
+
boo = C.foo
|
1615
|
+
goo = c1.foo
|
1616
|
+
d2 = D(2)
|
1617
|
+
vereq(d2.foo(), 2)
|
1618
|
+
vereq(d2.boo(), 2)
|
1619
|
+
vereq(d2.goo(), 1)
|
1620
|
+
class E(object):
|
1621
|
+
foo = C.foo
|
1622
|
+
vereq(E().foo, C.foo) # i.e., unbound
|
1623
|
+
verify(repr(C.foo.__get__(C(1))).startswith("<bound method "))
|
1624
|
+
|
1625
|
+
def specials():
|
1626
|
+
# Test operators like __hash__ for which a built-in default exists
|
1627
|
+
if verbose: print "Testing special operators..."
|
1628
|
+
# Test the default behavior for static classes
|
1629
|
+
class C(object):
|
1630
|
+
def __getitem__(self, i):
|
1631
|
+
if 0 <= i < 10: return i
|
1632
|
+
raise IndexError
|
1633
|
+
c1 = C()
|
1634
|
+
c2 = C()
|
1635
|
+
verify(not not c1)
|
1636
|
+
vereq(hash(c1), id(c1))
|
1637
|
+
vereq(cmp(c1, c2), cmp(id(c1), id(c2)))
|
1638
|
+
vereq(c1, c1)
|
1639
|
+
verify(c1 != c2)
|
1640
|
+
verify(not c1 != c1)
|
1641
|
+
verify(not c1 == c2)
|
1642
|
+
# Note that the module name appears in str/repr, and that varies
|
1643
|
+
# depending on whether this test is run standalone or from a framework.
|
1644
|
+
verify(str(c1).find('C object at ') >= 0)
|
1645
|
+
vereq(str(c1), repr(c1))
|
1646
|
+
verify(-1 not in c1)
|
1647
|
+
for i in range(10):
|
1648
|
+
verify(i in c1)
|
1649
|
+
verify(10 not in c1)
|
1650
|
+
# Test the default behavior for dynamic classes
|
1651
|
+
class D(object):
|
1652
|
+
def __getitem__(self, i):
|
1653
|
+
if 0 <= i < 10: return i
|
1654
|
+
raise IndexError
|
1655
|
+
d1 = D()
|
1656
|
+
d2 = D()
|
1657
|
+
verify(not not d1)
|
1658
|
+
vereq(hash(d1), id(d1))
|
1659
|
+
vereq(cmp(d1, d2), cmp(id(d1), id(d2)))
|
1660
|
+
vereq(d1, d1)
|
1661
|
+
verify(d1 != d2)
|
1662
|
+
verify(not d1 != d1)
|
1663
|
+
verify(not d1 == d2)
|
1664
|
+
# Note that the module name appears in str/repr, and that varies
|
1665
|
+
# depending on whether this test is run standalone or from a framework.
|
1666
|
+
verify(str(d1).find('D object at ') >= 0)
|
1667
|
+
vereq(str(d1), repr(d1))
|
1668
|
+
verify(-1 not in d1)
|
1669
|
+
for i in range(10):
|
1670
|
+
verify(i in d1)
|
1671
|
+
verify(10 not in d1)
|
1672
|
+
# Test overridden behavior for static classes
|
1673
|
+
class Proxy(object):
|
1674
|
+
def __init__(self, x):
|
1675
|
+
self.x = x
|
1676
|
+
def __nonzero__(self):
|
1677
|
+
return not not self.x
|
1678
|
+
def __hash__(self):
|
1679
|
+
return hash(self.x)
|
1680
|
+
def __eq__(self, other):
|
1681
|
+
return self.x == other
|
1682
|
+
def __ne__(self, other):
|
1683
|
+
return self.x != other
|
1684
|
+
def __cmp__(self, other):
|
1685
|
+
return cmp(self.x, other.x)
|
1686
|
+
def __str__(self):
|
1687
|
+
return "Proxy:%s" % self.x
|
1688
|
+
def __repr__(self):
|
1689
|
+
return "Proxy(%r)" % self.x
|
1690
|
+
def __contains__(self, value):
|
1691
|
+
return value in self.x
|
1692
|
+
p0 = Proxy(0)
|
1693
|
+
p1 = Proxy(1)
|
1694
|
+
p_1 = Proxy(-1)
|
1695
|
+
verify(not p0)
|
1696
|
+
verify(not not p1)
|
1697
|
+
vereq(hash(p0), hash(0))
|
1698
|
+
vereq(p0, p0)
|
1699
|
+
verify(p0 != p1)
|
1700
|
+
verify(not p0 != p0)
|
1701
|
+
vereq(not p0, p1)
|
1702
|
+
vereq(cmp(p0, p1), -1)
|
1703
|
+
vereq(cmp(p0, p0), 0)
|
1704
|
+
vereq(cmp(p0, p_1), 1)
|
1705
|
+
vereq(str(p0), "Proxy:0")
|
1706
|
+
vereq(repr(p0), "Proxy(0)")
|
1707
|
+
p10 = Proxy(range(10))
|
1708
|
+
verify(-1 not in p10)
|
1709
|
+
for i in range(10):
|
1710
|
+
verify(i in p10)
|
1711
|
+
verify(10 not in p10)
|
1712
|
+
# Test overridden behavior for dynamic classes
|
1713
|
+
class DProxy(object):
|
1714
|
+
def __init__(self, x):
|
1715
|
+
self.x = x
|
1716
|
+
def __nonzero__(self):
|
1717
|
+
return not not self.x
|
1718
|
+
def __hash__(self):
|
1719
|
+
return hash(self.x)
|
1720
|
+
def __eq__(self, other):
|
1721
|
+
return self.x == other
|
1722
|
+
def __ne__(self, other):
|
1723
|
+
return self.x != other
|
1724
|
+
def __cmp__(self, other):
|
1725
|
+
return cmp(self.x, other.x)
|
1726
|
+
def __str__(self):
|
1727
|
+
return "DProxy:%s" % self.x
|
1728
|
+
def __repr__(self):
|
1729
|
+
return "DProxy(%r)" % self.x
|
1730
|
+
def __contains__(self, value):
|
1731
|
+
return value in self.x
|
1732
|
+
p0 = DProxy(0)
|
1733
|
+
p1 = DProxy(1)
|
1734
|
+
p_1 = DProxy(-1)
|
1735
|
+
verify(not p0)
|
1736
|
+
verify(not not p1)
|
1737
|
+
vereq(hash(p0), hash(0))
|
1738
|
+
vereq(p0, p0)
|
1739
|
+
verify(p0 != p1)
|
1740
|
+
verify(not p0 != p0)
|
1741
|
+
vereq(not p0, p1)
|
1742
|
+
vereq(cmp(p0, p1), -1)
|
1743
|
+
vereq(cmp(p0, p0), 0)
|
1744
|
+
vereq(cmp(p0, p_1), 1)
|
1745
|
+
vereq(str(p0), "DProxy:0")
|
1746
|
+
vereq(repr(p0), "DProxy(0)")
|
1747
|
+
p10 = DProxy(range(10))
|
1748
|
+
verify(-1 not in p10)
|
1749
|
+
for i in range(10):
|
1750
|
+
verify(i in p10)
|
1751
|
+
verify(10 not in p10)
|
1752
|
+
# Safety test for __cmp__
|
1753
|
+
def unsafecmp(a, b):
|
1754
|
+
try:
|
1755
|
+
a.__class__.__cmp__(a, b)
|
1756
|
+
except TypeError:
|
1757
|
+
pass
|
1758
|
+
else:
|
1759
|
+
raise TestFailed, "shouldn't allow %s.__cmp__(%r, %r)" % (
|
1760
|
+
a.__class__, a, b)
|
1761
|
+
unsafecmp(u"123", "123")
|
1762
|
+
unsafecmp("123", u"123")
|
1763
|
+
unsafecmp(1, 1.0)
|
1764
|
+
unsafecmp(1.0, 1)
|
1765
|
+
unsafecmp(1, 1L)
|
1766
|
+
unsafecmp(1L, 1)
|
1767
|
+
|
1768
|
+
class Letter(str):
|
1769
|
+
def __new__(cls, letter):
|
1770
|
+
if letter == 'EPS':
|
1771
|
+
return str.__new__(cls)
|
1772
|
+
return str.__new__(cls, letter)
|
1773
|
+
def __str__(self):
|
1774
|
+
if not self:
|
1775
|
+
return 'EPS'
|
1776
|
+
return self
|
1777
|
+
|
1778
|
+
# sys.stdout needs to be the original to trigger the recursion bug
|
1779
|
+
import sys
|
1780
|
+
test_stdout = sys.stdout
|
1781
|
+
sys.stdout = get_original_stdout()
|
1782
|
+
try:
|
1783
|
+
# nothing should actually be printed, this should raise an exception
|
1784
|
+
print Letter('w')
|
1785
|
+
except RuntimeError:
|
1786
|
+
pass
|
1787
|
+
else:
|
1788
|
+
raise TestFailed, "expected a RuntimeError for print recursion"
|
1789
|
+
sys.stdout = test_stdout
|
1790
|
+
|
1791
|
+
def weakrefs():
|
1792
|
+
if verbose: print "Testing weak references..."
|
1793
|
+
import weakref
|
1794
|
+
class C(object):
|
1795
|
+
pass
|
1796
|
+
c = C()
|
1797
|
+
r = weakref.ref(c)
|
1798
|
+
verify(r() is c)
|
1799
|
+
del c
|
1800
|
+
verify(r() is None)
|
1801
|
+
del r
|
1802
|
+
class NoWeak(object):
|
1803
|
+
__slots__ = ['foo']
|
1804
|
+
no = NoWeak()
|
1805
|
+
try:
|
1806
|
+
weakref.ref(no)
|
1807
|
+
except TypeError, msg:
|
1808
|
+
verify(str(msg).find("weak reference") >= 0)
|
1809
|
+
else:
|
1810
|
+
verify(0, "weakref.ref(no) should be illegal")
|
1811
|
+
class Weak(object):
|
1812
|
+
__slots__ = ['foo', '__weakref__']
|
1813
|
+
yes = Weak()
|
1814
|
+
r = weakref.ref(yes)
|
1815
|
+
verify(r() is yes)
|
1816
|
+
del yes
|
1817
|
+
verify(r() is None)
|
1818
|
+
del r
|
1819
|
+
|
1820
|
+
def properties():
|
1821
|
+
if verbose: print "Testing property..."
|
1822
|
+
class C(object):
|
1823
|
+
def getx(self):
|
1824
|
+
return self.__x
|
1825
|
+
def setx(self, value):
|
1826
|
+
self.__x = value
|
1827
|
+
def delx(self):
|
1828
|
+
del self.__x
|
1829
|
+
x = property(getx, setx, delx, doc="I'm the x property.")
|
1830
|
+
a = C()
|
1831
|
+
verify(not hasattr(a, "x"))
|
1832
|
+
a.x = 42
|
1833
|
+
vereq(a._C__x, 42)
|
1834
|
+
vereq(a.x, 42)
|
1835
|
+
del a.x
|
1836
|
+
verify(not hasattr(a, "x"))
|
1837
|
+
verify(not hasattr(a, "_C__x"))
|
1838
|
+
C.x.__set__(a, 100)
|
1839
|
+
vereq(C.x.__get__(a), 100)
|
1840
|
+
C.x.__delete__(a)
|
1841
|
+
verify(not hasattr(a, "x"))
|
1842
|
+
|
1843
|
+
raw = C.__dict__['x']
|
1844
|
+
verify(isinstance(raw, property))
|
1845
|
+
|
1846
|
+
attrs = dir(raw)
|
1847
|
+
verify("__doc__" in attrs)
|
1848
|
+
verify("fget" in attrs)
|
1849
|
+
verify("fset" in attrs)
|
1850
|
+
verify("fdel" in attrs)
|
1851
|
+
|
1852
|
+
vereq(raw.__doc__, "I'm the x property.")
|
1853
|
+
verify(raw.fget is C.__dict__['getx'])
|
1854
|
+
verify(raw.fset is C.__dict__['setx'])
|
1855
|
+
verify(raw.fdel is C.__dict__['delx'])
|
1856
|
+
|
1857
|
+
for attr in "__doc__", "fget", "fset", "fdel":
|
1858
|
+
try:
|
1859
|
+
setattr(raw, attr, 42)
|
1860
|
+
except TypeError, msg:
|
1861
|
+
if str(msg).find('readonly') < 0:
|
1862
|
+
raise TestFailed("when setting readonly attr %r on a "
|
1863
|
+
"property, got unexpected TypeError "
|
1864
|
+
"msg %r" % (attr, str(msg)))
|
1865
|
+
else:
|
1866
|
+
raise TestFailed("expected TypeError from trying to set "
|
1867
|
+
"readonly %r attr on a property" % attr)
|
1868
|
+
|
1869
|
+
class D(object):
|
1870
|
+
__getitem__ = property(lambda s: 1/0)
|
1871
|
+
|
1872
|
+
d = D()
|
1873
|
+
try:
|
1874
|
+
for i in d:
|
1875
|
+
str(i)
|
1876
|
+
except ZeroDivisionError:
|
1877
|
+
pass
|
1878
|
+
else:
|
1879
|
+
raise TestFailed, "expected ZeroDivisionError from bad property"
|
1880
|
+
|
1881
|
+
def supers():
|
1882
|
+
if verbose: print "Testing super..."
|
1883
|
+
|
1884
|
+
class A(object):
|
1885
|
+
def meth(self, a):
|
1886
|
+
return "A(%r)" % a
|
1887
|
+
|
1888
|
+
vereq(A().meth(1), "A(1)")
|
1889
|
+
|
1890
|
+
class B(A):
|
1891
|
+
def __init__(self):
|
1892
|
+
self.__super = super(B, self)
|
1893
|
+
def meth(self, a):
|
1894
|
+
return "B(%r)" % a + self.__super.meth(a)
|
1895
|
+
|
1896
|
+
vereq(B().meth(2), "B(2)A(2)")
|
1897
|
+
|
1898
|
+
class C(A):
|
1899
|
+
def meth(self, a):
|
1900
|
+
return "C(%r)" % a + self.__super.meth(a)
|
1901
|
+
C._C__super = super(C)
|
1902
|
+
|
1903
|
+
vereq(C().meth(3), "C(3)A(3)")
|
1904
|
+
|
1905
|
+
class D(C, B):
|
1906
|
+
def meth(self, a):
|
1907
|
+
return "D(%r)" % a + super(D, self).meth(a)
|
1908
|
+
|
1909
|
+
vereq(D().meth(4), "D(4)C(4)B(4)A(4)")
|
1910
|
+
|
1911
|
+
# Test for subclassing super
|
1912
|
+
|
1913
|
+
class mysuper(super):
|
1914
|
+
def __init__(self, *args):
|
1915
|
+
return super(mysuper, self).__init__(*args)
|
1916
|
+
|
1917
|
+
class E(D):
|
1918
|
+
def meth(self, a):
|
1919
|
+
return "E(%r)" % a + mysuper(E, self).meth(a)
|
1920
|
+
|
1921
|
+
vereq(E().meth(5), "E(5)D(5)C(5)B(5)A(5)")
|
1922
|
+
|
1923
|
+
class F(E):
|
1924
|
+
def meth(self, a):
|
1925
|
+
s = self.__super # == mysuper(F, self)
|
1926
|
+
return "F(%r)[%s]" % (a, s.__class__.__name__) + s.meth(a)
|
1927
|
+
F._F__super = mysuper(F)
|
1928
|
+
|
1929
|
+
vereq(F().meth(6), "F(6)[mysuper]E(6)D(6)C(6)B(6)A(6)")
|
1930
|
+
|
1931
|
+
# Make sure certain errors are raised
|
1932
|
+
|
1933
|
+
try:
|
1934
|
+
super(D, 42)
|
1935
|
+
except TypeError:
|
1936
|
+
pass
|
1937
|
+
else:
|
1938
|
+
raise TestFailed, "shouldn't allow super(D, 42)"
|
1939
|
+
|
1940
|
+
try:
|
1941
|
+
super(D, C())
|
1942
|
+
except TypeError:
|
1943
|
+
pass
|
1944
|
+
else:
|
1945
|
+
raise TestFailed, "shouldn't allow super(D, C())"
|
1946
|
+
|
1947
|
+
try:
|
1948
|
+
super(D).__get__(12)
|
1949
|
+
except TypeError:
|
1950
|
+
pass
|
1951
|
+
else:
|
1952
|
+
raise TestFailed, "shouldn't allow super(D).__get__(12)"
|
1953
|
+
|
1954
|
+
try:
|
1955
|
+
super(D).__get__(C())
|
1956
|
+
except TypeError:
|
1957
|
+
pass
|
1958
|
+
else:
|
1959
|
+
raise TestFailed, "shouldn't allow super(D).__get__(C())"
|
1960
|
+
|
1961
|
+
# Make sure data descriptors can be overridden and accessed via super
|
1962
|
+
# (new feature in Python 2.3)
|
1963
|
+
|
1964
|
+
class DDbase(object):
|
1965
|
+
def getx(self): return 42
|
1966
|
+
x = property(getx)
|
1967
|
+
|
1968
|
+
class DDsub(DDbase):
|
1969
|
+
def getx(self): return "hello"
|
1970
|
+
x = property(getx)
|
1971
|
+
|
1972
|
+
dd = DDsub()
|
1973
|
+
vereq(dd.x, "hello")
|
1974
|
+
vereq(super(DDsub, dd).x, 42)
|
1975
|
+
|
1976
|
+
# Ensure that super() lookup of descriptor from classmethod
|
1977
|
+
# works (SF ID# 743627)
|
1978
|
+
|
1979
|
+
class Base(object):
|
1980
|
+
aProp = property(lambda self: "foo")
|
1981
|
+
|
1982
|
+
class Sub(Base):
|
1983
|
+
def test(klass):
|
1984
|
+
return super(Sub,klass).aProp
|
1985
|
+
test = classmethod(test)
|
1986
|
+
|
1987
|
+
veris(Sub.test(), Base.aProp)
|
1988
|
+
|
1989
|
+
|
1990
|
+
def inherits():
|
1991
|
+
if verbose: print "Testing inheritance from basic types..."
|
1992
|
+
|
1993
|
+
class hexint(int):
|
1994
|
+
def __repr__(self):
|
1995
|
+
return hex(self)
|
1996
|
+
def __add__(self, other):
|
1997
|
+
return hexint(int.__add__(self, other))
|
1998
|
+
# (Note that overriding __radd__ doesn't work,
|
1999
|
+
# because the int type gets first dibs.)
|
2000
|
+
vereq(repr(hexint(7) + 9), "0x10")
|
2001
|
+
vereq(repr(hexint(1000) + 7), "0x3ef")
|
2002
|
+
a = hexint(12345)
|
2003
|
+
vereq(a, 12345)
|
2004
|
+
vereq(int(a), 12345)
|
2005
|
+
verify(int(a).__class__ is int)
|
2006
|
+
vereq(hash(a), hash(12345))
|
2007
|
+
verify((+a).__class__ is int)
|
2008
|
+
verify((a >> 0).__class__ is int)
|
2009
|
+
verify((a << 0).__class__ is int)
|
2010
|
+
verify((hexint(0) << 12).__class__ is int)
|
2011
|
+
verify((hexint(0) >> 12).__class__ is int)
|
2012
|
+
|
2013
|
+
class octlong(long):
|
2014
|
+
__slots__ = []
|
2015
|
+
def __str__(self):
|
2016
|
+
s = oct(self)
|
2017
|
+
if s[-1] == 'L':
|
2018
|
+
s = s[:-1]
|
2019
|
+
return s
|
2020
|
+
def __add__(self, other):
|
2021
|
+
return self.__class__(super(octlong, self).__add__(other))
|
2022
|
+
__radd__ = __add__
|
2023
|
+
vereq(str(octlong(3) + 5), "010")
|
2024
|
+
# (Note that overriding __radd__ here only seems to work
|
2025
|
+
# because the example uses a short int left argument.)
|
2026
|
+
vereq(str(5 + octlong(3000)), "05675")
|
2027
|
+
a = octlong(12345)
|
2028
|
+
vereq(a, 12345L)
|
2029
|
+
vereq(long(a), 12345L)
|
2030
|
+
vereq(hash(a), hash(12345L))
|
2031
|
+
verify(long(a).__class__ is long)
|
2032
|
+
verify((+a).__class__ is long)
|
2033
|
+
verify((-a).__class__ is long)
|
2034
|
+
verify((-octlong(0)).__class__ is long)
|
2035
|
+
verify((a >> 0).__class__ is long)
|
2036
|
+
verify((a << 0).__class__ is long)
|
2037
|
+
verify((a - 0).__class__ is long)
|
2038
|
+
verify((a * 1).__class__ is long)
|
2039
|
+
verify((a ** 1).__class__ is long)
|
2040
|
+
verify((a // 1).__class__ is long)
|
2041
|
+
verify((1 * a).__class__ is long)
|
2042
|
+
verify((a | 0).__class__ is long)
|
2043
|
+
verify((a ^ 0).__class__ is long)
|
2044
|
+
verify((a & -1L).__class__ is long)
|
2045
|
+
verify((octlong(0) << 12).__class__ is long)
|
2046
|
+
verify((octlong(0) >> 12).__class__ is long)
|
2047
|
+
verify(abs(octlong(0)).__class__ is long)
|
2048
|
+
|
2049
|
+
# Because octlong overrides __add__, we can't check the absence of +0
|
2050
|
+
# optimizations using octlong.
|
2051
|
+
class longclone(long):
|
2052
|
+
pass
|
2053
|
+
a = longclone(1)
|
2054
|
+
verify((a + 0).__class__ is long)
|
2055
|
+
verify((0 + a).__class__ is long)
|
2056
|
+
|
2057
|
+
# Check that negative clones don't segfault
|
2058
|
+
a = longclone(-1)
|
2059
|
+
vereq(a.__dict__, {})
|
2060
|
+
vereq(long(a), -1) # verify PyNumber_Long() copies the sign bit
|
2061
|
+
|
2062
|
+
class precfloat(float):
|
2063
|
+
__slots__ = ['prec']
|
2064
|
+
def __init__(self, value=0.0, prec=12):
|
2065
|
+
self.prec = int(prec)
|
2066
|
+
float.__init__(value)
|
2067
|
+
def __repr__(self):
|
2068
|
+
return "%.*g" % (self.prec, self)
|
2069
|
+
vereq(repr(precfloat(1.1)), "1.1")
|
2070
|
+
a = precfloat(12345)
|
2071
|
+
vereq(a, 12345.0)
|
2072
|
+
vereq(float(a), 12345.0)
|
2073
|
+
verify(float(a).__class__ is float)
|
2074
|
+
vereq(hash(a), hash(12345.0))
|
2075
|
+
verify((+a).__class__ is float)
|
2076
|
+
|
2077
|
+
class madcomplex(complex):
|
2078
|
+
def __repr__(self):
|
2079
|
+
return "%.17gj%+.17g" % (self.imag, self.real)
|
2080
|
+
a = madcomplex(-3, 4)
|
2081
|
+
vereq(repr(a), "4j-3")
|
2082
|
+
base = complex(-3, 4)
|
2083
|
+
veris(base.__class__, complex)
|
2084
|
+
vereq(a, base)
|
2085
|
+
vereq(complex(a), base)
|
2086
|
+
veris(complex(a).__class__, complex)
|
2087
|
+
a = madcomplex(a) # just trying another form of the constructor
|
2088
|
+
vereq(repr(a), "4j-3")
|
2089
|
+
vereq(a, base)
|
2090
|
+
vereq(complex(a), base)
|
2091
|
+
veris(complex(a).__class__, complex)
|
2092
|
+
vereq(hash(a), hash(base))
|
2093
|
+
veris((+a).__class__, complex)
|
2094
|
+
veris((a + 0).__class__, complex)
|
2095
|
+
vereq(a + 0, base)
|
2096
|
+
veris((a - 0).__class__, complex)
|
2097
|
+
vereq(a - 0, base)
|
2098
|
+
veris((a * 1).__class__, complex)
|
2099
|
+
vereq(a * 1, base)
|
2100
|
+
veris((a / 1).__class__, complex)
|
2101
|
+
vereq(a / 1, base)
|
2102
|
+
|
2103
|
+
class madtuple(tuple):
|
2104
|
+
_rev = None
|
2105
|
+
def rev(self):
|
2106
|
+
if self._rev is not None:
|
2107
|
+
return self._rev
|
2108
|
+
L = list(self)
|
2109
|
+
L.reverse()
|
2110
|
+
self._rev = self.__class__(L)
|
2111
|
+
return self._rev
|
2112
|
+
a = madtuple((1,2,3,4,5,6,7,8,9,0))
|
2113
|
+
vereq(a, (1,2,3,4,5,6,7,8,9,0))
|
2114
|
+
vereq(a.rev(), madtuple((0,9,8,7,6,5,4,3,2,1)))
|
2115
|
+
vereq(a.rev().rev(), madtuple((1,2,3,4,5,6,7,8,9,0)))
|
2116
|
+
for i in range(512):
|
2117
|
+
t = madtuple(range(i))
|
2118
|
+
u = t.rev()
|
2119
|
+
v = u.rev()
|
2120
|
+
vereq(v, t)
|
2121
|
+
a = madtuple((1,2,3,4,5))
|
2122
|
+
vereq(tuple(a), (1,2,3,4,5))
|
2123
|
+
verify(tuple(a).__class__ is tuple)
|
2124
|
+
vereq(hash(a), hash((1,2,3,4,5)))
|
2125
|
+
verify(a[:].__class__ is tuple)
|
2126
|
+
verify((a * 1).__class__ is tuple)
|
2127
|
+
verify((a * 0).__class__ is tuple)
|
2128
|
+
verify((a + ()).__class__ is tuple)
|
2129
|
+
a = madtuple(())
|
2130
|
+
vereq(tuple(a), ())
|
2131
|
+
verify(tuple(a).__class__ is tuple)
|
2132
|
+
verify((a + a).__class__ is tuple)
|
2133
|
+
verify((a * 0).__class__ is tuple)
|
2134
|
+
verify((a * 1).__class__ is tuple)
|
2135
|
+
verify((a * 2).__class__ is tuple)
|
2136
|
+
verify(a[:].__class__ is tuple)
|
2137
|
+
|
2138
|
+
class madstring(str):
|
2139
|
+
_rev = None
|
2140
|
+
def rev(self):
|
2141
|
+
if self._rev is not None:
|
2142
|
+
return self._rev
|
2143
|
+
L = list(self)
|
2144
|
+
L.reverse()
|
2145
|
+
self._rev = self.__class__("".join(L))
|
2146
|
+
return self._rev
|
2147
|
+
s = madstring("abcdefghijklmnopqrstuvwxyz")
|
2148
|
+
vereq(s, "abcdefghijklmnopqrstuvwxyz")
|
2149
|
+
vereq(s.rev(), madstring("zyxwvutsrqponmlkjihgfedcba"))
|
2150
|
+
vereq(s.rev().rev(), madstring("abcdefghijklmnopqrstuvwxyz"))
|
2151
|
+
for i in range(256):
|
2152
|
+
s = madstring("".join(map(chr, range(i))))
|
2153
|
+
t = s.rev()
|
2154
|
+
u = t.rev()
|
2155
|
+
vereq(u, s)
|
2156
|
+
s = madstring("12345")
|
2157
|
+
vereq(str(s), "12345")
|
2158
|
+
verify(str(s).__class__ is str)
|
2159
|
+
|
2160
|
+
base = "\x00" * 5
|
2161
|
+
s = madstring(base)
|
2162
|
+
vereq(s, base)
|
2163
|
+
vereq(str(s), base)
|
2164
|
+
verify(str(s).__class__ is str)
|
2165
|
+
vereq(hash(s), hash(base))
|
2166
|
+
vereq({s: 1}[base], 1)
|
2167
|
+
vereq({base: 1}[s], 1)
|
2168
|
+
verify((s + "").__class__ is str)
|
2169
|
+
vereq(s + "", base)
|
2170
|
+
verify(("" + s).__class__ is str)
|
2171
|
+
vereq("" + s, base)
|
2172
|
+
verify((s * 0).__class__ is str)
|
2173
|
+
vereq(s * 0, "")
|
2174
|
+
verify((s * 1).__class__ is str)
|
2175
|
+
vereq(s * 1, base)
|
2176
|
+
verify((s * 2).__class__ is str)
|
2177
|
+
vereq(s * 2, base + base)
|
2178
|
+
verify(s[:].__class__ is str)
|
2179
|
+
vereq(s[:], base)
|
2180
|
+
verify(s[0:0].__class__ is str)
|
2181
|
+
vereq(s[0:0], "")
|
2182
|
+
verify(s.strip().__class__ is str)
|
2183
|
+
vereq(s.strip(), base)
|
2184
|
+
verify(s.lstrip().__class__ is str)
|
2185
|
+
vereq(s.lstrip(), base)
|
2186
|
+
verify(s.rstrip().__class__ is str)
|
2187
|
+
vereq(s.rstrip(), base)
|
2188
|
+
identitytab = ''.join([chr(i) for i in range(256)])
|
2189
|
+
verify(s.translate(identitytab).__class__ is str)
|
2190
|
+
vereq(s.translate(identitytab), base)
|
2191
|
+
verify(s.translate(identitytab, "x").__class__ is str)
|
2192
|
+
vereq(s.translate(identitytab, "x"), base)
|
2193
|
+
vereq(s.translate(identitytab, "\x00"), "")
|
2194
|
+
verify(s.replace("x", "x").__class__ is str)
|
2195
|
+
vereq(s.replace("x", "x"), base)
|
2196
|
+
verify(s.ljust(len(s)).__class__ is str)
|
2197
|
+
vereq(s.ljust(len(s)), base)
|
2198
|
+
verify(s.rjust(len(s)).__class__ is str)
|
2199
|
+
vereq(s.rjust(len(s)), base)
|
2200
|
+
verify(s.center(len(s)).__class__ is str)
|
2201
|
+
vereq(s.center(len(s)), base)
|
2202
|
+
verify(s.lower().__class__ is str)
|
2203
|
+
vereq(s.lower(), base)
|
2204
|
+
|
2205
|
+
s = madstring("x y")
|
2206
|
+
vereq(s, "x y")
|
2207
|
+
verify(intern(s).__class__ is str)
|
2208
|
+
verify(intern(s) is intern("x y"))
|
2209
|
+
vereq(intern(s), "x y")
|
2210
|
+
|
2211
|
+
i = intern("y x")
|
2212
|
+
s = madstring("y x")
|
2213
|
+
vereq(s, i)
|
2214
|
+
verify(intern(s).__class__ is str)
|
2215
|
+
verify(intern(s) is i)
|
2216
|
+
|
2217
|
+
s = madstring(i)
|
2218
|
+
verify(intern(s).__class__ is str)
|
2219
|
+
verify(intern(s) is i)
|
2220
|
+
|
2221
|
+
class madunicode(unicode):
|
2222
|
+
_rev = None
|
2223
|
+
def rev(self):
|
2224
|
+
if self._rev is not None:
|
2225
|
+
return self._rev
|
2226
|
+
L = list(self)
|
2227
|
+
L.reverse()
|
2228
|
+
self._rev = self.__class__(u"".join(L))
|
2229
|
+
return self._rev
|
2230
|
+
u = madunicode("ABCDEF")
|
2231
|
+
vereq(u, u"ABCDEF")
|
2232
|
+
vereq(u.rev(), madunicode(u"FEDCBA"))
|
2233
|
+
vereq(u.rev().rev(), madunicode(u"ABCDEF"))
|
2234
|
+
base = u"12345"
|
2235
|
+
u = madunicode(base)
|
2236
|
+
vereq(unicode(u), base)
|
2237
|
+
verify(unicode(u).__class__ is unicode)
|
2238
|
+
vereq(hash(u), hash(base))
|
2239
|
+
vereq({u: 1}[base], 1)
|
2240
|
+
vereq({base: 1}[u], 1)
|
2241
|
+
verify(u.strip().__class__ is unicode)
|
2242
|
+
vereq(u.strip(), base)
|
2243
|
+
verify(u.lstrip().__class__ is unicode)
|
2244
|
+
vereq(u.lstrip(), base)
|
2245
|
+
verify(u.rstrip().__class__ is unicode)
|
2246
|
+
vereq(u.rstrip(), base)
|
2247
|
+
verify(u.replace(u"x", u"x").__class__ is unicode)
|
2248
|
+
vereq(u.replace(u"x", u"x"), base)
|
2249
|
+
verify(u.replace(u"xy", u"xy").__class__ is unicode)
|
2250
|
+
vereq(u.replace(u"xy", u"xy"), base)
|
2251
|
+
verify(u.center(len(u)).__class__ is unicode)
|
2252
|
+
vereq(u.center(len(u)), base)
|
2253
|
+
verify(u.ljust(len(u)).__class__ is unicode)
|
2254
|
+
vereq(u.ljust(len(u)), base)
|
2255
|
+
verify(u.rjust(len(u)).__class__ is unicode)
|
2256
|
+
vereq(u.rjust(len(u)), base)
|
2257
|
+
verify(u.lower().__class__ is unicode)
|
2258
|
+
vereq(u.lower(), base)
|
2259
|
+
verify(u.upper().__class__ is unicode)
|
2260
|
+
vereq(u.upper(), base)
|
2261
|
+
verify(u.capitalize().__class__ is unicode)
|
2262
|
+
vereq(u.capitalize(), base)
|
2263
|
+
verify(u.title().__class__ is unicode)
|
2264
|
+
vereq(u.title(), base)
|
2265
|
+
verify((u + u"").__class__ is unicode)
|
2266
|
+
vereq(u + u"", base)
|
2267
|
+
verify((u"" + u).__class__ is unicode)
|
2268
|
+
vereq(u"" + u, base)
|
2269
|
+
verify((u * 0).__class__ is unicode)
|
2270
|
+
vereq(u * 0, u"")
|
2271
|
+
verify((u * 1).__class__ is unicode)
|
2272
|
+
vereq(u * 1, base)
|
2273
|
+
verify((u * 2).__class__ is unicode)
|
2274
|
+
vereq(u * 2, base + base)
|
2275
|
+
verify(u[:].__class__ is unicode)
|
2276
|
+
vereq(u[:], base)
|
2277
|
+
verify(u[0:0].__class__ is unicode)
|
2278
|
+
vereq(u[0:0], u"")
|
2279
|
+
|
2280
|
+
class sublist(list):
|
2281
|
+
pass
|
2282
|
+
a = sublist(range(5))
|
2283
|
+
vereq(a, range(5))
|
2284
|
+
a.append("hello")
|
2285
|
+
vereq(a, range(5) + ["hello"])
|
2286
|
+
a[5] = 5
|
2287
|
+
vereq(a, range(6))
|
2288
|
+
a.extend(range(6, 20))
|
2289
|
+
vereq(a, range(20))
|
2290
|
+
a[-5:] = []
|
2291
|
+
vereq(a, range(15))
|
2292
|
+
del a[10:15]
|
2293
|
+
vereq(len(a), 10)
|
2294
|
+
vereq(a, range(10))
|
2295
|
+
vereq(list(a), range(10))
|
2296
|
+
vereq(a[0], 0)
|
2297
|
+
vereq(a[9], 9)
|
2298
|
+
vereq(a[-10], 0)
|
2299
|
+
vereq(a[-1], 9)
|
2300
|
+
vereq(a[:5], range(5))
|
2301
|
+
|
2302
|
+
class CountedInput(file):
|
2303
|
+
"""Counts lines read by self.readline().
|
2304
|
+
|
2305
|
+
self.lineno is the 0-based ordinal of the last line read, up to
|
2306
|
+
a maximum of one greater than the number of lines in the file.
|
2307
|
+
|
2308
|
+
self.ateof is true if and only if the final "" line has been read,
|
2309
|
+
at which point self.lineno stops incrementing, and further calls
|
2310
|
+
to readline() continue to return "".
|
2311
|
+
"""
|
2312
|
+
|
2313
|
+
lineno = 0
|
2314
|
+
ateof = 0
|
2315
|
+
def readline(self):
|
2316
|
+
if self.ateof:
|
2317
|
+
return ""
|
2318
|
+
s = file.readline(self)
|
2319
|
+
# Next line works too.
|
2320
|
+
# s = super(CountedInput, self).readline()
|
2321
|
+
self.lineno += 1
|
2322
|
+
if s == "":
|
2323
|
+
self.ateof = 1
|
2324
|
+
return s
|
2325
|
+
|
2326
|
+
f = file(name=TESTFN, mode='w')
|
2327
|
+
lines = ['a\n', 'b\n', 'c\n']
|
2328
|
+
try:
|
2329
|
+
f.writelines(lines)
|
2330
|
+
f.close()
|
2331
|
+
f = CountedInput(TESTFN)
|
2332
|
+
for (i, expected) in zip(range(1, 5) + [4], lines + 2 * [""]):
|
2333
|
+
got = f.readline()
|
2334
|
+
vereq(expected, got)
|
2335
|
+
vereq(f.lineno, i)
|
2336
|
+
vereq(f.ateof, (i > len(lines)))
|
2337
|
+
f.close()
|
2338
|
+
finally:
|
2339
|
+
try:
|
2340
|
+
f.close()
|
2341
|
+
except:
|
2342
|
+
pass
|
2343
|
+
try:
|
2344
|
+
import os
|
2345
|
+
os.unlink(TESTFN)
|
2346
|
+
except:
|
2347
|
+
pass
|
2348
|
+
|
2349
|
+
def keywords():
|
2350
|
+
if verbose:
|
2351
|
+
print "Testing keyword args to basic type constructors ..."
|
2352
|
+
vereq(int(x=1), 1)
|
2353
|
+
vereq(float(x=2), 2.0)
|
2354
|
+
vereq(long(x=3), 3L)
|
2355
|
+
vereq(complex(imag=42, real=666), complex(666, 42))
|
2356
|
+
vereq(str(object=500), '500')
|
2357
|
+
vereq(unicode(string='abc', errors='strict'), u'abc')
|
2358
|
+
vereq(tuple(sequence=range(3)), (0, 1, 2))
|
2359
|
+
vereq(list(sequence=(0, 1, 2)), range(3))
|
2360
|
+
# note: as of Python 2.3, dict() no longer has an "items" keyword arg
|
2361
|
+
|
2362
|
+
for constructor in (int, float, long, complex, str, unicode,
|
2363
|
+
tuple, list, file):
|
2364
|
+
try:
|
2365
|
+
constructor(bogus_keyword_arg=1)
|
2366
|
+
except TypeError:
|
2367
|
+
pass
|
2368
|
+
else:
|
2369
|
+
raise TestFailed("expected TypeError from bogus keyword "
|
2370
|
+
"argument to %r" % constructor)
|
2371
|
+
|
2372
|
+
def restricted():
|
2373
|
+
# XXX This test is disabled because rexec is not deemed safe
|
2374
|
+
return
|
2375
|
+
import rexec
|
2376
|
+
if verbose:
|
2377
|
+
print "Testing interaction with restricted execution ..."
|
2378
|
+
|
2379
|
+
sandbox = rexec.RExec()
|
2380
|
+
|
2381
|
+
code1 = """f = open(%r, 'w')""" % TESTFN
|
2382
|
+
code2 = """f = file(%r, 'w')""" % TESTFN
|
2383
|
+
code3 = """\
|
2384
|
+
f = open(%r)
|
2385
|
+
t = type(f) # a sneaky way to get the file() constructor
|
2386
|
+
f.close()
|
2387
|
+
f = t(%r, 'w') # rexec can't catch this by itself
|
2388
|
+
""" % (TESTFN, TESTFN)
|
2389
|
+
|
2390
|
+
f = open(TESTFN, 'w') # Create the file so code3 can find it.
|
2391
|
+
f.close()
|
2392
|
+
|
2393
|
+
try:
|
2394
|
+
for code in code1, code2, code3:
|
2395
|
+
try:
|
2396
|
+
sandbox.r_exec(code)
|
2397
|
+
except IOError, msg:
|
2398
|
+
if str(msg).find("restricted") >= 0:
|
2399
|
+
outcome = "OK"
|
2400
|
+
else:
|
2401
|
+
outcome = "got an exception, but not an expected one"
|
2402
|
+
else:
|
2403
|
+
outcome = "expected a restricted-execution exception"
|
2404
|
+
|
2405
|
+
if outcome != "OK":
|
2406
|
+
raise TestFailed("%s, in %r" % (outcome, code))
|
2407
|
+
|
2408
|
+
finally:
|
2409
|
+
try:
|
2410
|
+
import os
|
2411
|
+
os.unlink(TESTFN)
|
2412
|
+
except:
|
2413
|
+
pass
|
2414
|
+
|
2415
|
+
def str_subclass_as_dict_key():
|
2416
|
+
if verbose:
|
2417
|
+
print "Testing a str subclass used as dict key .."
|
2418
|
+
|
2419
|
+
class cistr(str):
|
2420
|
+
"""Sublcass of str that computes __eq__ case-insensitively.
|
2421
|
+
|
2422
|
+
Also computes a hash code of the string in canonical form.
|
2423
|
+
"""
|
2424
|
+
|
2425
|
+
def __init__(self, value):
|
2426
|
+
self.canonical = value.lower()
|
2427
|
+
self.hashcode = hash(self.canonical)
|
2428
|
+
|
2429
|
+
def __eq__(self, other):
|
2430
|
+
if not isinstance(other, cistr):
|
2431
|
+
other = cistr(other)
|
2432
|
+
return self.canonical == other.canonical
|
2433
|
+
|
2434
|
+
def __hash__(self):
|
2435
|
+
return self.hashcode
|
2436
|
+
|
2437
|
+
vereq(cistr('ABC'), 'abc')
|
2438
|
+
vereq('aBc', cistr('ABC'))
|
2439
|
+
vereq(str(cistr('ABC')), 'ABC')
|
2440
|
+
|
2441
|
+
d = {cistr('one'): 1, cistr('two'): 2, cistr('tHree'): 3}
|
2442
|
+
vereq(d[cistr('one')], 1)
|
2443
|
+
vereq(d[cistr('tWo')], 2)
|
2444
|
+
vereq(d[cistr('THrEE')], 3)
|
2445
|
+
verify(cistr('ONe') in d)
|
2446
|
+
vereq(d.get(cistr('thrEE')), 3)
|
2447
|
+
|
2448
|
+
def classic_comparisons():
|
2449
|
+
if verbose: print "Testing classic comparisons..."
|
2450
|
+
class classic:
|
2451
|
+
pass
|
2452
|
+
for base in (classic, int, object):
|
2453
|
+
if verbose: print " (base = %s)" % base
|
2454
|
+
class C(base):
|
2455
|
+
def __init__(self, value):
|
2456
|
+
self.value = int(value)
|
2457
|
+
def __cmp__(self, other):
|
2458
|
+
if isinstance(other, C):
|
2459
|
+
return cmp(self.value, other.value)
|
2460
|
+
if isinstance(other, int) or isinstance(other, long):
|
2461
|
+
return cmp(self.value, other)
|
2462
|
+
return NotImplemented
|
2463
|
+
c1 = C(1)
|
2464
|
+
c2 = C(2)
|
2465
|
+
c3 = C(3)
|
2466
|
+
vereq(c1, 1)
|
2467
|
+
c = {1: c1, 2: c2, 3: c3}
|
2468
|
+
for x in 1, 2, 3:
|
2469
|
+
for y in 1, 2, 3:
|
2470
|
+
verify(cmp(c[x], c[y]) == cmp(x, y), "x=%d, y=%d" % (x, y))
|
2471
|
+
for op in "<", "<=", "==", "!=", ">", ">=":
|
2472
|
+
verify(eval("c[x] %s c[y]" % op) == eval("x %s y" % op),
|
2473
|
+
"x=%d, y=%d" % (x, y))
|
2474
|
+
verify(cmp(c[x], y) == cmp(x, y), "x=%d, y=%d" % (x, y))
|
2475
|
+
verify(cmp(x, c[y]) == cmp(x, y), "x=%d, y=%d" % (x, y))
|
2476
|
+
|
2477
|
+
def rich_comparisons():
|
2478
|
+
if verbose:
|
2479
|
+
print "Testing rich comparisons..."
|
2480
|
+
class Z(complex):
|
2481
|
+
pass
|
2482
|
+
z = Z(1)
|
2483
|
+
vereq(z, 1+0j)
|
2484
|
+
vereq(1+0j, z)
|
2485
|
+
class ZZ(complex):
|
2486
|
+
def __eq__(self, other):
|
2487
|
+
try:
|
2488
|
+
return abs(self - other) <= 1e-6
|
2489
|
+
except:
|
2490
|
+
return NotImplemented
|
2491
|
+
zz = ZZ(1.0000003)
|
2492
|
+
vereq(zz, 1+0j)
|
2493
|
+
vereq(1+0j, zz)
|
2494
|
+
|
2495
|
+
class classic:
|
2496
|
+
pass
|
2497
|
+
for base in (classic, int, object, list):
|
2498
|
+
if verbose: print " (base = %s)" % base
|
2499
|
+
class C(base):
|
2500
|
+
def __init__(self, value):
|
2501
|
+
self.value = int(value)
|
2502
|
+
def __cmp__(self, other):
|
2503
|
+
raise TestFailed, "shouldn't call __cmp__"
|
2504
|
+
def __eq__(self, other):
|
2505
|
+
if isinstance(other, C):
|
2506
|
+
return self.value == other.value
|
2507
|
+
if isinstance(other, int) or isinstance(other, long):
|
2508
|
+
return self.value == other
|
2509
|
+
return NotImplemented
|
2510
|
+
def __ne__(self, other):
|
2511
|
+
if isinstance(other, C):
|
2512
|
+
return self.value != other.value
|
2513
|
+
if isinstance(other, int) or isinstance(other, long):
|
2514
|
+
return self.value != other
|
2515
|
+
return NotImplemented
|
2516
|
+
def __lt__(self, other):
|
2517
|
+
if isinstance(other, C):
|
2518
|
+
return self.value < other.value
|
2519
|
+
if isinstance(other, int) or isinstance(other, long):
|
2520
|
+
return self.value < other
|
2521
|
+
return NotImplemented
|
2522
|
+
def __le__(self, other):
|
2523
|
+
if isinstance(other, C):
|
2524
|
+
return self.value <= other.value
|
2525
|
+
if isinstance(other, int) or isinstance(other, long):
|
2526
|
+
return self.value <= other
|
2527
|
+
return NotImplemented
|
2528
|
+
def __gt__(self, other):
|
2529
|
+
if isinstance(other, C):
|
2530
|
+
return self.value > other.value
|
2531
|
+
if isinstance(other, int) or isinstance(other, long):
|
2532
|
+
return self.value > other
|
2533
|
+
return NotImplemented
|
2534
|
+
def __ge__(self, other):
|
2535
|
+
if isinstance(other, C):
|
2536
|
+
return self.value >= other.value
|
2537
|
+
if isinstance(other, int) or isinstance(other, long):
|
2538
|
+
return self.value >= other
|
2539
|
+
return NotImplemented
|
2540
|
+
c1 = C(1)
|
2541
|
+
c2 = C(2)
|
2542
|
+
c3 = C(3)
|
2543
|
+
vereq(c1, 1)
|
2544
|
+
c = {1: c1, 2: c2, 3: c3}
|
2545
|
+
for x in 1, 2, 3:
|
2546
|
+
for y in 1, 2, 3:
|
2547
|
+
for op in "<", "<=", "==", "!=", ">", ">=":
|
2548
|
+
verify(eval("c[x] %s c[y]" % op) == eval("x %s y" % op),
|
2549
|
+
"x=%d, y=%d" % (x, y))
|
2550
|
+
verify(eval("c[x] %s y" % op) == eval("x %s y" % op),
|
2551
|
+
"x=%d, y=%d" % (x, y))
|
2552
|
+
verify(eval("x %s c[y]" % op) == eval("x %s y" % op),
|
2553
|
+
"x=%d, y=%d" % (x, y))
|
2554
|
+
|
2555
|
+
def coercions():
|
2556
|
+
if verbose: print "Testing coercions..."
|
2557
|
+
class I(int): pass
|
2558
|
+
coerce(I(0), 0)
|
2559
|
+
coerce(0, I(0))
|
2560
|
+
class L(long): pass
|
2561
|
+
coerce(L(0), 0)
|
2562
|
+
coerce(L(0), 0L)
|
2563
|
+
coerce(0, L(0))
|
2564
|
+
coerce(0L, L(0))
|
2565
|
+
class F(float): pass
|
2566
|
+
coerce(F(0), 0)
|
2567
|
+
coerce(F(0), 0L)
|
2568
|
+
coerce(F(0), 0.)
|
2569
|
+
coerce(0, F(0))
|
2570
|
+
coerce(0L, F(0))
|
2571
|
+
coerce(0., F(0))
|
2572
|
+
class C(complex): pass
|
2573
|
+
coerce(C(0), 0)
|
2574
|
+
coerce(C(0), 0L)
|
2575
|
+
coerce(C(0), 0.)
|
2576
|
+
coerce(C(0), 0j)
|
2577
|
+
coerce(0, C(0))
|
2578
|
+
coerce(0L, C(0))
|
2579
|
+
coerce(0., C(0))
|
2580
|
+
coerce(0j, C(0))
|
2581
|
+
|
2582
|
+
def descrdoc():
|
2583
|
+
if verbose: print "Testing descriptor doc strings..."
|
2584
|
+
def check(descr, what):
|
2585
|
+
vereq(descr.__doc__, what)
|
2586
|
+
check(file.closed, "True if the file is closed") # getset descriptor
|
2587
|
+
check(file.name, "file name") # member descriptor
|
2588
|
+
|
2589
|
+
def setclass():
|
2590
|
+
if verbose: print "Testing __class__ assignment..."
|
2591
|
+
class C(object): pass
|
2592
|
+
class D(object): pass
|
2593
|
+
class E(object): pass
|
2594
|
+
class F(D, E): pass
|
2595
|
+
for cls in C, D, E, F:
|
2596
|
+
for cls2 in C, D, E, F:
|
2597
|
+
x = cls()
|
2598
|
+
x.__class__ = cls2
|
2599
|
+
verify(x.__class__ is cls2)
|
2600
|
+
x.__class__ = cls
|
2601
|
+
verify(x.__class__ is cls)
|
2602
|
+
def cant(x, C):
|
2603
|
+
try:
|
2604
|
+
x.__class__ = C
|
2605
|
+
except TypeError:
|
2606
|
+
pass
|
2607
|
+
else:
|
2608
|
+
raise TestFailed, "shouldn't allow %r.__class__ = %r" % (x, C)
|
2609
|
+
try:
|
2610
|
+
delattr(x, "__class__")
|
2611
|
+
except TypeError:
|
2612
|
+
pass
|
2613
|
+
else:
|
2614
|
+
raise TestFailed, "shouldn't allow del %r.__class__" % x
|
2615
|
+
cant(C(), list)
|
2616
|
+
cant(list(), C)
|
2617
|
+
cant(C(), 1)
|
2618
|
+
cant(C(), object)
|
2619
|
+
cant(object(), list)
|
2620
|
+
cant(list(), object)
|
2621
|
+
class Int(int): __slots__ = []
|
2622
|
+
cant(2, Int)
|
2623
|
+
cant(Int(), int)
|
2624
|
+
cant(2, bool)
|
2625
|
+
o = object()
|
2626
|
+
cant(o, type(1))
|
2627
|
+
cant(o, type(None))
|
2628
|
+
del o
|
2629
|
+
|
2630
|
+
def setdict():
|
2631
|
+
if verbose: print "Testing __dict__ assignment..."
|
2632
|
+
class C(object): pass
|
2633
|
+
a = C()
|
2634
|
+
a.__dict__ = {'b': 1}
|
2635
|
+
vereq(a.b, 1)
|
2636
|
+
def cant(x, dict):
|
2637
|
+
try:
|
2638
|
+
x.__dict__ = dict
|
2639
|
+
except TypeError:
|
2640
|
+
pass
|
2641
|
+
else:
|
2642
|
+
raise TestFailed, "shouldn't allow %r.__dict__ = %r" % (x, dict)
|
2643
|
+
cant(a, None)
|
2644
|
+
cant(a, [])
|
2645
|
+
cant(a, 1)
|
2646
|
+
del a.__dict__ # Deleting __dict__ is allowed
|
2647
|
+
# Classes don't allow __dict__ assignment
|
2648
|
+
cant(C, {})
|
2649
|
+
|
2650
|
+
def pickles():
|
2651
|
+
if verbose:
|
2652
|
+
print "Testing pickling and copying new-style classes and objects..."
|
2653
|
+
import pickle, cPickle
|
2654
|
+
|
2655
|
+
def sorteditems(d):
|
2656
|
+
L = d.items()
|
2657
|
+
L.sort()
|
2658
|
+
return L
|
2659
|
+
|
2660
|
+
global C
|
2661
|
+
class C(object):
|
2662
|
+
def __init__(self, a, b):
|
2663
|
+
super(C, self).__init__()
|
2664
|
+
self.a = a
|
2665
|
+
self.b = b
|
2666
|
+
def __repr__(self):
|
2667
|
+
return "C(%r, %r)" % (self.a, self.b)
|
2668
|
+
|
2669
|
+
global C1
|
2670
|
+
class C1(list):
|
2671
|
+
def __new__(cls, a, b):
|
2672
|
+
return super(C1, cls).__new__(cls)
|
2673
|
+
def __getnewargs__(self):
|
2674
|
+
return (self.a, self.b)
|
2675
|
+
def __init__(self, a, b):
|
2676
|
+
self.a = a
|
2677
|
+
self.b = b
|
2678
|
+
def __repr__(self):
|
2679
|
+
return "C1(%r, %r)<%r>" % (self.a, self.b, list(self))
|
2680
|
+
|
2681
|
+
global C2
|
2682
|
+
class C2(int):
|
2683
|
+
def __new__(cls, a, b, val=0):
|
2684
|
+
return super(C2, cls).__new__(cls, val)
|
2685
|
+
def __getnewargs__(self):
|
2686
|
+
return (self.a, self.b, int(self))
|
2687
|
+
def __init__(self, a, b, val=0):
|
2688
|
+
self.a = a
|
2689
|
+
self.b = b
|
2690
|
+
def __repr__(self):
|
2691
|
+
return "C2(%r, %r)<%r>" % (self.a, self.b, int(self))
|
2692
|
+
|
2693
|
+
global C3
|
2694
|
+
class C3(object):
|
2695
|
+
def __init__(self, foo):
|
2696
|
+
self.foo = foo
|
2697
|
+
def __getstate__(self):
|
2698
|
+
return self.foo
|
2699
|
+
def __setstate__(self, foo):
|
2700
|
+
self.foo = foo
|
2701
|
+
|
2702
|
+
global C4classic, C4
|
2703
|
+
class C4classic: # classic
|
2704
|
+
pass
|
2705
|
+
class C4(C4classic, object): # mixed inheritance
|
2706
|
+
pass
|
2707
|
+
|
2708
|
+
for p in pickle, cPickle:
|
2709
|
+
for bin in 0, 1:
|
2710
|
+
if verbose:
|
2711
|
+
print p.__name__, ["text", "binary"][bin]
|
2712
|
+
|
2713
|
+
for cls in C, C1, C2:
|
2714
|
+
s = p.dumps(cls, bin)
|
2715
|
+
cls2 = p.loads(s)
|
2716
|
+
verify(cls2 is cls)
|
2717
|
+
|
2718
|
+
a = C1(1, 2); a.append(42); a.append(24)
|
2719
|
+
b = C2("hello", "world", 42)
|
2720
|
+
s = p.dumps((a, b), bin)
|
2721
|
+
x, y = p.loads(s)
|
2722
|
+
vereq(x.__class__, a.__class__)
|
2723
|
+
vereq(sorteditems(x.__dict__), sorteditems(a.__dict__))
|
2724
|
+
vereq(y.__class__, b.__class__)
|
2725
|
+
vereq(sorteditems(y.__dict__), sorteditems(b.__dict__))
|
2726
|
+
vereq(`x`, `a`)
|
2727
|
+
vereq(`y`, `b`)
|
2728
|
+
if verbose:
|
2729
|
+
print "a = x =", a
|
2730
|
+
print "b = y =", b
|
2731
|
+
# Test for __getstate__ and __setstate__ on new style class
|
2732
|
+
u = C3(42)
|
2733
|
+
s = p.dumps(u, bin)
|
2734
|
+
v = p.loads(s)
|
2735
|
+
veris(u.__class__, v.__class__)
|
2736
|
+
vereq(u.foo, v.foo)
|
2737
|
+
# Test for picklability of hybrid class
|
2738
|
+
u = C4()
|
2739
|
+
u.foo = 42
|
2740
|
+
s = p.dumps(u, bin)
|
2741
|
+
v = p.loads(s)
|
2742
|
+
veris(u.__class__, v.__class__)
|
2743
|
+
vereq(u.foo, v.foo)
|
2744
|
+
|
2745
|
+
# Testing copy.deepcopy()
|
2746
|
+
if verbose:
|
2747
|
+
print "deepcopy"
|
2748
|
+
import copy
|
2749
|
+
for cls in C, C1, C2:
|
2750
|
+
cls2 = copy.deepcopy(cls)
|
2751
|
+
verify(cls2 is cls)
|
2752
|
+
|
2753
|
+
a = C1(1, 2); a.append(42); a.append(24)
|
2754
|
+
b = C2("hello", "world", 42)
|
2755
|
+
x, y = copy.deepcopy((a, b))
|
2756
|
+
vereq(x.__class__, a.__class__)
|
2757
|
+
vereq(sorteditems(x.__dict__), sorteditems(a.__dict__))
|
2758
|
+
vereq(y.__class__, b.__class__)
|
2759
|
+
vereq(sorteditems(y.__dict__), sorteditems(b.__dict__))
|
2760
|
+
vereq(`x`, `a`)
|
2761
|
+
vereq(`y`, `b`)
|
2762
|
+
if verbose:
|
2763
|
+
print "a = x =", a
|
2764
|
+
print "b = y =", b
|
2765
|
+
|
2766
|
+
def pickleslots():
|
2767
|
+
if verbose: print "Testing pickling of classes with __slots__ ..."
|
2768
|
+
import pickle, cPickle
|
2769
|
+
# Pickling of classes with __slots__ but without __getstate__ should fail
|
2770
|
+
global B, C, D, E
|
2771
|
+
class B(object):
|
2772
|
+
pass
|
2773
|
+
for base in [object, B]:
|
2774
|
+
class C(base):
|
2775
|
+
__slots__ = ['a']
|
2776
|
+
class D(C):
|
2777
|
+
pass
|
2778
|
+
try:
|
2779
|
+
pickle.dumps(C())
|
2780
|
+
except TypeError:
|
2781
|
+
pass
|
2782
|
+
else:
|
2783
|
+
raise TestFailed, "should fail: pickle C instance - %s" % base
|
2784
|
+
try:
|
2785
|
+
cPickle.dumps(C())
|
2786
|
+
except TypeError:
|
2787
|
+
pass
|
2788
|
+
else:
|
2789
|
+
raise TestFailed, "should fail: cPickle C instance - %s" % base
|
2790
|
+
try:
|
2791
|
+
pickle.dumps(C())
|
2792
|
+
except TypeError:
|
2793
|
+
pass
|
2794
|
+
else:
|
2795
|
+
raise TestFailed, "should fail: pickle D instance - %s" % base
|
2796
|
+
try:
|
2797
|
+
cPickle.dumps(D())
|
2798
|
+
except TypeError:
|
2799
|
+
pass
|
2800
|
+
else:
|
2801
|
+
raise TestFailed, "should fail: cPickle D instance - %s" % base
|
2802
|
+
# Give C a nice generic __getstate__ and __setstate__
|
2803
|
+
class C(base):
|
2804
|
+
__slots__ = ['a']
|
2805
|
+
def __getstate__(self):
|
2806
|
+
try:
|
2807
|
+
d = self.__dict__.copy()
|
2808
|
+
except AttributeError:
|
2809
|
+
d = {}
|
2810
|
+
for cls in self.__class__.__mro__:
|
2811
|
+
for sn in cls.__dict__.get('__slots__', ()):
|
2812
|
+
try:
|
2813
|
+
d[sn] = getattr(self, sn)
|
2814
|
+
except AttributeError:
|
2815
|
+
pass
|
2816
|
+
return d
|
2817
|
+
def __setstate__(self, d):
|
2818
|
+
for k, v in d.items():
|
2819
|
+
setattr(self, k, v)
|
2820
|
+
class D(C):
|
2821
|
+
pass
|
2822
|
+
# Now it should work
|
2823
|
+
x = C()
|
2824
|
+
y = pickle.loads(pickle.dumps(x))
|
2825
|
+
vereq(hasattr(y, 'a'), 0)
|
2826
|
+
y = cPickle.loads(cPickle.dumps(x))
|
2827
|
+
vereq(hasattr(y, 'a'), 0)
|
2828
|
+
x.a = 42
|
2829
|
+
y = pickle.loads(pickle.dumps(x))
|
2830
|
+
vereq(y.a, 42)
|
2831
|
+
y = cPickle.loads(cPickle.dumps(x))
|
2832
|
+
vereq(y.a, 42)
|
2833
|
+
x = D()
|
2834
|
+
x.a = 42
|
2835
|
+
x.b = 100
|
2836
|
+
y = pickle.loads(pickle.dumps(x))
|
2837
|
+
vereq(y.a + y.b, 142)
|
2838
|
+
y = cPickle.loads(cPickle.dumps(x))
|
2839
|
+
vereq(y.a + y.b, 142)
|
2840
|
+
# A subclass that adds a slot should also work
|
2841
|
+
class E(C):
|
2842
|
+
__slots__ = ['b']
|
2843
|
+
x = E()
|
2844
|
+
x.a = 42
|
2845
|
+
x.b = "foo"
|
2846
|
+
y = pickle.loads(pickle.dumps(x))
|
2847
|
+
vereq(y.a, x.a)
|
2848
|
+
vereq(y.b, x.b)
|
2849
|
+
y = cPickle.loads(cPickle.dumps(x))
|
2850
|
+
vereq(y.a, x.a)
|
2851
|
+
vereq(y.b, x.b)
|
2852
|
+
|
2853
|
+
def copies():
|
2854
|
+
if verbose: print "Testing copy.copy() and copy.deepcopy()..."
|
2855
|
+
import copy
|
2856
|
+
class C(object):
|
2857
|
+
pass
|
2858
|
+
|
2859
|
+
a = C()
|
2860
|
+
a.foo = 12
|
2861
|
+
b = copy.copy(a)
|
2862
|
+
vereq(b.__dict__, a.__dict__)
|
2863
|
+
|
2864
|
+
a.bar = [1,2,3]
|
2865
|
+
c = copy.copy(a)
|
2866
|
+
vereq(c.bar, a.bar)
|
2867
|
+
verify(c.bar is a.bar)
|
2868
|
+
|
2869
|
+
d = copy.deepcopy(a)
|
2870
|
+
vereq(d.__dict__, a.__dict__)
|
2871
|
+
a.bar.append(4)
|
2872
|
+
vereq(d.bar, [1,2,3])
|
2873
|
+
|
2874
|
+
def binopoverride():
|
2875
|
+
if verbose: print "Testing overrides of binary operations..."
|
2876
|
+
class I(int):
|
2877
|
+
def __repr__(self):
|
2878
|
+
return "I(%r)" % int(self)
|
2879
|
+
def __add__(self, other):
|
2880
|
+
return I(int(self) + int(other))
|
2881
|
+
__radd__ = __add__
|
2882
|
+
def __pow__(self, other, mod=None):
|
2883
|
+
if mod is None:
|
2884
|
+
return I(pow(int(self), int(other)))
|
2885
|
+
else:
|
2886
|
+
return I(pow(int(self), int(other), int(mod)))
|
2887
|
+
def __rpow__(self, other, mod=None):
|
2888
|
+
if mod is None:
|
2889
|
+
return I(pow(int(other), int(self), mod))
|
2890
|
+
else:
|
2891
|
+
return I(pow(int(other), int(self), int(mod)))
|
2892
|
+
|
2893
|
+
vereq(`I(1) + I(2)`, "I(3)")
|
2894
|
+
vereq(`I(1) + 2`, "I(3)")
|
2895
|
+
vereq(`1 + I(2)`, "I(3)")
|
2896
|
+
vereq(`I(2) ** I(3)`, "I(8)")
|
2897
|
+
vereq(`2 ** I(3)`, "I(8)")
|
2898
|
+
vereq(`I(2) ** 3`, "I(8)")
|
2899
|
+
vereq(`pow(I(2), I(3), I(5))`, "I(3)")
|
2900
|
+
class S(str):
|
2901
|
+
def __eq__(self, other):
|
2902
|
+
return self.lower() == other.lower()
|
2903
|
+
|
2904
|
+
def subclasspropagation():
|
2905
|
+
if verbose: print "Testing propagation of slot functions to subclasses..."
|
2906
|
+
class A(object):
|
2907
|
+
pass
|
2908
|
+
class B(A):
|
2909
|
+
pass
|
2910
|
+
class C(A):
|
2911
|
+
pass
|
2912
|
+
class D(B, C):
|
2913
|
+
pass
|
2914
|
+
d = D()
|
2915
|
+
vereq(hash(d), id(d))
|
2916
|
+
A.__hash__ = lambda self: 42
|
2917
|
+
vereq(hash(d), 42)
|
2918
|
+
C.__hash__ = lambda self: 314
|
2919
|
+
vereq(hash(d), 314)
|
2920
|
+
B.__hash__ = lambda self: 144
|
2921
|
+
vereq(hash(d), 144)
|
2922
|
+
D.__hash__ = lambda self: 100
|
2923
|
+
vereq(hash(d), 100)
|
2924
|
+
del D.__hash__
|
2925
|
+
vereq(hash(d), 144)
|
2926
|
+
del B.__hash__
|
2927
|
+
vereq(hash(d), 314)
|
2928
|
+
del C.__hash__
|
2929
|
+
vereq(hash(d), 42)
|
2930
|
+
del A.__hash__
|
2931
|
+
vereq(hash(d), id(d))
|
2932
|
+
d.foo = 42
|
2933
|
+
d.bar = 42
|
2934
|
+
vereq(d.foo, 42)
|
2935
|
+
vereq(d.bar, 42)
|
2936
|
+
def __getattribute__(self, name):
|
2937
|
+
if name == "foo":
|
2938
|
+
return 24
|
2939
|
+
return object.__getattribute__(self, name)
|
2940
|
+
A.__getattribute__ = __getattribute__
|
2941
|
+
vereq(d.foo, 24)
|
2942
|
+
vereq(d.bar, 42)
|
2943
|
+
def __getattr__(self, name):
|
2944
|
+
if name in ("spam", "foo", "bar"):
|
2945
|
+
return "hello"
|
2946
|
+
raise AttributeError, name
|
2947
|
+
B.__getattr__ = __getattr__
|
2948
|
+
vereq(d.spam, "hello")
|
2949
|
+
vereq(d.foo, 24)
|
2950
|
+
vereq(d.bar, 42)
|
2951
|
+
del A.__getattribute__
|
2952
|
+
vereq(d.foo, 42)
|
2953
|
+
del d.foo
|
2954
|
+
vereq(d.foo, "hello")
|
2955
|
+
vereq(d.bar, 42)
|
2956
|
+
del B.__getattr__
|
2957
|
+
try:
|
2958
|
+
d.foo
|
2959
|
+
except AttributeError:
|
2960
|
+
pass
|
2961
|
+
else:
|
2962
|
+
raise TestFailed, "d.foo should be undefined now"
|
2963
|
+
|
2964
|
+
# Test a nasty bug in recurse_down_subclasses()
|
2965
|
+
import gc
|
2966
|
+
class A(object):
|
2967
|
+
pass
|
2968
|
+
class B(A):
|
2969
|
+
pass
|
2970
|
+
del B
|
2971
|
+
gc.collect()
|
2972
|
+
A.__setitem__ = lambda *a: None # crash
|
2973
|
+
|
2974
|
+
def buffer_inherit():
|
2975
|
+
import binascii
|
2976
|
+
# SF bug [#470040] ParseTuple t# vs subclasses.
|
2977
|
+
if verbose:
|
2978
|
+
print "Testing that buffer interface is inherited ..."
|
2979
|
+
|
2980
|
+
class MyStr(str):
|
2981
|
+
pass
|
2982
|
+
base = 'abc'
|
2983
|
+
m = MyStr(base)
|
2984
|
+
# b2a_hex uses the buffer interface to get its argument's value, via
|
2985
|
+
# PyArg_ParseTuple 't#' code.
|
2986
|
+
vereq(binascii.b2a_hex(m), binascii.b2a_hex(base))
|
2987
|
+
|
2988
|
+
# It's not clear that unicode will continue to support the character
|
2989
|
+
# buffer interface, and this test will fail if that's taken away.
|
2990
|
+
class MyUni(unicode):
|
2991
|
+
pass
|
2992
|
+
base = u'abc'
|
2993
|
+
m = MyUni(base)
|
2994
|
+
vereq(binascii.b2a_hex(m), binascii.b2a_hex(base))
|
2995
|
+
|
2996
|
+
class MyInt(int):
|
2997
|
+
pass
|
2998
|
+
m = MyInt(42)
|
2999
|
+
try:
|
3000
|
+
binascii.b2a_hex(m)
|
3001
|
+
raise TestFailed('subclass of int should not have a buffer interface')
|
3002
|
+
except TypeError:
|
3003
|
+
pass
|
3004
|
+
|
3005
|
+
def str_of_str_subclass():
|
3006
|
+
import binascii
|
3007
|
+
import cStringIO
|
3008
|
+
|
3009
|
+
if verbose:
|
3010
|
+
print "Testing __str__ defined in subclass of str ..."
|
3011
|
+
|
3012
|
+
class octetstring(str):
|
3013
|
+
def __str__(self):
|
3014
|
+
return binascii.b2a_hex(self)
|
3015
|
+
def __repr__(self):
|
3016
|
+
return self + " repr"
|
3017
|
+
|
3018
|
+
o = octetstring('A')
|
3019
|
+
vereq(type(o), octetstring)
|
3020
|
+
vereq(type(str(o)), str)
|
3021
|
+
vereq(type(repr(o)), str)
|
3022
|
+
vereq(ord(o), 0x41)
|
3023
|
+
vereq(str(o), '41')
|
3024
|
+
vereq(repr(o), 'A repr')
|
3025
|
+
vereq(o.__str__(), '41')
|
3026
|
+
vereq(o.__repr__(), 'A repr')
|
3027
|
+
|
3028
|
+
capture = cStringIO.StringIO()
|
3029
|
+
# Calling str() or not exercises different internal paths.
|
3030
|
+
print >> capture, o
|
3031
|
+
print >> capture, str(o)
|
3032
|
+
vereq(capture.getvalue(), '41\n41\n')
|
3033
|
+
capture.close()
|
3034
|
+
|
3035
|
+
def kwdargs():
|
3036
|
+
if verbose: print "Testing keyword arguments to __init__, __call__..."
|
3037
|
+
def f(a): return a
|
3038
|
+
vereq(f.__call__(a=42), 42)
|
3039
|
+
a = []
|
3040
|
+
list.__init__(a, sequence=[0, 1, 2])
|
3041
|
+
vereq(a, [0, 1, 2])
|
3042
|
+
|
3043
|
+
def delhook():
|
3044
|
+
if verbose: print "Testing __del__ hook..."
|
3045
|
+
log = []
|
3046
|
+
class C(object):
|
3047
|
+
def __del__(self):
|
3048
|
+
log.append(1)
|
3049
|
+
c = C()
|
3050
|
+
vereq(log, [])
|
3051
|
+
del c
|
3052
|
+
vereq(log, [1])
|
3053
|
+
|
3054
|
+
class D(object): pass
|
3055
|
+
d = D()
|
3056
|
+
try: del d[0]
|
3057
|
+
except TypeError: pass
|
3058
|
+
else: raise TestFailed, "invalid del() didn't raise TypeError"
|
3059
|
+
|
3060
|
+
def hashinherit():
|
3061
|
+
if verbose: print "Testing hash of mutable subclasses..."
|
3062
|
+
|
3063
|
+
class mydict(dict):
|
3064
|
+
pass
|
3065
|
+
d = mydict()
|
3066
|
+
try:
|
3067
|
+
hash(d)
|
3068
|
+
except TypeError:
|
3069
|
+
pass
|
3070
|
+
else:
|
3071
|
+
raise TestFailed, "hash() of dict subclass should fail"
|
3072
|
+
|
3073
|
+
class mylist(list):
|
3074
|
+
pass
|
3075
|
+
d = mylist()
|
3076
|
+
try:
|
3077
|
+
hash(d)
|
3078
|
+
except TypeError:
|
3079
|
+
pass
|
3080
|
+
else:
|
3081
|
+
raise TestFailed, "hash() of list subclass should fail"
|
3082
|
+
|
3083
|
+
def strops():
|
3084
|
+
try: 'a' + 5
|
3085
|
+
except TypeError: pass
|
3086
|
+
else: raise TestFailed, "'' + 5 doesn't raise TypeError"
|
3087
|
+
|
3088
|
+
try: ''.split('')
|
3089
|
+
except ValueError: pass
|
3090
|
+
else: raise TestFailed, "''.split('') doesn't raise ValueError"
|
3091
|
+
|
3092
|
+
try: ''.join([0])
|
3093
|
+
except TypeError: pass
|
3094
|
+
else: raise TestFailed, "''.join([0]) doesn't raise TypeError"
|
3095
|
+
|
3096
|
+
try: ''.rindex('5')
|
3097
|
+
except ValueError: pass
|
3098
|
+
else: raise TestFailed, "''.rindex('5') doesn't raise ValueError"
|
3099
|
+
|
3100
|
+
try: '%(n)s' % None
|
3101
|
+
except TypeError: pass
|
3102
|
+
else: raise TestFailed, "'%(n)s' % None doesn't raise TypeError"
|
3103
|
+
|
3104
|
+
try: '%(n' % {}
|
3105
|
+
except ValueError: pass
|
3106
|
+
else: raise TestFailed, "'%(n' % {} '' doesn't raise ValueError"
|
3107
|
+
|
3108
|
+
try: '%*s' % ('abc')
|
3109
|
+
except TypeError: pass
|
3110
|
+
else: raise TestFailed, "'%*s' % ('abc') doesn't raise TypeError"
|
3111
|
+
|
3112
|
+
try: '%*.*s' % ('abc', 5)
|
3113
|
+
except TypeError: pass
|
3114
|
+
else: raise TestFailed, "'%*.*s' % ('abc', 5) doesn't raise TypeError"
|
3115
|
+
|
3116
|
+
try: '%s' % (1, 2)
|
3117
|
+
except TypeError: pass
|
3118
|
+
else: raise TestFailed, "'%s' % (1, 2) doesn't raise TypeError"
|
3119
|
+
|
3120
|
+
try: '%' % None
|
3121
|
+
except ValueError: pass
|
3122
|
+
else: raise TestFailed, "'%' % None doesn't raise ValueError"
|
3123
|
+
|
3124
|
+
vereq('534253'.isdigit(), 1)
|
3125
|
+
vereq('534253x'.isdigit(), 0)
|
3126
|
+
vereq('%c' % 5, '\x05')
|
3127
|
+
vereq('%c' % '5', '5')
|
3128
|
+
|
3129
|
+
def deepcopyrecursive():
|
3130
|
+
if verbose: print "Testing deepcopy of recursive objects..."
|
3131
|
+
class Node:
|
3132
|
+
pass
|
3133
|
+
a = Node()
|
3134
|
+
b = Node()
|
3135
|
+
a.b = b
|
3136
|
+
b.a = a
|
3137
|
+
z = deepcopy(a) # This blew up before
|
3138
|
+
|
3139
|
+
def modules():
|
3140
|
+
if verbose: print "Testing uninitialized module objects..."
|
3141
|
+
from types import ModuleType as M
|
3142
|
+
m = M.__new__(M)
|
3143
|
+
str(m)
|
3144
|
+
vereq(hasattr(m, "__name__"), 0)
|
3145
|
+
vereq(hasattr(m, "__file__"), 0)
|
3146
|
+
vereq(hasattr(m, "foo"), 0)
|
3147
|
+
vereq(m.__dict__, None)
|
3148
|
+
m.foo = 1
|
3149
|
+
vereq(m.__dict__, {"foo": 1})
|
3150
|
+
|
3151
|
+
def dictproxyiterkeys():
|
3152
|
+
class C(object):
|
3153
|
+
def meth(self):
|
3154
|
+
pass
|
3155
|
+
if verbose: print "Testing dict-proxy iterkeys..."
|
3156
|
+
keys = [ key for key in C.__dict__.iterkeys() ]
|
3157
|
+
keys.sort()
|
3158
|
+
vereq(keys, ['__dict__', '__doc__', '__module__', '__weakref__', 'meth'])
|
3159
|
+
|
3160
|
+
def dictproxyitervalues():
|
3161
|
+
class C(object):
|
3162
|
+
def meth(self):
|
3163
|
+
pass
|
3164
|
+
if verbose: print "Testing dict-proxy itervalues..."
|
3165
|
+
values = [ values for values in C.__dict__.itervalues() ]
|
3166
|
+
vereq(len(values), 5)
|
3167
|
+
|
3168
|
+
def dictproxyiteritems():
|
3169
|
+
class C(object):
|
3170
|
+
def meth(self):
|
3171
|
+
pass
|
3172
|
+
if verbose: print "Testing dict-proxy iteritems..."
|
3173
|
+
keys = [ key for (key, value) in C.__dict__.iteritems() ]
|
3174
|
+
keys.sort()
|
3175
|
+
vereq(keys, ['__dict__', '__doc__', '__module__', '__weakref__', 'meth'])
|
3176
|
+
|
3177
|
+
def funnynew():
|
3178
|
+
if verbose: print "Testing __new__ returning something unexpected..."
|
3179
|
+
class C(object):
|
3180
|
+
def __new__(cls, arg):
|
3181
|
+
if isinstance(arg, str): return [1, 2, 3]
|
3182
|
+
elif isinstance(arg, int): return object.__new__(D)
|
3183
|
+
else: return object.__new__(cls)
|
3184
|
+
class D(C):
|
3185
|
+
def __init__(self, arg):
|
3186
|
+
self.foo = arg
|
3187
|
+
vereq(C("1"), [1, 2, 3])
|
3188
|
+
vereq(D("1"), [1, 2, 3])
|
3189
|
+
d = D(None)
|
3190
|
+
veris(d.foo, None)
|
3191
|
+
d = C(1)
|
3192
|
+
vereq(isinstance(d, D), True)
|
3193
|
+
vereq(d.foo, 1)
|
3194
|
+
d = D(1)
|
3195
|
+
vereq(isinstance(d, D), True)
|
3196
|
+
vereq(d.foo, 1)
|
3197
|
+
|
3198
|
+
def imulbug():
|
3199
|
+
# SF bug 544647
|
3200
|
+
if verbose: print "Testing for __imul__ problems..."
|
3201
|
+
class C(object):
|
3202
|
+
def __imul__(self, other):
|
3203
|
+
return (self, other)
|
3204
|
+
x = C()
|
3205
|
+
y = x
|
3206
|
+
y *= 1.0
|
3207
|
+
vereq(y, (x, 1.0))
|
3208
|
+
y = x
|
3209
|
+
y *= 2
|
3210
|
+
vereq(y, (x, 2))
|
3211
|
+
y = x
|
3212
|
+
y *= 3L
|
3213
|
+
vereq(y, (x, 3L))
|
3214
|
+
y = x
|
3215
|
+
y *= 1L<<100
|
3216
|
+
vereq(y, (x, 1L<<100))
|
3217
|
+
y = x
|
3218
|
+
y *= None
|
3219
|
+
vereq(y, (x, None))
|
3220
|
+
y = x
|
3221
|
+
y *= "foo"
|
3222
|
+
vereq(y, (x, "foo"))
|
3223
|
+
|
3224
|
+
def docdescriptor():
|
3225
|
+
# SF bug 542984
|
3226
|
+
if verbose: print "Testing __doc__ descriptor..."
|
3227
|
+
class DocDescr(object):
|
3228
|
+
def __get__(self, object, otype):
|
3229
|
+
if object:
|
3230
|
+
object = object.__class__.__name__ + ' instance'
|
3231
|
+
if otype:
|
3232
|
+
otype = otype.__name__
|
3233
|
+
return 'object=%s; type=%s' % (object, otype)
|
3234
|
+
class OldClass:
|
3235
|
+
__doc__ = DocDescr()
|
3236
|
+
class NewClass(object):
|
3237
|
+
__doc__ = DocDescr()
|
3238
|
+
vereq(OldClass.__doc__, 'object=None; type=OldClass')
|
3239
|
+
vereq(OldClass().__doc__, 'object=OldClass instance; type=OldClass')
|
3240
|
+
vereq(NewClass.__doc__, 'object=None; type=NewClass')
|
3241
|
+
vereq(NewClass().__doc__, 'object=NewClass instance; type=NewClass')
|
3242
|
+
|
3243
|
+
def string_exceptions():
|
3244
|
+
if verbose:
|
3245
|
+
print "Testing string exceptions ..."
|
3246
|
+
|
3247
|
+
# Ensure builtin strings work OK as exceptions.
|
3248
|
+
astring = "An exception string."
|
3249
|
+
try:
|
3250
|
+
raise astring
|
3251
|
+
except astring:
|
3252
|
+
pass
|
3253
|
+
else:
|
3254
|
+
raise TestFailed, "builtin string not usable as exception"
|
3255
|
+
|
3256
|
+
# Ensure string subclass instances do not.
|
3257
|
+
class MyStr(str):
|
3258
|
+
pass
|
3259
|
+
|
3260
|
+
newstring = MyStr("oops -- shouldn't work")
|
3261
|
+
try:
|
3262
|
+
raise newstring
|
3263
|
+
except TypeError:
|
3264
|
+
pass
|
3265
|
+
except:
|
3266
|
+
raise TestFailed, "string subclass allowed as exception"
|
3267
|
+
|
3268
|
+
def copy_setstate():
|
3269
|
+
if verbose:
|
3270
|
+
print "Testing that copy.*copy() correctly uses __setstate__..."
|
3271
|
+
import copy
|
3272
|
+
class C(object):
|
3273
|
+
def __init__(self, foo=None):
|
3274
|
+
self.foo = foo
|
3275
|
+
self.__foo = foo
|
3276
|
+
def setfoo(self, foo=None):
|
3277
|
+
self.foo = foo
|
3278
|
+
def getfoo(self):
|
3279
|
+
return self.__foo
|
3280
|
+
def __getstate__(self):
|
3281
|
+
return [self.foo]
|
3282
|
+
def __setstate__(self, lst):
|
3283
|
+
assert len(lst) == 1
|
3284
|
+
self.__foo = self.foo = lst[0]
|
3285
|
+
a = C(42)
|
3286
|
+
a.setfoo(24)
|
3287
|
+
vereq(a.foo, 24)
|
3288
|
+
vereq(a.getfoo(), 42)
|
3289
|
+
b = copy.copy(a)
|
3290
|
+
vereq(b.foo, 24)
|
3291
|
+
vereq(b.getfoo(), 24)
|
3292
|
+
b = copy.deepcopy(a)
|
3293
|
+
vereq(b.foo, 24)
|
3294
|
+
vereq(b.getfoo(), 24)
|
3295
|
+
|
3296
|
+
def slices():
|
3297
|
+
if verbose:
|
3298
|
+
print "Testing cases with slices and overridden __getitem__ ..."
|
3299
|
+
# Strings
|
3300
|
+
vereq("hello"[:4], "hell")
|
3301
|
+
vereq("hello"[slice(4)], "hell")
|
3302
|
+
vereq(str.__getitem__("hello", slice(4)), "hell")
|
3303
|
+
class S(str):
|
3304
|
+
def __getitem__(self, x):
|
3305
|
+
return str.__getitem__(self, x)
|
3306
|
+
vereq(S("hello")[:4], "hell")
|
3307
|
+
vereq(S("hello")[slice(4)], "hell")
|
3308
|
+
vereq(S("hello").__getitem__(slice(4)), "hell")
|
3309
|
+
# Tuples
|
3310
|
+
vereq((1,2,3)[:2], (1,2))
|
3311
|
+
vereq((1,2,3)[slice(2)], (1,2))
|
3312
|
+
vereq(tuple.__getitem__((1,2,3), slice(2)), (1,2))
|
3313
|
+
class T(tuple):
|
3314
|
+
def __getitem__(self, x):
|
3315
|
+
return tuple.__getitem__(self, x)
|
3316
|
+
vereq(T((1,2,3))[:2], (1,2))
|
3317
|
+
vereq(T((1,2,3))[slice(2)], (1,2))
|
3318
|
+
vereq(T((1,2,3)).__getitem__(slice(2)), (1,2))
|
3319
|
+
# Lists
|
3320
|
+
vereq([1,2,3][:2], [1,2])
|
3321
|
+
vereq([1,2,3][slice(2)], [1,2])
|
3322
|
+
vereq(list.__getitem__([1,2,3], slice(2)), [1,2])
|
3323
|
+
class L(list):
|
3324
|
+
def __getitem__(self, x):
|
3325
|
+
return list.__getitem__(self, x)
|
3326
|
+
vereq(L([1,2,3])[:2], [1,2])
|
3327
|
+
vereq(L([1,2,3])[slice(2)], [1,2])
|
3328
|
+
vereq(L([1,2,3]).__getitem__(slice(2)), [1,2])
|
3329
|
+
# Now do lists and __setitem__
|
3330
|
+
a = L([1,2,3])
|
3331
|
+
a[slice(1, 3)] = [3,2]
|
3332
|
+
vereq(a, [1,3,2])
|
3333
|
+
a[slice(0, 2, 1)] = [3,1]
|
3334
|
+
vereq(a, [3,1,2])
|
3335
|
+
a.__setitem__(slice(1, 3), [2,1])
|
3336
|
+
vereq(a, [3,2,1])
|
3337
|
+
a.__setitem__(slice(0, 2, 1), [2,3])
|
3338
|
+
vereq(a, [2,3,1])
|
3339
|
+
|
3340
|
+
def subtype_resurrection():
|
3341
|
+
if verbose:
|
3342
|
+
print "Testing resurrection of new-style instance..."
|
3343
|
+
|
3344
|
+
class C(object):
|
3345
|
+
container = []
|
3346
|
+
|
3347
|
+
def __del__(self):
|
3348
|
+
# resurrect the instance
|
3349
|
+
C.container.append(self)
|
3350
|
+
|
3351
|
+
c = C()
|
3352
|
+
c.attr = 42
|
3353
|
+
# The most interesting thing here is whether this blows up, due to flawed
|
3354
|
+
# GC tracking logic in typeobject.c's call_finalizer() (a 2.2.1 bug).
|
3355
|
+
del c
|
3356
|
+
|
3357
|
+
# If that didn't blow up, it's also interesting to see whether clearing
|
3358
|
+
# the last container slot works: that will attempt to delete c again,
|
3359
|
+
# which will cause c to get appended back to the container again "during"
|
3360
|
+
# the del.
|
3361
|
+
del C.container[-1]
|
3362
|
+
vereq(len(C.container), 1)
|
3363
|
+
vereq(C.container[-1].attr, 42)
|
3364
|
+
|
3365
|
+
# Make c mortal again, so that the test framework with -l doesn't report
|
3366
|
+
# it as a leak.
|
3367
|
+
del C.__del__
|
3368
|
+
|
3369
|
+
def slottrash():
|
3370
|
+
# Deallocating deeply nested slotted trash caused stack overflows
|
3371
|
+
if verbose:
|
3372
|
+
print "Testing slot trash..."
|
3373
|
+
class trash(object):
|
3374
|
+
__slots__ = ['x']
|
3375
|
+
def __init__(self, x):
|
3376
|
+
self.x = x
|
3377
|
+
o = None
|
3378
|
+
for i in xrange(50000):
|
3379
|
+
o = trash(o)
|
3380
|
+
del o
|
3381
|
+
|
3382
|
+
def slotmultipleinheritance():
|
3383
|
+
# SF bug 575229, multiple inheritance w/ slots dumps core
|
3384
|
+
class A(object):
|
3385
|
+
__slots__=()
|
3386
|
+
class B(object):
|
3387
|
+
pass
|
3388
|
+
class C(A,B) :
|
3389
|
+
__slots__=()
|
3390
|
+
vereq(C.__basicsize__, B.__basicsize__)
|
3391
|
+
verify(hasattr(C, '__dict__'))
|
3392
|
+
verify(hasattr(C, '__weakref__'))
|
3393
|
+
C().x = 2
|
3394
|
+
|
3395
|
+
def testrmul():
|
3396
|
+
# SF patch 592646
|
3397
|
+
if verbose:
|
3398
|
+
print "Testing correct invocation of __rmul__..."
|
3399
|
+
class C(object):
|
3400
|
+
def __mul__(self, other):
|
3401
|
+
return "mul"
|
3402
|
+
def __rmul__(self, other):
|
3403
|
+
return "rmul"
|
3404
|
+
a = C()
|
3405
|
+
vereq(a*2, "mul")
|
3406
|
+
vereq(a*2.2, "mul")
|
3407
|
+
vereq(2*a, "rmul")
|
3408
|
+
vereq(2.2*a, "rmul")
|
3409
|
+
|
3410
|
+
def testipow():
|
3411
|
+
# [SF bug 620179]
|
3412
|
+
if verbose:
|
3413
|
+
print "Testing correct invocation of __ipow__..."
|
3414
|
+
class C(object):
|
3415
|
+
def __ipow__(self, other):
|
3416
|
+
pass
|
3417
|
+
a = C()
|
3418
|
+
a **= 2
|
3419
|
+
|
3420
|
+
def do_this_first():
|
3421
|
+
if verbose:
|
3422
|
+
print "Testing SF bug 551412 ..."
|
3423
|
+
# This dumps core when SF bug 551412 isn't fixed --
|
3424
|
+
# but only when test_descr.py is run separately.
|
3425
|
+
# (That can't be helped -- as soon as PyType_Ready()
|
3426
|
+
# is called for PyLong_Type, the bug is gone.)
|
3427
|
+
class UserLong(object):
|
3428
|
+
def __pow__(self, *args):
|
3429
|
+
pass
|
3430
|
+
try:
|
3431
|
+
pow(0L, UserLong(), 0L)
|
3432
|
+
except:
|
3433
|
+
pass
|
3434
|
+
|
3435
|
+
if verbose:
|
3436
|
+
print "Testing SF bug 570483..."
|
3437
|
+
# Another segfault only when run early
|
3438
|
+
# (before PyType_Ready(tuple) is called)
|
3439
|
+
type.mro(tuple)
|
3440
|
+
|
3441
|
+
def test_mutable_bases():
|
3442
|
+
if verbose:
|
3443
|
+
print "Testing mutable bases..."
|
3444
|
+
# stuff that should work:
|
3445
|
+
class C(object):
|
3446
|
+
pass
|
3447
|
+
class C2(object):
|
3448
|
+
def __getattribute__(self, attr):
|
3449
|
+
if attr == 'a':
|
3450
|
+
return 2
|
3451
|
+
else:
|
3452
|
+
return super(C2, self).__getattribute__(attr)
|
3453
|
+
def meth(self):
|
3454
|
+
return 1
|
3455
|
+
class D(C):
|
3456
|
+
pass
|
3457
|
+
class E(D):
|
3458
|
+
pass
|
3459
|
+
d = D()
|
3460
|
+
e = E()
|
3461
|
+
D.__bases__ = (C,)
|
3462
|
+
D.__bases__ = (C2,)
|
3463
|
+
vereq(d.meth(), 1)
|
3464
|
+
vereq(e.meth(), 1)
|
3465
|
+
vereq(d.a, 2)
|
3466
|
+
vereq(e.a, 2)
|
3467
|
+
vereq(C2.__subclasses__(), [D])
|
3468
|
+
|
3469
|
+
# stuff that shouldn't:
|
3470
|
+
class L(list):
|
3471
|
+
pass
|
3472
|
+
|
3473
|
+
try:
|
3474
|
+
L.__bases__ = (dict,)
|
3475
|
+
except TypeError:
|
3476
|
+
pass
|
3477
|
+
else:
|
3478
|
+
raise TestFailed, "shouldn't turn list subclass into dict subclass"
|
3479
|
+
|
3480
|
+
try:
|
3481
|
+
list.__bases__ = (dict,)
|
3482
|
+
except TypeError:
|
3483
|
+
pass
|
3484
|
+
else:
|
3485
|
+
raise TestFailed, "shouldn't be able to assign to list.__bases__"
|
3486
|
+
|
3487
|
+
try:
|
3488
|
+
del D.__bases__
|
3489
|
+
except TypeError:
|
3490
|
+
pass
|
3491
|
+
else:
|
3492
|
+
raise TestFailed, "shouldn't be able to delete .__bases__"
|
3493
|
+
|
3494
|
+
try:
|
3495
|
+
D.__bases__ = ()
|
3496
|
+
except TypeError, msg:
|
3497
|
+
if str(msg) == "a new-style class can't have only classic bases":
|
3498
|
+
raise TestFailed, "wrong error message for .__bases__ = ()"
|
3499
|
+
else:
|
3500
|
+
raise TestFailed, "shouldn't be able to set .__bases__ to ()"
|
3501
|
+
|
3502
|
+
try:
|
3503
|
+
D.__bases__ = (D,)
|
3504
|
+
except TypeError:
|
3505
|
+
pass
|
3506
|
+
else:
|
3507
|
+
# actually, we'll have crashed by here...
|
3508
|
+
raise TestFailed, "shouldn't be able to create inheritance cycles"
|
3509
|
+
|
3510
|
+
try:
|
3511
|
+
D.__bases__ = (C, C)
|
3512
|
+
except TypeError:
|
3513
|
+
pass
|
3514
|
+
else:
|
3515
|
+
raise TestFailed, "didn't detect repeated base classes"
|
3516
|
+
|
3517
|
+
try:
|
3518
|
+
D.__bases__ = (E,)
|
3519
|
+
except TypeError:
|
3520
|
+
pass
|
3521
|
+
else:
|
3522
|
+
raise TestFailed, "shouldn't be able to create inheritance cycles"
|
3523
|
+
|
3524
|
+
# let's throw a classic class into the mix:
|
3525
|
+
class Classic:
|
3526
|
+
def meth2(self):
|
3527
|
+
return 3
|
3528
|
+
|
3529
|
+
D.__bases__ = (C, Classic)
|
3530
|
+
|
3531
|
+
vereq(d.meth2(), 3)
|
3532
|
+
vereq(e.meth2(), 3)
|
3533
|
+
try:
|
3534
|
+
d.a
|
3535
|
+
except AttributeError:
|
3536
|
+
pass
|
3537
|
+
else:
|
3538
|
+
raise TestFailed, "attribute should have vanished"
|
3539
|
+
|
3540
|
+
try:
|
3541
|
+
D.__bases__ = (Classic,)
|
3542
|
+
except TypeError:
|
3543
|
+
pass
|
3544
|
+
else:
|
3545
|
+
raise TestFailed, "new-style class must have a new-style base"
|
3546
|
+
|
3547
|
+
def test_mutable_bases_with_failing_mro():
|
3548
|
+
if verbose:
|
3549
|
+
print "Testing mutable bases with failing mro..."
|
3550
|
+
class WorkOnce(type):
|
3551
|
+
def __new__(self, name, bases, ns):
|
3552
|
+
self.flag = 0
|
3553
|
+
return super(WorkOnce, self).__new__(WorkOnce, name, bases, ns)
|
3554
|
+
def mro(self):
|
3555
|
+
if self.flag > 0:
|
3556
|
+
raise RuntimeError, "bozo"
|
3557
|
+
else:
|
3558
|
+
self.flag += 1
|
3559
|
+
return type.mro(self)
|
3560
|
+
|
3561
|
+
class WorkAlways(type):
|
3562
|
+
def mro(self):
|
3563
|
+
# this is here to make sure that .mro()s aren't called
|
3564
|
+
# with an exception set (which was possible at one point).
|
3565
|
+
# An error message will be printed in a debug build.
|
3566
|
+
# What's a good way to test for this?
|
3567
|
+
return type.mro(self)
|
3568
|
+
|
3569
|
+
class C(object):
|
3570
|
+
pass
|
3571
|
+
|
3572
|
+
class C2(object):
|
3573
|
+
pass
|
3574
|
+
|
3575
|
+
class D(C):
|
3576
|
+
pass
|
3577
|
+
|
3578
|
+
class E(D):
|
3579
|
+
pass
|
3580
|
+
|
3581
|
+
class F(D):
|
3582
|
+
__metaclass__ = WorkOnce
|
3583
|
+
|
3584
|
+
class G(D):
|
3585
|
+
__metaclass__ = WorkAlways
|
3586
|
+
|
3587
|
+
# Immediate subclasses have their mro's adjusted in alphabetical
|
3588
|
+
# order, so E's will get adjusted before adjusting F's fails. We
|
3589
|
+
# check here that E's gets restored.
|
3590
|
+
|
3591
|
+
E_mro_before = E.__mro__
|
3592
|
+
D_mro_before = D.__mro__
|
3593
|
+
|
3594
|
+
try:
|
3595
|
+
D.__bases__ = (C2,)
|
3596
|
+
except RuntimeError:
|
3597
|
+
vereq(E.__mro__, E_mro_before)
|
3598
|
+
vereq(D.__mro__, D_mro_before)
|
3599
|
+
else:
|
3600
|
+
raise TestFailed, "exception not propagated"
|
3601
|
+
|
3602
|
+
def test_mutable_bases_catch_mro_conflict():
|
3603
|
+
if verbose:
|
3604
|
+
print "Testing mutable bases catch mro conflict..."
|
3605
|
+
class A(object):
|
3606
|
+
pass
|
3607
|
+
|
3608
|
+
class B(object):
|
3609
|
+
pass
|
3610
|
+
|
3611
|
+
class C(A, B):
|
3612
|
+
pass
|
3613
|
+
|
3614
|
+
class D(A, B):
|
3615
|
+
pass
|
3616
|
+
|
3617
|
+
class E(C, D):
|
3618
|
+
pass
|
3619
|
+
|
3620
|
+
try:
|
3621
|
+
C.__bases__ = (B, A)
|
3622
|
+
except TypeError:
|
3623
|
+
pass
|
3624
|
+
else:
|
3625
|
+
raise TestFailed, "didn't catch MRO conflict"
|
3626
|
+
|
3627
|
+
def mutable_names():
|
3628
|
+
if verbose:
|
3629
|
+
print "Testing mutable names..."
|
3630
|
+
class C(object):
|
3631
|
+
pass
|
3632
|
+
|
3633
|
+
# C.__module__ could be 'test_descr' or '__main__'
|
3634
|
+
mod = C.__module__
|
3635
|
+
|
3636
|
+
C.__name__ = 'D'
|
3637
|
+
vereq((C.__module__, C.__name__), (mod, 'D'))
|
3638
|
+
|
3639
|
+
C.__name__ = 'D.E'
|
3640
|
+
vereq((C.__module__, C.__name__), (mod, 'D.E'))
|
3641
|
+
|
3642
|
+
def subclass_right_op():
|
3643
|
+
if verbose:
|
3644
|
+
print "Testing correct dispatch of subclass overloading __r<op>__..."
|
3645
|
+
|
3646
|
+
# This code tests various cases where right-dispatch of a subclass
|
3647
|
+
# should be preferred over left-dispatch of a base class.
|
3648
|
+
|
3649
|
+
# Case 1: subclass of int; this tests code in abstract.c::binary_op1()
|
3650
|
+
|
3651
|
+
class B(int):
|
3652
|
+
def __floordiv__(self, other):
|
3653
|
+
return "B.__floordiv__"
|
3654
|
+
def __rfloordiv__(self, other):
|
3655
|
+
return "B.__rfloordiv__"
|
3656
|
+
|
3657
|
+
vereq(B(1) // 1, "B.__floordiv__")
|
3658
|
+
vereq(1 // B(1), "B.__rfloordiv__")
|
3659
|
+
|
3660
|
+
# Case 2: subclass of object; this is just the baseline for case 3
|
3661
|
+
|
3662
|
+
class C(object):
|
3663
|
+
def __floordiv__(self, other):
|
3664
|
+
return "C.__floordiv__"
|
3665
|
+
def __rfloordiv__(self, other):
|
3666
|
+
return "C.__rfloordiv__"
|
3667
|
+
|
3668
|
+
vereq(C() // 1, "C.__floordiv__")
|
3669
|
+
vereq(1 // C(), "C.__rfloordiv__")
|
3670
|
+
|
3671
|
+
# Case 3: subclass of new-style class; here it gets interesting
|
3672
|
+
|
3673
|
+
class D(C):
|
3674
|
+
def __floordiv__(self, other):
|
3675
|
+
return "D.__floordiv__"
|
3676
|
+
def __rfloordiv__(self, other):
|
3677
|
+
return "D.__rfloordiv__"
|
3678
|
+
|
3679
|
+
vereq(D() // C(), "D.__floordiv__")
|
3680
|
+
vereq(C() // D(), "D.__rfloordiv__")
|
3681
|
+
|
3682
|
+
# Case 4: this didn't work right in 2.2.2 and 2.3a1
|
3683
|
+
|
3684
|
+
class E(C):
|
3685
|
+
pass
|
3686
|
+
|
3687
|
+
vereq(E.__rfloordiv__, C.__rfloordiv__)
|
3688
|
+
|
3689
|
+
vereq(E() // 1, "C.__floordiv__")
|
3690
|
+
vereq(1 // E(), "C.__rfloordiv__")
|
3691
|
+
vereq(E() // C(), "C.__floordiv__")
|
3692
|
+
vereq(C() // E(), "C.__floordiv__") # This one would fail
|
3693
|
+
|
3694
|
+
def subclass_cmp_right_op():
|
3695
|
+
if verbose:
|
3696
|
+
print "Testing correct dispatch of subclass overloading for comp ops"
|
3697
|
+
|
3698
|
+
# Case 1: subclass of int
|
3699
|
+
|
3700
|
+
class B(int):
|
3701
|
+
def __ge__(self, other):
|
3702
|
+
return "B.__ge__"
|
3703
|
+
def __le__(self, other):
|
3704
|
+
return "B.__le__"
|
3705
|
+
|
3706
|
+
vereq(B(1) >= 1, "B.__ge__")
|
3707
|
+
vereq(1 >= B(1), "B.__le__")
|
3708
|
+
|
3709
|
+
# Case 2: subclass of object
|
3710
|
+
|
3711
|
+
class C(object):
|
3712
|
+
def __ge__(self, other):
|
3713
|
+
return "C.__ge__"
|
3714
|
+
def __le__(self, other):
|
3715
|
+
return "C.__le__"
|
3716
|
+
|
3717
|
+
vereq(C() >= 1, "C.__ge__")
|
3718
|
+
vereq(1 >= C(), "C.__le__")
|
3719
|
+
|
3720
|
+
# Case 3: subclass of new-style class; here it gets interesting
|
3721
|
+
|
3722
|
+
class D(C):
|
3723
|
+
def __ge__(self, other):
|
3724
|
+
return "D.__ge__"
|
3725
|
+
def __le__(self, other):
|
3726
|
+
return "D.__le__"
|
3727
|
+
|
3728
|
+
vereq(D() >= C(), "D.__ge__")
|
3729
|
+
vereq(C() >= D(), "D.__le__")
|
3730
|
+
|
3731
|
+
# Case 4: comparison is different than other binops
|
3732
|
+
|
3733
|
+
class E(C):
|
3734
|
+
pass
|
3735
|
+
|
3736
|
+
vereq(E.__le__, C.__le__)
|
3737
|
+
|
3738
|
+
vereq(E() >= 1, "C.__ge__")
|
3739
|
+
vereq(1 >= E(), "C.__le__")
|
3740
|
+
vereq(E() >= C(), "C.__ge__")
|
3741
|
+
vereq(C() >= E(), "C.__le__") # different
|
3742
|
+
|
3743
|
+
def dict_type_with_metaclass():
|
3744
|
+
if verbose:
|
3745
|
+
print "Testing type of __dict__ when __metaclass__ set..."
|
3746
|
+
|
3747
|
+
class B(object):
|
3748
|
+
pass
|
3749
|
+
class M(type):
|
3750
|
+
pass
|
3751
|
+
class C:
|
3752
|
+
# In 2.3a1, C.__dict__ was a real dict rather than a dict proxy
|
3753
|
+
__metaclass__ = M
|
3754
|
+
veris(type(C.__dict__), type(B.__dict__))
|
3755
|
+
|
3756
|
+
def meth_class_get():
|
3757
|
+
# Full coverage of descrobject.c::classmethod_get()
|
3758
|
+
if verbose:
|
3759
|
+
print "Testing __get__ method of METH_CLASS C methods..."
|
3760
|
+
# Baseline
|
3761
|
+
arg = [1, 2, 3]
|
3762
|
+
res = {1: None, 2: None, 3: None}
|
3763
|
+
vereq(dict.fromkeys(arg), res)
|
3764
|
+
vereq({}.fromkeys(arg), res)
|
3765
|
+
# Now get the descriptor
|
3766
|
+
descr = dict.__dict__["fromkeys"]
|
3767
|
+
# More baseline using the descriptor directly
|
3768
|
+
vereq(descr.__get__(None, dict)(arg), res)
|
3769
|
+
vereq(descr.__get__({})(arg), res)
|
3770
|
+
# Now check various error cases
|
3771
|
+
try:
|
3772
|
+
descr.__get__(None, None)
|
3773
|
+
except TypeError:
|
3774
|
+
pass
|
3775
|
+
else:
|
3776
|
+
raise TestFailed, "shouldn't have allowed descr.__get__(None, None)"
|
3777
|
+
try:
|
3778
|
+
descr.__get__(42)
|
3779
|
+
except TypeError:
|
3780
|
+
pass
|
3781
|
+
else:
|
3782
|
+
raise TestFailed, "shouldn't have allowed descr.__get__(42)"
|
3783
|
+
try:
|
3784
|
+
descr.__get__(None, 42)
|
3785
|
+
except TypeError:
|
3786
|
+
pass
|
3787
|
+
else:
|
3788
|
+
raise TestFailed, "shouldn't have allowed descr.__get__(None, 42)"
|
3789
|
+
try:
|
3790
|
+
descr.__get__(None, int)
|
3791
|
+
except TypeError:
|
3792
|
+
pass
|
3793
|
+
else:
|
3794
|
+
raise TestFailed, "shouldn't have allowed descr.__get__(None, int)"
|
3795
|
+
|
3796
|
+
def isinst_isclass():
|
3797
|
+
if verbose:
|
3798
|
+
print "Testing proxy isinstance() and isclass()..."
|
3799
|
+
class Proxy(object):
|
3800
|
+
def __init__(self, obj):
|
3801
|
+
self.__obj = obj
|
3802
|
+
def __getattribute__(self, name):
|
3803
|
+
if name.startswith("_Proxy__"):
|
3804
|
+
return object.__getattribute__(self, name)
|
3805
|
+
else:
|
3806
|
+
return getattr(self.__obj, name)
|
3807
|
+
# Test with a classic class
|
3808
|
+
class C:
|
3809
|
+
pass
|
3810
|
+
a = C()
|
3811
|
+
pa = Proxy(a)
|
3812
|
+
verify(isinstance(a, C)) # Baseline
|
3813
|
+
verify(isinstance(pa, C)) # Test
|
3814
|
+
# Test with a classic subclass
|
3815
|
+
class D(C):
|
3816
|
+
pass
|
3817
|
+
a = D()
|
3818
|
+
pa = Proxy(a)
|
3819
|
+
verify(isinstance(a, C)) # Baseline
|
3820
|
+
verify(isinstance(pa, C)) # Test
|
3821
|
+
# Test with a new-style class
|
3822
|
+
class C(object):
|
3823
|
+
pass
|
3824
|
+
a = C()
|
3825
|
+
pa = Proxy(a)
|
3826
|
+
verify(isinstance(a, C)) # Baseline
|
3827
|
+
verify(isinstance(pa, C)) # Test
|
3828
|
+
# Test with a new-style subclass
|
3829
|
+
class D(C):
|
3830
|
+
pass
|
3831
|
+
a = D()
|
3832
|
+
pa = Proxy(a)
|
3833
|
+
verify(isinstance(a, C)) # Baseline
|
3834
|
+
verify(isinstance(pa, C)) # Test
|
3835
|
+
|
3836
|
+
def proxysuper():
|
3837
|
+
if verbose:
|
3838
|
+
print "Testing super() for a proxy object..."
|
3839
|
+
class Proxy(object):
|
3840
|
+
def __init__(self, obj):
|
3841
|
+
self.__obj = obj
|
3842
|
+
def __getattribute__(self, name):
|
3843
|
+
if name.startswith("_Proxy__"):
|
3844
|
+
return object.__getattribute__(self, name)
|
3845
|
+
else:
|
3846
|
+
return getattr(self.__obj, name)
|
3847
|
+
|
3848
|
+
class B(object):
|
3849
|
+
def f(self):
|
3850
|
+
return "B.f"
|
3851
|
+
|
3852
|
+
class C(B):
|
3853
|
+
def f(self):
|
3854
|
+
return super(C, self).f() + "->C.f"
|
3855
|
+
|
3856
|
+
obj = C()
|
3857
|
+
p = Proxy(obj)
|
3858
|
+
vereq(C.__dict__["f"](p), "B.f->C.f")
|
3859
|
+
|
3860
|
+
def carloverre():
|
3861
|
+
if verbose:
|
3862
|
+
print "Testing prohibition of Carlo Verre's hack..."
|
3863
|
+
try:
|
3864
|
+
object.__setattr__(str, "foo", 42)
|
3865
|
+
except TypeError:
|
3866
|
+
pass
|
3867
|
+
else:
|
3868
|
+
raise TestFailed, "Carlo Verre __setattr__ suceeded!"
|
3869
|
+
try:
|
3870
|
+
object.__delattr__(str, "lower")
|
3871
|
+
except TypeError:
|
3872
|
+
pass
|
3873
|
+
else:
|
3874
|
+
raise TestFailed, "Carlo Verre __delattr__ succeeded!"
|
3875
|
+
|
3876
|
+
def weakref_segfault():
|
3877
|
+
# SF 742911
|
3878
|
+
if verbose:
|
3879
|
+
print "Testing weakref segfault..."
|
3880
|
+
|
3881
|
+
import weakref
|
3882
|
+
|
3883
|
+
class Provoker:
|
3884
|
+
def __init__(self, referrent):
|
3885
|
+
self.ref = weakref.ref(referrent)
|
3886
|
+
|
3887
|
+
def __del__(self):
|
3888
|
+
x = self.ref()
|
3889
|
+
|
3890
|
+
class Oops(object):
|
3891
|
+
pass
|
3892
|
+
|
3893
|
+
o = Oops()
|
3894
|
+
o.whatever = Provoker(o)
|
3895
|
+
del o
|
3896
|
+
|
3897
|
+
# Fix SF #762455, segfault when sys.stdout is changed in getattr
|
3898
|
+
def filefault():
|
3899
|
+
if verbose:
|
3900
|
+
print "Testing sys.stdout is changed in getattr..."
|
3901
|
+
import sys
|
3902
|
+
class StdoutGuard:
|
3903
|
+
def __getattr__(self, attr):
|
3904
|
+
sys.stdout = sys.__stdout__
|
3905
|
+
raise RuntimeError("Premature access to sys.stdout.%s" % attr)
|
3906
|
+
sys.stdout = StdoutGuard()
|
3907
|
+
try:
|
3908
|
+
print "Oops!"
|
3909
|
+
except RuntimeError:
|
3910
|
+
pass
|
3911
|
+
|
3912
|
+
def subclass_binop():
|
3913
|
+
if verbose:
|
3914
|
+
print "Testing binary ops with subclasses"
|
3915
|
+
|
3916
|
+
def raises(exc, expected, callable, *args):
|
3917
|
+
try:
|
3918
|
+
callable(*args)
|
3919
|
+
except exc, msg:
|
3920
|
+
if str(msg) != expected:
|
3921
|
+
raise TestFailed, "Message %r, expected %r" % (str(msg),
|
3922
|
+
expected)
|
3923
|
+
else:
|
3924
|
+
raise TestFailed, "Expected %s" % exc
|
3925
|
+
|
3926
|
+
class B(object):
|
3927
|
+
pass
|
3928
|
+
|
3929
|
+
class C(object):
|
3930
|
+
def __radd__(self, o):
|
3931
|
+
return '%r + C()' % (o,)
|
3932
|
+
|
3933
|
+
def __rmul__(self, o):
|
3934
|
+
return '%r * C()' % (o,)
|
3935
|
+
|
3936
|
+
# Test strs, unicode, lists and tuples
|
3937
|
+
mapping = []
|
3938
|
+
|
3939
|
+
# + binop
|
3940
|
+
mapping.append((lambda o: 'foo' + o,
|
3941
|
+
TypeError, "cannot concatenate 'str' and 'B' objects",
|
3942
|
+
"'foo' + C()"))
|
3943
|
+
# XXX: There's probably work to be done here besides just emulating this
|
3944
|
+
# message
|
3945
|
+
#mapping.append((lambda o: u'foo' + o,
|
3946
|
+
# TypeError,
|
3947
|
+
# 'coercing to Unicode: need string or buffer, B found',
|
3948
|
+
# "u'foo' + C()"))
|
3949
|
+
mapping.append((lambda o: u'foo' + o,
|
3950
|
+
TypeError, "cannot concatenate 'unicode' and 'B' objects",
|
3951
|
+
"u'foo' + C()"))
|
3952
|
+
mapping.append((lambda o: [1, 2] + o,
|
3953
|
+
TypeError, 'can only concatenate list (not "B") to list',
|
3954
|
+
'[1, 2] + C()'))
|
3955
|
+
mapping.append((lambda o: ('foo', 'bar') + o,
|
3956
|
+
TypeError, 'can only concatenate tuple (not "B") to tuple',
|
3957
|
+
"('foo', 'bar') + C()"))
|
3958
|
+
|
3959
|
+
# * binop
|
3960
|
+
mapping.append((lambda o: 'foo' * o,
|
3961
|
+
TypeError, "can't multiply sequence by non-int of type 'B'",
|
3962
|
+
"'foo' * C()"))
|
3963
|
+
mapping.append((lambda o: u'foo' * o,
|
3964
|
+
TypeError, "can't multiply sequence by non-int of type 'B'",
|
3965
|
+
"u'foo' * C()"))
|
3966
|
+
mapping.append((lambda o: [1, 2] * o,
|
3967
|
+
TypeError, "can't multiply sequence by non-int of type 'B'",
|
3968
|
+
'[1, 2] * C()'))
|
3969
|
+
mapping.append((lambda o: ('foo', 'bar') * o,
|
3970
|
+
TypeError, "can't multiply sequence by non-int of type 'B'",
|
3971
|
+
"('foo', 'bar') * C()"))
|
3972
|
+
|
3973
|
+
for func, bexc, bexc_msg, cresult in mapping:
|
3974
|
+
raises(bexc, bexc_msg, lambda : func(B()))
|
3975
|
+
vereq(func(C()), cresult)
|
3976
|
+
|
3977
|
+
def test_main():
|
3978
|
+
testfuncs = [
|
3979
|
+
weakref_segfault, # Must be first, somehow
|
3980
|
+
do_this_first,
|
3981
|
+
class_docstrings,
|
3982
|
+
lists,
|
3983
|
+
dicts,
|
3984
|
+
dict_constructor,
|
3985
|
+
test_dir,
|
3986
|
+
ints,
|
3987
|
+
longs,
|
3988
|
+
floats,
|
3989
|
+
complexes,
|
3990
|
+
pydicts,
|
3991
|
+
pylists,
|
3992
|
+
metaclass,
|
3993
|
+
pymods,
|
3994
|
+
multi,
|
3995
|
+
mro_disagreement,
|
3996
|
+
diamond,
|
3997
|
+
ex5,
|
3998
|
+
monotonicity,
|
3999
|
+
consistency_with_epg,
|
4000
|
+
objects,
|
4001
|
+
slots,
|
4002
|
+
slotspecials,
|
4003
|
+
dynamics,
|
4004
|
+
errors,
|
4005
|
+
classmethods,
|
4006
|
+
staticmethods,
|
4007
|
+
classic,
|
4008
|
+
compattr,
|
4009
|
+
newslot,
|
4010
|
+
altmro,
|
4011
|
+
overloading,
|
4012
|
+
methods,
|
4013
|
+
specials,
|
4014
|
+
weakrefs,
|
4015
|
+
properties,
|
4016
|
+
supers,
|
4017
|
+
inherits,
|
4018
|
+
keywords,
|
4019
|
+
restricted,
|
4020
|
+
str_subclass_as_dict_key,
|
4021
|
+
classic_comparisons,
|
4022
|
+
rich_comparisons,
|
4023
|
+
coercions,
|
4024
|
+
descrdoc,
|
4025
|
+
setclass,
|
4026
|
+
setdict,
|
4027
|
+
pickles,
|
4028
|
+
copies,
|
4029
|
+
binopoverride,
|
4030
|
+
subclasspropagation,
|
4031
|
+
buffer_inherit,
|
4032
|
+
str_of_str_subclass,
|
4033
|
+
kwdargs,
|
4034
|
+
delhook,
|
4035
|
+
hashinherit,
|
4036
|
+
strops,
|
4037
|
+
deepcopyrecursive,
|
4038
|
+
modules,
|
4039
|
+
dictproxyiterkeys,
|
4040
|
+
dictproxyitervalues,
|
4041
|
+
dictproxyiteritems,
|
4042
|
+
pickleslots,
|
4043
|
+
funnynew,
|
4044
|
+
imulbug,
|
4045
|
+
docdescriptor,
|
4046
|
+
string_exceptions,
|
4047
|
+
copy_setstate,
|
4048
|
+
slices,
|
4049
|
+
subtype_resurrection,
|
4050
|
+
slottrash,
|
4051
|
+
slotmultipleinheritance,
|
4052
|
+
testrmul,
|
4053
|
+
testipow,
|
4054
|
+
test_mutable_bases,
|
4055
|
+
test_mutable_bases_with_failing_mro,
|
4056
|
+
test_mutable_bases_catch_mro_conflict,
|
4057
|
+
mutable_names,
|
4058
|
+
subclass_right_op,
|
4059
|
+
subclass_cmp_right_op,
|
4060
|
+
dict_type_with_metaclass,
|
4061
|
+
meth_class_get,
|
4062
|
+
isinst_isclass,
|
4063
|
+
proxysuper,
|
4064
|
+
carloverre,
|
4065
|
+
filefault,
|
4066
|
+
subclass_binop,
|
4067
|
+
]
|
4068
|
+
if __name__ == '__main__':
|
4069
|
+
import sys
|
4070
|
+
if len(sys.argv) > 1:
|
4071
|
+
testfuncs = [globals()[arg] for arg in sys.argv[1:]]
|
4072
|
+
|
4073
|
+
n = len(testfuncs)
|
4074
|
+
success = 0
|
4075
|
+
|
4076
|
+
for testfunc in testfuncs:
|
4077
|
+
try:
|
4078
|
+
print "*"*40
|
4079
|
+
testfunc()
|
4080
|
+
except Exception, e:
|
4081
|
+
if isinstance(e, KeyboardInterrupt) or n == 1:
|
4082
|
+
raise
|
4083
|
+
print "-->", testfunc.__name__, "FAILURE(%d/%d)" % (success, n), str(e)
|
4084
|
+
else:
|
4085
|
+
success += 1
|
4086
|
+
print "-->", testfunc.__name__, "OK(%d/%d)" % (success, n)
|
4087
|
+
|
4088
|
+
if n != success:
|
4089
|
+
raise TestFailed, "%d/%d" % (success, n)
|
4090
|
+
else:
|
4091
|
+
if verbose: print "All OK"
|
4092
|
+
|
4093
|
+
if __name__ == "__main__":
|
4094
|
+
test_main()
|