コード例 #1
0
    def compile(self, source):
        command = self.get_command()
        try:
            compiler = Popen(command, stdin=PIPE, stdout=PIPE, stderr=PIPE)
        except Exception:
            raise CompileError("Could not execute command %r" % command[0])

        (out, err) = compiler.communicate(input=source.encode('utf-8'))
        if compiler.returncode:
            cmd_output = misc.ustr(out) + misc.ustr(err)
            if not cmd_output:
                cmd_output = u"Process exited with return code %d\n" % compiler.returncode
            raise CompileError(cmd_output)
        return out.decode('utf8')
コード例 #2
0
ファイル: assetsbundle.py プロジェクト: westlyou/flectra-1
    def compile_css(self, cmd, source):
        """Sanitizes @import rules, remove duplicates @import rules, then compile"""
        imports = []

        def sanitize(matchobj):
            ref = matchobj.group(2)
            line = '@import "%s"%s' % (ref, matchobj.group(3))
            if '.' not in ref and line not in imports and not ref.startswith(('.', '/', '~')):
                imports.append(line)
                return line
            msg = "Local import '%s' is forbidden for security reasons." % ref
            _logger.warning(msg)
            self.css_errors.append(msg)
            return ''
        source = re.sub(self.rx_preprocess_imports, sanitize, source)

        try:
            compiler = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE)
        except Exception:
            msg = "Could not execute command %r" % cmd[0]
            _logger.error(msg)
            self.css_errors.append(msg)
            return ''
        result = compiler.communicate(input=source.encode('utf-8'))
        if compiler.returncode:
            cmd_output = ''.join(misc.ustr(result))
            if not cmd_output:
                cmd_output = "Process exited with return code %d\n" % compiler.returncode
            error = self.get_preprocessor_error(cmd_output, source=source)
            _logger.warning(error)
            self.css_errors.append(error)
            return ''
        compiled = result[0].strip().decode('utf8')
        return compiled
コード例 #3
0
    def _signup_create_user(self, values):
        """ create a new user from the template user """
        get_param = self.env['ir.config_parameter'].sudo().get_param
        template_user_id = literal_eval(
            get_param('auth_signup.template_user_id', 'False'))
        template_user = self.browse(template_user_id)
        assert template_user.exists(), 'Signup: invalid template user'

        # check that uninvited users may sign up
        if 'partner_id' not in values:
            if not literal_eval(
                    get_param('auth_signup.allow_uninvited', 'False')):
                raise SignupError(
                    _('Signup is not allowed for uninvited users'))

        assert values.get('login'), "Signup: no login given for new user"
        assert values.get('partner_id') or values.get(
            'name'), "Signup: no name or partner given for new user"

        # create a copy of the template user (attached to a specific partner_id if given)
        values['active'] = True
        try:
            with self.env.cr.savepoint():
                return template_user.with_context(
                    no_reset_password=True).copy(values)
        except Exception as e:
            # copy may failed if asked login is not available.
            raise SignupError(ustr(e))
コード例 #4
0
ファイル: test_unsubscribe.py プロジェクト: yemanadep/Flectra
 def _unsubscribe_check(self, text):
     url = "/groups/unsubscribe/{}/{}/{}".format(self.mailing_list.id,
                                                 self.partner.id,
                                                 self.token)
     r = self.url_open(url)
     body = ustr(r.content)
     # normalize space to make matching simpler
     self.assertIn(text, u' '.join(body.split()))
コード例 #5
0
ファイル: assetsbundle.py プロジェクト: westlyou/flectra-1
 def get_preprocessor_error(self, stderr, source=None):
     """Improve and remove sensitive information from sass/less compilator error messages"""
     error = misc.ustr(stderr).split('Load paths')[0].replace('  Use --trace for backtrace.', '')
     if 'Cannot load compass' in error:
         error += "Maybe you should install the compass gem using this extra argument:\n\n" \
                  "    $ sudo gem install compass --pre\n"
     error += "This error occured while compiling the bundle '%s' containing:" % self.name
     for asset in self.stylesheets:
         if isinstance(asset, PreprocessedCSS):
             error += '\n    - %s' % (asset.url if asset.url else '<inline sass>')
     return error
コード例 #6
0
 def simple_vat_check(self, country_code, vat_number):
     '''
     Check the VAT number depending of the country.
     http://sima-pc.com/nif.php
     '''
     if not ustr(country_code).encode('utf-8').isalpha():
         return False
     check_func_name = 'check_vat_' + country_code
     check_func = getattr(self, check_func_name, None) or getattr(
         vatnumber, check_func_name, None)
     if not check_func:
         # No VAT validation available, default to check that the country code exists
         if country_code.upper() == 'EU':
             # Foreign companies that trade with non-enterprises in the EU
             # may have a VATIN starting with "EU" instead of a country code.
             return True
         return bool(self.env['res.country'].search([('code', '=ilike',
                                                      country_code)]))
     return check_func(vat_number)
コード例 #7
0
    def run_rtlcss(self, source):
        rtlcss = 'rtlcss'
        if os.name == 'nt':
            try:
                rtlcss = misc.find_in_path('rtlcss.cmd')
            except IOError:
                rtlcss = 'rtlcss'
        cmd = [rtlcss, '-']

        try:
            rtlcss = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE)
        except Exception:

            # Check the presence of rtlcss, if rtlcss not available then we should return normal less file
            try:
                process = Popen(['rtlcss', '--version'],
                                stdout=PIPE,
                                stderr=PIPE)
            except (OSError, IOError):
                _logger.warning(
                    'You need https://rtlcss.com/ to convert css file to right to left compatiblity. Use: npm install -g rtlcss'
                )
                return source

            msg = "Could not execute command %r" % cmd[0]
            _logger.error(msg)
            self.css_errors.append(msg)
            return ''

        result = rtlcss.communicate(input=source.encode('utf-8'))
        if rtlcss.returncode:
            cmd_output = ''.join(misc.ustr(result))
            if not cmd_output:
                cmd_output = "Process exited with return code %d\n" % rtlcss.returncode
            error = self.get_rtlcss_error(cmd_output, source=source)
            _logger.warning(error)
            self.css_errors.append(error)
            return ''
        rtlcss_result = result[0].strip().decode('utf8')
        return rtlcss_result
コード例 #8
0
ファイル: res_users.py プロジェクト: sheetal4123/flectra
    def _create_user_from_template(self, values):
        template_user_id = literal_eval(
            self.env['ir.config_parameter'].sudo().get_param(
                'base.template_portal_user_id', 'False'))
        template_user = self.browse(template_user_id)
        if not template_user.exists():
            raise ValueError(_('Signup: invalid template user'))

        if not values.get('login'):
            raise ValueError(_('Signup: no login given for new user'))
        if not values.get('partner_id') and not values.get('name'):
            raise ValueError(
                _('Signup: no name or partner given for new user'))

        # create a copy of the template user (attached to a specific partner_id if given)
        values['active'] = True
        try:
            with self.env.cr.savepoint():
                return template_user.with_context(
                    no_reset_password=True).copy(values)
        except Exception as e:
            # copy may failed if asked login is not available.
            raise SignupError(ustr(e))
コード例 #9
0
    def check_vat_mx(self, vat):
        ''' Mexican VAT verification

        Verificar RFC México
        '''
        # we convert to 8-bit encoding, to help the regex parse only bytes
        vat = ustr(vat).encode('iso8859-1')
        m = self.__check_vat_mx_re.match(vat)
        if not m:
            #No valid format
            return False
        try:
            ano = int(m.group('ano'))
            if ano > 30:
                ano = 1900 + ano
            else:
                ano = 2000 + ano
            datetime.date(ano, int(m.group('mes')), int(m.group('dia')))
        except ValueError:
            return False

        # Valid format and valid date
        return True
コード例 #10
0
 def get_rtlcss_error(self, stderr, source=None):
     """Improve and remove sensitive information from sass/less compilator error messages"""
     error = misc.ustr(stderr).split('Load paths')[0].replace(
         '  Use --trace for backtrace.', '')
     error += "This error occured while compiling the bundle '%s' containing:" % self.name
     return error