Commit d699e307 authored by Christophe Benz's avatar Christophe Benz Committed by Christophe Benz

use lower_case_with_underscores instead of mixedCase for methods (PEP 8)

parent e4846ff2
......@@ -23,7 +23,7 @@ class Backend:
def __init__(self, weboob):
self.weboob = weboob
def hasCaps(self, caps):
def has_caps(self, caps):
if not isinstance(caps, (list,tuple)):
caps = (caps,)
......
......@@ -66,57 +66,57 @@ class AdopteUnMec(Browser):
}
def login(self):
if not self.isOnPage(LoginPage):
if not self.is_on_page(LoginPage):
self.home()
self.page.login(self.username, self.password)
def isLogged(self):
return not self.isOnPage(LoginPage)
def is_logged(self):
return not self.is_on_page(LoginPage)
def home(self):
return self.location('http://www.adopteunmec.com/home.php')
def pageaccess(func):
def inner(self, *args, **kwargs):
if self.isOnPage(WaitPage):
if self.is_on_page(WaitPage):
if not self.page.check():
raise AdopteWait()
self.home()
if not self.page or self.isOnPage(LoginPage) and self.password:
if not self.page or self.is_on_page(LoginPage) and self.password:
self.home()
return func(self, *args, **kwargs)
return inner
def register(self, nickname, password, sex, birthday_d, birthday_m, birthday_y, zipcode, country, godfather=''):
if not self.isOnPage(RegisterPage):
if not self.is_on_page(RegisterPage):
self.location('http://www.adopteunmec.com/register2.php')
return self.page.register(nickname, password, sex, birthday_d, birthday_m, birthday_y, zipcode, country, godfather)
@pageaccess
def addPhoto(self, name, f):
if not self.isOnPage(EditPhotoPage):
def add_photo(self, name, f):
if not self.is_on_page(EditPhotoPage):
self.location('/edit.php?type=1')
return self.page.addPhoto(name, f)
return self.page.add_photo(name, f)
@pageaccess
def setNickname(self, nickname):
if not self.isOnPage(EditAnnouncePage):
def set_nickname(self, nickname):
if not self.is_on_page(EditAnnouncePage):
self.location('/edit.php?type=2')
return self.page.setNickname(nickname)
return self.page.set_nickname(nickname)
@pageaccess
def setAnnounce(self, title=None, description=None, lookingfor=None):
if not self.isOnPage(EditAnnouncePage):
def set_announce(self, title=None, description=None, lookingfor=None):
if not self.is_on_page(EditAnnouncePage):
self.location('/edit.php?type=2')
return self.page.setAnnounce(title, description, lookingfor)
return self.page.set_announce(title, description, lookingfor)
@pageaccess
def setDescription(self, **args):
if not self.isOnPage(EditDescriptionPage):
def set_description(self, **args):
if not self.is_on_page(EditDescriptionPage):
self.location('/edit.php?type=3')
return self.page.setDescription(**args)
return self.page.set_description(**args)
@pageaccess
def score(self):
......@@ -125,75 +125,75 @@ class AdopteUnMec(Browser):
return self.page.score()
@pageaccess
def getMyName(self):
def get_my_name(self):
if time.time() - self.__last_update > 60:
self.home()
return self.page.getMyName()
return self.page.get_my_name()
@pageaccess
def getMyID(self):
if not self.isOnPage(HomePage):
def get_my_id(self):
if not self.is_on_page(HomePage):
self.home()
return self.page.getMyID()
return self.page.get_my_id()
@pageaccess
def nbNewMails(self):
def nb_new_mails(self):
if time.time() - self.__last_update > 60:
self.home()
return self.page.nbNewMails()
return self.page.nb_new_mails()
@pageaccess
def nbNewBaskets(self):
def nb_new_baskets(self):
if time.time() - self.__last_update > 60:
self.home()
return self.page.nbNewBaskets()
return self.page.nb_new_baskets()
@pageaccess
def nbNewVisites(self):
def nb_new_visites(self):
if time.time() - self.__last_update > 60:
self.home()
return self.page.nbNewVisites()
return self.page.nb_new_visites()
@pageaccess
def nbAvailableCharms(self):
def nb_available_charms(self):
self.home()
return self.page.nbAvailableCharms()
return self.page.nb_available_charms()
@pageaccess
def getBaskets(self):
def get_baskets(self):
self.location('/mails.php?type=1')
return self.page.getProfilesIDsList()
return self.page.get_profiles_ids_list()
@pageaccess
def flushVisits(self):
def flush_visits(self):
""" Does nothing, only flush new visits to increase my score """
self.openurl('/mails.php?type=3')
@pageaccess
def getContactList(self):
if not self.isOnPage(ContactListPage):
def get_contact_list(self):
if not self.is_on_page(ContactListPage):
self.location('/mails.php')
return self.page.getContactList()
return self.page.get_contact_list()
@pageaccess
def getThreadMails(self, id):
self.page.openThreadPage(id)
return self.page.getMails()
def get_thread_mails(self, id):
self.page.open_thread_page(id)
return self.page.get_mails()
@pageaccess
def postMail(self, id, content):
self.page.openThreadPage(id)
def post_mail(self, id, content):
self.page.open_thread_page(id)
self.page.post(content)
@pageaccess
def sendCharm(self, id):
def send_charm(self, id):
result = self.openurl('http://www.adopteunmec.com/fajax_addBasket.php?id=%s' % id).read()
warning('Charm: %s' % result)
return result.find('noMoreFlashes') < 0
@pageaccess
def addBasket(self, id):
def add_basket(self, id):
result = self.openurl('http://www.adopteunmec.com/fajax_addBasket.php?id=%s' % id).read()
warning('Basket: %s' % result)
# TODO check if it works (but it should)
......@@ -212,20 +212,20 @@ class AdopteUnMec(Browser):
return float(result)
@pageaccess
def searchProfiles(self, **kwargs):
def search_profiles(self, **kwargs):
self.location('/search.php?display=1')
self.page.search(**kwargs)
return self.page.getProfilesIDs()
return self.page.get_profiles_ids()
@pageaccess
def getProfile(self, link):
def get_profile(self, link):
if isinstance(link, (str,unicode)) and link.startswith('/'):
link = link[1:]
self.location('/%s' % link)
return self.page
@pageaccess
def getSlutState(self, id):
def get_slut_state(self, id):
result = self.openurl('http://www.adopteunmec.com/%s' % id).read()
if result.find('<td align="right" style="font-size:12px;font-weight:bold">en ligne</td>') >= 0:
r = 'online'
......@@ -242,7 +242,7 @@ class AdopteUnMec(Browser):
return r
@pageaccess
def isSlutOnline(self, id):
def is_slut_online(self, id):
result = self.openurl('http://www.adopteunmec.com/%s' % id).read()
r = result.find('<td align="right" style="font-size:12px;font-weight:bold">en ligne</td>') >= 0
print 'isSlutOnline(%s) = %s' % (id, r)
......
......@@ -25,5 +25,5 @@ class AuMBackend(Backend, ICapMessages, ICapMessagesReply):
def __init__(self, weboob):
Backend.__init__(self, weboob)
def iterNewMessages(self, thread=None):
def iter_new_messages(self, thread=None):
pass
......@@ -34,36 +34,36 @@ class Mail:
self.content = ''
self.date = datetime.datetime.utcnow()
def getDateInt(self):
return int(time.strftime('%Y%m%d%H%M%S', self.getDate().timetuple()))
def get_date_int(self):
return int(time.strftime('%Y%m%d%H%M%S', self.get_date().timetuple()))
def getMsgID(self, sender):
return '<%s.%d@%s>' % (self.getDateInt(), self.id, sender)
def get_msg_id(self, sender):
return '<%s.%d@%s>' % (self.get_date_int(), self.id, sender)
def getReplyID(self, sender):
def get_reply_id(self, sender):
if self.reply_date:
return '<%s.%d@%s>' % (self.reply_date, self.id, sender)
else:
return ''
def getID(self):
def get_id(self):
return self.id
def getName(self):
def get_name(self):
return self.name
def getDate(self):
def get_date(self):
return self.date
def getProfileLink(self):
def get_profile_link(self):
return self.profile_link
def getFrom(self):
def get_from(self):
return self.sender
def getContent(self):
def get_content(self):
return self.content
def isNew(self):
def is_new(self):
return self.new
......@@ -23,10 +23,10 @@ from logging import error, warning
from weboob.tools.browser import BasePage
class PageBase(BasePage):
def openContactListPage(self):
def open_contact_list_page(self):
self.browser.follow_link(url_regex=r"/mails.php$")
def openThreadPage(self, id):
def open_thread_page(self, id):
self.browser.location('/thread.php?id=%d' % int(id))
def score(self):
......@@ -70,7 +70,7 @@ class PageBase(BasePage):
return 0
MYNAME_REGEXP = re.compile("Bonjour (.*)")
def getMyName(self):
def get_my_name(self):
""" <span class=header2>Bonjour Romain</span> """
tags = self.document.getElementsByTagName('span')
......@@ -83,14 +83,14 @@ class PageBase(BasePage):
warning('Warning: Unable to fetch name')
return '?'
def nbNewMails(self):
def nb_new_mails(self):
return self.__get_indicator(u'mailsCounter')
def nbNewBaskets(self):
def nb_new_baskets(self):
return self.__get_indicator(u'flashsCounter')
def nbNewVisites(self):
def nb_new_visites(self):
return self.__get_indicator(u'visitesCounter')
......@@ -54,7 +54,7 @@ class ContactItem:
return self.tr.getElementsByTagName('td')[self.fields.index(id)]
def getName(self):
def get_name(self):
tag = self.__get_element('name')
node = tag.getElementsByTagName('b')[0].firstChild
if node:
......@@ -65,24 +65,24 @@ class ContactItem:
return name
def getStatus(self):
def get_status(self):
tag = self.__get_element('status')
return tag.firstChild.data
def isNew(self):
return self.getStatus() == u'nouveau'
def is_new(self):
return self.get_status() == u'nouveau'
def isAnswered(self):
return self.getStatus() == u'répondu'
def is_answered(self):
return self.get_status() == u'répondu'
def getResume(self):
def get_resume(self):
tag = self.__get_element('resume')
return tag.getElementsByTagName('b')[0].firstChild.data.split('\n')[0]
def getID(self):
def get_id(self):
tag = self.__get_element('thread_link')
text = tag.getAttribute('onclick')
......@@ -113,5 +113,5 @@ class ContactListPage(PageBase):
self.items += [ContactItem(tag)]
def getContactList(self):
def get_contact_list(self):
return self.items
......@@ -113,7 +113,7 @@ class MailParser(Mail):
for child in td.childNodes[1].childNodes:
if hasattr(child, 'data'):
date += child.data
self.parseDate(date)
self.parse_date(date)
content = ''
for c in td.childNodes[3].childNodes:
if hasattr(c, 'data'):
......@@ -131,10 +131,10 @@ class MailParser(Mail):
self.content = content
break
self.parseProfileLink()
self.parseFrom()
self.parse_profile_link()
self.parse_from()
def parseDate(self, date_str):
def parse_date(self, date_str):
# To match regexp, we have to remove any return chars in string
......@@ -161,7 +161,7 @@ class MailParser(Mail):
else:
error('Error: unable to parse the datetime string "%s"' % date_str)
def parseProfileLink(self):
def parse_profile_link(self):
tables = self.tr.getElementsByTagName('div')
for table in tables:
......@@ -176,9 +176,9 @@ class MailParser(Mail):
self.profile_link = m.group(1)
return
warning('Unable to find the profile URL in the message %s@%s' % (self.getFrom(), self.getID()))
warning('Unable to find the profile URL in the message %s@%s' % (self.get_from(), self.get_id()))
def parseFrom(self):
def parse_from(self):
tds = self.tr.getElementsByTagName('div')
for td in tds:
......@@ -190,7 +190,7 @@ class MailParser(Mail):
return
warning('Warning: unable to find from in the mail %s' % self.getID())
warning('Warning: unable to find from in the mail %s' % self.get_id())
class ContactThreadPage(PageBase):
......@@ -308,9 +308,9 @@ class ContactThreadPage(PageBase):
mail = MailParser(self.id, self.name, tag)
if self.items:
self.items[-1].reply_date = mail.getDateInt()
self.items[-1].reply_date = mail.get_date_int()
self.items += [mail]
def getMails(self):
def get_mails(self):
return self.items
......@@ -21,7 +21,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
from weboob.backends.aum.pages.base import PageBase
class EditPhotoPage(PageBase):
def addPhoto(self, name, f):
def add_photo(self, name, f):
self.browser.select_form(name="form")
self.browser.find_control('uploaded').add_file(f, 'image/jpeg', name)
self.browser.submit()
......@@ -32,12 +32,12 @@ class EditPhotoCbPage(PageBase):
pass
class EditAnnouncePage(PageBase):
def setNickname(self, nickname):
def set_nickname(self, nickname):
self.browser.select_form(name="form")
self.browser['pseudo'] = nickname
self.browser.submit()
def setAnnounce(self, title=None, description=None, lookingfor=None):
def set_announce(self, title=None, description=None, lookingfor=None):
self.browser.select_form(name="form")
self.browser.set_field(kwargs, 'title')
self.browser.set_field(kwargs, 'description', field='about1')
......@@ -56,7 +56,7 @@ class EditDescriptionPage(PageBase):
DRINKS = ['--', 'jamais', 'de temps en temps', 'souvent', 'pilier de bar']
SMOKES = ['--', u'ne tolère pas la fumée', u'tolère la fumée', 'fume de temps en temps', 'fume souvent']
def setDescription(self, **kwargs):
def set_description(self, **kwargs):
self.browser.select_form(name='form')
self.browser.set_field(kwargs, 'height', field='size', is_list=True)
......
......@@ -27,7 +27,7 @@ class HomePage(PageBase):
MYID_REGEXP = re.compile("http://www.adopteunmec.com/\?mid=(\d+)")
def getMyID(self):
def get_my_id(self):
fonts = self.document.getElementsByTagName('font')
for font in fonts:
m = self.MYID_REGEXP.match(font.firstChild.data)
......@@ -37,7 +37,7 @@ class HomePage(PageBase):
error("Error: Unable to find my ID")
return 0
def nbAvailableCharms(self):
def nb_available_charms(self):
tables = self.document.getElementsByTagName('table')
for table in tables:
if table.hasAttribute('style') and table.getAttribute('style') == 'background-color:black;background-image:url(http://s.adopteunmec.com/img/barmec.gif);background-repeat:no-repeat':
......
......@@ -28,27 +28,27 @@ class FieldBase:
def __init__(self, key):
self.key = key
def putValue(self, d, value):
def put_value(self, d, value):
raise NotImplementedError
class FieldString(FieldBase):
def putValue(self, d, value):
def put_value(self, d, value):
d[self.key] = unicode(value)
class FieldList(FieldBase):
def putValue(self, d, value):
def put_value(self, d, value):
d[self.key] = value.split(', ')
class FieldWideList(FieldBase):
def putValue(self, d, value):
def put_value(self, d, value):
d[self.key] += [value]
class FieldOld(FieldBase):
regexp = re.compile(u'([0-9]+) ans( \(Née le ([0-9]+) ([^ ]+) ([0-9]+)\))?')
month2i = ['', 'janvier', u'février', 'mars', 'avril', 'mai', 'juin', 'juillet', u'août', 'septembre', 'octobre', 'novembre', u'décembre']
def putValue(self, d, value):
def put_value(self, d, value):
m = self.regexp.match(value)
warning(value)
if not m:
......@@ -70,7 +70,7 @@ class FieldLocation(FieldBase):
def __init__(self):
FieldBase.__init__(self, '')
def putValue(self, d, value):
def put_value(self, d, value):
# TODO: determine distance, or something like
m = self.location.match(value)
if m:
......@@ -88,7 +88,7 @@ class FieldMeasurements(FieldBase):
def __init__(self):
FieldBase.__init__(self, '')
def putValue(self, d, value):
def put_value(self, d, value):
for s in value.split(', '):
m = self.height.match(s)
if m:
......@@ -114,7 +114,7 @@ class FieldMeasurements(FieldBase):
class FieldParticularSignes(FieldBase):
def __init__(self): FieldBase.__init__(self, '')
def putValue(self, d, value):
def put_value(self, d, value):
for s in value.split(', '):
if s.find('tatouages') >= 0:
d['tatoos'] = True
......@@ -284,10 +284,10 @@ class ProfilePage(PageBase):
for div in divs:
if div.hasAttribute('id'):
if div.getAttribute('id') == 'about_div':
self.parseDescription(div)
self.parse_description(div)
if div.getAttribute('id').startswith('tab_'):
self.parseTable(div)
self.parse_table(div)
for tag in ('img', 'td'):
imgs = self.document.getElementsByTagName(tag)
......@@ -300,7 +300,7 @@ class ProfilePage(PageBase):
if self.id:
break
def parseDescription(self, div):
def parse_description(self, div):
# look for description
description = ''
......@@ -312,7 +312,7 @@ class ProfilePage(PageBase):
self.description = description
def parseTable(self, div):
def parse_table(self, div):
d = self.table[self.tables[div.getAttribute('id')]]
fields = self.fields[self.tables[div.getAttribute('id')]]
......@@ -354,7 +354,7 @@ class ProfilePage(PageBase):
if label1 and value2:
# This is a typically tuple of key/value on the line.
try:
fields[label1].putValue(d, value2)
fields[label1].put_value(d, value2)
except KeyError:
warning('Unable to find "%s" (%s)' % (label1, repr(label1)))
elif label1 and label2:
......@@ -365,45 +365,45 @@ class ProfilePage(PageBase):
elif not label1 and not label1:
# two values, so it is a line of values
if field1 and value1:
field1.putValue(d, value1)
field1.put_value(d, value1)
if field2 and value2:
field2.putValue(d, value2)
field2.put_value(d, value2)
def getName(self):
def get_name(self):
return self.name
def getDescription(self):
def get_description(self):
return self.description
def getTable(self):
def get_table(self):
return self.table
def getID(self):
def get_id(self):
return self.id
def getPhotos(self):
def get_photos(self):
return self.photos
def getStatus(self):
def get_status(self):
return self.status
def isOnline(self):
def is_online(self):
return self.status.find('en ligne') >= 0
def getStats(self):
def get_stats(self):
return self.stats
def getProfileText(self):
def get_profile_text(self):
body = u'Status: %s' % unicode(self.status)
if self.photos:
body += u'\nPhotos:'
for photo in self.photos:
body += u'\n\t\t%s' % unicode(photo)
body += u'\nStats:'
for label, value in self.getStats().iteritems():
for label, value in self.get_stats().iteritems():
body += u'\n\t\t%-15s %s' % (label + ':', value)
body += u'\n\nInformations:'
for section, d in self.getTable().iteritems():
for section, d in self.get_table().iteritems():
body += u'\n\t%s\n' % section
for key, value in d.items():
key = '%s:' % key
......@@ -413,7 +413,7 @@ class ProfilePage(PageBase):
body += u'\t\t%-15s %.2f\n' % (key, value)
else:
body += u'\t\t%-15s %s\n' % (key, unicode(value))
body += u'\n\nDescription:\n%s' % unicode(self.getDescription())
body += u'\n\nDescription:\n%s' % unicode(self.get_description())
return body
......
......@@ -43,8 +43,8 @@ class ProfilesListBase(PageBase):
m and (self.SHOW_WITHOUT_PHOTO or m.group(1) != self.WITHOUT_PHOTO):
self.id_list.append(url)
def getProfilesIDs(self):
def get_profiles_ids(self):
return set(self.id_list)
def getProfilesIDsList(self):
def get_profiles_ids_list(self):
return self.id_list
......@@ -31,7 +31,7 @@ class WaitPage(PageBase):
result = self.browser.openurl('http://www.adopteunmec.com/fajax_checkEnter.php?anticache=0.46168455299380795').read()
return result == 'Ok'
def processWait(self):
def process_wait(self):
while not self.check(self):
sleep(10)
......
......@@ -26,7 +26,8 @@ class DLFPBackend(Backend, ICapMessages, ICapMessagesReply):
def __init__(self, weboob):
Backend.__init__(self, weboob)
def iterNewMessages(self, thread=None):
def iter_new_messages(self, thread=None):
articles_list = ArticlesList('newspaper')
for id, author, title in articles_list.iter_articles():
yield Message('threadid', id, title, author, signature='Bite bite bite bite', content='Content content\nContent content.')
yield Message('threadid', id, title, author, signature='Bite bite bite bite',
content='Content content\nContent content.')
......@@ -36,5 +36,5 @@ class DLFP(Browser):
def login(self):
self.location('/login.html', 'login=%s&passwd=%s&isauto=1' % (self.username, self.password))
def isLogged(self):
return (self.page and self.page.isLogged())
def is_logged(self):
return (self.page and self.page.is_logged())
......@@ -21,7 +21,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
from weboob.tools.browser import BrowserIncorrectPassword, BasePage
class DLFPPage(BasePage):
def isLogged(self):
def is_logged(self):
forms = self.document.getElementsByTagName('form')
for form in forms:
if form.getAttribute('id') == 'formulaire':
......@@ -35,10 +35,10 @@ class IndexPage(DLFPPage):
class LoginPage(DLFPPage):
def loaded(self):
if self.hasError():
if self.has_error():
raise BrowserIncorrectPassword()
def hasError(self):
def has_error(self):
plist = self.document.getElementsByTagName('p')
for p in plist:
p = p.childNodes[0]
......