Python custom exceptions in C(++) extensions

Python is a nice scripting language, but it has the fame of being difficult to embed and interact with existing projects.

Until now, I have been able to embed it in the software I work on with pybind11 and Binder (half of my MS degree thesis is about that), I had some problems, but I was able to solve most of them. But recently I have experienced a problem that is quite uncommon on the Internet: declaring a new exception in a native (C++/C module) with some custom methods/properties.

The existing proposal

I quickly looked on the Internet for the problem. The Python C API makes creating an exception type possible with PyObject *PyErr_NewException(const char *name, PyObject *bases, PyObject *dict): the first parameter is the name of the exception, in the modulename.ExceptionName format, the second parameter is the base or bases of the new exception (can be a PyType, or a tuple of PyTypes), and a dictionary of custom members and methods for the new type.

However both the second and third parameter can be left to NULL: in this case the new type will inherit from PyExc_Exception and will not have customizations. This is the majority of the cases, and by a search on the CPython code I could not find any reference that could use as an example on how to use the dict parameter. … [Leggi il resto]

Adwaita+Tango for PuTTY

Recently I have started using PuTTY more and more. It is a very nice program that has lots of features but it has also a big problem: with the default settings, fonts and colors are a bit ugly and in some case the text is even difficult to read.

Luckily PuTTY has lots of customization possibilities. My first idea was to use Solarized (Light), because I use it also on my phone with JuiceSSH and on Gedit. However, almost immediately I realized this problem:

ls using the Solarized Light theme: the image shows that it is difficult to tells directories from files

As you can see, directories, files and links have almost the same color and are very difficult to distinguish. Notice that I have enabled the bold as font, which by default is disabled, otherwise directories and links would have normal weight, and it would be even more difficult to what is what. … [Leggi il resto]

A note about Call Of Duty 1/UO BSP maps

Call Of Duty 1 and its expansion, United Offensive, are based on the Quake III engine, therefore they share some of its features, like a Binary Space Partitioning to describe maps, even though the format isn’t compatible.

An article copyrighted 2000 describes very well the BSP format of Quake 3. It’s interesting, because it’s the very base to understand CoD, too, at least its devision in lumps and some of them.

An article on “Mappers United Wiki” depicts the lumps of CoD 1 maps and the size of single lump, but they aren’t explained. Luckily in the same site there’s an article on CoD 2, and most of the structs are equal.

So I’ve tried to render them, but I’ve only managed to build the geometry of maps. … [Leggi il resto]

Plugin Tabmenu (v4.1) [Flatpress]

Description

This is the new version of the Tabmenu plugin, that replaces, the version 4.0.

The plugin adds “sel” class if you are in that page (in HTML, class=”sel”).

You can use both {{TABCLASS}} and {{TABSELECT}} patterns: the difference is that the first adds the class attribute, the second just the sel and so you can speficy other classes. See below for an example.
This is an example (for the homepage):

<li {{TABCLASS:index}}><a href="/" title="Homepage>Homepage</a></li>
<li class="myotherclass {{TABSELECT:index}}"><a href="/" title="Homepage>Homepage</a></li>

Replace index with:

  • index for the homepage;
  • blogindex or blog for the blog homepage;
  • contact for contact.php
  • admin for admin panel
  • login for login page
  • post:entry_id or entry:entry_id for entries (entry_id is the entry id in format entryYYMMDD-hhmmss) … [Leggi il resto]

Plugin RewriteURLs (v2.3.6) [Flatpress]

There is a new small fix in RewriteURLs plugin.

It fixes the strange behavior with ?u mode.

So if you use the classic mode or pathinfo mode you don’t need to update it.

Thanks to LTB for the reporting.

Downlaod: rewriteurls_v2.3.6.tar.gz.

Released under GPLv2.