Reproducible Builds: Reproducible Builds in December 2021

Planet Debian - Wed, 2022-01-05 09:44

Welcome to the December 2021 report from the Reproducible Builds project! In these reports, we try and summarise what we have been up to over the past month, as well as what else has been occurring in the world of software supply-chain security.

As a quick recap of what reproducible builds is trying to address, whilst anyone may inspect the source code of free software for malicious flaws, almost all software is distributed to end users as pre-compiled binaries. The motivation behind the reproducible builds effort is to ensure no flaws have been introduced during this compilation process by promising identical results are always generated from a given source, thus allowing multiple third-parties to come to a consensus on whether a build was compromised. As always, if you would like to contribute to the project, please get in touch with us directly or visit the Contribute page on our website.

Early in December, Julien Voisin blogged about setting up a rebuilderd instance in order to reproduce Tails images. Working on previous work from 2018, Julien has now set up a public-facing instance which is providing build attestations.

As Julien dryly notes in his post, “Currently, this isn’t really super-useful to anyone, except maybe some Tails developers who want to check that the release manager didn’t backdoor the released image.” Naturally, we would contend — sincerely — that this is indeed useful.

The secure/anonymous Tor browser now supports reproducible source releases. According to the project’s changelog, version of Tor can now build reproducible tarballs via the make dist-reprod command. This issue was tracked via Tor issue #26299.

Fabian Keil posted a question to our mailing list this month asking how they might analyse differences in images produced with the FreeBSD and ElectroBSD’s mkimg and makefs commands:

After rebasing ElectroBSD from FreeBSD stable/11 to stable/12
I recently noticed that the "memstick" images are unfortunately
still not 100% reproducible.

Fabian’s original post generated a short back-and-forth with Chris Lamb regarding how diffoscope might be able to support the particular format of images generated by this command set.


diffoscope is our in-depth and content-aware diff utility. Not only can it locate and diagnose reproducibility issues, it can provide human-readable diffs from many kinds of binary formats. This month, Chris Lamb prepared and uploading versions 195, 196, 197 and 198 to Debian, as well as made the following changes:

  • Support showing Ordering differences only within .dsc field values. []
  • Add support for ‘XMLb’ files. []
  • Also add, for example, /usr/lib/x86_64-linux-gnu to our local binary search path. []
  • Support OCaml versions 4.11, 4.12 and 4.13. []
  • Drop some unnecessary has_same_content_as logging calls. []
  • Replace token variable with an anonymously-named variable instead to remove extra lines. []
  • Don’t use the runtime platform’s native endianness when unpacking .pyc files. This fixes test failures on big-endian machines. []

Mattia Rizzolo also made a number of changes to diffoscope this month as well, such as:

  • Also recognize GnuCash files as XML. []
  • Support the pgpdump PGP packet visualiser version 0.34. []
  • Ignore the new Lintian tag binary-with-bad-dynamic-table. []
  • Fix the Enhances field in debian/control. []

Finally, Brent Spillner fixed the version detection for Black ‘uncompromising code formatter’ [], Jelle van der Waa added an external tool reference for Arch Linux [] and Roland Clobus added support for reporting when the GNU_BUILD_ID field has been modified []. Thank you for your contributions!

Distribution work

In Debian this month, 70 reviews of packages were added, 27 were updated and 41 were removed, adding to our database of knowledge about specific issues. A number of issue types were created as well, including:

strip-nondeterminism version 1.13.0-1 was uploaded to Debian unstable by Holger Levsen. It included contributions already covered in previous months as well as new ones from Mattia Rizzolo, particularly that the dh_strip_nondeterminism Debian integration interface uses the new get_non_binnmu_date_epoch() utility when available: this is important to ensure that strip-nondeterminism does not break some kinds of binNMUs.

In the world of openSUSE, however, Bernhard M. Wiedemann posted his monthly reproducible builds status report.

In NixOS, work towards the longer-term goal of making the graphical installation image reproducible is ongoing. For example, Artturin made the gnome-desktop package reproducible.

Upstream patches

The Reproducible Builds project attempts to fix as many currently-unreproducible packages as possible. In December, we wrote a large number of such patches, including:

Testing framework

The Reproducible Builds project runs a significant testing framework at tests.reproducible-builds.org, to check packages and other artifacts for reproducibility. This month, the following changes were made:

  • Holger Levsen:

    • Run the Debian scheduler less often. []
    • Fix the name of the Debian ‘testing’ suite name. []
    • Detect builds that are rescheduling due to problems with the diffoscope container. []
    • No longer special-case particular machines having a different /boot partition size. []
    • Automatically fix failed apt-daily and apt-daily-upgrade services [], failed e2scrub_all.service & user@ systemd units [][] as well as ‘generic’ build failures [].
    • Simplify a script to powercycle arm64 architecture nodes hosted at/by codethink.co.uk. []
    • Detect if the udd-mirror.debian.net service is down. []
    • Various miscellaneous node maintenance. [][]
  • Roland Clobus (Debian ‘live’ image generation):

    • If the latest snapshot is not complete yet, try to use the previous snapshot instead. []
    • Minor: whitespace correction + comment correction. []
    • Use unique folders and reports for each Debian version. []
    • Turn off debugging. []
    • Add a better error description for incorrect/missing arguments. []
    • Report non-reproducible issues in Debian sid images. []

Lastly, Mattia Rizzolo updated the automatic logfile parsing rules in a number of ways (eg. to ignore a warning about the Python setuptools deprecation) [][] and Vagrant Cascadian adjusted the config for the Squid caching proxy on a node. []

If you are interested in contributing to the Reproducible Builds project, please visit our Contribute page on our website. However, you can get in touch with us via:

Categories: FLOSS Project Planets

Python for Beginners: Check For Ugly Number In Python

Planet Python - Wed, 2022-01-05 09:14

You might have heard about natural numbers, prime numbers, even numbers, and odd numbers. But, have you ever wondered what an ugly number is? In this article, we will discuss what an ugly number is. We will also write a program to check for an ugly number in python.

What Is An Ugly Number?

A number is said to be an ugly number if it has only 2,3, and 5 as its prime factors. In other words, If a number can be obtained by multiplying powers for 2, 3, or 5, the number is said to be an ugly number. 

For instance, 18 can be obtained as 21x 32. Hence, it is an ugly number. Similarly, 90 is also an ugly number as it can be obtained as 21x 32x 51. On the contrary, 126 is not an ugly number as it can be obtained as 21x 32x 71. Here, 126 has 7 as one of its prime factors. Hence, it is not an ugly number.

Now, let us formulate an algorithm to check for an ugly number in Python.

Algorithm To Check For Ugly Number In Python

To check if a number is an ugly number or not, we will perform repetitive division on it. First, we will divide the given number repeatedly with 2. If the resultant number becomes indivisible by 2, we will check if the number is 1 or not. If it’s 1, we will say that a number is an ugly number. Otherwise, we will perform repetitive division on the resultant by 3. Once the resultant becomes indivisible by 3, we will check if it’s 1 or not. If yes, we will say that the given number is an ugly number. Otherwise, we will perform repetitive division on the resultant by 5. Once the resultant becomes indivisible by 5, we will check if the resultant is 1. If yes, we will say that a number is an ugly number. Otherwise, we will say that the number is not an ugly number.

Let us now implement this idea in Python

Python Program To Check For Ugly Number

Here, we have implemented a function is_ugly() using the while loop for repetitive division and if-else statements for condition checking. The function takes an integer as an input argument and returns True if the input number is an ugly number. Otherwise, it returns False.

def is_ugly(N): while N % 2 == 0: N = N // 2 if N == 1: return True while N % 3 == 0: N = N // 3 if N == 1: return True while N % 5 == 0: N = N // 5 if N == 1: return True return False input_number = 18 output = is_ugly(input_number) print("{} is an ugly number:{}".format(input_number, output)) input_number = 126 output = is_ugly(input_number) print("{} is an ugly number:{}".format(input_number, output))


18 is an ugly number:True 126 is an ugly number:False Conclusion

In this article, we have discussed and implemented a program to check whether a given number is an ugly number or not. To learn more about numbers in python, you can read this article on decimal numbers in python. You might also like this article on complex numbers in python.

The post Check For Ugly Number In Python appeared first on PythonForBeginners.com.

Categories: FLOSS Project Planets

Real Python: Build a Django Front End With Bulma – Part 2

Planet Python - Wed, 2022-01-05 09:00

In this four-part tutorial series, you’re building a social network with Django that you can showcase in your portfolio. This project will strengthen your understanding of relationships between Django models and show you how to use forms so that users can interact with your app and with each other. You’ll also make your Django front end look good by using the Bulma CSS framework.

In the first part, you extended the Django User model to add profile information that allows users to follow and unfollow each other. You also learned how to customize the Django admin interface and troubleshoot during development with the help of Django’s error messages.

In the second part of this tutorial series, you’ll learn how to:

  • Integrate Bulma CSS and style your app
  • Use template inheritance to reduce repetition
  • Structure Django templates in a folder hierarchy
  • Build routing and view functions
  • Interlink pages of your app using dynamic URLs

After finishing the second part of this project, you’ll move on to the third part of this tutorial series, where you’ll create the back end for adding content to your social network. You’ll also add the missing templates to allow your users to view the text-based content on their dashboard page.

You can download the code that you’ll need to start the second part of this project by clicking the link below and going to the source_code_start/ folder:

Get Source Code: Click here to get the source code for this part of building out your Django social network.


In this four-part tutorial series, you’re building a small social network that allows users to post short text-based messages. The users of your app can also follow other user profiles to see the posts of these users or unfollow them to stop seeing their text-based posts:

In the second part of this series, you’ll work with templates and learn to use the CSS framework Bulma to give your app a user-friendly appearance. You’ll also tackle common tasks such as setting up routing, views, and templates for individual user profile pages as well as interlinking them with the profile list page:

At the end of this part of the tutorial series, you’ll be able to access detail pages and the profile list page and navigate between them. You’ll also have Bulma added to style the pages.

Project Overview

In this section, you’ll get an overview of the topics that you’ll cover in this second part of the tutorial series. You’ll also get a chance to revisit the full project implementation steps, in case you need to skip back to a previous step from an earlier part of the series or if you want to see what’s still up ahead.

At this point, you should have finished working through part one of this tutorial series. If you did, then you’re ready to continue with your next steps, which focus on templates and front-end styling:

    Step 4 Create a Base Template With Bulma Step 5 List All User Profiles Step 6 Access Individual Profile Pages

After completing all steps of this second part of the series, you can continue with part three.

To refresh your memory and get an overview of how you’ll work through all four parts of this series on building your Django social network, you can expand the collapsible section below:

Full Project Implementation StepsShow/Hide

You’re implementing the project in a number of steps spread out over multiple separate tutorials in this series. There’s a lot to cover, and you’re going into detail along the way:

✅ Part 1: Models and Relationships

  • Step 1: Set Up the Base Project
  • Step 2: Extend the Django User Model
  • Step 3: Implement a Post-Save Hook

📍 Part 2: Templates and Front-End Styling

  • Step 4: Create a Base Template With Bulma
  • Step 5: List All User Profiles
  • Step 6: Access Individual Profile Pages

⏭ Part 3: Follows and Dweets

  • Step 7: Follow and Unfollow Other Profiles
  • Step 8: Create the Back-End Logic For Dweets
  • Step 9: Display Dweets on the Front End

⏭ Part 4: Forms and Submissions

  • Step 10: Submit Dweets Through a Django Form
  • Step 11: Prevent Double Submissions and Handle Errors
  • Step 12: Improve the Front-End User Experience

Each of these steps will provide links to any necessary resources. By approaching the steps one at a time, you’ll have the opportunity to pause and come back at a later point in case you want to take a break.

With the high-level structure of this tutorial series in mind, you’ve got a good idea of where you’re at and which implementation steps you’ll handle in the later parts.

Before getting started with the next step, take a quick look at the prerequisites to skim any links to other resources that might be helpful along the way.


To successfully work through this part of your project, you need to have completed the first part on models and relationships and you should confirm that your project is working as described there. It would be best if you’re also comfortable with the following concepts:

Read the full article at https://realpython.com/django-social-front-end-2/ »

[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. >> Click here to learn more and see examples ]

Categories: FLOSS Project Planets

Kushal Das: Releasing Tumpa for Mac

Planet Python - Wed, 2022-01-05 08:50

I am happy to announce the release of Tumpa (The Usability Minded PGP Application) for Mac. This release contains the old UI (and the UI bugs), but creates RSA4096 keys by default. Right now Tumpa will allow the following:

  • Create new RSA4096 OpenPGP key. Remember to click on the “Authentication” subkey checkbox if you want to use the key for ssh.
  • Export the public key.
  • You can reset the Yubikey from the smartcard menu.
  • Allows to upload the subkeys to Yubikey (4 or 5).
  • Change the user pin/admin pin of the Yubikey.
  • Change the name and public key URL of the Yubikey.

The keys are stored at ~/.tumpa/ directory, you can back it up in an encrypted USB drive.

You can download the dmg file from my website.

$ wget https://kushaldas.in/tumpa-0.1.3.dmg $ sha256sum ./tumpa-0.1.3.dmg 6204cf3253fbe41ada91429684fccc0df87257f85345976d9468c8adf131c591 ./tumpa-0.1.3.dmg

Download & install from the dmg in the standard drag & drop style. If you are using one of the new M1 box, remember to click on “Open in Rosetta” for the application.

Click on “Open”.

Here is a GIF recorded on Linux, the functions are same in Mac.

Saptak (my amazing comaintainer) is working on a new website. He is also leading the development of the future UI, based on usability reports. We already saw a few UI issues on Mac (specially while generating a new key), those will be fixed in a future release.

Feel free to open issues as you find, find us in #tumpa channel on Libera.chat IRC network.

Categories: FLOSS Project Planets

Jonathan Wiltshire: Continuing adventures of the mystery cable

Planet Debian - Wed, 2022-01-05 08:39

My 4×2 has been in action again, trying to find the remainder of the mystery sometimes-4mm/sometimes-2.5mm/sometimes-1.5mm cable. It finally appeared in the tiniest gap possible between back wall and joist.

As we had suspected by tracing everything else, the junction is an unfused union of all three cable types with a 230V 32A circuit breaker on one end and a light switch on the other. So in the event of fault current at the kitchen lights, the 1.5mm cable is definitely going to burn out and almost certainly set fire to the flat roof. Delightful.

It is no longer like this.

More hunting for the mystery cable (bonus glimpse of one of the new light fittings) The 4×2 ceiling removal device in action At last, quarry in sight! Mystery Cable Junction Box of Fire and Doom ? All the terrifying branches removed and ready to go back into the ceiling for now, until the next room is refurbished
Categories: FLOSS Project Planets

Krita in 2021 and 2022

Planet KDE - Wed, 2022-01-05 08:13

A bit later than planned… Our overview of last year and a look forward to this year! We’re all still alive and working hard — sometimes a bit too hard. We kept the same core team this year, but we also had a lot of contributions from volunteers. Over a hundred people made all in all over ten thousand contributions to Krita, the website, the manual and the translations.

We also launched the Krita Dev Fund, based on Blender’s funding website code. We are really pleased with the community response to this initiative, but we’re not yet at a point where we won’t need the income from the various app stores. We launched Krita on the Epic app store, and we’ve made our first submission to the Apple MacOS store. (note: NOT the iPadOS store!)

Releases https://krita.org/wp-content/uploads/2021/12/Video-for-store_final-30fps.mp4

Last year, 2021, was, of course the year of the Krita 5 release! We also released from Krita 4.4.2 all the way through to Krita 4.4.8, so it was a busy year. With the release of 4.4.5 we said we wouldn’t do another 4.4 release, but we did…

The list of new features for Krita 5 is huge. But even the 4.4 releases brought new features, like mesh gradients, mesh transformation, new fill layer types and new brush presets.


Last year we ended up with 16 bugs more than we started the year with, this year we’re twelve bugs to the good. Weirdly enough, last year we only had 563 open bugs, so something is weird. In any case, we worked through about 200 more bugs than last year. In other words, there was a lot of churn!


We also had three Google Summer of Code students participating in Google’s abbreviated program for students. This year, everyone can apply, even if you’re not a student anymore. Santosh, Tanmay and Sachin: thanks for your hard work!

We finished the huge resource system rewrite that we started in 2015. It’s certain that now that is out in the wild we will discover lots of things that need fixing, but then… That’s always the case with code…


The number of downloads from the download page grew to 5,637,579, almost a million more than in 2020, which was already a record year. That excludes all other places where people can get Krita, from Flatpak to Snap, from distributions to app stores to third-party download sites (but be careful with those!)

We also had a huge problem, that’s since then hit other free software projects like inkscape and darktable: scammers mailed people behind a lot of youtube channels, related or unrelated to graphics software, about a possible collaboration with the Krita team. This was, obviously, not us. Some forensic work showed that they were trying to install ransomware on the victims’ computers.

And for this year…

I’m not expecting we’re going to be able to have in-person developer meetings this year. But now that Krita 5.0 is out of the door, there will be time for some fun new things.

We haven’t decided what yet, because we’re notoriously bad at making roadmaps, plans or predictions…

But among the things we want to work on are the text shape, a new startup page, starting work on a mobile-friendly user interface, a new docker implementation, integration with 3d models, a rework of the tools system or the brush preset system, improved calligraphy or vectors in general , new tools for easy filling shapes, per-project resources and assets, — maybe even a Krita cloud… And we’re working on a proposal for making collaborative painting possible.

More news later!

The post Krita in 2021 and 2022 appeared first on Krita.

Categories: FLOSS Project Planets

Thomas Lange: FAI.me service now support backports for Debian 11 (bullseye)

Planet Debian - Wed, 2022-01-05 06:46

The FAI.me service for creating customized installation and cloud images now supports a backports kernel for the stable release Debian 11 (aka bullseye). If you enable the backports option, you will currently get kernel 5.14. This will help you if you have newer hardware that is not support by the default kernel 5.10. The backports option is also still available for the images when using the old Debian 10 (buster) release.

The URL of the FAI.me service is



Categories: FLOSS Project Planets

Inspired Python: Game Boy Emulator: Designing the CPU

Planet Python - Wed, 2022-01-05 04:27
Game Boy Emulator: Designing the CPU

In we learned how to write an instruction decoder and disassembler. It’s an important first step towards writing a Game Boy emulator. Assembly language – or the binary machine code form of it anyway – is the language of the CPU, and so we must represent, in software, a facsimile of a real CPU that can execute these machine code instructions for us.

So let’s start off with a quick overview of what exactly a CPU is and does, and how we’ll emulate it.

Categories: FLOSS Project Planets

Python Bytes: #265 Get asizeof pympler and muppy

Planet Python - Wed, 2022-01-05 03:00
<p><strong>Watch the live stream:</strong></p> <a href='https://www.youtube.com/watch?v=qjQwrS0xLqI' style='font-weight: bold;'>Watch on YouTube</a><br> <br> <p><strong>About the show</strong></p> <p>Sponsored by <strong>us:</strong></p> <ul> <li>Check out the <a href="https://training.talkpython.fm/courses/all"><strong>courses over at Talk Python</strong></a></li> <li>And <a href="https://pythontest.com/pytest-book/"><strong>Brian’s book too</strong></a>!</li> </ul> <p>Special guest: Matt Kramer (<a href="https://twitter.com/__matt_kramer__">@__matt_kramer__</a>)</p> <p><strong>Michael #1: Survey results</strong></p> <ul> <li>Question 1: <img src="https://paper-attachments.dropbox.com/s_3370DBC8B17DDD025FB99F5F8E61DB76EED1D134B78707EFC4676F383C096EF5_1641344127195_q1.png" alt="" /></li> </ul> <p>Question 2:</p> <p><img src="https://paper-attachments.dropbox.com/s_3370DBC8B17DDD025FB99F5F8E61DB76EED1D134B78707EFC4676F383C096EF5_1641344142950_q2.png" alt="" /></p> <ul> <li>In terms of too long, the “extras” section has started at these times in the last 4 episodes: <ul> <li>39m, 32m, 35m, and 33m ~= 34m on average </li> </ul></li> </ul> <p><strong>Brian #2:</strong> <strong>Modern attrs API</strong></p> <ul> <li><a href="https://www.attrs.org/en/latest/overview.html">attrs overview</a> now focus on using <code>@define</code></li> <li>History of attrs article: <a href="https://hynek.me/articles/import-attrs/">import attrs</a>, by Hynek <ul> <li>predecessor was called <code>characteristic</code>. </li> <li>A discussion between Glyph and Hynek in 2015 about where to take the idea.</li> <li><code>attrs</code> popularity takes off in 2016 after a post by Glyph: <a href="https://glyph.twistedmatrix.com/2016/08/attrs.html"><em>‌The One Python Library Everyone Needs</em></a></li> <li>In 2017 people started wanting something like attrs in std library. Thus PEP 557 and dataclasses. Hynek, Eric Smith, and Guido discuss it at PyCon US 2017. </li> <li>dataclasses, with a subset of attrs functionality, was introduced in Python 3.7. </li> <li>Types take off. attrs starts supporting type hints as well, even before Python 3.7</li> <li>Post 3.7, some people start wondering if they still need attrs, since they have dataclasses.</li> <li><code>@define</code>, <code>field()</code> and other API improvements came with attrs 20.1.0 in 2020.</li> <li>attrs 21.3.0 released in December, with what Hynek calls “Modern attrs”.</li> </ul></li> <li>OG attrs:</li> </ul> <div class="codehilite"><pre><span></span><code><span class="kn">import</span> <span class="nn">attr</span> <span class="nd">@attr</span><span class="o">.</span><span class="n">s</span> <span class="k">class</span> <span class="nc">Point</span><span class="p">:</span> <span class="n">x</span> <span class="o">=</span> <span class="n">attr</span><span class="o">.</span><span class="n">ib</span><span class="p">()</span> <span class="n">y</span> <span class="o">=</span> <span class="n">attr</span><span class="o">.</span><span class="n">ib</span><span class="p">()</span> </code></pre></div> <ul> <li>modern attrs:</li> </ul> <div class="codehilite"><pre><span></span><code><span class="kn">from</span> <span class="nn">attr</span> <span class="kn">import</span> <span class="n">define</span> <span class="nd">@define</span> <span class="k">class</span> <span class="nc">Point</span><span class="p">:</span> <span class="n">x</span><span class="p">:</span> <span class="nb">int</span> <span class="n">y</span><span class="p">:</span> <span class="nb">int</span> </code></pre></div> <ul> <li>Many reasons to use attrs listed in <a href="https://www.attrs.org/en/latest/why.html">Why not…</a>, which is an excellent read. <ul> <li>why not dataclasses?</li> <li>less powerful than attrs, intentionally <ul> <li>attrs has validators, converters, equality customization, …</li> </ul></li> <li>attrs doesn’t force type annotation if you don’t like them</li> <li>slots on by default, dataclasses only support slots in Python 3.10 and are off by default <ul> <li>attrs can and will move faster</li> </ul></li> <li>See also comparisons with pydantic, named tuples, tuples, dicts, hand-written classes</li> </ul></li> </ul> <p><strong>Matt</strong> <strong>#3:</strong> <a href="https://craftinginterpreters.com/"><strong>Crafting Interpreters</strong></a></p> <ul> <li>Wanting to learn more about how Python works “under the hood”, I first read Anthony Shaw’s <a href="https://realpython.com/products/cpython-internals-book/">CPython internals</a> book <ul> <li>A fantastic, detailed overview of how CPython is implemented</li> </ul></li> <li>Since I don’t have a formal CS background, I found myself wanting to learn a bit more about the fundamentals <ul> <li>Parsing, Tokenization, Bytecode, data structures, etc.</li> </ul></li> <li>Crafting Interpreters is an incredible book by Bob Nystrom (on Dart team at Google)</li> <li>Although not Python, you walk through the implementation of a dynamic, interpreted language from scratch</li> <li>Implement same language (called lox) in two interpreters <ul> <li>First a direct evaluation of Abstract Syntax Tree, written in Java</li> <li>Second is a bytecode interpreter, written from the ground up in C, including a compiler</li> </ul></li> <li>Every line of code is in the book, it is incredibly well-written and beautifully rendered</li> <li>I highly recommend to anyone wanting to learn more about language design &amp; implementation</li> </ul> <p><strong>Michael #4:</strong> <a href="https://github.com/23andMe/Yamale"><strong>Yamele - A schema and validator for YAML</strong></a></p> <ul> <li>via Andrew Simon</li> <li>A basic schema:</li> </ul> <pre><code>name: str() age: int(max=200) height: num() awesome: bool() </code></pre> <ul> <li>And some YAML that validates:</li> </ul> <pre><code>name: Bill age: 26 height: 6.2 awesome: True </code></pre> <ul> <li>Take a look at the <a href="https://github.com/23andMe/Yamale#examples">Examples</a> section for more complex schema ideas.</li> <li>⚠️ Ensure that your schema definitions come from internal or trusted sources. Yamale does not protect against intentionally malicious schemas.</li> </ul> <p><strong>Brian #5:</strong> <a href="https://pympler.readthedocs.io/en/latest/"><strong>pympler</strong></a></p> <ul> <li>Inspired by something Bob Belderbos wrote about sizes of objects, I think.</li> <li>“Pympler is a development tool to measure, monitor and analyze the memory behavior of Python objects in a running Python application.</li> <li>By pympling a Python application, detailed insight in the size and the lifetime of Python objects can be obtained. Undesirable or unexpected runtime behavior like memory bloat and other “pymples” can easily be identified.”</li> <li>3 separate modules for profiling <ul> <li><a href="https://pympler.readthedocs.io/en/latest/asizeof.html#asizeof">asizeof</a> module provides basic size information for one or several Python objects</li> <li><a href="https://pympler.readthedocs.io/en/latest/muppy.html#muppy">muppy</a> is used for on-line monitoring of a Python application</li> <li><a href="https://pympler.readthedocs.io/en/latest/classtracker.html#classtracker">Class Tracker</a> provides off-line analysis of the lifetime of selected Python objects.</li> </ul></li> <li>asizeof is what I looked at recently <ul> <li>In contrast to <code>sys.getsizeof</code>, <code>asizeof</code> sizes objects recursively. </li> <li>You can use one of the <a href="https://pympler.readthedocs.io/en/latest/asizeof.html#asizeof">asizeof</a> functions to get the size of these objects and all associated referents:</li> </ul></li> </ul> <pre><code>&gt;&gt;&gt; from pympler import asizeof &gt;&gt;&gt; obj = [1, 2, (3, 4), 'text'] &gt;&gt;&gt; asizeof.asizeof(obj) 176 &gt;&gt;&gt; print(asizeof.asized(obj, detail=1).format()) [1, 2, (3, 4), 'text'] size=176 flat=48 (3, 4) size=64 flat=32 'text' size=32 flat=32 1 size=16 flat=16 2 size=16 flat=16 </code></pre> <ul> <li>“Function <strong>flatsize</strong> returns the <em>flat size</em> of a Python object in bytes defined as the <em>basic size</em> plus the <em>item size</em> times the <em>length</em> of the given object.”</li> </ul> <p><strong>Matt</strong> <strong>#6:</strong> <a href="https://hvplot.holoviz.org/user_guide/Interactive.html#"><strong>hvPlot Interactive</strong></a></p> <ul> <li>hvPlot is a high-level plotting API that is part of the PyData ecosystem, built on HoloViews</li> <li>My colleague Phillip Rudiger recently gave a talk at PyData Global on a new <code>.interactive</code> feature</li> <li><a href="https://discourse.holoviz.org/t/pydata-2021-build-polished-data-driven-applications-directly-from-your-pandas-or-xarray-pipelines/3017">Here’s an announcement in the HoloViz forum</a></li> <li>Allows integration of widgets directly into <code>pandas</code> analysis pipeline (method-chain), so you can add interactivity to your notebook for exploratory data analysis, or serve it as a <a href="https://panel.holoviz.org/">Panel app</a></li> <li><a href="https://gist.github.com/MarcSkovMadsen/ffb273636dced88705c8c88d5ee28f23">Gist &amp; video</a> by Marc Skov Madsen</li> </ul> <p><strong>Extras</strong> </p> <p>Michael:</p> <ul> <li><a href="https://typora.io/"><strong>Typora app</strong></a>, recommended!</li> <li><a href="https://twitter.com/willmcgugan/status/1474342602665304076?s=12"><strong>Congrats Will</strong></a></li> <li>Got a chance to solve a race condition with <a href="https://tenacity.readthedocs.io/en/latest/"><strong>Tenacity</strong></a></li> <li>New <a href="https://docs.github.com/en/issues/trying-out-the-new-projects-experience"><strong>project management at GitHub</strong></a></li> </ul> <p>Matt: </p> <ul> <li>Check out new <a href="https://community.anaconda.cloud/">Anaconda Nucleus Community</a> forums!</li> <li>We’re hiring, and remote-first. Check out <a href="http://anaconda.com/careers">anaconda.com/careers</a></li> <li><a href="https://blog.pyston.org/2021/12/07/pre-compiled-packages-now-available-for-pyston/">Pre-compiled packages now available for Pyston</a></li> <li>We have an upcoming webinar from Martin Durant: <a href="https://event.on24.com/wcc/r/3544490/FB8F3D77C106DBA907A895338C3F6881?partnerref=anacondacom">When Your Big Problem is I/O Bound</a></li> </ul> <p><strong>Joke:</strong> </p> <p><img src="https://paper-attachments.dropbox.com/s_3370DBC8B17DDD025FB99F5F8E61DB76EED1D134B78707EFC4676F383C096EF5_1641345305415_Screen_Shot_2020-06-08_at_10.42.24_PM.png" alt="" /></p>
Categories: FLOSS Project Planets

Matt Glaman: Ensuring Drupal route lookups by path are cached by domain

Planet Drupal - Tue, 2022-01-04 22:01

In this episode of "Matt does ridiculous things with Drupal," I found out that the inbound processing of a path and the lookup for its route gets cached. That makes sense, it can be an expensive process to say /foo is actually an alias of /node/1 and should go to the entity view controller. What I did not know is that the route provider in Drupal creates a cache ID based on the path and language code, only.

Here's where the cache ID for the request's route collection is generated (link to the full source.)

Categories: FLOSS Project Planets

Will Kahn-Greene: Kent v0.1.0 released! And the story of Kent in the first place....

Planet Python - Tue, 2022-01-04 20:00
What is it?

Before explaining what it is, I want to talk about Why.

A couple of years ago, we migrated from the Raven Sentry client (Python) to sentry-sdk. One of the things we did was implement our own sanitization code which removed personally identifyable information and secret information (as best as possible) from error reports.

I find the documentation for writing sanitization filters really confusing. before_send? before_breadcrumb? When do those hooks kick off? What does an event look like? There's a link to a page that describes an event, but there's a lot of verbiage and no schema so it's not wildly clear what the errors my application is sending look like. 1

Anyhow, so when we switched to sentry-sdk, we implemented some sanitization code because while Raven had some code, sentry-sdk did not. Then at some point between then and now, the sanitization code stopped working. It's my fault probably. I bet something changed in the sentry-sdk and I didn't notice.

Why didn't I notice? Am I a crappy engineer? Sure, but in this case the problem here is that the sanitization code runs in the context of handling an unhandled error. In handling the unhandled error, Sentry passes the event through our broken sanitization code and that throws an exception. Nothing gets sent to Sentry--neither the original error nor the sanitization error.

Once I realized there were errors, I looked in the logs and I can see the original errors--but not the sanitization errors.


Fun fact: turns out John Whitlock thought about this when he wrote the sanitization code and added some code to emit a metric if the sanitization code errors out. If I had a graph in the dashboard showing this metric, I would have seen it.

"You should test your sanitization code!" you say! Right on! That's what we should be doing! We have unit tests but they run with ficticious data in a pocket dimension. So they passed wonderfully despite the issue!

What we needed was a few things:

  1. I needed to be able to run a fake Sentry service that I could throw errors at and debug the sanitization code in my local environment without having to spin up a real Sentry instance

  2. I needed to be able to see exactly what is in the error payloads for my application.

  3. I needed something I can use for integration tests with the sentry-sdk.

That's how I ended up putting aside all the things I needed to do and built Kent.


I don't intend to bash Sentry and the Sentry folks and all the work they do. Their docs may be great. I'm probably the dumb one here.

So what is Kent?

Kent is a fake Sentry service. You can run it, set the Sentry DSN of your application to soemthing like http://public@localhost:8000/1, and then Kent will capture Sentry error reports.

Kent takes 2 seconds to set up. You can run it locally:

$ pip install kent $ kent-server run

You can run it in a Docker container. There's a sample Dockerfile in the repo.

It doesn't require databases, credentials, caching, or any of that stuff.

Kent stores things in-memory. You don't have to clean up after it.

Kent has a website letting you view errors with your browser.

Kent has an API letting you build integration tests that create the errors and then fetch them and assert things against them.

What questionable architectural decisions did you make?

I built it with Flask. Flask is great for stuff like this--that part is fine.

The part that's less fine is that I decided to put in the least amount of effort in standing it up as a service and putting it behind a real WSGI server, so I'm (ab)using Flask's cli and monkeypatching werkzeug to not print out "helpful" (but in this case--unhelpful) messages to the console.

I used pico.css because I read about it like yesterday and it seemed easier to use that than to go fiddling with CSS frameworks to get a really lovely looking site for a fake Sentry service.

I may replace that at some point with something that involves less horizontal space.

I only wrote one test. I have testing set up, but only wrote one test to make sure it's minimally viable. I may write more at some point.

I only tested with Python sentry-sdk. I figure if other people need it, they can let me know what else it works with and we can fix any issues that come up.

I decided to store errors in memory rather than persist things to disk. That was easy to do and seems like the right move. Maybe we'll hit something that requires us to do something different.

I named it Kent. I like short names. Friends suggested I name it Caerbannog because it was a sentry of a sort. I love that name, but I can't reliably spell it.

0.1.0 released!

I thought about making this 1.0.0, but then decided to put it into the world and use it for a bit and fix any issues that come up and then release 1.0.0.

Initial release with minimally viable feature set.

  • capture errors and keep them in memory

  • API endpoint to list errors

  • API endpoint to fetch error

Where to go for more

History of releases: https://github.com/willkg/kent/blob/main/HISTORY.rst

Source code, issue tracker, documentation, and quickstart here: https://github.com/willkg/kent

Let me know how this helps you!

I say that in a lot of my posts. "Let me know how this helps you!" or "Comment by sending me an email!" or something like that. I occasionally get a response--usually from Sumana--but most often, it's me talking to the void. I do an awful lot of work that theoretically positively affects thousands of people to be constantly talking to the void.

Let me know if you have positive or negative feelings about Kent by:

  1. click on this link: https://github.com/willkg/kent/issues/3

  2. add a reaction to the description which should be like two clicks

Categories: FLOSS Project Planets

Promet Source: 2021 in Review: Top Trends and Topics

Planet Drupal - Tue, 2022-01-04 19:34
There’s much about 2021 that did not play out as planned. The list is longer for some than others, but despite big-picture setbacks, 2021 proved to be a year of powerful momentum within the Open Source Community. 
Categories: FLOSS Project Planets

Russell Coker: Terrorists Inspired by Fiction

Planet Debian - Tue, 2022-01-04 18:00

The Tom Clancy book Debt of Honor published in August 1994 first introduced the concept of a heavy passenger aircraft being used as a weapon by terrorists against a well defended building. In April 1994 there was an attempt to hijack and deliberately crash FedEx flight 705. It’s possible for a book to be changed 4 months before publication, but it seems unlikely that a significant plot point in a series of books was changed in such a small amount of time so it’s likely that Tom Clancy got the idea first. There have been other variations on that theme, such as the Yokosuka_MXY-7 Kamakazi flying bomb (known by the Allies as “Baka” which is Japanese for idiot). But Tom Clancy seemed to pioneer the idea of a commercial passenger jet being subverted for the purpose of ground attack.

7 years after Tom Clancy’s book was published the 911 hijackings happened.

The TV series Black Mirror first aired in 2011, and the first episode was about terrorists kidnapping a princess and demanding that the UK PM perform an indecent act with a pig for her release. While the plot was a little extreme (the entire series is extreme) the basic concept of sexual extortion based on terrorist acts is something that could be done in real life, and if terrorists were inspired by this they are taking longer than expected to do it.

Most democracies seem to end up with two major parties that are closely matched. Even if a government was strict about not negotiating with terrorists it seems likely that terrorists demanding that a politician perform an unusual sex act on TV would change things, supporters would be divided into groups that support and oppose negotiating. Discussions wouldn’t be as civil as when the negotiation involves money or freeing prisoners. If an election result was perceived to have been influenced by such terrorism then supporters of the side that lost would claim it to be unfair and reject the result. If the goal of terrorists was to cause chaos then that would be one way of achieving it, and they have had over 10 years to consider this possibility.

Are we overdue for a terror attack inspired by Black Mirror?

No related posts.

Categories: FLOSS Project Planets

libunistring @ Savannah: GNU libunistring-1.0 released

GNU Planet! - Tue, 2022-01-04 17:48

Download from https://ftp.gnu.org/gnu/libunistring/libunistring-1.0.tar.gz

This is a stable release.

New in this release:

  • The license has changed from "LGPLv3+ or GPLv2" to "LGPLv3+ or GPLv2+".
  • The data tables and algorithms have been updated to Unicode version 14.0.0.
  • The functions u8_uctomb, u16_uctomb, u32_uctomb now support strings larger than 2 GiB by taking an 'n' argument of type ptrdiff_t (instead of int).
  • The functions u*_possible_linebreaks and u*_width_linebreaks now make it easier to work with strings that contain CR-LF sequences: In this case, in the returned array, it will return UC_BREAK_CR_BEFORE_LF followed by UC_BREAK_MANDATORY (instead of twice UC_BREAK_MANDATORY).
  • There are new properties for recognizing pictographic symbols and regional indicators:

    - UC_PROPERTY_EMOJI                  uc_is_property_emoji
    - UC_PROPERTY_EMOJI_PRESENTATION     uc_is_property_emoji_presentation
    - UC_PROPERTY_EMOJI_MODIFIER         uc_is_property_emoji_modifier
    - UC_PROPERTY_EMOJI_MODIFIER_BASE    uc_is_property_emoji_modifier_base
    - UC_PROPERTY_EMOJI_COMPONENT        uc_is_property_emoji_component
    - UC_PROPERTY_EXTENDED_PICTOGRAPHIC  uc_is_property_extended_pictographic
    - UC_PROPERTY_REGIONAL_INDICATOR     uc_is_property_regional_indicator

  • Fixed multithread-safety bugs on Cygwin, native Windows, and Haiku.
Categories: FLOSS Project Planets

PyCoder’s Weekly: Issue #506 (Jan. 4, 2022)

Planet Python - Tue, 2022-01-04 14:30

#506 – JANUARY 4, 2022
View in Browser »

Gem: Exploding String Alternatives

Here’s a Python gem: a small bit of Python that uses the power of the language and standard library well. It’s a function to list strings generated by a pattern with embedded alternatives. It takes an input string with brace-wrapped possibilities, and generates all the strings made from making choices among them: explode("{Alice,Bob} ate a {banana,donut}.")

Build a Social Network With Django – Part 1

In this four-part tutorial series, you’ll build a social network with Django to showcase in your portfolio. You’ll learn about relationships between Django models and how to use forms so that users can interact with your app. You’ll also make your site look good by using the Bulma CSS framework.

Provision Your Cloud Infrastructure Using Python and Pulumi

What if you could use your existing programming knowledge to build, deploy, and manage cloud infrastructure using your favorite languages and tools? Pulumi is a cloud engineering platform that lets you write infrastructure as code in any programming language, on any cloud platform. Get started today →
PULUMI sponsor

Learn Python ASTs, by Building Your Own Linter

A guide to Abstract Syntax Trees in Python. They form the basis of a lot of tools we take for granted, like linters, code formatters and syntax highlighting. With this article you’ll get to learn about ASTs by building your own linter from scratch.
TUSHAR SADHWANI • Shared by Tushar Sadhwani

urllib3 Raised $15,000 in 2021


Django Developers Survey 2021 Results


Discussions Python vs C % (Modulo/Remainder) Operator Behavior

In Python the % operator returns a number with the same sign as the second argument. C doesn’t actually have a “modulo” operator but a “remainder” operator, according to the C spec. Read the Hacker News discussion after the tweet for a full explanation.

Python Threads Scheduling Differences Between 3.10 and 3.9

“Unintended consequence of Mark Shannon’s change that refactors fast opcode dispatching […]”

Python Jobs Senior Software Engineer (Anywhere)


Senior DevOps Engineer (San Jose, CA, USA)

Tara Techincal Solutions

Senior Python Developer (100% Remote) (Anywhere)

Six Feet Up

Senior Software Engineer (Anywhere)


More Python Jobs >>>

Articles & Tutorials Is Your Python Code Vulnerable to Log Injection?

Following the news on log4j lately, you may wonder if Python’s logging library is safe. After all, there is a potential for injection attacks where string formatting meets user input. Thankfully, Python’s logging isn’t vulnerable to remote code execution. Nonetheless it is still important to be careful with untrusted data. This article describes some common pitfalls, and how logging f-strings could—in certain situations—leave you vulnerable to other types of attacks.
ARIE BOVENBERG • Shared by Arie Bovenberg

2021 Real Python Articles Wrap Up

It’s been a year of change at Real Python! The Real Python team has written, edited, curated, illustrated, and produced a mountain of Python articles this year. We also added many new members to the team, updated the site’s features, and created new styles of tutorials and projects.

Application Performance Monitoring, Built for Developers by Developers

Scout is an application performance monitoring tool designed to help Python developers find and fix performance issues quickly. With unlimited seats and applications, users of Scout’s APM tool find that anyone can be a performance expert. Click to sign up for your free 14-day trial today →
SCOUT APM sponsor

Python Type Hints: How to Handle Optional Imports

This post is not about importing typing.Optional, but instead imports that are themselves optional. Libraries often have optional dependencies, and the code should work whether or not the import is there.

Reading Tracebacks in Python

When exceptions go unhandled, Python prints a traceback. Tracebacks are read from the bottom upward. The last line describes what happened and lines above describe where it happened.

Three Problems With a Tool

A discussion of three problems with Python: “packaging, fractured tooling, crufty standard library”

What’s Your Favorite Programming Language?

Take the Developer Nation survey, share your views and make an impact on the developer ecosystem. Plus, you get a chance to win cool prizes, licenses, gaming accessories, vouchers and many more.

Pointers/References in Python


Unravelling elif/else From if Statements


Unravelling finally and else From try Statements


Using Borb to Create Ebooks From Project Gutenberg

JORIS SCHELLEKENS • Shared by Joris Schellekens

Projects & Code numbers-parser: Python Module for Parsing Apple Numbers Spreadsheets


NetworkX: Network Analysis in Python


python-minifier: Transform Python Source Code Into It’s Most Compact Representation

GITHUB.COM/DFLOOK • Shared by Python Bytes FM

emacspy: Program Emacs in Python Instead of ELisp


fastwsgi: Ultra Fast WSGI Server for Python 3


django-browser-reload: Automatically Reload Your Browser in Development


Events Weekly Real Python Office Hours Q&A (Virtual)

January 5, 2021

Canberra Python Meetup

January 6, 2022

Sydney Python User Group (SyPy)

January 6, 2022

Reunión Python Valencia

January 6, 2022

Python Miami

January 8 to January 9, 2022

DFW Pythoneers 2nd Saturday Teaching Meeting

January 8, 2022

Edmonton Python User Group

January 10, 2022

Happy Pythoning!
This was PyCoder’s Weekly Issue #506.
View in Browser »

[ Subscribe to 🐍 PyCoder’s Weekly 💌 – Get the best Python news, articles, and tutorials delivered to your inbox once a week >> Click here to learn more ]

Categories: FLOSS Project Planets

Jelmer Vernooij: Personal Streaming Audio Server

Planet Debian - Tue, 2022-01-04 13:00

For a while now, I’ve been looking for a good way to stream music from my home music collection on my phone.

There are quite a few options for music servers that support streaming. However, Android apps that can stream music from one of those servers tend to be unmaintained, clunky or slow (or more than one of those).

It is possible to use something that runs in a web server, but that means no offline caching - which can be quite convenient in spots without connectivity, such as the Underground or other random bits of London with poor cell coverage.


Most music servers today support some form of the subsonic API.

I’ve tried a couple, with mixed results:

  • supysonic; Python. Slow. Ran into some issues with subsonic clients. No real web UI.
  • gonic; Go. Works well & fast enough. Minimal web UI, i.e. no ability to play music from a browser.
  • airsonic; Java. Last in a chain of (abandoned) forks. More effort to get to work, and resource intensive.

Eventually, I’ve settled on Navidrome. It’s got a couple of things going for it:

  • Good subsonic implementation that worked with all the Android apps I used it with.
  • Great Web UI for use in a browser

I run Navidrome in Kubernetes. It’s surprisingly easy to get going. Here’s the deployment I’m using:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69apiVersion: apps/v1 kind: Deployment metadata: name: navidrome spec: replicas: 1 selector: matchLabels: app: navidrome template: metadata: labels: app: navidrome spec: containers: - name: navidrome image: deluan/navidrome:latest imagePullPolicy: Always resources: limits: cpu: ".5" memory: "2Gi" requests: cpu: "0.1" memory: "10M" ports: - containerPort: 4533 volumeMounts: - name: navidrome-data-volume mountPath: /data - name: navidrome-music-volume mountPath: /music env: - name: ND_SCANSCHEDULE value: 1h - name: ND_LOGLEVEL value: info - name: ND_SESSIONTIMEOUT value: 24h - name: ND_BASEURL value: /navidrome livenessProbe: httpGet: path: /navidrome/app port: 4533 initialDelaySeconds: 30 periodSeconds: 3 timeoutSeconds: 90 volumes: - name: navidrome-data-volume hostPath: path: /srv/navidrome type: Directory - name: navidrome-music-volume hostPath: path: /srv/media/music type: Directory --- apiVersion: v1 kind: Service metadata: name: navidrome spec: ports: - port: 4533 name: web selector: app: navidrome type: ClusterIP

At the moment, this deployment is still tied to the machine with my music on it since it relies on hostPath volumes, but I’m planning to move that to ceph in the future.

I then expose this service on /navidrome on my private domain (here replaced with example.com) using an Ingress:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: navidrome spec: ingressClassName: nginx rules: - host: example.com http: paths: - backend: service: name: navidrome port: name: web path: /navidrome(/|$)(.*) pathType: Prefix Client

On the desktop, I usually just use navidrome’s web interface. Clementine’s support for subsonic is also okay. sublime-music is meant to be a music player specifically for Subsonic, but I’ve not really found it stable enough for day-to-day usage.

There are various Android clients for Subsonic, but I’ve only really considered the Open Source ones that are hosted on F-Droid. Most of those are abandoned, but D-Sub works pretty well - as does my preferred option, Subtracks.

Categories: FLOSS Project Planets

ItsMyCode: Python TypeError: &#8216;int&#8217; object is not subscriptable

Planet Python - Tue, 2022-01-04 12:38

ItsMyCode |

In Python, we use Integers to store the whole numbers, and it is not a subscriptable object. If you treat an integer like a subscriptable object, the Python interpreter will raise TypeError: ‘int’ object is not subscriptable.

In this tutorial, we will learn what ‘int’ object is is not subscriptable error means and how to resolve this TypeError in your program with examples.

What is Subscriptable in Python?

Subscriptable” means that you’re trying to access an element of the object. The elements are usually accessed using indexing since it is the same as a mathematical notation that uses actual subscripts.

How do you make an object Subscriptable?

In Python, any objects that implement the __getitem__ method in the class definition are called subscriptable objects, and by using the  __getitem__  method, we can access the elements of the object.

For example, strings, lists, dictionaries, tuples are all subscriptable objects. We can retrieve the items from these objects using indexing.

Note: Python doesn't allow to subscript the NoneType if you do Python will raise TypeError: 'NoneType' object is not subscriptable How to Fix TypeError: ‘int’ object is not subscriptable?

Let us take a small example to read the birth date from the user and slice the day, months and year values into separate lines.

birth_date = int(input("Please enter your birthdate in the format of (mmddyyyy) ")) birth_month = birth_date[0:2] birth_day = birth_date[2:4] birth_year = birth_date[4:8] print("Birth Month:", birth_month) print("Birth Day:", birth_day) print("Birth Year:", birth_year)

If you look at the above program, we are reading the user birth date as an input parameter in the mmddyy format.

Then to retrieve the values of the day, month and year from the user input, we use slicing and store it into a variable.

When we run the code, Python will raise a TypeError: ‘int’ object is not subscriptable.

Please enter your birthdate in the format of (mmddyyyy) 01302004 Traceback (most recent call last): File "C:\Personal\IJS\Code\main.py", line 3, in <module> birth_month = birth_date[0:2] TypeError: 'int' object is not subscriptable Solution

 In our example, we are reading the birth date as input from the user and the value is converted to an integer. 

The integer values cannot be accessed using slicing or indexing, and if we do that, we get the TypeError. 

To solve this issue, we can remove the int() conversion while reading the input from the string. So now the birth_date will be of type string, and we can use slicing or indexing on the string variable.

Let’s correct our example and run the code.

birth_date = input("Please enter your birthdate in the format of (mmddyyyy) ") birth_month = birth_date[0:2] birth_day = birth_date[2:4] birth_year = birth_date[4:8] print("Birth Month:", birth_month) print("Birth Day:", birth_day) print("Birth Year:", birth_year)


Please enter your birthdate in the format of (mmddyyyy) 01302004 Birth Month: 01 Birth Day: 30 Birth Year: 2004

The code runs successfully since the int() conversion is removed from the code, and slicing works perfectly on the string object to extract a day, month and year.


The TypeError: ‘int’ object is not subscriptable error occurs if we try to index or slice the integer as if it is a subscriptable object like list, dict, or string objects.

The issue can be resolved by removing any indexing or slicing to access the values of the integer object. If you still need to perform indexing or slicing on integer objects, you need to first convert that into strings or lists and then perform this operation.

The post Python TypeError: ‘int’ object is not subscriptable appeared first on ItsMyCode.

Categories: FLOSS Project Planets

Jonathan McDowell: Upgrading from a CC2531 to a CC2538 Zigbee coordinator

Planet Debian - Tue, 2022-01-04 10:50

Previously I setup a CC2531 as a Zigbee coordinator for my home automation. This has turned out to be a good move, with the 4 gang wireless switch being particularly useful. However the range of the CC2531 is fairly poor; it has a simple PCB antenna. It’s also a very basic device. I set about trying to improve the range and scalability and settled upon a CC2538 + CC2592 device, which feature an MMCX antenna connector. This device also has the advantage that it’s ARM based, which I’m hopeful means I might be able to build some firmware myself using a standard GCC toolchain.

For now I fetched the JetHome firmware from https://github.com/jethome-ru/zigbee-firmware/tree/master/ti/coordinator/cc2538_cc2592 (JH_2538_2592_ZNP_UART_20211222.hex) - while it’s possible to do USB directly with the CC2538 my board doesn’t have those bits so going the external USB UART route is easier.

The device had some existing firmware on it, so I needed to erase this to force a drop into the boot loader. That means soldering up the JTAG pins and hooking it up to my Bus Pirate for OpenOCD goodness.

OpenOCD config source [find interface/buspirate.cfg] buspirate_port /dev/ttyUSB1 buspirate_mode normal buspirate_vreg 1 buspirate_pullup 0 transport select jtag source [find target/cc2538.cfg] Steps to erase $ telnet localhost 4444 Trying ::1... Trying Connected to localhost. Escape character is '^]'. Open On-Chip Debugger > mww 0x400D300C 0x7F800 > mww 0x400D3008 0x0205 > shutdown shutdown command invoked Connection closed by foreign host.

At that point I can switch to the UART connection (on PA0 + PA1) and flash using cc2538-bsl:

$ git clone https://github.com/JelmerT/cc2538-bsl.git $ cc2538-bsl/cc2538-bsl.py -p /dev/ttyUSB1 -e -w -v ~/JH_2538_2592_ZNP_UART_20211222.hex Opening port /dev/ttyUSB1, baud 500000 Reading data from /home/noodles/JH_2538_2592_ZNP_UART_20211222.hex Firmware file: Intel Hex Connecting to target... CC2538 PG2.0: 512KB Flash, 32KB SRAM, CCFG at 0x0027FFD4 Primary IEEE Address: 00:12:4B:00:22:22:22:22 Performing mass erase Erasing 524288 bytes starting at address 0x00200000 Erase done Writing 524256 bytes starting at address 0x00200000 Write 232 bytes at 0x0027FEF88 Write done Verifying by comparing CRC32 calculations. Verified (match: 0x74f2b0a1)

I then wanted to migrate from the old device to the new without having to repair everything. So I shut down Home Assistant and backed up the CC2531 network information using zigpy-znp (which is already installed for Home Assistant):

python3 -m zigpy_znp.tools.network_backup /dev/zigbee > cc2531-network.json

I copied the backup to cc2538-network.json and modified the coordinator_ieee to be the new device’s MAC address (rather than end up with 2 devices claiming the same MAC if/when I reuse the CC2531) and did:

python3 -m zigpy_znp.tools.network_restore --input cc2538-network.json /dev/ttyUSB1

The old CC2531 needed unplugged first, otherwise I got an RuntimeError: Network formation refused, RF environment is likely too noisy. Temporarily unscrew the antenna or shield the coordinator with metal until a network is formed. error.

After that I updated my udev rules to map the CC2538 to /dev/zigbee and restarted Home Assistant. To my surprise it came up and detected the existing devices without any extra effort on my part. However that resulted in 2 coordinators being shown in the visualisation, with the old one turning up as unk_manufacturer. Fixing that involved editing /etc/homeassistant/.storage/core.device_registry and removing the entry which had the old MAC address, removing the device entry in /etc/homeassistant/.storage/zha.storage for the old MAC and then finally firing up sqlite to modify the Zigbee database:

$ sqlite3 /etc/homeassistant/zigbee.db SQLite version 3.34.1 2021-01-20 14:10:07 Enter ".help" for usage hints. sqlite> DELETE FROM devices_v6 WHERE ieee = '00:12:4b:00:11:11:11:11'; sqlite> DELETE FROM endpoints_v6 WHERE ieee = '00:12:4b:00:11:11:11:11'; sqlite> DELETE FROM in_clusters_v6 WHERE ieee = '00:12:4b:00:11:11:11:11'; sqlite> DELETE FROM neighbors_v6 WHERE ieee = '00:12:4b:00:11:11:11:11' OR device_ieee = '00:12:4b:00:11:11:11:11'; sqlite> DELETE FROM node_descriptors_v6 WHERE ieee = '00:12:4b:00:11:11:11:11'; sqlite> DELETE FROM out_clusters_v6 WHERE ieee = '00:12:4b:00:11:11:11:11'; sqlite> .quit

So far it all seems a bit happier than with the CC2531; I’ve been able to pair a light bulb that was previously detected but would not integrate, which suggests the range is improved.

(This post another in the set of “things I should write down so I can just grep my own website when I forget what I did to do foo”.)

Categories: FLOSS Project Planets

Python Morsels: dataclasses

Planet Python - Tue, 2022-01-04 10:00

Let's talk about dataclasses in Python.

A minimal boilerplate class

This Point class represents a 2-dimensional point:

class Point: """A two-dimensional point.""" def __init__(self, x, y): self.x = x self.y = y def __repr__(self): return f"Point(x={self.x}, y={self.y})"

This class accepts arguments (thanks to the initializer method):

>>> from point import Point >>> p = Point(1, 2)

And it has a friendly string representation (thanks to the __repr__ method):

>>> p Point(x=1, y=2) Using the dataclass decorator

Instead of writing our __init__ and __repr__ method ourselves, we could use the dataclass decorator (from Python's dataclasses module) when defining our class.

The dataclass decorator requires us to define the attributes (and arguments) of our class with type hints:

from dataclasses import dataclass @dataclass class Point: """A two-dimensional point.""" x: float y: float

The resulting class is essentially equivalent to this:

class Point: """A two-dimensional point.""" def __init__(self, x: float, y: float) -> None: self.x = x self.y = y def __repr__(self): return f"Point(x={self.x}, y={self.y})" def __eq__(self, other): """Return True if our point is equal to the other point.""" if not isinstance(other, Point): return NotImplemented return (self.x, self.y) == (other.x, other.y)

It has an initializer and a nice string representation (just as before):

>>> from point import Point >>> p = Point(1, 2) >>> p >>> Point(x=1, y=2)

We can access x and y attributes (just as in our previous class):

>>> p.x 1 >>> p.y 2

But we can also we can check equality between two Point objects:

>>> p == Point(1, 2) True

We get all of that for free thanks to the dataclass decorator.

Making class objects immutable

To make our Point objects immutable, we could pass frozen=True to our dataclass decorator:

from dataclasses import dataclass @dataclass(frozen=True) class Point: """A two-dimensional point.""" x: float y: float

Now our Point objects are immutable which means we can't assign to their attributes:

>>> p = Point(1, 2) >>> p.x = 2 Traceback (most recent call last): File "<stdin>", line 1, in <module> File "<string>", line 4, in __setattr__ dataclasses.FrozenInstanceError: cannot assign to field 'x' When should you use dataclasses?

Whenever you'd like to quickly create a class with a friendly interface (with a nice string representation and sensible equality checking), consider reaching for the dataclass decorator from Python's dataclasses module.

Categories: FLOSS Project Planets

Real Python: Deploy Your Python Script on the Web With Flask

Planet Python - Tue, 2022-01-04 09:00

You wrote a Python script that you’re proud of, and now you want to show it off to the world. But how? Most people won’t know what to do with your .py file. Converting your script into a Python web application is a great solution to make your code usable for a broad audience.

In this course, you’ll learn how to go from a local Python script to a fully deployed Flask web application that you can share with the world.

By the end of this course, you’ll know:

  • What web applications are and how you can host them online
  • How to convert a Python script into a Flask web application
  • How to improve user experience by adding HTML to your Python code
  • How to deploy your Python web application to Google App Engine

[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. >> Click here to learn more and see examples ]

Categories: FLOSS Project Planets