Exemplo n.º 1
0
 def modify_legislation_json(self, modifier_function):
     """
     Copy the reference TaxBenefitSystem legislation_json attribute and return it.
     Used by reforms which need to modify the legislation_json, usually in the build_reform() function.
     Validates the new legislation.
     """
     reference_legislation_json = self.reference.get_legislation()
     reference_legislation_json_copy = copy.deepcopy(reference_legislation_json)
     reform_legislation_json = modifier_function(reference_legislation_json_copy)
     assert reform_legislation_json is not None, \
         'modifier_function {} in module {} must return the modified legislation_json'.format(
             modifier_function.__name__,
             modifier_function.__module__,
             )
     reform_legislation_json, errors = legislations.validate_legislation_json(reform_legislation_json)
     if errors is not None:
         errors = conv.embed_error(reform_legislation_json, 'errors', errors)
         if errors is None:
             legislation_json_str = json.dumps(
                 deep_encode(reform_legislation_json),
                 ensure_ascii = False,
                 indent = 2,
                 )
             raise ValueError('The modified legislation_json of the reform "{}" is invalid: {}'.format(
                 self.key.encode('utf-8'), legislation_json_str))
         raise ValueError(u'{} for: {}'.format(
             unicode(json.dumps(errors, ensure_ascii = False, indent = 2, sort_keys = True)),
             unicode(json.dumps(reform_legislation_json, ensure_ascii = False, indent = 2)),
             ).encode('utf-8'))
     self._legislation_json = reform_legislation_json
     self.compact_legislation_by_instant_cache = {}
Exemplo n.º 2
0
def get_url(ctx, *path, **query):
    path = [
        urllib.quote(unicode(sub_fragment).encode('utf-8'),
                     safe=',/:').decode('utf-8') for fragment in path
        if fragment for sub_fragment in unicode(fragment).split(u'/')
        if sub_fragment
    ]
    query = dict((str(name), strings.deep_encode(value))
                 for name, value in sorted(query.iteritems())
                 if value not in (None, [], (), ''))
    return u'{0}/{1}{2}'.format(
        get_base_url(ctx), u'/'.join(path),
        ('?' + urllib.urlencode(query, doseq=True)) if query else '')
Exemplo n.º 3
0
def get_url(ctx, *path, **query):
    path = [
        urllib.quote(unicode(sub_fragment).encode('utf-8'), safe = ',/:').decode('utf-8')
        for fragment in path
        if fragment
        for sub_fragment in unicode(fragment).split(u'/')
        if sub_fragment
        ]
    query = dict(
        (str(name), strings.deep_encode(value))
        for name, value in sorted(query.iteritems())
        if value not in (None, [], (), '')
        )
    return u'{0}/{1}{2}'.format(get_base_url(ctx), u'/'.join(path),
        ('?' + urllib.urlencode(query, doseq = True)) if query else '')
Exemplo n.º 4
0
def get_url(ctx, *path, **query):
    lang = query.pop('lang', None) or ctx.lang[0]
    static = query.pop('static', None)
    path = [
        urllib.quote(unicode(sub_fragment).encode('utf-8'),
                     safe=',/:').decode('utf-8')
        for fragment in itertools.chain(
            [lang if not static and lang != conf['languages'][0] else None],
            path,
        ) if fragment for sub_fragment in unicode(fragment).split(u'/')
        if sub_fragment
    ]
    query = dict((str(name), strings.deep_encode(value))
                 for name, value in sorted(query.iteritems())
                 if value not in (None, [], (), ''))
    return u'{0}/{1}{2}'.format(
        get_base_url(ctx), u'/'.join(path),
        ('?' + urllib.urlencode(query, doseq=True)) if query else '')
Exemplo n.º 5
0
def iter_full_urls(ctx, *path, **query):
    assert application_url is not None
    host_urls = conf['host_urls']
    if host_urls is None:
        yield get_full_url(ctx, *path, **query)
    else:
        path = [
            urllib.quote(unicode(sub_fragment).encode('utf-8'),
                         safe=',/:').decode('utf-8') for fragment in
            urlparse.urlsplit(application_url).path.split('/') + path
            if fragment for sub_fragment in unicode(fragment).split(u'/')
            if sub_fragment
        ]
        query = dict((str(name), strings.deep_encode(value))
                     for name, value in sorted(query.iteritems())
                     if value not in (None, [], (), ''))
        for host_url in host_urls:
            yield u'{0}{1}{2}'.format(
                host_url, u'/'.join(path),
                ('?' + urllib.urlencode(query, doseq=True)) if query else '')
Exemplo n.º 6
0
def get_url(ctx, *path, **query):
    lang = query.pop('lang', None) or ctx.lang[0]
    static = query.pop('static', None)
    path = [
        urllib.quote(unicode(sub_fragment).encode('utf-8'), safe = ',/:').decode('utf-8')
        for fragment in itertools.chain(
            [lang if not static and lang != conf['languages'][0] else None],
            path,
            )
        if fragment
        for sub_fragment in unicode(fragment).split(u'/')
        if sub_fragment
        ]
    query = dict(
        (str(name), strings.deep_encode(value))
        for name, value in sorted(query.iteritems())
        if value not in (None, [], (), '')
        )
    return u'{0}/{1}{2}'.format(get_base_url(ctx), u'/'.join(path),
        ('?' + urllib.urlencode(query, doseq = True)) if query else '')
Exemplo n.º 7
0
def iter_full_urls(ctx, *path, **query):
    assert application_url is not None
    host_urls = conf['host_urls']
    if host_urls is None:
        yield get_full_url(ctx, *path, **query)
    else:
        path = [
            urllib.quote(unicode(sub_fragment).encode('utf-8'), safe = ',/:').decode('utf-8')
            for fragment in urlparse.urlsplit(application_url).path.split('/') + path
            if fragment
            for sub_fragment in unicode(fragment).split(u'/')
            if sub_fragment
            ]
        query = dict(
            (str(name), strings.deep_encode(value))
            for name, value in sorted(query.iteritems())
            if value not in (None, [], (), '')
            )
        for host_url in host_urls:
            yield u'{0}{1}{2}'.format(host_url, u'/'.join(path),
                ('?' + urllib.urlencode(query, doseq = True)) if query else '')