Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 24ef147

Browse files
committed
Clean code managing cookieAuth parameter
1 parent 58d051a commit 24ef147

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

‎dokuwiki.py‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -138,26 +138,26 @@ class DokuWiki(object):
138138
for example).
139139
"""
140140

141-
def __init__(self, url, user, password, cookieAuth=False, **kwargs):
141+
def __init__(self, url, user, password, **kwargs):
142142
"""Initialize the object by connecting to the XMLRPC server."""
143-
# Initialize XMLRPC client.
143+
# Parse input URL
144144
try:
145145
params = _URL_RE.search(url).groupdict()
146-
if cookieAuth == False:
147-
url = '%s://%s:%s@%s%s/lib/exe/xmlrpc.php' % (
148-
params['proto'], user, password, params['host'], params['uri'] or '')
149-
else:
150-
url = '%s://%s%s/lib/exe/xmlrpc.php' % (
151-
params['proto'], params['host'], params['uri'] or '')
152146
except AttributeError:
153147
raise DokuWikiError("invalid url '%s'" % url)
154148

155-
if cookieAuth == False:
156-
self.proxy = ServerProxy(url, **kwargs)
157-
else:
158-
self.proxy = ServerProxy(url, CookiesTransport(params['proto']), **kwargs)
149+
# Set auth string or transport for cookie based authentication.
150+
auth = '{:s}:{:s}@'.format(user, password)
151+
if kwargs.pop('cookieAuth', False):
152+
auth = ''
153+
kwargs['transport'] = CookiesTransport(params['proto'])
154+
155+
xmlrpc_url = '%s://%s%s%s/lib/exe/xmlrpc.php' % (
156+
params['proto'], auth, params['host'], params['uri'] or '')
157+
self.proxy = ServerProxy(xmlrpc_url, **kwargs)
159158

160-
# Force login to check the connection.
159+
# Force login (required for cookie based authentication and allows
160+
# to check the connection).
161161
if not self.login(user, password):
162162
raise DokuWikiError('invalid login or password!')
163163

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /