Server IP : 127.0.0.2 / Your IP : 3.17.73.197 Web Server : Apache/2.4.18 (Ubuntu) System : User : www-data ( ) PHP Version : 7.0.33-0ubuntu0.16.04.16 Disable Function : disk_free_space,disk_total_space,diskfreespace,dl,exec,fpaththru,getmyuid,getmypid,highlight_file,ignore_user_abord,leak,listen,link,opcache_get_configuration,opcache_get_status,passthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,php_uname,phpinfo,posix_ctermid,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix,_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_times,posix_ttyname,posix_uname,pclose,popen,proc_open,proc_close,proc_get_status,proc_nice,proc_terminate,shell_exec,source,show_source,system,virtual MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /opt/odoo/odoo/tools/ |
Upload File : |
""" View validation code (using assertions, not the RNG schema). """ import collections import logging _logger = logging.getLogger(__name__) _validators = collections.defaultdict(list) def valid_view(arch): for pred in _validators[arch.tag]: if not pred(arch): _logger.error("Invalid XML: %s", pred.__doc__) return False return True def validate(*view_types): """ Registers a view-validation function for the specific view types """ def decorator(fn): for arch in view_types: _validators[arch].append(fn) return fn return decorator @validate('form') def valid_page_in_book(arch): """A `page` node must be below a `notebook` node.""" return not arch.xpath('//page[not(ancestor::notebook)]') @validate('graph') def valid_field_in_graph(arch): """ Children of ``graph`` can only be ``field`` """ return all( child.tag == 'field' for child in arch.xpath('/graph/*') ) @validate('tree') def valid_field_in_tree(arch): """ Children of ``tree`` view must be ``field`` or ``button``.""" return all( child.tag in ('field', 'button') for child in arch.xpath('/tree/*') ) @validate('form', 'graph', 'tree') def valid_att_in_field(arch): """ ``field`` nodes must all have a ``@name`` """ return not arch.xpath('//field[not(@name)]') @validate('form') def valid_att_in_label(arch): """ ``label`` nodes must have a ``@for`` or a ``@string`` """ return not arch.xpath('//label[not(@for or @string)]') @validate('form') def valid_att_in_form(arch): return True @validate('form') def valid_type_in_colspan(arch): """A `colspan` attribute must be an `integer` type.""" return all( attrib.isdigit() for attrib in arch.xpath('//@colspan') ) @validate('form') def valid_type_in_col(arch): """A `col` attribute must be an `integer` type.""" return all( attrib.isdigit() for attrib in arch.xpath('//@col') )