Skip to content

Commit

Permalink
REFACTOR: Improve readability vulnerability handling (#5579)
Browse files Browse the repository at this point in the history
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Maxime Rey <[email protected]>
  • Loading branch information
3 people authored Jan 8, 2025
1 parent a457727 commit b47ea37
Show file tree
Hide file tree
Showing 10 changed files with 162 additions and 203 deletions.
4 changes: 2 additions & 2 deletions src/ansys/aedt/core/desktop.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,8 +516,8 @@ def __init__(
if getattr(self, "_initialized", None) is not None and self._initialized:
try:
self.grpc_plugin.recreate_application(True)
except Exception: # nosec
pass
except Exception:
pyaedt_logger.debug("Failed to recreate application.")
return
else:
self._initialized = True
Expand Down
12 changes: 6 additions & 6 deletions src/ansys/aedt/core/modeler/geometry_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -1535,9 +1535,8 @@ def v_angle_sign(va, vb, vn, right_handed=True):
cross = GeometryOperators.v_cross(va, vb)
if GeometryOperators.v_norm(cross) < tol:
return math.pi
assert GeometryOperators.is_collinear(cross, vn), (
"vn must be the normal to the " "plane containing va and vb."
) # pragma: no cover
if not GeometryOperators.is_collinear(cross, vn):
raise ValueError("vn must be the normal to the plane containing va and vb") # pragma: no cover

vnn = GeometryOperators.normalize_vector(vn)
if right_handed:
Expand Down Expand Up @@ -1762,10 +1761,11 @@ def is_segment_intersecting_polygon(a, b, polygon):
float
``True`` if the segment intersect the polygon. ``False`` otherwise.
"""
assert len(a) == 2, "point must be a list in the form [x, y]"
assert len(b) == 2, "point must be a list in the form [x, y]"
if len(a) != 2 or len(b) != 2:
raise ValueError("Point must be a list in the form [x, y]")
pl = len(polygon[0])
assert len(polygon[1]) == pl, "Polygon x and y lists must be the same length"
if len(polygon[1]) != pl:
raise ValueError("The two sublists in polygon must have the same length")

a_in = GeometryOperators.is_point_in_polygon(a, polygon)
b_in = GeometryOperators.is_point_in_polygon(b, polygon)
Expand Down
143 changes: 65 additions & 78 deletions src/ansys/aedt/core/modeler/modeler_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def create_3dcomponent(
is_encrypted=False,
allow_edit=False,
security_message="",
password=None,
password=None, # nosec
edit_password=None,
password_type="UserSuppliedPassword",
hide_contents=False,
Expand Down Expand Up @@ -195,8 +195,10 @@ def create_3dcomponent(
name = self._app.design_name
dt_string = datetime.datetime.now().strftime("%H:%M:%S %p %b %d, %Y")
if password_type not in ["UserSuppliedPassword", "InternalPassword"]:
self.logger.error("Password type must be 'UserSuppliedPassword' or 'InternalPassword'")
return False
if component_outline not in ["BoundingBox", "None"]:
self.logger.error("Component outline must be 'BoundingBox' or 'None'")
return False
if password is None:
password = os.getenv("PYAEDT_ENCRYPTED_PASSWORD", "")
Expand Down Expand Up @@ -262,19 +264,16 @@ def create_3dcomponent(
for el in objs:
if "CreateRegion:1" in self.oeditor.GetChildObject(el).GetChildNames():
objs.remove(el)
arg.append("IncludedParts:="), arg.append(objs)
arg.append("HiddenParts:=")
if not hide_contents_flag:
arg.append([])
else:
arg.append(hide_contents)
if coordinate_systems:
allcs = coordinate_systems
else:
allcs = self.oeditor.GetCoordinateSystems()
arg.append("IncludedCS:="), arg.append(allcs)
arg.append("ReferenceCS:="), arg.append(reference_coordinate_system)
par_description = []
arg += [
"IncludedParts:=",
objs,
"HiddenParts:=",
hide_contents if hide_contents_flag else [],
"IncludedCS:=",
coordinate_systems if coordinate_systems else list(self.oeditor.GetCoordinateSystems()),
"ReferenceCS:=",
reference_coordinate_system,
]
variables = []
dependent_variables = []
if variables_to_include is not None and not variables_to_include == []:
Expand All @@ -289,47 +288,42 @@ def create_3dcomponent(
elif variables_to_include is None:
variables = self._app._variable_manager.independent_variable_names
dependent_variables = self._app._variable_manager.dependent_variable_names
arg += [
"IncludedParameters:=",
variables,
"IncludedDependentParameters:=",
dependent_variables,
"ParameterDescription:=",
[item for el in variables for item in (el + ":=", "")],
"IsLicensed:=",
False,
"LicensingDllName:=",
"",
"VendorComponentIdentifier:=",
"",
"PublicKeyFile:=",
"",
]

for el in variables:
par_description.append(el + ":=")
par_description.append("")
arg.append("IncludedParameters:="), arg.append(variables)

arg.append("IncludedDependentParameters:="), arg.append(dependent_variables)
for el in variables:
par_description.append(el + ":=")
par_description.append("")
arg.append("ParameterDescription:="), arg.append(par_description)
arg.append("IsLicensed:="), arg.append(False)
arg.append("LicensingDllName:="), arg.append("")
arg.append("VendorComponentIdentifier:="), arg.append("")
arg.append("PublicKeyFile:="), arg.append("")
arg2 = ["NAME:DesignData"]
if boundaries is not None:
boundaries = boundaries
else:
if not boundaries:
boundaries = self.get_boundaries_name()
arg2.append("Boundaries:="), arg2.append(boundaries)
if boundaries:
arg2 += ["Boundaries:=", boundaries]
if self._app.design_type == "Icepak":
meshregions = [mr.name for mr in self._app.mesh.meshregions]
try:
meshregions.remove("Global")
except Exception:
pass
if meshregions:
arg2.append("MeshRegions:="), arg2.append(meshregions)
mesh_regions = [mr.name for mr in self._app.mesh.meshregions if mr.name != "Global"]
if mesh_regions:
arg2 += ["MeshRegions:=", mesh_regions]
else:
if excitations is not None:
excitations = excitations
else:
if excitations is None:
excitations = self._app.excitations
if self._app.design_type == "HFSS":
exc = self._app.get_oo_name(self._app.odesign, "Excitations")
if exc and exc[0] not in self._app.excitations:
excitations.extend(exc)
excitations = list(set([i.split(":")[0] for i in excitations]))
if excitations:
arg2.append("Excitations:="), arg2.append(excitations)
arg2 += ["Excitations:=", excitations]
meshops = [el.name for el in self._app.mesh.meshoperations]
if meshops:
used_mesh_ops = []
Expand All @@ -342,9 +336,9 @@ def create_3dcomponent(
mesh_comp.append(self.objects[item].name)
if all(included_obj in objs for included_obj in mesh_comp):
used_mesh_ops.append(self._app.mesh.meshoperations[mesh].name)
arg2.append("MeshOperations:="), arg2.append(used_mesh_ops)
arg2 += ["MeshOperations:=", used_mesh_ops]
else:
arg2.append("MeshOperations:="), arg2.append(meshops)
arg2 += ["MeshOperations:=", meshops]
arg3 = ["NAME:ImageFile", "ImageFile:=", ""]
if export_auxiliary:
if isinstance(export_auxiliary, bool):
Expand Down Expand Up @@ -514,13 +508,16 @@ def replace_3dcomponent(
for el in objs:
if "CreateRegion:1" in self.oeditor.GetChildObject(el).GetChildNames():
objs.remove(el)
arg.append("IncludedParts:="), arg.append(objs)
arg.append("HiddenParts:="), arg.append([])
if not coordinate_systems:
coordinate_systems = list(self.oeditor.GetCoordinateSystems())
arg.append("IncludedCS:="), arg.append(coordinate_systems)
arg.append("ReferenceCS:="), arg.append(reference_coordinate_system)
par_description = []
arg += [
"IncludedParts:=",
objs,
"HiddenParts:=",
[],
"IncludedCS:=",
coordinate_systems if coordinate_systems else list(self.oeditor.GetCoordinateSystems()),
"ReferenceCS:=",
reference_coordinate_system,
]
variables = []
if variables_to_include:
dependent_variables = []
Expand All @@ -535,34 +532,24 @@ def replace_3dcomponent(
else:
variables = self._app._variable_manager.independent_variable_names
dependent_variables = self._app._variable_manager.dependent_variable_names

for el in variables:
par_description.append(el + ":=")
par_description.append("")
arg.append("IncludedParameters:="), arg.append(variables)

arg.append("IncludedDependentParameters:="), arg.append(dependent_variables)

for el in variables:
par_description.append(el + ":=")
par_description.append("")
arg.append("ParameterDescription:="), arg.append(par_description)
arg += [
"IncludedParameters:=",
variables,
"IncludedDependentParameters:=",
dependent_variables,
"ParameterDescription:=",
[item for el in variables for item in (el + ":=", "")],
]

arg2 = ["NAME:DesignData"]
if boundaries:
boundaries = boundaries
else:
if not boundaries:
boundaries = self.get_boundaries_name()
if boundaries:
arg2.append("Boundaries:="), arg2.append(boundaries)
arg2 += ["Boundaries:=", boundaries]
if self._app.design_type == "Icepak":
meshregions = [mr.name for mr in self._app.mesh.meshregions]
try:
meshregions.remove("Global")
except Exception:
pass
if meshregions:
arg2.append("MeshRegions:="), arg2.append(meshregions)
mesh_regions = [mr.name for mr in self._app.mesh.meshregions if mr.name != "Global"]
if mesh_regions:
arg2 += ["MeshRegions:=", mesh_regions]
else:
if excitations:
excitations = excitations
Expand All @@ -574,7 +561,7 @@ def replace_3dcomponent(
excitations.extend(exc)
excitations = list(set([i.split(":")[0] for i in excitations]))
if excitations:
arg2.append("Excitations:="), arg2.append(excitations)
arg2 += ["Excitations:=", excitations]
meshops = [el.name for el in self._app.mesh.meshoperations]
if meshops:
used_mesh_ops = []
Expand All @@ -587,9 +574,9 @@ def replace_3dcomponent(
mesh_comp.append(self.objects[item].name)
if all(included_obj in objs for included_obj in mesh_comp):
used_mesh_ops.append(self._app.mesh.meshoperations[mesh].name)
arg2.append("MeshOperations:="), arg2.append(used_mesh_ops)
arg2 += ["MeshOperations:=", used_mesh_ops]
else:
arg2.append("MeshOperations:="), arg2.append(meshops)
arg2 += ["MeshOperations:=", meshops]
arg3 = ["NAME:ImageFile", "ImageFile:=", ""]
old_components = self.user_defined_component_names
self.oeditor.ReplaceWith3DComponent(arg, arg2, arg3)
Expand Down
7 changes: 3 additions & 4 deletions src/ansys/aedt/core/modeler/modeler_pcb.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ def model_units(self):

@model_units.setter
def model_units(self, units):
assert units in AEDT_UNITS["Length"], f"Invalid units string {units}."
if not units in AEDT_UNITS["Length"]:
raise ValueError(f"Invalid units '{units}'")
self.oeditor.SetActiveUnits(units)
self._model_units = units

Expand Down Expand Up @@ -357,7 +358,7 @@ def merge_design(self, merged_design=None, x="0.0", y="0.0", z="0.0", rotation="
comp_name = str(i)
break
except Exception:
continue
self.logger.debug(f"Couldn't get component name from component {i}")
if not comp_name:
return False
comp = ComponentsSubCircuit3DLayout(self, comp_name)
Expand Down Expand Up @@ -648,8 +649,6 @@ def convert_to_selections(self, assignment, return_list=False):
objnames.append(el)
elif "name" in dir(el):
objnames.append(el.name)
else:
pass
if return_list:
return objnames
else:
Expand Down
6 changes: 3 additions & 3 deletions src/ansys/aedt/core/modeler/pcb/object_3d_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -1064,12 +1064,12 @@ def name(self):
def name(self, value):
try:
del self._primitives._lines[self.name]
vMaterial = ["NAME:Name", "Value:=", value]
self.change_property(vMaterial)
args = ["NAME:Name", "Value:=", value]
self.change_property(args)
self._name = value
self._primitives._lines[self._name] = self
except Exception:
pass
self.logger.debug(f"Couldn't update geometry name into '{value}'.")

@property
def is_closed(self):
Expand Down
5 changes: 2 additions & 3 deletions src/ansys/aedt/core/modeler/pcb/primitives_3d_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ def padstacks(self):
if p[0] == "NAME:psd":
props = p
except Exception:
pass
self.logger.debug("Couldn't access first property.")
self._padstacks[name] = Padstack(name, self.opadstackmanager, self.model_units)

for prop in props:
Expand Down Expand Up @@ -819,9 +819,8 @@ def padstacks(self):
self._padstacks[name].layers[lay_name].connectiony = lay[14]
self._padstacks[name].layers[lay_name].connectiondir = lay[16]
i += 1
pass
except Exception:
pass
self.logger.debug(f"Exception caught when updating padstack '{name}' properties.")

return self._padstacks

Expand Down
2 changes: 1 addition & 1 deletion src/ansys/aedt/core/modules/material_workbench.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@
from collections import defaultdict
import copy
import re
from xml.etree.ElementTree import ParseError

from ansys.aedt.core.aedt_logger import pyaedt_logger as logger
from ansys.aedt.core.generic.data_handlers import normalize_string_format
from ansys.aedt.core.modules.material import MatProperties
import defusedxml
from defusedxml.ElementTree import ParseError

defusedxml.defuse_stdlib()

Expand Down
Loading

0 comments on commit b47ea37

Please sign in to comment.