Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
mantid
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mantidproject
mantid
Commits
a287f60e
Commit
a287f60e
authored
4 years ago
by
Conor Finn
Browse files
Options
Downloads
Patches
Plain Diff
RE #27722 Remove py3compat init file code
parent
bda9c00a
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Framework/PythonInterface/mantid/py3compat/__init__.py
+0
-99
0 additions, 99 deletions
Framework/PythonInterface/mantid/py3compat/__init__.py
with
0 additions
and
99 deletions
Framework/PythonInterface/mantid/py3compat/__init__.py
+
0
−
99
View file @
a287f60e
...
...
@@ -6,102 +6,3 @@
# SPDX - License - Identifier: GPL - 3.0 +
# This file is part of the mantid workbench.
#
#
"""
mantid.py3compat
------------------
Transitional module providing compatibility functions intended to help
migrating from Python 2 to Python 3. Mostly just wraps six but allowing
for additional functionality of our own.
This module should be fully compatible with:
* Python >=v2.7
* Python 3
"""
import
inspect
import
six
from
six
import
*
# noqa
import
sys
# Enumerations are built in with Python 3
try
:
from
enum
import
Enum
except
ImportError
:
# use a compatability layer
from
enum
import
Enum
# noqa
# -----------------------------------------------------------------------------
# Globals and constants
# -----------------------------------------------------------------------------
__all__
=
dir
(
six
)
# -----------------------------------------------------------------------------
# Library functions
# -----------------------------------------------------------------------------
if
sys
.
version_info
[
0
:
2
]
<
(
3
,
2
):
setswitchinterval
=
sys
.
setcheckinterval
else
:
setswitchinterval
=
sys
.
setswitchinterval
if
sys
.
version_info
[
0
:
2
]
<
(
3
,
5
):
# getfullargspec deprecated up until python 3.5, so use getargspec
getfullargspec
=
inspect
.
getargspec
else
:
getfullargspec
=
inspect
.
getfullargspec
# -----------------------------------------------------------------------------
# File manipulation
# -----------------------------------------------------------------------------
csv_open_type
=
'
w
'
# -----------------------------------------------------------------------------
# Strings
# -----------------------------------------------------------------------------
if
not
hasattr
(
six
,
"
ensure_str
"
):
# Ubuntu 16.04, Windows, and OSX Mantid builds have a version of six which
# doesn't include ensure_str
# ensure_str was added in six 1.12.0
def
ensure_str
(
s
,
encoding
=
'
utf-8
'
,
errors
=
'
strict
'
):
"""
Coerce *s* to `str`.
For Python 2:
- `unicode` -> encoded to `str`
- `str` -> `str`
For Python 3:
- `str` -> `str`
- `bytes` -> decoded to `str`
"""
if
not
isinstance
(
s
,
(
text_type
,
binary_type
)):
raise
TypeError
(
"
not expecting type
'
%s
'"
%
type
(
s
))
if
isinstance
(
s
,
text_type
):
s
=
s
.
encode
(
encoding
,
errors
)
elif
isinstance
(
s
,
binary_type
):
s
=
s
.
decode
(
encoding
,
errors
)
return
s
def
is_text_string
(
obj
):
"""
Return True if `obj` is a text string, False if it is anything else,
like binary data (Python 3) or QString (Python 2, PyQt API #1)
"""
return
isinstance
(
obj
,
str
)
def
to_text_string
(
obj
,
encoding
=
None
):
"""
Convert `obj` to (unicode) text string
"""
if
encoding
is
None
:
return
str
(
obj
)
elif
isinstance
(
obj
,
str
):
# In case this function is not used properly, this could happen
return
obj
else
:
return
str
(
obj
,
encoding
)
def
qbytearray_to_str
(
qba
):
"""
Convert QByteArray object to str in a way compatible with Python 2/3
"""
return
str
(
bytes
(
qba
.
toHex
().
data
()).
decode
())
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment