MCPcopy Create free account
hub / github.com/NVIDIA/TensorRT / String

Class String

tools/Polygraphy/polygraphy/tools/script.py:202–248  ·  view source on GitHub ↗

Represents a string that has passed Polygraphy's security checks.

Source from the content-addressed store, hash-verified

200 """
201
202 class String:
203 """
204 Represents a string that has passed Polygraphy's security checks.
205 """
206
207 def __init__(self, s, safe=False, inline=False):
208 self.s = s
209 self.safe = safe
210 self.inline = inline
211
212 def __str__(self):
213 return str(self.s)
214
215 def __repr__(self):
216 if self.inline:
217 # Since only safe strings can be marked inline, self.safe is always
218 # True in this branch, so no need to check it.
219 return str(self.s)
220 return repr(self.s)
221
222 def __iadd__(self, other):
223 if not isinstance(other, Script.String):
224 G_LOGGER.internal_error(f"Cannot concatenate str and Script.String. Note: str was: {other}")
225 elif self.safe != other.safe:
226 G_LOGGER.internal_error(f"Cannot concatenate unsafe string ({other}) to safe string ({self.s})!")
227 self.s += other.s
228 return self
229
230 def __eq__(self, other):
231 return (
232 isinstance(other, Script.String)
233 and self.safe == other.safe
234 and self.inline == other.inline
235 and self.s == other.s
236 )
237
238 def __hash__(self):
239 return hash((self.s, self.safe, self.inline))
240
241 def unwrap(self):
242 """
243 Returns the underlying string object.
244
245 Returns:
246 str
247 """
248 return self.s
249
250 DATA_LOADER_NAME = String("data_loader", safe=True, inline=True)
251

Callers 1

ScriptClass · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected