src/eric7/Documentation/Source/eric7.Plugins.CheckerPlugins.CodeStyleChecker.Security.SecurityUtils.html

branch
eric7
changeset 9209
b99e7fd55fd3
parent 8596
d64760b2da50
child 9295
d14096c04126
equal deleted inserted replaced
9208:3fc8dfeb6ebe 9209:b99e7fd55fd3
1 <!DOCTYPE html>
2 <html><head>
3 <title>eric7.Plugins.CheckerPlugins.CodeStyleChecker.Security.SecurityUtils</title>
4 <meta charset="UTF-8">
5 <link rel="stylesheet" href="styles.css">
6 </head>
7 <body>
8 <a NAME="top" ID="top"></a>
9 <h1>eric7.Plugins.CheckerPlugins.CodeStyleChecker.Security.SecurityUtils</h1>
10
11 <p>
12 Module implementing utility functions used by the security checks.
13 </p>
14 <h3>Global Attributes</h3>
15
16 <table>
17 <tr><td>None</td></tr>
18 </table>
19 <h3>Classes</h3>
20
21 <table>
22
23 <tr>
24 <td><a href="#InvalidModulePath">InvalidModulePath</a></td>
25 <td>Class defining an exception for invalid module paths.</td>
26 </tr>
27 </table>
28 <h3>Functions</h3>
29
30 <table>
31
32 <tr>
33 <td><a href="#_get">_get</a></td>
34 <td></td>
35 </tr>
36 <tr>
37 <td><a href="#concatString">concatString</a></td>
38 <td>Function to build a string from an ast.BinOp chain.</td>
39 </tr>
40 <tr>
41 <td><a href="#deepgetattr">deepgetattr</a></td>
42 <td>Function to recurs through an attribute chain to get the ultimate value.</td>
43 </tr>
44 <tr>
45 <td><a href="#escapedBytesRepresentation">escapedBytesRepresentation</a></td>
46 <td>Function to escape bytes for comparison with other strings.</td>
47 </tr>
48 <tr>
49 <td><a href="#getAttrQualName">getAttrQualName</a></td>
50 <td>Function to get a the full name for the attribute node.</td>
51 </tr>
52 <tr>
53 <td><a href="#getCallName">getCallName</a></td>
54 <td>Function to extract the call name from an ast.Call node.</td>
55 </tr>
56 <tr>
57 <td><a href="#getCalledName">getCalledName</a></td>
58 <td>Function to get the function name from an ast.Call node.</td>
59 </tr>
60 <tr>
61 <td><a href="#getModuleQualnameFromPath">getModuleQualnameFromPath</a></td>
62 <td>Function to get the module's qualified name by analysis of the path.</td>
63 </tr>
64 <tr>
65 <td><a href="#getQualAttr">getQualAttr</a></td>
66 <td>Function to extract the qualified name from an ast.Attribute node.</td>
67 </tr>
68 <tr>
69 <td><a href="#linerange">linerange</a></td>
70 <td>Function to get line number range from a node.</td>
71 </tr>
72 <tr>
73 <td><a href="#linerange_fix">linerange_fix</a></td>
74 <td>Function to get a line number range working around a known Python bug with multi-line strings.</td>
75 </tr>
76 <tr>
77 <td><a href="#namespacePathJoin">namespacePathJoin</a></td>
78 <td>Function to extend a given namespace path.</td>
79 </tr>
80 <tr>
81 <td><a href="#namespacePathSplit">namespacePathSplit</a></td>
82 <td>Function to split a namespace path into a head and tail.</td>
83 </tr>
84 </table>
85 <hr />
86 <hr />
87 <a NAME="InvalidModulePath" ID="InvalidModulePath"></a>
88 <h2>InvalidModulePath</h2>
89
90 <p>
91 Class defining an exception for invalid module paths.
92 </p>
93 <h3>Derived from</h3>
94 Exception
95 <h3>Class Attributes</h3>
96
97 <table>
98 <tr><td>None</td></tr>
99 </table>
100 <h3>Class Methods</h3>
101
102 <table>
103 <tr><td>None</td></tr>
104 </table>
105 <h3>Methods</h3>
106
107 <table>
108 <tr><td>None</td></tr>
109 </table>
110 <h3>Static Methods</h3>
111
112 <table>
113 <tr><td>None</td></tr>
114 </table>
115
116 <div align="right"><a href="#top">Up</a></div>
117 <hr />
118 <hr />
119 <a NAME="_get" ID="_get"></a>
120 <h2>_get</h2>
121 <b>_get</b>(<i>node, bits, stop=None</i>)
122
123 <div align="right"><a href="#top">Up</a></div>
124 <hr />
125 <hr />
126 <a NAME="concatString" ID="concatString"></a>
127 <h2>concatString</h2>
128 <b>concatString</b>(<i>node, stop=None</i>)
129
130 <p>
131 Function to build a string from an ast.BinOp chain.
132 </p>
133 <p>
134 This will build a string from a series of ast.Str/ast.Constant nodes
135 wrapped in ast.BinOp nodes. Something like "a" + "b" + "c" or "a %s" % val
136 etc. The provided node can be any participant in the BinOp chain.
137 </p>
138 <dl>
139
140 <dt><i>node</i> (ast.BinOp or ast.Str/ast.Constant)</dt>
141 <dd>
142 node to be processed
143 </dd>
144 <dt><i>stop</i> (ast.BinOp or ast.Str/ast.Constant)</dt>
145 <dd>
146 base node to stop at
147 </dd>
148 </dl>
149 <dl>
150 <dt>Return:</dt>
151 <dd>
152 tuple containing the root node of the expression and the string
153 value
154 </dd>
155 </dl>
156 <dl>
157 <dt>Return Type:</dt>
158 <dd>
159 tuple of (ast.AST, str)
160 </dd>
161 </dl>
162 <div align="right"><a href="#top">Up</a></div>
163 <hr />
164 <hr />
165 <a NAME="deepgetattr" ID="deepgetattr"></a>
166 <h2>deepgetattr</h2>
167 <b>deepgetattr</b>(<i>obj, attr</i>)
168
169 <p>
170 Function to recurs through an attribute chain to get the ultimate value.
171 </p>
172 <dl>
173
174 <dt><i>obj</i> (ast.Name or ast.Attribute)</dt>
175 <dd>
176 reference to the object to be recursed
177 </dd>
178 <dt><i>attr</i> (ast.Attribute)</dt>
179 <dd>
180 attribute chain to be parsed
181 </dd>
182 </dl>
183 <dl>
184 <dt>Return:</dt>
185 <dd>
186 ultimate value
187 </dd>
188 </dl>
189 <dl>
190 <dt>Return Type:</dt>
191 <dd>
192 ast.AST
193 </dd>
194 </dl>
195 <div align="right"><a href="#top">Up</a></div>
196 <hr />
197 <hr />
198 <a NAME="escapedBytesRepresentation" ID="escapedBytesRepresentation"></a>
199 <h2>escapedBytesRepresentation</h2>
200 <b>escapedBytesRepresentation</b>(<i>b</i>)
201
202 <p>
203 Function to escape bytes for comparison with other strings.
204 </p>
205 <p>
206 In practice it turns control characters into acceptable codepoints then
207 encodes them into bytes again to turn unprintable bytes into printable
208 escape sequences.
209 </p>
210 <p>
211 This is safe to do for the whole range 0..255 and result matches
212 unicode_escape on a unicode string.
213 </p>
214 <dl>
215
216 <dt><i>b</i> (bytes)</dt>
217 <dd>
218 bytes object to be escaped
219 </dd>
220 </dl>
221 <dl>
222 <dt>Return:</dt>
223 <dd>
224 escaped bytes object
225 </dd>
226 </dl>
227 <dl>
228 <dt>Return Type:</dt>
229 <dd>
230 bytes
231 </dd>
232 </dl>
233 <div align="right"><a href="#top">Up</a></div>
234 <hr />
235 <hr />
236 <a NAME="getAttrQualName" ID="getAttrQualName"></a>
237 <h2>getAttrQualName</h2>
238 <b>getAttrQualName</b>(<i>node, aliases</i>)
239
240 <p>
241 Function to get a the full name for the attribute node.
242 </p>
243 <p>
244 This will resolve a pseudo-qualified name for the attribute
245 rooted at node as long as all the deeper nodes are Names or
246 Attributes. This will give you how the code referenced the name but
247 will not tell you what the name actually refers to. If we
248 encounter a node without a static name we punt with an
249 empty string. If this encounters something more complex, such as
250 foo.mylist[0](a,b) we just return empty string.
251 </p>
252 <dl>
253
254 <dt><i>node</i> (ast.Attribute)</dt>
255 <dd>
256 attribute node to be treated
257 </dd>
258 <dt><i>aliases</i> (dict)</dt>
259 <dd>
260 dictionary of import aliases
261 </dd>
262 </dl>
263 <dl>
264 <dt>Return:</dt>
265 <dd>
266 qualified name of the attribute
267 </dd>
268 </dl>
269 <dl>
270 <dt>Return Type:</dt>
271 <dd>
272 str
273 </dd>
274 </dl>
275 <div align="right"><a href="#top">Up</a></div>
276 <hr />
277 <hr />
278 <a NAME="getCallName" ID="getCallName"></a>
279 <h2>getCallName</h2>
280 <b>getCallName</b>(<i>node, aliases</i>)
281
282 <p>
283 Function to extract the call name from an ast.Call node.
284 </p>
285 <dl>
286
287 <dt><i>node</i> (ast.Call)</dt>
288 <dd>
289 node to extract information from
290 </dd>
291 <dt><i>aliases</i> (dict)</dt>
292 <dd>
293 dictionary of import aliases
294 </dd>
295 </dl>
296 <dl>
297 <dt>Return:</dt>
298 <dd>
299 name of the ast.Call node
300 </dd>
301 </dl>
302 <dl>
303 <dt>Return Type:</dt>
304 <dd>
305 str
306 </dd>
307 </dl>
308 <div align="right"><a href="#top">Up</a></div>
309 <hr />
310 <hr />
311 <a NAME="getCalledName" ID="getCalledName"></a>
312 <h2>getCalledName</h2>
313 <b>getCalledName</b>(<i>node</i>)
314
315 <p>
316 Function to get the function name from an ast.Call node.
317 </p>
318 <p>
319 An ast.Call node representing a method call will present differently to one
320 wrapping a function call: thing.call() vs call(). This helper will grab the
321 unqualified call name correctly in either case.
322 </p>
323 <dl>
324
325 <dt><i>node</i> (ast.Call)</dt>
326 <dd>
327 reference to the call node
328 </dd>
329 </dl>
330 <dl>
331 <dt>Return:</dt>
332 <dd>
333 function name of the node
334 </dd>
335 </dl>
336 <dl>
337 <dt>Return Type:</dt>
338 <dd>
339 str
340 </dd>
341 </dl>
342 <div align="right"><a href="#top">Up</a></div>
343 <hr />
344 <hr />
345 <a NAME="getModuleQualnameFromPath" ID="getModuleQualnameFromPath"></a>
346 <h2>getModuleQualnameFromPath</h2>
347 <b>getModuleQualnameFromPath</b>(<i>path</i>)
348
349 <p>
350 Function to get the module's qualified name by analysis of the
351 path.
352 </p>
353 <p>
354 Resolve the absolute pathname and eliminate symlinks. This could result
355 in an incorrect name if symlinks are used to restructure the python lib
356 directory.
357 </p>
358 <p>
359 Starting from the right-most directory component look for __init__.py
360 in the directory component. If it exists then the directory name is
361 part of the module name. Move left to the subsequent directory
362 components until a directory is found without __init__.py.
363 </p>
364 <dl>
365
366 <dt><i>path</i> (str)</dt>
367 <dd>
368 path of the module to be analyzed
369 </dd>
370 </dl>
371 <dl>
372 <dt>Return:</dt>
373 <dd>
374 qualified name of the module
375 </dd>
376 </dl>
377 <dl>
378 <dt>Return Type:</dt>
379 <dd>
380 str
381 </dd>
382 </dl>
383 <dl>
384
385 <dt>Raises <b>InvalidModulePath</b>:</dt>
386 <dd>
387 raised to indicate an invalid module path
388 </dd>
389 </dl>
390 <div align="right"><a href="#top">Up</a></div>
391 <hr />
392 <hr />
393 <a NAME="getQualAttr" ID="getQualAttr"></a>
394 <h2>getQualAttr</h2>
395 <b>getQualAttr</b>(<i>node, aliases</i>)
396
397 <p>
398 Function to extract the qualified name from an ast.Attribute node.
399 </p>
400 <dl>
401
402 <dt><i>node</i> (ast.Attribute)</dt>
403 <dd>
404 node to extract information from
405 </dd>
406 <dt><i>aliases</i> (dict)</dt>
407 <dd>
408 dictionary of import aliases
409 </dd>
410 </dl>
411 <dl>
412 <dt>Return:</dt>
413 <dd>
414 qualified attribute name
415 </dd>
416 </dl>
417 <dl>
418 <dt>Return Type:</dt>
419 <dd>
420 str
421 </dd>
422 </dl>
423 <div align="right"><a href="#top">Up</a></div>
424 <hr />
425 <hr />
426 <a NAME="linerange" ID="linerange"></a>
427 <h2>linerange</h2>
428 <b>linerange</b>(<i>node</i>)
429
430 <p>
431 Function to get line number range from a node.
432 </p>
433 <dl>
434
435 <dt><i>node</i> (ast.AST)</dt>
436 <dd>
437 node to extract a line range from
438 </dd>
439 </dl>
440 <dl>
441 <dt>Return:</dt>
442 <dd>
443 list containing the line number range
444 </dd>
445 </dl>
446 <dl>
447 <dt>Return Type:</dt>
448 <dd>
449 list of int
450 </dd>
451 </dl>
452 <div align="right"><a href="#top">Up</a></div>
453 <hr />
454 <hr />
455 <a NAME="linerange_fix" ID="linerange_fix"></a>
456 <h2>linerange_fix</h2>
457 <b>linerange_fix</b>(<i>node</i>)
458
459 <p>
460 Function to get a line number range working around a known Python bug
461 with multi-line strings.
462 </p>
463 <dl>
464
465 <dt><i>node</i> (ast.AST)</dt>
466 <dd>
467 node to extract a line range from
468 </dd>
469 </dl>
470 <dl>
471 <dt>Return:</dt>
472 <dd>
473 list containing the line number range
474 </dd>
475 </dl>
476 <dl>
477 <dt>Return Type:</dt>
478 <dd>
479 list of int
480 </dd>
481 </dl>
482 <div align="right"><a href="#top">Up</a></div>
483 <hr />
484 <hr />
485 <a NAME="namespacePathJoin" ID="namespacePathJoin"></a>
486 <h2>namespacePathJoin</h2>
487 <b>namespacePathJoin</b>(<i>namespace, name</i>)
488
489 <p>
490 Function to extend a given namespace path.
491 </p>
492 <dl>
493
494 <dt><i>namespace</i> (str)</dt>
495 <dd>
496 namespace to be extended
497 </dd>
498 <dt><i>name</i> (str)</dt>
499 <dd>
500 node name to be appended
501 </dd>
502 </dl>
503 <dl>
504 <dt>Return:</dt>
505 <dd>
506 extended namespace
507 </dd>
508 </dl>
509 <dl>
510 <dt>Return Type:</dt>
511 <dd>
512 str
513 </dd>
514 </dl>
515 <div align="right"><a href="#top">Up</a></div>
516 <hr />
517 <hr />
518 <a NAME="namespacePathSplit" ID="namespacePathSplit"></a>
519 <h2>namespacePathSplit</h2>
520 <b>namespacePathSplit</b>(<i>path</i>)
521
522 <p>
523 Function to split a namespace path into a head and tail.
524 </p>
525 <p>
526 Tail will be the last namespace path component and head will
527 be everything leading up to that in the path. This is similar to
528 os.path.split.
529 </p>
530 <dl>
531
532 <dt><i>path</i> (str)</dt>
533 <dd>
534 namespace path to be split
535 </dd>
536 </dl>
537 <dl>
538 <dt>Return:</dt>
539 <dd>
540 tuple containing the namespace path head and tail
541 </dd>
542 </dl>
543 <dl>
544 <dt>Return Type:</dt>
545 <dd>
546 tuple of (str, str)
547 </dd>
548 </dl>
549 <div align="right"><a href="#top">Up</a></div>
550 <hr />
551 </body></html>

eric ide

mercurial