Merge lp:~sidnei/zope3/ztk-1.0a1 into lp:~landscape/zope3/trunk
- ztk-1.0a1
- Merge into trunk
Proposed by
Sidnei da Silva
Status: | Merged |
---|---|
Approved by: | Muharem Hrnjadovic |
Approved revision: | 16 |
Merged at revision: | 16 |
Proposed branch: | lp:~sidnei/zope3/ztk-1.0a1 |
Merge into: | lp:~landscape/zope3/trunk |
Diff against target: |
41688 lines (+18120/-9441) 556 files modified
src/ClientForm.py (+0/-3401) src/ZConfig/__init__.py (+1/-1) src/ZConfig/cfgparser.py (+1/-1) src/ZConfig/cmdline.py (+1/-1) src/ZConfig/components/basic/mapping.py (+1/-1) src/ZConfig/components/basic/tests/test_mapping.py (+1/-1) src/ZConfig/components/logger/__init__.py (+1/-1) src/ZConfig/components/logger/datatypes.py (+1/-1) src/ZConfig/components/logger/factory.py (+1/-1) src/ZConfig/components/logger/handlers.py (+15/-2) src/ZConfig/components/logger/handlers.xml (+2/-0) src/ZConfig/components/logger/logger.py (+1/-1) src/ZConfig/components/logger/loghandler.py (+1/-1) src/ZConfig/components/logger/tests/test_logger.py (+49/-1) src/ZConfig/datatypes.py (+1/-1) src/ZConfig/info.py (+1/-1) src/ZConfig/loader.py (+11/-3) src/ZConfig/matcher.py (+1/-1) src/ZConfig/schema.py (+1/-1) src/ZConfig/schemaless.py (+1/-1) src/ZConfig/substitution.py (+1/-1) src/ZConfig/tests/__init__.py (+1/-1) src/ZConfig/tests/library/thing/__init__.py (+1/-1) src/ZConfig/tests/support.py (+1/-1) src/ZConfig/tests/test_cfgimports.py (+1/-1) src/ZConfig/tests/test_cmdline.py (+1/-1) src/ZConfig/tests/test_config.py (+1/-1) src/ZConfig/tests/test_cookbook.py (+1/-1) src/ZConfig/tests/test_datatypes.py (+1/-1) src/ZConfig/tests/test_loader.py (+6/-1) src/ZConfig/tests/test_readme.py (+1/-1) src/ZConfig/tests/test_schema.py (+1/-1) src/ZConfig/tests/test_schemaless.py (+1/-1) src/ZConfig/tests/test_subst.py (+1/-1) src/ZConfig/url.py (+1/-1) src/ZEO/cache.py (+31/-20) src/ZEO/mkzeoinst.py (+9/-227) src/ZEO/tests/testZEO.py (+4/-1) src/ZODB/ConflictResolution.py (+5/-1) src/ZODB/ConflictResolution.txt (+11/-1) src/ZODB/Connection.py (+3/-2) src/ZODB/scripts/tests/test_repozo.py (+4/-10) src/ZODB/serialize.py (+27/-10) src/ZODB/tests/testConnection.py (+20/-4) src/ZODB/tests/testConnectionSavepoint.py (+29/-1) src/Zope3.egg-info/PKG-INFO (+10/-0) src/Zope3.egg-info/SOURCES.txt (+1924/-0) src/Zope3.egg-info/dependency_links.txt (+1/-0) src/Zope3.egg-info/namespace_packages.txt (+3/-0) src/Zope3.egg-info/not-zip-safe (+1/-0) src/Zope3.egg-info/top_level.txt (+14/-0) src/mechanize/__init__.py (+83/-15) src/mechanize/_auth.py (+4/-458) src/mechanize/_beautifulsoup.py (+2/-5) src/mechanize/_clientcookie.py (+14/-21) src/mechanize/_debug.py (+1/-1) src/mechanize/_file.py (+0/-60) src/mechanize/_firefox3cookiejar.py (+4/-5) src/mechanize/_form.py (+3275/-0) src/mechanize/_gzip.py (+4/-2) src/mechanize/_html.py (+43/-53) src/mechanize/_http.py (+157/-468) src/mechanize/_markupbase.py (+393/-0) src/mechanize/_mechanize.py (+14/-20) src/mechanize/_msiecookiejar.py (+1/-1) src/mechanize/_opener.py (+73/-67) src/mechanize/_pullparser.py (+4/-3) src/mechanize/_request.py (+4/-51) src/mechanize/_response.py (+6/-8) src/mechanize/_rfc3986.py (+4/-0) src/mechanize/_seek.py (+0/-16) src/mechanize/_sgmllib_copy.py (+559/-0) src/mechanize/_testcase.py (+89/-1) src/mechanize/_upgrade.py (+0/-40) src/mechanize/_urllib2.py (+21/-26) src/mechanize/_urllib2_fork.py (+1410/-0) src/mechanize/_useragent.py (+26/-11) src/mechanize/_util.py (+16/-2) src/mechanize/_version.py (+2/-0) src/persistent/cPickleCache.c (+6/-4) src/persistent/wref.py (+59/-2) src/transaction/__init__.py (+5/-3) src/transaction/_manager.py (+46/-59) src/transaction/_transaction.py (+10/-2) src/transaction/interfaces.py (+21/-13) src/transaction/tests/convenience.txt (+183/-0) src/transaction/tests/sampledm.py (+2/-2) src/transaction/tests/savepointsample.py (+2/-3) src/transaction/tests/test_SampleDataManager.py (+2/-4) src/transaction/tests/test_SampleResourceManager.py (+2/-2) src/transaction/tests/test_register_compat.py (+2/-3) src/transaction/tests/test_savepoint.py (+24/-5) src/transaction/tests/test_transaction.py (+68/-10) src/transaction/tests/test_weakset.py (+1/-1) src/transaction/tests/warnhook.py (+1/-1) src/transaction/weakset.py (+1/-1) src/wsgi_intercept/__init__.py (+565/-0) src/wsgi_intercept/httplib2_intercept.py (+50/-0) src/wsgi_intercept/mechanize_intercept/__init__.py (+6/-0) src/wsgi_intercept/mechanize_intercept/wsgi_browser.py (+33/-0) src/wsgi_intercept/mechanoid_intercept/__init__.py (+6/-0) src/wsgi_intercept/mechanoid_intercept/wsgi_browser.py (+35/-0) src/wsgi_intercept/mock_http.py (+70/-0) src/wsgi_intercept/setup_cmd/__init__.py (+1/-0) src/wsgi_intercept/setup_cmd/build_docs.py (+146/-0) src/wsgi_intercept/setup_cmd/publish_docs.py (+199/-0) src/wsgi_intercept/test/test_httplib2.py (+38/-0) src/wsgi_intercept/test/test_mechanize.py (+47/-0) src/wsgi_intercept/test/test_mechanoid.py (+34/-0) src/wsgi_intercept/test/test_webtest.py (+37/-0) src/wsgi_intercept/test/test_webunit.py (+47/-0) src/wsgi_intercept/test/test_wsgi_compliance.py (+55/-0) src/wsgi_intercept/test/test_wsgi_urllib2.py (+40/-0) src/wsgi_intercept/test/test_zope_testbrowser.py (+41/-0) src/wsgi_intercept/test_wsgi_app.py (+24/-0) src/wsgi_intercept/urllib2_intercept/__init__.py (+7/-0) src/wsgi_intercept/urllib2_intercept/wsgi_urllib2.py (+59/-0) src/wsgi_intercept/webtest_intercept/__init__.py (+7/-0) src/wsgi_intercept/webtest_intercept/webtest.py (+418/-0) src/wsgi_intercept/webunit_intercept/HTMLParser.py (+439/-0) src/wsgi_intercept/webunit_intercept/IMGSucker.py (+112/-0) src/wsgi_intercept/webunit_intercept/SimpleDOM.py (+473/-0) src/wsgi_intercept/webunit_intercept/__init__.py (+8/-0) src/wsgi_intercept/webunit_intercept/config.py (+33/-0) src/wsgi_intercept/webunit_intercept/cookie.py (+92/-0) src/wsgi_intercept/webunit_intercept/utility.py (+85/-0) src/wsgi_intercept/webunit_intercept/webunittest.py (+743/-0) src/wsgi_intercept/zope_testbrowser/__init__.py (+6/-0) src/wsgi_intercept/zope_testbrowser/wsgi_testbrowser.py (+20/-0) src/zope/app/appsetup/appsetup.py (+7/-4) src/zope/app/appsetup/bootstrap.txt (+1/-1) src/zope/app/appsetup/ftesting.zcml (+20/-0) src/zope/app/appsetup/product.py (+7/-2) src/zope/app/appsetup/testlayer.py (+82/-0) src/zope/app/appsetup/testlayer.txt (+62/-0) src/zope/app/appsetup/testpackage/__init__.py (+1/-0) src/zope/app/appsetup/testpackage/ftesting.zcml (+6/-0) src/zope/app/appsetup/testpackage/testobject.py (+5/-0) src/zope/app/appsetup/tests.py (+50/-44) src/zope/app/dav/proppatch.py (+29/-14) src/zope/app/dav/tests/test_proppatch.py (+0/-5) src/zope/app/http/exception/methodnotallowed.py (+15/-8) src/zope/app/http/exception/tests/test_methodnotallowed.py (+47/-10) src/zope/app/http/testing.py (+0/-26) src/zope/app/http/tests/test_delete.py (+2/-3) src/zope/app/http/tests/test_functional_put.py (+22/-19) src/zope/app/http/tests/test_options.py (+2/-3) src/zope/app/http/tests/test_put.py (+16/-6) src/zope/app/locales/de/LC_MESSAGES/zope.po (+389/-980) src/zope/app/locales/nl/LC_MESSAGES/zope.po (+4/-8) src/zope/app/locales/tests.py (+29/-1) src/zope/app/localpermission/browser.zcml (+1/-0) src/zope/app/pagetemplate/meta.zcml (+1/-8) src/zope/app/pagetemplate/metaconfigure.py (+4/-31) src/zope/app/pagetemplate/tests/test_directives.py (+0/-60) src/zope/app/principalannotation/bootstrap.zcml (+1/-1) src/zope/app/publication/ftesting.zcml (+41/-29) src/zope/app/publication/httpfactory.txt (+7/-5) src/zope/app/publication/methodnotallowed.txt (+7/-6) src/zope/app/publication/testing.py (+15/-7) src/zope/app/publication/tests/ftest_zcml_dependencies.zcml (+2/-2) src/zope/app/publication/tests/support.py (+29/-0) src/zope/app/publication/tests/test_browserpublication.py (+27/-13) src/zope/app/publication/tests/test_dependencies.py (+12/-15) src/zope/app/publication/tests/test_functional.py (+14/-10) src/zope/app/publication/tests/test_http.py (+4/-5) src/zope/app/publication/tests/test_httpfactory.py (+1/-2) src/zope/app/publication/tests/test_simplecomponenttraverser.py (+6/-5) src/zope/app/publication/tests/test_xmlrpcpublication.py (+16/-11) src/zope/app/publication/tests/test_zopepublication.py (+124/-87) src/zope/app/testing/dochttp.py (+2/-2) src/zope/app/testing/functional.py (+3/-4) src/zope/app/testing/placelesssetup.py (+2/-2) src/zope/app/testing/setup.py (+2/-2) src/zope/app/testing/testing.py (+2/-2) src/zope/app/testing/tests.py (+3/-3) src/zope/app/testing/xmlrpc.py (+2/-2) src/zope/app/testing/ztapi.py (+2/-2) src/zope/app/wsgi/README.txt (+21/-40) src/zope/app/wsgi/__init__.py (+15/-6) src/zope/app/wsgi/ftesting.zcml (+22/-10) src/zope/app/wsgi/testing.py (+6/-7) src/zope/app/wsgi/testlayer.py (+273/-0) src/zope/app/wsgi/tests.py (+27/-19) src/zope/app/zapi/README.txt (+0/-42) src/zope/app/zapi/__init__.py (+0/-57) src/zope/app/zapi/configure.zcml (+0/-23) src/zope/app/zapi/interfaces.py (+0/-67) src/zope/app/zapi/tests.py (+0/-59) src/zope/authentication/tests/test_logout.py (+2/-2) src/zope/authentication/tests/test_principal.py (+2/-2) src/zope/browser/__init__.py (+1/-1) src/zope/browser/interfaces.py (+109/-109) src/zope/browser/tests.py (+32/-32) src/zope/browsermenu/tests/test_addMenuItem.py (+2/-2) src/zope/browsermenu/tests/test_directives.py (+2/-2) src/zope/browsermenu/tests/test_fields.py (+3/-2) src/zope/browsermenu/tests/test_menu.py (+5/-3) src/zope/browserpage/meta.zcml (+9/-0) src/zope/browserpage/metaconfigure.py (+9/-2) src/zope/browserpage/metadirectives.py (+19/-2) src/zope/browserpage/namedtemplate.py (+1/-1) src/zope/browserpage/simpleviewclass.py (+2/-2) src/zope/browserpage/tests/sample.py (+2/-2) src/zope/browserpage/tests/simpletestview.py (+2/-2) src/zope/browserpage/tests/test_boundpagetemplate.py (+2/-2) src/zope/browserpage/tests/test_expressiontype.py (+60/-0) src/zope/browserpage/tests/test_namedtemplate.py (+6/-4) src/zope/browserpage/tests/test_page.py (+3/-3) src/zope/browserpage/tests/test_simpleviewclass.py (+2/-2) src/zope/browserpage/tests/test_viewzpt.py (+2/-2) src/zope/browserpage/viewpagetemplatefile.py (+2/-2) src/zope/browserresource/tests/test_file.py (+4/-2) src/zope/browserresource/tests/test_resources.py (+4/-2) src/zope/cachedescriptors/property.txt (+18/-18) src/zope/cachedescriptors/tests.py (+2/-7) src/zope/component/__init__.py (+2/-2) src/zope/component/_api.py (+2/-2) src/zope/component/_declaration.py (+2/-2) src/zope/component/event.py (+2/-2) src/zope/component/eventtesting.py (+2/-2) src/zope/component/factory.py (+2/-2) src/zope/component/globalregistry.py (+2/-2) src/zope/component/hookable.py (+1/-1) src/zope/component/hooks.py (+1/-1) src/zope/component/interface.py (+2/-2) src/zope/component/interfaces.py (+2/-2) src/zope/component/nexttesting.py (+2/-2) src/zope/component/persistentregistry.py (+2/-2) src/zope/component/registry.py (+2/-2) src/zope/component/security.py (+1/-1) src/zope/component/testfiles/adapter.py (+2/-2) src/zope/component/testfiles/components.py (+2/-2) src/zope/component/testfiles/views.py (+2/-2) src/zope/component/testing.py (+2/-2) src/zope/component/testlayer.py (+1/-1) src/zope/component/tests.py (+27/-3) src/zope/component/zcml.py (+3/-3) src/zope/component/zcml.txt (+2/-2) src/zope/component/zcml_conditional.txt (+2/-2) src/zope/configuration/__init__.py (+1/-1) src/zope/configuration/config.py (+2/-2) src/zope/configuration/docutils.py (+2/-2) src/zope/configuration/exceptions.py (+2/-2) src/zope/configuration/fields.py (+2/-2) src/zope/configuration/interfaces.py (+2/-2) src/zope/configuration/name.py (+2/-2) src/zope/configuration/stxdocs.py (+2/-2) src/zope/configuration/tests/directives.py (+2/-2) src/zope/configuration/tests/samplepackage/foo.py (+2/-2) src/zope/configuration/tests/test_conditions.py (+3/-3) src/zope/configuration/tests/test_config.py (+3/-3) src/zope/configuration/tests/test_docutils.py (+3/-3) src/zope/configuration/tests/test_nested.py (+3/-3) src/zope/configuration/tests/test_simple.py (+3/-3) src/zope/configuration/tests/test_xmlconfig.py (+3/-3) src/zope/configuration/xmlconfig.py (+2/-2) src/zope/configuration/zopeconfigure.py (+2/-2) src/zope/container/contained.py (+53/-43) src/zope/container/tests/test_btree.py (+2/-2) src/zope/container/tests/test_constraints.py (+4/-2) src/zope/container/tests/test_contained.py (+94/-5) src/zope/container/tests/test_directory.py (+5/-3) src/zope/container/tests/test_ordered.py (+4/-2) src/zope/contentprovider/__init__.py (+2/-2) src/zope/contentprovider/configure.zcml (+1/-1) src/zope/contentprovider/interfaces.py (+2/-2) src/zope/contentprovider/tales.py (+2/-2) src/zope/contentprovider/tests.py (+12/-11) src/zope/contenttype/__init__.py (+14/-18) src/zope/contenttype/mime.types (+1/-1) src/zope/contenttype/tests/testContentTypes.py (+47/-39) src/zope/deferredimport/DEPENDENCIES.cfg (+0/-2) src/zope/deferredimport/deferredmodule.py (+2/-2) src/zope/deferredimport/tests.py (+17/-7) src/zope/event/__init__.py (+2/-2) src/zope/event/tests.py (+30/-4) src/zope/exceptions/__init__.py (+2/-2) src/zope/exceptions/exceptionformatter.py (+2/-2) src/zope/exceptions/interfaces.py (+2/-2) src/zope/exceptions/log.py (+2/-2) src/zope/exceptions/tests/test_exceptionformatter.py (+3/-4) src/zope/formlib/__init__.py (+2/-2) src/zope/formlib/boolwidgets.py (+2/-2) src/zope/formlib/errors.py (+2/-2) src/zope/formlib/exception.py (+2/-2) src/zope/formlib/form.py (+53/-39) src/zope/formlib/form.txt (+12/-6) src/zope/formlib/interfaces.py (+2/-2) src/zope/formlib/itemswidgets.py (+7/-7) src/zope/formlib/namedtemplate.py (+2/-2) src/zope/formlib/objectwidget.py (+2/-2) src/zope/formlib/sequencewidget.py (+2/-2) src/zope/formlib/source.py (+2/-2) src/zope/formlib/source.txt (+1/-1) src/zope/formlib/tests/support.py (+2/-2) src/zope/formlib/tests/test_browserwidget.py (+2/-2) src/zope/formlib/tests/test_checkboxwidget.py (+2/-2) src/zope/formlib/tests/test_choicecollections.py (+2/-2) src/zope/formlib/tests/test_choicewidget.py (+2/-2) src/zope/formlib/tests/test_datetimewidget.py (+2/-2) src/zope/formlib/tests/test_datewidget.py (+2/-2) src/zope/formlib/tests/test_decimalwidget.py (+2/-2) src/zope/formlib/tests/test_displaywidget.py (+2/-2) src/zope/formlib/tests/test_exception.py (+2/-2) src/zope/formlib/tests/test_filewidget.py (+2/-2) src/zope/formlib/tests/test_floatwidget.py (+2/-2) src/zope/formlib/tests/test_formlib.py (+2/-11) src/zope/formlib/tests/test_functional_booleanradiowidget.py (+2/-2) src/zope/formlib/tests/test_functional_checkboxwidget.py (+2/-2) src/zope/formlib/tests/test_functional_datetimewidget.py (+2/-2) src/zope/formlib/tests/test_functional_decimalwidget.py (+2/-2) src/zope/formlib/tests/test_functional_filewidget.py (+2/-2) src/zope/formlib/tests/test_functional_floatwidget.py (+2/-2) src/zope/formlib/tests/test_functional_intwidget.py (+2/-2) src/zope/formlib/tests/test_functional_objectwidget.py (+2/-2) src/zope/formlib/tests/test_functional_selectwidget.py (+2/-2) src/zope/formlib/tests/test_functional_textareawidget.py (+2/-2) src/zope/formlib/tests/test_functional_textwidget.py (+2/-2) src/zope/formlib/tests/test_intwidget.py (+2/-2) src/zope/formlib/tests/test_itemswidget.py (+52/-6) src/zope/formlib/tests/test_multicheckboxwidget.py (+2/-2) src/zope/formlib/tests/test_objectwidget.py (+2/-2) src/zope/formlib/tests/test_passwordwidget.py (+2/-2) src/zope/formlib/tests/test_radiowidget.py (+2/-2) src/zope/formlib/tests/test_registrations.py (+2/-2) src/zope/formlib/tests/test_selectwidget.py (+2/-2) src/zope/formlib/tests/test_sequencewidget.py (+2/-2) src/zope/formlib/tests/test_setprefix.py (+2/-2) src/zope/formlib/tests/test_source.py (+2/-2) src/zope/formlib/tests/test_textareawidget.py (+2/-2) src/zope/formlib/tests/test_textwidget.py (+2/-2) src/zope/formlib/tests/test_widget.py (+2/-2) src/zope/formlib/tests/test_widgetdocs.py (+2/-2) src/zope/formlib/textwidgets.py (+2/-2) src/zope/formlib/utility.py (+1/-1) src/zope/formlib/widget.py (+2/-2) src/zope/formlib/widgets.py (+2/-2) src/zope/i18n/locales/tests/test_docstrings.py (+4/-3) src/zope/i18n/locales/tests/test_fallbackcollator.py (+1/-1) src/zope/i18n/tests/test.py (+2/-2) src/zope/i18n/tests/test_testmessagecatalog.py (+1/-1) src/zope/i18nmessageid/__init__.py (+2/-2) src/zope/i18nmessageid/_zope_i18nmessageid_message.c (+3/-3) src/zope/i18nmessageid/message.py (+2/-2) src/zope/i18nmessageid/tests.py (+4/-3) src/zope/interface/README.ru.txt (+22/-16) src/zope/interface/README.txt (+38/-18) src/zope/interface/__init__.py (+4/-3) src/zope/interface/_flatten.py (+1/-1) src/zope/interface/_zope_interface_coptimizations.c (+85/-45) src/zope/interface/_zope_interface_coptimizations.py (+7/-0) src/zope/interface/adapter.py (+11/-1) src/zope/interface/adapter.ru.txt (+3/-6) src/zope/interface/adapter.txt (+3/-6) src/zope/interface/advice.py (+20/-9) src/zope/interface/common/idatetime.py (+2/-2) src/zope/interface/common/interfaces.py (+1/-1) src/zope/interface/common/mapping.py (+2/-2) src/zope/interface/common/sequence.py (+2/-2) src/zope/interface/common/tests/basemapping.py (+2/-8) src/zope/interface/common/tests/test_idatetime.py (+1/-1) src/zope/interface/common/tests/test_import_interfaces.py (+1/-1) src/zope/interface/declarations.py (+67/-57) src/zope/interface/document.py (+2/-2) src/zope/interface/exceptions.py (+1/-1) src/zope/interface/interface.py (+38/-29) src/zope/interface/interfaces.py (+11/-2) src/zope/interface/ro.py (+1/-1) src/zope/interface/tests/__init__.py (+13/-2) src/zope/interface/tests/dummy.py (+2/-3) src/zope/interface/tests/ifoo.py (+2/-2) src/zope/interface/tests/m1.py (+1/-1) src/zope/interface/tests/m2.py (+1/-1) src/zope/interface/tests/odd.py (+8/-6) src/zope/interface/tests/test_adapter.py (+3/-4) src/zope/interface/tests/test_advice.py (+16/-7) src/zope/interface/tests/test_declarations.py (+34/-37) src/zope/interface/tests/test_document.py (+2/-2) src/zope/interface/tests/test_element.py (+1/-1) src/zope/interface/tests/test_interface.py (+164/-84) src/zope/interface/tests/test_odd_declarations.py (+30/-18) src/zope/interface/tests/test_sorting.py (+4/-4) src/zope/interface/tests/test_verify.py (+6/-7) src/zope/interface/tests/unitfixtures.py (+2/-2) src/zope/interface/verify.py (+9/-4) src/zope/interface/verify.txt (+25/-12) src/zope/lifecycleevent/tests.py (+5/-2) src/zope/pagetemplate/engine.py (+6/-6) src/zope/pagetemplate/tests/test_engine.py (+2/-2) src/zope/password/__init__.py (+2/-2) src/zope/password/interfaces.py (+2/-2) src/zope/password/password.py (+22/-10) src/zope/password/testing.py (+2/-2) src/zope/password/tests.py (+0/-28) src/zope/password/tests/__init__.py (+16/-0) src/zope/password/tests/test_password.py (+27/-0) src/zope/password/tests/test_zpasswd.py (+157/-0) src/zope/password/zpasswd.py (+280/-0) src/zope/principalannotation/README.txt (+1/-0) src/zope/principalannotation/interfaces.py (+2/-2) src/zope/principalannotation/tests.py (+2/-2) src/zope/principalannotation/utility.py (+8/-5) src/zope/proxy/DEPENDENCIES.cfg (+0/-2) src/zope/proxy/SETUP.cfg (+0/-8) src/zope/proxy/tests/test_decorator.py (+2/-2) src/zope/proxy/tests/test_proxy.py (+2/-2) src/zope/publisher/http.py (+9/-8) src/zope/publisher/publish.py (+7/-2) src/zope/publisher/skinnable.txt (+330/-330) src/zope/publisher/tests/test_browser.py (+2/-2) src/zope/publisher/tests/test_defaultview.py (+1/-1) src/zope/publisher/tests/test_http.py (+46/-8) src/zope/publisher/tests/test_paste.py (+2/-1) src/zope/publisher/tests/test_publisher.py (+41/-3) src/zope/publisher/tests/test_skinnable.py (+2/-2) src/zope/publisher/tests/test_xmlrpc.py (+2/-2) src/zope/publisher/xmlrpc.py (+10/-5) src/zope/schema/__init__.py (+1/-3) src/zope/schema/_bootstrapfields.py (+1/-3) src/zope/schema/_bootstrapinterfaces.py (+2/-5) src/zope/schema/_field.py (+34/-17) src/zope/schema/_messageid.py (+20/-0) src/zope/schema/_schema.py (+1/-3) src/zope/schema/accessors.py (+1/-3) src/zope/schema/fieldproperty.py (+6/-8) src/zope/schema/interfaces.py (+20/-12) src/zope/schema/tests/states.py (+1/-3) src/zope/schema/tests/test_accessors.py (+1/-3) src/zope/schema/tests/test_boolfield.py (+1/-3) src/zope/schema/tests/test_choice.py (+1/-3) src/zope/schema/tests/test_containerfield.py (+1/-3) src/zope/schema/tests/test_date.py (+1/-3) src/zope/schema/tests/test_datetime.py (+1/-3) src/zope/schema/tests/test_decimalfield.py (+1/-3) src/zope/schema/tests/test_dictfield.py (+1/-3) src/zope/schema/tests/test_docs.py (+5/-8) src/zope/schema/tests/test_equality.py (+1/-3) src/zope/schema/tests/test_field.py (+5/-8) src/zope/schema/tests/test_fieldproperty.py (+1/-3) src/zope/schema/tests/test_floatfield.py (+1/-3) src/zope/schema/tests/test_interfacefield.py (+1/-3) src/zope/schema/tests/test_intfield.py (+1/-3) src/zope/schema/tests/test_iterablefield.py (+1/-3) src/zope/schema/tests/test_listfield.py (+1/-3) src/zope/schema/tests/test_objectfield.py (+121/-6) src/zope/schema/tests/test_schema.py (+1/-3) src/zope/schema/tests/test_setfield.py (+1/-3) src/zope/schema/tests/test_states.py (+1/-3) src/zope/schema/tests/test_strfield.py (+1/-3) src/zope/schema/tests/test_timedelta.py (+1/-3) src/zope/schema/tests/test_tuplefield.py (+1/-3) src/zope/schema/tests/test_vocabulary.py (+1/-3) src/zope/schema/vocabulary.py (+1/-3) src/zope/security/checker.py (+7/-2) src/zope/security/permission.py (+2/-2) src/zope/security/tests/test_adapter.py (+2/-6) src/zope/security/tests/test_decorator.py (+2/-3) src/zope/security/tests/test_directives.py (+2/-2) src/zope/security/tests/test_location.py (+1/-2) src/zope/security/tests/test_module_directives.py (+3/-2) src/zope/security/tests/test_permission.py (+3/-5) src/zope/security/tests/test_proxy.py (+3/-7) src/zope/security/tests/test_set_checkers.py (+3/-6) src/zope/security/tests/test_standard_checkers.py (+1/-10) src/zope/security/untrustedpython/tests.py (+12/-12) src/zope/sendmail/maildir.py (+9/-2) src/zope/sendmail/tests/test_delivery.py (+2/-2) src/zope/sendmail/tests/test_maildir.py (+15/-1) src/zope/sendmail/tests/test_vocabulary.py (+2/-2) src/zope/server/__init__.py (+1/-3) src/zope/server/adjustments.py (+1/-3) src/zope/server/buffers.py (+1/-3) src/zope/server/dualmodechannel.py (+1/-3) src/zope/server/fixedstreamreceiver.py (+1/-3) src/zope/server/ftp/logger.py (+1/-3) src/zope/server/ftp/publisher.py (+1/-3) src/zope/server/ftp/server.py (+1/-3) src/zope/server/ftp/tests/demofs.py (+1/-3) src/zope/server/ftp/tests/fstests.py (+1/-3) src/zope/server/ftp/tests/test_demofs.py (+1/-3) src/zope/server/ftp/tests/test_ftpserver.py (+1/-3) src/zope/server/ftp/tests/test_publisher.py (+1/-3) src/zope/server/http/chunking.py (+1/-3) src/zope/server/http/commonaccesslogger.py (+1/-3) src/zope/server/http/http_date.py (+1/-3) src/zope/server/http/httprequestparser.py (+1/-3) src/zope/server/http/httpserver.py (+1/-3) src/zope/server/http/httpserverchannel.py (+1/-3) src/zope/server/http/httptask.py (+1/-3) src/zope/server/http/publisherhttpserver.py (+1/-3) src/zope/server/http/tests/test_commonaccesslogger.py (+1/-3) src/zope/server/http/tests/test_httpdate.py (+1/-3) src/zope/server/http/tests/test_httprequestparser.py (+1/-3) src/zope/server/http/tests/test_httpserver.py (+1/-3) src/zope/server/http/tests/test_wsgiserver.py (+1/-3) src/zope/server/http/wsgihttpserver.py (+1/-3) src/zope/server/interfaces/__init__.py (+1/-3) src/zope/server/interfaces/ftp.py (+1/-3) src/zope/server/interfaces/logger.py (+1/-3) src/zope/server/linereceiver/linecommandparser.py (+1/-3) src/zope/server/linereceiver/lineserverchannel.py (+1/-3) src/zope/server/linereceiver/linetask.py (+1/-3) src/zope/server/logger/filelogger.py (+1/-3) src/zope/server/logger/pythonlogger.py (+1/-3) src/zope/server/logger/resolvinglogger.py (+1/-3) src/zope/server/logger/rotatingfilelogger.py (+1/-3) src/zope/server/logger/socketlogger.py (+1/-3) src/zope/server/logger/sysloglogger.py (+1/-3) src/zope/server/logger/taillogger.py (+1/-3) src/zope/server/logger/tests/test_pythonlogger.py (+1/-3) src/zope/server/logger/unresolvinglogger.py (+1/-3) src/zope/server/maxsockets.py (+1/-3) src/zope/server/serverbase.py (+1/-3) src/zope/server/serverchannelbase.py (+1/-3) src/zope/server/taskthreads.py (+6/-5) src/zope/server/tests/asyncerror.py (+1/-3) src/zope/server/tests/test_serverbase.py (+1/-3) src/zope/server/trigger.py (+1/-1) src/zope/server/utilities.py (+1/-3) src/zope/server/zlogintegration.py (+1/-3) src/zope/site/tests/test_folder.py (+2/-3) src/zope/site/tests/test_registration.py (+6/-5) src/zope/site/tests/test_site.py (+3/-2) src/zope/structuredtext/STNG.txt (+0/-111) src/zope/structuredtext/TODO.txt (+0/-6) src/zope/structuredtext/__init__.py (+15/-12) src/zope/structuredtext/docbook.py (+40/-24) src/zope/structuredtext/document.py (+240/-168) src/zope/structuredtext/html.py (+81/-49) src/zope/structuredtext/regressions/Acquisition.ref (+18/-18) src/zope/structuredtext/regressions/ExtensionClass.ref (+18/-18) src/zope/structuredtext/regressions/MultiMapping.ref (+10/-10) src/zope/structuredtext/regressions/examples.ref (+2/-2) src/zope/structuredtext/regressions/examples1.ref (+2/-2) src/zope/structuredtext/stdom.py (+1/-3) src/zope/structuredtext/stletters.py (+2/-3) src/zope/structuredtext/stng.py (+5/-4) src/zope/structuredtext/tests.py (+139/-29) src/zope/tales/tests/test_tales.py (+2/-2) src/zope/testbrowser/README.txt (+36/-1) src/zope/testbrowser/__init__.py (+2/-2) src/zope/testbrowser/browser.py (+14/-14) src/zope/testbrowser/cookies.py (+1/-1) src/zope/testbrowser/fixed-bugs.txt (+1/-3) src/zope/testbrowser/interfaces.py (+4/-4) src/zope/testbrowser/testing.py (+12/-19) src/zope/testbrowser/tests.py (+149/-101) src/zope/traversing/tests/test_namespacetrversal.py (+2/-2) src/zope/viewlet/__init__.py (+2/-2) src/zope/viewlet/interfaces.py (+2/-2) src/zope/viewlet/manager.py (+2/-2) src/zope/viewlet/metaconfigure.py (+2/-2) src/zope/viewlet/metadirectives.py (+3/-3) src/zope/viewlet/tests.py (+10/-3) src/zope/viewlet/viewlet.py (+2/-2) |
To merge this branch: | bzr merge lp:~sidnei/zope3/ztk-1.0a1 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Muharem Hrnjadovic (community) | Approve | ||
Thomas Herve (community) | Approve | ||
Review via email: mp+29032@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
Revision history for this message
Muharem Hrnjadovic (al-maisan) wrote : | # |
Looks good, +1
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === removed file 'src/ClientForm.py' | |||
2 | --- src/ClientForm.py 2010-03-01 20:29:16 +0000 | |||
3 | +++ src/ClientForm.py 1970-01-01 00:00:00 +0000 | |||
4 | @@ -1,3401 +0,0 @@ | |||
5 | 1 | """HTML form handling for web clients. | ||
6 | 2 | |||
7 | 3 | ClientForm is a Python module for handling HTML forms on the client | ||
8 | 4 | side, useful for parsing HTML forms, filling them in and returning the | ||
9 | 5 | completed forms to the server. It has developed from a port of Gisle | ||
10 | 6 | Aas' Perl module HTML::Form, from the libwww-perl library, but the | ||
11 | 7 | interface is not the same. | ||
12 | 8 | |||
13 | 9 | The most useful docstring is the one for HTMLForm. | ||
14 | 10 | |||
15 | 11 | RFC 1866: HTML 2.0 | ||
16 | 12 | RFC 1867: Form-based File Upload in HTML | ||
17 | 13 | RFC 2388: Returning Values from Forms: multipart/form-data | ||
18 | 14 | HTML 3.2 Specification, W3C Recommendation 14 January 1997 (for ISINDEX) | ||
19 | 15 | HTML 4.01 Specification, W3C Recommendation 24 December 1999 | ||
20 | 16 | |||
21 | 17 | |||
22 | 18 | Copyright 2002-2007 John J. Lee <jjl@pobox.com> | ||
23 | 19 | Copyright 2005 Gary Poster | ||
24 | 20 | Copyright 2005 Zope Corporation | ||
25 | 21 | Copyright 1998-2000 Gisle Aas. | ||
26 | 22 | |||
27 | 23 | This code is free software; you can redistribute it and/or modify it | ||
28 | 24 | under the terms of the BSD or ZPL 2.1 licenses (see the file | ||
29 | 25 | COPYING.txt included with the distribution). | ||
30 | 26 | |||
31 | 27 | """ | ||
32 | 28 | |||
33 | 29 | # XXX | ||
34 | 30 | # Remove parser testing hack | ||
35 | 31 | # safeUrl()-ize action | ||
36 | 32 | # Switch to unicode throughout (would be 0.3.x) | ||
37 | 33 | # See Wichert Akkerman's 2004-01-22 message to c.l.py. | ||
38 | 34 | # Add charset parameter to Content-type headers? How to find value?? | ||
39 | 35 | # Add some more functional tests | ||
40 | 36 | # Especially single and multiple file upload on the internet. | ||
41 | 37 | # Does file upload work when name is missing? Sourceforge tracker form | ||
42 | 38 | # doesn't like it. Check standards, and test with Apache. Test | ||
43 | 39 | # binary upload with Apache. | ||
44 | 40 | # mailto submission & enctype text/plain | ||
45 | 41 | # I'm not going to fix this unless somebody tells me what real servers | ||
46 | 42 | # that want this encoding actually expect: If enctype is | ||
47 | 43 | # application/x-www-form-urlencoded and there's a FILE control present. | ||
48 | 44 | # Strictly, it should be 'name=data' (see HTML 4.01 spec., section | ||
49 | 45 | # 17.13.2), but I send "name=" ATM. What about multiple file upload?? | ||
50 | 46 | |||
51 | 47 | # Would be nice, but I'm not going to do it myself: | ||
52 | 48 | # ------------------------------------------------- | ||
53 | 49 | # Maybe a 0.4.x? | ||
54 | 50 | # Replace by_label etc. with moniker / selector concept. Allows, eg., | ||
55 | 51 | # a choice between selection by value / id / label / element | ||
56 | 52 | # contents. Or choice between matching labels exactly or by | ||
57 | 53 | # substring. Etc. | ||
58 | 54 | # Remove deprecated methods. | ||
59 | 55 | # ...what else? | ||
60 | 56 | # Work on DOMForm. | ||
61 | 57 | # XForms? Don't know if there's a need here. | ||
62 | 58 | |||
63 | 59 | __all__ = ['AmbiguityError', 'CheckboxControl', 'Control', | ||
64 | 60 | 'ControlNotFoundError', 'FileControl', 'FormParser', 'HTMLForm', | ||
65 | 61 | 'HiddenControl', 'IgnoreControl', 'ImageControl', 'IsindexControl', | ||
66 | 62 | 'Item', 'ItemCountError', 'ItemNotFoundError', 'Label', | ||
67 | 63 | 'ListControl', 'LocateError', 'Missing', 'ParseError', 'ParseFile', | ||
68 | 64 | 'ParseFileEx', 'ParseResponse', 'ParseResponseEx','PasswordControl', | ||
69 | 65 | 'RadioControl', 'ScalarControl', 'SelectControl', | ||
70 | 66 | 'SubmitButtonControl', 'SubmitControl', 'TextControl', | ||
71 | 67 | 'TextareaControl', 'XHTMLCompatibleFormParser'] | ||
72 | 68 | |||
73 | 69 | try: True | ||
74 | 70 | except NameError: | ||
75 | 71 | True = 1 | ||
76 | 72 | False = 0 | ||
77 | 73 | |||
78 | 74 | try: bool | ||
79 | 75 | except NameError: | ||
80 | 76 | def bool(expr): | ||
81 | 77 | if expr: return True | ||
82 | 78 | else: return False | ||
83 | 79 | |||
84 | 80 | try: | ||
85 | 81 | import logging | ||
86 | 82 | import inspect | ||
87 | 83 | except ImportError: | ||
88 | 84 | def debug(msg, *args, **kwds): | ||
89 | 85 | pass | ||
90 | 86 | else: | ||
91 | 87 | _logger = logging.getLogger("ClientForm") | ||
92 | 88 | OPTIMIZATION_HACK = True | ||
93 | 89 | |||
94 | 90 | def debug(msg, *args, **kwds): | ||
95 | 91 | if OPTIMIZATION_HACK: | ||
96 | 92 | return | ||
97 | 93 | |||
98 | 94 | caller_name = inspect.stack()[1][3] | ||
99 | 95 | extended_msg = '%%s %s' % msg | ||
100 | 96 | extended_args = (caller_name,)+args | ||
101 | 97 | debug = _logger.debug(extended_msg, *extended_args, **kwds) | ||
102 | 98 | |||
103 | 99 | def _show_debug_messages(): | ||
104 | 100 | global OPTIMIZATION_HACK | ||
105 | 101 | OPTIMIZATION_HACK = False | ||
106 | 102 | _logger.setLevel(logging.DEBUG) | ||
107 | 103 | handler = logging.StreamHandler(sys.stdout) | ||
108 | 104 | handler.setLevel(logging.DEBUG) | ||
109 | 105 | _logger.addHandler(handler) | ||
110 | 106 | |||
111 | 107 | import sys, urllib, urllib2, types, mimetools, copy, urlparse, \ | ||
112 | 108 | htmlentitydefs, re, random | ||
113 | 109 | from cStringIO import StringIO | ||
114 | 110 | |||
115 | 111 | import sgmllib | ||
116 | 112 | # monkeypatch to fix http://www.python.org/sf/803422 :-( | ||
117 | 113 | sgmllib.charref = re.compile("&#(x?[0-9a-fA-F]+)[^0-9a-fA-F]") | ||
118 | 114 | |||
119 | 115 | # HTMLParser.HTMLParser is recent, so live without it if it's not available | ||
120 | 116 | # (also, sgmllib.SGMLParser is much more tolerant of bad HTML) | ||
121 | 117 | try: | ||
122 | 118 | import HTMLParser | ||
123 | 119 | except ImportError: | ||
124 | 120 | HAVE_MODULE_HTMLPARSER = False | ||
125 | 121 | else: | ||
126 | 122 | HAVE_MODULE_HTMLPARSER = True | ||
127 | 123 | |||
128 | 124 | try: | ||
129 | 125 | import warnings | ||
130 | 126 | except ImportError: | ||
131 | 127 | def deprecation(message, stack_offset=0): | ||
132 | 128 | pass | ||
133 | 129 | else: | ||
134 | 130 | def deprecation(message, stack_offset=0): | ||
135 | 131 | warnings.warn(message, DeprecationWarning, stacklevel=3+stack_offset) | ||
136 | 132 | |||
137 | 133 | VERSION = "0.2.10" | ||
138 | 134 | |||
139 | 135 | CHUNK = 1024 # size of chunks fed to parser, in bytes | ||
140 | 136 | |||
141 | 137 | DEFAULT_ENCODING = "latin-1" | ||
142 | 138 | |||
143 | 139 | class Missing: pass | ||
144 | 140 | |||
145 | 141 | _compress_re = re.compile(r"\s+") | ||
146 | 142 | def compress_text(text): return _compress_re.sub(" ", text.strip()) | ||
147 | 143 | |||
148 | 144 | def normalize_line_endings(text): | ||
149 | 145 | return re.sub(r"(?:(?<!\r)\n)|(?:\r(?!\n))", "\r\n", text) | ||
150 | 146 | |||
151 | 147 | |||
152 | 148 | # This version of urlencode is from my Python 1.5.2 back-port of the | ||
153 | 149 | # Python 2.1 CVS maintenance branch of urllib. It will accept a sequence | ||
154 | 150 | # of pairs instead of a mapping -- the 2.0 version only accepts a mapping. | ||
155 | 151 | def urlencode(query,doseq=False,): | ||
156 | 152 | """Encode a sequence of two-element tuples or dictionary into a URL query \ | ||
157 | 153 | string. | ||
158 | 154 | |||
159 | 155 | If any values in the query arg are sequences and doseq is true, each | ||
160 | 156 | sequence element is converted to a separate parameter. | ||
161 | 157 | |||
162 | 158 | If the query arg is a sequence of two-element tuples, the order of the | ||
163 | 159 | parameters in the output will match the order of parameters in the | ||
164 | 160 | input. | ||
165 | 161 | """ | ||
166 | 162 | |||
167 | 163 | if hasattr(query,"items"): | ||
168 | 164 | # mapping objects | ||
169 | 165 | query = query.items() | ||
170 | 166 | else: | ||
171 | 167 | # it's a bother at times that strings and string-like objects are | ||
172 | 168 | # sequences... | ||
173 | 169 | try: | ||
174 | 170 | # non-sequence items should not work with len() | ||
175 | 171 | x = len(query) | ||
176 | 172 | # non-empty strings will fail this | ||
177 | 173 | if len(query) and type(query[0]) != types.TupleType: | ||
178 | 174 | raise TypeError() | ||
179 | 175 | # zero-length sequences of all types will get here and succeed, | ||
180 | 176 | # but that's a minor nit - since the original implementation | ||
181 | 177 | # allowed empty dicts that type of behavior probably should be | ||
182 | 178 | # preserved for consistency | ||
183 | 179 | except TypeError: | ||
184 | 180 | ty,va,tb = sys.exc_info() | ||
185 | 181 | raise TypeError("not a valid non-string sequence or mapping " | ||
186 | 182 | "object", tb) | ||
187 | 183 | |||
188 | 184 | l = [] | ||
189 | 185 | if not doseq: | ||
190 | 186 | # preserve old behavior | ||
191 | 187 | for k, v in query: | ||
192 | 188 | k = urllib.quote_plus(str(k)) | ||
193 | 189 | v = urllib.quote_plus(str(v)) | ||
194 | 190 | l.append(k + '=' + v) | ||
195 | 191 | else: | ||
196 | 192 | for k, v in query: | ||
197 | 193 | k = urllib.quote_plus(str(k)) | ||
198 | 194 | if type(v) == types.StringType: | ||
199 | 195 | v = urllib.quote_plus(v) | ||
200 | 196 | l.append(k + '=' + v) | ||
201 | 197 | elif type(v) == types.UnicodeType: | ||
202 | 198 | # is there a reasonable way to convert to ASCII? | ||
203 | 199 | # encode generates a string, but "replace" or "ignore" | ||
204 | 200 | # lose information and "strict" can raise UnicodeError | ||
205 | 201 | v = urllib.quote_plus(v.encode("ASCII","replace")) | ||
206 | 202 | l.append(k + '=' + v) | ||
207 | 203 | else: | ||
208 | 204 | try: | ||
209 | 205 | # is this a sufficient test for sequence-ness? | ||
210 | 206 | x = len(v) | ||
211 | 207 | except TypeError: | ||
212 | 208 | # not a sequence | ||
213 | 209 | v = urllib.quote_plus(str(v)) | ||
214 | 210 | l.append(k + '=' + v) | ||
215 | 211 | else: | ||
216 | 212 | # loop over the sequence | ||
217 | 213 | for elt in v: | ||
218 | 214 | l.append(k + '=' + urllib.quote_plus(str(elt))) | ||
219 | 215 | return '&'.join(l) | ||
220 | 216 | |||
221 | 217 | def unescape(data, entities, encoding=DEFAULT_ENCODING): | ||
222 | 218 | if data is None or "&" not in data: | ||
223 | 219 | return data | ||
224 | 220 | |||
225 | 221 | def replace_entities(match, entities=entities, encoding=encoding): | ||
226 | 222 | ent = match.group() | ||
227 | 223 | if ent[1] == "#": | ||
228 | 224 | return unescape_charref(ent[2:-1], encoding) | ||
229 | 225 | |||
230 | 226 | repl = entities.get(ent) | ||
231 | 227 | if repl is not None: | ||
232 | 228 | if type(repl) != type(""): | ||
233 | 229 | try: | ||
234 | 230 | repl = repl.encode(encoding) | ||
235 | 231 | except UnicodeError: | ||
236 | 232 | repl = ent | ||
237 | 233 | else: | ||
238 | 234 | repl = ent | ||
239 | 235 | |||
240 | 236 | return repl | ||
241 | 237 | |||
242 | 238 | return re.sub(r"&#?[A-Za-z0-9]+?;", replace_entities, data) | ||
243 | 239 | |||
244 | 240 | def unescape_charref(data, encoding): | ||
245 | 241 | name, base = data, 10 | ||
246 | 242 | if name.startswith("x"): | ||
247 | 243 | name, base= name[1:], 16 | ||
248 | 244 | uc = unichr(int(name, base)) | ||
249 | 245 | if encoding is None: | ||
250 | 246 | return uc | ||
251 | 247 | else: | ||
252 | 248 | try: | ||
253 | 249 | repl = uc.encode(encoding) | ||
254 | 250 | except UnicodeError: | ||
255 | 251 | repl = "&#%s;" % data | ||
256 | 252 | return repl | ||
257 | 253 | |||
258 | 254 | def get_entitydefs(): | ||
259 | 255 | import htmlentitydefs | ||
260 | 256 | from codecs import latin_1_decode | ||
261 | 257 | entitydefs = {} | ||
262 | 258 | try: | ||
263 | 259 | htmlentitydefs.name2codepoint | ||
264 | 260 | except AttributeError: | ||
265 | 261 | entitydefs = {} | ||
266 | 262 | for name, char in htmlentitydefs.entitydefs.items(): | ||
267 | 263 | uc = latin_1_decode(char)[0] | ||
268 | 264 | if uc.startswith("&#") and uc.endswith(";"): | ||
269 | 265 | uc = unescape_charref(uc[2:-1], None) | ||
270 | 266 | entitydefs["&%s;" % name] = uc | ||
271 | 267 | else: | ||
272 | 268 | for name, codepoint in htmlentitydefs.name2codepoint.items(): | ||
273 | 269 | entitydefs["&%s;" % name] = unichr(codepoint) | ||
274 | 270 | return entitydefs | ||
275 | 271 | |||
276 | 272 | |||
277 | 273 | def issequence(x): | ||
278 | 274 | try: | ||
279 | 275 | x[0] | ||
280 | 276 | except (TypeError, KeyError): | ||
281 | 277 | return False | ||
282 | 278 | except IndexError: | ||
283 | 279 | pass | ||
284 | 280 | return True | ||
285 | 281 | |||
286 | 282 | def isstringlike(x): | ||
287 | 283 | try: x+"" | ||
288 | 284 | except: return False | ||
289 | 285 | else: return True | ||
290 | 286 | |||
291 | 287 | |||
292 | 288 | def choose_boundary(): | ||
293 | 289 | """Return a string usable as a multipart boundary.""" | ||
294 | 290 | # follow IE and firefox | ||
295 | 291 | nonce = "".join([str(random.randint(0, sys.maxint-1)) for i in 0,1,2]) | ||
296 | 292 | return "-"*27 + nonce | ||
297 | 293 | |||
298 | 294 | # This cut-n-pasted MimeWriter from standard library is here so can add | ||
299 | 295 | # to HTTP headers rather than message body when appropriate. It also uses | ||
300 | 296 | # \r\n in place of \n. This is a bit nasty. | ||
301 | 297 | class MimeWriter: | ||
302 | 298 | |||
303 | 299 | """Generic MIME writer. | ||
304 | 300 | |||
305 | 301 | Methods: | ||
306 | 302 | |||
307 | 303 | __init__() | ||
308 | 304 | addheader() | ||
309 | 305 | flushheaders() | ||
310 | 306 | startbody() | ||
311 | 307 | startmultipartbody() | ||
312 | 308 | nextpart() | ||
313 | 309 | lastpart() | ||
314 | 310 | |||
315 | 311 | A MIME writer is much more primitive than a MIME parser. It | ||
316 | 312 | doesn't seek around on the output file, and it doesn't use large | ||
317 | 313 | amounts of buffer space, so you have to write the parts in the | ||
318 | 314 | order they should occur on the output file. It does buffer the | ||
319 | 315 | headers you add, allowing you to rearrange their order. | ||
320 | 316 | |||
321 | 317 | General usage is: | ||
322 | 318 | |||
323 | 319 | f = <open the output file> | ||
324 | 320 | w = MimeWriter(f) | ||
325 | 321 | ...call w.addheader(key, value) 0 or more times... | ||
326 | 322 | |||
327 | 323 | followed by either: | ||
328 | 324 | |||
329 | 325 | f = w.startbody(content_type) | ||
330 | 326 | ...call f.write(data) for body data... | ||
331 | 327 | |||
332 | 328 | or: | ||
333 | 329 | |||
334 | 330 | w.startmultipartbody(subtype) | ||
335 | 331 | for each part: | ||
336 | 332 | subwriter = w.nextpart() | ||
337 | 333 | ...use the subwriter's methods to create the subpart... | ||
338 | 334 | w.lastpart() | ||
339 | 335 | |||
340 | 336 | The subwriter is another MimeWriter instance, and should be | ||
341 | 337 | treated in the same way as the toplevel MimeWriter. This way, | ||
342 | 338 | writing recursive body parts is easy. | ||
343 | 339 | |||
344 | 340 | Warning: don't forget to call lastpart()! | ||
345 | 341 | |||
346 | 342 | XXX There should be more state so calls made in the wrong order | ||
347 | 343 | are detected. | ||
348 | 344 | |||
349 | 345 | Some special cases: | ||
350 | 346 | |||
351 | 347 | - startbody() just returns the file passed to the constructor; | ||
352 | 348 | but don't use this knowledge, as it may be changed. | ||
353 | 349 | |||
354 | 350 | - startmultipartbody() actually returns a file as well; | ||
355 | 351 | this can be used to write the initial 'if you can read this your | ||
356 | 352 | mailer is not MIME-aware' message. | ||
357 | 353 | |||
358 | 354 | - If you call flushheaders(), the headers accumulated so far are | ||
359 | 355 | written out (and forgotten); this is useful if you don't need a | ||
360 | 356 | body part at all, e.g. for a subpart of type message/rfc822 | ||
361 | 357 | that's (mis)used to store some header-like information. | ||
362 | 358 | |||
363 | 359 | - Passing a keyword argument 'prefix=<flag>' to addheader(), | ||
364 | 360 | start*body() affects where the header is inserted; 0 means | ||
365 | 361 | append at the end, 1 means insert at the start; default is | ||
366 | 362 | append for addheader(), but insert for start*body(), which use | ||
367 | 363 | it to determine where the Content-type header goes. | ||
368 | 364 | |||
369 | 365 | """ | ||
370 | 366 | |||
371 | 367 | def __init__(self, fp, http_hdrs=None): | ||
372 | 368 | self._http_hdrs = http_hdrs | ||
373 | 369 | self._fp = fp | ||
374 | 370 | self._headers = [] | ||
375 | 371 | self._boundary = [] | ||
376 | 372 | self._first_part = True | ||
377 | 373 | |||
378 | 374 | def addheader(self, key, value, prefix=0, | ||
379 | 375 | add_to_http_hdrs=0): | ||
380 | 376 | """ | ||
381 | 377 | prefix is ignored if add_to_http_hdrs is true. | ||
382 | 378 | """ | ||
383 | 379 | lines = value.split("\r\n") | ||
384 | 380 | while lines and not lines[-1]: del lines[-1] | ||
385 | 381 | while lines and not lines[0]: del lines[0] | ||
386 | 382 | if add_to_http_hdrs: | ||
387 | 383 | value = "".join(lines) | ||
388 | 384 | # 2.2 urllib2 doesn't normalize header case | ||
389 | 385 | self._http_hdrs.append((key.capitalize(), value)) | ||
390 | 386 | else: | ||
391 | 387 | for i in range(1, len(lines)): | ||
392 | 388 | lines[i] = " " + lines[i].strip() | ||
393 | 389 | value = "\r\n".join(lines) + "\r\n" | ||
394 | 390 | line = key.title() + ": " + value | ||
395 | 391 | if prefix: | ||
396 | 392 | self._headers.insert(0, line) | ||
397 | 393 | else: | ||
398 | 394 | self._headers.append(line) | ||
399 | 395 | |||
400 | 396 | def flushheaders(self): | ||
401 | 397 | self._fp.writelines(self._headers) | ||
402 | 398 | self._headers = [] | ||
403 | 399 | |||
404 | 400 | def startbody(self, ctype=None, plist=[], prefix=1, | ||
405 | 401 | add_to_http_hdrs=0, content_type=1): | ||
406 | 402 | """ | ||
407 | 403 | prefix is ignored if add_to_http_hdrs is true. | ||
408 | 404 | """ | ||
409 | 405 | if content_type and ctype: | ||
410 | 406 | for name, value in plist: | ||
411 | 407 | ctype = ctype + ';\r\n %s=%s' % (name, value) | ||
412 | 408 | self.addheader("Content-Type", ctype, prefix=prefix, | ||
413 | 409 | add_to_http_hdrs=add_to_http_hdrs) | ||
414 | 410 | self.flushheaders() | ||
415 | 411 | if not add_to_http_hdrs: self._fp.write("\r\n") | ||
416 | 412 | self._first_part = True | ||
417 | 413 | return self._fp | ||
418 | 414 | |||
419 | 415 | def startmultipartbody(self, subtype, boundary=None, plist=[], prefix=1, | ||
420 | 416 | add_to_http_hdrs=0, content_type=1): | ||
421 | 417 | boundary = boundary or choose_boundary() | ||
422 | 418 | self._boundary.append(boundary) | ||
423 | 419 | return self.startbody("multipart/" + subtype, | ||
424 | 420 | [("boundary", boundary)] + plist, | ||
425 | 421 | prefix=prefix, | ||
426 | 422 | add_to_http_hdrs=add_to_http_hdrs, | ||
427 | 423 | content_type=content_type) | ||
428 | 424 | |||
429 | 425 | def nextpart(self): | ||
430 | 426 | boundary = self._boundary[-1] | ||
431 | 427 | if self._first_part: | ||
432 | 428 | self._first_part = False | ||
433 | 429 | else: | ||
434 | 430 | self._fp.write("\r\n") | ||
435 | 431 | self._fp.write("--" + boundary + "\r\n") | ||
436 | 432 | return self.__class__(self._fp) | ||
437 | 433 | |||
438 | 434 | def lastpart(self): | ||
439 | 435 | if self._first_part: | ||
440 | 436 | self.nextpart() | ||
441 | 437 | boundary = self._boundary.pop() | ||
442 | 438 | self._fp.write("\r\n--" + boundary + "--\r\n") | ||
443 | 439 | |||
444 | 440 | |||
445 | 441 | class LocateError(ValueError): pass | ||
446 | 442 | class AmbiguityError(LocateError): pass | ||
447 | 443 | class ControlNotFoundError(LocateError): pass | ||
448 | 444 | class ItemNotFoundError(LocateError): pass | ||
449 | 445 | |||
450 | 446 | class ItemCountError(ValueError): pass | ||
451 | 447 | |||
452 | 448 | # for backwards compatibility, ParseError derives from exceptions that were | ||
453 | 449 | # raised by versions of ClientForm <= 0.2.5 | ||
454 | 450 | if HAVE_MODULE_HTMLPARSER: | ||
455 | 451 | SGMLLIB_PARSEERROR = sgmllib.SGMLParseError | ||
456 | 452 | class ParseError(sgmllib.SGMLParseError, | ||
457 | 453 | HTMLParser.HTMLParseError, | ||
458 | 454 | ): | ||
459 | 455 | pass | ||
460 | 456 | else: | ||
461 | 457 | if hasattr(sgmllib, "SGMLParseError"): | ||
462 | 458 | SGMLLIB_PARSEERROR = sgmllib.SGMLParseError | ||
463 | 459 | class ParseError(sgmllib.SGMLParseError): | ||
464 | 460 | pass | ||
465 | 461 | else: | ||
466 | 462 | SGMLLIB_PARSEERROR = RuntimeError | ||
467 | 463 | class ParseError(RuntimeError): | ||
468 | 464 | pass | ||
469 | 465 | |||
470 | 466 | |||
471 | 467 | class _AbstractFormParser: | ||
472 | 468 | """forms attribute contains HTMLForm instances on completion.""" | ||
473 | 469 | # thanks to Moshe Zadka for an example of sgmllib/htmllib usage | ||
474 | 470 | def __init__(self, entitydefs=None, encoding=DEFAULT_ENCODING): | ||
475 | 471 | if entitydefs is None: | ||
476 | 472 | entitydefs = get_entitydefs() | ||
477 | 473 | self._entitydefs = entitydefs | ||
478 | 474 | self._encoding = encoding | ||
479 | 475 | |||
480 | 476 | self.base = None | ||
481 | 477 | self.forms = [] | ||
482 | 478 | self.labels = [] | ||
483 | 479 | self._current_label = None | ||
484 | 480 | self._current_form = None | ||
485 | 481 | self._select = None | ||
486 | 482 | self._optgroup = None | ||
487 | 483 | self._option = None | ||
488 | 484 | self._textarea = None | ||
489 | 485 | |||
490 | 486 | # forms[0] will contain all controls that are outside of any form | ||
491 | 487 | # self._global_form is an alias for self.forms[0] | ||
492 | 488 | self._global_form = None | ||
493 | 489 | self.start_form([]) | ||
494 | 490 | self.end_form() | ||
495 | 491 | self._current_form = self._global_form = self.forms[0] | ||
496 | 492 | |||
497 | 493 | def do_base(self, attrs): | ||
498 | 494 | debug("%s", attrs) | ||
499 | 495 | for key, value in attrs: | ||
500 | 496 | if key == "href": | ||
501 | 497 | self.base = self.unescape_attr_if_required(value) | ||
502 | 498 | |||
503 | 499 | def end_body(self): | ||
504 | 500 | debug("") | ||
505 | 501 | if self._current_label is not None: | ||
506 | 502 | self.end_label() | ||
507 | 503 | if self._current_form is not self._global_form: | ||
508 | 504 | self.end_form() | ||
509 | 505 | |||
510 | 506 | def start_form(self, attrs): | ||
511 | 507 | debug("%s", attrs) | ||
512 | 508 | if self._current_form is not self._global_form: | ||
513 | 509 | raise ParseError("nested FORMs") | ||
514 | 510 | name = None | ||
515 | 511 | action = None | ||
516 | 512 | enctype = "application/x-www-form-urlencoded" | ||
517 | 513 | method = "GET" | ||
518 | 514 | d = {} | ||
519 | 515 | for key, value in attrs: | ||
520 | 516 | if key == "name": | ||
521 | 517 | name = self.unescape_attr_if_required(value) | ||
522 | 518 | elif key == "action": | ||
523 | 519 | action = self.unescape_attr_if_required(value) | ||
524 | 520 | elif key == "method": | ||
525 | 521 | method = self.unescape_attr_if_required(value.upper()) | ||
526 | 522 | elif key == "enctype": | ||
527 | 523 | enctype = self.unescape_attr_if_required(value.lower()) | ||
528 | 524 | d[key] = self.unescape_attr_if_required(value) | ||
529 | 525 | controls = [] | ||
530 | 526 | self._current_form = (name, action, method, enctype), d, controls | ||
531 | 527 | |||
532 | 528 | def end_form(self): | ||
533 | 529 | debug("") | ||
534 | 530 | if self._current_label is not None: | ||
535 | 531 | self.end_label() | ||
536 | 532 | if self._current_form is self._global_form: | ||
537 | 533 | raise ParseError("end of FORM before start") | ||
538 | 534 | self.forms.append(self._current_form) | ||
539 | 535 | self._current_form = self._global_form | ||
540 | 536 | |||
541 | 537 | def start_select(self, attrs): | ||
542 | 538 | debug("%s", attrs) | ||
543 | 539 | if self._select is not None: | ||
544 | 540 | raise ParseError("nested SELECTs") | ||
545 | 541 | if self._textarea is not None: | ||
546 | 542 | raise ParseError("SELECT inside TEXTAREA") | ||
547 | 543 | d = {} | ||
548 | 544 | for key, val in attrs: | ||
549 | 545 | d[key] = self.unescape_attr_if_required(val) | ||
550 | 546 | |||
551 | 547 | self._select = d | ||
552 | 548 | self._add_label(d) | ||
553 | 549 | |||
554 | 550 | self._append_select_control({"__select": d}) | ||
555 | 551 | |||
556 | 552 | def end_select(self): | ||
557 | 553 | debug("") | ||
558 | 554 | if self._select is None: | ||
559 | 555 | raise ParseError("end of SELECT before start") | ||
560 | 556 | |||
561 | 557 | if self._option is not None: | ||
562 | 558 | self._end_option() | ||
563 | 559 | |||
564 | 560 | self._select = None | ||
565 | 561 | |||
566 | 562 | def start_optgroup(self, attrs): | ||
567 | 563 | debug("%s", attrs) | ||
568 | 564 | if self._select is None: | ||
569 | 565 | raise ParseError("OPTGROUP outside of SELECT") | ||
570 | 566 | d = {} | ||
571 | 567 | for key, val in attrs: | ||
572 | 568 | d[key] = self.unescape_attr_if_required(val) | ||
573 | 569 | |||
574 | 570 | self._optgroup = d | ||
575 | 571 | |||
576 | 572 | def end_optgroup(self): | ||
577 | 573 | debug("") | ||
578 | 574 | if self._optgroup is None: | ||
579 | 575 | raise ParseError("end of OPTGROUP before start") | ||
580 | 576 | self._optgroup = None | ||
581 | 577 | |||
582 | 578 | def _start_option(self, attrs): | ||
583 | 579 | debug("%s", attrs) | ||
584 | 580 | if self._select is None: | ||
585 | 581 | raise ParseError("OPTION outside of SELECT") | ||
586 | 582 | if self._option is not None: | ||
587 | 583 | self._end_option() | ||
588 | 584 | |||
589 | 585 | d = {} | ||
590 | 586 | for key, val in attrs: | ||
591 | 587 | d[key] = self.unescape_attr_if_required(val) | ||
592 | 588 | |||
593 | 589 | self._option = {} | ||
594 | 590 | self._option.update(d) | ||
595 | 591 | if (self._optgroup and self._optgroup.has_key("disabled") and | ||
596 | 592 | not self._option.has_key("disabled")): | ||
597 | 593 | self._option["disabled"] = None | ||
598 | 594 | |||
599 | 595 | def _end_option(self): | ||
600 | 596 | debug("") | ||
601 | 597 | if self._option is None: | ||
602 | 598 | raise ParseError("end of OPTION before start") | ||
603 | 599 | |||
604 | 600 | contents = self._option.get("contents", "").strip() | ||
605 | 601 | self._option["contents"] = contents | ||
606 | 602 | if not self._option.has_key("value"): | ||
607 | 603 | self._option["value"] = contents | ||
608 | 604 | if not self._option.has_key("label"): | ||
609 | 605 | self._option["label"] = contents | ||
610 | 606 | # stuff dict of SELECT HTML attrs into a special private key | ||
611 | 607 | # (gets deleted again later) | ||
612 | 608 | self._option["__select"] = self._select | ||
613 | 609 | self._append_select_control(self._option) | ||
614 | 610 | self._option = None | ||
615 | 611 | |||
616 | 612 | def _append_select_control(self, attrs): | ||
617 | 613 | debug("%s", attrs) | ||
618 | 614 | controls = self._current_form[2] | ||
619 | 615 | name = self._select.get("name") | ||
620 | 616 | controls.append(("select", name, attrs)) | ||
621 | 617 | |||
622 | 618 | def start_textarea(self, attrs): | ||
623 | 619 | debug("%s", attrs) | ||
624 | 620 | if self._textarea is not None: | ||
625 | 621 | raise ParseError("nested TEXTAREAs") | ||
626 | 622 | if self._select is not None: | ||
627 | 623 | raise ParseError("TEXTAREA inside SELECT") | ||
628 | 624 | d = {} | ||
629 | 625 | for key, val in attrs: | ||
630 | 626 | d[key] = self.unescape_attr_if_required(val) | ||
631 | 627 | self._add_label(d) | ||
632 | 628 | |||
633 | 629 | self._textarea = d | ||
634 | 630 | |||
635 | 631 | def end_textarea(self): | ||
636 | 632 | debug("") | ||
637 | 633 | if self._textarea is None: | ||
638 | 634 | raise ParseError("end of TEXTAREA before start") | ||
639 | 635 | controls = self._current_form[2] | ||
640 | 636 | name = self._textarea.get("name") | ||
641 | 637 | controls.append(("textarea", name, self._textarea)) | ||
642 | 638 | self._textarea = None | ||
643 | 639 | |||
644 | 640 | def start_label(self, attrs): | ||
645 | 641 | debug("%s", attrs) | ||
646 | 642 | if self._current_label: | ||
647 | 643 | self.end_label() | ||
648 | 644 | d = {} | ||
649 | 645 | for key, val in attrs: | ||
650 | 646 | d[key] = self.unescape_attr_if_required(val) | ||
651 | 647 | taken = bool(d.get("for")) # empty id is invalid | ||
652 | 648 | d["__text"] = "" | ||
653 | 649 | d["__taken"] = taken | ||
654 | 650 | if taken: | ||
655 | 651 | self.labels.append(d) | ||
656 | 652 | self._current_label = d | ||
657 | 653 | |||
658 | 654 | def end_label(self): | ||
659 | 655 | debug("") | ||
660 | 656 | label = self._current_label | ||
661 | 657 | if label is None: | ||
662 | 658 | # something is ugly in the HTML, but we're ignoring it | ||
663 | 659 | return | ||
664 | 660 | self._current_label = None | ||
665 | 661 | # if it is staying around, it is True in all cases | ||
666 | 662 | del label["__taken"] | ||
667 | 663 | |||
668 | 664 | def _add_label(self, d): | ||
669 | 665 | #debug("%s", d) | ||
670 | 666 | if self._current_label is not None: | ||
671 | 667 | if not self._current_label["__taken"]: | ||
672 | 668 | self._current_label["__taken"] = True | ||
673 | 669 | d["__label"] = self._current_label | ||
674 | 670 | |||
675 | 671 | def handle_data(self, data): | ||
676 | 672 | debug("%s", data) | ||
677 | 673 | |||
678 | 674 | if self._option is not None: | ||
679 | 675 | # self._option is a dictionary of the OPTION element's HTML | ||
680 | 676 | # attributes, but it has two special keys, one of which is the | ||
681 | 677 | # special "contents" key contains text between OPTION tags (the | ||
682 | 678 | # other is the "__select" key: see the end_option method) | ||
683 | 679 | map = self._option | ||
684 | 680 | key = "contents" | ||
685 | 681 | elif self._textarea is not None: | ||
686 | 682 | map = self._textarea | ||
687 | 683 | key = "value" | ||
688 | 684 | data = normalize_line_endings(data) | ||
689 | 685 | # not if within option or textarea | ||
690 | 686 | elif self._current_label is not None: | ||
691 | 687 | map = self._current_label | ||
692 | 688 | key = "__text" | ||
693 | 689 | else: | ||
694 | 690 | return | ||
695 | 691 | |||
696 | 692 | if data and not map.has_key(key): | ||
697 | 693 | # according to | ||
698 | 694 | # http://www.w3.org/TR/html4/appendix/notes.html#h-B.3.1 line break | ||
699 | 695 | # immediately after start tags or immediately before end tags must | ||
700 | 696 | # be ignored, but real browsers only ignore a line break after a | ||
701 | 697 | # start tag, so we'll do that. | ||
702 | 698 | if data[0:2] == "\r\n": | ||
703 | 699 | data = data[2:] | ||
704 | 700 | elif data[0:1] in ["\n", "\r"]: | ||
705 | 701 | data = data[1:] | ||
706 | 702 | map[key] = data | ||
707 | 703 | else: | ||
708 | 704 | map[key] = map[key] + data | ||
709 | 705 | |||
710 | 706 | def do_button(self, attrs): | ||
711 | 707 | debug("%s", attrs) | ||
712 | 708 | d = {} | ||
713 | 709 | d["type"] = "submit" # default | ||
714 | 710 | for key, val in attrs: | ||
715 | 711 | d[key] = self.unescape_attr_if_required(val) | ||
716 | 712 | controls = self._current_form[2] | ||
717 | 713 | |||
718 | 714 | type = d["type"] | ||
719 | 715 | name = d.get("name") | ||
720 | 716 | # we don't want to lose information, so use a type string that | ||
721 | 717 | # doesn't clash with INPUT TYPE={SUBMIT,RESET,BUTTON} | ||
722 | 718 | # e.g. type for BUTTON/RESET is "resetbutton" | ||
723 | 719 | # (type for INPUT/RESET is "reset") | ||
724 | 720 | type = type+"button" | ||
725 | 721 | self._add_label(d) | ||
726 | 722 | controls.append((type, name, d)) | ||
727 | 723 | |||
728 | 724 | def do_input(self, attrs): | ||
729 | 725 | debug("%s", attrs) | ||
730 | 726 | d = {} | ||
731 | 727 | d["type"] = "text" # default | ||
732 | 728 | for key, val in attrs: | ||
733 | 729 | d[key] = self.unescape_attr_if_required(val) | ||
734 | 730 | controls = self._current_form[2] | ||
735 | 731 | |||
736 | 732 | type = d["type"] | ||
737 | 733 | name = d.get("name") | ||
738 | 734 | self._add_label(d) | ||
739 | 735 | controls.append((type, name, d)) | ||
740 | 736 | |||
741 | 737 | def do_isindex(self, attrs): | ||
742 | 738 | debug("%s", attrs) | ||
743 | 739 | d = {} | ||
744 | 740 | for key, val in attrs: | ||
745 | 741 | d[key] = self.unescape_attr_if_required(val) | ||
746 | 742 | controls = self._current_form[2] | ||
747 | 743 | |||
748 | 744 | self._add_label(d) | ||
749 | 745 | # isindex doesn't have type or name HTML attributes | ||
750 | 746 | controls.append(("isindex", None, d)) | ||
751 | 747 | |||
752 | 748 | def handle_entityref(self, name): | ||
753 | 749 | #debug("%s", name) | ||
754 | 750 | self.handle_data(unescape( | ||
755 | 751 | '&%s;' % name, self._entitydefs, self._encoding)) | ||
756 | 752 | |||
757 | 753 | def handle_charref(self, name): | ||
758 | 754 | #debug("%s", name) | ||
759 | 755 | self.handle_data(unescape_charref(name, self._encoding)) | ||
760 | 756 | |||
761 | 757 | def unescape_attr(self, name): | ||
762 | 758 | #debug("%s", name) | ||
763 | 759 | return unescape(name, self._entitydefs, self._encoding) | ||
764 | 760 | |||
765 | 761 | def unescape_attrs(self, attrs): | ||
766 | 762 | #debug("%s", attrs) | ||
767 | 763 | escaped_attrs = {} | ||
768 | 764 | for key, val in attrs.items(): | ||
769 | 765 | try: | ||
770 | 766 | val.items | ||
771 | 767 | except AttributeError: | ||
772 | 768 | escaped_attrs[key] = self.unescape_attr(val) | ||
773 | 769 | else: | ||
774 | 770 | # e.g. "__select" -- yuck! | ||
775 | 771 | escaped_attrs[key] = self.unescape_attrs(val) | ||
776 | 772 | return escaped_attrs | ||
777 | 773 | |||
778 | 774 | def unknown_entityref(self, ref): self.handle_data("&%s;" % ref) | ||
779 | 775 | def unknown_charref(self, ref): self.handle_data("&#%s;" % ref) | ||
780 | 776 | |||
781 | 777 | |||
782 | 778 | if not HAVE_MODULE_HTMLPARSER: | ||
783 | 779 | class XHTMLCompatibleFormParser: | ||
784 | 780 | def __init__(self, entitydefs=None, encoding=DEFAULT_ENCODING): | ||
785 | 781 | raise ValueError("HTMLParser could not be imported") | ||
786 | 782 | else: | ||
787 | 783 | class XHTMLCompatibleFormParser(_AbstractFormParser, HTMLParser.HTMLParser): | ||
788 | 784 | """Good for XHTML, bad for tolerance of incorrect HTML.""" | ||
789 | 785 | # thanks to Michael Howitz for this! | ||
790 | 786 | def __init__(self, entitydefs=None, encoding=DEFAULT_ENCODING): | ||
791 | 787 | HTMLParser.HTMLParser.__init__(self) | ||
792 | 788 | _AbstractFormParser.__init__(self, entitydefs, encoding) | ||
793 | 789 | |||
794 | 790 | def feed(self, data): | ||
795 | 791 | try: | ||
796 | 792 | HTMLParser.HTMLParser.feed(self, data) | ||
797 | 793 | except HTMLParser.HTMLParseError, exc: | ||
798 | 794 | raise ParseError(exc) | ||
799 | 795 | |||
800 | 796 | def start_option(self, attrs): | ||
801 | 797 | _AbstractFormParser._start_option(self, attrs) | ||
802 | 798 | |||
803 | 799 | def end_option(self): | ||
804 | 800 | _AbstractFormParser._end_option(self) | ||
805 | 801 | |||
806 | 802 | def handle_starttag(self, tag, attrs): | ||
807 | 803 | try: | ||
808 | 804 | method = getattr(self, "start_" + tag) | ||
809 | 805 | except AttributeError: | ||
810 | 806 | try: | ||
811 | 807 | method = getattr(self, "do_" + tag) | ||
812 | 808 | except AttributeError: | ||
813 | 809 | pass # unknown tag | ||
814 | 810 | else: | ||
815 | 811 | method(attrs) | ||
816 | 812 | else: | ||
817 | 813 | method(attrs) | ||
818 | 814 | |||
819 | 815 | def handle_endtag(self, tag): | ||
820 | 816 | try: | ||
821 | 817 | method = getattr(self, "end_" + tag) | ||
822 | 818 | except AttributeError: | ||
823 | 819 | pass # unknown tag | ||
824 | 820 | else: | ||
825 | 821 | method() | ||
826 | 822 | |||
827 | 823 | def unescape(self, name): | ||
828 | 824 | # Use the entitydefs passed into constructor, not | ||
829 | 825 | # HTMLParser.HTMLParser's entitydefs. | ||
830 | 826 | return self.unescape_attr(name) | ||
831 | 827 | |||
832 | 828 | def unescape_attr_if_required(self, name): | ||
833 | 829 | return name # HTMLParser.HTMLParser already did it | ||
834 | 830 | def unescape_attrs_if_required(self, attrs): | ||
835 | 831 | return attrs # ditto | ||
836 | 832 | |||
837 | 833 | def close(self): | ||
838 | 834 | HTMLParser.HTMLParser.close(self) | ||
839 | 835 | self.end_body() | ||
840 | 836 | |||
841 | 837 | |||
842 | 838 | class _AbstractSgmllibParser(_AbstractFormParser): | ||
843 | 839 | |||
844 | 840 | def do_option(self, attrs): | ||
845 | 841 | _AbstractFormParser._start_option(self, attrs) | ||
846 | 842 | |||
847 | 843 | if sys.version_info[:2] >= (2,5): | ||
848 | 844 | # we override this attr to decode hex charrefs | ||
849 | 845 | entity_or_charref = re.compile( | ||
850 | 846 | '&(?:([a-zA-Z][-.a-zA-Z0-9]*)|#(x?[0-9a-fA-F]+))(;?)') | ||
851 | 847 | def convert_entityref(self, name): | ||
852 | 848 | return unescape("&%s;" % name, self._entitydefs, self._encoding) | ||
853 | 849 | def convert_charref(self, name): | ||
854 | 850 | return unescape_charref("%s" % name, self._encoding) | ||
855 | 851 | def unescape_attr_if_required(self, name): | ||
856 | 852 | return name # sgmllib already did it | ||
857 | 853 | def unescape_attrs_if_required(self, attrs): | ||
858 | 854 | return attrs # ditto | ||
859 | 855 | else: | ||
860 | 856 | def unescape_attr_if_required(self, name): | ||
861 | 857 | return self.unescape_attr(name) | ||
862 | 858 | def unescape_attrs_if_required(self, attrs): | ||
863 | 859 | return self.unescape_attrs(attrs) | ||
864 | 860 | |||
865 | 861 | |||
866 | 862 | class FormParser(_AbstractSgmllibParser, sgmllib.SGMLParser): | ||
867 | 863 | """Good for tolerance of incorrect HTML, bad for XHTML.""" | ||
868 | 864 | def __init__(self, entitydefs=None, encoding=DEFAULT_ENCODING): | ||
869 | 865 | sgmllib.SGMLParser.__init__(self) | ||
870 | 866 | _AbstractFormParser.__init__(self, entitydefs, encoding) | ||
871 | 867 | |||
872 | 868 | def feed(self, data): | ||
873 | 869 | try: | ||
874 | 870 | sgmllib.SGMLParser.feed(self, data) | ||
875 | 871 | except SGMLLIB_PARSEERROR, exc: | ||
876 | 872 | raise ParseError(exc) | ||
877 | 873 | |||
878 | 874 | def close(self): | ||
879 | 875 | sgmllib.SGMLParser.close(self) | ||
880 | 876 | self.end_body() | ||
881 | 877 | |||
882 | 878 | |||
883 | 879 | # sigh, must support mechanize by allowing dynamic creation of classes based on | ||
884 | 880 | # its bundled copy of BeautifulSoup (which was necessary because of dependency | ||
885 | 881 | # problems) | ||
886 | 882 | |||
887 | 883 | def _create_bs_classes(bs, | ||
888 | 884 | icbinbs, | ||
889 | 885 | ): | ||
890 | 886 | class _AbstractBSFormParser(_AbstractSgmllibParser): | ||
891 | 887 | bs_base_class = None | ||
892 | 888 | def __init__(self, entitydefs=None, encoding=DEFAULT_ENCODING): | ||
893 | 889 | _AbstractFormParser.__init__(self, entitydefs, encoding) | ||
894 | 890 | self.bs_base_class.__init__(self) | ||
895 | 891 | def handle_data(self, data): | ||
896 | 892 | _AbstractFormParser.handle_data(self, data) | ||
897 | 893 | self.bs_base_class.handle_data(self, data) | ||
898 | 894 | def feed(self, data): | ||
899 | 895 | try: | ||
900 | 896 | self.bs_base_class.feed(self, data) | ||
901 | 897 | except SGMLLIB_PARSEERROR, exc: | ||
902 | 898 | raise ParseError(exc) | ||
903 | 899 | def close(self): | ||
904 | 900 | self.bs_base_class.close(self) | ||
905 | 901 | self.end_body() | ||
906 | 902 | |||
907 | 903 | class RobustFormParser(_AbstractBSFormParser, bs): | ||
908 | 904 | """Tries to be highly tolerant of incorrect HTML.""" | ||
909 | 905 | pass | ||
910 | 906 | RobustFormParser.bs_base_class = bs | ||
911 | 907 | class NestingRobustFormParser(_AbstractBSFormParser, icbinbs): | ||
912 | 908 | """Tries to be highly tolerant of incorrect HTML. | ||
913 | 909 | |||
914 | 910 | Different from RobustFormParser in that it more often guesses nesting | ||
915 | 911 | above missing end tags (see BeautifulSoup docs). | ||
916 | 912 | |||
917 | 913 | """ | ||
918 | 914 | pass | ||
919 | 915 | NestingRobustFormParser.bs_base_class = icbinbs | ||
920 | 916 | |||
921 | 917 | return RobustFormParser, NestingRobustFormParser | ||
922 | 918 | |||
923 | 919 | try: | ||
924 | 920 | if sys.version_info[:2] < (2, 2): | ||
925 | 921 | raise ImportError # BeautifulSoup uses generators | ||
926 | 922 | import BeautifulSoup | ||
927 | 923 | except ImportError: | ||
928 | 924 | pass | ||
929 | 925 | else: | ||
930 | 926 | RobustFormParser, NestingRobustFormParser = _create_bs_classes( | ||
931 | 927 | BeautifulSoup.BeautifulSoup, BeautifulSoup.ICantBelieveItsBeautifulSoup | ||
932 | 928 | ) | ||
933 | 929 | __all__ += ['RobustFormParser', 'NestingRobustFormParser'] | ||
934 | 930 | |||
935 | 931 | |||
936 | 932 | #FormParser = XHTMLCompatibleFormParser # testing hack | ||
937 | 933 | #FormParser = RobustFormParser # testing hack | ||
938 | 934 | |||
939 | 935 | |||
940 | 936 | def ParseResponseEx(response, | ||
941 | 937 | select_default=False, | ||
942 | 938 | form_parser_class=FormParser, | ||
943 | 939 | request_class=urllib2.Request, | ||
944 | 940 | entitydefs=None, | ||
945 | 941 | encoding=DEFAULT_ENCODING, | ||
946 | 942 | |||
947 | 943 | # private | ||
948 | 944 | _urljoin=urlparse.urljoin, | ||
949 | 945 | _urlparse=urlparse.urlparse, | ||
950 | 946 | _urlunparse=urlparse.urlunparse, | ||
951 | 947 | ): | ||
952 | 948 | """Identical to ParseResponse, except that: | ||
953 | 949 | |||
954 | 950 | 1. The returned list contains an extra item. The first form in the list | ||
955 | 951 | contains all controls not contained in any FORM element. | ||
956 | 952 | |||
957 | 953 | 2. The arguments ignore_errors and backwards_compat have been removed. | ||
958 | 954 | |||
959 | 955 | 3. Backwards-compatibility mode (backwards_compat=True) is not available. | ||
960 | 956 | """ | ||
961 | 957 | return _ParseFileEx(response, response.geturl(), | ||
962 | 958 | select_default, | ||
963 | 959 | False, | ||
964 | 960 | form_parser_class, | ||
965 | 961 | request_class, | ||
966 | 962 | entitydefs, | ||
967 | 963 | False, | ||
968 | 964 | encoding, | ||
969 | 965 | _urljoin=_urljoin, | ||
970 | 966 | _urlparse=_urlparse, | ||
971 | 967 | _urlunparse=_urlunparse, | ||
972 | 968 | ) | ||
973 | 969 | |||
974 | 970 | def ParseFileEx(file, base_uri, | ||
975 | 971 | select_default=False, | ||
976 | 972 | form_parser_class=FormParser, | ||
977 | 973 | request_class=urllib2.Request, | ||
978 | 974 | entitydefs=None, | ||
979 | 975 | encoding=DEFAULT_ENCODING, | ||
980 | 976 | |||
981 | 977 | # private | ||
982 | 978 | _urljoin=urlparse.urljoin, | ||
983 | 979 | _urlparse=urlparse.urlparse, | ||
984 | 980 | _urlunparse=urlparse.urlunparse, | ||
985 | 981 | ): | ||
986 | 982 | """Identical to ParseFile, except that: | ||
987 | 983 | |||
988 | 984 | 1. The returned list contains an extra item. The first form in the list | ||
989 | 985 | contains all controls not contained in any FORM element. | ||
990 | 986 | |||
991 | 987 | 2. The arguments ignore_errors and backwards_compat have been removed. | ||
992 | 988 | |||
993 | 989 | 3. Backwards-compatibility mode (backwards_compat=True) is not available. | ||
994 | 990 | """ | ||
995 | 991 | return _ParseFileEx(file, base_uri, | ||
996 | 992 | select_default, | ||
997 | 993 | False, | ||
998 | 994 | form_parser_class, | ||
999 | 995 | request_class, | ||
1000 | 996 | entitydefs, | ||
1001 | 997 | False, | ||
1002 | 998 | encoding, | ||
1003 | 999 | _urljoin=_urljoin, | ||
1004 | 1000 | _urlparse=_urlparse, | ||
1005 | 1001 | _urlunparse=_urlunparse, | ||
1006 | 1002 | ) | ||
1007 | 1003 | |||
1008 | 1004 | def ParseResponse(response, *args, **kwds): | ||
1009 | 1005 | """Parse HTTP response and return a list of HTMLForm instances. | ||
1010 | 1006 | |||
1011 | 1007 | The return value of urllib2.urlopen can be conveniently passed to this | ||
1012 | 1008 | function as the response parameter. | ||
1013 | 1009 | |||
1014 | 1010 | ClientForm.ParseError is raised on parse errors. | ||
1015 | 1011 | |||
1016 | 1012 | response: file-like object (supporting read() method) with a method | ||
1017 | 1013 | geturl(), returning the URI of the HTTP response | ||
1018 | 1014 | select_default: for multiple-selection SELECT controls and RADIO controls, | ||
1019 | 1015 | pick the first item as the default if none are selected in the HTML | ||
1020 | 1016 | form_parser_class: class to instantiate and use to pass | ||
1021 | 1017 | request_class: class to return from .click() method (default is | ||
1022 | 1018 | urllib2.Request) | ||
1023 | 1019 | entitydefs: mapping like {"&": "&", ...} containing HTML entity | ||
1024 | 1020 | definitions (a sensible default is used) | ||
1025 | 1021 | encoding: character encoding used for encoding numeric character references | ||
1026 | 1022 | when matching link text. ClientForm does not attempt to find the encoding | ||
1027 | 1023 | in a META HTTP-EQUIV attribute in the document itself (mechanize, for | ||
1028 | 1024 | example, does do that and will pass the correct value to ClientForm using | ||
1029 | 1025 | this parameter). | ||
1030 | 1026 | |||
1031 | 1027 | backwards_compat: boolean that determines whether the returned HTMLForm | ||
1032 | 1028 | objects are backwards-compatible with old code. If backwards_compat is | ||
1033 | 1029 | true: | ||
1034 | 1030 | |||
1035 | 1031 | - ClientForm 0.1 code will continue to work as before. | ||
1036 | 1032 | |||
1037 | 1033 | - Label searches that do not specify a nr (number or count) will always | ||
1038 | 1034 | get the first match, even if other controls match. If | ||
1039 | 1035 | backwards_compat is False, label searches that have ambiguous results | ||
1040 | 1036 | will raise an AmbiguityError. | ||
1041 | 1037 | |||
1042 | 1038 | - Item label matching is done by strict string comparison rather than | ||
1043 | 1039 | substring matching. | ||
1044 | 1040 | |||
1045 | 1041 | - De-selecting individual list items is allowed even if the Item is | ||
1046 | 1042 | disabled. | ||
1047 | 1043 | |||
1048 | 1044 | The backwards_compat argument will be deprecated in a future release. | ||
1049 | 1045 | |||
1050 | 1046 | Pass a true value for select_default if you want the behaviour specified by | ||
1051 | 1047 | RFC 1866 (the HTML 2.0 standard), which is to select the first item in a | ||
1052 | 1048 | RADIO or multiple-selection SELECT control if none were selected in the | ||
1053 | 1049 | HTML. Most browsers (including Microsoft Internet Explorer (IE) and | ||
1054 | 1050 | Netscape Navigator) instead leave all items unselected in these cases. The | ||
1055 | 1051 | W3C HTML 4.0 standard leaves this behaviour undefined in the case of | ||
1056 | 1052 | multiple-selection SELECT controls, but insists that at least one RADIO | ||
1057 | 1053 | button should be checked at all times, in contradiction to browser | ||
1058 | 1054 | behaviour. | ||
1059 | 1055 | |||
1060 | 1056 | There is a choice of parsers. ClientForm.XHTMLCompatibleFormParser (uses | ||
1061 | 1057 | HTMLParser.HTMLParser) works best for XHTML, ClientForm.FormParser (uses | ||
1062 | 1058 | sgmllib.SGMLParser) (the default) works better for ordinary grubby HTML. | ||
1063 | 1059 | Note that HTMLParser is only available in Python 2.2 and later. You can | ||
1064 | 1060 | pass your own class in here as a hack to work around bad HTML, but at your | ||
1065 | 1061 | own risk: there is no well-defined interface. | ||
1066 | 1062 | |||
1067 | 1063 | """ | ||
1068 | 1064 | return _ParseFileEx(response, response.geturl(), *args, **kwds)[1:] | ||
1069 | 1065 | |||
1070 | 1066 | def ParseFile(file, base_uri, *args, **kwds): | ||
1071 | 1067 | """Parse HTML and return a list of HTMLForm instances. | ||
1072 | 1068 | |||
1073 | 1069 | ClientForm.ParseError is raised on parse errors. | ||
1074 | 1070 | |||
1075 | 1071 | file: file-like object (supporting read() method) containing HTML with zero | ||
1076 | 1072 | or more forms to be parsed | ||
1077 | 1073 | base_uri: the URI of the document (note that the base URI used to submit | ||
1078 | 1074 | the form will be that given in the BASE element if present, not that of | ||
1079 | 1075 | the document) | ||
1080 | 1076 | |||
1081 | 1077 | For the other arguments and further details, see ParseResponse.__doc__. | ||
1082 | 1078 | |||
1083 | 1079 | """ | ||
1084 | 1080 | return _ParseFileEx(file, base_uri, *args, **kwds)[1:] | ||
1085 | 1081 | |||
1086 | 1082 | def _ParseFileEx(file, base_uri, | ||
1087 | 1083 | select_default=False, | ||
1088 | 1084 | ignore_errors=False, | ||
1089 | 1085 | form_parser_class=FormParser, | ||
1090 | 1086 | request_class=urllib2.Request, | ||
1091 | 1087 | entitydefs=None, | ||
1092 | 1088 | backwards_compat=True, | ||
1093 | 1089 | encoding=DEFAULT_ENCODING, | ||
1094 | 1090 | _urljoin=urlparse.urljoin, | ||
1095 | 1091 | _urlparse=urlparse.urlparse, | ||
1096 | 1092 | _urlunparse=urlparse.urlunparse, | ||
1097 | 1093 | ): | ||
1098 | 1094 | if backwards_compat: | ||
1099 | 1095 | deprecation("operating in backwards-compatibility mode", 1) | ||
1100 | 1096 | fp = form_parser_class(entitydefs, encoding) | ||
1101 | 1097 | while 1: | ||
1102 | 1098 | data = file.read(CHUNK) | ||
1103 | 1099 | try: | ||
1104 | 1100 | fp.feed(data) | ||
1105 | 1101 | except ParseError, e: | ||
1106 | 1102 | e.base_uri = base_uri | ||
1107 | 1103 | raise | ||
1108 | 1104 | if len(data) != CHUNK: break | ||
1109 | 1105 | fp.close() | ||
1110 | 1106 | if fp.base is not None: | ||
1111 | 1107 | # HTML BASE element takes precedence over document URI | ||
1112 | 1108 | base_uri = fp.base | ||
1113 | 1109 | labels = [] # Label(label) for label in fp.labels] | ||
1114 | 1110 | id_to_labels = {} | ||
1115 | 1111 | for l in fp.labels: | ||
1116 | 1112 | label = Label(l) | ||
1117 | 1113 | labels.append(label) | ||
1118 | 1114 | for_id = l["for"] | ||
1119 | 1115 | coll = id_to_labels.get(for_id) | ||
1120 | 1116 | if coll is None: | ||
1121 | 1117 | id_to_labels[for_id] = [label] | ||
1122 | 1118 | else: | ||
1123 | 1119 | coll.append(label) | ||
1124 | 1120 | forms = [] | ||
1125 | 1121 | for (name, action, method, enctype), attrs, controls in fp.forms: | ||
1126 | 1122 | if action is None: | ||
1127 | 1123 | action = base_uri | ||
1128 | 1124 | else: | ||
1129 | 1125 | action = _urljoin(base_uri, action) | ||
1130 | 1126 | # would be nice to make HTMLForm class (form builder) pluggable | ||
1131 | 1127 | form = HTMLForm( | ||
1132 | 1128 | action, method, enctype, name, attrs, request_class, | ||
1133 | 1129 | forms, labels, id_to_labels, backwards_compat) | ||
1134 | 1130 | form._urlparse = _urlparse | ||
1135 | 1131 | form._urlunparse = _urlunparse | ||
1136 | 1132 | for ii in range(len(controls)): | ||
1137 | 1133 | type, name, attrs = controls[ii] | ||
1138 | 1134 | # index=ii*10 allows ImageControl to return multiple ordered pairs | ||
1139 | 1135 | form.new_control( | ||
1140 | 1136 | type, name, attrs, select_default=select_default, index=ii*10) | ||
1141 | 1137 | forms.append(form) | ||
1142 | 1138 | for form in forms: | ||
1143 | 1139 | form.fixup() | ||
1144 | 1140 | return forms | ||
1145 | 1141 | |||
1146 | 1142 | |||
1147 | 1143 | class Label: | ||
1148 | 1144 | def __init__(self, attrs): | ||
1149 | 1145 | self.id = attrs.get("for") | ||
1150 | 1146 | self._text = attrs.get("__text").strip() | ||
1151 | 1147 | self._ctext = compress_text(self._text) | ||
1152 | 1148 | self.attrs = attrs | ||
1153 | 1149 | self._backwards_compat = False # maintained by HTMLForm | ||
1154 | 1150 | |||
1155 | 1151 | def __getattr__(self, name): | ||
1156 | 1152 | if name == "text": | ||
1157 | 1153 | if self._backwards_compat: | ||
1158 | 1154 | return self._text | ||
1159 | 1155 | else: | ||
1160 | 1156 | return self._ctext | ||
1161 | 1157 | return getattr(Label, name) | ||
1162 | 1158 | |||
1163 | 1159 | def __setattr__(self, name, value): | ||
1164 | 1160 | if name == "text": | ||
1165 | 1161 | # don't see any need for this, so make it read-only | ||
1166 | 1162 | raise AttributeError("text attribute is read-only") | ||
1167 | 1163 | self.__dict__[name] = value | ||
1168 | 1164 | |||
1169 | 1165 | def __str__(self): | ||
1170 | 1166 | return "<Label(id=%r, text=%r)>" % (self.id, self.text) | ||
1171 | 1167 | |||
1172 | 1168 | |||
1173 | 1169 | def _get_label(attrs): | ||
1174 | 1170 | text = attrs.get("__label") | ||
1175 | 1171 | if text is not None: | ||
1176 | 1172 | return Label(text) | ||
1177 | 1173 | else: | ||
1178 | 1174 | return None | ||
1179 | 1175 | |||
1180 | 1176 | class Control: | ||
1181 | 1177 | """An HTML form control. | ||
1182 | 1178 | |||
1183 | 1179 | An HTMLForm contains a sequence of Controls. The Controls in an HTMLForm | ||
1184 | 1180 | are accessed using the HTMLForm.find_control method or the | ||
1185 | 1181 | HTMLForm.controls attribute. | ||
1186 | 1182 | |||
1187 | 1183 | Control instances are usually constructed using the ParseFile / | ||
1188 | 1184 | ParseResponse functions. If you use those functions, you can ignore the | ||
1189 | 1185 | rest of this paragraph. A Control is only properly initialised after the | ||
1190 | 1186 | fixup method has been called. In fact, this is only strictly necessary for | ||
1191 | 1187 | ListControl instances. This is necessary because ListControls are built up | ||
1192 | 1188 | from ListControls each containing only a single item, and their initial | ||
1193 | 1189 | value(s) can only be known after the sequence is complete. | ||
1194 | 1190 | |||
1195 | 1191 | The types and values that are acceptable for assignment to the value | ||
1196 | 1192 | attribute are defined by subclasses. | ||
1197 | 1193 | |||
1198 | 1194 | If the disabled attribute is true, this represents the state typically | ||
1199 | 1195 | represented by browsers by 'greying out' a control. If the disabled | ||
1200 | 1196 | attribute is true, the Control will raise AttributeError if an attempt is | ||
1201 | 1197 | made to change its value. In addition, the control will not be considered | ||
1202 | 1198 | 'successful' as defined by the W3C HTML 4 standard -- ie. it will | ||
1203 | 1199 | contribute no data to the return value of the HTMLForm.click* methods. To | ||
1204 | 1200 | enable a control, set the disabled attribute to a false value. | ||
1205 | 1201 | |||
1206 | 1202 | If the readonly attribute is true, the Control will raise AttributeError if | ||
1207 | 1203 | an attempt is made to change its value. To make a control writable, set | ||
1208 | 1204 | the readonly attribute to a false value. | ||
1209 | 1205 | |||
1210 | 1206 | All controls have the disabled and readonly attributes, not only those that | ||
1211 | 1207 | may have the HTML attributes of the same names. | ||
1212 | 1208 | |||
1213 | 1209 | On assignment to the value attribute, the following exceptions are raised: | ||
1214 | 1210 | TypeError, AttributeError (if the value attribute should not be assigned | ||
1215 | 1211 | to, because the control is disabled, for example) and ValueError. | ||
1216 | 1212 | |||
1217 | 1213 | If the name or value attributes are None, or the value is an empty list, or | ||
1218 | 1214 | if the control is disabled, the control is not successful. | ||
1219 | 1215 | |||
1220 | 1216 | Public attributes: | ||
1221 | 1217 | |||
1222 | 1218 | type: string describing type of control (see the keys of the | ||
1223 | 1219 | HTMLForm.type2class dictionary for the allowable values) (readonly) | ||
1224 | 1220 | name: name of control (readonly) | ||
1225 | 1221 | value: current value of control (subclasses may allow a single value, a | ||
1226 | 1222 | sequence of values, or either) | ||
1227 | 1223 | disabled: disabled state | ||
1228 | 1224 | readonly: readonly state | ||
1229 | 1225 | id: value of id HTML attribute | ||
1230 | 1226 | |||
1231 | 1227 | """ | ||
1232 | 1228 | def __init__(self, type, name, attrs, index=None): | ||
1233 | 1229 | """ | ||
1234 | 1230 | type: string describing type of control (see the keys of the | ||
1235 | 1231 | HTMLForm.type2class dictionary for the allowable values) | ||
1236 | 1232 | name: control name | ||
1237 | 1233 | attrs: HTML attributes of control's HTML element | ||
1238 | 1234 | |||
1239 | 1235 | """ | ||
1240 | 1236 | raise NotImplementedError() | ||
1241 | 1237 | |||
1242 | 1238 | def add_to_form(self, form): | ||
1243 | 1239 | self._form = form | ||
1244 | 1240 | form.controls.append(self) | ||
1245 | 1241 | |||
1246 | 1242 | def fixup(self): | ||
1247 | 1243 | pass | ||
1248 | 1244 | |||
1249 | 1245 | def is_of_kind(self, kind): | ||
1250 | 1246 | raise NotImplementedError() | ||
1251 | 1247 | |||
1252 | 1248 | def clear(self): | ||
1253 | 1249 | raise NotImplementedError() | ||
1254 | 1250 | |||
1255 | 1251 | def __getattr__(self, name): raise NotImplementedError() | ||
1256 | 1252 | def __setattr__(self, name, value): raise NotImplementedError() | ||
1257 | 1253 | |||
1258 | 1254 | def pairs(self): | ||
1259 | 1255 | """Return list of (key, value) pairs suitable for passing to urlencode. | ||
1260 | 1256 | """ | ||
1261 | 1257 | return [(k, v) for (i, k, v) in self._totally_ordered_pairs()] | ||
1262 | 1258 | |||
1263 | 1259 | def _totally_ordered_pairs(self): | ||
1264 | 1260 | """Return list of (key, value, index) tuples. | ||
1265 | 1261 | |||
1266 | 1262 | Like pairs, but allows preserving correct ordering even where several | ||
1267 | 1263 | controls are involved. | ||
1268 | 1264 | |||
1269 | 1265 | """ | ||
1270 | 1266 | raise NotImplementedError() | ||
1271 | 1267 | |||
1272 | 1268 | def _write_mime_data(self, mw, name, value): | ||
1273 | 1269 | """Write data for a subitem of this control to a MimeWriter.""" | ||
1274 | 1270 | # called by HTMLForm | ||
1275 | 1271 | mw2 = mw.nextpart() | ||
1276 | 1272 | mw2.addheader("Content-Disposition", | ||
1277 | 1273 | 'form-data; name="%s"' % name, 1) | ||
1278 | 1274 | f = mw2.startbody(prefix=0) | ||
1279 | 1275 | f.write(value) | ||
1280 | 1276 | |||
1281 | 1277 | def __str__(self): | ||
1282 | 1278 | raise NotImplementedError() | ||
1283 | 1279 | |||
1284 | 1280 | def get_labels(self): | ||
1285 | 1281 | """Return all labels (Label instances) for this control. | ||
1286 | 1282 | |||
1287 | 1283 | If the control was surrounded by a <label> tag, that will be the first | ||
1288 | 1284 | label; all other labels, connected by 'for' and 'id', are in the order | ||
1289 | 1285 | that appear in the HTML. | ||
1290 | 1286 | |||
1291 | 1287 | """ | ||
1292 | 1288 | res = [] | ||
1293 | 1289 | if self._label: | ||
1294 | 1290 | res.append(self._label) | ||
1295 | 1291 | if self.id: | ||
1296 | 1292 | res.extend(self._form._id_to_labels.get(self.id, ())) | ||
1297 | 1293 | return res | ||
1298 | 1294 | |||
1299 | 1295 | |||
1300 | 1296 | #--------------------------------------------------- | ||
1301 | 1297 | class ScalarControl(Control): | ||
1302 | 1298 | """Control whose value is not restricted to one of a prescribed set. | ||
1303 | 1299 | |||
1304 | 1300 | Some ScalarControls don't accept any value attribute. Otherwise, takes a | ||
1305 | 1301 | single value, which must be string-like. | ||
1306 | 1302 | |||
1307 | 1303 | Additional read-only public attribute: | ||
1308 | 1304 | |||
1309 | 1305 | attrs: dictionary mapping the names of original HTML attributes of the | ||
1310 | 1306 | control to their values | ||
1311 | 1307 | |||
1312 | 1308 | """ | ||
1313 | 1309 | def __init__(self, type, name, attrs, index=None): | ||
1314 | 1310 | self._index = index | ||
1315 | 1311 | self._label = _get_label(attrs) | ||
1316 | 1312 | self.__dict__["type"] = type.lower() | ||
1317 | 1313 | self.__dict__["name"] = name | ||
1318 | 1314 | self._value = attrs.get("value") | ||
1319 | 1315 | self.disabled = attrs.has_key("disabled") | ||
1320 | 1316 | self.readonly = attrs.has_key("readonly") | ||
1321 | 1317 | self.id = attrs.get("id") | ||
1322 | 1318 | |||
1323 | 1319 | self.attrs = attrs.copy() | ||
1324 | 1320 | |||
1325 | 1321 | self._clicked = False | ||
1326 | 1322 | |||
1327 | 1323 | self._urlparse = urlparse.urlparse | ||
1328 | 1324 | self._urlunparse = urlparse.urlunparse | ||
1329 | 1325 | |||
1330 | 1326 | def __getattr__(self, name): | ||
1331 | 1327 | if name == "value": | ||
1332 | 1328 | return self.__dict__["_value"] | ||
1333 | 1329 | else: | ||
1334 | 1330 | raise AttributeError("%s instance has no attribute '%s'" % | ||
1335 | 1331 | (self.__class__.__name__, name)) | ||
1336 | 1332 | |||
1337 | 1333 | def __setattr__(self, name, value): | ||
1338 | 1334 | if name == "value": | ||
1339 | 1335 | if not isstringlike(value): | ||
1340 | 1336 | raise TypeError("must assign a string") | ||
1341 | 1337 | elif self.readonly: | ||
1342 | 1338 | raise AttributeError("control '%s' is readonly" % self.name) | ||
1343 | 1339 | elif self.disabled: | ||
1344 | 1340 | raise AttributeError("control '%s' is disabled" % self.name) | ||
1345 | 1341 | self.__dict__["_value"] = value | ||
1346 | 1342 | elif name in ("name", "type"): | ||
1347 | 1343 | raise AttributeError("%s attribute is readonly" % name) | ||
1348 | 1344 | else: | ||
1349 | 1345 | self.__dict__[name] = value | ||
1350 | 1346 | |||
1351 | 1347 | def _totally_ordered_pairs(self): | ||
1352 | 1348 | name = self.name | ||
1353 | 1349 | value = self.value | ||
1354 | 1350 | if name is None or value is None or self.disabled: | ||
1355 | 1351 | return [] | ||
1356 | 1352 | return [(self._index, name, value)] | ||
1357 | 1353 | |||
1358 | 1354 | def clear(self): | ||
1359 | 1355 | if self.readonly: | ||
1360 | 1356 | raise AttributeError("control '%s' is readonly" % self.name) | ||
1361 | 1357 | self.__dict__["_value"] = None | ||
1362 | 1358 | |||
1363 | 1359 | def __str__(self): | ||
1364 | 1360 | name = self.name | ||
1365 | 1361 | value = self.value | ||
1366 | 1362 | if name is None: name = "<None>" | ||
1367 | 1363 | if value is None: value = "<None>" | ||
1368 | 1364 | |||
1369 | 1365 | infos = [] | ||
1370 | 1366 | if self.disabled: infos.append("disabled") | ||
1371 | 1367 | if self.readonly: infos.append("readonly") | ||
1372 | 1368 | info = ", ".join(infos) | ||
1373 | 1369 | if info: info = " (%s)" % info | ||
1374 | 1370 | |||
1375 | 1371 | return "<%s(%s=%s)%s>" % (self.__class__.__name__, name, value, info) | ||
1376 | 1372 | |||
1377 | 1373 | |||
1378 | 1374 | #--------------------------------------------------- | ||
1379 | 1375 | class TextControl(ScalarControl): | ||
1380 | 1376 | """Textual input control. | ||
1381 | 1377 | |||
1382 | 1378 | Covers: | ||
1383 | 1379 | |||
1384 | 1380 | INPUT/TEXT | ||
1385 | 1381 | INPUT/PASSWORD | ||
1386 | 1382 | INPUT/HIDDEN | ||
1387 | 1383 | TEXTAREA | ||
1388 | 1384 | |||
1389 | 1385 | """ | ||
1390 | 1386 | def __init__(self, type, name, attrs, index=None): | ||
1391 | 1387 | ScalarControl.__init__(self, type, name, attrs, index) | ||
1392 | 1388 | if self.type == "hidden": self.readonly = True | ||
1393 | 1389 | if self._value is None: | ||
1394 | 1390 | self._value = "" | ||
1395 | 1391 | |||
1396 | 1392 | def is_of_kind(self, kind): return kind == "text" | ||
1397 | 1393 | |||
1398 | 1394 | #--------------------------------------------------- | ||
1399 | 1395 | class FileControl(ScalarControl): | ||
1400 | 1396 | """File upload with INPUT TYPE=FILE. | ||
1401 | 1397 | |||
1402 | 1398 | The value attribute of a FileControl is always None. Use add_file instead. | ||
1403 | 1399 | |||
1404 | 1400 | Additional public method: add_file | ||
1405 | 1401 | |||
1406 | 1402 | """ | ||
1407 | 1403 | |||
1408 | 1404 | def __init__(self, type, name, attrs, index=None): | ||
1409 | 1405 | ScalarControl.__init__(self, type, name, attrs, index) | ||
1410 | 1406 | self._value = None | ||
1411 | 1407 | self._upload_data = [] | ||
1412 | 1408 | |||
1413 | 1409 | def is_of_kind(self, kind): return kind == "file" | ||
1414 | 1410 | |||
1415 | 1411 | def clear(self): | ||
1416 | 1412 | if self.readonly: | ||
1417 | 1413 | raise AttributeError("control '%s' is readonly" % self.name) | ||
1418 | 1414 | self._upload_data = [] | ||
1419 | 1415 | |||
1420 | 1416 | def __setattr__(self, name, value): | ||
1421 | 1417 | if name in ("value", "name", "type"): | ||
1422 | 1418 | raise AttributeError("%s attribute is readonly" % name) | ||
1423 | 1419 | else: | ||
1424 | 1420 | self.__dict__[name] = value | ||
1425 | 1421 | |||
1426 | 1422 | def add_file(self, file_object, content_type=None, filename=None): | ||
1427 | 1423 | if not hasattr(file_object, "read"): | ||
1428 | 1424 | raise TypeError("file-like object must have read method") | ||
1429 | 1425 | if content_type is not None and not isstringlike(content_type): | ||
1430 | 1426 | raise TypeError("content type must be None or string-like") | ||
1431 | 1427 | if filename is not None and not isstringlike(filename): | ||
1432 | 1428 | raise TypeError("filename must be None or string-like") | ||
1433 | 1429 | if content_type is None: | ||
1434 | 1430 | content_type = "application/octet-stream" | ||
1435 | 1431 | self._upload_data.append((file_object, content_type, filename)) | ||
1436 | 1432 | |||
1437 | 1433 | def _totally_ordered_pairs(self): | ||
1438 | 1434 | # XXX should it be successful even if unnamed? | ||
1439 | 1435 | if self.name is None or self.disabled: | ||
1440 | 1436 | return [] | ||
1441 | 1437 | return [(self._index, self.name, "")] | ||
1442 | 1438 | |||
1443 | 1439 | def _write_mime_data(self, mw, _name, _value): | ||
1444 | 1440 | # called by HTMLForm | ||
1445 | 1441 | # assert _name == self.name and _value == '' | ||
1446 | 1442 | if len(self._upload_data) < 2: | ||
1447 | 1443 | if len(self._upload_data) == 0: | ||
1448 | 1444 | file_object = StringIO() | ||
1449 | 1445 | content_type = "application/octet-stream" | ||
1450 | 1446 | filename = "" | ||
1451 | 1447 | else: | ||
1452 | 1448 | file_object, content_type, filename = self._upload_data[0] | ||
1453 | 1449 | if filename is None: | ||
1454 | 1450 | filename = "" | ||
1455 | 1451 | mw2 = mw.nextpart() | ||
1456 | 1452 | fn_part = '; filename="%s"' % filename | ||
1457 | 1453 | disp = 'form-data; name="%s"%s' % (self.name, fn_part) | ||
1458 | 1454 | mw2.addheader("Content-Disposition", disp, prefix=1) | ||
1459 | 1455 | fh = mw2.startbody(content_type, prefix=0) | ||
1460 | 1456 | fh.write(file_object.read()) | ||
1461 | 1457 | else: | ||
1462 | 1458 | # multiple files | ||
1463 | 1459 | mw2 = mw.nextpart() | ||
1464 | 1460 | disp = 'form-data; name="%s"' % self.name | ||
1465 | 1461 | mw2.addheader("Content-Disposition", disp, prefix=1) | ||
1466 | 1462 | fh = mw2.startmultipartbody("mixed", prefix=0) | ||
1467 | 1463 | for file_object, content_type, filename in self._upload_data: | ||
1468 | 1464 | mw3 = mw2.nextpart() | ||
1469 | 1465 | if filename is None: | ||
1470 | 1466 | filename = "" | ||
1471 | 1467 | fn_part = '; filename="%s"' % filename | ||
1472 | 1468 | disp = "file%s" % fn_part | ||
1473 | 1469 | mw3.addheader("Content-Disposition", disp, prefix=1) | ||
1474 | 1470 | fh2 = mw3.startbody(content_type, prefix=0) | ||
1475 | 1471 | fh2.write(file_object.read()) | ||
1476 | 1472 | mw2.lastpart() | ||
1477 | 1473 | |||
1478 | 1474 | def __str__(self): | ||
1479 | 1475 | name = self.name | ||
1480 | 1476 | if name is None: name = "<None>" | ||
1481 | 1477 | |||
1482 | 1478 | if not self._upload_data: | ||
1483 | 1479 | value = "<No files added>" | ||
1484 | 1480 | else: | ||
1485 | 1481 | value = [] | ||
1486 | 1482 | for file, ctype, filename in self._upload_data: | ||
1487 | 1483 | if filename is None: | ||
1488 | 1484 | value.append("<Unnamed file>") | ||
1489 | 1485 | else: | ||
1490 | 1486 | value.append(filename) | ||
1491 | 1487 | value = ", ".join(value) | ||
1492 | 1488 | |||
1493 | 1489 | info = [] | ||
1494 | 1490 | if self.disabled: info.append("disabled") | ||
1495 | 1491 | if self.readonly: info.append("readonly") | ||
1496 | 1492 | info = ", ".join(info) | ||
1497 | 1493 | if info: info = " (%s)" % info | ||
1498 | 1494 | |||
1499 | 1495 | return "<%s(%s=%s)%s>" % (self.__class__.__name__, name, value, info) | ||
1500 | 1496 | |||
1501 | 1497 | |||
1502 | 1498 | #--------------------------------------------------- | ||
1503 | 1499 | class IsindexControl(ScalarControl): | ||
1504 | 1500 | """ISINDEX control. | ||
1505 | 1501 | |||
1506 | 1502 | ISINDEX is the odd-one-out of HTML form controls. In fact, it isn't really | ||
1507 | 1503 | part of regular HTML forms at all, and predates it. You're only allowed | ||
1508 | 1504 | one ISINDEX per HTML document. ISINDEX and regular form submission are | ||
1509 | 1505 | mutually exclusive -- either submit a form, or the ISINDEX. | ||
1510 | 1506 | |||
1511 | 1507 | Having said this, since ISINDEX controls may appear in forms (which is | ||
1512 | 1508 | probably bad HTML), ParseFile / ParseResponse will include them in the | ||
1513 | 1509 | HTMLForm instances it returns. You can set the ISINDEX's value, as with | ||
1514 | 1510 | any other control (but note that ISINDEX controls have no name, so you'll | ||
1515 | 1511 | need to use the type argument of set_value!). When you submit the form, | ||
1516 | 1512 | the ISINDEX will not be successful (ie., no data will get returned to the | ||
1517 | 1513 | server as a result of its presence), unless you click on the ISINDEX | ||
1518 | 1514 | control, in which case the ISINDEX gets submitted instead of the form: | ||
1519 | 1515 | |||
1520 | 1516 | form.set_value("my isindex value", type="isindex") | ||
1521 | 1517 | urllib2.urlopen(form.click(type="isindex")) | ||
1522 | 1518 | |||
1523 | 1519 | ISINDEX elements outside of FORMs are ignored. If you want to submit one | ||
1524 | 1520 | by hand, do it like so: | ||
1525 | 1521 | |||
1526 | 1522 | url = urlparse.urljoin(page_uri, "?"+urllib.quote_plus("my isindex value")) | ||
1527 | 1523 | result = urllib2.urlopen(url) | ||
1528 | 1524 | |||
1529 | 1525 | """ | ||
1530 | 1526 | def __init__(self, type, name, attrs, index=None): | ||
1531 | 1527 | ScalarControl.__init__(self, type, name, attrs, index) | ||
1532 | 1528 | if self._value is None: | ||
1533 | 1529 | self._value = "" | ||
1534 | 1530 | |||
1535 | 1531 | def is_of_kind(self, kind): return kind in ["text", "clickable"] | ||
1536 | 1532 | |||
1537 | 1533 | def _totally_ordered_pairs(self): | ||
1538 | 1534 | return [] | ||
1539 | 1535 | |||
1540 | 1536 | def _click(self, form, coord, return_type, request_class=urllib2.Request): | ||
1541 | 1537 | # Relative URL for ISINDEX submission: instead of "foo=bar+baz", | ||
1542 | 1538 | # want "bar+baz". | ||
1543 | 1539 | # This doesn't seem to be specified in HTML 4.01 spec. (ISINDEX is | ||
1544 | 1540 | # deprecated in 4.01, but it should still say how to submit it). | ||
1545 | 1541 | # Submission of ISINDEX is explained in the HTML 3.2 spec, though. | ||
1546 | 1542 | parts = self._urlparse(form.action) | ||
1547 | 1543 | rest, (query, frag) = parts[:-2], parts[-2:] | ||
1548 | 1544 | parts = rest + (urllib.quote_plus(self.value), None) | ||
1549 | 1545 | url = self._urlunparse(parts) | ||
1550 | 1546 | req_data = url, None, [] | ||
1551 | 1547 | |||
1552 | 1548 | if return_type == "pairs": | ||
1553 | 1549 | return [] | ||
1554 | 1550 | elif return_type == "request_data": | ||
1555 | 1551 | return req_data | ||
1556 | 1552 | else: | ||
1557 | 1553 | return request_class(url) | ||
1558 | 1554 | |||
1559 | 1555 | def __str__(self): | ||
1560 | 1556 | value = self.value | ||
1561 | 1557 | if value is None: value = "<None>" | ||
1562 | 1558 | |||
1563 | 1559 | infos = [] | ||
1564 | 1560 | if self.disabled: infos.append("disabled") | ||
1565 | 1561 | if self.readonly: infos.append("readonly") | ||
1566 | 1562 | info = ", ".join(infos) | ||
1567 | 1563 | if info: info = " (%s)" % info | ||
1568 | 1564 | |||
1569 | 1565 | return "<%s(%s)%s>" % (self.__class__.__name__, value, info) | ||
1570 | 1566 | |||
1571 | 1567 | |||
1572 | 1568 | #--------------------------------------------------- | ||
1573 | 1569 | class IgnoreControl(ScalarControl): | ||
1574 | 1570 | """Control that we're not interested in. | ||
1575 | 1571 | |||
1576 | 1572 | Covers: | ||
1577 | 1573 | |||
1578 | 1574 | INPUT/RESET | ||
1579 | 1575 | BUTTON/RESET | ||
1580 | 1576 | INPUT/BUTTON | ||
1581 | 1577 | BUTTON/BUTTON | ||
1582 | 1578 | |||
1583 | 1579 | These controls are always unsuccessful, in the terminology of HTML 4 (ie. | ||
1584 | 1580 | they never require any information to be returned to the server). | ||
1585 | 1581 | |||
1586 | 1582 | BUTTON/BUTTON is used to generate events for script embedded in HTML. | ||
1587 | 1583 | |||
1588 | 1584 | The value attribute of IgnoreControl is always None. | ||
1589 | 1585 | |||
1590 | 1586 | """ | ||
1591 | 1587 | def __init__(self, type, name, attrs, index=None): | ||
1592 | 1588 | ScalarControl.__init__(self, type, name, attrs, index) | ||
1593 | 1589 | self._value = None | ||
1594 | 1590 | |||
1595 | 1591 | def is_of_kind(self, kind): return False | ||
1596 | 1592 | |||
1597 | 1593 | def __setattr__(self, name, value): | ||
1598 | 1594 | if name == "value": | ||
1599 | 1595 | raise AttributeError( | ||
1600 | 1596 | "control '%s' is ignored, hence read-only" % self.name) | ||
1601 | 1597 | elif name in ("name", "type"): | ||
1602 | 1598 | raise AttributeError("%s attribute is readonly" % name) | ||
1603 | 1599 | else: | ||
1604 | 1600 | self.__dict__[name] = value | ||
1605 | 1601 | |||
1606 | 1602 | |||
1607 | 1603 | #--------------------------------------------------- | ||
1608 | 1604 | # ListControls | ||
1609 | 1605 | |||
1610 | 1606 | # helpers and subsidiary classes | ||
1611 | 1607 | |||
1612 | 1608 | class Item: | ||
1613 | 1609 | def __init__(self, control, attrs, index=None): | ||
1614 | 1610 | label = _get_label(attrs) | ||
1615 | 1611 | self.__dict__.update({ | ||
1616 | 1612 | "name": attrs["value"], | ||
1617 | 1613 | "_labels": label and [label] or [], | ||
1618 | 1614 | "attrs": attrs, | ||
1619 | 1615 | "_control": control, | ||
1620 | 1616 | "disabled": attrs.has_key("disabled"), | ||
1621 | 1617 | "_selected": False, | ||
1622 | 1618 | "id": attrs.get("id"), | ||
1623 | 1619 | "_index": index, | ||
1624 | 1620 | }) | ||
1625 | 1621 | control.items.append(self) | ||
1626 | 1622 | |||
1627 | 1623 | def get_labels(self): | ||
1628 | 1624 | """Return all labels (Label instances) for this item. | ||
1629 | 1625 | |||
1630 | 1626 | For items that represent radio buttons or checkboxes, if the item was | ||
1631 | 1627 | surrounded by a <label> tag, that will be the first label; all other | ||
1632 | 1628 | labels, connected by 'for' and 'id', are in the order that appear in | ||
1633 | 1629 | the HTML. | ||
1634 | 1630 | |||
1635 | 1631 | For items that represent select options, if the option had a label | ||
1636 | 1632 | attribute, that will be the first label. If the option has contents | ||
1637 | 1633 | (text within the option tags) and it is not the same as the label | ||
1638 | 1634 | attribute (if any), that will be a label. There is nothing in the | ||
1639 | 1635 | spec to my knowledge that makes an option with an id unable to be the | ||
1640 | 1636 | target of a label's for attribute, so those are included, if any, for | ||
1641 | 1637 | the sake of consistency and completeness. | ||
1642 | 1638 | |||
1643 | 1639 | """ | ||
1644 | 1640 | res = [] | ||
1645 | 1641 | res.extend(self._labels) | ||
1646 | 1642 | if self.id: | ||
1647 | 1643 | res.extend(self._control._form._id_to_labels.get(self.id, ())) | ||
1648 | 1644 | return res | ||
1649 | 1645 | |||
1650 | 1646 | def __getattr__(self, name): | ||
1651 | 1647 | if name=="selected": | ||
1652 | 1648 | return self._selected | ||
1653 | 1649 | raise AttributeError(name) | ||
1654 | 1650 | |||
1655 | 1651 | def __setattr__(self, name, value): | ||
1656 | 1652 | if name == "selected": | ||
1657 | 1653 | self._control._set_selected_state(self, value) | ||
1658 | 1654 | elif name == "disabled": | ||
1659 | 1655 | self.__dict__["disabled"] = bool(value) | ||
1660 | 1656 | else: | ||
1661 | 1657 | raise AttributeError(name) | ||
1662 | 1658 | |||
1663 | 1659 | def __str__(self): | ||
1664 | 1660 | res = self.name | ||
1665 | 1661 | if self.selected: | ||
1666 | 1662 | res = "*" + res | ||
1667 | 1663 | if self.disabled: | ||
1668 | 1664 | res = "(%s)" % res | ||
1669 | 1665 | return res | ||
1670 | 1666 | |||
1671 | 1667 | def __repr__(self): | ||
1672 | 1668 | # XXX appending the attrs without distinguishing them from name and id | ||
1673 | 1669 | # is silly | ||
1674 | 1670 | attrs = [("name", self.name), ("id", self.id)]+self.attrs.items() | ||
1675 | 1671 | return "<%s %s>" % ( | ||
1676 | 1672 | self.__class__.__name__, | ||
1677 | 1673 | " ".join(["%s=%r" % (k, v) for k, v in attrs]) | ||
1678 | 1674 | ) | ||
1679 | 1675 | |||
1680 | 1676 | def disambiguate(items, nr, **kwds): | ||
1681 | 1677 | msgs = [] | ||
1682 | 1678 | for key, value in kwds.items(): | ||
1683 | 1679 | msgs.append("%s=%r" % (key, value)) | ||
1684 | 1680 | msg = " ".join(msgs) | ||
1685 | 1681 | if not items: | ||
1686 | 1682 | raise ItemNotFoundError(msg) | ||
1687 | 1683 | if nr is None: | ||
1688 | 1684 | if len(items) > 1: | ||
1689 | 1685 | raise AmbiguityError(msg) | ||
1690 | 1686 | nr = 0 | ||
1691 | 1687 | if len(items) <= nr: | ||
1692 | 1688 | raise ItemNotFoundError(msg) | ||
1693 | 1689 | return items[nr] | ||
1694 | 1690 | |||
1695 | 1691 | class ListControl(Control): | ||
1696 | 1692 | """Control representing a sequence of items. | ||
1697 | 1693 | |||
1698 | 1694 | The value attribute of a ListControl represents the successful list items | ||
1699 | 1695 | in the control. The successful list items are those that are selected and | ||
1700 | 1696 | not disabled. | ||
1701 | 1697 | |||
1702 | 1698 | ListControl implements both list controls that take a length-1 value | ||
1703 | 1699 | (single-selection) and those that take length >1 values | ||
1704 | 1700 | (multiple-selection). | ||
1705 | 1701 | |||
1706 | 1702 | ListControls accept sequence values only. Some controls only accept | ||
1707 | 1703 | sequences of length 0 or 1 (RADIO, and single-selection SELECT). | ||
1708 | 1704 | In those cases, ItemCountError is raised if len(sequence) > 1. CHECKBOXes | ||
1709 | 1705 | and multiple-selection SELECTs (those having the "multiple" HTML attribute) | ||
1710 | 1706 | accept sequences of any length. | ||
1711 | 1707 | |||
1712 | 1708 | Note the following mistake: | ||
1713 | 1709 | |||
1714 | 1710 | control.value = some_value | ||
1715 | 1711 | assert control.value == some_value # not necessarily true | ||
1716 | 1712 | |||
1717 | 1713 | The reason for this is that the value attribute always gives the list items | ||
1718 | 1714 | in the order they were listed in the HTML. | ||
1719 | 1715 | |||
1720 | 1716 | ListControl items can also be referred to by their labels instead of names. | ||
1721 | 1717 | Use the label argument to .get(), and the .set_value_by_label(), | ||
1722 | 1718 | .get_value_by_label() methods. | ||
1723 | 1719 | |||
1724 | 1720 | Note that, rather confusingly, though SELECT controls are represented in | ||
1725 | 1721 | HTML by SELECT elements (which contain OPTION elements, representing | ||
1726 | 1722 | individual list items), CHECKBOXes and RADIOs are not represented by *any* | ||
1727 | 1723 | element. Instead, those controls are represented by a collection of INPUT | ||
1728 | 1724 | elements. For example, this is a SELECT control, named "control1": | ||
1729 | 1725 | |||
1730 | 1726 | <select name="control1"> | ||
1731 | 1727 | <option>foo</option> | ||
1732 | 1728 | <option value="1">bar</option> | ||
1733 | 1729 | </select> | ||
1734 | 1730 | |||
1735 | 1731 | and this is a CHECKBOX control, named "control2": | ||
1736 | 1732 | |||
1737 | 1733 | <input type="checkbox" name="control2" value="foo" id="cbe1"> | ||
1738 | 1734 | <input type="checkbox" name="control2" value="bar" id="cbe2"> | ||
1739 | 1735 | |||
1740 | 1736 | The id attribute of a CHECKBOX or RADIO ListControl is always that of its | ||
1741 | 1737 | first element (for example, "cbe1" above). | ||
1742 | 1738 | |||
1743 | 1739 | |||
1744 | 1740 | Additional read-only public attribute: multiple. | ||
1745 | 1741 | |||
1746 | 1742 | """ | ||
1747 | 1743 | |||
1748 | 1744 | # ListControls are built up by the parser from their component items by | ||
1749 | 1745 | # creating one ListControl per item, consolidating them into a single | ||
1750 | 1746 | # master ListControl held by the HTMLForm: | ||
1751 | 1747 | |||
1752 | 1748 | # -User calls form.new_control(...) | ||
1753 | 1749 | # -Form creates Control, and calls control.add_to_form(self). | ||
1754 | 1750 | # -Control looks for a Control with the same name and type in the form, | ||
1755 | 1751 | # and if it finds one, merges itself with that control by calling | ||
1756 | 1752 | # control.merge_control(self). The first Control added to the form, of | ||
1757 | 1753 | # a particular name and type, is the only one that survives in the | ||
1758 | 1754 | # form. | ||
1759 | 1755 | # -Form calls control.fixup for all its controls. ListControls in the | ||
1760 | 1756 | # form know they can now safely pick their default values. | ||
1761 | 1757 | |||
1762 | 1758 | # To create a ListControl without an HTMLForm, use: | ||
1763 | 1759 | |||
1764 | 1760 | # control.merge_control(new_control) | ||
1765 | 1761 | |||
1766 | 1762 | # (actually, it's much easier just to use ParseFile) | ||
1767 | 1763 | |||
1768 | 1764 | _label = None | ||
1769 | 1765 | |||
1770 | 1766 | def __init__(self, type, name, attrs={}, select_default=False, | ||
1771 | 1767 | called_as_base_class=False, index=None): | ||
1772 | 1768 | """ | ||
1773 | 1769 | select_default: for RADIO and multiple-selection SELECT controls, pick | ||
1774 | 1770 | the first item as the default if no 'selected' HTML attribute is | ||
1775 | 1771 | present | ||
1776 | 1772 | |||
1777 | 1773 | """ | ||
1778 | 1774 | if not called_as_base_class: | ||
1779 | 1775 | raise NotImplementedError() | ||
1780 | 1776 | |||
1781 | 1777 | self.__dict__["type"] = type.lower() | ||
1782 | 1778 | self.__dict__["name"] = name | ||
1783 | 1779 | self._value = attrs.get("value") | ||
1784 | 1780 | self.disabled = False | ||
1785 | 1781 | self.readonly = False | ||
1786 | 1782 | self.id = attrs.get("id") | ||
1787 | 1783 | self._closed = False | ||
1788 | 1784 | |||
1789 | 1785 | # As Controls are merged in with .merge_control(), self.attrs will | ||
1790 | 1786 | # refer to each Control in turn -- always the most recently merged | ||
1791 | 1787 | # control. Each merged-in Control instance corresponds to a single | ||
1792 | 1788 | # list item: see ListControl.__doc__. | ||
1793 | 1789 | self.items = [] | ||
1794 | 1790 | self._form = None | ||
1795 | 1791 | |||
1796 | 1792 | self._select_default = select_default | ||
1797 | 1793 | self._clicked = False | ||
1798 | 1794 | |||
1799 | 1795 | def clear(self): | ||
1800 | 1796 | self.value = [] | ||
1801 | 1797 | |||
1802 | 1798 | def is_of_kind(self, kind): | ||
1803 | 1799 | if kind == "list": | ||
1804 | 1800 | return True | ||
1805 | 1801 | elif kind == "multilist": | ||
1806 | 1802 | return bool(self.multiple) | ||
1807 | 1803 | elif kind == "singlelist": | ||
1808 | 1804 | return not self.multiple | ||
1809 | 1805 | else: | ||
1810 | 1806 | return False | ||
1811 | 1807 | |||
1812 | 1808 | def get_items(self, name=None, label=None, id=None, | ||
1813 | 1809 | exclude_disabled=False): | ||
1814 | 1810 | """Return matching items by name or label. | ||
1815 | 1811 | |||
1816 | 1812 | For argument docs, see the docstring for .get() | ||
1817 | 1813 | |||
1818 | 1814 | """ | ||
1819 | 1815 | if name is not None and not isstringlike(name): | ||
1820 | 1816 | raise TypeError("item name must be string-like") | ||
1821 | 1817 | if label is not None and not isstringlike(label): | ||
1822 | 1818 | raise TypeError("item label must be string-like") | ||
1823 | 1819 | if id is not None and not isstringlike(id): | ||
1824 | 1820 | raise TypeError("item id must be string-like") | ||
1825 | 1821 | items = [] # order is important | ||
1826 | 1822 | compat = self._form.backwards_compat | ||
1827 | 1823 | for o in self.items: | ||
1828 | 1824 | if exclude_disabled and o.disabled: | ||
1829 | 1825 | continue | ||
1830 | 1826 | if name is not None and o.name != name: | ||
1831 | 1827 | continue | ||
1832 | 1828 | if label is not None: | ||
1833 | 1829 | for l in o.get_labels(): | ||
1834 | 1830 | if ((compat and l.text == label) or | ||
1835 | 1831 | (not compat and l.text.find(label) > -1)): | ||
1836 | 1832 | break | ||
1837 | 1833 | else: | ||
1838 | 1834 | continue | ||
1839 | 1835 | if id is not None and o.id != id: | ||
1840 | 1836 | continue | ||
1841 | 1837 | items.append(o) | ||
1842 | 1838 | return items | ||
1843 | 1839 | |||
1844 | 1840 | def get(self, name=None, label=None, id=None, nr=None, | ||
1845 | 1841 | exclude_disabled=False): | ||
1846 | 1842 | """Return item by name or label, disambiguating if necessary with nr. | ||
1847 | 1843 | |||
1848 | 1844 | All arguments must be passed by name, with the exception of 'name', | ||
1849 | 1845 | which may be used as a positional argument. | ||
1850 | 1846 | |||
1851 | 1847 | If name is specified, then the item must have the indicated name. | ||
1852 | 1848 | |||
1853 | 1849 | If label is specified, then the item must have a label whose | ||
1854 | 1850 | whitespace-compressed, stripped, text substring-matches the indicated | ||
1855 | 1851 | label string (eg. label="please choose" will match | ||
1856 | 1852 | " Do please choose an item "). | ||
1857 | 1853 | |||
1858 | 1854 | If id is specified, then the item must have the indicated id. | ||
1859 | 1855 | |||
1860 | 1856 | nr is an optional 0-based index of the items matching the query. | ||
1861 | 1857 | |||
1862 | 1858 | If nr is the default None value and more than item is found, raises | ||
1863 | 1859 | AmbiguityError (unless the HTMLForm instance's backwards_compat | ||
1864 | 1860 | attribute is true). | ||
1865 | 1861 | |||
1866 | 1862 | If no item is found, or if items are found but nr is specified and not | ||
1867 | 1863 | found, raises ItemNotFoundError. | ||
1868 | 1864 | |||
1869 | 1865 | Optionally excludes disabled items. | ||
1870 | 1866 | |||
1871 | 1867 | """ | ||
1872 | 1868 | if nr is None and self._form.backwards_compat: | ||
1873 | 1869 | nr = 0 # :-/ | ||
1874 | 1870 | items = self.get_items(name, label, id, exclude_disabled) | ||
1875 | 1871 | return disambiguate(items, nr, name=name, label=label, id=id) | ||
1876 | 1872 | |||
1877 | 1873 | def _get(self, name, by_label=False, nr=None, exclude_disabled=False): | ||
1878 | 1874 | # strictly for use by deprecated methods | ||
1879 | 1875 | if by_label: | ||
1880 | 1876 | name, label = None, name | ||
1881 | 1877 | else: | ||
1882 | 1878 | name, label = name, None | ||
1883 | 1879 | return self.get(name, label, nr, exclude_disabled) | ||
1884 | 1880 | |||
1885 | 1881 | def toggle(self, name, by_label=False, nr=None): | ||
1886 | 1882 | """Deprecated: given a name or label and optional disambiguating index | ||
1887 | 1883 | nr, toggle the matching item's selection. | ||
1888 | 1884 | |||
1889 | 1885 | Selecting items follows the behavior described in the docstring of the | ||
1890 | 1886 | 'get' method. | ||
1891 | 1887 | |||
1892 | 1888 | if the item is disabled, or this control is disabled or readonly, | ||
1893 | 1889 | raise AttributeError. | ||
1894 | 1890 | |||
1895 | 1891 | """ | ||
1896 | 1892 | deprecation( | ||
1897 | 1893 | "item = control.get(...); item.selected = not item.selected") | ||
1898 | 1894 | o = self._get(name, by_label, nr) | ||
1899 | 1895 | self._set_selected_state(o, not o.selected) | ||
1900 | 1896 | |||
1901 | 1897 | def set(self, selected, name, by_label=False, nr=None): | ||
1902 | 1898 | """Deprecated: given a name or label and optional disambiguating index | ||
1903 | 1899 | nr, set the matching item's selection to the bool value of selected. | ||
1904 | 1900 | |||
1905 | 1901 | Selecting items follows the behavior described in the docstring of the | ||
1906 | 1902 | 'get' method. | ||
1907 | 1903 | |||
1908 | 1904 | if the item is disabled, or this control is disabled or readonly, | ||
1909 | 1905 | raise AttributeError. | ||
1910 | 1906 | |||
1911 | 1907 | """ | ||
1912 | 1908 | deprecation( | ||
1913 | 1909 | "control.get(...).selected = <boolean>") | ||
1914 | 1910 | self._set_selected_state(self._get(name, by_label, nr), selected) | ||
1915 | 1911 | |||
1916 | 1912 | def _set_selected_state(self, item, action): | ||
1917 | 1913 | # action: | ||
1918 | 1914 | # bool False: off | ||
1919 | 1915 | # bool True: on | ||
1920 | 1916 | if self.disabled: | ||
1921 | 1917 | raise AttributeError("control '%s' is disabled" % self.name) | ||
1922 | 1918 | if self.readonly: | ||
1923 | 1919 | raise AttributeError("control '%s' is readonly" % self.name) | ||
1924 | 1920 | action == bool(action) | ||
1925 | 1921 | compat = self._form.backwards_compat | ||
1926 | 1922 | if not compat and item.disabled: | ||
1927 | 1923 | raise AttributeError("item is disabled") | ||
1928 | 1924 | else: | ||
1929 | 1925 | if compat and item.disabled and action: | ||
1930 | 1926 | raise AttributeError("item is disabled") | ||
1931 | 1927 | if self.multiple: | ||
1932 | 1928 | item.__dict__["_selected"] = action | ||
1933 | 1929 | else: | ||
1934 | 1930 | if not action: | ||
1935 | 1931 | item.__dict__["_selected"] = False | ||
1936 | 1932 | else: | ||
1937 | 1933 | for o in self.items: | ||
1938 | 1934 | o.__dict__["_selected"] = False | ||
1939 | 1935 | item.__dict__["_selected"] = True | ||
1940 | 1936 | |||
1941 | 1937 | def toggle_single(self, by_label=None): | ||
1942 | 1938 | """Deprecated: toggle the selection of the single item in this control. | ||
1943 | 1939 | |||
1944 | 1940 | Raises ItemCountError if the control does not contain only one item. | ||
1945 | 1941 | |||
1946 | 1942 | by_label argument is ignored, and included only for backwards | ||
1947 | 1943 | compatibility. | ||
1948 | 1944 | |||
1949 | 1945 | """ | ||
1950 | 1946 | deprecation( | ||
1951 | 1947 | "control.items[0].selected = not control.items[0].selected") | ||
1952 | 1948 | if len(self.items) != 1: | ||
1953 | 1949 | raise ItemCountError( | ||
1954 | 1950 | "'%s' is not a single-item control" % self.name) | ||
1955 | 1951 | item = self.items[0] | ||
1956 | 1952 | self._set_selected_state(item, not item.selected) | ||
1957 | 1953 | |||
1958 | 1954 | def set_single(self, selected, by_label=None): | ||
1959 | 1955 | """Deprecated: set the selection of the single item in this control. | ||
1960 | 1956 | |||
1961 | 1957 | Raises ItemCountError if the control does not contain only one item. | ||
1962 | 1958 | |||
1963 | 1959 | by_label argument is ignored, and included only for backwards | ||
1964 | 1960 | compatibility. | ||
1965 | 1961 | |||
1966 | 1962 | """ | ||
1967 | 1963 | deprecation( | ||
1968 | 1964 | "control.items[0].selected = <boolean>") | ||
1969 | 1965 | if len(self.items) != 1: | ||
1970 | 1966 | raise ItemCountError( | ||
1971 | 1967 | "'%s' is not a single-item control" % self.name) | ||
1972 | 1968 | self._set_selected_state(self.items[0], selected) | ||
1973 | 1969 | |||
1974 | 1970 | def get_item_disabled(self, name, by_label=False, nr=None): | ||
1975 | 1971 | """Get disabled state of named list item in a ListControl.""" | ||
1976 | 1972 | deprecation( | ||
1977 | 1973 | "control.get(...).disabled") | ||
1978 | 1974 | return self._get(name, by_label, nr).disabled | ||
1979 | 1975 | |||
1980 | 1976 | def set_item_disabled(self, disabled, name, by_label=False, nr=None): | ||
1981 | 1977 | """Set disabled state of named list item in a ListControl. | ||
1982 | 1978 | |||
1983 | 1979 | disabled: boolean disabled state | ||
1984 | 1980 | |||
1985 | 1981 | """ | ||
1986 | 1982 | deprecation( | ||
1987 | 1983 | "control.get(...).disabled = <boolean>") | ||
1988 | 1984 | self._get(name, by_label, nr).disabled = disabled | ||
1989 | 1985 | |||
1990 | 1986 | def set_all_items_disabled(self, disabled): | ||
1991 | 1987 | """Set disabled state of all list items in a ListControl. | ||
1992 | 1988 | |||
1993 | 1989 | disabled: boolean disabled state | ||
1994 | 1990 | |||
1995 | 1991 | """ | ||
1996 | 1992 | for o in self.items: | ||
1997 | 1993 | o.disabled = disabled | ||
1998 | 1994 | |||
1999 | 1995 | def get_item_attrs(self, name, by_label=False, nr=None): | ||
2000 | 1996 | """Return dictionary of HTML attributes for a single ListControl item. | ||
2001 | 1997 | |||
2002 | 1998 | The HTML element types that describe list items are: OPTION for SELECT | ||
2003 | 1999 | controls, INPUT for the rest. These elements have HTML attributes that | ||
2004 | 2000 | you may occasionally want to know about -- for example, the "alt" HTML | ||
2005 | 2001 | attribute gives a text string describing the item (graphical browsers | ||
2006 | 2002 | usually display this as a tooltip). | ||
2007 | 2003 | |||
2008 | 2004 | The returned dictionary maps HTML attribute names to values. The names | ||
2009 | 2005 | and values are taken from the original HTML. | ||
2010 | 2006 | |||
2011 | 2007 | """ | ||
2012 | 2008 | deprecation( | ||
2013 | 2009 | "control.get(...).attrs") | ||
2014 | 2010 | return self._get(name, by_label, nr).attrs | ||
2015 | 2011 | |||
2016 | 2012 | def close_control(self): | ||
2017 | 2013 | self._closed = True | ||
2018 | 2014 | |||
2019 | 2015 | def add_to_form(self, form): | ||
2020 | 2016 | assert self._form is None or form == self._form, ( | ||
2021 | 2017 | "can't add control to more than one form") | ||
2022 | 2018 | self._form = form | ||
2023 | 2019 | if self.name is None: | ||
2024 | 2020 | # always count nameless elements as separate controls | ||
2025 | 2021 | Control.add_to_form(self, form) | ||
2026 | 2022 | else: | ||
2027 | 2023 | for ii in range(len(form.controls)-1, -1, -1): | ||
2028 | 2024 | control = form.controls[ii] | ||
2029 | 2025 | if control.name == self.name and control.type == self.type: | ||
2030 | 2026 | if control._closed: | ||
2031 | 2027 | Control.add_to_form(self, form) | ||
2032 | 2028 | else: | ||
2033 | 2029 | control.merge_control(self) | ||
2034 | 2030 | break | ||
2035 | 2031 | else: | ||
2036 | 2032 | Control.add_to_form(self, form) | ||
2037 | 2033 | |||
2038 | 2034 | def merge_control(self, control): | ||
2039 | 2035 | assert bool(control.multiple) == bool(self.multiple) | ||
2040 | 2036 | # usually, isinstance(control, self.__class__) | ||
2041 | 2037 | self.items.extend(control.items) | ||
2042 | 2038 | |||
2043 | 2039 | def fixup(self): | ||
2044 | 2040 | """ | ||
2045 | 2041 | ListControls are built up from component list items (which are also | ||
2046 | 2042 | ListControls) during parsing. This method should be called after all | ||
2047 | 2043 | items have been added. See ListControl.__doc__ for the reason this is | ||
2048 | 2044 | required. | ||
2049 | 2045 | |||
2050 | 2046 | """ | ||
2051 | 2047 | # Need to set default selection where no item was indicated as being | ||
2052 | 2048 | # selected by the HTML: | ||
2053 | 2049 | |||
2054 | 2050 | # CHECKBOX: | ||
2055 | 2051 | # Nothing should be selected. | ||
2056 | 2052 | # SELECT/single, SELECT/multiple and RADIO: | ||
2057 | 2053 | # RFC 1866 (HTML 2.0): says first item should be selected. | ||
2058 | 2054 | # W3C HTML 4.01 Specification: says that client behaviour is | ||
2059 | 2055 | # undefined in this case. For RADIO, exactly one must be selected, | ||
2060 | 2056 | # though which one is undefined. | ||
2061 | 2057 | # Both Netscape and Microsoft Internet Explorer (IE) choose first | ||
2062 | 2058 | # item for SELECT/single. However, both IE5 and Mozilla (both 1.0 | ||
2063 | 2059 | # and Firebird 0.6) leave all items unselected for RADIO and | ||
2064 | 2060 | # SELECT/multiple. | ||
2065 | 2061 | |||
2066 | 2062 | # Since both Netscape and IE all choose the first item for | ||
2067 | 2063 | # SELECT/single, we do the same. OTOH, both Netscape and IE | ||
2068 | 2064 | # leave SELECT/multiple with nothing selected, in violation of RFC 1866 | ||
2069 | 2065 | # (but not in violation of the W3C HTML 4 standard); the same is true | ||
2070 | 2066 | # of RADIO (which *is* in violation of the HTML 4 standard). We follow | ||
2071 | 2067 | # RFC 1866 if the _select_default attribute is set, and Netscape and IE | ||
2072 | 2068 | # otherwise. RFC 1866 and HTML 4 are always violated insofar as you | ||
2073 | 2069 | # can deselect all items in a RadioControl. | ||
2074 | 2070 | |||
2075 | 2071 | for o in self.items: | ||
2076 | 2072 | # set items' controls to self, now that we've merged | ||
2077 | 2073 | o.__dict__["_control"] = self | ||
2078 | 2074 | |||
2079 | 2075 | def __getattr__(self, name): | ||
2080 | 2076 | if name == "value": | ||
2081 | 2077 | compat = self._form.backwards_compat | ||
2082 | 2078 | if self.name is None: | ||
2083 | 2079 | return [] | ||
2084 | 2080 | return [o.name for o in self.items if o.selected and | ||
2085 | 2081 | (not o.disabled or compat)] | ||
2086 | 2082 | else: | ||
2087 | 2083 | raise AttributeError("%s instance has no attribute '%s'" % | ||
2088 | 2084 | (self.__class__.__name__, name)) | ||
2089 | 2085 | |||
2090 | 2086 | def __setattr__(self, name, value): | ||
2091 | 2087 | if name == "value": | ||
2092 | 2088 | if self.disabled: | ||
2093 | 2089 | raise AttributeError("control '%s' is disabled" % self.name) | ||
2094 | 2090 | if self.readonly: | ||
2095 | 2091 | raise AttributeError("control '%s' is readonly" % self.name) | ||
2096 | 2092 | self._set_value(value) | ||
2097 | 2093 | elif name in ("name", "type", "multiple"): | ||
2098 | 2094 | raise AttributeError("%s attribute is readonly" % name) | ||
2099 | 2095 | else: | ||
2100 | 2096 | self.__dict__[name] = value | ||
2101 | 2097 | |||
2102 | 2098 | def _set_value(self, value): | ||
2103 | 2099 | if value is None or isstringlike(value): | ||
2104 | 2100 | raise TypeError("ListControl, must set a sequence") | ||
2105 | 2101 | if not value: | ||
2106 | 2102 | compat = self._form.backwards_compat | ||
2107 | 2103 | for o in self.items: | ||
2108 | 2104 | if not o.disabled or compat: | ||
2109 | 2105 | o.selected = False | ||
2110 | 2106 | elif self.multiple: | ||
2111 | 2107 | self._multiple_set_value(value) | ||
2112 | 2108 | elif len(value) > 1: | ||
2113 | 2109 | raise ItemCountError( | ||
2114 | 2110 | "single selection list, must set sequence of " | ||
2115 | 2111 | "length 0 or 1") | ||
2116 | 2112 | else: | ||
2117 | 2113 | self._single_set_value(value) | ||
2118 | 2114 | |||
2119 | 2115 | def _get_items(self, name, target=1): | ||
2120 | 2116 | all_items = self.get_items(name) | ||
2121 | 2117 | items = [o for o in all_items if not o.disabled] | ||
2122 | 2118 | if len(items) < target: | ||
2123 | 2119 | if len(all_items) < target: | ||
2124 | 2120 | raise ItemNotFoundError( | ||
2125 | 2121 | "insufficient items with name %r" % name) | ||
2126 | 2122 | else: | ||
2127 | 2123 | raise AttributeError( | ||
2128 | 2124 | "insufficient non-disabled items with name %s" % name) | ||
2129 | 2125 | on = [] | ||
2130 | 2126 | off = [] | ||
2131 | 2127 | for o in items: | ||
2132 | 2128 | if o.selected: | ||
2133 | 2129 | on.append(o) | ||
2134 | 2130 | else: | ||
2135 | 2131 | off.append(o) | ||
2136 | 2132 | return on, off | ||
2137 | 2133 | |||
2138 | 2134 | def _single_set_value(self, value): | ||
2139 | 2135 | assert len(value) == 1 | ||
2140 | 2136 | on, off = self._get_items(value[0]) | ||
2141 | 2137 | assert len(on) <= 1 | ||
2142 | 2138 | if not on: | ||
2143 | 2139 | off[0].selected = True | ||
2144 | 2140 | |||
2145 | 2141 | def _multiple_set_value(self, value): | ||
2146 | 2142 | compat = self._form.backwards_compat | ||
2147 | 2143 | turn_on = [] # transactional-ish | ||
2148 | 2144 | turn_off = [item for item in self.items if | ||
2149 | 2145 | item.selected and (not item.disabled or compat)] | ||
2150 | 2146 | names = {} | ||
2151 | 2147 | for nn in value: | ||
2152 | 2148 | if nn in names.keys(): | ||
2153 | 2149 | names[nn] += 1 | ||
2154 | 2150 | else: | ||
2155 | 2151 | names[nn] = 1 | ||
2156 | 2152 | for name, count in names.items(): | ||
2157 | 2153 | on, off = self._get_items(name, count) | ||
2158 | 2154 | for i in range(count): | ||
2159 | 2155 | if on: | ||
2160 | 2156 | item = on[0] | ||
2161 | 2157 | del on[0] | ||
2162 | 2158 | del turn_off[turn_off.index(item)] | ||
2163 | 2159 | else: | ||
2164 | 2160 | item = off[0] | ||
2165 | 2161 | del off[0] | ||
2166 | 2162 | turn_on.append(item) | ||
2167 | 2163 | for item in turn_off: | ||
2168 | 2164 | item.selected = False | ||
2169 | 2165 | for item in turn_on: | ||
2170 | 2166 | item.selected = True | ||
2171 | 2167 | |||
2172 | 2168 | def set_value_by_label(self, value): | ||
2173 | 2169 | """Set the value of control by item labels. | ||
2174 | 2170 | |||
2175 | 2171 | value is expected to be an iterable of strings that are substrings of | ||
2176 | 2172 | the item labels that should be selected. Before substring matching is | ||
2177 | 2173 | performed, the original label text is whitespace-compressed | ||
2178 | 2174 | (consecutive whitespace characters are converted to a single space | ||
2179 | 2175 | character) and leading and trailing whitespace is stripped. Ambiguous | ||
2180 | 2176 | labels are accepted without complaint if the form's backwards_compat is | ||
2181 | 2177 | True; otherwise, it will not complain as long as all ambiguous labels | ||
2182 | 2178 | share the same item name (e.g. OPTION value). | ||
2183 | 2179 | |||
2184 | 2180 | """ | ||
2185 | 2181 | if isstringlike(value): | ||
2186 | 2182 | raise TypeError(value) | ||
2187 | 2183 | if not self.multiple and len(value) > 1: | ||
2188 | 2184 | raise ItemCountError( | ||
2189 | 2185 | "single selection list, must set sequence of " | ||
2190 | 2186 | "length 0 or 1") | ||
2191 | 2187 | items = [] | ||
2192 | 2188 | for nn in value: | ||
2193 | 2189 | found = self.get_items(label=nn) | ||
2194 | 2190 | if len(found) > 1: | ||
2195 | 2191 | if not self._form.backwards_compat: | ||
2196 | 2192 | # ambiguous labels are fine as long as item names (e.g. | ||
2197 | 2193 | # OPTION values) are same | ||
2198 | 2194 | opt_name = found[0].name | ||
2199 | 2195 | if [o for o in found[1:] if o.name != opt_name]: | ||
2200 | 2196 | raise AmbiguityError(nn) | ||
2201 | 2197 | else: | ||
2202 | 2198 | # OK, we'll guess :-( Assume first available item. | ||
2203 | 2199 | found = found[:1] | ||
2204 | 2200 | for o in found: | ||
2205 | 2201 | # For the multiple-item case, we could try to be smarter, | ||
2206 | 2202 | # saving them up and trying to resolve, but that's too much. | ||
2207 | 2203 | if self._form.backwards_compat or o not in items: | ||
2208 | 2204 | items.append(o) | ||
2209 | 2205 | break | ||
2210 | 2206 | else: # all of them are used | ||
2211 | 2207 | raise ItemNotFoundError(nn) | ||
2212 | 2208 | # now we have all the items that should be on | ||
2213 | 2209 | # let's just turn everything off and then back on. | ||
2214 | 2210 | self.value = [] | ||
2215 | 2211 | for o in items: | ||
2216 | 2212 | o.selected = True | ||
2217 | 2213 | |||
2218 | 2214 | def get_value_by_label(self): | ||
2219 | 2215 | """Return the value of the control as given by normalized labels.""" | ||
2220 | 2216 | res = [] | ||
2221 | 2217 | compat = self._form.backwards_compat | ||
2222 | 2218 | for o in self.items: | ||
2223 | 2219 | if (not o.disabled or compat) and o.selected: | ||
2224 | 2220 | for l in o.get_labels(): | ||
2225 | 2221 | if l.text: | ||
2226 | 2222 | res.append(l.text) | ||
2227 | 2223 | break | ||
2228 | 2224 | else: | ||
2229 | 2225 | res.append(None) | ||
2230 | 2226 | return res | ||
2231 | 2227 | |||
2232 | 2228 | def possible_items(self, by_label=False): | ||
2233 | 2229 | """Deprecated: return the names or labels of all possible items. | ||
2234 | 2230 | |||
2235 | 2231 | Includes disabled items, which may be misleading for some use cases. | ||
2236 | 2232 | |||
2237 | 2233 | """ | ||
2238 | 2234 | deprecation( | ||
2239 | 2235 | "[item.name for item in self.items]") | ||
2240 | 2236 | if by_label: | ||
2241 | 2237 | res = [] | ||
2242 | 2238 | for o in self.items: | ||
2243 | 2239 | for l in o.get_labels(): | ||
2244 | 2240 | if l.text: | ||
2245 | 2241 | res.append(l.text) | ||
2246 | 2242 | break | ||
2247 | 2243 | else: | ||
2248 | 2244 | res.append(None) | ||
2249 | 2245 | return res | ||
2250 | 2246 | return [o.name for o in self.items] | ||
2251 | 2247 | |||
2252 | 2248 | def _totally_ordered_pairs(self): | ||
2253 | 2249 | if self.disabled or self.name is None: | ||
2254 | 2250 | return [] | ||
2255 | 2251 | else: | ||
2256 | 2252 | return [(o._index, self.name, o.name) for o in self.items | ||
2257 | 2253 | if o.selected and not o.disabled] | ||
2258 | 2254 | |||
2259 | 2255 | def __str__(self): | ||
2260 | 2256 | name = self.name | ||
2261 | 2257 | if name is None: name = "<None>" | ||
2262 | 2258 | |||
2263 | 2259 | display = [str(o) for o in self.items] | ||
2264 | 2260 | |||
2265 | 2261 | infos = [] | ||
2266 | 2262 | if self.disabled: infos.append("disabled") | ||
2267 | 2263 | if self.readonly: infos.append("readonly") | ||
2268 | 2264 | info = ", ".join(infos) | ||
2269 | 2265 | if info: info = " (%s)" % info | ||
2270 | 2266 | |||
2271 | 2267 | return "<%s(%s=[%s])%s>" % (self.__class__.__name__, | ||
2272 | 2268 | name, ", ".join(display), info) | ||
2273 | 2269 | |||
2274 | 2270 | |||
2275 | 2271 | class RadioControl(ListControl): | ||
2276 | 2272 | """ | ||
2277 | 2273 | Covers: | ||
2278 | 2274 | |||
2279 | 2275 | INPUT/RADIO | ||
2280 | 2276 | |||
2281 | 2277 | """ | ||
2282 | 2278 | def __init__(self, type, name, attrs, select_default=False, index=None): | ||
2283 | 2279 | attrs.setdefault("value", "on") | ||
2284 | 2280 | ListControl.__init__(self, type, name, attrs, select_default, | ||
2285 | 2281 | called_as_base_class=True, index=index) | ||
2286 | 2282 | self.__dict__["multiple"] = False | ||
2287 | 2283 | o = Item(self, attrs, index) | ||
2288 | 2284 | o.__dict__["_selected"] = attrs.has_key("checked") | ||
2289 | 2285 | |||
2290 | 2286 | def fixup(self): | ||
2291 | 2287 | ListControl.fixup(self) | ||
2292 | 2288 | found = [o for o in self.items if o.selected and not o.disabled] | ||
2293 | 2289 | if not found: | ||
2294 | 2290 | if self._select_default: | ||
2295 | 2291 | for o in self.items: | ||
2296 | 2292 | if not o.disabled: | ||
2297 | 2293 | o.selected = True | ||
2298 | 2294 | break | ||
2299 | 2295 | else: | ||
2300 | 2296 | # Ensure only one item selected. Choose the last one, | ||
2301 | 2297 | # following IE and Firefox. | ||
2302 | 2298 | for o in found[:-1]: | ||
2303 | 2299 | o.selected = False | ||
2304 | 2300 | |||
2305 | 2301 | def get_labels(self): | ||
2306 | 2302 | return [] | ||
2307 | 2303 | |||
2308 | 2304 | class CheckboxControl(ListControl): | ||
2309 | 2305 | """ | ||
2310 | 2306 | Covers: | ||
2311 | 2307 | |||
2312 | 2308 | INPUT/CHECKBOX | ||
2313 | 2309 | |||
2314 | 2310 | """ | ||
2315 | 2311 | def __init__(self, type, name, attrs, select_default=False, index=None): | ||
2316 | 2312 | attrs.setdefault("value", "on") | ||
2317 | 2313 | ListControl.__init__(self, type, name, attrs, select_default, | ||
2318 | 2314 | called_as_base_class=True, index=index) | ||
2319 | 2315 | self.__dict__["multiple"] = True | ||
2320 | 2316 | o = Item(self, attrs, index) | ||
2321 | 2317 | o.__dict__["_selected"] = attrs.has_key("checked") | ||
2322 | 2318 | |||
2323 | 2319 | def get_labels(self): | ||
2324 | 2320 | return [] | ||
2325 | 2321 | |||
2326 | 2322 | |||
2327 | 2323 | class SelectControl(ListControl): | ||
2328 | 2324 | """ | ||
2329 | 2325 | Covers: | ||
2330 | 2326 | |||
2331 | 2327 | SELECT (and OPTION) | ||
2332 | 2328 | |||
2333 | 2329 | |||
2334 | 2330 | OPTION 'values', in HTML parlance, are Item 'names' in ClientForm parlance. | ||
2335 | 2331 | |||
2336 | 2332 | SELECT control values and labels are subject to some messy defaulting | ||
2337 | 2333 | rules. For example, if the HTML representation of the control is: | ||
2338 | 2334 | |||
2339 | 2335 | <SELECT name=year> | ||
2340 | 2336 | <OPTION value=0 label="2002">current year</OPTION> | ||
2341 | 2337 | <OPTION value=1>2001</OPTION> | ||
2342 | 2338 | <OPTION>2000</OPTION> | ||
2343 | 2339 | </SELECT> | ||
2344 | 2340 | |||
2345 | 2341 | The items, in order, have labels "2002", "2001" and "2000", whereas their | ||
2346 | 2342 | names (the OPTION values) are "0", "1" and "2000" respectively. Note that | ||
2347 | 2343 | the value of the last OPTION in this example defaults to its contents, as | ||
2348 | 2344 | specified by RFC 1866, as do the labels of the second and third OPTIONs. | ||
2349 | 2345 | |||
2350 | 2346 | The OPTION labels are sometimes more meaningful than the OPTION values, | ||
2351 | 2347 | which can make for more maintainable code. | ||
2352 | 2348 | |||
2353 | 2349 | Additional read-only public attribute: attrs | ||
2354 | 2350 | |||
2355 | 2351 | The attrs attribute is a dictionary of the original HTML attributes of the | ||
2356 | 2352 | SELECT element. Other ListControls do not have this attribute, because in | ||
2357 | 2353 | other cases the control as a whole does not correspond to any single HTML | ||
2358 | 2354 | element. control.get(...).attrs may be used as usual to get at the HTML | ||
2359 | 2355 | attributes of the HTML elements corresponding to individual list items (for | ||
2360 | 2356 | SELECT controls, these are OPTION elements). | ||
2361 | 2357 | |||
2362 | 2358 | Another special case is that the Item.attrs dictionaries have a special key | ||
2363 | 2359 | "contents" which does not correspond to any real HTML attribute, but rather | ||
2364 | 2360 | contains the contents of the OPTION element: | ||
2365 | 2361 | |||
2366 | 2362 | <OPTION>this bit</OPTION> | ||
2367 | 2363 | |||
2368 | 2364 | """ | ||
2369 | 2365 | # HTML attributes here are treated slightly differently from other list | ||
2370 | 2366 | # controls: | ||
2371 | 2367 | # -The SELECT HTML attributes dictionary is stuffed into the OPTION | ||
2372 | 2368 | # HTML attributes dictionary under the "__select" key. | ||
2373 | 2369 | # -The content of each OPTION element is stored under the special | ||
2374 | 2370 | # "contents" key of the dictionary. | ||
2375 | 2371 | # After all this, the dictionary is passed to the SelectControl constructor | ||
2376 | 2372 | # as the attrs argument, as usual. However: | ||
2377 | 2373 | # -The first SelectControl constructed when building up a SELECT control | ||
2378 | 2374 | # has a constructor attrs argument containing only the __select key -- so | ||
2379 | 2375 | # this SelectControl represents an empty SELECT control. | ||
2380 | 2376 | # -Subsequent SelectControls have both OPTION HTML-attribute in attrs and | ||
2381 | 2377 | # the __select dictionary containing the SELECT HTML-attributes. | ||
2382 | 2378 | |||
2383 | 2379 | def __init__(self, type, name, attrs, select_default=False, index=None): | ||
2384 | 2380 | # fish out the SELECT HTML attributes from the OPTION HTML attributes | ||
2385 | 2381 | # dictionary | ||
2386 | 2382 | self.attrs = attrs["__select"].copy() | ||
2387 | 2383 | self.__dict__["_label"] = _get_label(self.attrs) | ||
2388 | 2384 | self.__dict__["id"] = self.attrs.get("id") | ||
2389 | 2385 | self.__dict__["multiple"] = self.attrs.has_key("multiple") | ||
2390 | 2386 | # the majority of the contents, label, and value dance already happened | ||
2391 | 2387 | contents = attrs.get("contents") | ||
2392 | 2388 | attrs = attrs.copy() | ||
2393 | 2389 | del attrs["__select"] | ||
2394 | 2390 | |||
2395 | 2391 | ListControl.__init__(self, type, name, self.attrs, select_default, | ||
2396 | 2392 | called_as_base_class=True, index=index) | ||
2397 | 2393 | self.disabled = self.attrs.has_key("disabled") | ||
2398 | 2394 | self.readonly = self.attrs.has_key("readonly") | ||
2399 | 2395 | if attrs.has_key("value"): | ||
2400 | 2396 | # otherwise it is a marker 'select started' token | ||
2401 | 2397 | o = Item(self, attrs, index) | ||
2402 | 2398 | o.__dict__["_selected"] = attrs.has_key("selected") | ||
2403 | 2399 | # add 'label' label and contents label, if different. If both are | ||
2404 | 2400 | # provided, the 'label' label is used for display in HTML | ||
2405 | 2401 | # 4.0-compliant browsers (and any lower spec? not sure) while the | ||
2406 | 2402 | # contents are used for display in older or less-compliant | ||
2407 | 2403 | # browsers. We make label objects for both, if the values are | ||
2408 | 2404 | # different. | ||
2409 | 2405 | label = attrs.get("label") | ||
2410 | 2406 | if label: | ||
2411 | 2407 | o._labels.append(Label({"__text": label})) | ||
2412 | 2408 | if contents and contents != label: | ||
2413 | 2409 | o._labels.append(Label({"__text": contents})) | ||
2414 | 2410 | elif contents: | ||
2415 | 2411 | o._labels.append(Label({"__text": contents})) | ||
2416 | 2412 | |||
2417 | 2413 | def fixup(self): | ||
2418 | 2414 | ListControl.fixup(self) | ||
2419 | 2415 | # Firefox doesn't exclude disabled items from those considered here | ||
2420 | 2416 | # (i.e. from 'found', for both branches of the if below). Note that | ||
2421 | 2417 | # IE6 doesn't support the disabled attribute on OPTIONs at all. | ||
2422 | 2418 | found = [o for o in self.items if o.selected] | ||
2423 | 2419 | if not found: | ||
2424 | 2420 | if not self.multiple or self._select_default: | ||
2425 | 2421 | for o in self.items: | ||
2426 | 2422 | if not o.disabled: | ||
2427 | 2423 | was_disabled = self.disabled | ||
2428 | 2424 | self.disabled = False | ||
2429 | 2425 | try: | ||
2430 | 2426 | o.selected = True | ||
2431 | 2427 | finally: | ||
2432 | 2428 | o.disabled = was_disabled | ||
2433 | 2429 | break | ||
2434 | 2430 | elif not self.multiple: | ||
2435 | 2431 | # Ensure only one item selected. Choose the last one, | ||
2436 | 2432 | # following IE and Firefox. | ||
2437 | 2433 | for o in found[:-1]: | ||
2438 | 2434 | o.selected = False | ||
2439 | 2435 | |||
2440 | 2436 | |||
2441 | 2437 | #--------------------------------------------------- | ||
2442 | 2438 | class SubmitControl(ScalarControl): | ||
2443 | 2439 | """ | ||
2444 | 2440 | Covers: | ||
2445 | 2441 | |||
2446 | 2442 | INPUT/SUBMIT | ||
2447 | 2443 | BUTTON/SUBMIT | ||
2448 | 2444 | |||
2449 | 2445 | """ | ||
2450 | 2446 | def __init__(self, type, name, attrs, index=None): | ||
2451 | 2447 | ScalarControl.__init__(self, type, name, attrs, index) | ||
2452 | 2448 | # IE5 defaults SUBMIT value to "Submit Query"; Firebird 0.6 leaves it | ||
2453 | 2449 | # blank, Konqueror 3.1 defaults to "Submit". HTML spec. doesn't seem | ||
2454 | 2450 | # to define this. | ||
2455 | 2451 | if self.value is None: self.value = "" | ||
2456 | 2452 | self.readonly = True | ||
2457 | 2453 | |||
2458 | 2454 | def get_labels(self): | ||
2459 | 2455 | res = [] | ||
2460 | 2456 | if self.value: | ||
2461 | 2457 | res.append(Label({"__text": self.value})) | ||
2462 | 2458 | res.extend(ScalarControl.get_labels(self)) | ||
2463 | 2459 | return res | ||
2464 | 2460 | |||
2465 | 2461 | def is_of_kind(self, kind): return kind == "clickable" | ||
2466 | 2462 | |||
2467 | 2463 | def _click(self, form, coord, return_type, request_class=urllib2.Request): | ||
2468 | 2464 | self._clicked = coord | ||
2469 | 2465 | r = form._switch_click(return_type, request_class) | ||
2470 | 2466 | self._clicked = False | ||
2471 | 2467 | return r | ||
2472 | 2468 | |||
2473 | 2469 | def _totally_ordered_pairs(self): | ||
2474 | 2470 | if not self._clicked: | ||
2475 | 2471 | return [] | ||
2476 | 2472 | return ScalarControl._totally_ordered_pairs(self) | ||
2477 | 2473 | |||
2478 | 2474 | |||
2479 | 2475 | #--------------------------------------------------- | ||
2480 | 2476 | class ImageControl(SubmitControl): | ||
2481 | 2477 | """ | ||
2482 | 2478 | Covers: | ||
2483 | 2479 | |||
2484 | 2480 | INPUT/IMAGE | ||
2485 | 2481 | |||
2486 | 2482 | Coordinates are specified using one of the HTMLForm.click* methods. | ||
2487 | 2483 | |||
2488 | 2484 | """ | ||
2489 | 2485 | def __init__(self, type, name, attrs, index=None): | ||
2490 | 2486 | SubmitControl.__init__(self, type, name, attrs, index) | ||
2491 | 2487 | self.readonly = False | ||
2492 | 2488 | |||
2493 | 2489 | def _totally_ordered_pairs(self): | ||
2494 | 2490 | clicked = self._clicked | ||
2495 | 2491 | if self.disabled or not clicked: | ||
2496 | 2492 | return [] | ||
2497 | 2493 | name = self.name | ||
2498 | 2494 | if name is None: return [] | ||
2499 | 2495 | pairs = [ | ||
2500 | 2496 | (self._index, "%s.x" % name, str(clicked[0])), | ||
2501 | 2497 | (self._index+1, "%s.y" % name, str(clicked[1])), | ||
2502 | 2498 | ] | ||
2503 | 2499 | value = self._value | ||
2504 | 2500 | if value: | ||
2505 | 2501 | pairs.append((self._index+2, name, value)) | ||
2506 | 2502 | return pairs | ||
2507 | 2503 | |||
2508 | 2504 | get_labels = ScalarControl.get_labels | ||
2509 | 2505 | |||
2510 | 2506 | # aliases, just to make str(control) and str(form) clearer | ||
2511 | 2507 | class PasswordControl(TextControl): pass | ||
2512 | 2508 | class HiddenControl(TextControl): pass | ||
2513 | 2509 | class TextareaControl(TextControl): pass | ||
2514 | 2510 | class SubmitButtonControl(SubmitControl): pass | ||
2515 | 2511 | |||
2516 | 2512 | |||
2517 | 2513 | def is_listcontrol(control): return control.is_of_kind("list") | ||
2518 | 2514 | |||
2519 | 2515 | |||
2520 | 2516 | class HTMLForm: | ||
2521 | 2517 | """Represents a single HTML <form> ... </form> element. | ||
2522 | 2518 | |||
2523 | 2519 | A form consists of a sequence of controls that usually have names, and | ||
2524 | 2520 | which can take on various values. The values of the various types of | ||
2525 | 2521 | controls represent variously: text, zero-or-one-of-many or many-of-many | ||
2526 | 2522 | choices, and files to be uploaded. Some controls can be clicked on to | ||
2527 | 2523 | submit the form, and clickable controls' values sometimes include the | ||
2528 | 2524 | coordinates of the click. | ||
2529 | 2525 | |||
2530 | 2526 | Forms can be filled in with data to be returned to the server, and then | ||
2531 | 2527 | submitted, using the click method to generate a request object suitable for | ||
2532 | 2528 | passing to urllib2.urlopen (or the click_request_data or click_pairs | ||
2533 | 2529 | methods if you're not using urllib2). | ||
2534 | 2530 | |||
2535 | 2531 | import ClientForm | ||
2536 | 2532 | forms = ClientForm.ParseFile(html, base_uri) | ||
2537 | 2533 | form = forms[0] | ||
2538 | 2534 | |||
2539 | 2535 | form["query"] = "Python" | ||
2540 | 2536 | form.find_control("nr_results").get("lots").selected = True | ||
2541 | 2537 | |||
2542 | 2538 | response = urllib2.urlopen(form.click()) | ||
2543 | 2539 | |||
2544 | 2540 | Usually, HTMLForm instances are not created directly. Instead, the | ||
2545 | 2541 | ParseFile or ParseResponse factory functions are used. If you do construct | ||
2546 | 2542 | HTMLForm objects yourself, however, note that an HTMLForm instance is only | ||
2547 | 2543 | properly initialised after the fixup method has been called (ParseFile and | ||
2548 | 2544 | ParseResponse do this for you). See ListControl.__doc__ for the reason | ||
2549 | 2545 | this is required. | ||
2550 | 2546 | |||
2551 | 2547 | Indexing a form (form["control_name"]) returns the named Control's value | ||
2552 | 2548 | attribute. Assignment to a form index (form["control_name"] = something) | ||
2553 | 2549 | is equivalent to assignment to the named Control's value attribute. If you | ||
2554 | 2550 | need to be more specific than just supplying the control's name, use the | ||
2555 | 2551 | set_value and get_value methods. | ||
2556 | 2552 | |||
2557 | 2553 | ListControl values are lists of item names (specifically, the names of the | ||
2558 | 2554 | items that are selected and not disabled, and hence are "successful" -- ie. | ||
2559 | 2555 | cause data to be returned to the server). The list item's name is the | ||
2560 | 2556 | value of the corresponding HTML element's"value" attribute. | ||
2561 | 2557 | |||
2562 | 2558 | Example: | ||
2563 | 2559 | |||
2564 | 2560 | <INPUT type="CHECKBOX" name="cheeses" value="leicester"></INPUT> | ||
2565 | 2561 | <INPUT type="CHECKBOX" name="cheeses" value="cheddar"></INPUT> | ||
2566 | 2562 | |||
2567 | 2563 | defines a CHECKBOX control with name "cheeses" which has two items, named | ||
2568 | 2564 | "leicester" and "cheddar". | ||
2569 | 2565 | |||
2570 | 2566 | Another example: | ||
2571 | 2567 | |||
2572 | 2568 | <SELECT name="more_cheeses"> | ||
2573 | 2569 | <OPTION>1</OPTION> | ||
2574 | 2570 | <OPTION value="2" label="CHEDDAR">cheddar</OPTION> | ||
2575 | 2571 | </SELECT> | ||
2576 | 2572 | |||
2577 | 2573 | defines a SELECT control with name "more_cheeses" which has two items, | ||
2578 | 2574 | named "1" and "2" (because the OPTION element's value HTML attribute | ||
2579 | 2575 | defaults to the element contents -- see SelectControl.__doc__ for more on | ||
2580 | 2576 | these defaulting rules). | ||
2581 | 2577 | |||
2582 | 2578 | To select, deselect or otherwise manipulate individual list items, use the | ||
2583 | 2579 | HTMLForm.find_control() and ListControl.get() methods. To set the whole | ||
2584 | 2580 | value, do as for any other control: use indexing or the set_/get_value | ||
2585 | 2581 | methods. | ||
2586 | 2582 | |||
2587 | 2583 | Example: | ||
2588 | 2584 | |||
2589 | 2585 | # select *only* the item named "cheddar" | ||
2590 | 2586 | form["cheeses"] = ["cheddar"] | ||
2591 | 2587 | # select "cheddar", leave other items unaffected | ||
2592 | 2588 | form.find_control("cheeses").get("cheddar").selected = True | ||
2593 | 2589 | |||
2594 | 2590 | Some controls (RADIO and SELECT without the multiple attribute) can only | ||
2595 | 2591 | have zero or one items selected at a time. Some controls (CHECKBOX and | ||
2596 | 2592 | SELECT with the multiple attribute) can have multiple items selected at a | ||
2597 | 2593 | time. To set the whole value of a ListControl, assign a sequence to a form | ||
2598 | 2594 | index: | ||
2599 | 2595 | |||
2600 | 2596 | form["cheeses"] = ["cheddar", "leicester"] | ||
2601 | 2597 | |||
2602 | 2598 | If the ListControl is not multiple-selection, the assigned list must be of | ||
2603 | 2599 | length one. | ||
2604 | 2600 | |||
2605 | 2601 | To check if a control has an item, if an item is selected, or if an item is | ||
2606 | 2602 | successful (selected and not disabled), respectively: | ||
2607 | 2603 | |||
2608 | 2604 | "cheddar" in [item.name for item in form.find_control("cheeses").items] | ||
2609 | 2605 | "cheddar" in [item.name for item in form.find_control("cheeses").items and | ||
2610 | 2606 | item.selected] | ||
2611 | 2607 | "cheddar" in form["cheeses"] # (or "cheddar" in form.get_value("cheeses")) | ||
2612 | 2608 | |||
2613 | 2609 | Note that some list items may be disabled (see below). | ||
2614 | 2610 | |||
2615 | 2611 | Note the following mistake: | ||
2616 | 2612 | |||
2617 | 2613 | form[control_name] = control_value | ||
2618 | 2614 | assert form[control_name] == control_value # not necessarily true | ||
2619 | 2615 | |||
2620 | 2616 | The reason for this is that form[control_name] always gives the list items | ||
2621 | 2617 | in the order they were listed in the HTML. | ||
2622 | 2618 | |||
2623 | 2619 | List items (hence list values, too) can be referred to in terms of list | ||
2624 | 2620 | item labels rather than list item names using the appropriate label | ||
2625 | 2621 | arguments. Note that each item may have several labels. | ||
2626 | 2622 | |||
2627 | 2623 | The question of default values of OPTION contents, labels and values is | ||
2628 | 2624 | somewhat complicated: see SelectControl.__doc__ and | ||
2629 | 2625 | ListControl.get_item_attrs.__doc__ if you think you need to know. | ||
2630 | 2626 | |||
2631 | 2627 | Controls can be disabled or readonly. In either case, the control's value | ||
2632 | 2628 | cannot be changed until you clear those flags (see example below). | ||
2633 | 2629 | Disabled is the state typically represented by browsers by 'greying out' a | ||
2634 | 2630 | control. Disabled controls are not 'successful' -- they don't cause data | ||
2635 | 2631 | to get returned to the server. Readonly controls usually appear in | ||
2636 | 2632 | browsers as read-only text boxes. Readonly controls are successful. List | ||
2637 | 2633 | items can also be disabled. Attempts to select or deselect disabled items | ||
2638 | 2634 | fail with AttributeError. | ||
2639 | 2635 | |||
2640 | 2636 | If a lot of controls are readonly, it can be useful to do this: | ||
2641 | 2637 | |||
2642 | 2638 | form.set_all_readonly(False) | ||
2643 | 2639 | |||
2644 | 2640 | To clear a control's value attribute, so that it is not successful (until a | ||
2645 | 2641 | value is subsequently set): | ||
2646 | 2642 | |||
2647 | 2643 | form.clear("cheeses") | ||
2648 | 2644 | |||
2649 | 2645 | More examples: | ||
2650 | 2646 | |||
2651 | 2647 | control = form.find_control("cheeses") | ||
2652 | 2648 | control.disabled = False | ||
2653 | 2649 | control.readonly = False | ||
2654 | 2650 | control.get("gruyere").disabled = True | ||
2655 | 2651 | control.items[0].selected = True | ||
2656 | 2652 | |||
2657 | 2653 | See the various Control classes for further documentation. Many methods | ||
2658 | 2654 | take name, type, kind, id, label and nr arguments to specify the control to | ||
2659 | 2655 | be operated on: see HTMLForm.find_control.__doc__. | ||
2660 | 2656 | |||
2661 | 2657 | ControlNotFoundError (subclass of ValueError) is raised if the specified | ||
2662 | 2658 | control can't be found. This includes occasions where a non-ListControl | ||
2663 | 2659 | is found, but the method (set, for example) requires a ListControl. | ||
2664 | 2660 | ItemNotFoundError (subclass of ValueError) is raised if a list item can't | ||
2665 | 2661 | be found. ItemCountError (subclass of ValueError) is raised if an attempt | ||
2666 | 2662 | is made to select more than one item and the control doesn't allow that, or | ||
2667 | 2663 | set/get_single are called and the control contains more than one item. | ||
2668 | 2664 | AttributeError is raised if a control or item is readonly or disabled and | ||
2669 | 2665 | an attempt is made to alter its value. | ||
2670 | 2666 | |||
2671 | 2667 | Security note: Remember that any passwords you store in HTMLForm instances | ||
2672 | 2668 | will be saved to disk in the clear if you pickle them (directly or | ||
2673 | 2669 | indirectly). The simplest solution to this is to avoid pickling HTMLForm | ||
2674 | 2670 | objects. You could also pickle before filling in any password, or just set | ||
2675 | 2671 | the password to "" before pickling. | ||
2676 | 2672 | |||
2677 | 2673 | |||
2678 | 2674 | Public attributes: | ||
2679 | 2675 | |||
2680 | 2676 | action: full (absolute URI) form action | ||
2681 | 2677 | method: "GET" or "POST" | ||
2682 | 2678 | enctype: form transfer encoding MIME type | ||
2683 | 2679 | name: name of form (None if no name was specified) | ||
2684 | 2680 | attrs: dictionary mapping original HTML form attributes to their values | ||
2685 | 2681 | |||
2686 | 2682 | controls: list of Control instances; do not alter this list | ||
2687 | 2683 | (instead, call form.new_control to make a Control and add it to the | ||
2688 | 2684 | form, or control.add_to_form if you already have a Control instance) | ||
2689 | 2685 | |||
2690 | 2686 | |||
2691 | 2687 | |||
2692 | 2688 | Methods for form filling: | ||
2693 | 2689 | ------------------------- | ||
2694 | 2690 | |||
2695 | 2691 | Most of the these methods have very similar arguments. See | ||
2696 | 2692 | HTMLForm.find_control.__doc__ for details of the name, type, kind, label | ||
2697 | 2693 | and nr arguments. | ||
2698 | 2694 | |||
2699 | 2695 | def find_control(self, | ||
2700 | 2696 | name=None, type=None, kind=None, id=None, predicate=None, | ||
2701 | 2697 | nr=None, label=None) | ||
2702 | 2698 | |||
2703 | 2699 | get_value(name=None, type=None, kind=None, id=None, nr=None, | ||
2704 | 2700 | by_label=False, # by_label is deprecated | ||
2705 | 2701 | label=None) | ||
2706 | 2702 | set_value(value, | ||
2707 | 2703 | name=None, type=None, kind=None, id=None, nr=None, | ||
2708 | 2704 | by_label=False, # by_label is deprecated | ||
2709 | 2705 | label=None) | ||
2710 | 2706 | |||
2711 | 2707 | clear_all() | ||
2712 | 2708 | clear(name=None, type=None, kind=None, id=None, nr=None, label=None) | ||
2713 | 2709 | |||
2714 | 2710 | set_all_readonly(readonly) | ||
2715 | 2711 | |||
2716 | 2712 | |||
2717 | 2713 | Method applying only to FileControls: | ||
2718 | 2714 | |||
2719 | 2715 | add_file(file_object, | ||
2720 | 2716 | content_type="application/octet-stream", filename=None, | ||
2721 | 2717 | name=None, id=None, nr=None, label=None) | ||
2722 | 2718 | |||
2723 | 2719 | |||
2724 | 2720 | Methods applying only to clickable controls: | ||
2725 | 2721 | |||
2726 | 2722 | click(name=None, type=None, id=None, nr=0, coord=(1,1), label=None) | ||
2727 | 2723 | click_request_data(name=None, type=None, id=None, nr=0, coord=(1,1), | ||
2728 | 2724 | label=None) | ||
2729 | 2725 | click_pairs(name=None, type=None, id=None, nr=0, coord=(1,1), label=None) | ||
2730 | 2726 | |||
2731 | 2727 | """ | ||
2732 | 2728 | |||
2733 | 2729 | type2class = { | ||
2734 | 2730 | "text": TextControl, | ||
2735 | 2731 | "password": PasswordControl, | ||
2736 | 2732 | "hidden": HiddenControl, | ||
2737 | 2733 | "textarea": TextareaControl, | ||
2738 | 2734 | |||
2739 | 2735 | "isindex": IsindexControl, | ||
2740 | 2736 | |||
2741 | 2737 | "file": FileControl, | ||
2742 | 2738 | |||
2743 | 2739 | "button": IgnoreControl, | ||
2744 | 2740 | "buttonbutton": IgnoreControl, | ||
2745 | 2741 | "reset": IgnoreControl, | ||
2746 | 2742 | "resetbutton": IgnoreControl, | ||
2747 | 2743 | |||
2748 | 2744 | "submit": SubmitControl, | ||
2749 | 2745 | "submitbutton": SubmitButtonControl, | ||
2750 | 2746 | "image": ImageControl, | ||
2751 | 2747 | |||
2752 | 2748 | "radio": RadioControl, | ||
2753 | 2749 | "checkbox": CheckboxControl, | ||
2754 | 2750 | "select": SelectControl, | ||
2755 | 2751 | } | ||
2756 | 2752 | |||
2757 | 2753 | #--------------------------------------------------- | ||
2758 | 2754 | # Initialisation. Use ParseResponse / ParseFile instead. | ||
2759 | 2755 | |||
2760 | 2756 | def __init__(self, action, method="GET", | ||
2761 | 2757 | enctype="application/x-www-form-urlencoded", | ||
2762 | 2758 | name=None, attrs=None, | ||
2763 | 2759 | request_class=urllib2.Request, | ||
2764 | 2760 | forms=None, labels=None, id_to_labels=None, | ||
2765 | 2761 | backwards_compat=True): | ||
2766 | 2762 | """ | ||
2767 | 2763 | In the usual case, use ParseResponse (or ParseFile) to create new | ||
2768 | 2764 | HTMLForm objects. | ||
2769 | 2765 | |||
2770 | 2766 | action: full (absolute URI) form action | ||
2771 | 2767 | method: "GET" or "POST" | ||
2772 | 2768 | enctype: form transfer encoding MIME type | ||
2773 | 2769 | name: name of form | ||
2774 | 2770 | attrs: dictionary mapping original HTML form attributes to their values | ||
2775 | 2771 | |||
2776 | 2772 | """ | ||
2777 | 2773 | self.action = action | ||
2778 | 2774 | self.method = method | ||
2779 | 2775 | self.enctype = enctype | ||
2780 | 2776 | self.name = name | ||
2781 | 2777 | if attrs is not None: | ||
2782 | 2778 | self.attrs = attrs.copy() | ||
2783 | 2779 | else: | ||
2784 | 2780 | self.attrs = {} | ||
2785 | 2781 | self.controls = [] | ||
2786 | 2782 | self._request_class = request_class | ||
2787 | 2783 | |||
2788 | 2784 | # these attributes are used by zope.testbrowser | ||
2789 | 2785 | self._forms = forms # this is a semi-public API! | ||
2790 | 2786 | self._labels = labels # this is a semi-public API! | ||
2791 | 2787 | self._id_to_labels = id_to_labels # this is a semi-public API! | ||
2792 | 2788 | |||
2793 | 2789 | self.backwards_compat = backwards_compat # note __setattr__ | ||
2794 | 2790 | |||
2795 | 2791 | self._urlunparse = urlparse.urlunparse | ||
2796 | 2792 | self._urlparse = urlparse.urlparse | ||
2797 | 2793 | |||
2798 | 2794 | def __getattr__(self, name): | ||
2799 | 2795 | if name == "backwards_compat": | ||
2800 | 2796 | return self._backwards_compat | ||
2801 | 2797 | return getattr(HTMLForm, name) | ||
2802 | 2798 | |||
2803 | 2799 | def __setattr__(self, name, value): | ||
2804 | 2800 | # yuck | ||
2805 | 2801 | if name == "backwards_compat": | ||
2806 | 2802 | name = "_backwards_compat" | ||
2807 | 2803 | value = bool(value) | ||
2808 | 2804 | for cc in self.controls: | ||
2809 | 2805 | try: | ||
2810 | 2806 | items = cc.items | ||
2811 | 2807 | except AttributeError: | ||
2812 | 2808 | continue | ||
2813 | 2809 | else: | ||
2814 | 2810 | for ii in items: | ||
2815 | 2811 | for ll in ii.get_labels(): | ||
2816 | 2812 | ll._backwards_compat = value | ||
2817 | 2813 | self.__dict__[name] = value | ||
2818 | 2814 | |||
2819 | 2815 | def new_control(self, type, name, attrs, | ||
2820 | 2816 | ignore_unknown=False, select_default=False, index=None): | ||
2821 | 2817 | """Adds a new control to the form. | ||
2822 | 2818 | |||
2823 | 2819 | This is usually called by ParseFile and ParseResponse. Don't call it | ||
2824 | 2820 | youself unless you're building your own Control instances. | ||
2825 | 2821 | |||
2826 | 2822 | Note that controls representing lists of items are built up from | ||
2827 | 2823 | controls holding only a single list item. See ListControl.__doc__ for | ||
2828 | 2824 | further information. | ||
2829 | 2825 | |||
2830 | 2826 | type: type of control (see Control.__doc__ for a list) | ||
2831 | 2827 | attrs: HTML attributes of control | ||
2832 | 2828 | ignore_unknown: if true, use a dummy Control instance for controls of | ||
2833 | 2829 | unknown type; otherwise, use a TextControl | ||
2834 | 2830 | select_default: for RADIO and multiple-selection SELECT controls, pick | ||
2835 | 2831 | the first item as the default if no 'selected' HTML attribute is | ||
2836 | 2832 | present (this defaulting happens when the HTMLForm.fixup method is | ||
2837 | 2833 | called) | ||
2838 | 2834 | index: index of corresponding element in HTML (see | ||
2839 | 2835 | MoreFormTests.test_interspersed_controls for motivation) | ||
2840 | 2836 | |||
2841 | 2837 | """ | ||
2842 | 2838 | type = type.lower() | ||
2843 | 2839 | klass = self.type2class.get(type) | ||
2844 | 2840 | if klass is None: | ||
2845 | 2841 | if ignore_unknown: | ||
2846 | 2842 | klass = IgnoreControl | ||
2847 | 2843 | else: | ||
2848 | 2844 | klass = TextControl | ||
2849 | 2845 | |||
2850 | 2846 | a = attrs.copy() | ||
2851 | 2847 | if issubclass(klass, ListControl): | ||
2852 | 2848 | control = klass(type, name, a, select_default, index) | ||
2853 | 2849 | else: | ||
2854 | 2850 | control = klass(type, name, a, index) | ||
2855 | 2851 | |||
2856 | 2852 | if type == "select" and len(attrs) == 1: | ||
2857 | 2853 | for ii in range(len(self.controls)-1, -1, -1): | ||
2858 | 2854 | ctl = self.controls[ii] | ||
2859 | 2855 | if ctl.type == "select": | ||
2860 | 2856 | ctl.close_control() | ||
2861 | 2857 | break | ||
2862 | 2858 | |||
2863 | 2859 | control.add_to_form(self) | ||
2864 | 2860 | control._urlparse = self._urlparse | ||
2865 | 2861 | control._urlunparse = self._urlunparse | ||
2866 | 2862 | |||
2867 | 2863 | def fixup(self): | ||
2868 | 2864 | """Normalise form after all controls have been added. | ||
2869 | 2865 | |||
2870 | 2866 | This is usually called by ParseFile and ParseResponse. Don't call it | ||
2871 | 2867 | youself unless you're building your own Control instances. | ||
2872 | 2868 | |||
2873 | 2869 | This method should only be called once, after all controls have been | ||
2874 | 2870 | added to the form. | ||
2875 | 2871 | |||
2876 | 2872 | """ | ||
2877 | 2873 | for control in self.controls: | ||
2878 | 2874 | control.fixup() | ||
2879 | 2875 | self.backwards_compat = self._backwards_compat | ||
2880 | 2876 | |||
2881 | 2877 | #--------------------------------------------------- | ||
2882 | 2878 | def __str__(self): | ||
2883 | 2879 | header = "%s%s %s %s" % ( | ||
2884 | 2880 | (self.name and self.name+" " or ""), | ||
2885 | 2881 | self.method, self.action, self.enctype) | ||
2886 | 2882 | rep = [header] | ||
2887 | 2883 | for control in self.controls: | ||
2888 | 2884 | rep.append(" %s" % str(control)) | ||
2889 | 2885 | return "<%s>" % "\n".join(rep) | ||
2890 | 2886 | |||
2891 | 2887 | #--------------------------------------------------- | ||
2892 | 2888 | # Form-filling methods. | ||
2893 | 2889 | |||
2894 | 2890 | def __getitem__(self, name): | ||
2895 | 2891 | return self.find_control(name).value | ||
2896 | 2892 | def __contains__(self, name): | ||
2897 | 2893 | return bool(self.find_control(name)) | ||
2898 | 2894 | def __setitem__(self, name, value): | ||
2899 | 2895 | control = self.find_control(name) | ||
2900 | 2896 | try: | ||
2901 | 2897 | control.value = value | ||
2902 | 2898 | except AttributeError, e: | ||
2903 | 2899 | raise ValueError(str(e)) | ||
2904 | 2900 | |||
2905 | 2901 | def get_value(self, | ||
2906 | 2902 | name=None, type=None, kind=None, id=None, nr=None, | ||
2907 | 2903 | by_label=False, # by_label is deprecated | ||
2908 | 2904 | label=None): | ||
2909 | 2905 | """Return value of control. | ||
2910 | 2906 | |||
2911 | 2907 | If only name and value arguments are supplied, equivalent to | ||
2912 | 2908 | |||
2913 | 2909 | form[name] | ||
2914 | 2910 | |||
2915 | 2911 | """ | ||
2916 | 2912 | if by_label: | ||
2917 | 2913 | deprecation("form.get_value_by_label(...)") | ||
2918 | 2914 | c = self.find_control(name, type, kind, id, label=label, nr=nr) | ||
2919 | 2915 | if by_label: | ||
2920 | 2916 | try: | ||
2921 | 2917 | meth = c.get_value_by_label | ||
2922 | 2918 | except AttributeError: | ||
2923 | 2919 | raise NotImplementedError( | ||
2924 | 2920 | "control '%s' does not yet support by_label" % c.name) | ||
2925 | 2921 | else: | ||
2926 | 2922 | return meth() | ||
2927 | 2923 | else: | ||
2928 | 2924 | return c.value | ||
2929 | 2925 | def set_value(self, value, | ||
2930 | 2926 | name=None, type=None, kind=None, id=None, nr=None, | ||
2931 | 2927 | by_label=False, # by_label is deprecated | ||
2932 | 2928 | label=None): | ||
2933 | 2929 | """Set value of control. | ||
2934 | 2930 | |||
2935 | 2931 | If only name and value arguments are supplied, equivalent to | ||
2936 | 2932 | |||
2937 | 2933 | form[name] = value | ||
2938 | 2934 | |||
2939 | 2935 | """ | ||
2940 | 2936 | if by_label: | ||
2941 | 2937 | deprecation("form.get_value_by_label(...)") | ||
2942 | 2938 | c = self.find_control(name, type, kind, id, label=label, nr=nr) | ||
2943 | 2939 | if by_label: | ||
2944 | 2940 | try: | ||
2945 | 2941 | meth = c.set_value_by_label | ||
2946 | 2942 | except AttributeError: | ||
2947 | 2943 | raise NotImplementedError( | ||
2948 | 2944 | "control '%s' does not yet support by_label" % c.name) | ||
2949 | 2945 | else: | ||
2950 | 2946 | meth(value) | ||
2951 | 2947 | else: | ||
2952 | 2948 | c.value = value | ||
2953 | 2949 | def get_value_by_label( | ||
2954 | 2950 | self, name=None, type=None, kind=None, id=None, label=None, nr=None): | ||
2955 | 2951 | """ | ||
2956 | 2952 | |||
2957 | 2953 | All arguments should be passed by name. | ||
2958 | 2954 | |||
2959 | 2955 | """ | ||
2960 | 2956 | c = self.find_control(name, type, kind, id, label=label, nr=nr) | ||
2961 | 2957 | return c.get_value_by_label() | ||
2962 | 2958 | |||
2963 | 2959 | def set_value_by_label( | ||
2964 | 2960 | self, value, | ||
2965 | 2961 | name=None, type=None, kind=None, id=None, label=None, nr=None): | ||
2966 | 2962 | """ | ||
2967 | 2963 | |||
2968 | 2964 | All arguments should be passed by name. | ||
2969 | 2965 | |||
2970 | 2966 | """ | ||
2971 | 2967 | c = self.find_control(name, type, kind, id, label=label, nr=nr) | ||
2972 | 2968 | c.set_value_by_label(value) | ||
2973 | 2969 | |||
2974 | 2970 | def set_all_readonly(self, readonly): | ||
2975 | 2971 | for control in self.controls: | ||
2976 | 2972 | control.readonly = bool(readonly) | ||
2977 | 2973 | |||
2978 | 2974 | def clear_all(self): | ||
2979 | 2975 | """Clear the value attributes of all controls in the form. | ||
2980 | 2976 | |||
2981 | 2977 | See HTMLForm.clear.__doc__. | ||
2982 | 2978 | |||
2983 | 2979 | """ | ||
2984 | 2980 | for control in self.controls: | ||
2985 | 2981 | control.clear() | ||
2986 | 2982 | |||
2987 | 2983 | def clear(self, | ||
2988 | 2984 | name=None, type=None, kind=None, id=None, nr=None, label=None): | ||
2989 | 2985 | """Clear the value attribute of a control. | ||
2990 | 2986 | |||
2991 | 2987 | As a result, the affected control will not be successful until a value | ||
2992 | 2988 | is subsequently set. AttributeError is raised on readonly controls. | ||
2993 | 2989 | |||
2994 | 2990 | """ | ||
2995 | 2991 | c = self.find_control(name, type, kind, id, label=label, nr=nr) | ||
2996 | 2992 | c.clear() | ||
2997 | 2993 | |||
2998 | 2994 | |||
2999 | 2995 | #--------------------------------------------------- | ||
3000 | 2996 | # Form-filling methods applying only to ListControls. | ||
3001 | 2997 | |||
3002 | 2998 | def possible_items(self, # deprecated | ||
3003 | 2999 | name=None, type=None, kind=None, id=None, | ||
3004 | 3000 | nr=None, by_label=False, label=None): | ||
3005 | 3001 | """Return a list of all values that the specified control can take.""" | ||
3006 | 3002 | c = self._find_list_control(name, type, kind, id, label, nr) | ||
3007 | 3003 | return c.possible_items(by_label) | ||
3008 | 3004 | |||
3009 | 3005 | def set(self, selected, item_name, # deprecated | ||
3010 | 3006 | name=None, type=None, kind=None, id=None, nr=None, | ||
3011 | 3007 | by_label=False, label=None): | ||
3012 | 3008 | """Select / deselect named list item. | ||
3013 | 3009 | |||
3014 | 3010 | selected: boolean selected state | ||
3015 | 3011 | |||
3016 | 3012 | """ | ||
3017 | 3013 | self._find_list_control(name, type, kind, id, label, nr).set( | ||
3018 | 3014 | selected, item_name, by_label) | ||
3019 | 3015 | def toggle(self, item_name, # deprecated | ||
3020 | 3016 | name=None, type=None, kind=None, id=None, nr=None, | ||
3021 | 3017 | by_label=False, label=None): | ||
3022 | 3018 | """Toggle selected state of named list item.""" | ||
3023 | 3019 | self._find_list_control(name, type, kind, id, label, nr).toggle( | ||
3024 | 3020 | item_name, by_label) | ||
3025 | 3021 | |||
3026 | 3022 | def set_single(self, selected, # deprecated | ||
3027 | 3023 | name=None, type=None, kind=None, id=None, | ||
3028 | 3024 | nr=None, by_label=None, label=None): | ||
3029 | 3025 | """Select / deselect list item in a control having only one item. | ||
3030 | 3026 | |||
3031 | 3027 | If the control has multiple list items, ItemCountError is raised. | ||
3032 | 3028 | |||
3033 | 3029 | This is just a convenience method, so you don't need to know the item's | ||
3034 | 3030 | name -- the item name in these single-item controls is usually | ||
3035 | 3031 | something meaningless like "1" or "on". | ||
3036 | 3032 | |||
3037 | 3033 | For example, if a checkbox has a single item named "on", the following | ||
3038 | 3034 | two calls are equivalent: | ||
3039 | 3035 | |||
3040 | 3036 | control.toggle("on") | ||
3041 | 3037 | control.toggle_single() | ||
3042 | 3038 | |||
3043 | 3039 | """ # by_label ignored and deprecated | ||
3044 | 3040 | self._find_list_control( | ||
3045 | 3041 | name, type, kind, id, label, nr).set_single(selected) | ||
3046 | 3042 | def toggle_single(self, name=None, type=None, kind=None, id=None, | ||
3047 | 3043 | nr=None, by_label=None, label=None): # deprecated | ||
3048 | 3044 | """Toggle selected state of list item in control having only one item. | ||
3049 | 3045 | |||
3050 | 3046 | The rest is as for HTMLForm.set_single.__doc__. | ||
3051 | 3047 | |||
3052 | 3048 | """ # by_label ignored and deprecated | ||
3053 | 3049 | self._find_list_control(name, type, kind, id, label, nr).toggle_single() | ||
3054 | 3050 | |||
3055 | 3051 | #--------------------------------------------------- | ||
3056 | 3052 | # Form-filling method applying only to FileControls. | ||
3057 | 3053 | |||
3058 | 3054 | def add_file(self, file_object, content_type=None, filename=None, | ||
3059 | 3055 | name=None, id=None, nr=None, label=None): | ||
3060 | 3056 | """Add a file to be uploaded. | ||
3061 | 3057 | |||
3062 | 3058 | file_object: file-like object (with read method) from which to read | ||
3063 | 3059 | data to upload | ||
3064 | 3060 | content_type: MIME content type of data to upload | ||
3065 | 3061 | filename: filename to pass to server | ||
3066 | 3062 | |||
3067 | 3063 | If filename is None, no filename is sent to the server. | ||
3068 | 3064 | |||
3069 | 3065 | If content_type is None, the content type is guessed based on the | ||
3070 | 3066 | filename and the data from read from the file object. | ||
3071 | 3067 | |||
3072 | 3068 | XXX | ||
3073 | 3069 | At the moment, guessed content type is always application/octet-stream. | ||
3074 | 3070 | Use sndhdr, imghdr modules. Should also try to guess HTML, XML, and | ||
3075 | 3071 | plain text. | ||
3076 | 3072 | |||
3077 | 3073 | Note the following useful HTML attributes of file upload controls (see | ||
3078 | 3074 | HTML 4.01 spec, section 17): | ||
3079 | 3075 | |||
3080 | 3076 | accept: comma-separated list of content types that the server will | ||
3081 | 3077 | handle correctly; you can use this to filter out non-conforming files | ||
3082 | 3078 | size: XXX IIRC, this is indicative of whether form wants multiple or | ||
3083 | 3079 | single files | ||
3084 | 3080 | maxlength: XXX hint of max content length in bytes? | ||
3085 | 3081 | |||
3086 | 3082 | """ | ||
3087 | 3083 | self.find_control(name, "file", id=id, label=label, nr=nr).add_file( | ||
3088 | 3084 | file_object, content_type, filename) | ||
3089 | 3085 | |||
3090 | 3086 | #--------------------------------------------------- | ||
3091 | 3087 | # Form submission methods, applying only to clickable controls. | ||
3092 | 3088 | |||
3093 | 3089 | def click(self, name=None, type=None, id=None, nr=0, coord=(1,1), | ||
3094 | 3090 | request_class=urllib2.Request, | ||
3095 | 3091 | label=None): | ||
3096 | 3092 | """Return request that would result from clicking on a control. | ||
3097 | 3093 | |||
3098 | 3094 | The request object is a urllib2.Request instance, which you can pass to | ||
3099 | 3095 | urllib2.urlopen (or ClientCookie.urlopen). | ||
3100 | 3096 | |||
3101 | 3097 | Only some control types (INPUT/SUBMIT & BUTTON/SUBMIT buttons and | ||
3102 | 3098 | IMAGEs) can be clicked. | ||
3103 | 3099 | |||
3104 | 3100 | Will click on the first clickable control, subject to the name, type | ||
3105 | 3101 | and nr arguments (as for find_control). If no name, type, id or number | ||
3106 | 3102 | is specified and there are no clickable controls, a request will be | ||
3107 | 3103 | returned for the form in its current, un-clicked, state. | ||
3108 | 3104 | |||
3109 | 3105 | IndexError is raised if any of name, type, id or nr is specified but no | ||
3110 | 3106 | matching control is found. ValueError is raised if the HTMLForm has an | ||
3111 | 3107 | enctype attribute that is not recognised. | ||
3112 | 3108 | |||
3113 | 3109 | You can optionally specify a coordinate to click at, which only makes a | ||
3114 | 3110 | difference if you clicked on an image. | ||
3115 | 3111 | |||
3116 | 3112 | """ | ||
3117 | 3113 | return self._click(name, type, id, label, nr, coord, "request", | ||
3118 | 3114 | self._request_class) | ||
3119 | 3115 | |||
3120 | 3116 | def click_request_data(self, | ||
3121 | 3117 | name=None, type=None, id=None, | ||
3122 | 3118 | nr=0, coord=(1,1), | ||
3123 | 3119 | request_class=urllib2.Request, | ||
3124 | 3120 | label=None): | ||
3125 | 3121 | """As for click method, but return a tuple (url, data, headers). | ||
3126 | 3122 | |||
3127 | 3123 | You can use this data to send a request to the server. This is useful | ||
3128 | 3124 | if you're using httplib or urllib rather than urllib2. Otherwise, use | ||
3129 | 3125 | the click method. | ||
3130 | 3126 | |||
3131 | 3127 | # Untested. Have to subclass to add headers, I think -- so use urllib2 | ||
3132 | 3128 | # instead! | ||
3133 | 3129 | import urllib | ||
3134 | 3130 | url, data, hdrs = form.click_request_data() | ||
3135 | 3131 | r = urllib.urlopen(url, data) | ||
3136 | 3132 | |||
3137 | 3133 | # Untested. I don't know of any reason to use httplib -- you can get | ||
3138 | 3134 | # just as much control with urllib2. | ||
3139 | 3135 | import httplib, urlparse | ||
3140 | 3136 | url, data, hdrs = form.click_request_data() | ||
3141 | 3137 | tup = urlparse(url) | ||
3142 | 3138 | host, path = tup[1], urlparse.urlunparse((None, None)+tup[2:]) | ||
3143 | 3139 | conn = httplib.HTTPConnection(host) | ||
3144 | 3140 | if data: | ||
3145 | 3141 | httplib.request("POST", path, data, hdrs) | ||
3146 | 3142 | else: | ||
3147 | 3143 | httplib.request("GET", path, headers=hdrs) | ||
3148 | 3144 | r = conn.getresponse() | ||
3149 | 3145 | |||
3150 | 3146 | """ | ||
3151 | 3147 | return self._click(name, type, id, label, nr, coord, "request_data", | ||
3152 | 3148 | self._request_class) | ||
3153 | 3149 | |||
3154 | 3150 | def click_pairs(self, name=None, type=None, id=None, | ||
3155 | 3151 | nr=0, coord=(1,1), | ||
3156 | 3152 | label=None): | ||
3157 | 3153 | """As for click_request_data, but returns a list of (key, value) pairs. | ||
3158 | 3154 | |||
3159 | 3155 | You can use this list as an argument to ClientForm.urlencode. This is | ||
3160 | 3156 | usually only useful if you're using httplib or urllib rather than | ||
3161 | 3157 | urllib2 or ClientCookie. It may also be useful if you want to manually | ||
3162 | 3158 | tweak the keys and/or values, but this should not be necessary. | ||
3163 | 3159 | Otherwise, use the click method. | ||
3164 | 3160 | |||
3165 | 3161 | Note that this method is only useful for forms of MIME type | ||
3166 | 3162 | x-www-form-urlencoded. In particular, it does not return the | ||
3167 | 3163 | information required for file upload. If you need file upload and are | ||
3168 | 3164 | not using urllib2, use click_request_data. | ||
3169 | 3165 | |||
3170 | 3166 | Also note that Python 2.0's urllib.urlencode is slightly broken: it | ||
3171 | 3167 | only accepts a mapping, not a sequence of pairs, as an argument. This | ||
3172 | 3168 | messes up any ordering in the argument. Use ClientForm.urlencode | ||
3173 | 3169 | instead. | ||
3174 | 3170 | |||
3175 | 3171 | """ | ||
3176 | 3172 | return self._click(name, type, id, label, nr, coord, "pairs", | ||
3177 | 3173 | self._request_class) | ||
3178 | 3174 | |||
3179 | 3175 | #--------------------------------------------------- | ||
3180 | 3176 | |||
3181 | 3177 | def find_control(self, | ||
3182 | 3178 | name=None, type=None, kind=None, id=None, | ||
3183 | 3179 | predicate=None, nr=None, | ||
3184 | 3180 | label=None): | ||
3185 | 3181 | """Locate and return some specific control within the form. | ||
3186 | 3182 | |||
3187 | 3183 | At least one of the name, type, kind, predicate and nr arguments must | ||
3188 | 3184 | be supplied. If no matching control is found, ControlNotFoundError is | ||
3189 | 3185 | raised. | ||
3190 | 3186 | |||
3191 | 3187 | If name is specified, then the control must have the indicated name. | ||
3192 | 3188 | |||
3193 | 3189 | If type is specified then the control must have the specified type (in | ||
3194 | 3190 | addition to the types possible for <input> HTML tags: "text", | ||
3195 | 3191 | "password", "hidden", "submit", "image", "button", "radio", "checkbox", | ||
3196 | 3192 | "file" we also have "reset", "buttonbutton", "submitbutton", | ||
3197 | 3193 | "resetbutton", "textarea", "select" and "isindex"). | ||
3198 | 3194 | |||
3199 | 3195 | If kind is specified, then the control must fall into the specified | ||
3200 | 3196 | group, each of which satisfies a particular interface. The types are | ||
3201 | 3197 | "text", "list", "multilist", "singlelist", "clickable" and "file". | ||
3202 | 3198 | |||
3203 | 3199 | If id is specified, then the control must have the indicated id. | ||
3204 | 3200 | |||
3205 | 3201 | If predicate is specified, then the control must match that function. | ||
3206 | 3202 | The predicate function is passed the control as its single argument, | ||
3207 | 3203 | and should return a boolean value indicating whether the control | ||
3208 | 3204 | matched. | ||
3209 | 3205 | |||
3210 | 3206 | nr, if supplied, is the sequence number of the control (where 0 is the | ||
3211 | 3207 | first). Note that control 0 is the first control matching all the | ||
3212 | 3208 | other arguments (if supplied); it is not necessarily the first control | ||
3213 | 3209 | in the form. If no nr is supplied, AmbiguityError is raised if | ||
3214 | 3210 | multiple controls match the other arguments (unless the | ||
3215 | 3211 | .backwards-compat attribute is true). | ||
3216 | 3212 | |||
3217 | 3213 | If label is specified, then the control must have this label. Note | ||
3218 | 3214 | that radio controls and checkboxes never have labels: their items do. | ||
3219 | 3215 | |||
3220 | 3216 | """ | ||
3221 | 3217 | if ((name is None) and (type is None) and (kind is None) and | ||
3222 | 3218 | (id is None) and (label is None) and (predicate is None) and | ||
3223 | 3219 | (nr is None)): | ||
3224 | 3220 | raise ValueError( | ||
3225 | 3221 | "at least one argument must be supplied to specify control") | ||
3226 | 3222 | return self._find_control(name, type, kind, id, label, predicate, nr) | ||
3227 | 3223 | |||
3228 | 3224 | #--------------------------------------------------- | ||
3229 | 3225 | # Private methods. | ||
3230 | 3226 | |||
3231 | 3227 | def _find_list_control(self, | ||
3232 | 3228 | name=None, type=None, kind=None, id=None, | ||
3233 | 3229 | label=None, nr=None): | ||
3234 | 3230 | if ((name is None) and (type is None) and (kind is None) and | ||
3235 | 3231 | (id is None) and (label is None) and (nr is None)): | ||
3236 | 3232 | raise ValueError( | ||
3237 | 3233 | "at least one argument must be supplied to specify control") | ||
3238 | 3234 | |||
3239 | 3235 | return self._find_control(name, type, kind, id, label, | ||
3240 | 3236 | is_listcontrol, nr) | ||
3241 | 3237 | |||
3242 | 3238 | def _find_control(self, name, type, kind, id, label, predicate, nr): | ||
3243 | 3239 | if ((name is not None) and (name is not Missing) and | ||
3244 | 3240 | not isstringlike(name)): | ||
3245 | 3241 | raise TypeError("control name must be string-like") | ||
3246 | 3242 | if (type is not None) and not isstringlike(type): | ||
3247 | 3243 | raise TypeError("control type must be string-like") | ||
3248 | 3244 | if (kind is not None) and not isstringlike(kind): | ||
3249 | 3245 | raise TypeError("control kind must be string-like") | ||
3250 | 3246 | if (id is not None) and not isstringlike(id): | ||
3251 | 3247 | raise TypeError("control id must be string-like") | ||
3252 | 3248 | if (label is not None) and not isstringlike(label): | ||
3253 | 3249 | raise TypeError("control label must be string-like") | ||
3254 | 3250 | if (predicate is not None) and not callable(predicate): | ||
3255 | 3251 | raise TypeError("control predicate must be callable") | ||
3256 | 3252 | if (nr is not None) and nr < 0: | ||
3257 | 3253 | raise ValueError("control number must be a positive integer") | ||
3258 | 3254 | |||
3259 | 3255 | orig_nr = nr | ||
3260 | 3256 | found = None | ||
3261 | 3257 | ambiguous = False | ||
3262 | 3258 | if nr is None and self.backwards_compat: | ||
3263 | 3259 | nr = 0 | ||
3264 | 3260 | |||
3265 | 3261 | for control in self.controls: | ||
3266 | 3262 | if ((name is not None and name != control.name) and | ||
3267 | 3263 | (name is not Missing or control.name is not None)): | ||
3268 | 3264 | continue | ||
3269 | 3265 | if type is not None and type != control.type: | ||
3270 | 3266 | continue | ||
3271 | 3267 | if kind is not None and not control.is_of_kind(kind): | ||
3272 | 3268 | continue | ||
3273 | 3269 | if id is not None and id != control.id: | ||
3274 | 3270 | continue | ||
3275 | 3271 | if predicate and not predicate(control): | ||
3276 | 3272 | continue | ||
3277 | 3273 | if label: | ||
3278 | 3274 | for l in control.get_labels(): | ||
3279 | 3275 | if l.text.find(label) > -1: | ||
3280 | 3276 | break | ||
3281 | 3277 | else: | ||
3282 | 3278 | continue | ||
3283 | 3279 | if nr is not None: | ||
3284 | 3280 | if nr == 0: | ||
3285 | 3281 | return control # early exit: unambiguous due to nr | ||
3286 | 3282 | nr -= 1 | ||
3287 | 3283 | continue | ||
3288 | 3284 | if found: | ||
3289 | 3285 | ambiguous = True | ||
3290 | 3286 | break | ||
3291 | 3287 | found = control | ||
3292 | 3288 | |||
3293 | 3289 | if found and not ambiguous: | ||
3294 | 3290 | return found | ||
3295 | 3291 | |||
3296 | 3292 | description = [] | ||
3297 | 3293 | if name is not None: description.append("name %s" % repr(name)) | ||
3298 | 3294 | if type is not None: description.append("type '%s'" % type) | ||
3299 | 3295 | if kind is not None: description.append("kind '%s'" % kind) | ||
3300 | 3296 | if id is not None: description.append("id '%s'" % id) | ||
3301 | 3297 | if label is not None: description.append("label '%s'" % label) | ||
3302 | 3298 | if predicate is not None: | ||
3303 | 3299 | description.append("predicate %s" % predicate) | ||
3304 | 3300 | if orig_nr: description.append("nr %d" % orig_nr) | ||
3305 | 3301 | description = ", ".join(description) | ||
3306 | 3302 | |||
3307 | 3303 | if ambiguous: | ||
3308 | 3304 | raise AmbiguityError("more than one control matching "+description) | ||
3309 | 3305 | elif not found: | ||
3310 | 3306 | raise ControlNotFoundError("no control matching "+description) | ||
3311 | 3307 | assert False | ||
3312 | 3308 | |||
3313 | 3309 | def _click(self, name, type, id, label, nr, coord, return_type, | ||
3314 | 3310 | request_class=urllib2.Request): | ||
3315 | 3311 | try: | ||
3316 | 3312 | control = self._find_control( | ||
3317 | 3313 | name, type, "clickable", id, label, None, nr) | ||
3318 | 3314 | except ControlNotFoundError: | ||
3319 | 3315 | if ((name is not None) or (type is not None) or (id is not None) or | ||
3320 | 3316 | (nr != 0)): | ||
3321 | 3317 | raise | ||
3322 | 3318 | # no clickable controls, but no control was explicitly requested, | ||
3323 | 3319 | # so return state without clicking any control | ||
3324 | 3320 | return self._switch_click(return_type, request_class) | ||
3325 | 3321 | else: | ||
3326 | 3322 | return control._click(self, coord, return_type, request_class) | ||
3327 | 3323 | |||
3328 | 3324 | def _pairs(self): | ||
3329 | 3325 | """Return sequence of (key, value) pairs suitable for urlencoding.""" | ||
3330 | 3326 | return [(k, v) for (i, k, v, c_i) in self._pairs_and_controls()] | ||
3331 | 3327 | |||
3332 | 3328 | |||
3333 | 3329 | def _pairs_and_controls(self): | ||
3334 | 3330 | """Return sequence of (index, key, value, control_index) | ||
3335 | 3331 | of totally ordered pairs suitable for urlencoding. | ||
3336 | 3332 | |||
3337 | 3333 | control_index is the index of the control in self.controls | ||
3338 | 3334 | """ | ||
3339 | 3335 | pairs = [] | ||
3340 | 3336 | for control_index in range(len(self.controls)): | ||
3341 | 3337 | control = self.controls[control_index] | ||
3342 | 3338 | for ii, key, val in control._totally_ordered_pairs(): | ||
3343 | 3339 | pairs.append((ii, key, val, control_index)) | ||
3344 | 3340 | |||
3345 | 3341 | # stable sort by ONLY first item in tuple | ||
3346 | 3342 | pairs.sort() | ||
3347 | 3343 | |||
3348 | 3344 | return pairs | ||
3349 | 3345 | |||
3350 | 3346 | def _request_data(self): | ||
3351 | 3347 | """Return a tuple (url, data, headers).""" | ||
3352 | 3348 | method = self.method.upper() | ||
3353 | 3349 | #scheme, netloc, path, parameters, query, frag = urlparse.urlparse(self.action) | ||
3354 | 3350 | parts = self._urlparse(self.action) | ||
3355 | 3351 | rest, (query, frag) = parts[:-2], parts[-2:] | ||
3356 | 3352 | |||
3357 | 3353 | if method == "GET": | ||
3358 | 3354 | if self.enctype != "application/x-www-form-urlencoded": | ||
3359 | 3355 | raise ValueError( | ||
3360 | 3356 | "unknown GET form encoding type '%s'" % self.enctype) | ||
3361 | 3357 | parts = rest + (urlencode(self._pairs()), None) | ||
3362 | 3358 | uri = self._urlunparse(parts) | ||
3363 | 3359 | return uri, None, [] | ||
3364 | 3360 | elif method == "POST": | ||
3365 | 3361 | parts = rest + (query, None) | ||
3366 | 3362 | uri = self._urlunparse(parts) | ||
3367 | 3363 | if self.enctype == "application/x-www-form-urlencoded": | ||
3368 | 3364 | return (uri, urlencode(self._pairs()), | ||
3369 | 3365 | [("Content-Type", self.enctype)]) | ||
3370 | 3366 | elif self.enctype == "multipart/form-data": | ||
3371 | 3367 | data = StringIO() | ||
3372 | 3368 | http_hdrs = [] | ||
3373 | 3369 | mw = MimeWriter(data, http_hdrs) | ||
3374 | 3370 | f = mw.startmultipartbody("form-data", add_to_http_hdrs=True, | ||
3375 | 3371 | prefix=0) | ||
3376 | 3372 | for ii, k, v, control_index in self._pairs_and_controls(): | ||
3377 | 3373 | self.controls[control_index]._write_mime_data(mw, k, v) | ||
3378 | 3374 | mw.lastpart() | ||
3379 | 3375 | return uri, data.getvalue(), http_hdrs | ||
3380 | 3376 | else: | ||
3381 | 3377 | raise ValueError( | ||
3382 | 3378 | "unknown POST form encoding type '%s'" % self.enctype) | ||
3383 | 3379 | else: | ||
3384 | 3380 | raise ValueError("Unknown method '%s'" % method) | ||
3385 | 3381 | |||
3386 | 3382 | def _switch_click(self, return_type, request_class=urllib2.Request): | ||
3387 | 3383 | # This is called by HTMLForm and clickable Controls to hide switching | ||
3388 | 3384 | # on return_type. | ||
3389 | 3385 | if return_type == "pairs": | ||
3390 | 3386 | return self._pairs() | ||
3391 | 3387 | elif return_type == "request_data": | ||
3392 | 3388 | return self._request_data() | ||
3393 | 3389 | else: | ||
3394 | 3390 | req_data = self._request_data() | ||
3395 | 3391 | req = request_class(req_data[0], req_data[1]) | ||
3396 | 3392 | for key, val in req_data[2]: | ||
3397 | 3393 | add_hdr = req.add_header | ||
3398 | 3394 | if key.lower() == "content-type": | ||
3399 | 3395 | try: | ||
3400 | 3396 | add_hdr = req.add_unredirected_header | ||
3401 | 3397 | except AttributeError: | ||
3402 | 3398 | # pre-2.4 and not using ClientCookie | ||
3403 | 3399 | pass | ||
3404 | 3400 | add_hdr(key, val) | ||
3405 | 3401 | return req | ||
3406 | 3402 | 0 | ||
3407 | === modified file 'src/ZConfig/__init__.py' | |||
3408 | --- src/ZConfig/__init__.py 2010-03-01 20:29:16 +0000 | |||
3409 | +++ src/ZConfig/__init__.py 2010-07-01 19:15:41 +0000 | |||
3410 | @@ -1,6 +1,6 @@ | |||
3411 | 1 | ############################################################################## | 1 | ############################################################################## |
3412 | 2 | # | 2 | # |
3414 | 3 | # Copyright (c) 2002, 2003 Zope Corporation and Contributors. | 3 | # Copyright (c) 2002, 2003 Zope Foundation and Contributors. |
3415 | 4 | # All Rights Reserved. | 4 | # All Rights Reserved. |
3416 | 5 | # | 5 | # |
3417 | 6 | # This software is subject to the provisions of the Zope Public License, | 6 | # This software is subject to the provisions of the Zope Public License, |
3418 | 7 | 7 | ||
3419 | === modified file 'src/ZConfig/cfgparser.py' | |||
3420 | --- src/ZConfig/cfgparser.py 2009-04-23 15:12:18 +0000 | |||
3421 | +++ src/ZConfig/cfgparser.py 2010-07-01 19:15:41 +0000 | |||
3422 | @@ -1,6 +1,6 @@ | |||
3423 | 1 | ############################################################################## | 1 | ############################################################################## |
3424 | 2 | # | 2 | # |
3426 | 3 | # Copyright (c) 2002, 2003 Zope Corporation and Contributors. | 3 | # Copyright (c) 2002, 2003 Zope Foundation and Contributors. |
3427 | 4 | # All Rights Reserved. | 4 | # All Rights Reserved. |
3428 | 5 | # | 5 | # |
3429 | 6 | # This software is subject to the provisions of the Zope Public License, | 6 | # This software is subject to the provisions of the Zope Public License, |
3430 | 7 | 7 | ||
3431 | === modified file 'src/ZConfig/cmdline.py' | |||
3432 | --- src/ZConfig/cmdline.py 2009-04-23 15:12:18 +0000 | |||
3433 | +++ src/ZConfig/cmdline.py 2010-07-01 19:15:41 +0000 | |||
3434 | @@ -1,6 +1,6 @@ | |||
3435 | 1 | ############################################################################## | 1 | ############################################################################## |
3436 | 2 | # | 2 | # |
3438 | 3 | # Copyright (c) 2003 Zope Corporation and Contributors. | 3 | # Copyright (c) 2003 Zope Foundation and Contributors. |
3439 | 4 | # All Rights Reserved. | 4 | # All Rights Reserved. |
3440 | 5 | # | 5 | # |
3441 | 6 | # This software is subject to the provisions of the Zope Public License, | 6 | # This software is subject to the provisions of the Zope Public License, |
3442 | 7 | 7 | ||
3443 | === modified file 'src/ZConfig/components/basic/mapping.py' | |||
3444 | --- src/ZConfig/components/basic/mapping.py 2009-04-23 15:12:18 +0000 | |||
3445 | +++ src/ZConfig/components/basic/mapping.py 2010-07-01 19:15:41 +0000 | |||
3446 | @@ -1,6 +1,6 @@ | |||
3447 | 1 | ############################################################################## | 1 | ############################################################################## |
3448 | 2 | # | 2 | # |
3450 | 3 | # Copyright (c) 2003 Zope Corporation and Contributors. | 3 | # Copyright (c) 2003 Zope Foundation and Contributors. |
3451 | 4 | # All Rights Reserved. | 4 | # All Rights Reserved. |
3452 | 5 | # | 5 | # |
3453 | 6 | # This software is subject to the provisions of the Zope Public License, | 6 | # This software is subject to the provisions of the Zope Public License, |
3454 | 7 | 7 | ||
3455 | === modified file 'src/ZConfig/components/basic/tests/test_mapping.py' | |||
3456 | --- src/ZConfig/components/basic/tests/test_mapping.py 2009-04-23 15:12:18 +0000 | |||
3457 | +++ src/ZConfig/components/basic/tests/test_mapping.py 2010-07-01 19:15:41 +0000 | |||
3458 | @@ -1,6 +1,6 @@ | |||
3459 | 1 | ############################################################################## | 1 | ############################################################################## |
3460 | 2 | # | 2 | # |
3462 | 3 | # Copyright (c) 2003 Zope Corporation and Contributors. | 3 | # Copyright (c) 2003 Zope Foundation and Contributors. |
3463 | 4 | # All Rights Reserved. | 4 | # All Rights Reserved. |
3464 | 5 | # | 5 | # |
3465 | 6 | # This software is subject to the provisions of the Zope Public License, | 6 | # This software is subject to the provisions of the Zope Public License, |
3466 | 7 | 7 | ||
3467 | === modified file 'src/ZConfig/components/logger/__init__.py' | |||
3468 | --- src/ZConfig/components/logger/__init__.py 2009-04-23 15:12:18 +0000 | |||
3469 | +++ src/ZConfig/components/logger/__init__.py 2010-07-01 19:15:41 +0000 | |||
3470 | @@ -1,6 +1,6 @@ | |||
3471 | 1 | ############################################################################## | 1 | ############################################################################## |
3472 | 2 | # | 2 | # |
3474 | 3 | # Copyright (c) 2003 Zope Corporation and Contributors. | 3 | # Copyright (c) 2003 Zope Foundation and Contributors. |
3475 | 4 | # All Rights Reserved. | 4 | # All Rights Reserved. |
3476 | 5 | # | 5 | # |
3477 | 6 | # This software is subject to the provisions of the Zope Public License, | 6 | # This software is subject to the provisions of the Zope Public License, |
3478 | 7 | 7 | ||
3479 | === modified file 'src/ZConfig/components/logger/datatypes.py' | |||
3480 | --- src/ZConfig/components/logger/datatypes.py 2009-04-23 15:12:18 +0000 | |||
3481 | +++ src/ZConfig/components/logger/datatypes.py 2010-07-01 19:15:41 +0000 | |||
3482 | @@ -1,6 +1,6 @@ | |||
3483 | 1 | ############################################################################## | 1 | ############################################################################## |
3484 | 2 | # | 2 | # |
3486 | 3 | # Copyright (c) 2002 Zope Corporation and Contributors. All Rights Reserved. | 3 | # Copyright (c) 2002 Zope Foundation and Contributors. |
3487 | 4 | # | 4 | # |
3488 | 5 | # This software is subject to the provisions of the Zope Public License, | 5 | # This software is subject to the provisions of the Zope Public License, |
3489 | 6 | # Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. | 6 | # Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. |
3490 | 7 | 7 | ||
3491 | === modified file 'src/ZConfig/components/logger/factory.py' | |||
3492 | --- src/ZConfig/components/logger/factory.py 2009-04-23 15:12:18 +0000 | |||
3493 | +++ src/ZConfig/components/logger/factory.py 2010-07-01 19:15:41 +0000 | |||
3494 | @@ -1,6 +1,6 @@ | |||
3495 | 1 | ############################################################################## | 1 | ############################################################################## |
3496 | 2 | # | 2 | # |
3498 | 3 | # Copyright (c) 2002 Zope Corporation and Contributors. | 3 | # Copyright (c) 2002 Zope Foundation and Contributors. |
3499 | 4 | # All Rights Reserved. | 4 | # All Rights Reserved. |
3500 | 5 | # | 5 | # |
3501 | 6 | # This software is subject to the provisions of the Zope Public License, | 6 | # This software is subject to the provisions of the Zope Public License, |
3502 | 7 | 7 | ||
3503 | === modified file 'src/ZConfig/components/logger/handlers.py' | |||
3504 | --- src/ZConfig/components/logger/handlers.py 2010-03-01 20:29:16 +0000 | |||
3505 | +++ src/ZConfig/components/logger/handlers.py 2010-07-01 19:15:41 +0000 | |||
3506 | @@ -1,6 +1,6 @@ | |||
3507 | 1 | ############################################################################## | 1 | ############################################################################## |
3508 | 2 | # | 2 | # |
3510 | 3 | # Copyright (c) 2003 Zope Corporation and Contributors. | 3 | # Copyright (c) 2003 Zope Foundation and Contributors. |
3511 | 4 | # All Rights Reserved. | 4 | # All Rights Reserved. |
3512 | 5 | # | 5 | # |
3513 | 6 | # This software is subject to the provisions of the Zope Public License, | 6 | # This software is subject to the provisions of the Zope Public License, |
3514 | @@ -212,7 +212,20 @@ | |||
3515 | 212 | mailhost = host | 212 | mailhost = host |
3516 | 213 | else: | 213 | else: |
3517 | 214 | mailhost = host, port | 214 | mailhost = host, port |
3518 | 215 | kwargs = {} | ||
3519 | 216 | if self.section.smtp_username and self.section.smtp_password: | ||
3520 | 217 | # Since credentials were only added in py2.6 we use a kwarg to not | ||
3521 | 218 | # break compatibility with older py | ||
3522 | 219 | if sys.version_info < (2, 6): | ||
3523 | 220 | raise ValueError('SMTP auth requires at least Python 2.6.') | ||
3524 | 221 | kwargs['credentials'] = (self.section.smtp_username, | ||
3525 | 222 | self.section.smtp_password) | ||
3526 | 223 | elif (self.section.smtp_username or self.section.smtp_password): | ||
3527 | 224 | raise ValueError( | ||
3528 | 225 | 'Either both smtp-username and smtp-password or none must be ' | ||
3529 | 226 | 'given') | ||
3530 | 215 | return loghandler.SMTPHandler(mailhost, | 227 | return loghandler.SMTPHandler(mailhost, |
3531 | 216 | self.section.fromaddr, | 228 | self.section.fromaddr, |
3532 | 217 | self.section.toaddrs, | 229 | self.section.toaddrs, |
3534 | 218 | self.section.subject) | 230 | self.section.subject, |
3535 | 231 | **kwargs) | ||
3536 | 219 | 232 | ||
3537 | === modified file 'src/ZConfig/components/logger/handlers.xml' | |||
3538 | --- src/ZConfig/components/logger/handlers.xml 2010-03-01 20:29:16 +0000 | |||
3539 | +++ src/ZConfig/components/logger/handlers.xml 2010-07-01 19:15:41 +0000 | |||
3540 | @@ -79,6 +79,8 @@ | |||
3541 | 79 | <multikey name="to" required="yes" attribute="toaddrs"/> | 79 | <multikey name="to" required="yes" attribute="toaddrs"/> |
3542 | 80 | <key name="subject" default="Message from Zope"/> | 80 | <key name="subject" default="Message from Zope"/> |
3543 | 81 | <key name="smtp-server" default="localhost" datatype="inet-address"/> | 81 | <key name="smtp-server" default="localhost" datatype="inet-address"/> |
3544 | 82 | <key name="smtp-username" default="" datatype="string"/> | ||
3545 | 83 | <key name="smtp-password" default="" datatype="string"/> | ||
3546 | 82 | <key name="format" | 84 | <key name="format" |
3547 | 83 | default="%(asctime)s %(levelname)s %(name)s %(message)s" | 85 | default="%(asctime)s %(levelname)s %(name)s %(message)s" |
3548 | 84 | datatype=".log_format"/> | 86 | datatype=".log_format"/> |
3549 | 85 | 87 | ||
3550 | === modified file 'src/ZConfig/components/logger/logger.py' | |||
3551 | --- src/ZConfig/components/logger/logger.py 2009-04-23 15:12:18 +0000 | |||
3552 | +++ src/ZConfig/components/logger/logger.py 2010-07-01 19:15:41 +0000 | |||
3553 | @@ -1,6 +1,6 @@ | |||
3554 | 1 | ############################################################################## | 1 | ############################################################################## |
3555 | 2 | # | 2 | # |
3557 | 3 | # Copyright (c) 2003 Zope Corporation and Contributors. | 3 | # Copyright (c) 2003 Zope Foundation and Contributors. |
3558 | 4 | # All Rights Reserved. | 4 | # All Rights Reserved. |
3559 | 5 | # | 5 | # |
3560 | 6 | # This software is subject to the provisions of the Zope Public License, | 6 | # This software is subject to the provisions of the Zope Public License, |
3561 | 7 | 7 | ||
3562 | === modified file 'src/ZConfig/components/logger/loghandler.py' | |||
3563 | --- src/ZConfig/components/logger/loghandler.py 2010-03-01 20:29:16 +0000 | |||
3564 | +++ src/ZConfig/components/logger/loghandler.py 2010-07-01 19:15:41 +0000 | |||
3565 | @@ -1,6 +1,6 @@ | |||
3566 | 1 | ############################################################################## | 1 | ############################################################################## |
3567 | 2 | # | 2 | # |
3569 | 3 | # Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved. | 3 | # Copyright (c) 2001 Zope Foundation and Contributors. |
3570 | 4 | # | 4 | # |
3571 | 5 | # This software is subject to the provisions of the Zope Public License, | 5 | # This software is subject to the provisions of the Zope Public License, |
3572 | 6 | # Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. | 6 | # Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. |
3573 | 7 | 7 | ||
3574 | === modified file 'src/ZConfig/components/logger/tests/test_logger.py' | |||
3575 | --- src/ZConfig/components/logger/tests/test_logger.py 2010-03-01 20:29:16 +0000 | |||
3576 | +++ src/ZConfig/components/logger/tests/test_logger.py 2010-07-01 19:15:41 +0000 | |||
3577 | @@ -1,6 +1,6 @@ | |||
3578 | 1 | ############################################################################## | 1 | ############################################################################## |
3579 | 2 | # | 2 | # |
3581 | 3 | # Copyright (c) 2002 Zope Corporation and Contributors. | 3 | # Copyright (c) 2002 Zope Foundation and Contributors. |
3582 | 4 | # All Rights Reserved. | 4 | # All Rights Reserved. |
3583 | 5 | # | 5 | # |
3584 | 6 | # This software is subject to the provisions of the Zope Public License, | 6 | # This software is subject to the provisions of the Zope Public License, |
3585 | @@ -346,6 +346,54 @@ | |||
3586 | 346 | self.assertEqual(handler.fromaddr, "zlog-user@example.com") | 346 | self.assertEqual(handler.fromaddr, "zlog-user@example.com") |
3587 | 347 | self.assertEqual(handler.level, logging.FATAL) | 347 | self.assertEqual(handler.level, logging.FATAL) |
3588 | 348 | 348 | ||
3589 | 349 | def test_with_email_notifier_with_credentials(self): | ||
3590 | 350 | try: | ||
3591 | 351 | logger = self.check_simple_logger("<eventlog>\n" | ||
3592 | 352 | " <email-notifier>\n" | ||
3593 | 353 | " to sysadmin@example.com\n" | ||
3594 | 354 | " from zlog-user@example.com\n" | ||
3595 | 355 | " level fatal\n" | ||
3596 | 356 | " smtp-username john\n" | ||
3597 | 357 | " smtp-password johnpw\n" | ||
3598 | 358 | " </email-notifier>\n" | ||
3599 | 359 | "</eventlog>") | ||
3600 | 360 | except ValueError: | ||
3601 | 361 | if sys.version_info >= (2, 6): | ||
3602 | 362 | # For python 2.6 no ValueError must be raised. | ||
3603 | 363 | raise | ||
3604 | 364 | else: | ||
3605 | 365 | # This path must only be reached with python >=2.6 | ||
3606 | 366 | self.assert_(sys.version_info >= (2, 6)) | ||
3607 | 367 | handler = logger.handlers[0] | ||
3608 | 368 | self.assertEqual(handler.toaddrs, ["sysadmin@example.com"]) | ||
3609 | 369 | self.assertEqual(handler.fromaddr, "zlog-user@example.com") | ||
3610 | 370 | self.assertEqual(handler.fromaddr, "zlog-user@example.com") | ||
3611 | 371 | self.assertEqual(handler.level, logging.FATAL) | ||
3612 | 372 | self.assertEqual(handler.username, 'john') | ||
3613 | 373 | self.assertEqual(handler.password, 'johnpw') | ||
3614 | 374 | |||
3615 | 375 | def test_with_email_notifier_with_invalid_credentials(self): | ||
3616 | 376 | self.assertRaises(ValueError, | ||
3617 | 377 | self.check_simple_logger, | ||
3618 | 378 | "<eventlog>\n" | ||
3619 | 379 | " <email-notifier>\n" | ||
3620 | 380 | " to sysadmin@example.com\n" | ||
3621 | 381 | " from zlog-user@example.com\n" | ||
3622 | 382 | " level fatal\n" | ||
3623 | 383 | " smtp-username john\n" | ||
3624 | 384 | " </email-notifier>\n" | ||
3625 | 385 | "</eventlog>") | ||
3626 | 386 | self.assertRaises(ValueError, | ||
3627 | 387 | self.check_simple_logger, | ||
3628 | 388 | "<eventlog>\n" | ||
3629 | 389 | " <email-notifier>\n" | ||
3630 | 390 | " to sysadmin@example.com\n" | ||
3631 | 391 | " from zlog-user@example.com\n" | ||
3632 | 392 | " level fatal\n" | ||
3633 | 393 | " smtp-password john\n" | ||
3634 | 394 | " </email-notifier>\n" | ||
3635 | 395 | "</eventlog>") | ||
3636 | 396 | |||
3637 | 349 | def check_simple_logger(self, text, level=logging.INFO): | 397 | def check_simple_logger(self, text, level=logging.INFO): |
3638 | 350 | conf = self.get_config(text) | 398 | conf = self.get_config(text) |
3639 | 351 | self.assert_(conf.eventlog is not None) | 399 | self.assert_(conf.eventlog is not None) |
3640 | 352 | 400 | ||
3641 | === modified file 'src/ZConfig/datatypes.py' | |||
3642 | --- src/ZConfig/datatypes.py 2009-04-23 15:12:18 +0000 | |||
3643 | +++ src/ZConfig/datatypes.py 2010-07-01 19:15:41 +0000 | |||
3644 | @@ -1,6 +1,6 @@ | |||
3645 | 1 | ############################################################################## | 1 | ############################################################################## |
3646 | 2 | # | 2 | # |
3648 | 3 | # Copyright (c) 2002, 2003 Zope Corporation and Contributors. | 3 | # Copyright (c) 2002, 2003 Zope Foundation and Contributors. |
3649 | 4 | # All Rights Reserved. | 4 | # All Rights Reserved. |
3650 | 5 | # | 5 | # |
3651 | 6 | # This software is subject to the provisions of the Zope Public License, | 6 | # This software is subject to the provisions of the Zope Public License, |
3652 | 7 | 7 | ||
3653 | === modified file 'src/ZConfig/info.py' | |||
3654 | --- src/ZConfig/info.py 2009-04-23 15:12:18 +0000 | |||
3655 | +++ src/ZConfig/info.py 2010-07-01 19:15:41 +0000 | |||
3656 | @@ -1,6 +1,6 @@ | |||
3657 | 1 | ############################################################################## | 1 | ############################################################################## |
3658 | 2 | # | 2 | # |
3660 | 3 | # Copyright (c) 2002, 2003 Zope Corporation and Contributors. | 3 | # Copyright (c) 2002, 2003 Zope Foundation and Contributors. |
3661 | 4 | # All Rights Reserved. | 4 | # All Rights Reserved. |
3662 | 5 | # | 5 | # |
3663 | 6 | # This software is subject to the provisions of the Zope Public License, | 6 | # This software is subject to the provisions of the Zope Public License, |
3664 | 7 | 7 | ||
3665 | === modified file 'src/ZConfig/loader.py' | |||
3666 | --- src/ZConfig/loader.py 2009-04-23 15:12:18 +0000 | |||
3667 | +++ src/ZConfig/loader.py 2010-07-01 19:15:41 +0000 | |||
3668 | @@ -1,6 +1,6 @@ | |||
3669 | 1 | ############################################################################## | 1 | ############################################################################## |
3670 | 2 | # | 2 | # |
3672 | 3 | # Copyright (c) 2002, 2003 Zope Corporation and Contributors. | 3 | # Copyright (c) 2002, 2003 Zope Foundation and Contributors. |
3673 | 4 | # All Rights Reserved. | 4 | # All Rights Reserved. |
3674 | 5 | # | 5 | # |
3675 | 6 | # This software is subject to the provisions of the Zope Public License, | 6 | # This software is subject to the provisions of the Zope Public License, |
3676 | @@ -15,6 +15,7 @@ | |||
3677 | 15 | 15 | ||
3678 | 16 | import cStringIO | 16 | import cStringIO |
3679 | 17 | import os.path | 17 | import os.path |
3680 | 18 | import re | ||
3681 | 18 | import sys | 19 | import sys |
3682 | 19 | import urllib | 20 | import urllib |
3683 | 20 | import urllib2 | 21 | import urllib2 |
3684 | @@ -128,14 +129,21 @@ | |||
3685 | 128 | url) | 129 | url) |
3686 | 129 | return newurl | 130 | return newurl |
3687 | 130 | 131 | ||
3688 | 132 | # from RFC 3986: | ||
3689 | 133 | # schema = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." ) | ||
3690 | 134 | _pathsep_rx = re.compile(r"[a-zA-Z][-+.a-zA-Z0-9]*:") | ||
3691 | 135 | |||
3692 | 131 | def isPath(self, s): | 136 | def isPath(self, s): |
3693 | 132 | """Return True iff 's' should be handled as a filesystem path.""" | 137 | """Return True iff 's' should be handled as a filesystem path.""" |
3694 | 133 | if ":" in s: | 138 | if ":" in s: |
3695 | 134 | # XXX This assumes that one-character scheme identifiers | 139 | # XXX This assumes that one-character scheme identifiers |
3696 | 135 | # are always Windows drive letters; I don't know of any | 140 | # are always Windows drive letters; I don't know of any |
3697 | 136 | # one-character scheme identifiers. | 141 | # one-character scheme identifiers. |
3700 | 137 | scheme, rest = urllib.splittype(s) | 142 | m = self._pathsep_rx.match(s) |
3701 | 138 | return len(scheme) == 1 | 143 | if m is None: |
3702 | 144 | return True | ||
3703 | 145 | # Does it look like a drive letter? | ||
3704 | 146 | return len(m.group(0)) == 2 | ||
3705 | 139 | else: | 147 | else: |
3706 | 140 | return True | 148 | return True |
3707 | 141 | 149 | ||
3708 | 142 | 150 | ||
3709 | === modified file 'src/ZConfig/matcher.py' | |||
3710 | --- src/ZConfig/matcher.py 2009-04-23 15:12:18 +0000 | |||
3711 | +++ src/ZConfig/matcher.py 2010-07-01 19:15:41 +0000 | |||
3712 | @@ -1,6 +1,6 @@ | |||
3713 | 1 | ############################################################################## | 1 | ############################################################################## |
3714 | 2 | # | 2 | # |
3716 | 3 | # Copyright (c) 2002, 2003 Zope Corporation and Contributors. | 3 | # Copyright (c) 2002, 2003 Zope Foundation and Contributors. |
3717 | 4 | # All Rights Reserved. | 4 | # All Rights Reserved. |
3718 | 5 | # | 5 | # |
3719 | 6 | # This software is subject to the provisions of the Zope Public License, | 6 | # This software is subject to the provisions of the Zope Public License, |
3720 | 7 | 7 | ||
3721 | === modified file 'src/ZConfig/schema.py' | |||
3722 | --- src/ZConfig/schema.py 2010-03-01 20:29:16 +0000 | |||
3723 | +++ src/ZConfig/schema.py 2010-07-01 19:15:41 +0000 | |||
3724 | @@ -1,6 +1,6 @@ | |||
3725 | 1 | ############################################################################## | 1 | ############################################################################## |
3726 | 2 | # | 2 | # |
3728 | 3 | # Copyright (c) 2002, 2003 Zope Corporation and Contributors. | 3 | # Copyright (c) 2002, 2003 Zope Foundation and Contributors. |
3729 | 4 | # All Rights Reserved. | 4 | # All Rights Reserved. |
3730 | 5 | # | 5 | # |
3731 | 6 | # This software is subject to the provisions of the Zope Public License, | 6 | # This software is subject to the provisions of the Zope Public License, |
3732 | 7 | 7 | ||
3733 | === modified file 'src/ZConfig/schemaless.py' | |||
3734 | --- src/ZConfig/schemaless.py 2009-04-23 15:12:18 +0000 | |||
3735 | +++ src/ZConfig/schemaless.py 2010-07-01 19:15:41 +0000 | |||
3736 | @@ -1,6 +1,6 @@ | |||
3737 | 1 | ############################################################################## | 1 | ############################################################################## |
3738 | 2 | # | 2 | # |
3740 | 3 | # Copyright (c) 2007 Zope Corporation and Contributors. | 3 | # Copyright (c) 2007 Zope Foundation and Contributors. |
3741 | 4 | # All Rights Reserved. | 4 | # All Rights Reserved. |
3742 | 5 | # | 5 | # |
3743 | 6 | # This software is subject to the provisions of the Zope Public License, | 6 | # This software is subject to the provisions of the Zope Public License, |
3744 | 7 | 7 | ||
3745 | === modified file 'src/ZConfig/substitution.py' | |||
3746 | --- src/ZConfig/substitution.py 2009-04-23 15:12:18 +0000 | |||
3747 | +++ src/ZConfig/substitution.py 2010-07-01 19:15:41 +0000 | |||
3748 | @@ -1,6 +1,6 @@ | |||
3749 | 1 | ############################################################################## | 1 | ############################################################################## |
3750 | 2 | # | 2 | # |
3752 | 3 | # Copyright (c) 2002, 2003 Zope Corporation and Contributors. | 3 | # Copyright (c) 2002, 2003 Zope Foundation and Contributors. |
3753 | 4 | # All Rights Reserved. | 4 | # All Rights Reserved. |
3754 | 5 | # | 5 | # |
3755 | 6 | # This software is subject to the provisions of the Zope Public License, | 6 | # This software is subject to the provisions of the Zope Public License, |
3756 | 7 | 7 | ||
3757 | === modified file 'src/ZConfig/tests/__init__.py' | |||
3758 | --- src/ZConfig/tests/__init__.py 2009-04-23 15:12:18 +0000 | |||
3759 | +++ src/ZConfig/tests/__init__.py 2010-07-01 19:15:41 +0000 | |||
3760 | @@ -1,6 +1,6 @@ | |||
3761 | 1 | ############################################################################## | 1 | ############################################################################## |
3762 | 2 | # | 2 | # |
3764 | 3 | # Copyright (c) 2002, 2003 Zope Corporation and Contributors. | 3 | # Copyright (c) 2002, 2003 Zope Foundation and Contributors. |
3765 | 4 | # All Rights Reserved. | 4 | # All Rights Reserved. |
3766 | 5 | # | 5 | # |
3767 | 6 | # This software is subject to the provisions of the Zope Public License, | 6 | # This software is subject to the provisions of the Zope Public License, |
3768 | 7 | 7 | ||
3769 | === modified file 'src/ZConfig/tests/library/thing/__init__.py' | |||
3770 | --- src/ZConfig/tests/library/thing/__init__.py 2009-04-23 15:12:18 +0000 | |||
3771 | +++ src/ZConfig/tests/library/thing/__init__.py 2010-07-01 19:15:41 +0000 | |||
3772 | @@ -1,6 +1,6 @@ | |||
3773 | 1 | ############################################################################## | 1 | ############################################################################## |
3774 | 2 | # | 2 | # |
3776 | 3 | # Copyright (c) 2003 Zope Corporation and Contributors. | 3 | # Copyright (c) 2003 Zope Foundation and Contributors. |
3777 | 4 | # All Rights Reserved. | 4 | # All Rights Reserved. |
3778 | 5 | # | 5 | # |
3779 | 6 | # This software is subject to the provisions of the Zope Public License, | 6 | # This software is subject to the provisions of the Zope Public License, |
3780 | 7 | 7 | ||
3781 | === modified file 'src/ZConfig/tests/support.py' | |||
3782 | --- src/ZConfig/tests/support.py 2009-04-23 15:12:18 +0000 | |||
3783 | +++ src/ZConfig/tests/support.py 2010-07-01 19:15:41 +0000 | |||
3784 | @@ -1,6 +1,6 @@ | |||
3785 | 1 | ############################################################################## | 1 | ############################################################################## |
3786 | 2 | # | 2 | # |
3788 | 3 | # Copyright (c) 2003 Zope Corporation and Contributors. | 3 | # Copyright (c) 2003 Zope Foundation and Contributors. |
3789 | 4 | # All Rights Reserved. | 4 | # All Rights Reserved. |
3790 | 5 | # | 5 | # |
3791 | 6 | # This software is subject to the provisions of the Zope Public License, | 6 | # This software is subject to the provisions of the Zope Public License, |
3792 | 7 | 7 | ||
3793 | === modified file 'src/ZConfig/tests/test_cfgimports.py' | |||
3794 | --- src/ZConfig/tests/test_cfgimports.py 2009-04-23 15:12:18 +0000 | |||
3795 | +++ src/ZConfig/tests/test_cfgimports.py 2010-07-01 19:15:41 +0000 | |||
3796 | @@ -1,6 +1,6 @@ | |||
3797 | 1 | ############################################################################## | 1 | ############################################################################## |
3798 | 2 | # | 2 | # |
3800 | 3 | # Copyright (c) 2003 Zope Corporation and Contributors. | 3 | # Copyright (c) 2003 Zope Foundation and Contributors. |
3801 | 4 | # All Rights Reserved. | 4 | # All Rights Reserved. |
3802 | 5 | # | 5 | # |
3803 | 6 | # This software is subject to the provisions of the Zope Public License, | 6 | # This software is subject to the provisions of the Zope Public License, |
3804 | 7 | 7 | ||
3805 | === modified file 'src/ZConfig/tests/test_cmdline.py' | |||
3806 | --- src/ZConfig/tests/test_cmdline.py 2009-04-23 15:12:18 +0000 | |||
3807 | +++ src/ZConfig/tests/test_cmdline.py 2010-07-01 19:15:41 +0000 | |||
3808 | @@ -1,6 +1,6 @@ | |||
3809 | 1 | ############################################################################## | 1 | ############################################################################## |
3810 | 2 | # | 2 | # |
3812 | 3 | # Copyright (c) 2003 Zope Corporation and Contributors. | 3 | # Copyright (c) 2003 Zope Foundation and Contributors. |
3813 | 4 | # All Rights Reserved. | 4 | # All Rights Reserved. |
3814 | 5 | # | 5 | # |
3815 | 6 | # This software is subject to the provisions of the Zope Public License, | 6 | # This software is subject to the provisions of the Zope Public License, |
3816 | 7 | 7 | ||
3817 | === modified file 'src/ZConfig/tests/test_config.py' | |||
3818 | --- src/ZConfig/tests/test_config.py 2009-04-23 15:12:18 +0000 | |||
3819 | +++ src/ZConfig/tests/test_config.py 2010-07-01 19:15:41 +0000 | |||
3820 | @@ -1,6 +1,6 @@ | |||
3821 | 1 | ############################################################################## | 1 | ############################################################################## |
3822 | 2 | # | 2 | # |
3824 | 3 | # Copyright (c) 2002, 2003 Zope Corporation and Contributors. | 3 | # Copyright (c) 2002, 2003 Zope Foundation and Contributors. |
3825 | 4 | # All Rights Reserved. | 4 | # All Rights Reserved. |
3826 | 5 | # | 5 | # |
3827 | 6 | # This software is subject to the provisions of the Zope Public License, | 6 | # This software is subject to the provisions of the Zope Public License, |
3828 | 7 | 7 | ||
3829 | === modified file 'src/ZConfig/tests/test_cookbook.py' | |||
3830 | --- src/ZConfig/tests/test_cookbook.py 2009-04-23 15:12:18 +0000 | |||
3831 | +++ src/ZConfig/tests/test_cookbook.py 2010-07-01 19:15:41 +0000 | |||
3832 | @@ -1,6 +1,6 @@ | |||
3833 | 1 | ############################################################################## | 1 | ############################################################################## |
3834 | 2 | # | 2 | # |
3836 | 3 | # Copyright (c) 2004 Zope Corporation and Contributors. | 3 | # Copyright (c) 2004 Zope Foundation and Contributors. |
3837 | 4 | # All Rights Reserved. | 4 | # All Rights Reserved. |
3838 | 5 | # | 5 | # |
3839 | 6 | # This software is subject to the provisions of the Zope Public License, | 6 | # This software is subject to the provisions of the Zope Public License, |
3840 | 7 | 7 | ||
3841 | === modified file 'src/ZConfig/tests/test_datatypes.py' | |||
3842 | --- src/ZConfig/tests/test_datatypes.py 2009-04-23 15:12:18 +0000 | |||
3843 | +++ src/ZConfig/tests/test_datatypes.py 2010-07-01 19:15:41 +0000 | |||
3844 | @@ -1,6 +1,6 @@ | |||
3845 | 1 | ############################################################################## | 1 | ############################################################################## |
3846 | 2 | # | 2 | # |
3848 | 3 | # Copyright (c) 2002, 2003 Zope Corporation and Contributors. | 3 | # Copyright (c) 2002, 2003 Zope Foundation and Contributors. |
3849 | 4 | # All Rights Reserved. | 4 | # All Rights Reserved. |
3850 | 5 | # | 5 | # |
3851 | 6 | # This software is subject to the provisions of the Zope Public License, | 6 | # This software is subject to the provisions of the Zope Public License, |
3852 | 7 | 7 | ||
3853 | === modified file 'src/ZConfig/tests/test_loader.py' | |||
3854 | --- src/ZConfig/tests/test_loader.py 2009-04-23 15:12:18 +0000 | |||
3855 | +++ src/ZConfig/tests/test_loader.py 2010-07-01 19:15:41 +0000 | |||
3856 | @@ -1,6 +1,6 @@ | |||
3857 | 1 | ############################################################################## | 1 | ############################################################################## |
3858 | 2 | # | 2 | # |
3860 | 3 | # Copyright (c) 2002, 2003 Zope Corporation and Contributors. | 3 | # Copyright (c) 2002, 2003 Zope Foundation and Contributors. |
3861 | 4 | # All Rights Reserved. | 4 | # All Rights Reserved. |
3862 | 5 | # | 5 | # |
3863 | 6 | # This software is subject to the provisions of the Zope Public License, | 6 | # This software is subject to the provisions of the Zope Public License, |
3864 | @@ -230,6 +230,11 @@ | |||
3865 | 230 | assert_(isPath(r"\abc")) | 230 | assert_(isPath(r"\abc")) |
3866 | 231 | assert_(isPath(r"\abc\def")) | 231 | assert_(isPath(r"\abc\def")) |
3867 | 232 | assert_(isPath(r"c:\abc\def")) | 232 | assert_(isPath(r"c:\abc\def")) |
3868 | 233 | assert_(isPath("/ab:cd")) | ||
3869 | 234 | assert_(isPath(r"\ab:cd")) | ||
3870 | 235 | assert_(isPath("long name with spaces")) | ||
3871 | 236 | assert_(isPath("long name:with spaces")) | ||
3872 | 237 | assert_(not isPath("ab:cd")) | ||
3873 | 233 | assert_(not isPath("http://www.example.com/")) | 238 | assert_(not isPath("http://www.example.com/")) |
3874 | 234 | assert_(not isPath("http://www.example.com/sample.conf")) | 239 | assert_(not isPath("http://www.example.com/sample.conf")) |
3875 | 235 | assert_(not isPath("file:///etc/zope/zope.conf")) | 240 | assert_(not isPath("file:///etc/zope/zope.conf")) |
3876 | 236 | 241 | ||
3877 | === modified file 'src/ZConfig/tests/test_readme.py' | |||
3878 | --- src/ZConfig/tests/test_readme.py 2010-03-01 20:29:16 +0000 | |||
3879 | +++ src/ZConfig/tests/test_readme.py 2010-07-01 19:15:41 +0000 | |||
3880 | @@ -1,6 +1,6 @@ | |||
3881 | 1 | ############################################################################## | 1 | ############################################################################## |
3882 | 2 | # | 2 | # |
3884 | 3 | # Copyright (c) 2009 Zope Corporation and Contributors. | 3 | # Copyright (c) 2009 Zope Foundation and Contributors. |
3885 | 4 | # All Rights Reserved. | 4 | # All Rights Reserved. |
3886 | 5 | # | 5 | # |
3887 | 6 | # This software is subject to the provisions of the Zope Public License, | 6 | # This software is subject to the provisions of the Zope Public License, |
3888 | 7 | 7 | ||
3889 | === modified file 'src/ZConfig/tests/test_schema.py' | |||
3890 | --- src/ZConfig/tests/test_schema.py 2010-03-01 20:29:16 +0000 | |||
3891 | +++ src/ZConfig/tests/test_schema.py 2010-07-01 19:15:41 +0000 | |||
3892 | @@ -1,6 +1,6 @@ | |||
3893 | 1 | ############################################################################## | 1 | ############################################################################## |
3894 | 2 | # | 2 | # |
3896 | 3 | # Copyright (c) 2002, 2003 Zope Corporation and Contributors. | 3 | # Copyright (c) 2002, 2003 Zope Foundation and Contributors. |
3897 | 4 | # All Rights Reserved. | 4 | # All Rights Reserved. |
3898 | 5 | # | 5 | # |
3899 | 6 | # This software is subject to the provisions of the Zope Public License, | 6 | # This software is subject to the provisions of the Zope Public License, |
3900 | 7 | 7 | ||
3901 | === modified file 'src/ZConfig/tests/test_schemaless.py' | |||
3902 | --- src/ZConfig/tests/test_schemaless.py 2009-04-23 15:12:18 +0000 | |||
3903 | +++ src/ZConfig/tests/test_schemaless.py 2010-07-01 19:15:41 +0000 | |||
3904 | @@ -1,6 +1,6 @@ | |||
3905 | 1 | ############################################################################## | 1 | ############################################################################## |
3906 | 2 | # | 2 | # |
3908 | 3 | # Copyright (c) 2007 Zope Corporation and Contributors. | 3 | # Copyright (c) 2007 Zope Foundation and Contributors. |
3909 | 4 | # All Rights Reserved. | 4 | # All Rights Reserved. |
3910 | 5 | # | 5 | # |
3911 | 6 | # This software is subject to the provisions of the Zope Public License, | 6 | # This software is subject to the provisions of the Zope Public License, |
3912 | 7 | 7 | ||
3913 | === modified file 'src/ZConfig/tests/test_subst.py' | |||
3914 | --- src/ZConfig/tests/test_subst.py 2009-04-23 15:12:18 +0000 | |||
3915 | +++ src/ZConfig/tests/test_subst.py 2010-07-01 19:15:41 +0000 | |||
3916 | @@ -1,6 +1,6 @@ | |||
3917 | 1 | ############################################################################## | 1 | ############################################################################## |
3918 | 2 | # | 2 | # |
3920 | 3 | # Copyright (c) 2002, 2003 Zope Corporation and Contributors. | 3 | # Copyright (c) 2002, 2003 Zope Foundation and Contributors. |
3921 | 4 | # All Rights Reserved. | 4 | # All Rights Reserved. |
3922 | 5 | # | 5 | # |
3923 | 6 | # This software is subject to the provisions of the Zope Public License, | 6 | # This software is subject to the provisions of the Zope Public License, |
3924 | 7 | 7 | ||
3925 | === modified file 'src/ZConfig/url.py' | |||
3926 | --- src/ZConfig/url.py 2009-04-23 15:12:18 +0000 | |||
3927 | +++ src/ZConfig/url.py 2010-07-01 19:15:41 +0000 | |||
3928 | @@ -1,6 +1,6 @@ | |||
3929 | 1 | ############################################################################## | 1 | ############################################################################## |
3930 | 2 | # | 2 | # |
3932 | 3 | # Copyright (c) 2002, 2003 Zope Corporation and Contributors. | 3 | # Copyright (c) 2002, 2003 Zope Foundation and Contributors. |
3933 | 4 | # All Rights Reserved. | 4 | # All Rights Reserved. |
3934 | 5 | # | 5 | # |
3935 | 6 | # This software is subject to the provisions of the Zope Public License, | 6 | # This software is subject to the provisions of the Zope Public License, |
3936 | 7 | 7 | ||
3937 | === modified file 'src/ZEO/cache.py' | |||
3938 | --- src/ZEO/cache.py 2010-03-01 20:29:16 +0000 | |||
3939 | +++ src/ZEO/cache.py 2010-07-01 19:15:41 +0000 | |||
3940 | @@ -39,19 +39,19 @@ | |||
3941 | 39 | logger = logging.getLogger("ZEO.cache") | 39 | logger = logging.getLogger("ZEO.cache") |
3942 | 40 | 40 | ||
3943 | 41 | # A disk-based cache for ZEO clients. | 41 | # A disk-based cache for ZEO clients. |
3945 | 42 | # | 42 | # |
3946 | 43 | # This class provides an interface to a persistent, disk-based cache | 43 | # This class provides an interface to a persistent, disk-based cache |
3947 | 44 | # used by ZEO clients to store copies of database records from the | 44 | # used by ZEO clients to store copies of database records from the |
3948 | 45 | # server. | 45 | # server. |
3950 | 46 | # | 46 | # |
3951 | 47 | # The details of the constructor as unspecified at this point. | 47 | # The details of the constructor as unspecified at this point. |
3953 | 48 | # | 48 | # |
3954 | 49 | # Each entry in the cache is valid for a particular range of transaction | 49 | # Each entry in the cache is valid for a particular range of transaction |
3955 | 50 | # ids. The lower bound is the transaction that wrote the data. The | 50 | # ids. The lower bound is the transaction that wrote the data. The |
3956 | 51 | # upper bound is the next transaction that wrote a revision of the | 51 | # upper bound is the next transaction that wrote a revision of the |
3957 | 52 | # object. If the data is current, the upper bound is stored as None; | 52 | # object. If the data is current, the upper bound is stored as None; |
3958 | 53 | # the data is considered current until an invalidate() call is made. | 53 | # the data is considered current until an invalidate() call is made. |
3960 | 54 | # | 54 | # |
3961 | 55 | # It is an error to call store() twice with the same object without an | 55 | # It is an error to call store() twice with the same object without an |
3962 | 56 | # intervening invalidate() to set the upper bound on the first cache | 56 | # intervening invalidate() to set the upper bound on the first cache |
3963 | 57 | # entry. Perhaps it will be necessary to have a call the removes | 57 | # entry. Perhaps it will be necessary to have a call the removes |
3964 | @@ -59,12 +59,12 @@ | |||
3965 | 59 | # entry. | 59 | # entry. |
3966 | 60 | 60 | ||
3967 | 61 | # Cache verification | 61 | # Cache verification |
3969 | 62 | # | 62 | # |
3970 | 63 | # When the client is connected to the server, it receives | 63 | # When the client is connected to the server, it receives |
3971 | 64 | # invalidations every time an object is modified. When the client is | 64 | # invalidations every time an object is modified. When the client is |
3972 | 65 | # disconnected then reconnects, it must perform cache verification to make | 65 | # disconnected then reconnects, it must perform cache verification to make |
3973 | 66 | # sure its cached data is synchronized with the storage's current state. | 66 | # sure its cached data is synchronized with the storage's current state. |
3975 | 67 | # | 67 | # |
3976 | 68 | # quick verification | 68 | # quick verification |
3977 | 69 | # full verification | 69 | # full verification |
3978 | 70 | # | 70 | # |
3979 | @@ -206,7 +206,7 @@ | |||
3980 | 206 | self.f = tempfile.TemporaryFile() | 206 | self.f = tempfile.TemporaryFile() |
3981 | 207 | self.f.write(magic+z64) | 207 | self.f.write(magic+z64) |
3982 | 208 | logger.info("created temporary cache file %r", self.f.name) | 208 | logger.info("created temporary cache file %r", self.f.name) |
3984 | 209 | 209 | ||
3985 | 210 | self._initfile(fsize) | 210 | self._initfile(fsize) |
3986 | 211 | 211 | ||
3987 | 212 | # Statistics: _n_adds, _n_added_bytes, | 212 | # Statistics: _n_adds, _n_added_bytes, |
3988 | @@ -328,7 +328,7 @@ | |||
3989 | 328 | seek(block_size-5, 1) | 328 | seek(block_size-5, 1) |
3990 | 329 | sync(self.f) | 329 | sync(self.f) |
3991 | 330 | 330 | ||
3993 | 331 | # There is always data to read and | 331 | # There is always data to read and |
3994 | 332 | assert last and status in ' f1234' | 332 | assert last and status in ' f1234' |
3995 | 333 | first_free_offset = last | 333 | first_free_offset = last |
3996 | 334 | else: | 334 | else: |
3997 | @@ -358,7 +358,7 @@ | |||
3998 | 358 | except KeyError: | 358 | except KeyError: |
3999 | 359 | logger.error("Couldn't find non-current %r", (oid, tid)) | 359 | logger.error("Couldn't find non-current %r", (oid, tid)) |
4000 | 360 | 360 | ||
4002 | 361 | 361 | ||
4003 | 362 | def clearStats(self): | 362 | def clearStats(self): |
4004 | 363 | self._n_adds = self._n_added_bytes = 0 | 363 | self._n_adds = self._n_added_bytes = 0 |
4005 | 364 | self._n_evicts = self._n_evicted_bytes = 0 | 364 | self._n_evicts = self._n_evicted_bytes = 0 |
4006 | @@ -471,7 +471,8 @@ | |||
4007 | 471 | return None | 471 | return None |
4008 | 472 | self.f.seek(ofs) | 472 | self.f.seek(ofs) |
4009 | 473 | read = self.f.read | 473 | read = self.f.read |
4011 | 474 | assert read(1) == 'a', (ofs, self.f.tell(), oid) | 474 | status = read(1) |
4012 | 475 | assert status == 'a', (ofs, self.f.tell(), oid) | ||
4013 | 475 | size, saved_oid, tid, end_tid, lver, ldata = unpack( | 476 | size, saved_oid, tid, end_tid, lver, ldata = unpack( |
4014 | 476 | ">I8s8s8sHI", read(34)) | 477 | ">I8s8s8sHI", read(34)) |
4015 | 477 | assert saved_oid == oid, (ofs, self.f.tell(), oid, saved_oid) | 478 | assert saved_oid == oid, (ofs, self.f.tell(), oid, saved_oid) |
4016 | @@ -479,7 +480,10 @@ | |||
4017 | 479 | 480 | ||
4018 | 480 | data = read(ldata) | 481 | data = read(ldata) |
4019 | 481 | assert len(data) == ldata, (ofs, self.f.tell(), oid, len(data), ldata) | 482 | assert len(data) == ldata, (ofs, self.f.tell(), oid, len(data), ldata) |
4021 | 482 | assert read(8) == oid, (ofs, self.f.tell(), oid) | 483 | |
4022 | 484 | # WARNING: The following assert changes the file position. | ||
4023 | 485 | # We must not depend on ths below or we'll fail in optimized mode. | ||
4024 | 486 | assert read(8) == oid, (ofs, self.f.tell(), oid) | ||
4025 | 483 | 487 | ||
4026 | 484 | self._n_accesses += 1 | 488 | self._n_accesses += 1 |
4027 | 485 | self._trace(0x22, oid, tid, end_tid, ldata) | 489 | self._trace(0x22, oid, tid, end_tid, ldata) |
4028 | @@ -507,7 +511,8 @@ | |||
4029 | 507 | 511 | ||
4030 | 508 | self.f.seek(ofs) | 512 | self.f.seek(ofs) |
4031 | 509 | read = self.f.read | 513 | read = self.f.read |
4033 | 510 | assert read(1) == 'a', (ofs, self.f.tell(), oid, before_tid) | 514 | status = read(1) |
4034 | 515 | assert status == 'a', (ofs, self.f.tell(), oid, before_tid) | ||
4035 | 511 | size, saved_oid, saved_tid, end_tid, lver, ldata = unpack( | 516 | size, saved_oid, saved_tid, end_tid, lver, ldata = unpack( |
4036 | 512 | ">I8s8s8sHI", read(34)) | 517 | ">I8s8s8sHI", read(34)) |
4037 | 513 | assert saved_oid == oid, (ofs, self.f.tell(), oid, saved_oid) | 518 | assert saved_oid == oid, (ofs, self.f.tell(), oid, saved_oid) |
4038 | @@ -516,12 +521,15 @@ | |||
4039 | 516 | assert lver == 0, "Versions aren't supported" | 521 | assert lver == 0, "Versions aren't supported" |
4040 | 517 | data = read(ldata) | 522 | data = read(ldata) |
4041 | 518 | assert len(data) == ldata, (ofs, self.f.tell()) | 523 | assert len(data) == ldata, (ofs, self.f.tell()) |
4042 | 524 | |||
4043 | 525 | # WARNING: The following assert changes the file position. | ||
4044 | 526 | # We must not depend on ths below or we'll fail in optimized mode. | ||
4045 | 519 | assert read(8) == oid, (ofs, self.f.tell(), oid) | 527 | assert read(8) == oid, (ofs, self.f.tell(), oid) |
4047 | 520 | 528 | ||
4048 | 521 | if end_tid < before_tid: | 529 | if end_tid < before_tid: |
4049 | 522 | self._trace(0x24, oid, "", before_tid) | 530 | self._trace(0x24, oid, "", before_tid) |
4050 | 523 | return None | 531 | return None |
4052 | 524 | 532 | ||
4053 | 525 | self._n_accesses += 1 | 533 | self._n_accesses += 1 |
4054 | 526 | self._trace(0x26, oid, "", saved_tid) | 534 | self._trace(0x26, oid, "", saved_tid) |
4055 | 527 | return data, saved_tid, end_tid | 535 | return data, saved_tid, end_tid |
4056 | @@ -543,7 +551,8 @@ | |||
4057 | 543 | if ofs: | 551 | if ofs: |
4058 | 544 | seek(ofs) | 552 | seek(ofs) |
4059 | 545 | read = self.f.read | 553 | read = self.f.read |
4061 | 546 | assert read(1) == 'a', (ofs, self.f.tell(), oid) | 554 | status = read(1) |
4062 | 555 | assert status == 'a', (ofs, self.f.tell(), oid) | ||
4063 | 547 | size, saved_oid, saved_tid, end_tid = unpack( | 556 | size, saved_oid, saved_tid, end_tid = unpack( |
4064 | 548 | ">I8s8s8s", read(28)) | 557 | ">I8s8s8s", read(28)) |
4065 | 549 | assert saved_oid == oid, (ofs, self.f.tell(), oid, saved_oid) | 558 | assert saved_oid == oid, (ofs, self.f.tell(), oid, saved_oid) |
4066 | @@ -613,7 +622,7 @@ | |||
4067 | 613 | else: | 622 | else: |
4068 | 614 | self.current[oid] = ofs | 623 | self.current[oid] = ofs |
4069 | 615 | self._trace(0x52, oid, start_tid, dlen=len(data)) | 624 | self._trace(0x52, oid, start_tid, dlen=len(data)) |
4071 | 616 | 625 | ||
4072 | 617 | self.currentofs += size | 626 | self.currentofs += size |
4073 | 618 | 627 | ||
4074 | 619 | ## | 628 | ## |
4075 | @@ -635,7 +644,7 @@ | |||
4076 | 635 | # to threading issues, that when applying a local | 644 | # to threading issues, that when applying a local |
4077 | 636 | # invalidation after a store, that later invalidations from | 645 | # invalidation after a store, that later invalidations from |
4078 | 637 | # the server may already have arrived. | 646 | # the server may already have arrived. |
4080 | 638 | 647 | ||
4081 | 639 | @locked | 648 | @locked |
4082 | 640 | def invalidate(self, oid, tid, server_invalidation=True): | 649 | def invalidate(self, oid, tid, server_invalidation=True): |
4083 | 641 | if tid is not None: | 650 | if tid is not None: |
4084 | @@ -655,7 +664,8 @@ | |||
4085 | 655 | 664 | ||
4086 | 656 | self.f.seek(ofs) | 665 | self.f.seek(ofs) |
4087 | 657 | read = self.f.read | 666 | read = self.f.read |
4089 | 658 | assert read(1) == 'a', (ofs, self.f.tell(), oid) | 667 | status = read(1) |
4090 | 668 | assert status == 'a', (ofs, self.f.tell(), oid) | ||
4091 | 659 | size, saved_oid, saved_tid, end_tid = unpack(">I8s8s8s", read(28)) | 669 | size, saved_oid, saved_tid, end_tid = unpack(">I8s8s8s", read(28)) |
4092 | 660 | assert saved_oid == oid, (ofs, self.f.tell(), oid, saved_oid) | 670 | assert saved_oid == oid, (ofs, self.f.tell(), oid, saved_oid) |
4093 | 661 | assert end_tid == z64, (ofs, self.f.tell(), oid) | 671 | assert end_tid == z64, (ofs, self.f.tell(), oid) |
4094 | @@ -685,7 +695,8 @@ | |||
4095 | 685 | self._lock.acquire() | 695 | self._lock.acquire() |
4096 | 686 | try: | 696 | try: |
4097 | 687 | seek(ofs) | 697 | seek(ofs) |
4099 | 688 | assert read(1) == 'a', (ofs, self.f.tell(), oid) | 698 | status = read(1) |
4100 | 699 | assert status == 'a', (ofs, self.f.tell(), oid) | ||
4101 | 689 | size, saved_oid, tid, end_tid = unpack(">I8s8s8s", read(28)) | 700 | size, saved_oid, tid, end_tid = unpack(">I8s8s8s", read(28)) |
4102 | 690 | assert saved_oid == oid, (ofs, self.f.tell(), oid, saved_oid) | 701 | assert saved_oid == oid, (ofs, self.f.tell(), oid, saved_oid) |
4103 | 691 | assert end_tid == z64, (ofs, self.f.tell(), oid) | 702 | assert end_tid == z64, (ofs, self.f.tell(), oid) |
4104 | @@ -750,7 +761,7 @@ | |||
4105 | 750 | except: | 761 | except: |
4106 | 751 | print `tid`, `end_tid` | 762 | print `tid`, `end_tid` |
4107 | 752 | raise | 763 | raise |
4109 | 753 | 764 | ||
4110 | 754 | self._trace = _trace | 765 | self._trace = _trace |
4111 | 755 | _trace(0x00) | 766 | _trace(0x00) |
4112 | 756 | 767 | ||
4113 | 757 | 768 | ||
4114 | === modified file 'src/ZEO/mkzeoinst.py' | |||
4115 | --- src/ZEO/mkzeoinst.py 2009-04-23 15:12:18 +0000 | |||
4116 | +++ src/ZEO/mkzeoinst.py 2010-07-01 19:15:41 +0000 | |||
4117 | @@ -11,233 +11,15 @@ | |||
4118 | 11 | # FOR A PARTICULAR PURPOSE. | 11 | # FOR A PARTICULAR PURPOSE. |
4119 | 12 | # | 12 | # |
4120 | 13 | ############################################################################## | 13 | ############################################################################## |
4137 | 14 | """%(program)s -- create a ZEO instance. | 14 | print """ |
4138 | 15 | 15 | The mkzeoinst script is no longer supported. | |
4139 | 16 | Usage: %(program)s home [port] | 16 | |
4140 | 17 | 17 | Install the zope.mkzeoinstance package: | |
4141 | 18 | Given an "instance home directory" <home> and some configuration | 18 | |
4142 | 19 | options (all of which have default values), create the following: | 19 | http://pypi.python.org/pypi/zope.mkzeoinstance |
4143 | 20 | 20 | ||
4144 | 21 | <home>/etc/zeo.conf -- ZEO config file | 21 | and use the installed mkzeointance script that is installed by that package. |
4129 | 22 | <home>/var/ -- Directory for data files: Data.fs etc. | ||
4130 | 23 | <home>/log/ -- Directory for log files: zeo.log and zeoctl.log | ||
4131 | 24 | <home>/bin/runzeo -- the zeo server runner | ||
4132 | 25 | <home>/bin/zeoctl -- start/stop script (a shim for zeoctl.py) | ||
4133 | 26 | |||
4134 | 27 | The script will not overwrite existing files; instead, it will issue a | ||
4135 | 28 | warning if an existing file is found that differs from the file that | ||
4136 | 29 | would be written if it didn't exist. | ||
4145 | 30 | """ | 22 | """ |
4146 | 31 | 23 | ||
4147 | 32 | # WARNING! Several templates and functions here are reused by ZRS. | ||
4148 | 33 | # So be careful with changes. | ||
4149 | 34 | |||
4150 | 35 | import os | ||
4151 | 36 | import sys | 24 | import sys |
4359 | 37 | import stat | 25 | sys.exit(1) |
4153 | 38 | import getopt | ||
4154 | 39 | |||
4155 | 40 | zeo_conf_template = """\ | ||
4156 | 41 | # ZEO configuration file | ||
4157 | 42 | |||
4158 | 43 | %%define INSTANCE %(instance_home)s | ||
4159 | 44 | |||
4160 | 45 | <zeo> | ||
4161 | 46 | address %(port)d | ||
4162 | 47 | read-only false | ||
4163 | 48 | invalidation-queue-size 100 | ||
4164 | 49 | # pid-filename $INSTANCE/var/ZEO.pid | ||
4165 | 50 | # monitor-address PORT | ||
4166 | 51 | # transaction-timeout SECONDS | ||
4167 | 52 | </zeo> | ||
4168 | 53 | |||
4169 | 54 | <filestorage 1> | ||
4170 | 55 | path $INSTANCE/var/Data.fs | ||
4171 | 56 | </filestorage> | ||
4172 | 57 | |||
4173 | 58 | <eventlog> | ||
4174 | 59 | level info | ||
4175 | 60 | <logfile> | ||
4176 | 61 | path $INSTANCE/log/zeo.log | ||
4177 | 62 | </logfile> | ||
4178 | 63 | </eventlog> | ||
4179 | 64 | |||
4180 | 65 | <runner> | ||
4181 | 66 | program $INSTANCE/bin/runzeo | ||
4182 | 67 | socket-name $INSTANCE/etc/%(package)s.zdsock | ||
4183 | 68 | daemon true | ||
4184 | 69 | forever false | ||
4185 | 70 | backoff-limit 10 | ||
4186 | 71 | exit-codes 0, 2 | ||
4187 | 72 | directory $INSTANCE | ||
4188 | 73 | default-to-interactive true | ||
4189 | 74 | # user zope | ||
4190 | 75 | python %(python)s | ||
4191 | 76 | zdrun %(zodb3_home)s/zdaemon/zdrun.py | ||
4192 | 77 | |||
4193 | 78 | # This logfile should match the one in the %(package)s.conf file. | ||
4194 | 79 | # It is used by zdctl's logtail command, zdrun/zdctl doesn't write it. | ||
4195 | 80 | logfile $INSTANCE/log/%(package)s.log | ||
4196 | 81 | </runner> | ||
4197 | 82 | """ | ||
4198 | 83 | |||
4199 | 84 | zeoctl_template = """\ | ||
4200 | 85 | #!/bin/sh | ||
4201 | 86 | # %(PACKAGE)s instance control script | ||
4202 | 87 | |||
4203 | 88 | # The following two lines are for chkconfig. On Red Hat Linux (and | ||
4204 | 89 | # some other systems), you can copy or symlink this script into | ||
4205 | 90 | # /etc/rc.d/init.d/ and then use chkconfig(8) to automatically start | ||
4206 | 91 | # %(PACKAGE)s at boot time. | ||
4207 | 92 | |||
4208 | 93 | # chkconfig: 345 90 10 | ||
4209 | 94 | # description: start a %(PACKAGE)s server | ||
4210 | 95 | |||
4211 | 96 | PYTHON="%(python)s" | ||
4212 | 97 | INSTANCE_HOME="%(instance_home)s" | ||
4213 | 98 | ZODB3_HOME="%(zodb3_home)s" | ||
4214 | 99 | |||
4215 | 100 | CONFIG_FILE="%(instance_home)s/etc/%(package)s.conf" | ||
4216 | 101 | |||
4217 | 102 | PYTHONPATH="$ZODB3_HOME" | ||
4218 | 103 | export PYTHONPATH INSTANCE_HOME | ||
4219 | 104 | |||
4220 | 105 | ZEOCTL="$ZODB3_HOME/ZEO/zeoctl.py" | ||
4221 | 106 | |||
4222 | 107 | exec "$PYTHON" "$ZEOCTL" -C "$CONFIG_FILE" ${1+"$@"} | ||
4223 | 108 | """ | ||
4224 | 109 | |||
4225 | 110 | runzeo_template = """\ | ||
4226 | 111 | #!/bin/sh | ||
4227 | 112 | # %(PACKAGE)s instance start script | ||
4228 | 113 | |||
4229 | 114 | PYTHON="%(python)s" | ||
4230 | 115 | INSTANCE_HOME="%(instance_home)s" | ||
4231 | 116 | ZODB3_HOME="%(zodb3_home)s" | ||
4232 | 117 | |||
4233 | 118 | CONFIG_FILE="%(instance_home)s/etc/%(package)s.conf" | ||
4234 | 119 | |||
4235 | 120 | PYTHONPATH="$ZODB3_HOME" | ||
4236 | 121 | export PYTHONPATH INSTANCE_HOME | ||
4237 | 122 | |||
4238 | 123 | RUNZEO="$ZODB3_HOME/ZEO/runzeo.py" | ||
4239 | 124 | |||
4240 | 125 | exec "$PYTHON" "$RUNZEO" -C "$CONFIG_FILE" ${1+"$@"} | ||
4241 | 126 | """ | ||
4242 | 127 | |||
4243 | 128 | def main(): | ||
4244 | 129 | ZEOInstanceBuilder().run() | ||
4245 | 130 | print "All done." | ||
4246 | 131 | |||
4247 | 132 | class ZEOInstanceBuilder: | ||
4248 | 133 | def run(self): | ||
4249 | 134 | try: | ||
4250 | 135 | opts, args = getopt.getopt(sys.argv[1:], "h", ["help"]) | ||
4251 | 136 | except getopt.error, msg: | ||
4252 | 137 | print msg | ||
4253 | 138 | sys.exit(2) | ||
4254 | 139 | program = os.path.basename(sys.argv[0]) | ||
4255 | 140 | if opts: | ||
4256 | 141 | # There's only the help options, so just dump some help: | ||
4257 | 142 | msg = __doc__ % {"program": program} | ||
4258 | 143 | print msg | ||
4259 | 144 | sys.exit() | ||
4260 | 145 | if len(args) not in [1, 2]: | ||
4261 | 146 | print "Usage: %s home [port]" % program | ||
4262 | 147 | sys.exit(2) | ||
4263 | 148 | |||
4264 | 149 | instance_home = args[0] | ||
4265 | 150 | if not os.path.isabs(instance_home): | ||
4266 | 151 | instance_home = os.path.abspath(instance_home) | ||
4267 | 152 | |||
4268 | 153 | for entry in sys.path: | ||
4269 | 154 | if os.path.exists(os.path.join(entry, 'ZODB')): | ||
4270 | 155 | zodb3_home = entry | ||
4271 | 156 | break | ||
4272 | 157 | else: | ||
4273 | 158 | print "Can't find the Zope home (not in sys.path)" | ||
4274 | 159 | sys.exit(2) | ||
4275 | 160 | |||
4276 | 161 | if args[1:]: | ||
4277 | 162 | port = int(args[1]) | ||
4278 | 163 | else: | ||
4279 | 164 | port = 8100 # match example in zope.conf | ||
4280 | 165 | |||
4281 | 166 | params = self.get_params(zodb3_home, instance_home, port) | ||
4282 | 167 | self.create(instance_home, params) | ||
4283 | 168 | |||
4284 | 169 | def get_params(self, zodb3_home, instance_home, port): | ||
4285 | 170 | return { | ||
4286 | 171 | "package": "zeo", | ||
4287 | 172 | "PACKAGE": "ZEO", | ||
4288 | 173 | "zodb3_home": zodb3_home, | ||
4289 | 174 | "instance_home": instance_home, | ||
4290 | 175 | "port": port, | ||
4291 | 176 | "python": sys.executable, | ||
4292 | 177 | } | ||
4293 | 178 | |||
4294 | 179 | def create(self, home, params): | ||
4295 | 180 | makedir(home) | ||
4296 | 181 | makedir(home, "etc") | ||
4297 | 182 | makedir(home, "var") | ||
4298 | 183 | makedir(home, "log") | ||
4299 | 184 | makedir(home, "bin") | ||
4300 | 185 | makefile(zeo_conf_template, home, "etc", "zeo.conf", **params) | ||
4301 | 186 | makexfile(zeoctl_template, home, "bin", "zeoctl", **params) | ||
4302 | 187 | makexfile(runzeo_template, home, "bin", "runzeo", **params) | ||
4303 | 188 | |||
4304 | 189 | |||
4305 | 190 | def which(program): | ||
4306 | 191 | strpath = os.getenv("PATH") | ||
4307 | 192 | binpath = strpath.split(os.pathsep) | ||
4308 | 193 | for dir in binpath: | ||
4309 | 194 | path = os.path.join(dir, program) | ||
4310 | 195 | if os.path.isfile(path) and os.access(path, os.X_OK): | ||
4311 | 196 | if not os.path.isabs(path): | ||
4312 | 197 | path = os.path.abspath(path) | ||
4313 | 198 | return path | ||
4314 | 199 | raise IOError("can't find %r on path %r" % (program, strpath)) | ||
4315 | 200 | |||
4316 | 201 | def makedir(*args): | ||
4317 | 202 | path = "" | ||
4318 | 203 | for arg in args: | ||
4319 | 204 | path = os.path.join(path, arg) | ||
4320 | 205 | mkdirs(path) | ||
4321 | 206 | return path | ||
4322 | 207 | |||
4323 | 208 | def mkdirs(path): | ||
4324 | 209 | if os.path.isdir(path): | ||
4325 | 210 | return | ||
4326 | 211 | head, tail = os.path.split(path) | ||
4327 | 212 | if head and tail and not os.path.isdir(head): | ||
4328 | 213 | mkdirs(head) | ||
4329 | 214 | os.mkdir(path) | ||
4330 | 215 | print "Created directory", path | ||
4331 | 216 | |||
4332 | 217 | def makefile(template, *args, **kwds): | ||
4333 | 218 | path = makedir(*args[:-1]) | ||
4334 | 219 | path = os.path.join(path, args[-1]) | ||
4335 | 220 | data = template % kwds | ||
4336 | 221 | if os.path.exists(path): | ||
4337 | 222 | f = open(path) | ||
4338 | 223 | olddata = f.read().strip() | ||
4339 | 224 | f.close() | ||
4340 | 225 | if olddata: | ||
4341 | 226 | if olddata != data.strip(): | ||
4342 | 227 | print "Warning: not overwriting existing file %r" % path | ||
4343 | 228 | return path | ||
4344 | 229 | f = open(path, "w") | ||
4345 | 230 | f.write(data) | ||
4346 | 231 | f.close() | ||
4347 | 232 | print "Wrote file", path | ||
4348 | 233 | return path | ||
4349 | 234 | |||
4350 | 235 | def makexfile(template, *args, **kwds): | ||
4351 | 236 | path = makefile(template, *args, **kwds) | ||
4352 | 237 | umask = os.umask(022) | ||
4353 | 238 | os.umask(umask) | ||
4354 | 239 | mode = 0777 & ~umask | ||
4355 | 240 | if stat.S_IMODE(os.stat(path)[stat.ST_MODE]) != mode: | ||
4356 | 241 | os.chmod(path, mode) | ||
4357 | 242 | print "Changed mode for %s to %o" % (path, mode) | ||
4358 | 243 | return path | ||
4360 | 244 | 26 | ||
4361 | === modified file 'src/ZEO/tests/testZEO.py' | |||
4362 | --- src/ZEO/tests/testZEO.py 2010-03-01 20:29:16 +0000 | |||
4363 | +++ src/ZEO/tests/testZEO.py 2010-07-01 19:15:41 +0000 | |||
4364 | @@ -486,7 +486,10 @@ | |||
4365 | 486 | # logged | 486 | # logged |
4366 | 487 | self._storage._connection.handle_request('foo',0,'history',(1,2,3,4)) | 487 | self._storage._connection.handle_request('foo',0,'history',(1,2,3,4)) |
4367 | 488 | # test logging | 488 | # test logging |
4369 | 489 | level,message,kw = log[1] | 489 | if __debug__: |
4370 | 490 | level,message,kw = log[1] | ||
4371 | 491 | else: | ||
4372 | 492 | level,message,kw = log[0] | ||
4373 | 490 | self.assertEqual(level,logging.ERROR) | 493 | self.assertEqual(level,logging.ERROR) |
4374 | 491 | self.failUnless(message.endswith( | 494 | self.failUnless(message.endswith( |
4375 | 492 | ') history() raised exception: history() takes at' | 495 | ') history() raised exception: history() takes at' |
4376 | 493 | 496 | ||
4377 | === modified file 'src/ZODB/ConflictResolution.py' | |||
4378 | --- src/ZODB/ConflictResolution.py 2010-03-01 20:29:16 +0000 | |||
4379 | +++ src/ZODB/ConflictResolution.py 2010-07-01 19:15:41 +0000 | |||
4380 | @@ -116,13 +116,17 @@ | |||
4381 | 116 | # 'm' = multi_persistent: (database_name, oid, klass) | 116 | # 'm' = multi_persistent: (database_name, oid, klass) |
4382 | 117 | # 'n' = multi_oid: (database_name, oid) | 117 | # 'n' = multi_oid: (database_name, oid) |
4383 | 118 | # 'w' = persistent weakref: (oid) | 118 | # 'w' = persistent weakref: (oid) |
4384 | 119 | # or persistent weakref: (oid, database_name) | ||
4385 | 119 | # else it is a weakref: reference_type | 120 | # else it is a weakref: reference_type |
4386 | 120 | if reference_type == 'm': | 121 | if reference_type == 'm': |
4387 | 121 | self.database_name, self.oid, self.klass = data[1] | 122 | self.database_name, self.oid, self.klass = data[1] |
4388 | 122 | elif reference_type == 'n': | 123 | elif reference_type == 'n': |
4389 | 123 | self.database_name, self.oid = data[1] | 124 | self.database_name, self.oid = data[1] |
4390 | 124 | elif reference_type == 'w': | 125 | elif reference_type == 'w': |
4392 | 125 | self.oid, = data[1] | 126 | try: |
4393 | 127 | self.oid, = data[1] | ||
4394 | 128 | except ValueError: | ||
4395 | 129 | self.oid, self.database_name = data[1] | ||
4396 | 126 | self.weak = True | 130 | self.weak = True |
4397 | 127 | else: | 131 | else: |
4398 | 128 | assert len(data) == 1, 'unknown reference format' | 132 | assert len(data) == 1, 'unknown reference format' |
4399 | 129 | 133 | ||
4400 | === modified file 'src/ZODB/ConflictResolution.txt' | |||
4401 | --- src/ZODB/ConflictResolution.txt 2010-03-01 20:29:16 +0000 | |||
4402 | +++ src/ZODB/ConflictResolution.txt 2010-07-01 19:15:41 +0000 | |||
4403 | @@ -474,6 +474,16 @@ | |||
4404 | 474 | >>> ref3.weak | 474 | >>> ref3.weak |
4405 | 475 | True | 475 | True |
4406 | 476 | 476 | ||
4407 | 477 | >>> ref3a = PersistentReference(['w', ('my_oid', 'other_db')]) | ||
4408 | 478 | >>> ref3a.oid | ||
4409 | 479 | 'my_oid' | ||
4410 | 480 | >>> print ref3a.klass | ||
4411 | 481 | None | ||
4412 | 482 | >>> ref3a.database_name | ||
4413 | 483 | 'other_db' | ||
4414 | 484 | >>> ref3a.weak | ||
4415 | 485 | True | ||
4416 | 486 | |||
4417 | 477 | >>> ref4 = PersistentReference(['m', ('other_db', 'my_oid', 'my_class')]) | 487 | >>> ref4 = PersistentReference(['m', ('other_db', 'my_oid', 'my_class')]) |
4418 | 478 | >>> ref4.oid | 488 | >>> ref4.oid |
4419 | 479 | 'my_oid' | 489 | 'my_oid' |
4420 | @@ -508,7 +518,7 @@ | |||
4421 | 508 | 518 | ||
4422 | 509 | >>> ref1 == ref1 and ref2 == ref2 and ref4 == ref4 and ref5 == ref5 | 519 | >>> ref1 == ref1 and ref2 == ref2 and ref4 == ref4 and ref5 == ref5 |
4423 | 510 | True | 520 | True |
4425 | 511 | >>> ref3 == ref3 and ref6 == ref6 # weak references | 521 | >>> ref3 == ref3 and ref3a == ref3a and ref6 == ref6 # weak references |
4426 | 512 | True | 522 | True |
4427 | 513 | 523 | ||
4428 | 514 | Non-weak references with the same oid and database_name are equal. | 524 | Non-weak references with the same oid and database_name are equal. |
4429 | 515 | 525 | ||
4430 | === modified file 'src/ZODB/Connection.py' | |||
4431 | --- src/ZODB/Connection.py 2010-03-01 20:29:16 +0000 | |||
4432 | +++ src/ZODB/Connection.py 2010-07-01 19:15:41 +0000 | |||
4433 | @@ -13,7 +13,7 @@ | |||
4434 | 13 | ############################################################################## | 13 | ############################################################################## |
4435 | 14 | """Database connection support | 14 | """Database connection support |
4436 | 15 | 15 | ||
4438 | 16 | $Id: Connection.py 106502 2009-12-14 19:27:08Z jim $""" | 16 | $Id: Connection.py 111314 2010-04-23 17:30:12Z jim $""" |
4439 | 17 | 17 | ||
4440 | 18 | import logging | 18 | import logging |
4441 | 19 | import sys | 19 | import sys |
4442 | @@ -1143,8 +1143,9 @@ | |||
4443 | 1143 | self._abort() | 1143 | self._abort() |
4444 | 1144 | self._registered_objects = [] | 1144 | self._registered_objects = [] |
4445 | 1145 | src = self._storage | 1145 | src = self._storage |
4447 | 1146 | self._cache.invalidate(src.index) | 1146 | index = src.index |
4448 | 1147 | src.reset(*state) | 1147 | src.reset(*state) |
4449 | 1148 | self._cache.invalidate(index) | ||
4450 | 1148 | 1149 | ||
4451 | 1149 | def _commit_savepoint(self, transaction): | 1150 | def _commit_savepoint(self, transaction): |
4452 | 1150 | """Commit all changes made in savepoints and begin 2-phase commit | 1151 | """Commit all changes made in savepoints and begin 2-phase commit |
4453 | 1151 | 1152 | ||
4454 | === modified file 'src/ZODB/scripts/tests/test_repozo.py' | |||
4455 | --- src/ZODB/scripts/tests/test_repozo.py 2010-03-01 20:29:16 +0000 | |||
4456 | +++ src/ZODB/scripts/tests/test_repozo.py 2010-07-01 19:15:41 +0000 | |||
4457 | @@ -1,4 +1,3 @@ | |||
4458 | 1 | #!/usr/bin/env python | ||
4459 | 2 | ############################################################################## | 1 | ############################################################################## |
4460 | 3 | # | 2 | # |
4461 | 4 | # Copyright (c) 2004-2009 Zope Corporation and Contributors. | 3 | # Copyright (c) 2004-2009 Zope Corporation and Contributors. |
4462 | @@ -12,10 +11,9 @@ | |||
4463 | 12 | # FOR A PARTICULAR PURPOSE. | 11 | # FOR A PARTICULAR PURPOSE. |
4464 | 13 | # | 12 | # |
4465 | 14 | ############################################################################## | 13 | ############################################################################## |
4466 | 15 | |||
4467 | 16 | import unittest | 14 | import unittest |
4468 | 17 | import os | 15 | import os |
4470 | 18 | import ZODB.tests.util | 16 | import ZODB.tests.util # layer used at class scope |
4471 | 19 | 17 | ||
4472 | 20 | _NOISY = os.environ.get('NOISY_REPOZO_TEST_OUTPUT') | 18 | _NOISY = os.environ.get('NOISY_REPOZO_TEST_OUTPUT') |
4473 | 21 | 19 | ||
4474 | @@ -172,10 +170,6 @@ | |||
4475 | 172 | 170 | ||
4476 | 173 | 171 | ||
4477 | 174 | def test_suite(): | 172 | def test_suite(): |
4485 | 175 | suite = unittest.TestSuite() | 173 | return unittest.TestSuite([ |
4486 | 176 | suite.addTest(unittest.makeSuite(RepozoTests)) | 174 | unittest.makeSuite(RepozoTests), |
4487 | 177 | return suite | 175 | ]) |
4481 | 178 | |||
4482 | 179 | |||
4483 | 180 | if __name__ == '__main__': | ||
4484 | 181 | unittest.main(defaultTest='test_suite') | ||
4488 | 182 | 176 | ||
4489 | === modified file 'src/ZODB/serialize.py' | |||
4490 | --- src/ZODB/serialize.py 2010-03-01 20:29:16 +0000 | |||
4491 | +++ src/ZODB/serialize.py 2010-07-01 19:15:41 +0000 | |||
4492 | @@ -100,7 +100,8 @@ | |||
4493 | 100 | The following reference types are defined: | 100 | The following reference types are defined: |
4494 | 101 | 101 | ||
4495 | 102 | 'w' | 102 | 'w' |
4497 | 103 | Persistent weak reference. The arguments consist of an oid. | 103 | Persistent weak reference. The arguments consist of an oid |
4498 | 104 | and optionally a database name. | ||
4499 | 104 | 105 | ||
4500 | 105 | The following are planned for the future: | 106 | The following are planned for the future: |
4501 | 106 | 107 | ||
4502 | @@ -298,8 +299,8 @@ | |||
4503 | 298 | 299 | ||
4504 | 299 | oid = obj.oid | 300 | oid = obj.oid |
4505 | 300 | if oid is None: | 301 | if oid is None: |
4508 | 301 | obj = obj() # get the referenced object | 302 | target = obj() # get the referenced object |
4509 | 302 | oid = obj._p_oid | 303 | oid = target._p_oid |
4510 | 303 | if oid is None: | 304 | if oid is None: |
4511 | 304 | # Here we are causing the object to be saved in | 305 | # Here we are causing the object to be saved in |
4512 | 305 | # the database. One could argue that we shouldn't | 306 | # the database. One could argue that we shouldn't |
4513 | @@ -308,10 +309,16 @@ | |||
4514 | 308 | # assume that the object will be added eventually. | 309 | # assume that the object will be added eventually. |
4515 | 309 | 310 | ||
4516 | 310 | oid = self._jar.new_oid() | 311 | oid = self._jar.new_oid() |
4521 | 311 | obj._p_jar = self._jar | 312 | target._p_jar = self._jar |
4522 | 312 | obj._p_oid = oid | 313 | target._p_oid = oid |
4523 | 313 | self._stack.append(obj) | 314 | self._stack.append(target) |
4524 | 314 | return ['w', (oid, )] | 315 | obj.oid = oid |
4525 | 316 | obj.dm = target._p_jar | ||
4526 | 317 | obj.database_name = obj.dm.db().database_name | ||
4527 | 318 | if obj.dm is self._jar: | ||
4528 | 319 | return ['w', (oid, )] | ||
4529 | 320 | else: | ||
4530 | 321 | return ['w', (oid, obj.database_name)] | ||
4531 | 315 | 322 | ||
4532 | 316 | 323 | ||
4533 | 317 | # Since we have an oid, we have either a persistent instance | 324 | # Since we have an oid, we have either a persistent instance |
4534 | @@ -530,10 +537,20 @@ | |||
4535 | 530 | loaders['m'] = load_multi_persistent | 537 | loaders['m'] = load_multi_persistent |
4536 | 531 | 538 | ||
4537 | 532 | 539 | ||
4539 | 533 | def load_persistent_weakref(self, oid): | 540 | def load_persistent_weakref(self, oid, database_name=None): |
4540 | 534 | obj = WeakRef.__new__(WeakRef) | 541 | obj = WeakRef.__new__(WeakRef) |
4541 | 535 | obj.oid = oid | 542 | obj.oid = oid |
4543 | 536 | obj.dm = self._conn | 543 | if database_name is None: |
4544 | 544 | obj.dm = self._conn | ||
4545 | 545 | else: | ||
4546 | 546 | obj.database_name = database_name | ||
4547 | 547 | try: | ||
4548 | 548 | obj.dm = self._conn.get_connection(database_name) | ||
4549 | 549 | except KeyError: | ||
4550 | 550 | # XXX Not sure what to do here. It seems wrong to | ||
4551 | 551 | # fail since this is a weak reference. For now we'll | ||
4552 | 552 | # just pretend that the target object has gone. | ||
4553 | 553 | pass | ||
4554 | 537 | return obj | 554 | return obj |
4555 | 538 | 555 | ||
4556 | 539 | loaders['w'] = load_persistent_weakref | 556 | loaders['w'] = load_persistent_weakref |
4557 | @@ -649,7 +666,7 @@ | |||
4558 | 649 | return oids | 666 | return oids |
4559 | 650 | 667 | ||
4560 | 651 | oid_klass_loaders = { | 668 | oid_klass_loaders = { |
4562 | 652 | 'w': lambda oid: None, | 669 | 'w': lambda oid, database_name=None: None, |
4563 | 653 | } | 670 | } |
4564 | 654 | 671 | ||
4565 | 655 | def get_refs(a_pickle): | 672 | def get_refs(a_pickle): |
4566 | 656 | 673 | ||
4567 | === modified file 'src/ZODB/tests/testConnection.py' | |||
4568 | --- src/ZODB/tests/testConnection.py 2010-03-01 20:29:16 +0000 | |||
4569 | +++ src/ZODB/tests/testConnection.py 2010-07-01 19:15:41 +0000 | |||
4570 | @@ -662,10 +662,26 @@ | |||
4571 | 662 | # sanity check | 662 | # sanity check |
4572 | 663 | self.assert_(cache.total_estimated_size >= 0) | 663 | self.assert_(cache.total_estimated_size >= 0) |
4573 | 664 | 664 | ||
4578 | 665 | 665 | def test_cache_garbage_collection_shrinking_object(self): | |
4579 | 666 | 666 | db = self.db | |
4580 | 667 | 667 | # activate size based cache garbage collection | |
4581 | 668 | 668 | db.setCacheSizeBytes(1000) | |
4582 | 669 | obj, conn, cache = self.obj, self.conn, self.conn._cache | ||
4583 | 670 | # verify the change worked as expected | ||
4584 | 671 | self.assertEqual(cache.cache_size_bytes, 1000) | ||
4585 | 672 | # verify our entrance assumption is fullfilled | ||
4586 | 673 | self.assert_(cache.total_estimated_size > 1) | ||
4587 | 674 | # give the objects some size | ||
4588 | 675 | obj.setValueWithSize(500) | ||
4589 | 676 | transaction.savepoint() | ||
4590 | 677 | self.assert_(cache.total_estimated_size > 500) | ||
4591 | 678 | # make the object smaller | ||
4592 | 679 | obj.setValueWithSize(100) | ||
4593 | 680 | transaction.savepoint() | ||
4594 | 681 | # make sure there was no overflow | ||
4595 | 682 | self.assert_(cache.total_estimated_size != 0) | ||
4596 | 683 | # the size is not larger than the allowed maximum | ||
4597 | 684 | self.assert_(cache.total_estimated_size <= 1000) | ||
4598 | 669 | 685 | ||
4599 | 670 | # ---- stubs | 686 | # ---- stubs |
4600 | 671 | 687 | ||
4601 | 672 | 688 | ||
4602 | === modified file 'src/ZODB/tests/testConnectionSavepoint.py' | |||
4603 | --- src/ZODB/tests/testConnectionSavepoint.py 2010-03-01 20:29:16 +0000 | |||
4604 | +++ src/ZODB/tests/testConnectionSavepoint.py 2010-07-01 19:15:41 +0000 | |||
4605 | @@ -13,7 +13,7 @@ | |||
4606 | 13 | ############################################################################## | 13 | ############################################################################## |
4607 | 14 | """Tests of savepoint feature | 14 | """Tests of savepoint feature |
4608 | 15 | 15 | ||
4610 | 16 | $Id: testConnectionSavepoint.py 103082 2009-08-22 13:36:27Z jim $ | 16 | $Id: testConnectionSavepoint.py 111314 2010-04-23 17:30:12Z jim $ |
4611 | 17 | """ | 17 | """ |
4612 | 18 | import unittest | 18 | import unittest |
4613 | 19 | from zope.testing import doctest | 19 | from zope.testing import doctest |
4614 | @@ -154,6 +154,34 @@ | |||
4615 | 154 | False | 154 | False |
4616 | 155 | """ | 155 | """ |
4617 | 156 | 156 | ||
4618 | 157 | class SelfActivatingObject(persistent.Persistent): | ||
4619 | 158 | |||
4620 | 159 | def _p_invalidate(self): | ||
4621 | 160 | super(SelfActivatingObject, self)._p_invalidate() | ||
4622 | 161 | self._p_activate() | ||
4623 | 162 | |||
4624 | 163 | def testInvalidateAfterRollback(): | ||
4625 | 164 | """\ | ||
4626 | 165 | The rollback used to invalidate objects before resetting the TmpStore. | ||
4627 | 166 | This caused problems for custom _p_invalidate methods that would load | ||
4628 | 167 | the wrong state. | ||
4629 | 168 | |||
4630 | 169 | >>> import ZODB.tests.util | ||
4631 | 170 | >>> db = ZODB.tests.util.DB() | ||
4632 | 171 | >>> connection = db.open() | ||
4633 | 172 | >>> root = connection.root() | ||
4634 | 173 | |||
4635 | 174 | >>> root['p'] = p = SelfActivatingObject() | ||
4636 | 175 | >>> transaction.commit() | ||
4637 | 176 | >>> p.foo = 1 | ||
4638 | 177 | >>> sp = transaction.savepoint() | ||
4639 | 178 | >>> p.foo = 2 | ||
4640 | 179 | >>> sp2 = transaction.savepoint() | ||
4641 | 180 | >>> sp.rollback() | ||
4642 | 181 | >>> p.foo # This used to wrongly return 2 | ||
4643 | 182 | 1 | ||
4644 | 183 | """ | ||
4645 | 184 | |||
4646 | 157 | def tearDown(test): | 185 | def tearDown(test): |
4647 | 158 | transaction.abort() | 186 | transaction.abort() |
4648 | 159 | 187 | ||
4649 | 160 | 188 | ||
4650 | === added directory 'src/Zope3.egg-info' | |||
4651 | === added file 'src/Zope3.egg-info/PKG-INFO' | |||
4652 | --- src/Zope3.egg-info/PKG-INFO 1970-01-01 00:00:00 +0000 | |||
4653 | +++ src/Zope3.egg-info/PKG-INFO 2010-07-01 19:15:41 +0000 | |||
4654 | @@ -0,0 +1,10 @@ | |||
4655 | 1 | Metadata-Version: 1.0 | ||
4656 | 2 | Name: Zope3 | ||
4657 | 3 | Version: 3.5dev | ||
4658 | 4 | Summary: Zope3 | ||
4659 | 5 | Home-page: UNKNOWN | ||
4660 | 6 | Author: Zope Corporation and Contributors | ||
4661 | 7 | Author-email: zope-dev@zope.org | ||
4662 | 8 | License: UNKNOWN | ||
4663 | 9 | Description: UNKNOWN | ||
4664 | 10 | Platform: UNKNOWN | ||
4665 | 0 | 11 | ||
4666 | === added file 'src/Zope3.egg-info/SOURCES.txt' | |||
4667 | --- src/Zope3.egg-info/SOURCES.txt 1970-01-01 00:00:00 +0000 | |||
4668 | +++ src/Zope3.egg-info/SOURCES.txt 2010-07-01 19:15:41 +0000 | |||
4669 | @@ -0,0 +1,1924 @@ | |||
4670 | 1 | README.txt | ||
4671 | 2 | setup.py | ||
4672 | 3 | src/BTrees/IFBTree.py | ||
4673 | 4 | src/BTrees/IIBTree.py | ||
4674 | 5 | src/BTrees/IOBTree.py | ||
4675 | 6 | src/BTrees/Interfaces.py | ||
4676 | 7 | src/BTrees/LFBTree.py | ||
4677 | 8 | src/BTrees/LLBTree.py | ||
4678 | 9 | src/BTrees/LOBTree.py | ||
4679 | 10 | src/BTrees/Length.py | ||
4680 | 11 | src/BTrees/OIBTree.py | ||
4681 | 12 | src/BTrees/OLBTree.py | ||
4682 | 13 | src/BTrees/OOBTree.py | ||
4683 | 14 | src/BTrees/_IFBTree.c | ||
4684 | 15 | src/BTrees/_IFBTree.py | ||
4685 | 16 | src/BTrees/_IIBTree.c | ||
4686 | 17 | src/BTrees/_IIBTree.py | ||
4687 | 18 | src/BTrees/_IOBTree.c | ||
4688 | 19 | src/BTrees/_IOBTree.py | ||
4689 | 20 | src/BTrees/_LFBTree.c | ||
4690 | 21 | src/BTrees/_LFBTree.py | ||
4691 | 22 | src/BTrees/_LLBTree.c | ||
4692 | 23 | src/BTrees/_LLBTree.py | ||
4693 | 24 | src/BTrees/_LOBTree.c | ||
4694 | 25 | src/BTrees/_LOBTree.py | ||
4695 | 26 | src/BTrees/_OIBTree.c | ||
4696 | 27 | src/BTrees/_OIBTree.py | ||
4697 | 28 | src/BTrees/_OLBTree.c | ||
4698 | 29 | src/BTrees/_OLBTree.py | ||
4699 | 30 | src/BTrees/_OOBTree.c | ||
4700 | 31 | src/BTrees/_OOBTree.py | ||
4701 | 32 | src/BTrees/__init__.py | ||
4702 | 33 | src/BTrees/_fsBTree.c | ||
4703 | 34 | src/BTrees/_fsBTree.py | ||
4704 | 35 | src/BTrees/check.py | ||
4705 | 36 | src/BTrees/fsBTree.py | ||
4706 | 37 | src/BTrees/tests/__init__.py | ||
4707 | 38 | src/BTrees/tests/testBTrees.py | ||
4708 | 39 | src/BTrees/tests/testBTreesUnicode.py | ||
4709 | 40 | src/BTrees/tests/testConflict.py | ||
4710 | 41 | src/BTrees/tests/testLength.py | ||
4711 | 42 | src/BTrees/tests/testSetOps.py | ||
4712 | 43 | src/BTrees/tests/test_btreesubclass.py | ||
4713 | 44 | src/BTrees/tests/test_check.py | ||
4714 | 45 | src/BTrees/tests/test_compare.py | ||
4715 | 46 | src/RestrictedPython/Eval.py | ||
4716 | 47 | src/RestrictedPython/Guards.py | ||
4717 | 48 | src/RestrictedPython/Limits.py | ||
4718 | 49 | src/RestrictedPython/MutatingWalker.py | ||
4719 | 50 | src/RestrictedPython/PrintCollector.py | ||
4720 | 51 | src/RestrictedPython/RCompile.py | ||
4721 | 52 | src/RestrictedPython/RestrictionMutator.py | ||
4722 | 53 | src/RestrictedPython/SelectCompiler.py | ||
4723 | 54 | src/RestrictedPython/Utilities.py | ||
4724 | 55 | src/RestrictedPython/__init__.py | ||
4725 | 56 | src/RestrictedPython/tests/__init__.py | ||
4726 | 57 | src/RestrictedPython/tests/before_and_after.py | ||
4727 | 58 | src/RestrictedPython/tests/before_and_after24.py | ||
4728 | 59 | src/RestrictedPython/tests/before_and_after25.py | ||
4729 | 60 | src/RestrictedPython/tests/before_and_after26.py | ||
4730 | 61 | src/RestrictedPython/tests/class.py | ||
4731 | 62 | src/RestrictedPython/tests/lambda.py | ||
4732 | 63 | src/RestrictedPython/tests/restricted_module.py | ||
4733 | 64 | src/RestrictedPython/tests/security_in_syntax.py | ||
4734 | 65 | src/RestrictedPython/tests/security_in_syntax26.py | ||
4735 | 66 | src/RestrictedPython/tests/testCompile.py | ||
4736 | 67 | src/RestrictedPython/tests/testREADME.py | ||
4737 | 68 | src/RestrictedPython/tests/testRestrictions.py | ||
4738 | 69 | src/RestrictedPython/tests/testUtiliities.py | ||
4739 | 70 | src/RestrictedPython/tests/unpack.py | ||
4740 | 71 | src/RestrictedPython/tests/verify.py | ||
4741 | 72 | src/ZConfig/__init__.py | ||
4742 | 73 | src/ZConfig/cfgparser.py | ||
4743 | 74 | src/ZConfig/cmdline.py | ||
4744 | 75 | src/ZConfig/datatypes.py | ||
4745 | 76 | src/ZConfig/info.py | ||
4746 | 77 | src/ZConfig/loader.py | ||
4747 | 78 | src/ZConfig/matcher.py | ||
4748 | 79 | src/ZConfig/schema.py | ||
4749 | 80 | src/ZConfig/schemaless.py | ||
4750 | 81 | src/ZConfig/substitution.py | ||
4751 | 82 | src/ZConfig/url.py | ||
4752 | 83 | src/ZConfig/components/__init__.py | ||
4753 | 84 | src/ZConfig/components/basic/__init__.py | ||
4754 | 85 | src/ZConfig/components/basic/mapping.py | ||
4755 | 86 | src/ZConfig/components/basic/tests/__init__.py | ||
4756 | 87 | src/ZConfig/components/basic/tests/test_mapping.py | ||
4757 | 88 | src/ZConfig/components/logger/__init__.py | ||
4758 | 89 | src/ZConfig/components/logger/datatypes.py | ||
4759 | 90 | src/ZConfig/components/logger/factory.py | ||
4760 | 91 | src/ZConfig/components/logger/handlers.py | ||
4761 | 92 | src/ZConfig/components/logger/logger.py | ||
4762 | 93 | src/ZConfig/components/logger/loghandler.py | ||
4763 | 94 | src/ZConfig/components/logger/tests/__init__.py | ||
4764 | 95 | src/ZConfig/components/logger/tests/test_logger.py | ||
4765 | 96 | src/ZConfig/tests/__init__.py | ||
4766 | 97 | src/ZConfig/tests/support.py | ||
4767 | 98 | src/ZConfig/tests/test_cfgimports.py | ||
4768 | 99 | src/ZConfig/tests/test_cmdline.py | ||
4769 | 100 | src/ZConfig/tests/test_config.py | ||
4770 | 101 | src/ZConfig/tests/test_cookbook.py | ||
4771 | 102 | src/ZConfig/tests/test_datatypes.py | ||
4772 | 103 | src/ZConfig/tests/test_loader.py | ||
4773 | 104 | src/ZConfig/tests/test_readme.py | ||
4774 | 105 | src/ZConfig/tests/test_schema.py | ||
4775 | 106 | src/ZConfig/tests/test_schemaless.py | ||
4776 | 107 | src/ZConfig/tests/test_subst.py | ||
4777 | 108 | src/ZConfig/tests/library/__init__.py | ||
4778 | 109 | src/ZConfig/tests/library/thing/__init__.py | ||
4779 | 110 | src/ZConfig/tests/library/widget/__init__.py | ||
4780 | 111 | src/ZEO/ClientStorage.py | ||
4781 | 112 | src/ZEO/CommitLog.py | ||
4782 | 113 | src/ZEO/Exceptions.py | ||
4783 | 114 | src/ZEO/ServerStub.py | ||
4784 | 115 | src/ZEO/StorageServer.py | ||
4785 | 116 | src/ZEO/TransactionBuffer.py | ||
4786 | 117 | src/ZEO/__init__.py | ||
4787 | 118 | src/ZEO/cache.py | ||
4788 | 119 | src/ZEO/hash.py | ||
4789 | 120 | src/ZEO/interfaces.py | ||
4790 | 121 | src/ZEO/mkzeoinst.py | ||
4791 | 122 | src/ZEO/monitor.py | ||
4792 | 123 | src/ZEO/runzeo.py | ||
4793 | 124 | src/ZEO/util.py | ||
4794 | 125 | src/ZEO/zeoctl.py | ||
4795 | 126 | src/ZEO/zeopasswd.py | ||
4796 | 127 | src/ZEO/auth/__init__.py | ||
4797 | 128 | src/ZEO/auth/auth_digest.py | ||
4798 | 129 | src/ZEO/auth/base.py | ||
4799 | 130 | src/ZEO/auth/hmac.py | ||
4800 | 131 | src/ZEO/scripts/__init__.py | ||
4801 | 132 | src/ZEO/scripts/parsezeolog.py | ||
4802 | 133 | src/ZEO/scripts/tests.py | ||
4803 | 134 | src/ZEO/scripts/timeout.py | ||
4804 | 135 | src/ZEO/scripts/zeopack.py | ||
4805 | 136 | src/ZEO/scripts/zeoqueue.py | ||
4806 | 137 | src/ZEO/scripts/zeoreplay.py | ||
4807 | 138 | src/ZEO/scripts/zeoserverlog.py | ||
4808 | 139 | src/ZEO/scripts/zeoup.py | ||
4809 | 140 | src/ZEO/tests/Cache.py | ||
4810 | 141 | src/ZEO/tests/CommitLockTests.py | ||
4811 | 142 | src/ZEO/tests/ConnectionTests.py | ||
4812 | 143 | src/ZEO/tests/InvalidationTests.py | ||
4813 | 144 | src/ZEO/tests/IterationTests.py | ||
4814 | 145 | src/ZEO/tests/TestThread.py | ||
4815 | 146 | src/ZEO/tests/ThreadTests.py | ||
4816 | 147 | src/ZEO/tests/__init__.py | ||
4817 | 148 | src/ZEO/tests/auth_plaintext.py | ||
4818 | 149 | src/ZEO/tests/deadlock.py | ||
4819 | 150 | src/ZEO/tests/forker.py | ||
4820 | 151 | src/ZEO/tests/servertesting.py | ||
4821 | 152 | src/ZEO/tests/speed.py | ||
4822 | 153 | src/ZEO/tests/stress.py | ||
4823 | 154 | src/ZEO/tests/testAuth.py | ||
4824 | 155 | src/ZEO/tests/testConnection.py | ||
4825 | 156 | src/ZEO/tests/testConversionSupport.py | ||
4826 | 157 | src/ZEO/tests/testMonitor.py | ||
4827 | 158 | src/ZEO/tests/testTransactionBuffer.py | ||
4828 | 159 | src/ZEO/tests/testZEO.py | ||
4829 | 160 | src/ZEO/tests/testZEO2.py | ||
4830 | 161 | src/ZEO/tests/testZEOOptions.py | ||
4831 | 162 | src/ZEO/tests/test_cache.py | ||
4832 | 163 | src/ZEO/tests/zeoserver.py | ||
4833 | 164 | src/ZEO/zrpc/__init__.py | ||
4834 | 165 | src/ZEO/zrpc/_hmac.py | ||
4835 | 166 | src/ZEO/zrpc/client.py | ||
4836 | 167 | src/ZEO/zrpc/connection.py | ||
4837 | 168 | src/ZEO/zrpc/error.py | ||
4838 | 169 | src/ZEO/zrpc/log.py | ||
4839 | 170 | src/ZEO/zrpc/marshal.py | ||
4840 | 171 | src/ZEO/zrpc/server.py | ||
4841 | 172 | src/ZEO/zrpc/smac.py | ||
4842 | 173 | src/ZEO/zrpc/trigger.py | ||
4843 | 174 | src/ZODB/ActivityMonitor.py | ||
4844 | 175 | src/ZODB/BaseStorage.py | ||
4845 | 176 | src/ZODB/ConflictResolution.py | ||
4846 | 177 | src/ZODB/Connection.py | ||
4847 | 178 | src/ZODB/DB.py | ||
4848 | 179 | src/ZODB/DemoStorage.py | ||
4849 | 180 | src/ZODB/ExportImport.py | ||
4850 | 181 | src/ZODB/MappingStorage.py | ||
4851 | 182 | src/ZODB/POSException.py | ||
4852 | 183 | src/ZODB/UndoLogCompatible.py | ||
4853 | 184 | src/ZODB/__init__.py | ||
4854 | 185 | src/ZODB/blob.py | ||
4855 | 186 | src/ZODB/broken.py | ||
4856 | 187 | src/ZODB/config.py | ||
4857 | 188 | src/ZODB/conversionhack.py | ||
4858 | 189 | src/ZODB/dbmStorage.py | ||
4859 | 190 | src/ZODB/fsIndex.py | ||
4860 | 191 | src/ZODB/fsrecover.py | ||
4861 | 192 | src/ZODB/fstools.py | ||
4862 | 193 | src/ZODB/interfaces.py | ||
4863 | 194 | src/ZODB/loglevels.py | ||
4864 | 195 | src/ZODB/persistentclass.py | ||
4865 | 196 | src/ZODB/serialize.py | ||
4866 | 197 | src/ZODB/transact.py | ||
4867 | 198 | src/ZODB/utils.py | ||
4868 | 199 | src/ZODB/FileStorage/FileStorage.py | ||
4869 | 200 | src/ZODB/FileStorage/__init__.py | ||
4870 | 201 | src/ZODB/FileStorage/format.py | ||
4871 | 202 | src/ZODB/FileStorage/fsdump.py | ||
4872 | 203 | src/ZODB/FileStorage/fsoids.py | ||
4873 | 204 | src/ZODB/FileStorage/fspack.py | ||
4874 | 205 | src/ZODB/FileStorage/interfaces.py | ||
4875 | 206 | src/ZODB/FileStorage/tests.py | ||
4876 | 207 | src/ZODB/scripts/__init__.py | ||
4877 | 208 | src/ZODB/scripts/analyze.py | ||
4878 | 209 | src/ZODB/scripts/checkbtrees.py | ||
4879 | 210 | src/ZODB/scripts/fsoids.py | ||
4880 | 211 | src/ZODB/scripts/fsrefs.py | ||
4881 | 212 | src/ZODB/scripts/fsstats.py | ||
4882 | 213 | src/ZODB/scripts/fstail.py | ||
4883 | 214 | src/ZODB/scripts/fstest.py | ||
4884 | 215 | src/ZODB/scripts/migrate.py | ||
4885 | 216 | src/ZODB/scripts/migrateblobs.py | ||
4886 | 217 | src/ZODB/scripts/netspace.py | ||
4887 | 218 | src/ZODB/scripts/referrers.py | ||
4888 | 219 | src/ZODB/scripts/repozo.py | ||
4889 | 220 | src/ZODB/scripts/simul.py | ||
4890 | 221 | src/ZODB/scripts/space.py | ||
4891 | 222 | src/ZODB/scripts/stats.py | ||
4892 | 223 | src/ZODB/scripts/zodbload.py | ||
4893 | 224 | src/ZODB/scripts/tests/__init__.py | ||
4894 | 225 | src/ZODB/scripts/tests/test_doc.py | ||
4895 | 226 | src/ZODB/scripts/tests/test_repozo.py | ||
4896 | 227 | src/ZODB/tests/BasicStorage.py | ||
4897 | 228 | src/ZODB/tests/ConflictResolution.py | ||
4898 | 229 | src/ZODB/tests/Corruption.py | ||
4899 | 230 | src/ZODB/tests/HistoryStorage.py | ||
4900 | 231 | src/ZODB/tests/IteratorStorage.py | ||
4901 | 232 | src/ZODB/tests/MTStorage.py | ||
4902 | 233 | src/ZODB/tests/MVCCMappingStorage.py | ||
4903 | 234 | src/ZODB/tests/MinPO.py | ||
4904 | 235 | src/ZODB/tests/PackableStorage.py | ||
4905 | 236 | src/ZODB/tests/PersistentStorage.py | ||
4906 | 237 | src/ZODB/tests/ReadOnlyStorage.py | ||
4907 | 238 | src/ZODB/tests/RecoveryStorage.py | ||
4908 | 239 | src/ZODB/tests/RevisionStorage.py | ||
4909 | 240 | src/ZODB/tests/StorageTestBase.py | ||
4910 | 241 | src/ZODB/tests/Synchronization.py | ||
4911 | 242 | src/ZODB/tests/TransactionalUndoStorage.py | ||
4912 | 243 | src/ZODB/tests/__init__.py | ||
4913 | 244 | src/ZODB/tests/dangle.py | ||
4914 | 245 | src/ZODB/tests/loggingsupport.py | ||
4915 | 246 | src/ZODB/tests/sampledm.py | ||
4916 | 247 | src/ZODB/tests/speed.py | ||
4917 | 248 | src/ZODB/tests/testActivityMonitor.py | ||
4918 | 249 | src/ZODB/tests/testBroken.py | ||
4919 | 250 | src/ZODB/tests/testCache.py | ||
4920 | 251 | src/ZODB/tests/testConfig.py | ||
4921 | 252 | src/ZODB/tests/testConnection.py | ||
4922 | 253 | src/ZODB/tests/testConnectionSavepoint.py | ||
4923 | 254 | src/ZODB/tests/testDB.py | ||
4924 | 255 | src/ZODB/tests/testDemoStorage.py | ||
4925 | 256 | src/ZODB/tests/testFileStorage.py | ||
4926 | 257 | src/ZODB/tests/testMVCCMappingStorage.py | ||
4927 | 258 | src/ZODB/tests/testMappingStorage.py | ||
4928 | 259 | src/ZODB/tests/testPersistentList.py | ||
4929 | 260 | src/ZODB/tests/testPersistentMapping.py | ||
4930 | 261 | src/ZODB/tests/testRecover.py | ||
4931 | 262 | src/ZODB/tests/testSerialize.py | ||
4932 | 263 | src/ZODB/tests/testTimeStamp.py | ||
4933 | 264 | src/ZODB/tests/testUtils.py | ||
4934 | 265 | src/ZODB/tests/testZODB.py | ||
4935 | 266 | src/ZODB/tests/test_cache.py | ||
4936 | 267 | src/ZODB/tests/test_datamanageradapter.py | ||
4937 | 268 | src/ZODB/tests/test_doctest_files.py | ||
4938 | 269 | src/ZODB/tests/test_fsdump.py | ||
4939 | 270 | src/ZODB/tests/test_storage.py | ||
4940 | 271 | src/ZODB/tests/testblob.py | ||
4941 | 272 | src/ZODB/tests/testconflictresolution.py | ||
4942 | 273 | src/ZODB/tests/testcrossdatabasereferences.py | ||
4943 | 274 | src/ZODB/tests/testfsIndex.py | ||
4944 | 275 | src/ZODB/tests/testfsoids.py | ||
4945 | 276 | src/ZODB/tests/testhistoricalconnections.py | ||
4946 | 277 | src/ZODB/tests/testmvcc.py | ||
4947 | 278 | src/ZODB/tests/testpersistentclass.py | ||
4948 | 279 | src/ZODB/tests/util.py | ||
4949 | 280 | src/ZODB/tests/warnhook.py | ||
4950 | 281 | src/Zope3.egg-info/PKG-INFO | ||
4951 | 282 | src/Zope3.egg-info/SOURCES.txt | ||
4952 | 283 | src/Zope3.egg-info/dependency_links.txt | ||
4953 | 284 | src/Zope3.egg-info/namespace_packages.txt | ||
4954 | 285 | src/Zope3.egg-info/not-zip-safe | ||
4955 | 286 | src/Zope3.egg-info/top_level.txt | ||
4956 | 287 | src/docutils/__init__.py | ||
4957 | 288 | src/docutils/_compat.py | ||
4958 | 289 | src/docutils/_string_template_compat.py | ||
4959 | 290 | src/docutils/core.py | ||
4960 | 291 | src/docutils/examples.py | ||
4961 | 292 | src/docutils/frontend.py | ||
4962 | 293 | src/docutils/io.py | ||
4963 | 294 | src/docutils/nodes.py | ||
4964 | 295 | src/docutils/statemachine.py | ||
4965 | 296 | src/docutils/urischemes.py | ||
4966 | 297 | src/docutils/utils.py | ||
4967 | 298 | src/docutils/languages/__init__.py | ||
4968 | 299 | src/docutils/languages/af.py | ||
4969 | 300 | src/docutils/languages/ca.py | ||
4970 | 301 | src/docutils/languages/cs.py | ||
4971 | 302 | src/docutils/languages/de.py | ||
4972 | 303 | src/docutils/languages/en.py | ||
4973 | 304 | src/docutils/languages/eo.py | ||
4974 | 305 | src/docutils/languages/es.py | ||
4975 | 306 | src/docutils/languages/fi.py | ||
4976 | 307 | src/docutils/languages/fr.py | ||
4977 | 308 | src/docutils/languages/gl.py | ||
4978 | 309 | src/docutils/languages/he.py | ||
4979 | 310 | src/docutils/languages/it.py | ||
4980 | 311 | src/docutils/languages/ja.py | ||
4981 | 312 | src/docutils/languages/nl.py | ||
4982 | 313 | src/docutils/languages/pl.py | ||
4983 | 314 | src/docutils/languages/pt_br.py | ||
4984 | 315 | src/docutils/languages/ru.py | ||
4985 | 316 | src/docutils/languages/sk.py | ||
4986 | 317 | src/docutils/languages/sv.py | ||
4987 | 318 | src/docutils/languages/zh_cn.py | ||
4988 | 319 | src/docutils/languages/zh_tw.py | ||
4989 | 320 | src/docutils/parsers/__init__.py | ||
4990 | 321 | src/docutils/parsers/null.py | ||
4991 | 322 | src/docutils/parsers/rst/__init__.py | ||
4992 | 323 | src/docutils/parsers/rst/roles.py | ||
4993 | 324 | src/docutils/parsers/rst/states.py | ||
4994 | 325 | src/docutils/parsers/rst/tableparser.py | ||
4995 | 326 | src/docutils/parsers/rst/directives/__init__.py | ||
4996 | 327 | src/docutils/parsers/rst/directives/admonitions.py | ||
4997 | 328 | src/docutils/parsers/rst/directives/body.py | ||
4998 | 329 | src/docutils/parsers/rst/directives/html.py | ||
4999 | 330 | src/docutils/parsers/rst/directives/images.py | ||
5000 | 331 | src/docutils/parsers/rst/directives/misc.py |
The diff has been truncated for viewing.
+1!