[Python-modules-commits] [python-social-auth] 65/71: PEP8 and doc styles applied

Wolfgang Borgert debacle at moszumanska.debian.org
Sat Dec 24 15:14:31 UTC 2016


This is an automated email from the git hooks/post-receive script.

debacle pushed a commit to tag v0.2.14
in repository python-social-auth.

commit 345721dcbae2da0db5622893e907709b9e0a99be
Author: Matías Aguirre <matiasaguirre at gmail.com>
Date:   Wed Dec 23 13:18:37 2015 -0300

    PEP8 and doc styles applied
---
 docs/backends/index.rst             |  1 +
 docs/backends/naver.rst             | 12 +++++++-----
 social/backends/naver.py            | 31 +++++++++++++++++++------------
 social/tests/backends/test_naver.py |  9 ++++++---
 4 files changed, 33 insertions(+), 20 deletions(-)

diff --git a/docs/backends/index.rst b/docs/backends/index.rst
index a6b63da..3d6b7e6 100644
--- a/docs/backends/index.rst
+++ b/docs/backends/index.rst
@@ -99,6 +99,7 @@ Social backends
    moves
    naszaklasa
    nationbuilder
+   naver
    odnoklassnikiru
    openstreetmap
    orbi
diff --git a/docs/backends/naver.rst b/docs/backends/naver.rst
index 3389f36..60d21d4 100644
--- a/docs/backends/naver.rst
+++ b/docs/backends/naver.rst
@@ -1,5 +1,5 @@
 Naver
-========
+=====
 
 Naver uses OAuth v2 for Authentication.
 
@@ -13,13 +13,15 @@ Naver uses OAuth v2 for Authentication.
         ...
     )
 
-- fill ``Client ID`` and ``Client Secret`` from developer.naver.com values in the settings::
+- fill ``Client ID`` and ``Client Secret`` from developer.naver.com
+  values in the settings::
 
 	SOCIAL_AUTH_NAVER_KEY = ''
 	SOCIAL_AUTH_NAVER_SECRET = ''
 
-- you can get EXTRA_DATA:: 
-	
-	SOCIAL_AUTH_NAVER_EXTRA_DATA = ['nickname', 'gender', 'age', 'birthday', 'profile_image']
+- you can get EXTRA_DATA::
+
+	SOCIAL_AUTH_NAVER_EXTRA_DATA = ['nickname', 'gender', 'age',
+                                        'birthday', 'profile_image']
 
 .. _Naver API: https://nid.naver.com/devcenter/docs.nhn?menu=API
diff --git a/social/backends/naver.py b/social/backends/naver.py
index 709db94..89acfdb 100644
--- a/social/backends/naver.py
+++ b/social/backends/naver.py
@@ -1,4 +1,3 @@
-
 from xml.dom import minidom
 
 from social.backends.oauth import BaseOAuth2
@@ -26,20 +25,25 @@ class NaverOAuth2(BaseOAuth2):
 
     def user_data(self, access_token, *args, **kwargs):
         """Loads user data from service"""
-        dom = minidom.parseString(self.request(
+        response = self.request(
             'https://openapi.naver.com/v1/nid/getUserProfile.xml',
-            headers={'Authorization': 'Bearer {0}'.format(access_token), 'Content_Type': 'text/xml'}
-            ).text.encode('utf-8').strip())
+            headers={
+                'Authorization': 'Bearer {0}'.format(access_token),
+                'Content_Type': 'text/xml'
+            }
+        )
+
+        dom = minidom.parseString(response.text.encode('utf-8').strip())
 
         return {
-            'id': dom.getElementsByTagName('id')[0].childNodes[0].data,
-            'email': dom.getElementsByTagName('email')[0].childNodes[0].data,
-            'username': dom.getElementsByTagName('name')[0].childNodes[0].data,
-            'nickname': dom.getElementsByTagName('nickname')[0].childNodes[0].data,
-            'gender': dom.getElementsByTagName('gender')[0].childNodes[0].data,
-            'age': dom.getElementsByTagName('age')[0].childNodes[0].data,
-            'birthday': dom.getElementsByTagName('birthday')[0].childNodes[0].data,
-            'profile_image': dom.getElementsByTagName('profile_image')[0].childNodes[0].data,
+            'id': self._dom_value(dom, 'id'),
+            'email': self._dom_value(dom, 'email'),
+            'username': self._dom_value(dom, 'name'),
+            'nickname': self._dom_value(dom, 'nickname'),
+            'gender': self._dom_value(dom, 'gender'),
+            'age': self._dom_value(dom, 'age'),
+            'birthday': self._dom_value(dom, 'birthday'),
+            'profile_image': self._dom_value(dom, 'profile_image')
         }
 
     def auth_headers(self):
@@ -50,3 +54,6 @@ class NaverOAuth2(BaseOAuth2):
             'client_id': client_id,
             'client_secret': client_secret,
         }
+
+    def _dom_value(self, dom, key):
+        return dom.getElementsByTagName(key)[0].childNodes[0].data
diff --git a/social/tests/backends/test_naver.py b/social/tests/backends/test_naver.py
index fcb0a67..096a3c2 100644
--- a/social/tests/backends/test_naver.py
+++ b/social/tests/backends/test_naver.py
@@ -1,6 +1,8 @@
 import json
+
 from social.tests.backends.oauth import OAuth2Test
 
+
 class NaverOAuth2Test(OAuth2Test):
     backend_path = 'social.backends.naver.NaverOAuth2'
     user_data_url = 'https://openapi.naver.com/v1/nid/getUserProfile.xml'
@@ -21,7 +23,9 @@ class NaverOAuth2Test(OAuth2Test):
         '<response>' \
             '<email><![CDATA[foobar at naver.com]]></email>' \
             '<nickname><![CDATA[foobar]]></nickname>' \
-            '<profile_image><![CDATA[http://naver.com/image.url.jpg]]></profile_image>' \
+            '<profile_image>' \
+                '<![CDATA[http://naver.com/image.url.jpg]]>' \
+            '</profile_image>' \
             '<age><![CDATA[20-29]]></age>' \
             '<gender>M</gender>' \
             '<id><![CDATA[123456]]></id>' \
@@ -30,9 +34,8 @@ class NaverOAuth2Test(OAuth2Test):
         '</response>' \
     '</data>'
 
-
     def test_login(self):
         self.do_login()
 
     def test_partial_pipeline(self):
-        self.do_partial_pipeline()
\ No newline at end of file
+        self.do_partial_pipeline()

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-social-auth.git



More information about the Python-modules-commits mailing list