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

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

eric ide

mercurial