python 3 fixes

This commit is contained in:
Achilles Rasquinha 2018-03-31 18:15:43 +05:30
parent d0bd66a4c2
commit 0fc518ace4
20 changed files with 25 additions and 25 deletions

View file

@ -65,7 +65,7 @@ def get_feed_match_conditions(user=None, force=True):
can_read = frappe.get_user().get_can_read()
can_read_doctypes = ['"{}"'.format(doctype) for doctype in
list(set(can_read) - set(user_permissions.keys()))]
list(set(can_read) - set(list(user_permissions)))]
if can_read_doctypes:
conditions += ["""(`tabCommunication`.reference_doctype is null

View file

@ -28,7 +28,7 @@ class DomainSettings(Document):
def restrict_roles_and_modules(self):
'''Disable all restricted roles and set `restrict_to_domain` property in Module Def'''
active_domains = frappe.get_active_domains()
all_domains = (frappe.get_hooks('domains') or {}).keys()
all_domains = list((frappe.get_hooks('domains') or {}))
def remove_role(role):
frappe.db.sql('delete from `tabHas Role` where role=%s', role)

View file

@ -719,7 +719,7 @@ class Database:
else:
# for singles
keys = to_update.keys()
keys = list(to_update)
self.sql('''
delete from tabSingles
where field in ({0}) and

View file

@ -119,7 +119,7 @@ def _get_linked_doctypes(doctype):
if not dt in ret:
ret[dt] = {"get_parent": True}
for dt in list(ret.keys()):
for dt in list(ret):
try:
doctype_module = load_doctype_module(dt)
except ImportError:

View file

@ -14,7 +14,7 @@ def get_notifications():
config = get_notification_config()
groups = list(config.get("for_doctype").keys()) + list(config.get("for_module").keys())
groups = list(config.get("for_doctype")) + list(config.get("for_module"))
cache = frappe.cache()
notification_count = {}
@ -161,8 +161,8 @@ def clear_notifications(user=None):
return
config = get_notification_config()
for_doctype = list(config.get('for_doctype').keys()) if config.get('for_doctype') else []
for_module = list(config.get('for_module').keys()) if config.get('for_module') else []
for_doctype = list(config.get('for_doctype')) if config.get('for_doctype') else []
for_module = list(config.get('for_module')) if config.get('for_module') else []
groups = for_doctype + for_module
cache = frappe.cache()
@ -194,7 +194,7 @@ def get_notification_info_for_boot():
module_doctypes = {}
doctype_info = dict(frappe.db.sql("""select name, module from tabDocType"""))
for d in list(set(can_read + list(config.for_doctype.keys()))):
for d in list(set(can_read + list(config.for_doctype))):
if d in config.for_doctype:
conditions[d] = config.for_doctype[d]

View file

@ -78,7 +78,7 @@ def compress(data, args = {}):
if not data: return data
values = []
keys = data[0].keys()
keys = list(data[0])
for row in data:
new_row = []
for key in keys:

View file

@ -81,7 +81,7 @@ class TestNewsletter(unittest.TestCase):
doc = frappe.get_doc("Newsletter", newsletter_name)
doc.get_context(context)
self.assertEqual(context.no_cache, 1)
self.assertTrue("attachments" not in context.keys())
self.assertTrue("attachments" not in list(context))
test_dependencies = ["Email Group"]

View file

@ -42,7 +42,7 @@ def delete_fields(args_dict, delete=0):
args_dict = { dt: [field names] }
"""
import frappe.utils
for dt in args_dict.keys():
for dt in list(args_dict):
fields = args_dict[dt]
if not fields: continue

View file

@ -190,7 +190,7 @@ class DbTable:
def get_column_definitions(self):
column_list = [] + default_columns
ret = []
for k in self.columns.keys():
for k in list(self.columns):
if k not in column_list:
d = self.columns[k].get_definition()
if d:

View file

@ -450,7 +450,7 @@ def get_user_permission_doctypes(user_permission_doctypes, user_permissions):
if cint(frappe.get_system_settings('ignore_user_permissions_if_missing')):
# select those user permission doctypes for which user permissions exist!
user_permission_doctypes = [
list(set(doctypes).intersection(set(user_permissions.keys())))
list(set(doctypes).intersection(set(list(user_permissions))))
for doctypes in user_permission_doctypes]
if len(user_permission_doctypes) > 1:

View file

@ -17,7 +17,7 @@ def get_context(context):
context.no_cache = 1
# all these keys exist in form_dict
if not (set(expected_keys) - set(frappe.form_dict.keys())):
if not (set(expected_keys) - set(list(frappe.form_dict))):
for key in expected_keys:
context[key] = frappe.form_dict[key]

View file

@ -17,7 +17,7 @@ def get_context(context):
context.publishable_key = get_api_key()
# all these keys exist in form_dict
if not (set(expected_keys) - set(frappe.form_dict.keys())):
if not (set(expected_keys) - set(list(frappe.form_dict))):
for key in expected_keys:
context[key] = frappe.form_dict[key]

View file

@ -178,7 +178,7 @@ def dict_to_str(args, sep='&'):
Converts a dictionary to URL
"""
t = []
for k in args.keys():
for k in list(args):
t.append(str(k)+'='+quote(str(args[k] or '')))
return sep.join(t)

View file

@ -179,7 +179,7 @@ def get_jobs(site=None, queue=None, key='method'):
def get_queue_list(queue_list=None):
'''Defines possible queues. Also wraps a given queue in a list after validating.'''
default_queue_list = queue_timeout.keys()
default_queue_list = list(queue_timeout)
if queue_list:
if isinstance(queue_list, string_types):
queue_list = [queue_list]
@ -200,7 +200,7 @@ def get_queue(queue, async=True):
def validate_queue(queue, default_queue_list=None):
if not default_queue_list:
default_queue_list = queue_timeout.keys()
default_queue_list = list(queue_timeout)
if queue not in default_queue_list:
frappe.throw(_("Queue should be one of {0}").format(', '.join(default_queue_list)))

View file

@ -77,12 +77,12 @@ def get_app_commands(app):
@click.command('get-frappe-commands')
def get_frappe_commands():
commands = list(get_app_commands('frappe').keys())
commands = list(get_app_commands('frappe'))
for app in get_apps():
app_commands = get_app_commands(app)
if app_commands:
commands.extend(app_commands.keys())
commands.extend(list(app_commands))
print(json.dumps(commands))

View file

@ -42,7 +42,7 @@ def parse_date(date):
date = date.split(" ")[0]
# why the sorting? checking should be done in a predictable order
check_formats = [None] + sorted(dateformats.keys(),
check_formats = [None] + sorted(list(dateformats),
reverse=not get_user_date_format().startswith("dd"))
for f in check_formats:

View file

@ -56,7 +56,7 @@ def get_jobs_by_queue(site=None):
consolidated_methods = {}
for method in jobs_per_queue[queue]:
if method not in consolidated_methods.keys():
if method not in list(consolidated_methods):
consolidated_methods[method] = 1
else:
consolidated_methods[method] += 1

View file

@ -14,7 +14,7 @@ def update(tz, out):
out["rules"][parts[1]] = data["rules"][parts[1]]
def get_all_timezones():
return sorted(data["zones"].keys())
return sorted(list(data["zones"]))
data = {
"zones": {

View file

@ -92,7 +92,7 @@ class RedisWrapper(redis.Redis):
except redis.exceptions.ConnectionError:
regex = re.compile(cstr(key).replace("|", "\|").replace("*", "[\w]*"))
return [k for k in frappe.local.cache.keys() if regex.match(k.decode())]
return [k for k in list(frappe.local.cache) if regex.match(k.decode())]
def delete_keys(self, key):
"""Delete keys with wildcard `*`."""

View file

@ -16,7 +16,7 @@ def get_query_key():
'''Return query string arg.'''
query_string = frappe.local.request.query_string
query = parse_qs(query_string)
if not 'k' in query.keys():
if not 'k' in list(query):
frappe.throw(_('Not Permitted'),frappe.PermissionError)
query = (query['k'][0]).strip()
if False in [i.isalpha() or i.isdigit() for i in query]: