From 36f3eab206de2362d54c40c00cd4a888569c572b Mon Sep 17 00:00:00 2001 From: Jim Carroll Date: Sun, 29 Dec 2013 09:59:35 -0500 Subject: [PATCH] [fix] ListItem.setInfo (or actually anything that takes a string via python) can now handle None. --- xbmc/interfaces/python/swig.cpp | 9 +++++++++ xbmc/interfaces/python/swig.h | 10 ++++++++++ 2 files changed, 19 insertions(+) diff --git a/xbmc/interfaces/python/swig.cpp b/xbmc/interfaces/python/swig.cpp index 76ee9b5cee0c3..8808f1e5e4918 100644 --- a/xbmc/interfaces/python/swig.cpp +++ b/xbmc/interfaces/python/swig.cpp @@ -21,6 +21,7 @@ #include "LanguageHook.h" #include "swig.h" #include "utils/StringUtils.h" +#include "interfaces/legacy/AddonString.h" #include @@ -46,6 +47,14 @@ namespace PythonBindings void PyXBMCGetUnicodeString(std::string& buf, PyObject* pObject, bool coerceToString, const char* argumentName, const char* methodname) throw (XBMCAddon::WrongTypeException) { + // It's okay for a string to be "None". In this case the buf returned + // will be the emptyString. + if (pObject == Py_None) + { + buf = XBMCAddon::emptyString; + return; + } + // TODO: UTF-8: Does python use UTF-16? // Do we need to convert from the string charset to UTF-8 // for non-unicode data? diff --git a/xbmc/interfaces/python/swig.h b/xbmc/interfaces/python/swig.h index e8bd15d267c0e..d2bfdd2cdccc2 100644 --- a/xbmc/interfaces/python/swig.h +++ b/xbmc/interfaces/python/swig.h @@ -33,6 +33,16 @@ namespace PythonBindings { + /** + * This call will convert the python object passed to a string. The object + * passed must be a python str or unicode object unless coerceToString is + * true. If coerceToString is true then the type must be castable to a string + * using the python call str(pObject). + * + * This method will handle a 'None' that's passed in. If 'None' is passed then + * the resulting buf will contain the value of XBMCAddon::emptyString (which + * is simply a std::string instantiated with the default constructor. + */ void PyXBMCGetUnicodeString(std::string& buf, PyObject* pObject, bool coerceToString = false, const char* pos = "unknown", const char* methodname = "unknown") throw (XBMCAddon::WrongTypeException);