Parcourir la source

chore: Drop dead and deprecated code

* Remove six for PY2 compatability since our dependencies are not, PY2
  is legacy.
* Removed usages of utils from future/past libraries since they are
  deprecated. This includes 'from __future__ ...' and 'from past...'
  statements.
* Removed compatibility imports for PY2, switched from six imports to
  standard library imports.
* Removed utils code blocks that handle operations depending on PY2/3
  versions.
* Removed 'from __future__ ...' lines from templates/code generators
* Used PY3 syntaxes in place of PY2 compatible blocks. eg: metaclass
version-14
Gavin D'souza il y a 4 ans
Parent
révision
e407b78506
100 fichiers modifiés avec 53 ajouts et 221 suppressions
  1. +0
    -1
      frappe/api.py
  2. +3
    -4
      frappe/app.py
  3. +1
    -5
      frappe/auth.py
  4. +0
    -2
      frappe/automation/doctype/assignment_rule/assignment_rule.py
  5. +0
    -2
      frappe/automation/doctype/assignment_rule/test_assignment_rule.py
  6. +0
    -1
      frappe/automation/doctype/assignment_rule_day/assignment_rule_day.py
  7. +0
    -1
      frappe/automation/doctype/assignment_rule_user/assignment_rule_user.py
  8. +0
    -1
      frappe/automation/doctype/auto_repeat/auto_repeat.py
  9. +0
    -2
      frappe/automation/doctype/auto_repeat/test_auto_repeat.py
  10. +0
    -1
      frappe/automation/doctype/auto_repeat_day/auto_repeat_day.py
  11. +0
    -2
      frappe/automation/doctype/milestone/milestone.py
  12. +0
    -2
      frappe/automation/doctype/milestone/test_milestone.py
  13. +0
    -2
      frappe/automation/doctype/milestone_tracker/milestone_tracker.py
  14. +0
    -2
      frappe/automation/doctype/milestone_tracker/test_milestone_tracker.py
  15. +2
    -7
      frappe/boot.py
  16. +1
    -3
      frappe/build.py
  17. +0
    -2
      frappe/cache_manager.py
  18. +1
    -1
      frappe/chat/__init__.py
  19. +0
    -2
      frappe/chat/doctype/chat_message/chat_message.py
  20. +0
    -2
      frappe/chat/doctype/chat_profile/chat_profile.py
  21. +0
    -2
      frappe/chat/doctype/chat_room/chat_room.py
  22. +0
    -2
      frappe/chat/doctype/chat_room_user/chat_room_user.py
  23. +0
    -1
      frappe/chat/doctype/chat_token/chat_token.py
  24. +0
    -2
      frappe/chat/util/__init__.py
  25. +1
    -4
      frappe/chat/util/test_util.py
  26. +0
    -2
      frappe/chat/util/util.py
  27. +1
    -1
      frappe/chat/website/__init__.py
  28. +8
    -11
      frappe/client.py
  29. +1
    -2
      frappe/commands/__init__.py
  30. +0
    -1
      frappe/commands/scheduler.py
  31. +0
    -1
      frappe/commands/translate.py
  32. +1
    -1
      frappe/commands/utils.py
  33. +0
    -3
      frappe/config/__init__.py
  34. +0
    -1
      frappe/contacts/address_and_contact.py
  35. +0
    -2
      frappe/contacts/doctype/address/test_address.py
  36. +0
    -1
      frappe/contacts/doctype/address_template/address_template.py
  37. +1
    -3
      frappe/contacts/doctype/address_template/test_address_template.py
  38. +0
    -1
      frappe/contacts/doctype/contact/contact.py
  39. +0
    -2
      frappe/contacts/doctype/contact/test_contact.py
  40. +0
    -1
      frappe/contacts/doctype/contact_email/contact_email.py
  41. +0
    -1
      frappe/contacts/doctype/contact_phone/contact_phone.py
  42. +0
    -1
      frappe/contacts/doctype/gender/gender.py
  43. +0
    -2
      frappe/contacts/doctype/gender/test_gender.py
  44. +0
    -1
      frappe/contacts/doctype/salutation/salutation.py
  45. +0
    -2
      frappe/contacts/doctype/salutation/test_salutation.py
  46. +1
    -4
      frappe/contacts/report/addresses_and_contacts/addresses_and_contacts.py
  47. +1
    -1
      frappe/contacts/report/addresses_and_contacts/test_addresses_and_contacts.py
  48. +0
    -2
      frappe/core/__init__.py
  49. +0
    -1
      frappe/core/doctype/__init__.py
  50. +0
    -2
      frappe/core/doctype/access_log/access_log.py
  51. +0
    -1
      frappe/core/doctype/activity_log/activity_log.py
  52. +1
    -3
      frappe/core/doctype/activity_log/feed.py
  53. +0
    -2
      frappe/core/doctype/activity_log/test_activity_log.py
  54. +0
    -1
      frappe/core/doctype/block_module/block_module.py
  55. +0
    -2
      frappe/core/doctype/comment/comment.py
  56. +0
    -2
      frappe/core/doctype/comment/test_comment.py
  57. +1
    -2
      frappe/core/doctype/communication/communication.py
  58. +4
    -7
      frappe/core/doctype/communication/email.py
  59. +1
    -3
      frappe/core/doctype/communication/test_communication.py
  60. +0
    -1
      frappe/core/doctype/communication_link/communication_link.py
  61. +0
    -1
      frappe/core/doctype/custom_docperm/custom_docperm.py
  62. +0
    -2
      frappe/core/doctype/custom_docperm/test_custom_docperm.py
  63. +0
    -1
      frappe/core/doctype/custom_role/custom_role.py
  64. +0
    -2
      frappe/core/doctype/custom_role/test_custom_role.py
  65. +0
    -1
      frappe/core/doctype/data_export/data_export.py
  66. +1
    -4
      frappe/core/doctype/data_export/exporter.py
  67. +0
    -1
      frappe/core/doctype/data_import/importer.py
  68. +0
    -2
      frappe/core/doctype/data_import/test_data_import.py
  69. +0
    -2
      frappe/core/doctype/data_import/test_exporter.py
  70. +0
    -2
      frappe/core/doctype/data_import/test_importer.py
  71. +2
    -6
      frappe/core/doctype/data_import_legacy/importer.py
  72. +0
    -2
      frappe/core/doctype/data_import_legacy/test_data_import_legacy.py
  73. +0
    -1
      frappe/core/doctype/defaultvalue/__init__.py
  74. +0
    -1
      frappe/core/doctype/defaultvalue/defaultvalue.py
  75. +0
    -1
      frappe/core/doctype/deleted_document/deleted_document.py
  76. +0
    -2
      frappe/core/doctype/deleted_document/test_deleted_document.py
  77. +0
    -1
      frappe/core/doctype/docfield/__init__.py
  78. +0
    -2
      frappe/core/doctype/docfield/docfield.py
  79. +0
    -1
      frappe/core/doctype/docperm/__init__.py
  80. +0
    -1
      frappe/core/doctype/docperm/docperm.py
  81. +0
    -1
      frappe/core/doctype/docshare/docshare.py
  82. +0
    -1
      frappe/core/doctype/docshare/test_docshare.py
  83. +0
    -1
      frappe/core/doctype/doctype/__init__.py
  84. +2
    -7
      frappe/core/doctype/doctype/doctype.py
  85. +0
    -2
      frappe/core/doctype/doctype/test_doctype.py
  86. +0
    -1
      frappe/core/doctype/doctype_action/doctype_action.py
  87. +0
    -1
      frappe/core/doctype/doctype_link/doctype_link.py
  88. +0
    -1
      frappe/core/doctype/document_naming_rule/document_naming_rule.py
  89. +0
    -2
      frappe/core/doctype/document_naming_rule/test_document_naming_rule.py
  90. +0
    -1
      frappe/core/doctype/document_naming_rule_condition/document_naming_rule_condition.py
  91. +0
    -2
      frappe/core/doctype/document_naming_rule_condition/test_document_naming_rule_condition.py
  92. +0
    -1
      frappe/core/doctype/domain/domain.py
  93. +0
    -2
      frappe/core/doctype/domain/test_domain.py
  94. +0
    -1
      frappe/core/doctype/domain_settings/domain_settings.py
  95. +0
    -1
      frappe/core/doctype/dynamic_link/dynamic_link.py
  96. +0
    -1
      frappe/core/doctype/error_log/error_log.py
  97. +0
    -2
      frappe/core/doctype/error_log/test_error_log.py
  98. +0
    -1
      frappe/core/doctype/error_snapshot/error_snapshot.py
  99. +0
    -2
      frappe/core/doctype/error_snapshot/test_error_snapshot.py
  100. +18
    -24
      frappe/core/doctype/file/file.py

+ 0
- 1
frappe/api.py Voir le fichier

@@ -1,6 +1,5 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# MIT License. See license.txt

import base64
import binascii
import json


+ 3
- 4
frappe/app.py Voir le fichier

@@ -1,10 +1,8 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# MIT License. See license.txt
from __future__ import unicode_literals

import os
from six import iteritems
import logging

from werkzeug.local import LocalManager
@@ -191,8 +189,9 @@ def make_form_dict(request):
frappe.throw(_("Invalid request arguments"))

try:
frappe.local.form_dict = frappe._dict({ k:v[0] if isinstance(v, (list, tuple)) else v \
for k, v in iteritems(args) })
frappe.local.form_dict = frappe._dict({
k: v[0] if isinstance(v, (list, tuple)) else v for k, v in args.items()
})
except IndexError:
frappe.local.form_dict = frappe._dict(args)



+ 1
- 5
frappe/auth.py Voir le fichier

@@ -1,9 +1,6 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# MIT License. See license.txt

from __future__ import unicode_literals
import datetime

from frappe import _
import frappe
import frappe.database
@@ -19,8 +16,7 @@ from frappe.core.doctype.activity_log.activity_log import add_authentication_log
from frappe.twofactor import (should_run_2fa, authenticate_for_2factor,
confirm_otp_token, get_cached_user_pass)
from frappe.website.utils import get_home_page

from six.moves.urllib.parse import quote
from urllib.parse import quote


class HTTPRequest:


+ 0
- 2
frappe/automation/doctype/assignment_rule/assignment_rule.py Voir le fichier

@@ -2,8 +2,6 @@
# Copyright (c) 2019, Frappe Technologies and contributors
# For license information, please see license.txt

from __future__ import unicode_literals

import frappe
from frappe.model.document import Document
from frappe.desk.form import assign_to


+ 0
- 2
frappe/automation/doctype/assignment_rule/test_assignment_rule.py Voir le fichier

@@ -1,8 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2019, Frappe Technologies and Contributors
# See license.txt
from __future__ import unicode_literals

import frappe
import unittest
from frappe.utils import random_string


+ 0
- 1
frappe/automation/doctype/assignment_rule_day/assignment_rule_day.py Voir le fichier

@@ -2,7 +2,6 @@
# Copyright (c) 2019, Frappe Technologies and contributors
# For license information, please see license.txt

from __future__ import unicode_literals
# import frappe
from frappe.model.document import Document



+ 0
- 1
frappe/automation/doctype/assignment_rule_user/assignment_rule_user.py Voir le fichier

@@ -2,7 +2,6 @@
# Copyright (c) 2019, Frappe Technologies and contributors
# For license information, please see license.txt

from __future__ import unicode_literals
# import frappe
from frappe.model.document import Document



+ 0
- 1
frappe/automation/doctype/auto_repeat/auto_repeat.py Voir le fichier

@@ -2,7 +2,6 @@
# Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors
# For license information, please see license.txt

from __future__ import unicode_literals
import frappe
from frappe import _
from datetime import timedelta


+ 0
- 2
frappe/automation/doctype/auto_repeat/test_auto_repeat.py Voir le fichier

@@ -1,8 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2018, Frappe Technologies and Contributors
# See license.txt
from __future__ import unicode_literals

import unittest

import frappe


+ 0
- 1
frappe/automation/doctype/auto_repeat_day/auto_repeat_day.py Voir le fichier

@@ -2,7 +2,6 @@
# Copyright (c) 2020, Frappe Technologies and contributors
# For license information, please see license.txt

from __future__ import unicode_literals
# import frappe
from frappe.model.document import Document



+ 0
- 2
frappe/automation/doctype/milestone/milestone.py Voir le fichier

@@ -2,8 +2,6 @@
# Copyright (c) 2019, Frappe Technologies and contributors
# For license information, please see license.txt

from __future__ import unicode_literals

import frappe
from frappe.model.document import Document



+ 0
- 2
frappe/automation/doctype/milestone/test_milestone.py Voir le fichier

@@ -1,8 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2019, Frappe Technologies and Contributors
# See license.txt
from __future__ import unicode_literals

#import frappe
import unittest



+ 0
- 2
frappe/automation/doctype/milestone_tracker/milestone_tracker.py Voir le fichier

@@ -2,8 +2,6 @@
# Copyright (c) 2019, Frappe Technologies and contributors
# For license information, please see license.txt

from __future__ import unicode_literals

import frappe
from frappe.model.document import Document
import frappe.cache_manager


+ 0
- 2
frappe/automation/doctype/milestone_tracker/test_milestone_tracker.py Voir le fichier

@@ -1,8 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2019, Frappe Technologies and Contributors
# See license.txt
from __future__ import unicode_literals

import frappe
import frappe.cache_manager
import unittest


+ 2
- 7
frappe/boot.py Voir le fichier

@@ -1,10 +1,5 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# MIT License. See license.txt

from __future__ import unicode_literals

from six import iteritems, text_type

"""
bootstrap client session
"""
@@ -75,7 +70,7 @@ def get_bootinfo():
frappe.get_attr(method)(bootinfo)

if bootinfo.lang:
bootinfo.lang = text_type(bootinfo.lang)
bootinfo.lang = str(bootinfo.lang)
bootinfo.versions = {k: v['version'] for k, v in get_versions().items()}

bootinfo.error_report_email = frappe.conf.error_report_email
@@ -220,7 +215,7 @@ def load_translations(bootinfo):
messages[name] = frappe._(name)

# only untranslated
messages = {k:v for k, v in iteritems(messages) if k!=v}
messages = {k: v for k, v in messages.items() if k!=v}

bootinfo["__messages"] = messages



+ 1
- 3
frappe/build.py Voir le fichier

@@ -1,11 +1,11 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# MIT License. See license.txt

import os
import re
import json
import shutil
import subprocess
from io import StringIO
from tempfile import mkdtemp, mktemp
from distutils.spawn import find_executable

@@ -402,8 +402,6 @@ def get_build_maps():


def pack(target, sources, no_compress, verbose):
from six import StringIO

outtype, outtxt = target.split(".")[-1], ""
jsm = JavascriptMinify()



+ 0
- 2
frappe/cache_manager.py Voir le fichier

@@ -1,8 +1,6 @@
# Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and Contributors
# MIT License. See license.txt

from __future__ import unicode_literals

import frappe, json
from frappe.model.document import Document
from frappe.desk.notifications import (delete_notification_count_for,


+ 1
- 1
frappe/chat/__init__.py Voir le fichier

@@ -1,4 +1,4 @@
from __future__ import unicode_literals
import frappe
from frappe import _



+ 0
- 2
frappe/chat/doctype/chat_message/chat_message.py Voir le fichier

@@ -1,5 +1,3 @@
from __future__ import unicode_literals

# imports - standard imports
import json



+ 0
- 2
frappe/chat/doctype/chat_profile/chat_profile.py Voir le fichier

@@ -1,5 +1,3 @@
from __future__ import unicode_literals

# imports - module imports
from frappe.model.document import Document
from frappe import _


+ 0
- 2
frappe/chat/doctype/chat_room/chat_room.py Voir le fichier

@@ -1,5 +1,3 @@
from __future__ import unicode_literals

# imports - module imports
from frappe.model.document import Document
from frappe import _


+ 0
- 2
frappe/chat/doctype/chat_room_user/chat_room_user.py Voir le fichier

@@ -1,5 +1,3 @@
from __future__ import unicode_literals

# imports - module imports
from frappe.model.document import Document
import frappe


+ 0
- 1
frappe/chat/doctype/chat_token/chat_token.py Voir le fichier

@@ -2,7 +2,6 @@
# Copyright (c) 2018, Frappe Technologies and contributors
# For license information, please see license.txt

from __future__ import unicode_literals
import frappe
from frappe.model.document import Document



+ 0
- 2
frappe/chat/util/__init__.py Voir le fichier

@@ -1,5 +1,3 @@
from __future__ import unicode_literals

# imports - module imports
from frappe.chat.util.util import (
get_user_doc,


+ 1
- 4
frappe/chat/util/test_util.py Voir le fichier

@@ -1,5 +1,3 @@
from __future__ import unicode_literals

# imports - standard imports
import unittest

@@ -9,7 +7,6 @@ from frappe.chat.util import (
safe_json_loads
)
import frappe
import six

class TestChatUtil(unittest.TestCase):
def test_safe_json_loads(self):
@@ -20,7 +17,7 @@ class TestChatUtil(unittest.TestCase):
self.assertEqual(type(number), float)

string = safe_json_loads("foobar")
self.assertEqual(type(string), six.text_type)
self.assertEqual(type(string), str)

array = safe_json_loads('[{ "foo": "bar" }]')
self.assertEqual(type(array), list)


+ 0
- 2
frappe/chat/util/util.py Voir le fichier

@@ -1,5 +1,3 @@
from __future__ import unicode_literals

# imports - standard imports
import json
from collections.abc import MutableMapping, MutableSequence, Sequence


+ 1
- 1
frappe/chat/website/__init__.py Voir le fichier

@@ -1,4 +1,4 @@
from __future__ import unicode_literals
import frappe
from frappe.chat.util import filter_dict, safe_json_loads



+ 8
- 11
frappe/client.py Voir le fichier

@@ -1,7 +1,5 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# MIT License. See license.txt

from __future__ import unicode_literals
import frappe
from frappe import _
import frappe.model
@@ -11,7 +9,6 @@ from frappe.utils import get_safe_filters
from frappe.desk.reportview import validate_args
from frappe.model.db_query import check_parent_permission

from six import iteritems, string_types, integer_types

'''
Handle RESTful requests that are mapped to the `/api/resource` route.
@@ -86,7 +83,7 @@ def get_value(doctype, fieldname, filters=None, as_dict=True, debug=False, paren
frappe.throw(_("No permission for {0}").format(doctype), frappe.PermissionError)

filters = get_safe_filters(filters)
if isinstance(filters, string_types):
if isinstance(filters, str):
filters = {"name": filters}

try:
@@ -135,7 +132,7 @@ def set_value(doctype, name, fieldname, value=None):

if not value:
values = fieldname
if isinstance(fieldname, string_types):
if isinstance(fieldname, str):
try:
values = json.loads(fieldname)
except ValueError:
@@ -161,7 +158,7 @@ def insert(doc=None):
'''Insert a document

:param doc: JSON or dict object to be inserted'''
if isinstance(doc, string_types):
if isinstance(doc, str):
doc = json.loads(doc)

if doc.get("parent") and doc.get("parenttype"):
@@ -179,7 +176,7 @@ def insert_many(docs=None):
'''Insert multiple documents

:param docs: JSON or list of dict objects to be inserted in one request'''
if isinstance(docs, string_types):
if isinstance(docs, str):
docs = json.loads(docs)

out = []
@@ -205,7 +202,7 @@ def save(doc):
'''Update (save) an existing document

:param doc: JSON or dict object with the properties of the document to be updated'''
if isinstance(doc, string_types):
if isinstance(doc, str):
doc = json.loads(doc)

doc = frappe.get_doc(doc)
@@ -228,7 +225,7 @@ def submit(doc):
'''Submit a document

:param doc: JSON or dict object to be submitted remotely'''
if isinstance(doc, string_types):
if isinstance(doc, str):
doc = json.loads(doc)

doc = frappe.get_doc(doc)
@@ -266,7 +263,7 @@ def make_width_property_setter(doc):
'''Set width Property Setter

:param doc: Property Setter document with `width` property'''
if isinstance(doc, string_types):
if isinstance(doc, str):
doc = json.loads(doc)
if doc["doctype"]=="Property Setter" and doc["property"]=="width":
frappe.get_doc(doc).insert(ignore_permissions = True)
@@ -280,7 +277,7 @@ def bulk_update(docs):
failed_docs = []
for doc in docs:
try:
ddoc = {key: val for key, val in iteritems(doc) if key not in ['doctype', 'docname']}
ddoc = {key: val for key, val in doc.items() if key not in ['doctype', 'docname']}
doctype = doc['doctype']
docname = doc['docname']
doc = frappe.get_doc(doctype, docname)


+ 1
- 2
frappe/commands/__init__.py Voir le fichier

@@ -1,7 +1,6 @@
# Copyright (c) 2015, Web Notes Technologies Pvt. Ltd. and Contributors
# MIT License. See license.txt

from __future__ import unicode_literals, absolute_import, print_function
import sys
import click
import cProfile
@@ -10,7 +9,7 @@ import frappe
import frappe.utils
import subprocess # nosec
from functools import wraps
from six import StringIO
from io import StringIO
from os import environ

click.disable_unicode_literals_warning = True


+ 0
- 1
frappe/commands/scheduler.py Voir le fichier

@@ -1,4 +1,3 @@
from __future__ import unicode_literals, absolute_import, print_function
import click
import sys
import frappe


+ 0
- 1
frappe/commands/translate.py Voir le fichier

@@ -1,4 +1,3 @@
from __future__ import unicode_literals, absolute_import, print_function
import click
from frappe.commands import pass_context, get_site
from frappe.exceptions import SiteNotSpecifiedError


+ 1
- 1
frappe/commands/utils.py Voir le fichier

@@ -222,7 +222,7 @@ def execute(context, method, args=None, kwargs=None, profile=False):

if profile:
import pstats
from six import StringIO
from io import StringIO

pr.disable()
s = StringIO()


+ 0
- 3
frappe/config/__init__.py Voir le fichier

@@ -1,6 +1,3 @@
from __future__ import unicode_literals
import json
from six import iteritems
import frappe
from frappe import _
from frappe.desk.moduleview import (get_data, get_onboard_items, config_exists, get_module_link_items_from_list)


+ 0
- 1
frappe/contacts/address_and_contact.py Voir le fichier

@@ -1,7 +1,6 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt

from __future__ import unicode_literals
import frappe

from frappe import _


+ 0
- 2
frappe/contacts/doctype/address/test_address.py Voir le fichier

@@ -1,8 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2015, Frappe Technologies and Contributors
# See license.txt
from __future__ import unicode_literals

import frappe, unittest
from frappe.contacts.doctype.address.address import get_address_display



+ 0
- 1
frappe/contacts/doctype/address_template/address_template.py Voir le fichier

@@ -2,7 +2,6 @@
# Copyright (c) 2015, Frappe Technologies and contributors
# For license information, please see license.txt

from __future__ import unicode_literals
import frappe
from frappe.model.document import Document
from frappe.utils import cint


+ 1
- 3
frappe/contacts/doctype/address_template/test_address_template.py Voir le fichier

@@ -1,8 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2015, Frappe Technologies and Contributors
# See license.txt
from __future__ import unicode_literals

import frappe, unittest

class TestAddressTemplate(unittest.TestCase):
@@ -42,4 +40,4 @@ class TestAddressTemplate(unittest.TestCase):
"doctype": "Address Template",
"country": 'Brazil',
"template": template
}).insert()
}).insert()

+ 0
- 1
frappe/contacts/doctype/contact/contact.py Voir le fichier

@@ -1,6 +1,5 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt

import frappe
from frappe.utils import cstr, has_gravatar
from frappe import _


+ 0
- 2
frappe/contacts/doctype/contact/test_contact.py Voir le fichier

@@ -1,8 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2017, Frappe Technologies and Contributors
# See license.txt
from __future__ import unicode_literals

import frappe
import unittest



+ 0
- 1
frappe/contacts/doctype/contact_email/contact_email.py Voir le fichier

@@ -2,7 +2,6 @@
# Copyright (c) 2019, Frappe Technologies and contributors
# For license information, please see license.txt

from __future__ import unicode_literals
# import frappe
from frappe.model.document import Document



+ 0
- 1
frappe/contacts/doctype/contact_phone/contact_phone.py Voir le fichier

@@ -2,7 +2,6 @@
# Copyright (c) 2019, Frappe Technologies and contributors
# For license information, please see license.txt

from __future__ import unicode_literals
# import frappe
from frappe.model.document import Document



+ 0
- 1
frappe/contacts/doctype/gender/gender.py Voir le fichier

@@ -2,7 +2,6 @@
# Copyright (c) 2017, Frappe Technologies and contributors
# For license information, please see license.txt

from __future__ import unicode_literals
from frappe.model.document import Document

class Gender(Document):


+ 0
- 2
frappe/contacts/doctype/gender/test_gender.py Voir le fichier

@@ -1,8 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2017, Frappe Technologies and Contributors
# See license.txt
from __future__ import unicode_literals

import unittest

class TestGender(unittest.TestCase):


+ 0
- 1
frappe/contacts/doctype/salutation/salutation.py Voir le fichier

@@ -2,7 +2,6 @@
# Copyright (c) 2017, Frappe Technologies and contributors
# For license information, please see license.txt

from __future__ import unicode_literals
from frappe.model.document import Document

class Salutation(Document):


+ 0
- 2
frappe/contacts/doctype/salutation/test_salutation.py Voir le fichier

@@ -1,8 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2017, Frappe Technologies and Contributors
# See license.txt
from __future__ import unicode_literals

import unittest

class TestSalutation(unittest.TestCase):


+ 1
- 4
frappe/contacts/report/addresses_and_contacts/addresses_and_contacts.py Voir le fichier

@@ -1,8 +1,5 @@
# Copyright (c) 2013, Frappe Technologies Pvt. Ltd. and contributors
# For license information, please see license.txt

from __future__ import unicode_literals
from six import iteritems
import frappe
from frappe import _

@@ -58,7 +55,7 @@ def get_reference_addresses_and_contact(reference_doctype, reference_name):
reference_details = get_reference_details(reference_doctype, "Address", reference_list, reference_details)
reference_details = get_reference_details(reference_doctype, "Contact", reference_list, reference_details)

for reference_name, details in iteritems(reference_details):
for reference_name, details in reference_details.items():
addresses = details.get("address", [])
contacts = details.get("contact", [])
if not any([addresses, contacts]):


+ 1
- 1
frappe/contacts/report/addresses_and_contacts/test_addresses_and_contacts.py Voir le fichier

@@ -1,4 +1,4 @@
from __future__ import unicode_literals
import frappe
import frappe.defaults
import unittest


+ 0
- 2
frappe/core/__init__.py Voir le fichier

@@ -1,4 +1,2 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# MIT License. See license.txt

from __future__ import unicode_literals

+ 0
- 1
frappe/core/doctype/__init__.py Voir le fichier

@@ -1,4 +1,3 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# MIT License. See license.txt

from __future__ import unicode_literals

+ 0
- 2
frappe/core/doctype/access_log/access_log.py Voir le fichier

@@ -3,8 +3,6 @@
# For license information, please see license.txt

# imports - standard imports
from __future__ import unicode_literals

# imports - module imports
import frappe
from frappe.model.document import Document


+ 0
- 1
frappe/core/doctype/activity_log/activity_log.py Voir le fichier

@@ -2,7 +2,6 @@
# Copyright (c) 2017, Frappe Technologies and contributors
# For license information, please see license.txt

from __future__ import unicode_literals
from frappe import _
from frappe.utils import get_fullname, now
from frappe.model.document import Document


+ 1
- 3
frappe/core/doctype/activity_log/feed.py Voir le fichier

@@ -1,13 +1,11 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: See license.txt

from __future__ import unicode_literals
import frappe
import frappe.permissions
from frappe.utils import get_fullname
from frappe import _
from frappe.core.doctype.activity_log.activity_log import add_authentication_log
from six import string_types

def update_feed(doc, method=None):
if frappe.flags.in_patch or frappe.flags.in_install or frappe.flags.in_import:
@@ -23,7 +21,7 @@ def update_feed(doc, method=None):
feed = doc.get_feed()

if feed:
if isinstance(feed, string_types):
if isinstance(feed, str):
feed = {"subject": feed}

feed = frappe._dict(feed)


+ 0
- 2
frappe/core/doctype/activity_log/test_activity_log.py Voir le fichier

@@ -1,8 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2015, Frappe Technologies and Contributors
# See license.txt
from __future__ import unicode_literals

import frappe
import unittest
import time


+ 0
- 1
frappe/core/doctype/block_module/block_module.py Voir le fichier

@@ -2,7 +2,6 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and contributors
# For license information, please see license.txt

from __future__ import unicode_literals
import frappe
from frappe.model.document import Document



+ 0
- 2
frappe/core/doctype/comment/comment.py Voir le fichier

@@ -1,8 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2019, Frappe Technologies and contributors
# For license information, please see license.txt

from __future__ import unicode_literals, absolute_import
import frappe
from frappe import _
import json


+ 0
- 2
frappe/core/doctype/comment/test_comment.py Voir le fichier

@@ -1,8 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2019, Frappe Technologies and Contributors
# See license.txt
from __future__ import unicode_literals

import frappe, json
import unittest



+ 1
- 2
frappe/core/doctype/communication/communication.py Voir le fichier

@@ -1,7 +1,6 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# MIT License. See license.txt

from __future__ import unicode_literals, absolute_import
from collections import Counter
import frappe
from frappe import _
@@ -13,7 +12,7 @@ from frappe.utils.bot import BotReply
from frappe.utils import parse_addr
from frappe.core.doctype.comment.comment import update_comment_in_doc
from email.utils import parseaddr
from six.moves.urllib.parse import unquote
from urllib.parse import unquote
from frappe.utils.user import is_system_user
from frappe.contacts.doctype.contact.contact import get_contact_name
from frappe.automation.doctype.assignment_rule.assignment_rule import apply as apply_assignment_rule


+ 4
- 7
frappe/core/doctype/communication/email.py Voir le fichier

@@ -1,9 +1,6 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# MIT License. See license.txt

from __future__ import unicode_literals, absolute_import
from six.moves import range
from six import string_types
import frappe
import json
from email.utils import formataddr
@@ -77,7 +74,7 @@ def make(doctype=None, name=None, content=None, subject=None, sent_or_received =

comm.save(ignore_permissions=True)

if isinstance(attachments, string_types):
if isinstance(attachments, str):
attachments = json.loads(attachments)

# if not committed, delayed task doesn't find the communication
@@ -249,11 +246,11 @@ def prepare_to_notify(doc, print_html=None, print_format=None, attachments=None)
"name":doc.reference_name, "print_format":print_format, "html":print_html})

if attachments:
if isinstance(attachments, string_types):
if isinstance(attachments, str):
attachments = json.loads(attachments)

for a in attachments:
if isinstance(a, string_types):
if isinstance(a, str):
# is it a filename?
try:
# check for both filename and file id
@@ -355,7 +352,7 @@ def add_attachments(name, attachments):
'''Add attachments to the given Communication'''
# loop through attachments
for a in attachments:
if isinstance(a, string_types):
if isinstance(a, str):
attach = frappe.db.get_value("File", {"name":a},
["file_name", "file_url", "is_private"], as_dict=1)



+ 1
- 3
frappe/core/doctype/communication/test_communication.py Voir le fichier

@@ -1,10 +1,8 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# See license.txt
from __future__ import unicode_literals

import frappe
import unittest
from six.moves.urllib.parse import quote
from urllib.parse import quote
test_records = frappe.get_test_records('Communication')




+ 0
- 1
frappe/core/doctype/communication_link/communication_link.py Voir le fichier

@@ -2,7 +2,6 @@
# Copyright (c) 2019, Frappe Technologies and contributors
# For license information, please see license.txt

from __future__ import unicode_literals
import frappe
from frappe.model.document import Document



+ 0
- 1
frappe/core/doctype/custom_docperm/custom_docperm.py Voir le fichier

@@ -2,7 +2,6 @@
# Copyright (c) 2015, Frappe Technologies and contributors
# For license information, please see license.txt

from __future__ import unicode_literals
import frappe
from frappe.model.document import Document



+ 0
- 2
frappe/core/doctype/custom_docperm/test_custom_docperm.py Voir le fichier

@@ -1,8 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2015, Frappe Technologies and Contributors
# See license.txt
from __future__ import unicode_literals

import frappe
import unittest



+ 0
- 1
frappe/core/doctype/custom_role/custom_role.py Voir le fichier

@@ -2,7 +2,6 @@
# Copyright (c) 2015, Frappe Technologies and contributors
# For license information, please see license.txt

from __future__ import unicode_literals
import frappe
from frappe.model.document import Document



+ 0
- 2
frappe/core/doctype/custom_role/test_custom_role.py Voir le fichier

@@ -1,8 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2015, Frappe Technologies and Contributors
# See license.txt
from __future__ import unicode_literals

import frappe
import unittest



+ 0
- 1
frappe/core/doctype/data_export/data_export.py Voir le fichier

@@ -2,7 +2,6 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and contributors
# For license information, please see license.txt

from __future__ import unicode_literals
from frappe.model.document import Document

class DataExport(Document):


+ 1
- 4
frappe/core/doctype/data_export/exporter.py Voir le fichier

@@ -1,8 +1,6 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# MIT License. See license.txt

from __future__ import unicode_literals

import frappe
from frappe import _
import frappe.permissions
@@ -10,7 +8,6 @@ import re, csv, os
from frappe.utils.csvutils import UnicodeWriter
from frappe.utils import cstr, formatdate, format_datetime, parse_json, cint, format_duration
from frappe.core.doctype.data_import_legacy.importer import get_data_keys
from six import string_types
from frappe.core.doctype.access_log.access_log import make_access_log

reflags = {
@@ -57,7 +54,7 @@ class DataExporter:

self.docs_to_export = {}
if self.doctype:
if isinstance(self.doctype, string_types):
if isinstance(self.doctype, str):
self.doctype = [self.doctype]

if len(self.doctype) > 1:


+ 0
- 1
frappe/core/doctype/data_import/importer.py Voir le fichier

@@ -1,7 +1,6 @@
# Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and Contributors
# MIT License. See license.txt

from __future__ import unicode_literals
import os
import io
import frappe


+ 0
- 2
frappe/core/doctype/data_import/test_data_import.py Voir le fichier

@@ -1,8 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2020, Frappe Technologies and Contributors
# See license.txt
from __future__ import unicode_literals

# import frappe
import unittest



+ 0
- 2
frappe/core/doctype/data_import/test_exporter.py Voir le fichier

@@ -1,8 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2019, Frappe Technologies and Contributors
# See license.txt
from __future__ import unicode_literals

import unittest
import frappe
from frappe.core.doctype.data_import.exporter import Exporter


+ 0
- 2
frappe/core/doctype/data_import/test_importer.py Voir le fichier

@@ -1,8 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2019, Frappe Technologies and Contributors
# See license.txt
from __future__ import unicode_literals

import unittest
import frappe
from frappe.core.doctype.data_import.importer import Importer


+ 2
- 6
frappe/core/doctype/data_import_legacy/importer.py Voir le fichier

@@ -3,9 +3,6 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# MIT License. See license.txt

from __future__ import unicode_literals, print_function

from six.moves import range
import requests
import frappe, json
import frappe.permissions
@@ -16,7 +13,6 @@ from frappe.utils.csvutils import getlink
from frappe.utils.dateutils import parse_date

from frappe.utils import cint, cstr, flt, getdate, get_datetime, get_url, get_absolute_url, duration_to_seconds
from six import string_types


@frappe.whitelist()
@@ -42,7 +38,7 @@ def upload(rows = None, submit_after_import=None, ignore_encoding_errors=False,
frappe.cache().hdel("lang", user)
frappe.set_user_lang(user)

if data_import_doc and isinstance(data_import_doc, string_types):
if data_import_doc and isinstance(data_import_doc, str):
data_import_doc = frappe.get_doc("Data Import Legacy", data_import_doc)
if data_import_doc and from_data_import == "Yes":
no_email = data_import_doc.no_email
@@ -152,7 +148,7 @@ def upload(rows = None, submit_after_import=None, ignore_encoding_errors=False,
elif fieldtype in ("Float", "Currency", "Percent"):
d[fieldname] = flt(d[fieldname])
elif fieldtype == "Date":
if d[fieldname] and isinstance(d[fieldname], string_types):
if d[fieldname] and isinstance(d[fieldname], str):
d[fieldname] = getdate(parse_date(d[fieldname]))
elif fieldtype == "Datetime":
if d[fieldname]:


+ 0
- 2
frappe/core/doctype/data_import_legacy/test_data_import_legacy.py Voir le fichier

@@ -1,8 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2020, Frappe Technologies and Contributors
# See license.txt
from __future__ import unicode_literals

# import frappe
import unittest



+ 0
- 1
frappe/core/doctype/defaultvalue/__init__.py Voir le fichier

@@ -1,4 +1,3 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# MIT License. See license.txt

from __future__ import unicode_literals

+ 0
- 1
frappe/core/doctype/defaultvalue/defaultvalue.py Voir le fichier

@@ -1,7 +1,6 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# MIT License. See license.txt

from __future__ import unicode_literals
import frappe

from frappe.model.document import Document


+ 0
- 1
frappe/core/doctype/deleted_document/deleted_document.py Voir le fichier

@@ -2,7 +2,6 @@
# Copyright (c) 2015, Frappe Technologies and contributors
# For license information, please see license.txt

from __future__ import unicode_literals
import frappe
import json
from frappe.desk.doctype.bulk_update.bulk_update import show_progress


+ 0
- 2
frappe/core/doctype/deleted_document/test_deleted_document.py Voir le fichier

@@ -1,8 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2015, Frappe Technologies and Contributors
# See license.txt
from __future__ import unicode_literals

import frappe
import unittest



+ 0
- 1
frappe/core/doctype/docfield/__init__.py Voir le fichier

@@ -1,4 +1,3 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# MIT License. See license.txt

from __future__ import unicode_literals

+ 0
- 2
frappe/core/doctype/docfield/docfield.py Voir le fichier

@@ -1,8 +1,6 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# MIT License. See license.txt

from __future__ import unicode_literals

import frappe
from frappe.model.document import Document



+ 0
- 1
frappe/core/doctype/docperm/__init__.py Voir le fichier

@@ -1,4 +1,3 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# MIT License. See license.txt

from __future__ import unicode_literals

+ 0
- 1
frappe/core/doctype/docperm/docperm.py Voir le fichier

@@ -1,7 +1,6 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# MIT License. See license.txt

from __future__ import unicode_literals
import frappe

from frappe.model.document import Document


+ 0
- 1
frappe/core/doctype/docshare/docshare.py Voir le fichier

@@ -1,7 +1,6 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and contributors
# For license information, please see license.txt

from __future__ import unicode_literals
import frappe
from frappe.model.document import Document
from frappe import _


+ 0
- 1
frappe/core/doctype/docshare/test_docshare.py Voir le fichier

@@ -1,7 +1,6 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# See license.txt

from __future__ import unicode_literals
import frappe
import frappe.share
import unittest


+ 0
- 1
frappe/core/doctype/doctype/__init__.py Voir le fichier

@@ -1,4 +1,3 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# MIT License. See license.txt

from __future__ import unicode_literals

+ 2
- 7
frappe/core/doctype/doctype/doctype.py Voir le fichier

@@ -2,15 +2,10 @@
# MIT License. See license.txt

# imports - standard imports
from __future__ import unicode_literals
import re, copy, os, shutil
import json
from frappe.cache_manager import clear_user_cache, clear_controller_cache

# imports - third party imports
import six
from six import iteritems

# imports - module imports
import frappe
import frappe.website.render
@@ -486,7 +481,7 @@ class DocType(Document):
# remove null and empty fields
def remove_null_fields(o):
to_remove = []
for attr, value in iteritems(o):
for attr, value in o.items():
if isinstance(value, list):
for v in value:
remove_null_fields(v)
@@ -670,7 +665,7 @@ class DocType(Document):
if not name:
name = self.name

flags = {"flags": re.ASCII} if six.PY3 else {}
flags = {"flags": re.ASCII}

# a DocType name should not start or end with an empty space
if re.search(r"^[ \t\n\r]+|[ \t\n\r]+$", name, **flags):


+ 0
- 2
frappe/core/doctype/doctype/test_doctype.py Voir le fichier

@@ -1,8 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# See license.txt
from __future__ import unicode_literals

import frappe
import unittest
from frappe.core.doctype.doctype.doctype import (UniqueFieldnameError,


+ 0
- 1
frappe/core/doctype/doctype_action/doctype_action.py Voir le fichier

@@ -2,7 +2,6 @@
# Copyright (c) 2019, Frappe Technologies and contributors
# For license information, please see license.txt

from __future__ import unicode_literals
# import frappe
from frappe.model.document import Document



+ 0
- 1
frappe/core/doctype/doctype_link/doctype_link.py Voir le fichier

@@ -2,7 +2,6 @@
# Copyright (c) 2019, Frappe Technologies and contributors
# For license information, please see license.txt

from __future__ import unicode_literals
# import frappe
from frappe.model.document import Document



+ 0
- 1
frappe/core/doctype/document_naming_rule/document_naming_rule.py Voir le fichier

@@ -2,7 +2,6 @@
# Copyright (c) 2020, Frappe Technologies and contributors
# For license information, please see license.txt

from __future__ import unicode_literals
import frappe
from frappe.model.document import Document
from frappe.utils.data import evaluate_filters


+ 0
- 2
frappe/core/doctype/document_naming_rule/test_document_naming_rule.py Voir le fichier

@@ -1,8 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2020, Frappe Technologies and Contributors
# See license.txt
from __future__ import unicode_literals

import frappe
import unittest



+ 0
- 1
frappe/core/doctype/document_naming_rule_condition/document_naming_rule_condition.py Voir le fichier

@@ -2,7 +2,6 @@
# Copyright (c) 2020, Frappe Technologies and contributors
# For license information, please see license.txt

from __future__ import unicode_literals
# import frappe
from frappe.model.document import Document



+ 0
- 2
frappe/core/doctype/document_naming_rule_condition/test_document_naming_rule_condition.py Voir le fichier

@@ -1,8 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2020, Frappe Technologies and Contributors
# See license.txt
from __future__ import unicode_literals

# import frappe
import unittest



+ 0
- 1
frappe/core/doctype/domain/domain.py Voir le fichier

@@ -2,7 +2,6 @@
# Copyright (c) 2017, Frappe Technologies and contributors
# For license information, please see license.txt

from __future__ import unicode_literals
import frappe

from frappe.model.document import Document


+ 0
- 2
frappe/core/doctype/domain/test_domain.py Voir le fichier

@@ -1,8 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2017, Frappe Technologies and Contributors
# See license.txt
from __future__ import unicode_literals

import frappe
import unittest



+ 0
- 1
frappe/core/doctype/domain_settings/domain_settings.py Voir le fichier

@@ -2,7 +2,6 @@
# Copyright (c) 2017, Frappe Technologies and contributors
# For license information, please see license.txt

from __future__ import unicode_literals
import frappe
from frappe.model.document import Document



+ 0
- 1
frappe/core/doctype/dynamic_link/dynamic_link.py Voir le fichier

@@ -2,7 +2,6 @@
# Copyright (c) 2015, Frappe Technologies and contributors
# For license information, please see license.txt

from __future__ import unicode_literals
import frappe
from frappe.model.document import Document



+ 0
- 1
frappe/core/doctype/error_log/error_log.py Voir le fichier

@@ -2,7 +2,6 @@
# Copyright (c) 2015, Frappe Technologies and contributors
# For license information, please see license.txt

from __future__ import unicode_literals
import frappe
from frappe.model.document import Document



+ 0
- 2
frappe/core/doctype/error_log/test_error_log.py Voir le fichier

@@ -1,8 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2015, Frappe Technologies and Contributors
# See license.txt
from __future__ import unicode_literals

import frappe
import unittest



+ 0
- 1
frappe/core/doctype/error_snapshot/error_snapshot.py Voir le fichier

@@ -2,7 +2,6 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and contributors
# For license information, please see license.txt

from __future__ import unicode_literals
import frappe
from frappe.model.document import Document



+ 0
- 2
frappe/core/doctype/error_snapshot/test_error_snapshot.py Voir le fichier

@@ -1,8 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# See license.txt
from __future__ import unicode_literals

import frappe
import unittest



+ 18
- 24
frappe/core/doctype/file/file.py Voir le fichier

@@ -7,8 +7,6 @@ record of files
naming for same name files: file.gif, file-1.gif, file-2.gif etc
"""

from __future__ import unicode_literals

import base64
import hashlib
import imghdr
@@ -23,8 +21,8 @@ import zipfile
import requests
import requests.exceptions
from PIL import Image, ImageFile, ImageOps
from six import PY2, StringIO, string_types, text_type
from six.moves.urllib.parse import quote, unquote
from io import StringIO
from urllib.parse import quote, unquote

import frappe
from frappe import _, conf
@@ -382,18 +380,14 @@ class File(Document):
file_path = self.get_full_path()

# read the file
if PY2:
with open(encode(file_path)) as f:
content = f.read()
else:
with io.open(encode(file_path), mode='rb') as f:
content = f.read()
try:
# for plain text files
content = content.decode()
except UnicodeDecodeError:
# for .png, .jpg, etc
pass
with io.open(encode(file_path), mode='rb') as f:
content = f.read()
try:
# for plain text files
content = content.decode()
except UnicodeDecodeError:
# for .png, .jpg, etc
pass

return content

@@ -430,7 +424,7 @@ class File(Document):
frappe.create_folder(file_path)
# write the file
self.content = self.get_content()
if isinstance(self.content, text_type):
if isinstance(self.content, str):
self.content = self.content.encode()
with open(os.path.join(file_path.encode('utf-8'), self.file_name.encode('utf-8')), 'wb+') as f:
f.write(self.content)
@@ -483,7 +477,7 @@ class File(Document):
self.content = content

if decode:
if isinstance(content, text_type):
if isinstance(content, str):
self.content = content.encode("utf-8")

if b"," in self.content:
@@ -632,7 +626,7 @@ def create_new_folder(file_name, folder):
@frappe.whitelist()
def move_file(file_list, new_parent, old_parent):

if isinstance(file_list, string_types):
if isinstance(file_list, str):
file_list = json.loads(file_list)

for file_obj in file_list:
@@ -834,7 +828,7 @@ def remove_file_by_url(file_url, doctype=None, name=None):


def get_content_hash(content):
if isinstance(content, text_type):
if isinstance(content, str):
content = content.encode()
return hashlib.md5(content).hexdigest() #nosec

@@ -887,8 +881,8 @@ def extract_images_from_html(doc, content):
filename = headers.split("filename=")[-1]

# decode filename
if not isinstance(filename, text_type):
filename = text_type(filename, 'utf-8')
if not isinstance(filename, str):
filename = str(filename, 'utf-8')
else:
mtype = headers.split(";")[0]
filename = get_random_filename(content_type=mtype)
@@ -911,7 +905,7 @@ def extract_images_from_html(doc, content):

return '<img src="{file_url}"'.format(file_url=file_url)

if content and isinstance(content, string_types):
if content and isinstance(content, str):
content = re.sub(r'<img[^>]*src\s*=\s*["\'](?=data:)(.*?)["\']', _save_file, content)

return content
@@ -941,7 +935,7 @@ def get_attached_images(doctype, names):
'''get list of image urls attached in form
returns {name: ['image.jpg', 'image.png']}'''

if isinstance(names, string_types):
if isinstance(names, str):
names = json.loads(names)

img_urls = frappe.db.get_list('File', filters={


Certains fichiers n'ont pas été affichés car il y a eu trop de fichiers modifiés dans ce diff

Chargement…
Annuler
Enregistrer