Skip to content

Instantly share code, notes, and snippets.

@mbursa
mbursa / kem-decryptor.py
Last active February 13, 2024 20:55
Python script to decrypt Kamstrup KEM files
# A Python script that decrypts the content of Kamstrup KEM file and imports meter files
# to wmbusmeters' config folder.
#
# The KEM file is a (sometimes zipped) xml file that contains xml-encrypted data using
# the xml-enc standard (http://www.w3.org/2001/04/xmlenc). The password needed to decrypt
# the xml-encrypted data can either be the CustomerId or something else selected by the
# person that has created the KEM file using Kamstrup software.
#
# This script takes the encrypted KEM file and decrypts its content (it automaticly detects
# the zip archive and extracts the kem file from it). The result is a XML with a list of meters
@mbursa
mbursa / rpyc_deep_copy.py
Created August 21, 2018 13:31
Routine to make a deep copy of RPyC remote objects.
def rpyc_deep_copy(obj):
"""
Makes a deep copy of netref objects that come as a result of RPyC remote method calls.
When RPyC client obtains a result from the remote method call, this result may contain
non-scalar types (List, Dict, ...) which are given as a wrapper class (a netref object).
This class does not have all the standard attributes (e.g. dict.tems() does not work)
and in addition the objects only exist while the connection is active (are weekly referenced).
To have a retuned value represented by python's native datatypes and to by able to use it
after the connection is terminated, this routine makes a recursive copy of the given object.
Currently, only `list` and `dist` types are supported for deep_copy, but other types may be