mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-02-17 03:38:13 +00:00
simplify withas (for now)
This commit is contained in:
parent
33f49849f5
commit
f1169af582
@ -1,7 +1,12 @@
|
||||
#!/bin/bash
|
||||
# Run tests over all Python versions in branch python-3.0-3.2
|
||||
set -e
|
||||
function finish {
|
||||
cd $owd
|
||||
}
|
||||
|
||||
owd=$(pwd)
|
||||
trap finish EXIT
|
||||
|
||||
cd $(dirname ${BASH_SOURCE[0]})
|
||||
if ! source ./pyenv-3.0-3.2-versions ; then
|
||||
@ -23,4 +28,4 @@ for version in $PYVERSIONS; do
|
||||
fi
|
||||
echo === $version ===
|
||||
done
|
||||
cd $owd
|
||||
finish
|
||||
|
@ -1,7 +1,7 @@
|
||||
#/bin/bash
|
||||
owd=$(pwd)
|
||||
uncompyle6_merge_24_owd=$(pwd)
|
||||
cd $(dirname ${BASH_SOURCE[0]})
|
||||
if . ./setup-python-2.4.sh; then
|
||||
git merge python-3.0-to-3.2
|
||||
fi
|
||||
cd $owd
|
||||
cd $uncompyle6_merge_24_owd
|
||||
|
@ -1,7 +1,7 @@
|
||||
#/bin/bash
|
||||
owd=$(pwd)
|
||||
uncompyle6_merge_30_owd=$(pwd)
|
||||
cd $(dirname ${BASH_SOURCE[0]})
|
||||
if . ./setup-python-3.0.sh; then
|
||||
git merge python-3.3-to-3.5
|
||||
fi
|
||||
cd $owd
|
||||
cd $uncompyle6_merge_30_owd
|
||||
|
@ -1,7 +1,7 @@
|
||||
#/bin/bash
|
||||
owd=$(pwd)
|
||||
uncompyle6_merge_33_owd=$(pwd)
|
||||
cd $(dirname ${BASH_SOURCE[0]})
|
||||
if . ./setup-python-3.3.sh; then
|
||||
git merge master
|
||||
fi
|
||||
cd $owd
|
||||
cd $uncompyle6_merge_33_owd
|
||||
|
@ -429,6 +429,10 @@ TABLE_DIRECT = {
|
||||
"whileelsestmt2": ("%|while %c:\n%+%c%-%|else:\n%+%c%-\n\n", 1, 2, -3),
|
||||
"whileelselaststmt": ("%|while %c:\n%+%c%-%|else:\n%+%c%-", 1, 2, -2),
|
||||
|
||||
# If there are situations where we need "with ... as ()"
|
||||
# We may need to customize this in n_withasstmt
|
||||
"withasstmt": ("%|with %c as %c:\n%+%c%-", 0, 2, 3),
|
||||
|
||||
"expr_stmt": (
|
||||
"%|%p\n",
|
||||
# When a statement contains only a named_expr (:=)
|
||||
|
@ -17,23 +17,24 @@
|
||||
|
||||
from uncompyle6.semantics.consts import TABLE_DIRECT
|
||||
|
||||
|
||||
#######################
|
||||
# Python 2.5+ Changes #
|
||||
#######################
|
||||
def customize_for_version25(self, version):
|
||||
|
||||
########################
|
||||
# Import style for 2.5+
|
||||
########################
|
||||
TABLE_DIRECT.update({
|
||||
'importmultiple': ( '%|import %c%c\n', 2, 3 ),
|
||||
'import_cont' : ( ', %c', 2 ),
|
||||
# With/as is allowed as "from future" thing in 2.5
|
||||
# Note: It is safe to put the variables after "as" in parenthesis,
|
||||
# and sometimes it is needed.
|
||||
'with': ( '%|with %c:\n%+%c%-', 0, 3),
|
||||
'withasstmt': ( '%|with %c as (%c):\n%+%c%-', 0, 2, 3),
|
||||
})
|
||||
TABLE_DIRECT.update(
|
||||
{
|
||||
"importmultiple": ("%|import %c%c\n", 2, 3),
|
||||
"import_cont": (", %c", 2),
|
||||
# With/as is allowed as "from future" thing in 2.5
|
||||
# Note: It is safe to put the variables after "as" in parenthesis,
|
||||
# and sometimes it is needed.
|
||||
"with": ("%|with %c:\n%+%c%-", 0, 3),
|
||||
}
|
||||
)
|
||||
|
||||
# In 2.5+ "except" handlers and the "finally" can appear in one
|
||||
# "try" statement. So the below has the effect of combining the
|
||||
@ -41,16 +42,18 @@ def customize_for_version25(self, version):
|
||||
# FIXME: something doesn't smell right, since the semantics
|
||||
# are different. See test_fileio.py for an example that shows this.
|
||||
def tryfinallystmt(node):
|
||||
if len(node[1][0]) == 1 and node[1][0][0] == 'stmt':
|
||||
if node[1][0][0][0] == 'try_except':
|
||||
node[1][0][0][0].kind = 'tf_try_except'
|
||||
if node[1][0][0][0] == 'tryelsestmt':
|
||||
node[1][0][0][0].kind = 'tf_tryelsestmt'
|
||||
if len(node[1][0]) == 1 and node[1][0][0] == "stmt":
|
||||
if node[1][0][0][0] == "try_except":
|
||||
node[1][0][0][0].kind = "tf_try_except"
|
||||
if node[1][0][0][0] == "tryelsestmt":
|
||||
node[1][0][0][0].kind = "tf_tryelsestmt"
|
||||
self.default(node)
|
||||
|
||||
self.n_tryfinallystmt = tryfinallystmt
|
||||
|
||||
def n_import_from(node):
|
||||
if node[0].pattr > 0:
|
||||
node[2].pattr = ("." * node[0].pattr) + node[2].pattr
|
||||
self.default(node)
|
||||
|
||||
self.n_import_from = n_import_from
|
||||
|
@ -51,7 +51,6 @@ def customize_for_version3(self, version):
|
||||
"tf_tryelsestmtl3": ("%c%-%c%|else:\n%+%c", 1, 3, 5),
|
||||
"store_locals": ("%|# inspect.currentframe().f_locals = __locals__\n",),
|
||||
"with": ("%|with %c:\n%+%c%-", 0, 3),
|
||||
"withasstmt": ("%|with %c as (%c):\n%+%c%-", 0, 2, 3),
|
||||
}
|
||||
)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user