Skip to content

Commit

Permalink
wordpressrxmlrpc.py: MockPost() and ChangerPosting()
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandre-mbm committed Jul 14, 2015
1 parent d356389 commit c2c7c9a
Showing 1 changed file with 55 additions and 1 deletion.
56 changes: 55 additions & 1 deletion paicemana/wordpressrxmlrpc.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from wordpress_xmlrpc import Client
from wordpress_xmlrpc.methods import posts

import re


def test():

client = Client(
Expand All @@ -22,5 +25,56 @@ def test():
# https://github.com/maxcutler/python-wordpress-xmlrpc/


class MockPost(object):

def __init__(self):
from testwordpresscontent import src_title as title
from testwordpresscontent import src_content as content
self.title = title
self.content = content

def __str__(self):
return '\n%s\n\n%s\n' % (self.title, self.content)


class ChangerPosting(object):

def __init__(self, post, lang='Ja'):
self.post = post
self.lang = lang

def do(src, text, lang):
return re.sub(
r'^(.*)(<!--:%s-->)(.(?<!<\!--:-->))*?(<!--:-->)(.*)$' % lang,
r'\1\2%s\4\5' % text,
src,
flags = re.MULTILINE + re.DOTALL
)

def do_for(self, newTitle=None, newContent=None):
if newTitle:
self.post.title = ChangerPosting.do(
self.post.title,
newTitle,
self.lang
)
if newContent:
self.post.content = ChangerPosting.do(
self.post.content,
newContent,
self.lang
)

def print_test(self):
print(self.post)


if __name__ == "__main__":
test()
#test()
post = MockPost()
#print(post)
changer = ChangerPosting(post)
s = 'My text here'
changer.do_for(s, s)
changer.print_test()

0 comments on commit c2c7c9a

Please sign in to comment.