Skip to content

Commit

Permalink
Fix: safe names for feature and attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
jmhorcas committed Aug 22, 2024
1 parent 0baf526 commit 8b65706
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import re
import string
from enum import Enum
from typing import Any, Optional

Expand Down Expand Up @@ -152,4 +153,8 @@ def parse_type_value(value: Any) -> str:


def safename(name: str) -> str:
return f'"{name}"' if ' ' in name else name
return f'"{name}"' if any(char in name for char in safecharacters()) else name


def safecharacters() -> str:
return string.ascii_letters + string.digits + '_'
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import string
from xml.etree import ElementTree
from xml.etree.ElementTree import Element
from xml.dom import minidom
Expand Down Expand Up @@ -139,4 +140,8 @@ def prettify(xml: str) -> bytes:


def safename(name: str) -> str:
return f'"{name}"' if ' ' in name else name
return f'"{name}"' if any(char in name for char in safecharacters()) else name


def safecharacters() -> str:
return string.ascii_letters + string.digits + '_'
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import string
from typing import Any

from flamapy.core.models.ast import Node, ASTOperation
Expand Down Expand Up @@ -106,4 +107,8 @@ def _get_ctc_info(ast_node: Node) -> dict[str, Any]:


def safename(name: str) -> str:
return f'"{name}"' if ' ' in name else name
return f'"{name}"' if any(char in name for char in safecharacters()) else name


def safecharacters() -> str:
return string.ascii_letters + string.digits + '_'
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import string
from enum import Enum
from typing import Any, Dict, List

Expand Down Expand Up @@ -126,4 +127,8 @@ def get_ctc_info(ast_node: Node) -> Dict[str, Any]:


def safename(name: str) -> str:
return f'"{name}"' if ' ' in name else name
return f'"{name}"' if any(char in name for char in safecharacters()) else name


def safecharacters() -> str:
return string.ascii_letters + string.digits + '_'
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import string

from flamapy.core.transformations import ModelToText
from flamapy.metamodels.fm_metamodel.models import (
FeatureModel,
Expand Down Expand Up @@ -83,4 +85,8 @@ def add_constraints(constraints: list[Constraint]) -> list[str]:


def safename(name: str) -> str:
return f'"{name}"' if ' ' in name else name
return f'"{name}"' if any(char in name for char in safecharacters()) else name


def safecharacters() -> str:
return string.ascii_letters + string.digits + '_'
4 changes: 2 additions & 2 deletions flamapy/metamodels/fm_metamodel/transformations/uvl_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def process_attributes(
constraint_attribute = attribute_context.constraintAttribute()

if value_attribute:
key = value_attribute.key().getText()
key = value_attribute.key().getText().replace('"', '')
if value_attribute.value():
value = self.process_value(value_attribute.value())
else:
Expand All @@ -96,7 +96,7 @@ def process_attributes(
else:
# Handle unexpected case
raise ValueError(
f"Unknown attribute type for: {attribute_context.getText()}"
f"Unknown attribute type for: {attribute_context.getText().replace('"', '')}"
)

attributes_dict[key] = value
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import re
import string

from flamapy.core.models.ast import ASTOperation
from flamapy.core.transformations import ModelToText
Expand Down Expand Up @@ -135,4 +136,8 @@ def serialize_constraint(ctc: Constraint) -> str:


def safename(name: str) -> str:
return f'"{name}"' if ' ' in name else name
return f'"{name}"' if any(char in name for char in safecharacters()) else name


def safecharacters() -> str:
return string.ascii_letters + string.digits + '_'

0 comments on commit 8b65706

Please sign in to comment.