Skip to content

Commit

Permalink
[fix] ListItem.setInfo (or actually anything that takes a string via …
Browse files Browse the repository at this point in the history
…python) can now handle None.
  • Loading branch information
Jim Carroll committed Dec 29, 2013
1 parent 951d978 commit 36f3eab
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
9 changes: 9 additions & 0 deletions xbmc/interfaces/python/swig.cpp
Expand Up @@ -21,6 +21,7 @@
#include "LanguageHook.h"
#include "swig.h"
#include "utils/StringUtils.h"
#include "interfaces/legacy/AddonString.h"

#include <string>

Expand All @@ -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?
Expand Down
10 changes: 10 additions & 0 deletions xbmc/interfaces/python/swig.h
Expand Up @@ -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);
Expand Down

1 comment on commit 36f3eab

@MartijnKaijser
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.