Change raise syntax to python 3 compatible style (#3497)

* python 3 compatible raise statement

* python 3 compatible raise statement

* python 3 compatible raise statement

* python 3 compatible raise statement

* python 3 compatible raise statement

* python 3 compatible raise statement

* python 3 compatible raise statement

* python 3 compatible raise statement

* python 3 compatible raise statement

* python 3 compatible raise statement

* python 3 compatible raise statement

* python 3 compatible raise statement
This commit is contained in:
tundebabzy 2017-06-19 04:37:19 +01:00 committed by Rushabh Mehta
parent d499ab619c
commit 702e52e665
15 changed files with 22 additions and 22 deletions

View file

@ -277,9 +277,9 @@ def msgprint(msg, title=None, raise_exception=0, as_table=False, indicator=None,
import inspect
if inspect.isclass(raise_exception) and issubclass(raise_exception, Exception):
raise raise_exception, encode(msg)
raise raise_exception(encode(msg))
else:
raise ValidationError, encode(msg)
raise ValidationError(encode(msg))
if flags.mute_messages:
_raise_exception()

View file

@ -376,7 +376,7 @@ def _drop_site(site, root_login='root', root_password=None, archived_sites_path=
def move(dest_dir, site):
if not os.path.isdir(dest_dir):
raise Exception, "destination is not a directory or does not exist"
raise Exception("destination is not a directory or does not exist")
frappe.init(site)
old_path = frappe.utils.get_site_path()

View file

@ -163,7 +163,7 @@ def clear_default(key=None, value=None, parent=None, name=None, parenttype=None)
clear_cache("__global")
if not conditions:
raise Exception, "[clear_default] No key specified."
raise Exception("[clear_default] No key specified.")
frappe.db.sql("""delete from tabDefaultValue where {0}""".format(" and ".join(conditions)),
tuple(values))

View file

@ -20,8 +20,8 @@ def get(name):
return docs
else:
frappe.response['403'] = 1
raise frappe.PermissionError, 'No read permission for Page %s' % \
(page.title or name)
raise frappe.PermissionError('No read permission for Page %s' %(page.title or name))
@frappe.whitelist(allow_guest=True)
def getpage():

View file

@ -20,7 +20,7 @@ def getdoc(doctype, name, user=None):
"""
if not (doctype and name):
raise Exception, 'doctype and name required!'
raise Exception('doctype and name required!')
if not name:
name = doctype
@ -34,7 +34,7 @@ def getdoc(doctype, name, user=None):
if not doc.has_permission("read"):
frappe.flags.error_message = _('Insufficient Permission for {0}').format(frappe.bold(doctype + ' ' + name))
raise frappe.PermissionError, ("read", doctype, name)
raise frappe.PermissionError(("read", doctype, name))
doc.apply_fieldlevel_read_permissions()

View file

@ -158,7 +158,7 @@ def runquery(q='', ret=0, from_export=0):
if frappe.form_dict.get('simple_query') or frappe.form_dict.get('is_simple'):
if not q: q = frappe.form_dict.get('simple_query') or frappe.form_dict.get('query')
if q.split()[0].lower() != 'select':
raise Exception, 'Query must be a SELECT'
raise Exception('Query must be a SELECT')
as_dict = cint(frappe.form_dict.get('as_dict'))
res = frappe.db.sql(q, as_dict = as_dict, as_list = not as_dict, formatted=formatted)
@ -209,7 +209,7 @@ def runquery(q='', ret=0, from_export=0):
qm = frappe.form_dict.get('query_max') or ''
if qm and qm.strip():
if qm.split()[0].lower() != 'select':
raise Exception, 'Query (Max) must be a SELECT'
raise Exception('Query (Max) must be a SELECT')
if not frappe.form_dict.get('simple_query'):
qm = add_match_conditions(qm, tl)

View file

@ -157,7 +157,7 @@ class SMTPServer:
if not getattr(self, 'server'):
err_msg = _('Email Account not setup. Please create a new Email Account from Setup > Email > Email Account')
frappe.msgprint(err_msg)
raise frappe.OutgoingEmailError, err_msg
raise frappe.OutgoingEmailError(err_msg)
try:
if self.use_tls and not self.port:
@ -169,7 +169,7 @@ class SMTPServer:
if not self._sess:
err_msg = _('Could not connect to outgoing email server')
frappe.msgprint(err_msg)
raise frappe.OutgoingEmailError, err_msg
raise frappe.OutgoingEmailError(err_msg)
if self.use_tls:
self._sess.ehlo()

View file

@ -43,7 +43,7 @@ def set_new_name(doc):
doc.name = (doc.get(fieldname) or "").strip()
if not doc.name:
frappe.throw(_("{0} is required").format(doc.meta.get_label(fieldname)))
raise Exception, 'Name is required'
raise Exception('Name is required')
if autoname.startswith("naming_series:"):
set_name_by_naming_series(doc)
elif "#" in autoname:

View file

@ -80,7 +80,7 @@ def read_doc_from_file(path):
print("bad json: {0}".format(path))
raise
else:
raise IOError, '%s missing' % path
raise IOError('%s missing' % path)
return doc

View file

@ -43,7 +43,7 @@ def export_customizations(module, doctype, sync_on_migrate=0, with_permissions=0
"""Export Custom Field and Property Setter for the current document to the app folder.
This will be synced with bench migrate"""
if not frappe.get_conf().developer_mode:
raise 'Not developer mode'
raise Exception('Not developer mode')
custom = {'custom_fields': [], 'property_setters': [], 'custom_perms': [],
'doctype': doctype, 'sync_on_migrate': 1}
@ -181,7 +181,7 @@ def load_doctype_module(doctype, module=None, prefix="", suffix=""):
if key not in doctype_python_modules:
doctype_python_modules[key] = frappe.get_module(module_name)
except ImportError:
raise ImportError, 'Module import failed for {0} ({1})'.format(doctype, module_name)
raise ImportError('Module import failed for {0} ({1})'.format(doctype, module_name))
return doctype_python_modules[key]

View file

@ -8,4 +8,4 @@ from frappe.installer import make_site_dirs
def execute():
make_site_dirs()
if frappe.local.conf.backup_path and frappe.local.conf.backup_path.startswith("public"):
raise Exception, "Backups path in conf set to public directory"
raise Exception("Backups path in conf set to public directory")

View file

@ -117,8 +117,8 @@ def json_handler(obj):
return repr(obj)
else:
raise TypeError, """Object of type %s with value of %s is not JSON serializable""" % \
(type(obj), repr(obj))
raise TypeError("""Object of type %s with value of %s is not JSON serializable""" % \
(type(obj), repr(obj)))
def as_page():
"""print web page"""

View file

@ -78,7 +78,7 @@ def go_to_module(module_name, item=None):
page = "List/" + module_name
m = find('#page-desktop [data-link="{0}"] .app-icon'.format(page))
if not m:
raise Exception, "Module {0} not found".format(module_name)
raise Exception("Module {0} not found".format(module_name))
m[0].click()
wait_for_page(page)

View file

@ -47,7 +47,7 @@ class BlogPost(WebsiteGenerator):
def get_context(self, context):
# this is for double precaution. usually it wont reach this code if not published
if not cint(self.published):
raise Exception, "This blog has not been published yet!"
raise Exception("This blog has not been published yet!")
# temp fields
context.full_name = get_fullname(self.owner)

View file

@ -436,7 +436,7 @@ def delete(web_form, name):
if frappe.session.user == owner and web_form.allow_delete:
frappe.delete_doc(web_form.doc_type, name, ignore_permissions=True)
else:
raise frappe.PermissionError, "Not Allowed"
raise frappe.PermissionError("Not Allowed")
def has_web_form_permission(doctype, name, ptype='read'):
if frappe.session.user=="Guest":