internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: web2py/web2py

Issue:
Shell.py doesn't work in Python 3
When trying to run web2py from shell under python3 it throws an exception since shell.py calls execfile() func:

Traceback (most recent call last):
  File "/Users/dev/Projects/www/gluon/shell.py", line 270, in run
    execfile(startfile, _env)
NameError: name 'execfile' is not defined




Discussion:

Resolving patch:
diff --git a/gluon/shell.py b/gluon/shell.py
--- a/gluon/shell.py
+++ b/gluon/shell.py
@@ -31,10 +31,16 @@
 from gluon.storage import Storage, List
 from gluon.admin import w2p_unpack
 from pydal.base import BaseAdapter
-from gluon._compat import iteritems, ClassType
+from gluon._compat import iteritems, ClassType, PY2
 
 logger = logging.getLogger("web2py")
 
+if not PY2:
+    def execfile(filename, global_vars=None, local_vars=None):
+        with open(filename) as f:
+            code = compile(f.read(), filename, 'exec')
+            exec(code, global_vars, local_vars)
+
 
 def enable_autocomplete_and_history(adir, env):
     try:


Test patch:
Repository: web2py/web2py

Issue:
appadmin errors page didn't show detail information
appadmin errors page didn't show like inspect attributes, code, arguments, variables, locals, request, response, session like in previous version (2.14.6)


Discussion:

Resolving patch:
diff --git a/gluon/compileapp.py b/gluon/compileapp.py
--- a/gluon/compileapp.py
+++ b/gluon/compileapp.py
@@ -676,6 +676,7 @@ def run_view_in(environment):
     badv = 'invalid view (%s)' % view
     patterns = response.get('generic_patterns')
     layer = None
+    scode = None
     if patterns:
         regex = re_compile('|'.join(map(fnmatch.translate, patterns)))
         short_action = '%(controller)s/%(function)s.%(extension)s' % request
@@ -718,12 +719,14 @@ def run_view_in(environment):
 
         # if the view is not compiled
         if not layer:
-            # Compile the template
-            ccode = parse_template(view,
+            # Parse template
+            scode = parse_template(view,
                                    pjoin(folder, 'views'),
                                    context=environment)
+            # Compile template
+            ccode = compile2(scode, filename)
         layer = filename
-    restricted(ccode, environment, layer=layer)
+    restricted(ccode, environment, layer=layer, scode=scode)
     # parse_template saves everything in response body
     return environment['response'].body.getvalue()
 
diff --git a/gluon/restricted.py b/gluon/restricted.py
--- a/gluon/restricted.py
+++ b/gluon/restricted.py
@@ -205,7 +205,7 @@ def compile2(code, layer):
     return compile(code, layer, 'exec')
 
 
-def restricted(ccode, environment=None, layer='Unknown'):
+def restricted(ccode, environment=None, layer='Unknown', scode=None):
     """
     Runs code in environment and returns the output. If an exception occurs
     in code it raises a RestrictedError containing the traceback. Layer is
@@ -230,7 +230,9 @@ def restricted(ccode, environment=None, layer='Unknown'):
             sys.excepthook(etype, evalue, tb)
         del tb
         output = "%s %s" % (etype, evalue)
-        raise RestrictedError(layer, ccode, output, environment)
+        # Save source code in ticket when available
+        scode = scode if scode else ccode
+        raise RestrictedError(layer, scode, output, environment)
 
 
 def snapshot(info=None, context=5, code=None, environment=None):


Test patch:
Repository: web2py/web2py

Issue:
LOAD() error which result from the python3 map function in gluon/compileapp.py line 208
I am using python3.6 and  web2py 2.15.4. When I use the LOAD() funtion I find an error "can only concatenate list (not "map") to list". After searching and debugging, I find that python3 change the behavior of map function. In python3 map() function return an map object not a list. So the gloun/compileapp line 208 `        other_request.env.path_info = '/' + \
            '/'.join([request.application, c, f] +
                     map(str, other_request.args))` throw out an error. Then I change the ‘map(str, other_request.args)’ to 'list(map(str, other_request.args))'. This make the LOAD() works fine. 


Discussion:
In addition, I can see that the map() function is used many times in the compileapp.py. Maybe, all the map function should be wrap with list()?
No no, don't do **list(map**, that's terrible looking and not that good for performance, just use a list comprehension instead of map.  

Resolving patch:
diff --git a/gluon/compileapp.py b/gluon/compileapp.py
--- a/gluon/compileapp.py
+++ b/gluon/compileapp.py
@@ -205,7 +205,7 @@ def LOAD(c=None, f='index', args=None, vars=None,
         other_response = Response()
         other_request.env.path_info = '/' + \
             '/'.join([request.application, c, f] +
-                     map(str, other_request.args))
+                     [str(a) for a in other_request.args])
         other_request.env.query_string = \
             vars and URL(vars=vars).split('?')[1] or ''
         other_request.env.http_web2py_component_location = \
@@ -288,7 +288,7 @@ def __call__(self, c=None, f='index', args=None, vars=None,
             other_response = globals.Response()
             other_request.env.path_info = '/' + \
                 '/'.join([request.application, c, f] +
-                         map(str, other_request.args))
+                         [str(a) for a in other_request.args])
             other_request.env.query_string = \
                 vars and html.URL(vars=vars).split('?')[1] or ''
             other_request.env.http_web2py_component_location = \
@@ -678,7 +678,7 @@ def run_view_in(environment):
     layer = None
     scode = None
     if patterns:
-        regex = re_compile('|'.join(map(fnmatch.translate, patterns)))
+        regex = re_compile('|'.join(fnmatch.translate(p) for p in patterns))
         short_action = '%(controller)s/%(function)s.%(extension)s' % request
         allow_generic = regex.search(short_action)
     else:


Test patch:
Repository: web2py/web2py

Issue:
user_agent.is_mobile fails with NoneType
web2py™ | Version 2.15.4-stable+timestamp.2017.09.02.04.02.22
Python 2.7.13: /usr/bin/python (prefix: /usr)

```
Traceback (most recent call last):
  File "/home/www-data/web2py/gluon/restricted.py", line 219, in restricted
    exec(ccode, environment)
  File "/home/www-data/web2py/applications/myapp/compiled/views.strategy.index.html.py", line 32, in <module>
  File "/home/www-data/web2py/gluon/globals.py", line 340, in user_agent
    user_agent.is_mobile = 'Mobile' in http_user_agent
TypeError: argument of type 'NoneType' is not iterable
```



Discussion:

Resolving patch:
diff --git a/gluon/globals.py b/gluon/globals.py
--- a/gluon/globals.py
+++ b/gluon/globals.py
@@ -331,7 +331,7 @@ def user_agent(self):
         user_agent = session._user_agent
         if user_agent:
             return user_agent
-        http_user_agent = self.env.http_user_agent
+        http_user_agent = self.env.http_user_agent or ''
         user_agent = user_agent_parser.detect(http_user_agent)
         for key, value in user_agent.items():
             if isinstance(value, dict):


Test patch:
Repository: web2py/web2py

Issue:
Auth change_password does not enforce settings.password_min_length
In authapi.py at https://github.com/web2py/web2py/blob/c4e08eeeb34cb51d9048a0eabc07586494ac8c8c/gluon/authapi.py#L991 and in tools.py at https://github.com/web2py/web2py/blob/c4e08eeeb34cb51d9048a0eabc07586494ac8c8c/gluon/tools.py#L3696, the `change_password` code sets the `CRYPT` `min_length` attribute to `0` (so the minimum length requirement will not be enforced on the old password). However, the instance of the `CRYPT` validator that is mutated is still the same instance attached to the `db.auth_user.password` field, so the subsequent validation of the new password does not enforce any minimum length.

The code should instead create a copy of the existing `CRYPT` validator rather than mutating the existing one.


Discussion:

Resolving patch:
diff --git a/gluon/authapi.py b/gluon/authapi.py
--- a/gluon/authapi.py
+++ b/gluon/authapi.py
@@ -988,7 +988,8 @@ def change_password(self, log=DEFAULT, **kwargs):
             requires = [requires]
         requires = list(filter(lambda t: isinstance(t, CRYPT), requires))
         if requires:
-            requires[0].min_length = 0
+            requires[0] = CRYPT(**requires[0].__dict__) # Copy the existing CRYPT attributes
+            requires[0].min_length = 0 # But do not enforce minimum length for the old password
 
         old_password = kwargs.get('old_password', '')
         new_password = kwargs.get('new_password', '')
diff --git a/gluon/tools.py b/gluon/tools.py
--- a/gluon/tools.py
+++ b/gluon/tools.py
@@ -3693,7 +3693,8 @@ def change_password(self,
             requires = [requires]
         requires = list(filter(lambda t: isinstance(t, CRYPT), requires))
         if requires:
-            requires[0].min_length = 0
+            requires[0] = CRYPT(**requires[0].__dict__) # Copy the existing CRYPT attributes
+            requires[0].min_length = 0 # But do not enforce minimum length for the old password
         form = SQLFORM.factory(
             Field('old_password', 'password', requires=requires,
                   label=self.messages.old_password),


Test patch:
diff --git a/gluon/tests/test_authapi.py b/gluon/tests/test_authapi.py
--- a/gluon/tests/test_authapi.py
+++ b/gluon/tests/test_authapi.py
@@ -138,6 +138,9 @@ def test_change_password(self):
         self.assertTrue('new_password2' in result['errors'])
         result = self.auth.change_password(old_password='bart_password', new_password='1234', new_password2='1234')
         self.assertTrue('old_password' in result['errors'])
+        # Test the default 4 min_length is enforced on change password
+        result = self.auth.change_password(old_password='1234', new_password='123', new_password2='123')
+        self.assertTrue('new_password' in result['errors'])
 
     def test_verify_key(self):
         self.auth.settings.registration_requires_verification = True
Repository: web2py/web2py

Issue:
response.include_meta() bug
Hi!
I have a function in my modules

```python
    def set_open_graph(type="website", title=None, url=None, image=None, description=None, site_name=None, locale=None, locale_alternate={}):
        data = locals()
        for name in ['type', 'title', 'url', 'description', 'site_name', 'locale']:
            my_dict = {}
            if data[name]:
                my_dict['name'] = "og:" + name
                my_dict['content'] = data[name]
                current.response.meta['og_' + name] = my_dict
```

Then in my 'layout.html:

`{{response.include_meta()}}`

It produces follow code:

```html
<meta b'name'="og:description" b'content'="My content" />
<meta b'name'="og:locale" b'content'="RU" />
```

OS: Linux Mint 18.2 (Ubuntu 16.04),
Web2py 2.16.1-stable+timestamp.2017.11.14.05.54.25
(Running on Rocket 1.2.6, Python 3.5.2)  


Discussion:

Resolving patch:
diff --git a/gluon/globals.py b/gluon/globals.py
--- a/gluon/globals.py
+++ b/gluon/globals.py
@@ -459,7 +459,7 @@ def include_meta(self):
         for meta in iteritems((self.meta or {})):
             k, v = meta
             if isinstance(v, dict):
-                s += '<meta' + ''.join(' %s="%s"' % (xmlescape(key),
+                s += '<meta' + ''.join(' %s="%s"' % (to_native(xmlescape(key)),
                                                      to_native(xmlescape(v[key]))) for key in v) + ' />\n'
             else:
                 s += '<meta name="%s" content="%s" />\n' % (k, to_native(xmlescape(v)))


Test patch:
diff --git a/gluon/tests/test_globals.py b/gluon/tests/test_globals.py
--- a/gluon/tests/test_globals.py
+++ b/gluon/tests/test_globals.py
@@ -230,3 +230,14 @@ def test_cookies_httponly(self):
         current.session._fixup_before_save()
         cookie = str(current.response.cookies)
         self.assertTrue('httponly' not in cookie.lower())
+
+    def test_include_meta(self):
+        response = Response()
+        response.meta[u'web2py'] = 'web2py'
+        response.include_meta()
+        self.assertEqual(response.body.getvalue(), '\n<meta name="web2py" content="web2py" />\n')
+        response = Response()
+        response.meta[u'meta_dict'] = {u'tag_name':'tag_value'}
+        response.include_meta()
+        self.assertEqual(response.body.getvalue(), '\n<meta tag_name="tag_value" />\n')
+
Repository: web2py/web2py

Issue:
Problem with web2py compilation
Hi there

Very simple to show this issue:

1. download latest version of web2py (I use Mac OS version for Normal users)
2. From Admin interface compile and pack the 'Welcome' application that comes as standard with web2py
3. Then from the Admin interface upload and install the compiled 'Welcome' application you have just created (calling a different name of course)
4. When you try to run this compiled application you will get an error e.g. Invalid function or similar

Kind Regards



Discussion:
I am trying to use web2py on python3 and when compiling my modules I am always getting an error:
NameError("name 'reload' is not defined",)

If I execute module files on command line I get no errors:
python3 mymodule.py
(blank, no errors)

I noticed the file gluon/appcompile.py has a "reload(module)" in line 351. The "reload" works on python2, but does not work on python3. Am I wrong?

Resolving patch:
diff --git a/gluon/utf8.py b/gluon/utf8.py
--- a/gluon/utf8.py
+++ b/gluon/utf8.py
@@ -11,7 +11,7 @@
 ----------------------------------------------
 """
 from __future__ import print_function
-from gluon._compat import builtin as __builtin__, unicodeT, iteritems, to_unicode, to_native
+from gluon._compat import builtin as __builtin__, unicodeT, iteritems, to_unicode, to_native, reload
 
 __all__ = ['Utf8']
 


Test patch:
Repository: web2py/web2py

Issue:
contrib/pg8000 is old and causes weird postgres errors
Please update the contrib/pg8000 driver to the current version.
Otherwise errors like Broken Pipe, Operationalerror,.. occur,
- at least for postgres 9.6,
- especially for long running task (ie. scheduler, where they are not properly handled (scheduler workers will restart and earlier run rmains as RUNNING).

related links:
https://github.com/mfenniak/pg8000/issues/73
https://groups.google.com/forum/#!topic/web2py/HAeJevtGtdU

..in copy into issues: web2py/web2py, web2py/pydal



Discussion:

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -63,7 +63,6 @@ def start():
                     'gluon/contrib/pymysql',
                     'gluon/contrib/pyrtf',
                     'gluon/contrib/pysimplesoap',
-                    'gluon/contrib/pg8000',
                     'gluon/contrib/plural_rules',
                     'gluon/contrib/minify',
                     'gluon/contrib/pyaes',


Test patch:
diff --git a/gluon/tests/test_dal.py b/gluon/tests/test_dal.py
--- a/gluon/tests/test_dal.py
+++ b/gluon/tests/test_dal.py
@@ -107,11 +107,3 @@ def test_mysql(self):
             os.environ["DB"] = "mysql://root:@localhost/pydal"
             result = self._run_tests()
             self.assertTrue(result)
-
-    def test_pg8000(self):
-        if os.environ.get('APPVEYOR'):
-            return
-        if os.environ.get('TRAVIS'):
-            os.environ["DB"] = "postgres:pg8000://postgres:@localhost/pydal"
-            result = self._run_tests()
-            self.assertTrue(result)
Repository: web2py/web2py

Issue:
Streamer.py handles IOError exception in non-python3 compatible way
Under python 3 and the latest repository, browsing to `http://127.0.0.1:8000/welcome/favicon.ico` causes `streamer.py` to crash because it treats the `IOError` exception in a non-python3 compatible way. The IOError exception occurs because `favicon.ico` is not found at `/ `. No error ticket is generated.

    except IOError as e:
        if e[0] == errno.EISDIR:
            raise HTTP(403, error_message, web2py_error='file is a directory')
        elif e[0] == errno.EACCES:
            raise HTTP(403, error_message, web2py_error='inaccessible file')
        else:
            raise HTTP(404, error_message, web2py_error='invalid file')

This works in python 2, but `e[0]` should be accesed as `e.errno` under python 3

Partial stack trace:

    Traceback (most recent call last):
      File "C:\web2py\gluon\main.py", line 329, in wsgibase
        response.stream(static_file, request=request)
      File "C:\web2py\gluon\globals.py", line 617, in stream
        status=self.status)
      File "C:\web2py\gluon\streamer.py", line 66, in stream_file_or_304_or_206
        if e[0] == errno.EISDIR:
    TypeError: 'FileNotFoundError' object is not subscriptable



Discussion:

Resolving patch:
diff --git a/gluon/streamer.py b/gluon/streamer.py
--- a/gluon/streamer.py
+++ b/gluon/streamer.py
@@ -63,9 +63,9 @@ def stream_file_or_304_or_206(
             open_f = open
         fp = open_f(static_file,'rb')
     except IOError as e:
-        if e[0] == errno.EISDIR:
+        if e.errno == errno.EISDIR:
             raise HTTP(403, error_message, web2py_error='file is a directory')
-        elif e[0] == errno.EACCES:
+        elif e.errno == errno.EACCES:
             raise HTTP(403, error_message, web2py_error='inaccessible file')
         else:
             raise HTTP(404, error_message, web2py_error='invalid file')
@@ -97,7 +97,7 @@ def stream_file_or_304_or_206(
             try:
                 stream = open(static_file, 'rb')
             except IOError as e:
-                if e[0] in (errno.EISDIR, errno.EACCES):
+                if e.errno in (errno.EISDIR, errno.EACCES):
                     raise HTTP(403)
                 else:
                     raise HTTP(404)
@@ -118,8 +118,8 @@ def stream_file_or_304_or_206(
         try:
             stream = open(static_file, 'rb')
         except IOError as e:
-            # this better does not happer when returning an error page ;-)
-            if e[0] in (errno.EISDIR, errno.EACCES):
+            # this better not happen when returning an error page ;-)
+            if e.errno in (errno.EISDIR, errno.EACCES):
                 raise HTTP(403)
             else:
                 raise HTTP(404)


Test patch:
Repository: web2py/web2py

Issue:
Can't initiate simplejsonrpc service object
When attempting to instatiate a simplejsonrpc service using Python3, the following happens:
```
>>> from gluon.contrib.simplejsonrpc import ServerProxy
>>> URL = "http://localhost:8000/app/webservice/call/jsonrpc"
>>> service = ServerProxy(URL, verbose=False)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/opt/web2py/gluon/contrib/simplejsonrpc.py", line 92, in __init__
    type, uri = urllib.splittype(uri)
AttributeError: module 'urllib' has no attribute 'splittype'
```
As far as I could see, the main problem is, among other little issues, that the function splittype has been moved to urllib.request, therefore it is not found.


Discussion:

Resolving patch:
diff --git a/gluon/contrib/simplejsonrpc.py b/gluon/contrib/simplejsonrpc.py
--- a/gluon/contrib/simplejsonrpc.py
+++ b/gluon/contrib/simplejsonrpc.py
@@ -20,11 +20,12 @@
 import sys
 PY2 = sys.version_info[0] == 2
 
-import urllib
 if PY2:
+    import urllib
     from xmlrpclib import Transport, SafeTransport
     from cStringIO import StringIO
 else:
+    import urllib.request as urllib
     from xmlrpc.client import Transport, SafeTransport
     from io import StringIO
 import random
@@ -47,7 +48,7 @@ def __init__(self):
         self.buf = StringIO()
 
     def feed(self, data):
-        self.buf.write(data)
+        self.buf.write(data.decode('utf-8'))
 
     def close(self):
         return self.buf.getvalue()
@@ -61,7 +62,7 @@ def send_content(self, connection, request_body):
         connection.putheader("Content-Length", str(len(request_body)))
         connection.endheaders()
         if request_body:
-            connection.send(request_body)
+            connection.send(str.encode(request_body))
         # todo: add gzip compression
 
     def getparser(self):


Test patch:
Repository: web2py/web2py

Issue:
wrong Definition for buttonback in ./gluon/sqlhtml.py
The icon glyphicon-arrow-left will not displayed in SQLFORM.grid if you show or edit an item.

**To Reproduce**
Steps to reproduce the behavior:
1. create a "SQLFORM.grid" form
2. Click on show or edit to show or edit an item
2. in the show or edit dialog the icon "glyphicon-arrow-left" will not displayed

**Expected behavior**
the icon should be displayed

**Screenshots**
display without the icon "glyphicon-arrow-left"
![leftarrow](https://user-images.githubusercontent.com/6215869/45928422-8632f280-bf43-11e8-9466-5135b711a908.png)

should display with the icon "glyphicon-arrow-left"
![arrowleft](https://user-images.githubusercontent.com/6215869/45928429-b1b5dd00-bf43-11e8-9440-c7dc11bab5b3.png)

**Desktop (please complete the following information):**
- on all IOs and Browsers

**Smartphone (please complete the following information):**
- on all Smartphones and all IOs and Browsers

**Additional context**
the error is probably a wrong definition in the file  ./gluon/sqlhtml.py

the line:
- buttonback='icon **leftarrow** icon-arrow-left glyphicon glyphicon-arrow-left',
should be:
- buttonback='icon **arrowleft** icon-arrow-left glyphicon glyphicon-arrow-left',



Discussion:

Resolving patch:
diff --git a/gluon/sqlhtml.py b/gluon/sqlhtml.py
--- a/gluon/sqlhtml.py
+++ b/gluon/sqlhtml.py
@@ -2315,7 +2315,7 @@ def grid(query,
                       button='button btn btn-default btn-secondary',
                       buttontext='buttontext button',
                       buttonadd='icon plus icon-plus glyphicon glyphicon-plus',
-                      buttonback='icon leftarrow icon-arrow-left glyphicon glyphicon-arrow-left',
+                      buttonback='icon arrowleft icon-arrow-left glyphicon glyphicon-arrow-left',
                       buttonexport='icon downarrow icon-download glyphicon glyphicon-download',
                       buttondelete='icon trash icon-trash glyphicon glyphicon-trash',
                       buttonedit='icon pen icon-pencil glyphicon glyphicon-pencil',


Test patch: