예제 #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
 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()))
예제 #3
0
 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
예제 #4
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
         country_code = _eu_country_vat_inverse.get(country_code, country_code)
         return bool(self.env['res.country'].search([('code', '=ilike', country_code)]))
     return check_func(vat_number)
예제 #5
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
예제 #6
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
예제 #7
0
    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))
예제 #8
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