<commit_before>import os.path
import colander
import pyramid.httpexceptions as exc
from pyramid.view import view_config, view_defaults

from ..models import Group
from .predicates import load_tag, load_file, load_group

from .validation import errors_to_angular


class GroupSchema(colander.MappingSchema):
    name = colander.SchemaNode(colander.String())
    abs_path = colander.SchemaNode(colander.String(),
                                   preparer=os.path.normpath)
    web_path = colander.SchemaNode(colander.String(),
                                   preparer=os.path.normpath)
    thumbnail_path = colander.SchemaNode(colander.String(),
                                         preparer=os.path.normpath)


@view_defaults(renderer='json')
class GroupView(object):

    def __init__(self, request):
        self.request = request

    @view_config(route_name='groups', request_method='GET')
    def get(self):
        query = self.request.dbsession.query(Group)
        groups = query.order_by(Group.group_id).all()
        lis = []
        for g in groups:
            lis.append({
                'id': g.group_id,
                'name': g.name,
                'abs_path': g.abs_path,
                'web_path': g.web_path,
                'thumbnail_path': g.thumbnail_path,
            })
        return {
            'groups': lis
        }
<commit_msg>Escape path correctly<commit_after>import os.path
import urlparse
import colander
import pyramid.httpexceptions as exc
from pyramid.view import view_config, view_defaults

from ..models import Group
from .predicates import load_tag, load_file, load_group

from .validation import errors_to_angular


def normpath(path):
    url = urlparse.urlparse(path)
    url._replace(path=os.path.normpath(url.path))
    print url.geturl()
    return url.geturl()


class GroupSchema(colander.MappingSchema):
    name = colander.SchemaNode(colander.String())
    abs_path = colander.SchemaNode(colander.String(),
                                   preparer=normpath)
    web_path = colander.SchemaNode(colander.String(),
                                   preparer=normpath)
    thumbnail_path = colander.SchemaNode(colander.String(),
                                         preparer=normpath)


@view_defaults(renderer='json')
class GroupView(object):

    def __init__(self, request):
        self.request = request

    @view_config(route_name='groups', request_method='GET')
    def get(self):
        query = self.request.dbsession.query(Group)
        groups = query.order_by(Group.group_id).all()
        lis = []
        for g in groups:
            lis.append({
                'id': g.group_id,
                'name': g.name,
                'abs_path': g.abs_path,
                'web_path': g.web_path,
                'thumbnail_path': g.thumbnail_path,
            })
        return {
            'groups': lis
        }

{'fraction_non_alphanumeric': 0.10079392474974111, 'fraction_numerical': 0.0, 'mean_word_length': 2.163755458515284, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4979791', 'n_tokens_mistral': 850, 'n_tokens_neox': 814, 'n_words': 163}