Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REFACTOR: Improve readability vulnerability handling #5579

Merged
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 @@
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.")

Check warning on line 520 in src/ansys/aedt/core/desktop.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/desktop.py#L519-L520

Added lines #L519 - L520 were not covered by tests
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 @@
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 @@
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]")

Check warning on line 1765 in src/ansys/aedt/core/modeler/geometry_operators.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/modeler/geometry_operators.py#L1765

Added line #L1765 was not covered by tests
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")

Check warning on line 1768 in src/ansys/aedt/core/modeler/geometry_operators.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/modeler/geometry_operators.py#L1768

Added line #L1768 was not covered by tests

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 @@
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 @@
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 @@
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 @@
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]

Check warning on line 316 in src/ansys/aedt/core/modeler/modeler_3d.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/modeler/modeler_3d.py#L316

Added line #L316 was not covered by tests
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 @@
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 @@
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 @@
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]

Check warning on line 552 in src/ansys/aedt/core/modeler/modeler_3d.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/modeler/modeler_3d.py#L550-L552

Added lines #L550 - L552 were not covered by tests
else:
if excitations:
excitations = excitations
Expand All @@ -574,7 +561,7 @@
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 @@
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 @@

@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}'")

Check warning on line 180 in src/ansys/aedt/core/modeler/modeler_pcb.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/modeler/modeler_pcb.py#L180

Added line #L180 was not covered by tests
self.oeditor.SetActiveUnits(units)
self._model_units = units

Expand Down Expand Up @@ -357,7 +358,7 @@
comp_name = str(i)
break
except Exception:
continue
self.logger.debug(f"Couldn't get component name from component {i}")

Check warning on line 361 in src/ansys/aedt/core/modeler/modeler_pcb.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/modeler/modeler_pcb.py#L361

Added line #L361 was not covered by tests
if not comp_name:
return False
comp = ComponentsSubCircuit3DLayout(self, comp_name)
Expand Down Expand Up @@ -648,8 +649,6 @@
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, 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}'.")

Check warning on line 1072 in src/ansys/aedt/core/modeler/pcb/object_3d_layout.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/modeler/pcb/object_3d_layout.py#L1072

Added line #L1072 was not covered by tests

@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.")
SMoraisAnsys marked this conversation as resolved.
Show resolved Hide resolved

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
Loading