zc.sourcefactory<\/a> is very handy to easily create a source (zope.schema.interfaces.IIterableSource to be precise) with corresponding titles and tokens for its contents. Every now and then a source requires an explicit interface. For zc.sourcefactory the following code snippet helps:<\/p>\nclass IMySource(zope.schema.interfaces.IIterableSource):\r\n \"\"\"my source\"\"\"\r\n\r\nclass MySource(\r\n zc.sourcefactory.contextual.BasicContextualSourceFactory):\r\n \"\"\"The source factory.\"\"\"\r\n\r\n class source_class(\r\n zc.sourcefactory.source.FactoredContextualSource):\r\n \"\"\"This class is being instanciated by the factory.\r\n\r\n It *must* be called source_class.\r\n \"\"\"\r\n zope.interface.implements(IMySource)\r\n\r\n def getValues(self, context):\r\n \u2026<\/pre>\nOf course it is also possible to declare the source_class separately from the source factory and reference it. But since its sole purpose is to hold an implements declaration, I’m fine with defining it inline.<\/p>\n","protected":false},"excerpt":{"rendered":"
zc.sourcefactory is very handy to easily create a source (zope.schema.interfaces.IIterableSource to be precise) with corresponding titles and tokens for its contents. Every now and then a source requires an explicit interface. For zc.sourcefactory the following code snippet helps: class IMySource(zope.schema.interfaces.IIterableSource): “””my source””” class MySource( zc.sourcefactory.contextual.BasicContextualSourceFactory): “””The source factory.””” class source_class( zc.sourcefactory.source.FactoredContextualSource): “””This class is being … Continue reading “Get a zc.sourcefactory to implement an interface”<\/span><\/a><\/p>\n","protected":false},"author":12389382,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_newsletter_tier_id":0,"footnotes":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[10221],"tags":[832,72208,33810459],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_likes_enabled":true,"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/pFP3y-11","jetpack-related-posts":[{"id":162,"url":"https:\/\/blog.gocept.com\/2012\/05\/11\/custom-widgets-in-zope-formlib\/","url_meta":{"origin":63,"position":0},"title":"Custom widgets in zope.formlib","author":"Michael Howitz","date":"May 11, 2012","format":false,"excerpt":"zope.formlib\u00a0has the ability to customize the used widget like this: class KeywordsManagementForm(five.formlib.formbase.SubPageForm): form_fields = zope.formlib.form.Fields(IKeywords) form_fields['keywords'].custom_widget = KWSelectWidgetFactory I do not like this approach for two reasons: the widget has to be set manually\u00a0every time the specific field is used there is no easy way to get a display widget\u2026","rel":"","context":"In "en"","block_context":{"text":"en","link":"https:\/\/blog.gocept.com\/category\/en\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2550,"url":"https:\/\/blog.gocept.com\/2017\/08\/22\/zope-preparing-to-enter-python-3-wonderland\/","url_meta":{"origin":63,"position":1},"title":"Zope preparing to enter Python 3 wonderland","author":"Michael Howitz","date":"August 22, 2017","format":false,"excerpt":"Once upon the time there\u00a0was an earl named Zope II. His prophets told him that around the year 2020 suddenly his peaceful country will be\u00a0devastated: They proclaim that with the \"sunset\" of\u00a0 Python 2 as stable pillar of his country, insecurity and pain will invade his borders and hurt everyone\u2026","rel":"","context":"In "en"","block_context":{"text":"en","link":"https:\/\/blog.gocept.com\/category\/en\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/blog.gocept.com\/wp-content\/uploads\/2017\/08\/pexels-photo-242558.jpg?fit=1200%2C800&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/blog.gocept.com\/wp-content\/uploads\/2017\/08\/pexels-photo-242558.jpg?fit=1200%2C800&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/blog.gocept.com\/wp-content\/uploads\/2017\/08\/pexels-photo-242558.jpg?fit=1200%2C800&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/blog.gocept.com\/wp-content\/uploads\/2017\/08\/pexels-photo-242558.jpg?fit=1200%2C800&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/blog.gocept.com\/wp-content\/uploads\/2017\/08\/pexels-photo-242558.jpg?fit=1200%2C800&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":268,"url":"https:\/\/blog.gocept.com\/2012\/11\/09\/python-2-and-3-compatible-builds-with-zc-buildout\/","url_meta":{"origin":63,"position":2},"title":"Python 2 and 3 compatible builds with zc.buildout","author":"","date":"November 9, 2012","format":false,"excerpt":"Creating a single-source build environment with zc.buildout that works for both Python 2 and 3 is a bit of a hassle. This blog post shows how to do it for a minimal demo project. During the sprints at PyCon DE 2012, we tried to make the upcoming 1.0 release of\u2026","rel":"","context":"In "en"","block_context":{"text":"en","link":"https:\/\/blog.gocept.com\/category\/en\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":135,"url":"https:\/\/blog.gocept.com\/2012\/04\/03\/profiling-class-based-views\/","url_meta":{"origin":63,"position":3},"title":"Profiling class-based views","author":"","date":"April 3, 2012","format":false,"excerpt":"Just a quick note for profiling e.g. Zope views: class MyView(object): \u00a0\u00a0\u00a0 def __call__(self): \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 result = {} \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 cProfile.runctx('result[\"x\"] = super(Body, self).__call__()', \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 globals(), locals(), '\/tmp\/viewprofile') \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 return result['x'] Even though \"exec 'result = super(...) in globals(), locals()' works, it seems that cProfile does something a little differently here,\u2026","rel":"","context":"In "en"","block_context":{"text":"en","link":"https:\/\/blog.gocept.com\/category\/en\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":349,"url":"https:\/\/blog.gocept.com\/2012\/12\/17\/yafowil-in-a-pyramid-project\/","url_meta":{"origin":63,"position":4},"title":"yafowil in a Pyramid project","author":"Michael Howitz","date":"December 17, 2012","format":false,"excerpt":"In a new Pyramid\u00a0project we used deform\u00a0to render forms. We did not really like it. (The reasons might be detailed in another post.) To see if other form libraries do better I\u00a0gave yafowil\u00a0a try at our\u00a0gocept Developer Punsch\u00a03: yafowil comes with written documentation. To get a form in our Pyramid\u2026","rel":"","context":"In "en"","block_context":{"text":"en","link":"https:\/\/blog.gocept.com\/category\/en\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1367,"url":"https:\/\/blog.gocept.com\/2013\/10\/17\/improving-http-security-at-the-flying-circus\/","url_meta":{"origin":63,"position":5},"title":"Improving HTTP security at the Flying Circus","author":"","date":"October 17, 2013","format":false,"excerpt":"We now know that the secret services employ extended eavesdropping techniques to scan and analyze nearly all Internet traffic. This worries us since we want to keep our customers' data confidential. We get a lot of questions about how secure sites hosted at the Flying Circus are. As security has\u2026","rel":"","context":"In "en"","block_context":{"text":"en","link":"https:\/\/blog.gocept.com\/category\/en\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/blog.gocept.com\/wp-json\/wp\/v2\/posts\/63"}],"collection":[{"href":"https:\/\/blog.gocept.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.gocept.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.gocept.com\/wp-json\/wp\/v2\/users\/12389382"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.gocept.com\/wp-json\/wp\/v2\/comments?post=63"}],"version-history":[{"count":9,"href":"https:\/\/blog.gocept.com\/wp-json\/wp\/v2\/posts\/63\/revisions"}],"predecessor-version":[{"id":338,"href":"https:\/\/blog.gocept.com\/wp-json\/wp\/v2\/posts\/63\/revisions\/338"}],"wp:attachment":[{"href":"https:\/\/blog.gocept.com\/wp-json\/wp\/v2\/media?parent=63"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.gocept.com\/wp-json\/wp\/v2\/categories?post=63"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.gocept.com\/wp-json\/wp\/v2\/tags?post=63"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}