<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Python on widerin</title><link>http://widerin.net/tags/python/</link><description>Recent content in Python on widerin</description><generator>Hugo</generator><language>en</language><lastBuildDate>Sun, 26 Jul 2020 12:30:34 +0200</lastBuildDate><atom:link href="http://widerin.net/tags/python/index.xml" rel="self" type="application/rss+xml"/><item><title>Hashing algorithms in Python 3</title><link>http://widerin.net/posts/2017/hashing-algorithms-in-python-3/</link><pubDate>Wed, 17 May 2017 00:00:00 +0000</pubDate><guid>http://widerin.net/posts/2017/hashing-algorithms-in-python-3/</guid><description>&lt;p&gt;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 &lt;code&gt;md5&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;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 &amp;quot;help&amp;quot;, &amp;quot;copyright&amp;quot;, &amp;quot;credits&amp;quot; or &amp;quot;license&amp;quot; for more information.
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Let&amp;rsquo;s compare 2 strings:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; aa = &amp;quot;Hello World&amp;quot;
&amp;gt;&amp;gt;&amp;gt; bb = &amp;quot;Hello World&amp;quot;
&amp;gt;&amp;gt;&amp;gt; aa == bb
True
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;So obviouly, these strings are equal. So also &lt;code&gt;hashlib&lt;/code&gt; should confirm this:&lt;/p&gt;</description></item><item><title>Connect devpi to your docker container</title><link>http://widerin.net/posts/2016/connect-devpi-to-your-docker-container/</link><pubDate>Thu, 07 Jan 2016 00:00:00 +0000</pubDate><guid>http://widerin.net/posts/2016/connect-devpi-to-your-docker-container/</guid><description>&lt;p&gt;You&amp;rsquo;re running &lt;a href="http://pypi.python.org/pypi/pip"&gt;pip install&lt;/a&gt;,
&lt;a href="http://pypi.python.org/pypi/zc.buildout"&gt;buildout&lt;/a&gt; or your automated
tests within a &lt;a href="https://www.docker.com"&gt;docker&lt;/a&gt; container and after
running it multiple times you&amp;rsquo;ve become tired of waiting for it to
finally complete? Then it&amp;rsquo;s time to connect a
&lt;a href="http://doc.devpi.net"&gt;devpi&lt;/a&gt; server.&lt;/p&gt;
&lt;div class="callout callout-info"&gt;
&lt;p class="callout-title"&gt;Docker installation required&lt;/p&gt;
&lt;a href="https://docs.docker.com/engine/installation/"&gt;Docker&lt;/a&gt; must be installed on your system.
&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-console" data-lang="console"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="gp"&gt;$&lt;/span&gt; docker version
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="go"&gt;Client: Docker Engine - Community
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="go"&gt; Version: 19.03.5
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="go"&gt; API version: 1.40
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="go"&gt; Go version: go1.12.12
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="go"&gt; Git commit: 633a0ea
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="go"&gt; Built: Wed Nov 13 07:22:34 2019
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="go"&gt; OS/Arch: darwin/amd64
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="go"&gt; Experimental: false
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="err"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="go"&gt;Server: Docker Engine - Community
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="go"&gt; Engine:
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="go"&gt; Version: 19.03.5
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="go"&gt; API version: 1.40 (minimum version 1.12)
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="go"&gt; Go version: go1.12.12
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="go"&gt; Git commit: 633a0ea
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="go"&gt; Built: Wed Nov 13 07:29:19 2019
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="go"&gt; OS/Arch: linux/amd64
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="go"&gt; Experimental: false
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="go"&gt; containerd:
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="go"&gt; Version: v1.2.10
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="go"&gt; GitCommit: b34a5c8af56e510852c35414db4c1f4fa6172339
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="go"&gt; runc:
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="go"&gt; Version: 1.0.0-rc8+dev
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="go"&gt; GitCommit: 3e425f80a8c931f88e6d94a8c831b9d5aa481657
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="go"&gt; docker-init:
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="go"&gt; Version: 0.18.0
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="go"&gt; GitCommit: fec3683
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;You&amp;rsquo;ll need a working directory where &lt;code&gt;docker-compose.yml&lt;/code&gt; file and
certificates are stored in, so please create a folder &lt;code&gt;my-devpi&lt;/code&gt; as
shown below:&lt;/p&gt;</description></item><item><title>Image filesize validator for dexterity content types in Plone</title><link>http://widerin.net/posts/2013/image-filesize-validator-for-dexterity-content-types-in-plone/</link><pubDate>Fri, 31 May 2013 00:00:00 +0000</pubDate><guid>http://widerin.net/posts/2013/image-filesize-validator-for-dexterity-content-types-in-plone/</guid><description>&lt;p&gt;When using &lt;a href="http://plone.org"&gt;Plone&lt;/a&gt; 4.3 with &lt;a href="https://pypi.python.org/pypi/plone.app.contenttypes"&gt;plone.app.contenttypes&lt;/a&gt;
you might want to limit max filesize for images by implementing a custom
&lt;a href="https://pypi.python.org/pypi/z3c.form"&gt;z3c.form&lt;/a&gt; validator. In ATCT we
were able to limit max image filesize by overwriting ATCT config file or
setting in &lt;code&gt;portal_atct&lt;/code&gt; tool.&lt;/p&gt;
&lt;h2 id="using-webserver"&gt;Using webserver&lt;/h2&gt;
&lt;p&gt;The simplest way to achieve a max-upload size is to just limit
&lt;code&gt;client_max_body_size&lt;/code&gt; in &lt;a href="http://nginx.org"&gt;nginx&lt;/a&gt; webserver (or
simliar in apache).&lt;/p&gt;
&lt;p&gt;But my current solution is really different. It creates a validator for
a special fieldtype, in our special case a &lt;code&gt;INamedBlobImageField&lt;/code&gt;.&lt;/p&gt;</description></item><item><title>Use Babel to translate your python package</title><link>http://widerin.net/posts/2013/use-babel-to-translate-your-python-package/</link><pubDate>Mon, 01 Apr 2013 00:00:00 +0000</pubDate><guid>http://widerin.net/posts/2013/use-babel-to-translate-your-python-package/</guid><description>&lt;p&gt;I use egg-containing &lt;a href="http://www.buildout.org/"&gt;buildout&lt;/a&gt;s for all my &lt;a href="https://plone.org"&gt;Plone&lt;/a&gt; packages. Since &lt;a href="https://pypi.org/project/i18ndude/"&gt;i18ndude&lt;/a&gt;
does not extract msgids from zcml files, i tried &lt;a href="http://babel.pocoo.org/"&gt;Babel&lt;/a&gt; and succeeded.&lt;/p&gt;
&lt;h2 id="problem"&gt;Problem&lt;/h2&gt;
&lt;p&gt;You want to translate titles in &lt;a href="https://plone.org"&gt;Plone&lt;/a&gt;&amp;rsquo;s diplay menu by adding &lt;code&gt;browser:menuItem&lt;/code&gt; in your zcml file as &lt;a href="http://developer.plone.org/content/dynamic_views.html#registering-a-dynamic-view-menu-item"&gt;shown here&lt;/a&gt;.&lt;/p&gt;
&lt;pre tabindex="0"&gt;&lt;code&gt;&amp;lt;configure
xmlns=&amp;#34;http://namespaces.zope.org/zope&amp;#34;
xmlns:browser=&amp;#34;http://namespaces.zope.org/browser&amp;#34;
xmlns:plone=&amp;#34;http://namespaces.plone.org/plone&amp;#34;
xmlns:i18n=&amp;#34;http://namespaces.zope.org/i18n&amp;#34;
i18n:domain=&amp;#34;my.package&amp;#34;&amp;gt;
&amp;lt;browser:page
for=&amp;#34;plone.folder.interfaces.IOrderableFolder&amp;#34;
name=&amp;#34;a_new_view&amp;#34;
class=&amp;#34;.demo_view.DemoView&amp;#34;
permission=&amp;#34;zope2.View&amp;#34;
template=&amp;#34;templates/demo_view.pt&amp;#34;
/&amp;gt;
&amp;lt;!-- Entry in display menu --&amp;gt;
&amp;lt;browser:menuItem
for=&amp;#34;plone.folder.interfaces.IOrderableFolder&amp;#34;
menu=&amp;#34;plone_displayviews&amp;#34;
title=&amp;#34;A new view&amp;#34;
action=&amp;#34;@@a_new_view&amp;#34;
description=&amp;#34;I want a view with translated title and description&amp;#34;
i18n:attributes=&amp;#34;title; description&amp;#34;
/&amp;gt;
&amp;lt;/configure&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;a href="https://pypi.org/project/i18ndude/"&gt;i18ndude&lt;/a&gt; does not extract message ids from zcml files, so i tried a diffent solution using &lt;a href="http://babel.pocoo.org/"&gt;Babel&lt;/a&gt;.&lt;/p&gt;</description></item><item><title>Howto use buildout version pins?</title><link>http://widerin.net/posts/2012/howto-use-buildout-version-pins/</link><pubDate>Wed, 14 Nov 2012 00:00:00 +0000</pubDate><guid>http://widerin.net/posts/2012/howto-use-buildout-version-pins/</guid><description>&lt;p&gt;When using &lt;a href="http://plone.org"&gt;Plone&lt;/a&gt; with &lt;a href="http://pypi.python.org/pypi/zc.buildout"&gt;buildout&lt;/a&gt; you want to be able
to reproduce your environment with the same set of eggs, even if there
were some new releases in between.&lt;/p&gt;
&lt;h2 id="buildout-2x"&gt;buildout 2.x&lt;/h2&gt;
&lt;p&gt;For &lt;a href="http://pypi.python.org/pypi/zc.buildout"&gt;buildout&lt;/a&gt; &lt;code&gt;2.x&lt;/code&gt; they implemented a lot of improvements for pinning versions.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;allow-picked-versions&lt;/code&gt; allow buildout to download pinned packages
only. Not pinned but required packages will raise an Exception.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;show-picked-versions&lt;/code&gt; shows a summary of picked versions after your
first buildout run. You can copy'n'paste this into a
&lt;code&gt;versions.cfg&lt;/code&gt; file.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="buildout-1x"&gt;buildout 1.x&lt;/h2&gt;
&lt;h3 id="manually"&gt;Manually&lt;/h3&gt;
&lt;p&gt;Without pinning your eggs it will be impossible to reproduce the deployed
&lt;a href="http://pypi.python.org/pypi/zc.buildout"&gt;buildout&lt;/a&gt; configuration in future. Use a this &lt;a href="http://pypi.python.org/pypi/zc.buildout"&gt;buildout&lt;/a&gt; extension for future
projects to avoid this pitfall:&lt;/p&gt;</description></item><item><title>Change minute_step in Archetypes DateTimeWidget</title><link>http://widerin.net/posts/2010/change-minute_step-in-archetypes-datetimewidget/</link><pubDate>Tue, 31 Aug 2010 00:00:00 +0000</pubDate><guid>http://widerin.net/posts/2010/change-minute_step-in-archetypes-datetimewidget/</guid><description>&lt;p&gt;Sometimes you need minutes which could not be divided by 5 which
&lt;a href="http://plone.org"&gt;Plone&lt;/a&gt; doesn&amp;rsquo;t select you by default. You don&amp;rsquo;t
need to rewrite core components in Archetypes &lt;code&gt;DateTimeWidget&lt;/code&gt; to change
this.&lt;/p&gt;
&lt;h2 id="prerequisites"&gt;Prerequisites&lt;/h2&gt;
&lt;p&gt;You need your own &lt;code&gt;BrowserLayer&lt;/code&gt; (a skin or theme product) or a
contenttype with at least one marker interface to customize on.&lt;/p&gt;
&lt;h2 id="howto"&gt;Howto&lt;/h2&gt;
&lt;p&gt;Create a file called &lt;code&gt;datecomponents.py&lt;/code&gt; in your &lt;code&gt;browser&lt;/code&gt; directory
with following content:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;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)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&amp;hellip; and register it for you browserlayer (replace &lt;code&gt;IThemeSpecific&lt;/code&gt; by
your layer interface) or for a type you want to customize its widget
(replace &lt;code&gt;for='*'&lt;/code&gt; with your types interface), thats it.&lt;/p&gt;</description></item><item><title>Howto use custom color for collective.captcha?</title><link>http://widerin.net/posts/2009/howto-use-custom-color-for-collective.captcha/</link><pubDate>Thu, 23 Apr 2009 00:00:00 +0000</pubDate><guid>http://widerin.net/posts/2009/howto-use-custom-color-for-collective.captcha/</guid><description>&lt;p&gt;How to use your custom color with &lt;a href="http://pypi.python.org/pypi/collective.captcha"&gt;collective.captcha&lt;/a&gt; and &lt;a href="http://plone.org"&gt;Plone&lt;/a&gt;? This
tutorial shows you an easy way to customize it using your own &lt;code&gt;BrowserLayer&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://pypi.python.org/pypi/collective.captcha"&gt;collective.captcha&lt;/a&gt; uses a &lt;code&gt;BrowserView&lt;/code&gt; to display it&amp;rsquo;s captcha image.
Therefore it&amp;rsquo;s very easy to customize it for your own theme because you can
subclass that &lt;code&gt;BrowserView&lt;/code&gt; for your own theme layer which is a &lt;code&gt;BrowserLayer&lt;/code&gt;.
You can change colors and/or fonts as you need it for your custom theme without
doing any code change on the original &lt;a href="http://pypi.python.org/pypi/collective.captcha"&gt;collective.captcha&lt;/a&gt; package.&lt;/p&gt;</description></item></channel></rss>