Skip to content

Commit

Permalink
spotless
Browse files Browse the repository at this point in the history
  • Loading branch information
lshala committed Nov 27, 2024
1 parent 8eb1875 commit cdab949
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,6 @@ import jep.python.PyObject
class ExpressionHandler(frontend: PythonLanguageFrontend) :
PythonHandler<Expression, Python.AST.BaseExpr>(::ProblemExpression, frontend) {

/*
* Magic numbers (https://docs.python.org/3/library/ast.html#ast.FormattedValue): conversion is
* an integer:
* - `-1`: no formatting
* - `115`: `!s` string formatting
* - `114`: `!r` repr formatting
* - `97`: `!a` ascii formatting
*/
private val formattedValConversionNoFormatting = -1L
private val formattedValConversionString = 115L
private val formattedValConversionRepr = 114L
private val formattedValConversionASCII = 97L

override fun handleNode(node: Python.AST.BaseExpr): Expression {
return when (node) {
is Python.AST.Name -> handleName(node)
Expand Down Expand Up @@ -189,6 +176,19 @@ class ExpressionHandler(frontend: PythonLanguageFrontend) :
* We are handling the format handling, following [PEP 3101](https://peps.python.org/pep-3101).
*/
private fun handleFormattedValue(node: Python.AST.FormattedValue): Expression {
/*
Magic numbers (https://docs.python.org/3/library/ast.html#ast.FormattedValue):
conversion is an integer:
-1: no formatting
115: !s string formatting
114: !r repr formatting
97: !a ascii formatting
*/
val formattedValConversionNoFormatting = -1L
val formattedValConversionString = 115L
val formattedValConversionRepr = 114L
val formattedValConversionASCII = 97L

val formatSpec = node.format_spec?.let { handle(it) }
val valueExpression = handle(node.value)
val conversion =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (c) 2024, Fraunhofer AISEC. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* $$$$$$\ $$$$$$$\ $$$$$$\
* $$ __$$\ $$ __$$\ $$ __$$\
* $$ / \__|$$ | $$ |$$ / \__|
* $$ | $$$$$$$ |$$ |$$$$\
* $$ | $$ ____/ $$ |\_$$ |
* $$ | $$\ $$ | $$ | $$ |
* \$$$$$ |$$ | \$$$$$ |
* \______/ \__| \______/
*
*/
package de.fraunhofer.aisec.cpg.frontends.python.expressionHandler

class FormattedValueHandlerTest {}
Empty file.

0 comments on commit cdab949

Please sign in to comment.