class EvervimEditor(object): """ editing buffertext """ _instance = None def __init__(self): if EvervimEditor._instance is not None: raise RuntimeError("EvervimPref must be one object!!!") self.api = None @classmethod def getInstance(self): if EvervimEditor._instance is None: EvervimEditor._instance = EvervimEditor() return EvervimEditor._instance def setAPI(self): pref = EvervimPref.getInstance() if EvervimPref.getInstance().username is None: raise AttributeError("username must be set!!") if EvervimPref.getInstance().password is None: raise AttributeError("password must be set!!") self.api = EvernoteAPI(pref.username, pref.password) def note2buffer(self, note): """ return strings array for buffer from note. """ """ note has attribute title, tagNames, content """ bufStrings = [] pref = EvervimPref.getInstance() doc = minidom.parseString(note.content) ennote = doc.getElementsByTagName("en-note")[0] if pref.usemarkdown == '0': bufStrings.append(note.title) bufStrings.append("Tags:" + ",".join(note.tagNames)) contentxml = ennote.toprettyxml(indent=pref.xmlindent, encoding='utf-8') contentxml = re.sub('^' + pref.xmlindent, '', contentxml, flags=re.MULTILINE) bufStrings.extend([line for line in contentxml.splitlines()[1:-1] if line.strip()]) else: bufStrings.append('# ' + note.title) bufStrings.append("Tags:" + ",".join(note.tagNames)) content = markdownAndENML.parseENML(ennote).encode('utf-8') bufStrings.extend(content.splitlines()) return bufStrings def buffer2note(self, note, buflines): """ return note that set title, tags, content from buftext """ pref = EvervimPref.getInstance() if pref.usemarkdown == '0': note.title = buflines[0] note = self.api.editTag(note, buflines[1].replace('Tags:', '')) note.content = EvernoteAPI.NOTECONTENT_HEADER + "\n".join(buflines[2:]) + EvernoteAPI.NOTECONTENT_FOOTER else: note.title = re.sub(r'^#', '',buflines[0]).strip() note = self.api.editTag(note, buflines[1].replace('Tags:', '')) parsedContent = markdownAndENML.parseMarkdown("\n".join(buflines[2:])) note.content = EvernoteAPI.NOTECONTENT_HEADER + parsedContent.encode('utf-8') + EvernoteAPI.NOTECONTENT_FOOTER return note
def setAPI(self): pref = EvervimPref.getInstance() if EvervimPref.getInstance().devtoken is None: raise AttributeError("devtoken must be set!!") self.api = EvernoteAPI( 'S=s72:U=dd4c83:E=16b968d716f:C=1643edc43a0:P=1cd:A=en-devtoken:V=2:H=3112905fcbf73376faa5fd27838d5f4d' )
def testAuth(self): # {{{ """ test auth """ self.api = EvernoteAPI(USERNAME, PASSWORD) self.api.auth() self.assertIsNotNone(self.api.user) self.assertIsNotNone(self.api.refreshAuthDataTime) self.assertIsNotNone(self.api.expirationDataTime)
def setAPI(self): pref = EvervimPref.getInstance() if EvervimPref.getInstance().username is None: raise AttributeError("username must be set!!") if EvervimPref.getInstance().password is None: raise AttributeError("password must be set!!") self.api = EvernoteAPI(pref.username, pref.password)
class EvervimEditor(object): """ editing buffertext """ _instance = None def __init__(self): if EvervimEditor._instance is not None: raise RuntimeError("EvervimPref must be one object!!!") self.api = None @classmethod def getInstance(self): if EvervimEditor._instance is None: EvervimEditor._instance = EvervimEditor() return EvervimEditor._instance def setAPI(self): pref = EvervimPref.getInstance() if EvervimPref.getInstance().devtoken is None: raise AttributeError("devtoken must be set!!") self.api = EvernoteAPI(self.devtoken) def note2buffer(self, note): """ return strings array for buffer from note. """ """ note has attribute title, tagNames, content """ bufStrings = [] pref = EvervimPref.getInstance() doc = minidom.parseString(note.content) ennote = doc.getElementsByTagName("en-note")[0] if pref.usemarkdown == '0': bufStrings.append(note.title) bufStrings.append("Tags:" + ",".join(note.tagNames)) contentxml = ennote.toprettyxml(indent=pref.xmlindent, encoding='utf-8') contentxml = re.sub('^' + pref.xmlindent, '', contentxml, flags=re.MULTILINE) bufStrings.extend([line for line in contentxml.splitlines()[1:-1] if line.strip()]) else: bufStrings.append('# ' + note.title) bufStrings.append("Tags:" + ",".join(note.tagNames)) content = markdownAndENML.parseENML(ennote).encode('utf-8') bufStrings.extend(content.splitlines()) return bufStrings def buffer2note(self, note, buflines): """ return note that set title, tags, content from buftext """ pref = EvervimPref.getInstance() if pref.usemarkdown == '0': note.title = buflines[0] note = self.api.editTag(note, buflines[1].replace('Tags:', '')) note.content = EvernoteAPI.NOTECONTENT_HEADER + "\n".join(buflines[2:]) + EvernoteAPI.NOTECONTENT_FOOTER else: note.title = re.sub(r'^#', '',buflines[0]).strip() note = self.api.editTag(note, buflines[1].replace('Tags:', '')) parsedContent = markdownAndENML.parseMarkdown("\n".join(buflines[2:])) note.content = EvernoteAPI.NOTECONTENT_HEADER + parsedContent + EvernoteAPI.NOTECONTENT_FOOTER return note
def testRefreshAuth(self): # {{{ self.api = EvernoteAPI(USERNAME, PASSWORD) self.api.auth() token = self.api.authToken refreshAuthDataTime = self.api.refreshAuthDataTime expirationDataTime = self.api.expirationDataTime self.api.refreshAuth() self.assertNotEqual(token, self.api.authToken) self.assertNotEqual(refreshAuthDataTime, self.api.refreshAuthDataTime) self.assertNotEqual(expirationDataTime, self.api.expirationDataTime)
def setAPI(self): pref = EvervimPref.getInstance() if pref.evernotehost is None: raise AttributeError("evernote_host must be set!!") if pref.developertoken is None: raise AttributeError("developer_token must be set!!") self.api = EvernoteAPI(pref.evernotehost, pref.developertoken)
def testRefreshAuth(self): # {{{ self.api = EvernoteAPI(USERNAME, PASSWORD) self.api.auth() token = self.api.authToken refreshAuthDataTime = self.api.refreshAuthDataTime expirationDataTime = self.api.expirationDataTime self.api.refreshAuth() self.assertNotEqual(token , self.api.authToken) self.assertNotEqual(refreshAuthDataTime , self.api.refreshAuthDataTime) self.assertNotEqual(expirationDataTime , self.api.expirationDataTime)
def testAuthFairueWrongToken(self): # {{{ self.api = EvernoteAPI("dummy tokens") self.assertRaises(Errors.EDAMUserException, lambda: {self.api.auth()})
def setUp(self): # {{{ self.api = EvernoteAPI(DEVELOPER_TOKEN)
class TestEvernoteAPI(unittest.TestCase): """ doc """ def setUp(self): # {{{ self.api = EvernoteAPI(DEVELOPER_TOKEN) #}}} def testAuthFairueWrongToken(self): # {{{ self.api = EvernoteAPI("dummy tokens") self.assertRaises(Errors.EDAMUserException, lambda: {self.api.auth()}) #}}} def testListNoteBooks(self): # {{{ notebooks = self.api.listNotebooks() self.assertIsInstance(notebooks, list) self.assertNotEquals(0, len(notebooks)) for notebook in notebooks: self.assertTrue(hasattr(notebook, 'guid')) self.assertTrue(hasattr(notebook, 'name')) #}}} def testListTags(self): # {{{ tags = self.api.listTags() self.assertIsInstance(tags, list) self.assertNotEquals(0, len(tags)) for tag in tags: self.assertTrue(hasattr(tag, 'guid')) self.assertTrue(hasattr(tag, 'name')) #}}} def testNotesByTag(self): # {{{ tags = self.api.listTags() notes = [] for tag in tags: [notes.append(note) for note in self.api.notesByTag(tag).elem] # less more 1 notes self.assertNotEquals(0, len(notes)) for note in notes: self.assertTrue(hasattr(note, 'guid')) #}}} def testNotesByNotebook(self): # {{{ notebooks = self.api.listNotebooks() notes = [] for notebook in notebooks: [ notes.append(note) for note in self.api.notesByNotebook(notebook).elem ] # less more 1 notes self.assertNotEquals(0, len(notes)) for note in notes: self.assertTrue(hasattr(note, 'guid')) #}}} def testNotesByQuery(self): # {{{ notes = self.api.notesByQuery('日本語').elem # less more 1 notes self.assertNotEquals(0, len(notes)) for note in notes: self.assertTrue(hasattr(note, 'guid')) #}}} def testGetNote(self): # {{{ note = self.__getOneNote() self.assertIsNone(note.content) notewithContent = self.api.getNote(note) self.assertIsNotNone(notewithContent.content) notewithContent.tagNames.append('google') self.api.updateNote(notewithContent) #}}} def testCreateNote(self): # {{{ note = Types.Note() editText = NOTECONTENT_HEADER + """this is content 日本語""" + NOTECONTENT_FOOTER note.title = "createNote" note.content = editText note = self.api.editTag(note, "tag1, newTag") createdNote = self.api.createNote(note) self.assertIsNotNone(createdNote.guid, None) getnote = Types.Note() getnote.guid = createdNote.guid self.assertIsNotNone(self.api.getNote(getnote)) #}}} def testWhenUpdateNoteTagDelete(self): # {{{ note = Types.Note() editText = NOTECONTENT_HEADER + """this is content 日本語""" + NOTECONTENT_FOOTER note.title = "createNote" note.content = editText note = self.api.editTag(note, "tag1, newTag") createdNote = self.api.createNote(note) editTextNoTag = NOTECONTENT_HEADER + """this is content updated""" + NOTECONTENT_FOOTER createdNote.title = 'createNoteUpdated' createdNote.content = editTextNoTag createdNote = self.api.editTag(createdNote, "") self.api.updateNote(createdNote) getnote = Types.Note() getnote.guid = createdNote.guid getnote = self.api.getNote(getnote) self.assertIsNotNone(getnote) self.assertIsNone(getnote.tagGuids) #}}} def __getOneNote(self): # {{{ notes = self.api.notesByQuery('日本語').elem self.assertNotEquals(0, len(notes)) for note in notes: return note #}}} def testEvernoteList(self): # {{{ evernoteList = EvernoteList() self.assertTrue(hasattr(evernoteList, 'elem')) self.assertTrue(hasattr(evernoteList, 'maxcount')) self.assertTrue(hasattr(evernoteList, 'maxpages')) self.assertTrue(hasattr(evernoteList, 'currentpage')) #}}} def testNoteList2EvernoteList(self): # {{{ class dummy(object): pass noteList = dummy() setattr(noteList, 'notes', []) setattr(noteList, 'totalNotes', 1) setattr(noteList, 'startIndex', 0) # test of private method! evernoteList = self.api._EvernoteAPI__NoteList2EvernoteList(noteList) self.assertEqual(evernoteList.maxpages, 0) self.assertEqual(evernoteList.currentpage, 0) setattr(noteList, 'totalNotes', 50) # 0 - 50 -> 0 ( 0 is none ) evernoteList = self.api._EvernoteAPI__NoteList2EvernoteList(noteList) self.assertEqual(evernoteList.maxpages, 0) setattr(noteList, 'totalNotes', 51) # 51 - 100 -> 1 evernoteList = self.api._EvernoteAPI__NoteList2EvernoteList(noteList) self.assertEqual(evernoteList.maxpages, 1) setattr(noteList, 'totalNotes', 100) # 101 - 150 -> 2 evernoteList = self.api._EvernoteAPI__NoteList2EvernoteList(noteList) self.assertEqual(evernoteList.maxpages, 1) setattr(noteList, 'totalNotes', 151) evernoteList = self.api._EvernoteAPI__NoteList2EvernoteList(noteList) self.assertEqual(evernoteList.maxpages, 3) setattr(noteList, 'startIndex', 49) # 0 - 49 -> 0index is start from 0 evernoteList = self.api._EvernoteAPI__NoteList2EvernoteList(noteList) self.assertEqual(evernoteList.currentpage, 0) setattr(noteList, 'startIndex', 50) # 50 - 99 -> 1 evernoteList = self.api._EvernoteAPI__NoteList2EvernoteList(noteList) self.assertEqual(evernoteList.currentpage, 1) setattr(noteList, 'startIndex', 100) evernoteList = self.api._EvernoteAPI__NoteList2EvernoteList(noteList) self.assertEqual(evernoteList.currentpage, 2) setattr(noteList, 'startIndex', 101) evernoteList = self.api._EvernoteAPI__NoteList2EvernoteList(noteList) self.assertEqual(evernoteList.currentpage, 2)
class TestEvernoteAPI(unittest.TestCase): """ doc """ def setUp(self): #{{{ self.api = EvernoteAPI(USERNAME, PASSWORD) #}}} # def testAuth(self): #{{{ # """ test auth """ # self.api.auth() # self.assertIsNotNone(self.api.user) # self.assertIsNotNone(self.api.authToken) # #}}} # def testAuthFairueByUsername(self): #{{{ # try: # failureApi = EvernoteAPI('wrong_user_name_xxxxxxxx', PASSWORD) # self.assertTrue(false) # must be exception # except StandardError: # pass # #}}} # def testAuthFairueByPassword(self): #{{{ # try: # failureApi = EvenoteAPI(USERNAME, 'wrong_user_name_xxxxxxxx') # self.assertTrue(false) # must be exception # except StandardError: # pass # #}}} # # def testListNoteBooks(self): #{{{ # notebooks = self.api.listNotebooks() # self.assertIsInstance(notebooks, list) # self.assertNotEquals(0, len(notebooks)) # for notebook in notebooks: # self.assertTrue(hasattr(notebook,'guid')) # self.assertTrue(hasattr(notebook,'name')) # #}}} # def testListTags(self): #{{{ # tags = self.api.listTags() # self.assertIsInstance(tags , list) # self.assertNotEquals(0, len(tags)) # for tag in tags: # self.assertTrue(hasattr(tag,'guid')) # self.assertTrue(hasattr(tag,'name')) # # #}}} # # def testNotesByTag(self): #{{{ # tags = self.api.listTags() # notes = [] # for tag in tags: # [notes.append(note) for note in self.api.notesByTag(tag)] # # less more 1 notes # self.assertNotEquals(0, len(notes)) # for note in notes: # self.assertTrue(hasattr(note, 'guid')) # #}}} # def testNotesByNotebook(self): #{{{ # notebooks = self.api.listNotebooks() # notes = [] # for notebook in notebooks: # [notes.append(note) for note in self.api.notesByNotebook(notebook)] # # less more 1 notes # self.assertNotEquals(0, len(notes)) # for note in notes: # self.assertTrue(hasattr(note, 'guid')) # #}}} # # def testNotesByQuery(self): #{{{ # notes = self.api.notesByQuery('日本語') # # less more 1 notes # self.assertNotEquals(0, len(notes)) # for note in notes: # self.assertTrue(hasattr(note, 'guid')) # #}}} # def testGetNote(self): #{{{ # note = self.__getOneNote() # self.assertIsNone(note.content) # notewithContent = self.api.getNote(note) # self.assertIsNotNone(notewithContent.content) # notewithContent.tagNames.append('google') # self.api.updateNote(notewithContent) # #}}} # def testEditNoteIllegalParameter(self): #{{{ # note = self.__getOneNote() # try: # self.assertRaises(StandardError, self.api.editNote(note, "1 line")) # except StandardError: # pass # try: # self.assertRaises(StandardError, self.api.editNote(note, "2 line\n 2")) # except StandardError: # pass # self.api.editNote(note, "3 line\n 1 \n 2") # self.assertTrue(True) # #}}} def testEditNote(self): #{{{ return # FIXME note = self.__getOneNote() notewithContent = self.api.getNote(note) content = minidom.parseString(notewithContent.content) editText = """this is test tag1, newTag """ + NOTECONTENT_HEADER + """this is content 日本語オーケー 追加部分""" + NOTECONTENT_FOOTER self.api.editNote(notewithContent, editText) self.assertListEqual(notewithContent.tagNames, []) self.assertNotEqual(0, len(notewithContent.guid)) self.assertEqual(notewithContent.title, 'this is test') self.assertEqual(notewithContent.content, NOTECONTENT_HEADER + """this is content 日本語オーケー 追加部分""" + NOTECONTENT_FOOTER) self.api.updateNote(notewithContent) self.assertTrue(True) #}}} def testCreateNote(self): #{{{ # return # FIXME note = Types.Note() editText = """createNote tag1, newTag """ + NOTECONTENT_HEADER + """this is content 日本語"""+ NOTECONTENT_FOOTER note = self.api.editNote(note, editText) createdNote = self.api.createNote(note) self.assertIsNotNone(createdNote.guid, None) getnote = Types.Note() getnote.guid = createdNote.guid self.assertIsNotNone(self.api.getNote(getnote)) #}}} def testWhenUpdateNoteTagDelete(self): #{{{ return # FIXME note = Types.Note() editText = """createNote tag1, newTag this is content 日本語""" note = self.api.editNote(note, editText) createdNote = self.api.createNote(note) editTextNoTag = """createNoteUpdated this is content updated""" createdNote = self.api.editNote(createdNote, editTextNoTag) self.api.updateNote(createdNote) getnote = Types.Note() getnote.guid = createdNote.guid getnote = self.api.getNote(getnote) self.assertIsNotNone(getnote) self.assertIsNone(getnote.tagGuids) #}}} def __getOneNote(self): #{{{ notes = self.api.notesByQuery('日本語') self.assertNotEquals(0, len(notes)) for note in notes: return note
def setAPI(self): pref = EvervimPref.getInstance() if EvervimPref.getInstance().devtoken is None: raise AttributeError("devtoken must be set!!") self.api = EvernoteAPI(pref.devtoken)
def setUp(self): # {{{ self.api = EvernoteAPI()
def testAuthFairueByUsername(self): # {{{ api = EvernoteAPI('wrong_user_name_xxxxxxxx', PASSWORD) self.assertRaises(StandardError, lambda: {api.auth()})
def setUp(self): # {{{ self.api = EvernoteAPI(USERNAME, PASSWORD)
def setAPI(self): pref = EvervimPref.getInstance() if EvervimPref.getInstance().devtoken is None: raise AttributeError("devtoken must be set!!") self.api = EvernoteAPI(pref.devtoken, pref.host)
class TestEvernoteAPI(unittest.TestCase): """ doc """ def setUp(self): # {{{ self.api = EvernoteAPI(USERNAME, PASSWORD) #}}} def testAuth(self): # {{{ """ test auth """ self.api = EvernoteAPI(USERNAME, PASSWORD) self.api.auth() self.assertIsNotNone(self.api.user) self.assertIsNotNone(self.api.refreshAuthDataTime) self.assertIsNotNone(self.api.expirationDataTime) #}}} def testRefreshAuth(self): # {{{ self.api = EvernoteAPI(USERNAME, PASSWORD) self.api.auth() token = self.api.authToken refreshAuthDataTime = self.api.refreshAuthDataTime expirationDataTime = self.api.expirationDataTime self.api.refreshAuth() self.assertNotEqual(token , self.api.authToken) self.assertNotEqual(refreshAuthDataTime , self.api.refreshAuthDataTime) self.assertNotEqual(expirationDataTime , self.api.expirationDataTime) #}}} def testAuthFairueByUsername(self): # {{{ api = EvernoteAPI('wrong_user_name_xxxxxxxx', PASSWORD) self.assertRaises(StandardError, lambda: {api.auth()}) #}}} def testAuthFairueByPassword(self): # {{{ api = EvernoteAPI(USERNAME, 'wrong_user_name_xxxxxxxx') self.assertRaises(StandardError, lambda: {api.auth()}) #}}} def testListNoteBooks(self): # {{{ notebooks = self.api.listNotebooks() self.assertIsInstance(notebooks, list) self.assertNotEquals(0, len(notebooks)) for notebook in notebooks: self.assertTrue(hasattr(notebook, 'guid')) self.assertTrue(hasattr(notebook, 'name')) #}}} def testListTags(self): # {{{ tags = self.api.listTags() self.assertIsInstance(tags , list) self.assertNotEquals(0, len(tags)) for tag in tags: self.assertTrue(hasattr(tag, 'guid')) self.assertTrue(hasattr(tag, 'name')) #}}} def testNotesByTag(self): # {{{ tags = self.api.listTags() notes = [] for tag in tags: [notes.append(note) for note in self.api.notesByTag(tag).elem] # less more 1 notes self.assertNotEquals(0, len(notes)) for note in notes: self.assertTrue(hasattr(note, 'guid')) #}}} def testNotesByNotebook(self): # {{{ notebooks = self.api.listNotebooks() notes = [] for notebook in notebooks: [notes.append(note) for note in self.api.notesByNotebook(notebook).elem] # less more 1 notes self.assertNotEquals(0, len(notes)) for note in notes: self.assertTrue(hasattr(note, 'guid')) #}}} def testNotesByQuery(self): # {{{ notes = self.api.notesByQuery('日本語').elem # less more 1 notes self.assertNotEquals(0, len(notes)) for note in notes: self.assertTrue(hasattr(note, 'guid')) #}}} def testGetNote(self): # {{{ note = self.__getOneNote() self.assertIsNone(note.content) notewithContent = self.api.getNote(note) self.assertIsNotNone(notewithContent.content) notewithContent.tagNames.append('google') self.api.updateNote(notewithContent) #}}} def testCreateNote(self): # {{{ note = Types.Note() editText = NOTECONTENT_HEADER + """this is content 日本語""" + NOTECONTENT_FOOTER note.title = "createNote" note.content = editText note = self.api.editTag(note, "tag1, newTag") createdNote = self.api.createNote(note) self.assertIsNotNone(createdNote.guid, None) getnote = Types.Note() getnote.guid = createdNote.guid self.assertIsNotNone(self.api.getNote(getnote)) #}}} def testWhenUpdateNoteTagDelete(self): # {{{ note = Types.Note() editText = NOTECONTENT_HEADER + """this is content 日本語""" + NOTECONTENT_FOOTER note.title = "createNote" note.content = editText note = self.api.editTag(note, "tag1, newTag") createdNote = self.api.createNote(note) editTextNoTag = NOTECONTENT_HEADER + """this is content updated""" + NOTECONTENT_FOOTER createdNote.title = 'createNoteUpdated' createdNote.content = editTextNoTag createdNote = self.api.editTag(createdNote, "") self.api.updateNote(createdNote) getnote = Types.Note() getnote.guid = createdNote.guid getnote = self.api.getNote(getnote) self.assertIsNotNone(getnote) self.assertIsNone(getnote.tagGuids) #}}} def __getOneNote(self): # {{{ notes = self.api.notesByQuery('日本語').elem self.assertNotEquals(0, len(notes)) for note in notes: return note #}}} def testEvernoteList(self): # {{{ evernoteList = EvernoteList() self.assertTrue(hasattr(evernoteList, 'elem')) self.assertTrue(hasattr(evernoteList, 'maxcount')) self.assertTrue(hasattr(evernoteList, 'maxpages')) self.assertTrue(hasattr(evernoteList, 'currentpage')) #}}} def testNoteList2EvernoteList(self): # {{{ class dummy(object): pass noteList = dummy() setattr(noteList , 'notes', []) setattr(noteList , 'totalNotes', 1) setattr(noteList , 'startIndex', 0) # test of private method! evernoteList = self.api._EvernoteAPI__NoteList2EvernoteList(noteList) self.assertEqual(evernoteList.maxpages, 0) self.assertEqual(evernoteList.currentpage, 0) setattr(noteList , 'totalNotes', 50) # 0 - 50 -> 0 ( 0 is none ) evernoteList = self.api._EvernoteAPI__NoteList2EvernoteList(noteList) self.assertEqual(evernoteList.maxpages, 0) setattr(noteList , 'totalNotes', 51) # 51 - 100 -> 1 evernoteList = self.api._EvernoteAPI__NoteList2EvernoteList(noteList) self.assertEqual(evernoteList.maxpages, 1) setattr(noteList , 'totalNotes', 100) # 101 - 150 -> 2 evernoteList = self.api._EvernoteAPI__NoteList2EvernoteList(noteList) self.assertEqual(evernoteList.maxpages, 1) setattr(noteList , 'totalNotes', 151) evernoteList = self.api._EvernoteAPI__NoteList2EvernoteList(noteList) self.assertEqual(evernoteList.maxpages, 3) setattr(noteList , 'startIndex', 49) # 0 - 49 -> 0index is start from 0 evernoteList = self.api._EvernoteAPI__NoteList2EvernoteList(noteList) self.assertEqual(evernoteList.currentpage, 0) setattr(noteList , 'startIndex', 50) # 50 - 99 -> 1 evernoteList = self.api._EvernoteAPI__NoteList2EvernoteList(noteList) self.assertEqual(evernoteList.currentpage, 1) setattr(noteList , 'startIndex', 100) evernoteList = self.api._EvernoteAPI__NoteList2EvernoteList(noteList) self.assertEqual(evernoteList.currentpage, 2) setattr(noteList , 'startIndex', 101) evernoteList = self.api._EvernoteAPI__NoteList2EvernoteList(noteList) self.assertEqual(evernoteList.currentpage, 2)
def testAuthFairueByPassword(self): # {{{ api = EvernoteAPI(USERNAME, 'wrong_user_name_xxxxxxxx') self.assertRaises(StandardError, lambda: {api.auth()})
def testAuthFairueByPassword(self): # {{{ api = EvernoteAPI() self.assertRaises(StandardError, lambda: {api.auth()})
class EvervimEditor(object): """ editing buffertext """ _instance = None def __init__(self): if EvervimEditor._instance is not None: raise RuntimeError("EvervimPref must be one object!!!") self.api = None @classmethod def getInstance(self): if EvervimEditor._instance is None: EvervimEditor._instance = EvervimEditor() return EvervimEditor._instance def setAPI(self): pref = EvervimPref.getInstance() if EvervimPref.getInstance().devtoken is None: raise AttributeError("devtoken must be set!!") self.api = EvernoteAPI(pref.devtoken) def note2buffer(self, note): """ return strings array for buffer from note. """ """ note has attribute title, tagNames, content """ bufStrings = [] pref = EvervimPref.getInstance() doc = minidom.parseString(note.content) ennote = doc.getElementsByTagName("en-note")[0] if pref.usemarkdown == '0': bufStrings.append(note.title) bufStrings.append("Tags:" + ",".join(note.tagNames)) contentxml = ennote.toprettyxml(indent=pref.xmlindent, encoding='utf-8') contentxml = re.sub('^' + pref.xmlindent, '', contentxml, flags=re.MULTILINE) bufStrings.extend([line for line in contentxml.splitlines()[1:-1] if line.strip()]) else: bufStrings.append('# ' + note.title) bufStrings.append("Tags:" + ",".join(note.tagNames)) # content = markdownAndENML.parseENML(ennote).encode('utf-8') try: divs = doc.getElementsByTagName("div") original_content = base64.b64decode(divs[-1].firstChild.nodeValue).split("\n") bufStrings.extend(original_content) except: self.__appendRestoreErrorMessage(bufStrings) contentxml = ennote.toprettyxml(indent=pref.xmlindent, encoding='utf-8') contentxml = re.sub('^' + pref.xmlindent, '', contentxml, flags=re.MULTILINE) bufStrings.extend([line for line in contentxml.splitlines()[1:-1] if line.strip()]) return bufStrings def __appendRestoreErrorMessage(self, bufStrings): bufStrings.append('*****************************************************') bufStrings.append('* THIS NOTE IS BROKEN OR IS NOT CREATED BY evervim. *') bufStrings.append('* YOU MUST NOT EDIT THIS NOTE !! *') bufStrings.append('*****************************************************') def buffer2note(self, note, buflines): """ return note that set title, tags, content from buftext """ pref = EvervimPref.getInstance() if pref.usemarkdown == '0': note.title = buflines[0] note = self.api.editTag(note, buflines[1].replace('Tags:', '')) note.content = EvernoteAPI.NOTECONTENT_HEADER + "\n".join(buflines[2:]) + EvernoteAPI.NOTECONTENT_FOOTER else: note.title = re.sub(r'^#', '',buflines[0]).strip() note = self.api.editTag(note, buflines[1].replace('Tags:', '')) parsedContent = markdownAndENML.parseMarkdown("\n".join(buflines[2:])) contents = buflines[2:] encoded_contents = base64.b64encode("\n".join(contents)) parsedContent = markdownAndENML.parseMarkdown("\n".join(contents)) parsedContent += ('\n<div style="display: none;">' + encoded_contents + '</div>') with open(os.path.dirname(__file__) + '/../../css/default.css', "r") as f: css = f.read() parsedContent = emailipy.inline_css(parsedContent, css) """ html tag and class attribute is not permitted in ENML """ parsedContent = re.sub('</?html[^>]*>', '', parsedContent) parsedContent = re.sub('class="[^"]*"', '', parsedContent) note.content = EvernoteAPI.NOTECONTENT_HEADER + parsedContent.encode('utf-8') + EvernoteAPI.NOTECONTENT_FOOTER return note