Repository: web2py/web2py

Issue:
error at py3
solve

``` diff
git diff globals.py
diff --git a/gluon/globals.py b/gluon/globals.py
index 41ac708..ae4e0bc 100644
--- a/gluon/globals.py
+++ b/gluon/globals.py
@@ -13,7 +13,7 @@ Contains the classes for the global used variables:
 - Session

 """
-from gluon._compat import pickle, StringIO, copyreg, Cookie, urlparse, PY2, iteritems, to_unicode, to_native, unicodeT
+from gluon._compat import pickle, StringIO, copyreg, Cookie, urlparse, PY2, iteritems, to_unicode, to_native, unicodeT, long
 from gluon.storage import Storage, List
 from gluon.streamer import streamer, stream_file_or_304_or_206, DEFAULT_CHUNK_SIZE
 from gluon.contenttype import contenttype
```



Discussion:
LGTM

also

``` diff
git diff contrib/login_methods/cas_auth.py
diff --git a/gluon/contrib/login_methods/cas_auth.py b/gluon/contrib/login_methods/cas_auth.py
index 61d9986..63261bb 100644
--- a/gluon/contrib/login_methods/cas_auth.py
+++ b/gluon/contrib/login_methods/cas_auth.py
@@ -86,7 +86,8 @@ class CasAuth(object):
         exposed as CAS.login(request)
         returns a token on success, None on failed authentication
         """
-        import urllib
+        from gluon._compat import urllib2 as urllib
+        from gluon._compat import PY2
         self.ticket = current.request.vars.ticket
         if not current.request.vars.ticket:
             redirect("%s?service=%s" % (self.cas_login_url,
@@ -96,6 +97,7 @@ class CasAuth(object):
                                                self.cas_my_url,
                                                self.ticket)
             data = urllib.urlopen(url).read()
+            if not PY2: data = data.decode('utf8')
             if data.startswith('yes') or data.startswith('no'):
                 data = data.split('\n')
                 if data[0] == 'yes':
@@ -118,8 +120,11 @@ class CasAuth(object):
                     res = dict()
                     for x in envelop[0].childNodes:
                         if x.nodeName.startswith('cas:') and len(x.childNodes):
-                            key = x.nodeName[4:].encode('utf8')
-                            value = x.childNodes[0].nodeValue.encode('utf8')
+                            key = x.nodeName[4:]#.encode('utf8')
+                            value = x.childNodes[0].nodeValue#.encode('utf8')
+                            if PY2:
+                                key = key.encode('utf8')
+                                value = value.encode('utf8')
                             if not key in res:
                                 res[key] = value
                             else:
```

and

``` diff
diff --git a/pydal/parsers/base.py b/pydal/parsers/base.py
index 2783fda..29944a7 100644
--- a/pydal/parsers/base.py
+++ b/pydal/parsers/base.py
@@ -34,7 +34,8 @@ class BasicParser(Parser):

     @for_type('blob')
     def _blob(self, value):
-        return to_native(b64decode(to_bytes(value)))
+        if PY2: return to_native(b64decode(to_bytes(value)))
+        else: return b64decode(value)

     @before_parse('reference')
     def reference_extras(self, field_type):
```

with order ... the last goes to pydal ...https://github.com/web2py/pydal/issues/417

@RekGRpth would you create a PR with such changes?
At first sight in `gluon/contrib/login_methods/cas_auth.py` you can use `to_native` instead of the `if`


Resolving patch:
diff --git a/gluon/contrib/login_methods/cas_auth.py b/gluon/contrib/login_methods/cas_auth.py
--- a/gluon/contrib/login_methods/cas_auth.py
+++ b/gluon/contrib/login_methods/cas_auth.py
@@ -8,9 +8,11 @@
 
 Tinkered by Szabolcs Gyuris < szimszo n @ o regpreshaz dot eu>
 """
+import xml.dom.minidom as dom
+import xml.parsers.expat as expat
 
 from gluon import current, redirect, URL
-
+from gluon._compat import urlopen, to_native
 
 class CasAuth(object):
     """
@@ -59,7 +61,7 @@ def __init__(self, g=None,  # g for backward compatibility ###
         # vars commented because of
         # https://code.google.com/p/web2py/issues/detail?id=1774
         self.cas_my_url = URL(args=current.request.args,
-                              #vars=current.request.vars, 
+                              #vars=current.request.vars,
                               scheme=True)
 
     def login_url(self, next="/"):
@@ -86,7 +88,6 @@ def _CAS_login(self):
         exposed as CAS.login(request)
         returns a token on success, None on failed authentication
         """
-        import urllib
         self.ticket = current.request.vars.ticket
         if not current.request.vars.ticket:
             redirect("%s?service=%s" % (self.cas_login_url,
@@ -95,7 +96,7 @@ def _CAS_login(self):
             url = "%s?service=%s&ticket=%s" % (self.cas_check_url,
                                                self.cas_my_url,
                                                self.ticket)
-            data = urllib.urlopen(url).read()
+            data = to_native(urlopen(url).read())
             if data.startswith('yes') or data.startswith('no'):
                 data = data.split('\n')
                 if data[0] == 'yes':
@@ -108,19 +109,16 @@ def _CAS_login(self):
                         a = b = c = data[1]
                     return dict(user=a, email=b, username=c)
                 return None
-            import xml.dom.minidom as dom
-            import xml.parsers.expat as expat
             try:
                 dxml = dom.parseString(data)
-                envelop = dxml.getElementsByTagName(
-                    "cas:authenticationSuccess")
+                envelop = dxml.getElementsByTagName("cas:authenticationSuccess")
                 if len(envelop) > 0:
                     res = dict()
                     for x in envelop[0].childNodes:
                         if x.nodeName.startswith('cas:') and len(x.childNodes):
-                            key = x.nodeName[4:].encode('utf8')
-                            value = x.childNodes[0].nodeValue.encode('utf8')
-                            if not key in res:
+                            key = to_native(x.nodeName[4:])
+                            value = to_native(x.childNodes[0].nodeValue)
+                            if key not in res:
                                 res[key] = value
                             else:
                                 if not isinstance(res[key], list):
@@ -136,5 +134,4 @@ def _CAS_logout(self):
         exposed CAS.logout()
         redirects to the CAS logout page
         """
-        import urllib
         redirect("%s?service=%s" % (self.cas_logout_url, self.cas_my_url))
diff --git a/gluon/globals.py b/gluon/globals.py
--- a/gluon/globals.py
+++ b/gluon/globals.py
@@ -13,7 +13,7 @@
 - Session
 
 """
-from gluon._compat import pickle, StringIO, copyreg, Cookie, urlparse, PY2, iteritems, to_unicode, to_native, unicodeT
+from gluon._compat import pickle, StringIO, copyreg, Cookie, urlparse, PY2, iteritems, to_unicode, to_native, unicodeT, long
 from gluon.storage import Storage, List
 from gluon.streamer import streamer, stream_file_or_304_or_206, DEFAULT_CHUNK_SIZE
 from gluon.contenttype import contenttype


Test patch: