fix few urllib.urlencode, close #1841
This commit is contained in:
@@ -5,7 +5,7 @@ import re
|
|||||||
import gzip
|
import gzip
|
||||||
import tarfile
|
import tarfile
|
||||||
from gluon.contrib.simplejsonrpc import ServerProxy
|
from gluon.contrib.simplejsonrpc import ServerProxy
|
||||||
from gluon._compat import StringIO, ProtocolError
|
from gluon._compat import StringIO, ProtocolError, urlencode, urllib2
|
||||||
|
|
||||||
def deploy():
|
def deploy():
|
||||||
response.title = T('Deploy to pythonanywhere')
|
response.title = T('Deploy to pythonanywhere')
|
||||||
@@ -26,9 +26,8 @@ def create_account():
|
|||||||
except ProtocolError as error:
|
except ProtocolError as error:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
import urllib, urllib2
|
|
||||||
url = 'https://www.pythonanywhere.com/api/web2py/create_account'
|
url = 'https://www.pythonanywhere.com/api/web2py/create_account'
|
||||||
data = urllib.urlencode(request.vars)
|
data = urlencode(request.vars)
|
||||||
req = urllib2.Request(url, data)
|
req = urllib2.Request(url, data)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -13,12 +13,11 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import urllib
|
|
||||||
from gluon import *
|
from gluon import *
|
||||||
from gluon.tools import fetch
|
from gluon.tools import fetch
|
||||||
from gluon.storage import Storage
|
from gluon.storage import Storage
|
||||||
import json
|
import json
|
||||||
|
from gluon._compat import urlencode
|
||||||
|
|
||||||
class RPXAccount(object):
|
class RPXAccount(object):
|
||||||
|
|
||||||
@@ -83,7 +82,7 @@ class RPXAccount(object):
|
|||||||
token = request.post_vars.token or request.get_vars.token
|
token = request.post_vars.token or request.get_vars.token
|
||||||
if token:
|
if token:
|
||||||
user = Storage()
|
user = Storage()
|
||||||
data = urllib.urlencode(
|
data = urlencode(
|
||||||
dict(apiKey=self.api_key, token=token))
|
dict(apiKey=self.api_key, token=token))
|
||||||
auth_info_json = fetch(self.auth_url + '?' + data)
|
auth_info_json = fetch(self.auth_url + '?' + data)
|
||||||
auth_info = json.loads(auth_info_json)
|
auth_info = json.loads(auth_info_json)
|
||||||
|
|||||||
+3
-4
@@ -15,12 +15,11 @@ Holds:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
import urllib
|
|
||||||
import re
|
import re
|
||||||
import copy
|
import copy
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from gluon._compat import StringIO, unichr, urllib_quote, iteritems, basestring, long, unicodeT, to_native, to_unicode
|
from gluon._compat import StringIO, unichr, urllib_quote, iteritems, basestring, long, unicodeT, to_native, to_unicode, urlencode
|
||||||
from gluon.http import HTTP, redirect
|
from gluon.http import HTTP, redirect
|
||||||
from gluon.html import XmlComponent, truncate_string
|
from gluon.html import XmlComponent, truncate_string
|
||||||
from gluon.html import XML, SPAN, TAG, A, DIV, CAT, UL, LI, TEXTAREA, BR, IMG
|
from gluon.html import XML, SPAN, TAG, A, DIV, CAT, UL, LI, TEXTAREA, BR, IMG
|
||||||
@@ -3550,7 +3549,7 @@ class SQLTABLE(TABLE):
|
|||||||
if ref.find('.') >= 0:
|
if ref.find('.') >= 0:
|
||||||
tref, fref = ref.split('.')
|
tref, fref = ref.split('.')
|
||||||
if hasattr(sqlrows.db[tref], '_primarykey'):
|
if hasattr(sqlrows.db[tref], '_primarykey'):
|
||||||
href = '%s/%s?%s' % (linkto, tref, urllib.urlencode({fref: r}))
|
href = '%s/%s?%s' % (linkto, tref, urlencode({fref: r}))
|
||||||
r = A(represent(field, r, record), _href=str(href))
|
r = A(represent(field, r, record), _href=str(href))
|
||||||
elif field.represent:
|
elif field.represent:
|
||||||
if field not in repr_cache:
|
if field not in repr_cache:
|
||||||
@@ -3561,7 +3560,7 @@ class SQLTABLE(TABLE):
|
|||||||
elif linkto and hasattr(field._table, '_primarykey')\
|
elif linkto and hasattr(field._table, '_primarykey')\
|
||||||
and fieldname in field._table._primarykey:
|
and fieldname in field._table._primarykey:
|
||||||
# have to test this with multi-key tables
|
# have to test this with multi-key tables
|
||||||
key = urllib.urlencode(dict([
|
key = urlencode(dict([
|
||||||
((tablename in record
|
((tablename in record
|
||||||
and isinstance(record, Row)
|
and isinstance(record, Row)
|
||||||
and isinstance(record[tablename], Row)) and
|
and isinstance(record[tablename], Row)) and
|
||||||
|
|||||||
+4
-5
@@ -12,7 +12,7 @@ Auth, Mail, PluginManager and various utilities
|
|||||||
|
|
||||||
import base64
|
import base64
|
||||||
from functools import reduce
|
from functools import reduce
|
||||||
from gluon._compat import pickle, thread, urllib2, Cookie, StringIO
|
from gluon._compat import pickle, thread, urllib2, Cookie, StringIO, urlencode
|
||||||
from gluon._compat import configparser, MIMEBase, MIMEMultipart, MIMEText, Header
|
from gluon._compat import configparser, MIMEBase, MIMEMultipart, MIMEText, Header
|
||||||
from gluon._compat import Encoders, Charset, long, urllib_quote, iteritems
|
from gluon._compat import Encoders, Charset, long, urllib_quote, iteritems
|
||||||
from gluon._compat import to_bytes, to_native, add_charset
|
from gluon._compat import to_bytes, to_native, add_charset
|
||||||
@@ -27,7 +27,6 @@ import time
|
|||||||
import fnmatch
|
import fnmatch
|
||||||
import traceback
|
import traceback
|
||||||
import smtplib
|
import smtplib
|
||||||
import urllib
|
|
||||||
import email.utils
|
import email.utils
|
||||||
import random
|
import random
|
||||||
import hmac
|
import hmac
|
||||||
@@ -873,7 +872,7 @@ class Recaptcha(DIV):
|
|||||||
and len(recaptcha_challenge_field)):
|
and len(recaptcha_challenge_field)):
|
||||||
self.errors['captcha'] = self.error_message
|
self.errors['captcha'] = self.error_message
|
||||||
return False
|
return False
|
||||||
params = urllib.urlencode({
|
params = urlencode({
|
||||||
'privatekey': private_key,
|
'privatekey': private_key,
|
||||||
'remoteip': remoteip,
|
'remoteip': remoteip,
|
||||||
'challenge': recaptcha_challenge_field,
|
'challenge': recaptcha_challenge_field,
|
||||||
@@ -1026,7 +1025,7 @@ class Recaptcha2(DIV):
|
|||||||
if not recaptcha_response_field:
|
if not recaptcha_response_field:
|
||||||
self.errors['captcha'] = self.error_message
|
self.errors['captcha'] = self.error_message
|
||||||
return False
|
return False
|
||||||
params = urllib.urlencode({
|
params = urlencode({
|
||||||
'secret': self.private_key,
|
'secret': self.private_key,
|
||||||
'remoteip': remoteip,
|
'remoteip': remoteip,
|
||||||
'response': recaptcha_response_field,
|
'response': recaptcha_response_field,
|
||||||
@@ -4738,7 +4737,7 @@ def fetch(url, data=None, headers=None,
|
|||||||
user_agent='Mozilla/5.0'):
|
user_agent='Mozilla/5.0'):
|
||||||
headers = headers or {}
|
headers = headers or {}
|
||||||
if data is not None:
|
if data is not None:
|
||||||
data = urllib.urlencode(data)
|
data = urlencode(data)
|
||||||
if user_agent:
|
if user_agent:
|
||||||
headers['User-agent'] = user_agent
|
headers['User-agent'] = user_agent
|
||||||
headers['Cookie'] = ' '.join(
|
headers['Cookie'] = ' '.join(
|
||||||
|
|||||||
+9
-3
@@ -35,11 +35,17 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
URL_CHECK_ACCESS = 'http://127.0.0.1:8002/%(app)s/default/check_access'
|
URL_CHECK_ACCESS = 'http://127.0.0.1:8002/%(app)s/default/check_access'
|
||||||
|
PY2 = sys.version_info[0] == 2
|
||||||
|
|
||||||
def allow_access(environ,host):
|
def allow_access(environ,host):
|
||||||
|
if PY2:
|
||||||
|
import urllib2
|
||||||
|
from urllib import urlencode
|
||||||
|
else:
|
||||||
|
from urllib import request as urllib2
|
||||||
|
from urllib.parse import urlencode
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import urllib
|
|
||||||
import urllib2
|
|
||||||
import datetime
|
import datetime
|
||||||
header = '%s @ %s ' % (datetime.datetime.now(),host) + '='*20
|
header = '%s @ %s ' % (datetime.datetime.now(),host) + '='*20
|
||||||
pprint = '\n'.join('%s:%s' % item for item in environ.items())
|
pprint = '\n'.join('%s:%s' % item for item in environ.items())
|
||||||
@@ -56,7 +62,7 @@ def allow_access(environ,host):
|
|||||||
if key.startswith('HTTP_'):
|
if key.startswith('HTTP_'):
|
||||||
headers[key[5:]] = environ[key] # this passes the cookies through!
|
headers[key[5:]] = environ[key] # this passes the cookies through!
|
||||||
try:
|
try:
|
||||||
data = urllib.urlencode({'request_uri':environ['REQUEST_URI']})
|
data = urlencode({'request_uri':environ['REQUEST_URI']})
|
||||||
request = urllib2.Request(URL_CHECK_ACCESS % dict(app=app),data,headers)
|
request = urllib2.Request(URL_CHECK_ACCESS % dict(app=app),data,headers)
|
||||||
response = urllib2.urlopen(request).read().strip().lower()
|
response = urllib2.urlopen(request).read().strip().lower()
|
||||||
if response.startswith('true'): return True
|
if response.startswith('true'): return True
|
||||||
|
|||||||
Reference in New Issue
Block a user