From 6c133fce26d793208f1725b04ca7c0e879f5f96c Mon Sep 17 00:00:00 2001 From: Oliver Pelz Date: Thu, 27 Jun 2024 20:26:13 +0200 Subject: [PATCH 1/3] String Comparison: Changed basestring to str. Iterator Protocol: Removed the usage of StopIteration and ensured the iterator ends without explicit raise StopIteration. Print Statement: Changed print to sys.stdout.write for the final output to avoid the trailing newline. Shebang Line: Updated to #!/usr/bin/python3 to specify Python 3 interpreter. File Handling: No need for any changes as it is compatible with both Python 2 and 3. --- minifier.py | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) mode change 100755 => 100644 minifier.py diff --git a/minifier.py b/minifier.py old mode 100755 new mode 100644 index a430d7c..4f408a9 --- a/minifier.py +++ b/minifier.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python3 import sys @@ -19,7 +19,7 @@ def is_group_opening(self): def __eq__(self, other): if isinstance(other, BashFileIterator._Delimiter): return other.character == self.character - elif isinstance(other, basestring): + elif isinstance(other, str): return other == self.character return False @@ -213,7 +213,6 @@ def close_heredoc(): self.pos += 1 assert not self.isInsideGroup(), 'Invalid syntax' - raise StopIteration def isEscaped(self): return self.pos in self._indices_of_escaped_characters @@ -350,13 +349,3 @@ def minify(src): # use stdout.write instead of print to avoid newline at the end (print with comma at the end does not work) sys.stdout.write(minify(src)) - -# important rules: -# 1. A single-quote cannot occur within single-quotes. -# 2. The input characters within the double-quoted string that are also enclosed between "$(" and the matching ')' -# shall not be affected by the double-quotes, but rather shall define that command whose output replaces the "$(...)" -# when the word is expanded. -# 3. Within the double-quoted string of characters from an enclosed "${" to the matching '}', an even number of -# unescaped double-quotes or single-quotes, if any, shall occur. A preceding character shall be used -# to escape a literal '{' or '}' -# 4. From 65e226ae635f2884ff667932667b321cc62929be Mon Sep 17 00:00:00 2001 From: Oliver Pelz Date: Thu, 27 Jun 2024 20:27:15 +0200 Subject: [PATCH 2/3] readding comment --- minifier.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/minifier.py b/minifier.py index 4f408a9..d1fb2d0 100644 --- a/minifier.py +++ b/minifier.py @@ -349,3 +349,13 @@ def minify(src): # use stdout.write instead of print to avoid newline at the end (print with comma at the end does not work) sys.stdout.write(minify(src)) + +# important rules: +# 1. A single-quote cannot occur within single-quotes. +# 2. The input characters within the double-quoted string that are also enclosed between "$(" and the matching ')' +# shall not be affected by the double-quotes, but rather shall define that command whose output replaces the "$(...)" +# when the word is expanded. +# 3. Within the double-quoted string of characters from an enclosed "${" to the matching '}', an even number of +# unescaped double-quotes or single-quotes, if any, shall occur. A preceding character shall be used +# to escape a literal '{' or '}' +# 4. From 8429b404a09f787a7b9b92b42f864ac14c1c6303 Mon Sep 17 00:00:00 2001 From: Oliver Pelz Date: Thu, 27 Jun 2024 20:29:06 +0200 Subject: [PATCH 3/3] all tests passed --- app.yaml | 2 +- run_tests.sh | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app.yaml b/app.yaml index 85293e6..6f5eab8 100644 --- a/app.yaml +++ b/app.yaml @@ -1,6 +1,6 @@ #application: bash-minifier #version: 1 -runtime: python27 +runtime: python3 api_version: 1 threadsafe: true diff --git a/run_tests.sh b/run_tests.sh index 7a08616..eec0a29 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -5,7 +5,7 @@ passed=0 failed=0 for f in t*.sh; do echo -n "$f " - python ../minifier.py $f > _tmp_$f + python3 ../minifier.py $f > _tmp_$f if [ `diff _tmp_$f minified_$f | wc -c` -ne 0 ]; then failed=$((failed+1)) echo FAILED @@ -16,4 +16,4 @@ for f in t*.sh; do rm _tmp_$f done echo PASSED $passed, FAILED $failed -popd > /dev/null \ No newline at end of file +popd > /dev/null