|
16 | 16 | Python code. |
17 | 17 | """ |
18 | 18 |
|
| 19 | +import importlib.util |
19 | 20 | import marshal |
20 | 21 | import os |
21 | 22 | import re |
22 | 23 | import sys |
23 | 24 | import types |
24 | 25 | from logging import getLogger |
25 | | - |
26 | | -import six |
27 | | -from six.moves.urllib.parse import quote |
| 26 | +from urllib.parse import quote |
28 | 27 |
|
29 | 28 | from AccessControl.class_init import InitializeClass |
30 | 29 | from AccessControl.Permissions import change_proxy_roles |
|
47 | 46 | from Shared.DC.Scripts.Script import Script |
48 | 47 | from Shared.DC.Scripts.Script import defaultBindings |
49 | 48 | from zExceptions import Forbidden |
| 49 | +from zExceptions import ResourceLockedError |
50 | 50 | from ZPublisher.HTTPRequest import default_encoding |
51 | 51 |
|
52 | 52 |
|
53 | | -try: |
54 | | - from zExceptions import ResourceLockedError |
55 | | -except ImportError: |
56 | | - from webdav.Lockable import ResourceLockedError |
57 | | - |
58 | 53 | LOG = getLogger('PythonScripts') |
59 | 54 |
|
60 | 55 | # Track the Python bytecode version |
61 | | -try: |
62 | | - import importlib.util |
63 | | - Python_magic = importlib.util.MAGIC_NUMBER |
64 | | -except ImportError: # Python 2 |
65 | | - import imp |
66 | | - Python_magic = imp.get_magic() |
67 | | - del imp |
| 56 | +Python_magic = importlib.util.MAGIC_NUMBER |
68 | 57 |
|
69 | 58 | # This should only be incremented to force recompilation. |
70 | 59 | Script_magic = 4 |
@@ -103,7 +92,7 @@ def manage_addPythonScript(self, id, title='', file=None, REQUEST=None, |
103 | 92 | except Exception: |
104 | 93 | u = REQUEST['URL1'] |
105 | 94 | if submit == 'Add and Edit': |
106 | | - u = '%s/%s' % (u, quote(id)) |
| 95 | + u = f'{u}/{quote(id)}' |
107 | 96 | REQUEST.RESPONSE.redirect(u + '/manage_main') |
108 | 97 | return '' |
109 | 98 |
|
@@ -288,7 +277,7 @@ def _newfun(self, code): |
288 | 277 | safe_globals['__name__'] = 'script' |
289 | 278 |
|
290 | 279 | safe_locals = {} |
291 | | - six.exec_(code, safe_globals, safe_locals) |
| 280 | + exec(code, safe_globals, safe_locals) |
292 | 281 | func = list(safe_locals.values())[0] |
293 | 282 | self._v_ft = (func.__code__, safe_globals, func.__defaults__ or ()) |
294 | 283 | return func |
@@ -332,7 +321,7 @@ def _exec(self, bound_names, args, kw): |
332 | 321 | if ft is None: |
333 | 322 | __traceback_supplement__ = ( |
334 | 323 | PythonScriptTracebackSupplement, self) |
335 | | - raise RuntimeError('%s %s has errors.' % (self.meta_type, self.id)) |
| 324 | + raise RuntimeError(f'{self.meta_type} {self.id} has errors.') |
336 | 325 |
|
337 | 326 | function_code, safe_globals, function_argument_definitions = ft |
338 | 327 | safe_globals = safe_globals.copy() |
@@ -433,10 +422,8 @@ def write(self, text): |
433 | 422 | bindmap = self.getBindingAssignments().getAssignedNames() |
434 | 423 | bup = 0 |
435 | 424 |
|
436 | | - if six.PY3 and isinstance(text, bytes): |
| 425 | + if isinstance(text, bytes): |
437 | 426 | text = text.decode(default_encoding) |
438 | | - elif six.PY2 and not isinstance(text, bytes): |
439 | | - text = text.encode(default_encoding) |
440 | 427 |
|
441 | 428 | st = 0 |
442 | 429 | try: |
@@ -520,7 +507,7 @@ def read(self): |
520 | 507 | else: |
521 | 508 | prefix = '##' |
522 | 509 |
|
523 | | - hlines = ['%s %s "%s"' % (prefix, self.meta_type, self.id)] |
| 510 | + hlines = [f'{prefix} {self.meta_type} "{self.id}"'] |
524 | 511 | mm = sorted(self._metadata_map().items()) |
525 | 512 | for kv in mm: |
526 | 513 | hlines.append('%s=%s' % kv) |
@@ -553,7 +540,7 @@ def get_size(self): |
553 | 540 | @security.protected(view_management_screens) |
554 | 541 | def PrincipiaSearchSource(self): |
555 | 542 | """Support for searching - the document's contents are searched.""" |
556 | | - return '%s\n%s' % (self._params, self._body) |
| 543 | + return f'{self._params}\n{self._body}' |
557 | 544 |
|
558 | 545 | @security.protected(view_management_screens) |
559 | 546 | def document_src(self, REQUEST=None, RESPONSE=None): |
|
0 commit comments