diff --git a/frappe/__init__.py b/frappe/__init__.py index 52aa734f8a..7cffb9a512 100644 --- a/frappe/__init__.py +++ b/frappe/__init__.py @@ -1590,7 +1590,7 @@ def read_file(path, raise_not_found=False): def get_attr(method_string: str) -> Any: """Get python method object from its name.""" - app_name = method_string.split(".")[0] + app_name = method_string.split(".", 1)[0] if ( not local.flags.in_uninstall and not local.flags.in_install diff --git a/frappe/auth.py b/frappe/auth.py index d1dc10817c..3321784ce2 100644 --- a/frappe/auth.py +++ b/frappe/auth.py @@ -55,7 +55,9 @@ class HTTPRequest: def set_request_ip(self): if frappe.get_request_header("X-Forwarded-For"): - frappe.local.request_ip = (frappe.get_request_header("X-Forwarded-For").split(",")[0]).strip() + frappe.local.request_ip = ( + frappe.get_request_header("X-Forwarded-For").split(",", 1)[0] + ).strip() elif frappe.get_request_header("REMOTE_ADDR"): frappe.local.request_ip = frappe.get_request_header("REMOTE_ADDR") diff --git a/frappe/commands/utils.py b/frappe/commands/utils.py index f4f2cd8744..280e656f1c 100644 --- a/frappe/commands/utils.py +++ b/frappe/commands/utils.py @@ -562,7 +562,7 @@ def _psql(): def jupyter(context): """Start an interactive jupyter notebook""" installed_packages = ( - r.split("==")[0] + r.split("==", 1)[0] for r in subprocess.check_output([sys.executable, "-m", "pip", "freeze"], encoding="utf8") ) @@ -1001,7 +1001,7 @@ def request(context, args=None, path=None): frappe.local.form_dict = frappe._dict() if args.startswith("/api/method"): - frappe.local.form_dict.cmd = args.split("?")[0].split("/")[-1] + frappe.local.form_dict.cmd = args.split("?", 1)[0].split("/")[-1] elif path: with open(os.path.join("..", path)) as f: args = json.loads(f.read()) diff --git a/frappe/core/doctype/communication/communication.py b/frappe/core/doctype/communication/communication.py index 9944961ca9..9756bc73c0 100644 --- a/frappe/core/doctype/communication/communication.py +++ b/frappe/core/doctype/communication/communication.py @@ -499,7 +499,7 @@ def parse_email(communication, email_strings): if email_string: for email in email_string.split(","): if delimiter in email: - email = email.split("@")[0] + email = email.split("@", 1)[0] email_local_parts = email.split(delimiter) if not len(email_local_parts) == 3: continue @@ -521,7 +521,7 @@ def get_email_without_link(email): try: _email = email.split("@") - email_id = _email[0].split("+")[0] + email_id = _email[0].split("+", 1)[0] email_host = _email[1] except IndexError: return email diff --git a/frappe/core/doctype/doctype/doctype.py b/frappe/core/doctype/doctype/doctype.py index a3d42ed4ec..64b6f3123d 100644 --- a/frappe/core/doctype/doctype/doctype.py +++ b/frappe/core/doctype/doctype/doctype.py @@ -885,7 +885,7 @@ def validate_series(dt, autoname=None, name=None): if not autoname and dt.get("fields", {"fieldname": "naming_series"}): dt.autoname = "naming_series:" elif dt.autoname and dt.autoname.startswith("naming_series:"): - fieldname = dt.autoname.split("naming_series:")[0] or "naming_series" + fieldname = dt.autoname.split("naming_series:", 1)[0] or "naming_series" if not dt.get("fields", {"fieldname": fieldname}): frappe.throw( _("Fieldname called {0} must exist to enable autonaming").format(frappe.bold(fieldname)), @@ -913,7 +913,7 @@ def validate_series(dt, autoname=None, name=None): and (not autoname.startswith("format:")) ): - prefix = autoname.split(".")[0] + prefix = autoname.split(".", 1)[0] doctype = frappe.qb.DocType("DocType") used_in = ( frappe.qb.from_(doctype) @@ -1348,7 +1348,7 @@ def validate_fields(meta): if meta.sort_field: sort_fields = [meta.sort_field] if "," in meta.sort_field: - sort_fields = [d.split()[0] for d in meta.sort_field.split(",")] + sort_fields = [d.split(maxsplit=1)[0] for d in meta.sort_field.split(",")] for fieldname in sort_fields: if fieldname not in (fieldname_list + list(default_fields) + list(child_table_fields)): diff --git a/frappe/core/doctype/file/utils.py b/frappe/core/doctype/file/utils.py index d99e5cff48..17a092e340 100644 --- a/frappe/core/doctype/file/utils.py +++ b/frappe/core/doctype/file/utils.py @@ -225,7 +225,7 @@ def extract_images_from_html(doc: "Document", content: str, is_private: bool = F def _save_file(match): data = match.group(1).split("data:")[1] headers, content = data.split(",") - mtype = headers.split(";")[0] + mtype = headers.split(";", 1)[0] if isinstance(content, str): content = content.encode("utf-8") @@ -237,7 +237,7 @@ def extract_images_from_html(doc: "Document", content: str, is_private: bool = F if "filename=" in headers: filename = headers.split("filename=")[-1] - filename = safe_decode(filename).split(";")[0] + filename = safe_decode(filename).split(";", 1)[0] else: filename = get_random_filename(content_type=mtype) diff --git a/frappe/core/doctype/package_import/package_import.py b/frappe/core/doctype/package_import/package_import.py index 19762eae4a..4939b357b0 100644 --- a/frappe/core/doctype/package_import/package_import.py +++ b/frappe/core/doctype/package_import/package_import.py @@ -26,7 +26,7 @@ class PackageImport(Document): attachment = attachment[0] # get package_name from file (package_name-0.0.0.tar.gz) - package_name = attachment.file_name.split(".")[0].rsplit("-", 1)[0] + package_name = attachment.file_name.split(".", 1)[0].rsplit("-", 1)[0] if not os.path.exists(frappe.get_site_path("packages")): os.makedirs(frappe.get_site_path("packages")) diff --git a/frappe/core/doctype/user_permission/test_user_permission.py b/frappe/core/doctype/user_permission/test_user_permission.py index 10dc75ba39..8742d2e040 100644 --- a/frappe/core/doctype/user_permission/test_user_permission.py +++ b/frappe/core/doctype/user_permission/test_user_permission.py @@ -277,7 +277,7 @@ def create_user(email, *roles): user = frappe.new_doc("User") user.email = email - user.first_name = email.split("@")[0] + user.first_name = email.split("@", 1)[0] if not roles: roles = ("System Manager",) diff --git a/frappe/database/mariadb/setup_db.py b/frappe/database/mariadb/setup_db.py index 67f809abf7..add7fa373f 100644 --- a/frappe/database/mariadb/setup_db.py +++ b/frappe/database/mariadb/setup_db.py @@ -19,7 +19,7 @@ def get_mariadb_version(version_string: str = ""): # MariaDB classifies their versions as Major (1st and 2nd number), and Minor (3rd number) # Example: Version 10.3.13 is Major Version = 10.3, Minor Version = 13 version_string = version_string or get_mariadb_variables().get("version") - version = version_string.split("-")[0] + version = version_string.split("-", 1)[0] return version.rsplit(".", 1) diff --git a/frappe/desk/doctype/event/event.py b/frappe/desk/doctype/event/event.py index fafd317155..6ce356fc7d 100644 --- a/frappe/desk/doctype/event/event.py +++ b/frappe/desk/doctype/event/event.py @@ -306,8 +306,8 @@ def get_events(start, end, user=None, for_reminder=False, filters=None) -> list[ ) # process recurring events - start = start.split(" ")[0] - end = end.split(" ")[0] + start = start.split(" ", 1)[0] + end = end.split(" ", 1)[0] add_events = [] remove_events = [] @@ -315,7 +315,7 @@ def get_events(start, end, user=None, for_reminder=False, filters=None) -> list[ new_event = e.copy() enddate = ( - add_days(date, int(date_diff(e.ends_on.split(" ")[0], e.starts_on.split(" ")[0]))) + add_days(date, int(date_diff(e.ends_on.split(" ", 1)[0], e.starts_on.split(" ", 1)[0]))) if (e.starts_on and e.ends_on) else date ) @@ -337,8 +337,8 @@ def get_events(start, end, user=None, for_reminder=False, filters=None) -> list[ repeat = "3000-01-01" if cstr(e.repeat_till) == "" else e.repeat_till if e.repeat_on == "Yearly": - start_year = cint(start.split("-")[0]) - end_year = cint(end.split("-")[0]) + start_year = cint(start.split("-", 1)[0]) + end_year = cint(end.split("-", 1)[0]) # creates a string with date (27) and month (07) eg: 07-27 event_start = "-".join(event_start.split("-")[1:]) @@ -357,7 +357,13 @@ def get_events(start, end, user=None, for_reminder=False, filters=None) -> list[ if e.repeat_on == "Monthly": # creates a string with date (27) and month (07) and year (2019) eg: 2019-07-27 - date = start.split("-")[0] + "-" + start.split("-")[1] + "-" + event_start.split("-")[2] + date = ( + start.split("-", maxsplit=1)[0] + + "-" + + start.split("-", maxsplit=2)[1] + + "-" + + event_start.split("-", maxsplit=3)[2] + ) # last day of month issue, start from prev month! try: diff --git a/frappe/desk/form/meta.py b/frappe/desk/form/meta.py index 90d20c8fc4..3fd1b1edf3 100644 --- a/frappe/desk/form/meta.py +++ b/frappe/desk/form/meta.py @@ -134,7 +134,7 @@ class FormMeta(Meta): for fname in os.listdir(path): if fname.endswith(".html"): with open(os.path.join(path, fname), encoding="utf-8") as f: - templates[fname.split(".")[0]] = scrub_html_template(f.read()) + templates[fname.split(".", 1)[0]] = scrub_html_template(f.read()) self.set("__templates", templates or None) @@ -249,7 +249,7 @@ class FormMeta(Meta): def load_templates(self): if not self.custom: module = load_doctype_module(self.name) - app = module.__name__.split(".")[0] + app = module.__name__.split(".", 1)[0] templates = {} if hasattr(module, "form_grid_templates"): for key, path in module.form_grid_templates.items(): diff --git a/frappe/desk/query_report.py b/frappe/desk/query_report.py index b4a51ffaf3..7abd6657e5 100644 --- a/frappe/desk/query_report.py +++ b/frappe/desk/query_report.py @@ -428,7 +428,7 @@ def add_total_row(result, columns, meta=None, is_tree=False, parent_field=None): if isinstance(columns[0], str): first_col = columns[0].split(":") if len(first_col) > 1: - first_col_fieldtype = first_col[1].split("/")[0] + first_col_fieldtype = first_col[1].split("/", 1)[0] else: first_col_fieldtype = columns[0].get("fieldtype") diff --git a/frappe/desk/reportview.py b/frappe/desk/reportview.py index 8f929311e0..d68c1d36fe 100644 --- a/frappe/desk/reportview.py +++ b/frappe/desk/reportview.py @@ -185,7 +185,7 @@ def extract_fieldname(field): fieldname = field for sep in (" as ", " AS "): if sep in fieldname: - fieldname = fieldname.split(sep)[0] + fieldname = fieldname.split(sep, 1)[0] # certain functions allowed, extract the fieldname from the function if fieldname.startswith("count(") or fieldname.startswith("sum(") or fieldname.startswith("avg("): @@ -456,13 +456,13 @@ def handle_duration_fieldtype_values(doctype, data, fields): def parse_field(field: str) -> tuple[str | None, str]: """Parse a field into parenttype and fieldname.""" - key = field.split(" as ")[0] + key = field.split(" as ", 1)[0] if key.startswith(("count(", "sum(", "avg(")): raise ValueError if "." in key: - return key.split(".")[0][4:-1], key.split(".")[1].strip("`") + return key.split(".", 1)[0][4:-1], key.split(".", 2)[1].strip("`") return None, key.strip("`") diff --git a/frappe/desk/search.py b/frappe/desk/search.py index 446f842a0b..2af9b575be 100644 --- a/frappe/desk/search.py +++ b/frappe/desk/search.py @@ -76,7 +76,7 @@ def search_widget( standard_queries = frappe.get_hooks().standard_queries or {} - if query and query.split()[0].lower() != "select": + if query and query.split(maxsplit=1)[0].lower() != "select": # by method try: is_whitelisted(frappe.get_attr(query)) diff --git a/frappe/frappeclient.py b/frappe/frappeclient.py index ec5f205197..3f7577fac6 100644 --- a/frappe/frappeclient.py +++ b/frappe/frappeclient.py @@ -288,7 +288,11 @@ class FrappeClient: if doctype != "User" and not frappe.db.exists("User", doc.get("owner")): frappe.get_doc( - {"doctype": "User", "email": doc.get("owner"), "first_name": doc.get("owner").split("@")[0]} + { + "doctype": "User", + "email": doc.get("owner"), + "first_name": doc.get("owner").split("@", 1)[0], + } ).insert() if update: diff --git a/frappe/installer.py b/frappe/installer.py index 0016be3699..9c2807d7cd 100644 --- a/frappe/installer.py +++ b/frappe/installer.py @@ -242,7 +242,7 @@ def parse_app_name(name: str) -> str: _repo = name.split(":")[1].rsplit("/", 1)[1] else: _repo = name.rsplit("/", 2)[2] - repo = _repo.split(".")[0] + repo = _repo.split(".", 1)[0] else: _, repo, _ = fetch_details_from_tag(name) return repo @@ -785,7 +785,7 @@ def is_downgrade(sql_file_path, verbose=False): for app in all_apps: app_name = app[0] - app_version = app[1].split(" ")[0] + app_version = app[1].split(" ", 1)[0] if app_name == "frappe": try: diff --git a/frappe/model/create_new.py b/frappe/model/create_new.py index 51810c3e18..f8b7a73a3b 100644 --- a/frappe/model/create_new.py +++ b/frappe/model/create_new.py @@ -115,7 +115,7 @@ def get_static_default_value(df, doctype_user_permissions, allowed_records): return df.default elif df.fieldtype == "Select" and df.options and df.options not in ("[Select]", "Loading..."): - return df.options.split("\n")[0] + return df.options.split("\n", 1)[0] def validate_value_via_user_permissions( diff --git a/frappe/model/db_query.py b/frappe/model/db_query.py index 1d156d0d1a..99b07c199d 100644 --- a/frappe/model/db_query.py +++ b/frappe/model/db_query.py @@ -435,7 +435,7 @@ class DatabaseQuery: if not ("tab" in field and "." in field) or any(x for x in sql_functions if x in field): continue - table_name = field.split(".")[0] + table_name = field.split(".", 1)[0] if table_name.lower().startswith("group_concat("): table_name = table_name[13:] @@ -897,7 +897,7 @@ class DatabaseQuery: # will covert to # `tabItem`.`idx` desc, `tabItem`.`modified` desc args.order_by = ", ".join( - f"`tab{self.doctype}`.`{f.split()[0].strip()}` {f.split()[1].strip()}" + f"`tab{self.doctype}`.`{f.split(maxsplit=1)[0].strip()}` {f.split(maxsplit=2)[1].strip()}" for f in meta.sort_field.split(",") ) else: @@ -1029,7 +1029,7 @@ def get_order_by(doctype, meta): # will covert to # `tabItem`.`idx` desc, `tabItem`.`modified` desc order_by = ", ".join( - f"`tab{doctype}`.`{f.split()[0].strip()}` {f.split()[1].strip()}" + f"`tab{doctype}`.`{f.split(maxsplit=1)[0].strip()}` {f.split(maxsplit=2)[1].strip()}" for f in meta.sort_field.split(",") ) diff --git a/frappe/model/delete_doc.py b/frappe/model/delete_doc.py index 48eaa63460..bfad833d38 100644 --- a/frappe/model/delete_doc.py +++ b/frappe/model/delete_doc.py @@ -176,7 +176,7 @@ def update_naming_series(doc): if doc.meta.autoname.startswith("naming_series:") and getattr(doc, "naming_series", None): revert_series_if_last(doc.naming_series, doc.name, doc) - elif doc.meta.autoname.split(":")[0] not in ("Prompt", "field", "hash", "autoincrement"): + elif doc.meta.autoname.split(":", 1)[0] not in ("Prompt", "field", "hash", "autoincrement"): revert_series_if_last(doc.meta.autoname, doc.name, doc) diff --git a/frappe/model/utils/rename_field.py b/frappe/model/utils/rename_field.py index 9e4fc5d84a..c17d01183b 100644 --- a/frappe/model/utils/rename_field.py +++ b/frappe/model/utils/rename_field.py @@ -27,7 +27,7 @@ def rename_field(doctype, old_fieldname, new_fieldname): frappe.db.sql( """update `tab%s` set parentfield=%s where parentfield=%s""" - % (new_field.options.split("\n")[0], "%s", "%s"), + % (new_field.options.split("\n", 1)[0], "%s", "%s"), (new_fieldname, old_fieldname), ) diff --git a/frappe/modules/import_file.py b/frappe/modules/import_file.py index 3690da0657..36e329409a 100644 --- a/frappe/modules/import_file.py +++ b/frappe/modules/import_file.py @@ -252,7 +252,7 @@ def load_code_properties(doc, path): if hasattr(doc, "get_code_fields"): dirname, filename = os.path.split(path) for key, extn in doc.get_code_fields().items(): - codefile = os.path.join(dirname, filename.split(".")[0] + "." + extn) + codefile = os.path.join(dirname, filename.split(".", 1)[0] + "." + extn) if os.path.exists(codefile): with open(codefile) as txtfile: doc.set(key, txtfile.read()) diff --git a/frappe/modules/patch_handler.py b/frappe/modules/patch_handler.py index 15144a1630..230c1547c6 100644 --- a/frappe/modules/patch_handler.py +++ b/frappe/modules/patch_handler.py @@ -152,7 +152,7 @@ def run_single(patchmodule=None, method=None, methodargs=None, force=False): return True -def execute_patch(patchmodule, method=None, methodargs=None): +def execute_patch(patchmodule: str, method=None, methodargs=None): """execute the patch""" _patch_mode(True) @@ -162,7 +162,7 @@ def execute_patch(patchmodule, method=None, methodargs=None): docstring = "" else: has_patch_file = True - patch = f"{patchmodule.split()[0]}.execute" + patch = f"{patchmodule.split(maxsplit=1)[0]}.execute" _patch = frappe.get_attr(patch) docstring = _patch.__doc__ or "" diff --git a/frappe/search/website_search.py b/frappe/search/website_search.py index 9af827aaa8..2b35b86de7 100644 --- a/frappe/search/website_search.py +++ b/frappe/search/website_search.py @@ -123,7 +123,7 @@ def get_static_pages_from_all_apps(): files_to_index = glob(path_to_index + "/**/*.html", recursive=True) files_to_index.extend(glob(path_to_index + "/**/*.md", recursive=True)) for file in files_to_index: - route = os.path.relpath(file, path_to_index).split(".")[0] + route = os.path.relpath(file, path_to_index).split(".", maxsplit=1)[0] if route.endswith("index"): route = route.rsplit("index", 1)[0] routes_to_index.append(route) diff --git a/frappe/tests/test_commands.py b/frappe/tests/test_commands.py index f8f3921440..4a10484d1d 100644 --- a/frappe/tests/test_commands.py +++ b/frappe/tests/test_commands.py @@ -330,7 +330,7 @@ class TestCommands(BaseTestCommands): # test 2: bare functionality for single site self.execute("bench --site {site} list-apps") self.assertEqual(self.returncode, 0) - list_apps = {_x.split()[0] for _x in self.stdout.split("\n")} + list_apps = {_x.split(maxsplit=1)[0] for _x in self.stdout.split("\n")} doctype = frappe.get_single("Installed Applications").installed_applications if doctype: installed_apps = {x.app_name for x in doctype} diff --git a/frappe/tests/test_patches.py b/frappe/tests/test_patches.py index f12f3a182c..99fe76ce84 100644 --- a/frappe/tests/test_patches.py +++ b/frappe/tests/test_patches.py @@ -59,7 +59,7 @@ class TestPatches(FrappeTestCase): else: if patchmodule.startswith("finally:"): patchmodule = patchmodule.split("finally:")[-1] - self.assertTrue(frappe.get_attr(patchmodule.split()[0] + ".execute")) + self.assertTrue(frappe.get_attr(patchmodule.split(maxsplit=1)[0] + ".execute")) frappe.flags.in_install = False @@ -149,7 +149,7 @@ def check_patch_files(app): patch_dir = Path(frappe.get_app_path(app)) / "patches" - app_patches = [p.split()[0] for p in patch_handler.get_patches_from_app(app)] + app_patches = [p.split(maxsplit=1)[0] for p in patch_handler.get_patches_from_app(app)] missing_patches = [] diff --git a/frappe/tests/test_search.py b/frappe/tests/test_search.py index 24bd8b8057..fdcf005da8 100644 --- a/frappe/tests/test_search.py +++ b/frappe/tests/test_search.py @@ -54,7 +54,7 @@ class TestSearch(FrappeTestCase): user.update( { "email": email, - "first_name": email.split("@")[0], + "first_name": email.split("@", 1)[0], "enabled": False, "allowed_in_mentions": True, } diff --git a/frappe/translate.py b/frappe/translate.py index 464b6e064c..5179daa545 100644 --- a/frappe/translate.py +++ b/frappe/translate.py @@ -314,7 +314,7 @@ def get_translations_from_apps(lang, apps=None): path = os.path.join(frappe.get_pymodule_path(app), "translations", lang + ".csv") translations.update(get_translation_dict_from_file(path, lang, app) or {}) if "-" in lang: - parent = lang.split("-")[0] + parent = lang.split("-", 1)[0] parent_translations = get_translations_from_apps(parent) parent_translations.update(translations) return parent_translations diff --git a/frappe/utils/__init__.py b/frappe/utils/__init__.py index 47f083b638..c715097be2 100644 --- a/frappe/utils/__init__.py +++ b/frappe/utils/__init__.py @@ -509,7 +509,7 @@ def decode_dict(d, encoding="utf-8"): @functools.lru_cache def get_site_name(hostname): - return hostname.split(":")[0] + return hostname.split(":", 1)[0] def get_disk_usage(): diff --git a/frappe/utils/backups.py b/frappe/utils/backups.py index 1035c111a5..10e7cbc1a5 100644 --- a/frappe/utils/backups.py +++ b/frappe/utils/backups.py @@ -265,7 +265,7 @@ class BackupGenerator: def backup_time(file_path): file_name = file_path.split(os.sep)[-1] - file_timestamp = file_name.split("-")[0] + file_timestamp = file_name.split("-", 1)[0] return timegm(datetime.strptime(file_timestamp, "%Y%m%d_%H%M%S").utctimetuple()) def get_latest(file_pattern): diff --git a/frappe/utils/change_log.py b/frappe/utils/change_log.py index 55534614e6..a4b56686c2 100644 --- a/frappe/utils/change_log.py +++ b/frappe/utils/change_log.py @@ -177,7 +177,7 @@ def check_for_update(): # Get local instance's current version or the app branch_version = ( - apps[app]["branch_version"].split(" ")[0] if apps[app].get("branch_version", "") else "" + apps[app]["branch_version"].split(" ", 1)[0] if apps[app].get("branch_version", "") else "" ) instance_version = Version(branch_version or apps[app].get("version")) # Compare and popup update message diff --git a/frappe/utils/data.py b/frappe/utils/data.py index 3e2d3c0959..f17a6e59d0 100644 --- a/frappe/utils/data.py +++ b/frappe/utils/data.py @@ -1191,7 +1191,7 @@ def fmt_money( if flt(amount) < 0: minus = "-" - amount = cstr(abs(flt(amount))).split(".")[0] + amount = cstr(abs(flt(amount))).split(".", 1)[0] if len(amount) > 3: parts.append(amount[-3:]) @@ -1348,7 +1348,7 @@ def is_image(filepath: str) -> bool: from mimetypes import guess_type # filepath can be https://example.com/bed.jpg?v=129 - filepath = (filepath or "").split("?")[0] + filepath = (filepath or "").split("?", 1)[0] return (guess_type(filepath)[0] or "").startswith("image/") diff --git a/frappe/utils/dateutils.py b/frappe/utils/dateutils.py index ca147744d4..217ce59ea9 100644 --- a/frappe/utils/dateutils.py +++ b/frappe/utils/dateutils.py @@ -51,7 +51,7 @@ def parse_date(date): if " " in date: # as date-timestamp, remove the time part - date = date.split(" ")[0] + date = date.split(" ", 1)[0] # why the sorting? checking should be done in a predictable order check_formats = [None] + sorted( diff --git a/frappe/utils/error.py b/frappe/utils/error.py index 32a9e97e71..432591175c 100644 --- a/frappe/utils/error.py +++ b/frappe/utils/error.py @@ -68,7 +68,7 @@ def get_snapshot(exception, context=10): s = { "pyver": "Python {version:s}: {executable:s} (prefix: {prefix:s})".format( - version=sys.version.split()[0], executable=sys.executable, prefix=sys.prefix + version=sys.version.split(maxsplit=1)[0], executable=sys.executable, prefix=sys.prefix ), "timestamp": cstr(datetime.datetime.now()), "traceback": traceback.format_exc(), diff --git a/frappe/utils/global_search.py b/frappe/utils/global_search.py index 391533edc0..5e5c1da141 100644 --- a/frappe/utils/global_search.py +++ b/frappe/utils/global_search.py @@ -307,7 +307,7 @@ def get_routes_to_index(): filepath = os.path.join(dirpath, f) route = os.path.relpath(filepath, base) - route = route.split(".")[0] + route = route.split(".", 1)[0] if route.endswith("index"): route = route.rsplit("index", 1)[0] diff --git a/frappe/website/doctype/blogger/blogger.py b/frappe/website/doctype/blogger/blogger.py index 9f348a2ea1..fc48bf2800 100644 --- a/frappe/website/doctype/blogger/blogger.py +++ b/frappe/website/doctype/blogger/blogger.py @@ -13,7 +13,7 @@ class Blogger(Document): if self.user and not frappe.db.exists("User", self.user): # for data import frappe.get_doc( - {"doctype": "User", "email": self.user, "first_name": self.user.split("@")[0]} + {"doctype": "User", "email": self.user, "first_name": self.user.split("@", 1)[0]} ).insert() def on_update(self): diff --git a/frappe/website/doctype/personal_data_download_request/test_personal_data_download_request.py b/frappe/website/doctype/personal_data_download_request/test_personal_data_download_request.py index ed054931e7..1a8bb1743f 100644 --- a/frappe/website/doctype/personal_data_download_request/test_personal_data_download_request.py +++ b/frappe/website/doctype/personal_data_download_request/test_personal_data_download_request.py @@ -61,7 +61,7 @@ def create_user_if_not_exists(email, first_name=None): "user_type": "Website User", "email": email, "send_welcome_email": 0, - "first_name": first_name or email.split("@")[0], + "first_name": first_name or email.split("@", 1)[0], "birth_date": frappe.utils.now_datetime(), } ).insert(ignore_permissions=True) diff --git a/frappe/website/doctype/web_page/web_page.py b/frappe/website/doctype/web_page/web_page.py index 2a02c28756..9a16654085 100644 --- a/frappe/website/doctype/web_page/web_page.py +++ b/frappe/website/doctype/web_page/web_page.py @@ -153,7 +153,7 @@ class WebPage(WebsiteGenerator): def check_for_redirect(self, context): if "")[0].strip() + context.main_section.split("", 1)[0].strip() ) raise frappe.Redirect diff --git a/frappe/website/doctype/web_page_view/web_page_view.py b/frappe/website/doctype/web_page_view/web_page_view.py index 31e36d3b1f..40c11782f5 100644 --- a/frappe/website/doctype/web_page_view/web_page_view.py +++ b/frappe/website/doctype/web_page_view/web_page_view.py @@ -18,7 +18,7 @@ def make_view_log(path, referrer=None, browser=None, version=None, url=None, use user_agent = request_dict.get("environ", {}).get("HTTP_USER_AGENT") if referrer: - referrer = referrer.split("?")[0] + referrer = referrer.split("?", 1)[0] is_unique = True if referrer.startswith(url):