From 9f66fa0f9a4d9d759b9fdb44f411a4dc1a0748cb Mon Sep 17 00:00:00 2001 From: Raymond Wagner Date: Tue, 23 Oct 2012 15:42:31 -0400 Subject: [PATCH] Fix immutable methods in Artwork class. This fixes an issue with several immutable methods in the Artwork class, inherited from the parent UserString class. As the Artwork class is modified for use as a property, and not intended to be called directly for storage of a string, the inherited UserString methods that returned a new instance using the __class__ attribute would fail. This adds a __new__ method that detects such uses and forces the call to return a standard str type instead. --- mythtv/bindings/python/MythTV/dataheap.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/mythtv/bindings/python/MythTV/dataheap.py b/mythtv/bindings/python/MythTV/dataheap.py index 30bd0224f0e..f6570ffca6a 100644 --- a/mythtv/bindings/python/MythTV/dataheap.py +++ b/mythtv/bindings/python/MythTV/dataheap.py @@ -48,6 +48,14 @@ def data(self): raise RuntimeError("Artwork property must be used through an " +\ "object, not independently.") + def __new__(cls, attr, parent=None, imagetype=None): + if (imagetype is None) and (attr not in cls._types): + # usage appears to be export from immutable UserString methods + # return a dumb string + return str.__new__(str, attr) + else: + return super(Artwork, cls).__new__(cls, attr, parent, imagetype) + def __init__(self, attr, parent=None, imagetype=None): # replace standard MutableString init to not overwrite self.data from warnings import warnpy3k