Mercurial > libervia-backend
comparison src/memory/memory.py @ 784:900987e1c0c4
memory: factorize the node checks in Params.__constructProfileXml
author | souliane <souliane@mailoo.org> |
---|---|
date | Sun, 05 Jan 2014 07:26:41 +0100 |
parents | a978c703bf57 |
children | 9007bb133009 |
comparison
equal
deleted
inserted
replaced
783:27581cddb758 | 784:900987e1c0c4 |
---|---|
531 @param app: name of the frontend requesting the parameters, or '' to get all parameters | 531 @param app: name of the frontend requesting the parameters, or '' to get all parameters |
532 @param profile: profile name (not key !) | 532 @param profile: profile name (not key !) |
533 @return: a deferred that fire a minidom.Document of the profile xml (cf warning above) | 533 @return: a deferred that fire a minidom.Document of the profile xml (cf warning above) |
534 """ | 534 """ |
535 | 535 |
536 def checkNode(node): | |
537 """Check the node against security_limit and app""" | |
538 return self.checkSecurityLimit(node, security_limit) and self.checkApp(node, app) | |
539 | |
536 def constructProfile(ignore, profile_cache): | 540 def constructProfile(ignore, profile_cache): |
537 # init the result document | 541 # init the result document |
538 prof_xml = minidom.parseString('<params/>') | 542 prof_xml = minidom.parseString('<params/>') |
539 cache = {} | 543 cache = {} |
540 | 544 |
551 # we make a copy for the new xml | 555 # we make a copy for the new xml |
552 cache[category] = dest_cat = cat_node.cloneNode(True) | 556 cache[category] = dest_cat = cat_node.cloneNode(True) |
553 for node in dest_cat.childNodes: | 557 for node in dest_cat.childNodes: |
554 if node.nodeName != "param": | 558 if node.nodeName != "param": |
555 continue | 559 continue |
556 if not self.checkSecurityLimit(node, security_limit): | 560 if not checkNode(node): |
557 dest_cat.removeChild(node) | |
558 continue | |
559 if not self.checkApp(node, app): | |
560 dest_cat.removeChild(node) | 561 dest_cat.removeChild(node) |
561 continue | 562 continue |
562 dest_params[node.getAttribute('name')] = node | 563 dest_params[node.getAttribute('name')] = node |
563 new_node = True | 564 new_node = True |
564 else: | 565 else: |
569 | 570 |
570 for param_node in params: | 571 for param_node in params: |
571 # we have to merge new params (we are parsing individual parameters, we have to add them | 572 # we have to merge new params (we are parsing individual parameters, we have to add them |
572 # to the previously parsed general ones) | 573 # to the previously parsed general ones) |
573 name = param_node.getAttribute('name') | 574 name = param_node.getAttribute('name') |
574 if not self.checkSecurityLimit(param_node, security_limit): | 575 if not checkNode(param_node): |
575 continue | |
576 if not self.checkApp(param_node, app): | |
577 continue | 576 continue |
578 if name not in dest_params: | 577 if name not in dest_params: |
579 # this is reached when a previous category exists | 578 # this is reached when a previous category exists |
580 dest_params[name] = param_node.cloneNode(True) | 579 dest_params[name] = param_node.cloneNode(True) |
581 dest_cat.appendChild(dest_params[name]) | 580 dest_cat.appendChild(dest_params[name]) |