Exemplo n.º 1
0
def file_display(request):
    """
    Stream a file
    """
    root_path = get_root_directory(request)
    rel_filepath = decode_path(request.params['name'])
    # remove the leading slash to be able to join
    rel_filepath = rel_filepath.strip('/')
    filepath = os.path.join(root_path, rel_filepath)
    filename = os.path.basename(filepath)
    company_code = request.context.code_compta

    if not code_is_not_null(company_code):
        logger.warn("Current context has no code")
        return HTTPForbidden()

    if not isprefixed(filename, company_code):
        logger.warn("Current context has no code")
        return HTTPForbidden()

    if not issubdir(root_path, filepath):
        logger.warn("Given filepath is not a subdirectory")
        logger.warn(filepath)
        logger.warn(root_path)
        return HTTPForbidden()

    if os.path.isfile(filepath):
        file_obj = AbstractFile(filename, filepath)
        file_obj.as_response(request)
        return request.response

    logger.warn("AbstractFile not found")
    logger.warn(filepath)
    return HTTPNotFound()
Exemplo n.º 2
0
def file_display(request):
    """
    Stream a file
    """
    root_path = get_root_directory(request)
    rel_filepath = decode_path(request.params['name'])
    # remove the leading slash to be able to join
    rel_filepath = rel_filepath.strip('/')
    filepath = os.path.join(root_path, rel_filepath)
    filename = os.path.basename(filepath)
    company_code = request.context.code_compta

    if not code_is_not_null(company_code):
        logger.warn("Current context has no code")
        return HTTPForbidden()

    if not isprefixed(filename, company_code):
        logger.warn("Current context has no code")
        return HTTPForbidden()

    if not issubdir(root_path, filepath):
        logger.warn("Given filepath is not a subdirectory")
        logger.warn(filepath)
        logger.warn(root_path)
        return HTTPForbidden()

    if os.path.isfile(filepath):
        file_obj = AbstractFile(filename, filepath)
        file_obj.as_response(request)
        return request.response

    logger.warn("AbstractFile not found")
    logger.warn(filepath)
    return HTTPNotFound()
Exemplo n.º 3
0
def test_encode_decode():
    st = u"$deù % ù$ùdeù % - /// //  \ \dekodok %spkoij  idje  ' kopk \""
    encoded = encode_path(st)
    assert decode_path(encoded) == st
Exemplo n.º 4
0
 def test_encode_decode(self):
     st = u"$deù % ù$ùdeù % - /// //  \ \dekodok %spkoij  idje  ' kopk \""
     encoded = encode_path(st)
     self.assertEqual(decode_path(encoded), st)
Exemplo n.º 5
0
def test_encode_decode():
    st = u"$deù % ù$ùdeù % - /// //  \ \dekodok %spkoij  idje  ' kopk \""
    encoded = encode_path(st)
    assert decode_path(encoded) == st