Hashing algorithms in Python 3

While working on a larger project there was a need to detect some changes happened in given data structures. Usually, you immediately start over using the default hashing algorithm md5: Python 3.4.5 (default, Jan 14 2017, 22:06:30) [GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)] on darwin Type "help", "copyright", "credits" or "license" for more information. Let’s compare 2 strings: >>> aa = "Hello World" >>> bb = "Hello World" >>> aa == bb True So obviouly, these strings are equal. So also hashlib should confirm this: ...

May 17, 2017 · 4 min · 799 words · dw

Connect devpi to your docker container

You’re running pip install, buildout or your automated tests within a docker container and after running it multiple times you’ve become tired of waiting for it to finally complete? Then it’s time to connect a devpi server. Docker installation required Docker must be installed on your system. $ docker version Client: Docker Engine - Community Version: 19.03.5 API version: 1.40 Go version: go1.12.12 Git commit: 633a0ea Built: Wed Nov 13 07:22:34 2019 OS/Arch: darwin/amd64 Experimental: false Server: Docker Engine - Community Engine: Version: 19.03.5 API version: 1.40 (minimum version 1.12) Go version: go1.12.12 Git commit: 633a0ea Built: Wed Nov 13 07:29:19 2019 OS/Arch: linux/amd64 Experimental: false containerd: Version: v1.2.10 GitCommit: b34a5c8af56e510852c35414db4c1f4fa6172339 runc: Version: 1.0.0-rc8+dev GitCommit: 3e425f80a8c931f88e6d94a8c831b9d5aa481657 docker-init: Version: 0.18.0 GitCommit: fec3683 You’ll need a working directory where docker-compose.yml file and certificates are stored in, so please create a folder my-devpi as shown below: ...

January 7, 2016 · 2 min · 424 words · dw

Image filesize validator for dexterity content types in Plone

When using Plone 4.3 with plone.app.contenttypes you might want to limit max filesize for images by implementing a custom z3c.form validator. In ATCT we were able to limit max image filesize by overwriting ATCT config file or setting in portal_atct tool. Using webserver The simplest way to achieve a max-upload size is to just limit client_max_body_size in nginx webserver (or simliar in apache). But my current solution is really different. It creates a validator for a special fieldtype, in our special case a INamedBlobImageField. ...

May 31, 2013 · 1 min · 203 words · dw

Use Babel to translate your python package

I use egg-containing buildouts for all my Plone packages. Since i18ndude does not extract msgids from zcml files, i tried Babel and succeeded. Problem You want to translate titles in Plone’s diplay menu by adding browser:menuItem in your zcml file as shown here. <configure xmlns="http://namespaces.zope.org/zope" xmlns:browser="http://namespaces.zope.org/browser" xmlns:plone="http://namespaces.plone.org/plone" xmlns:i18n="http://namespaces.zope.org/i18n" i18n:domain="my.package"> <browser:page for="plone.folder.interfaces.IOrderableFolder" name="a_new_view" class=".demo_view.DemoView" permission="zope2.View" template="templates/demo_view.pt" /> <!-- Entry in display menu --> <browser:menuItem for="plone.folder.interfaces.IOrderableFolder" menu="plone_displayviews" title="A new view" action="@@a_new_view" description="I want a view with translated title and description" i18n:attributes="title; description" /> </configure> i18ndude does not extract message ids from zcml files, so i tried a diffent solution using Babel. ...

April 1, 2013 · 3 min · 594 words · Daniel

Howto use buildout version pins?

When using Plone with buildout you want to be able to reproduce your environment with the same set of eggs, even if there were some new releases in between. buildout 2.x For buildout 2.x they implemented a lot of improvements for pinning versions. allow-picked-versions allow buildout to download pinned packages only. Not pinned but required packages will raise an Exception. show-picked-versions shows a summary of picked versions after your first buildout run. You can copy'n'paste this into a versions.cfg file. buildout 1.x Manually Without pinning your eggs it will be impossible to reproduce the deployed buildout configuration in future. Use a this buildout extension for future projects to avoid this pitfall: ...

November 14, 2012 · 2 min · 238 words · dw

Change minute_step in Archetypes DateTimeWidget

Sometimes you need minutes which could not be divided by 5 which Plone doesn’t select you by default. You don’t need to rewrite core components in Archetypes DateTimeWidget to change this. Prerequisites You need your own BrowserLayer (a skin or theme product) or a contenttype with at least one marker interface to customize on. Howto Create a file called datecomponents.py in your browser directory with following content: from plone.app.form.widgets import datecomponents class DateComponents(datecomponents.DateComponents): def result(self, date=None, use_ampm=False, starting_year=None, ending_year=None, future_years=None, minute_step=5): # Change minute steps to 1 return super(DateComponents, self).result(date, use_ampm, starting_year, ending_year, future_years, 1) … and register it for you browserlayer (replace IThemeSpecific by your layer interface) or for a type you want to customize its widget (replace for='*' with your types interface), thats it. ...

August 31, 2010 · 1 min · 141 words · dw

Howto use custom color for collective.captcha?

How to use your custom color with collective.captcha and Plone? This tutorial shows you an easy way to customize it using your own BrowserLayer. collective.captcha uses a BrowserView to display it’s captcha image. Therefore it’s very easy to customize it for your own theme because you can subclass that BrowserView for your own theme layer which is a BrowserLayer. You can change colors and/or fonts as you need it for your custom theme without doing any code change on the original collective.captcha package. ...

April 23, 2009 · 2 min · 275 words · dw