From 25f4ce12db135aa2c098bca329757db5a83f371f Mon Sep 17 00:00:00 2001
From: Bryan Tong Minh <bryan.tongminh@gmail.com>
Date: Thu, 15 May 2008 19:41:43 +0000
Subject: [PATCH] * More verbose errors * Add expandtemplates

---
 mwclient/client.py | 16 +++++++++++++++-
 mwclient/errors.py |  4 ++--
 2 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/mwclient/client.py b/mwclient/client.py
index 82d97c7..55278b5 100644
--- a/mwclient/client.py
+++ b/mwclient/client.py
@@ -148,7 +148,7 @@ class Site(object):
 					self.wait(token)
 					continue
 				raise errors.APIError(info['error']['code'],
-					info['error']['info'])
+					info['error']['info'], kwargs)
 			return info
 		
 	@staticmethod
@@ -461,3 +461,17 @@ class Site(object):
 		if allrev: kwargs['wlallrev'] = '1'
 		return listing.List(self, 'watchlist', 'wl', limit = limit, **kwargs)
 		
+	def expandtemplates(self, text, title = None, generatexml = False):
+		self.require(1, 11)
+		
+		kwargs = {}
+		if title is None: kwargs['title'] = title
+		if generatexml: kwargs['generatexml'] = '1'
+		
+		result = self.api('expandtemplates', text = text, **kwargs)
+		
+		if generatexml:
+			return result['expandtemplates']['*'], result['parsetree']['*']
+		else:
+			return result['expandtemplates']['*']
+		
diff --git a/mwclient/errors.py b/mwclient/errors.py
index d996eb2..297e6b9 100644
--- a/mwclient/errors.py
+++ b/mwclient/errors.py
@@ -14,10 +14,10 @@ class MaximumRetriesExceeded(MwClientError):
 	pass
 	
 class APIError(MwClientError):
-	def __init__(self, code, info):
+	def __init__(self, code, info, kwargs):
 		self.code = code
 		self.info = info
-		MwClientError.__init__(self, code, info)
+		MwClientError.__init__(self, code, info, kwargs)
 	
 class InsufficientPermission(MwClientError):
 	pass
-- 
GitLab