Ejemplo n.º 1
0
 def test_generates_a_random_string_between_minlen_and_maxlen(self):
     self._gen_checker(tools.generateRandStr(4, 10), 4, 10)
     self._gen_checker(tools.generateRandStr(4, 10), 4, 10)
     self._gen_checker(tools.generateRandStr(4, 10), 4, 10)
     self._gen_checker(tools.generateRandStr(4, 10), 4, 10)
     self._gen_checker(tools.generateRandStr(4, 10), 4, 10)
     self._gen_checker(tools.generateRandStr(3, 12), 3, 12)
     self._gen_checker(tools.generateRandStr(3, 12), 3, 12)
     self._gen_checker(tools.generateRandStr(3, 12), 3, 12)
     self._gen_checker(tools.generateRandStr(3, 12), 3, 12)
     self._gen_checker(tools.generateRandStr(3, 12), 3, 12)
Ejemplo n.º 2
0
def blogger_editPost(request,
                     appkey,
                     postid,
                     username,
                     password,
                     content,
                     publish=1):
    """
    Edit an existing post
    """
    authenticate(request, username, password)
    config = request.getConfiguration()
    filename = os.path.normpath(os.path.join(config['datadir'], postid[1:]))
    if publish and re.search(r'-$', filename):
        switchTo = re.sub(r'-$', '', filename)
    elif not publish and re.search(r'txt$', filename):
        switchTo = filename + '-'
    else:
        switchTo = filename
    cache_driver = tools.importName('Pyblosxom.cache',
                                    config.get('cacheDriver', 'base'))
    cache = cache_driver.BlosxomCache(request, config.get('cacheConfig', ''))
    # Check if file exists or not, edit everything here
    if os.path.isfile(filename):
        if filename != switchTo:
            if cache.has_key(filename):
                del cache[filename]
            os.remove(filename)

            if os.path.isfile(switchTo):
                basefilename, ext = os.path.splitext(
                    os.path.basename(switchTo))
                dirname = os.path.dirname(switchTo)
                switchTo = os.path.normpath(
                    os.path.join(
                        config['datadir'], dirname[1:] + basefilename +
                        tools.generateRandStr() + ext))
        open(switchTo, 'w').write(content)

        return xmlrpclib. True
    else:
        raise xmlrpclib.Fault('UpdateError', 'Post does not exist')
Ejemplo n.º 3
0
def blogger_editPost(request, appkey, postid, username, password, content,
        publish=1):
    """
    Edit an existing post
    """
    authenticate(request, username, password)
    config = request.getConfiguration()
    filename = os.path.normpath(os.path.join(config['datadir'], postid[1:]))
    if publish and re.search(r'-$', filename):
        switchTo = re.sub(r'-$','',filename)
    elif not publish and re.search(r'txt$', filename):
        switchTo = filename + '-'
    else:
        switchTo = filename
    cache_driver = tools.importName('Pyblosxom.cache', 
            config.get('cacheDriver', 'base'))
    cache = cache_driver.BlosxomCache(request, config.get('cacheConfig', ''))
    # Check if file exists or not, edit everything here
    if os.path.isfile(filename):
        if filename != switchTo:
            if cache.has_key(filename):
                del cache[filename]
            os.remove(filename)

            if os.path.isfile(switchTo):
                basefilename, ext = os.path.splitext(os.path.basename(switchTo))
                dirname = os.path.dirname(switchTo)
                switchTo = os.path.normpath(
                    os.path.join(
                        config['datadir'], dirname[1:] + basefilename +
                        tools.generateRandStr() + ext
                    )
                )
        open(switchTo, 'w').write(content)
                
        return xmlrpclib.True
    else:
        raise xmlrpclib.Fault('UpdateError','Post does not exist')
Ejemplo n.º 4
0
def blogger_newPost(request, appkey, blogid, username, password, content,
        publish=1):
    """
    Used for creating new posts on the server
    """
    authenticate(request, username, password)

    config = request.getConfiguration()
    if os.path.isdir(os.path.normpath(os.path.join(config['datadir'],
            blogid[1:]))):
        # Look at content
        blogTitle = content.split(LINEFEED)[0].strip()

        tempMarker = (not publish and '-' or '')
        blogID = os.path.normpath(
            os.path.join(
                config['datadir'], blogid[1:] +
                re.sub('[^A-Za-z0-9]','_',blogTitle) + '.txt' +
                tempMarker
            )
        )
        if os.path.isfile(blogID) or os.path.isfile(blogID + '-'):
            # Generate a ficticious blog name
            blogID = os.path.normpath(
                os.path.join(
                    config['datadir'], blogid[1:] +
                    re.sub('[^A-Za-z0-9]','_',blogTitle) +
                    tools.generateRandStr() + '.txt' + tempMarker
                )
            )
        open(blogID, 'w').write(content.encode(config['blog_encoding']))

        # Generate BlogID
        return blogID.replace(config['datadir'], '')
    else: 
        raise xmlrpclib.Fault('PostError','Blog %s does not exist' % blogid)
Ejemplo n.º 5
0
def blogger_newPost(request,
                    appkey,
                    blogid,
                    username,
                    password,
                    content,
                    publish=1):
    """
    Used for creating new posts on the server
    """
    authenticate(request, username, password)

    config = request.getConfiguration()
    if os.path.isdir(
            os.path.normpath(os.path.join(config['datadir'], blogid[1:]))):
        # Look at content
        blogTitle = content.split(LINEFEED)[0].strip()

        tempMarker = (not publish and '-' or '')
        blogID = os.path.normpath(
            os.path.join(
                config['datadir'], blogid[1:] +
                re.sub('[^A-Za-z0-9]', '_', blogTitle) + '.txt' + tempMarker))
        if os.path.isfile(blogID) or os.path.isfile(blogID + '-'):
            # Generate a ficticious blog name
            blogID = os.path.normpath(
                os.path.join(
                    config['datadir'],
                    blogid[1:] + re.sub('[^A-Za-z0-9]', '_', blogTitle) +
                    tools.generateRandStr() + '.txt' + tempMarker))
        open(blogID, 'w').write(content.encode(config['blog_encoding']))

        # Generate BlogID
        return blogID.replace(config['datadir'], '')
    else:
        raise xmlrpclib.Fault('PostError', 'Blog %s does not exist' % blogid)
Ejemplo n.º 6
0
 def test_generates_a_random_string(self):
     self._gen_checker(tools.generateRandStr(), 5, 10)
     self._gen_checker(tools.generateRandStr(), 5, 10)
     self._gen_checker(tools.generateRandStr(), 5, 10)
     self._gen_checker(tools.generateRandStr(), 5, 10)
     self._gen_checker(tools.generateRandStr(), 5, 10)