Skip to content
This repository was archived by the owner on Apr 25, 2024. It is now read-only.

Commit ee51c7b

Browse files
alperenkoseAlp Kose
authored andcommitted
Merge pull request #1 from alperenkose/3.0
Python 3 Support
2 parents 6c8b487 + 4d7c9e0 commit ee51c7b

20 files changed

+210
-199
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
Important Note
2+
===
3+
This is an updated version of geeknote for Python 3 using evernote-sdk-python3 (which is also in beta). Even though things are not throughly tested, basic functionality works.
4+
15
Geeknote for Evernote (or 印象笔记) [![Travis CI](https://travis-ci.org/jeffkowalski/geeknote.svg?branch=master)](https://travis-ci.org/jeffkowalski/geeknote) [![Circle CI](https://circleci.com/gh/jeffkowalski/geeknote.svg?&style=shield)](https://circleci.com/gh/jeffkowalski/geeknote)
26
===
37

geeknote/argparser.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# -*- coding: utf-8 -*-
22

3-
from log import logging
4-
import out
3+
from .log import logging
4+
from . import out
55

66

77
COMMANDS_DICT = {
@@ -442,7 +442,7 @@ def __init__(self, sys_argv):
442442
self.INPUT = sys_argv
443443

444444
# list of commands
445-
self.CMD_LIST = self.COMMANDS.keys()
445+
self.CMD_LIST = list(self.COMMANDS.keys())
446446
# command
447447
self.CMD = None if self.LVL == 0 else self.INPUT[0]
448448
# list of possible arguments of the command line
@@ -497,7 +497,7 @@ def parse(self):
497497
return False
498498

499499
# prepare data
500-
for arg, params in self.CMD_ARGS.items() + self.CMD_FLAGS.items():
500+
for arg, params in list(self.CMD_ARGS.items()) + list(self.CMD_FLAGS.items()):
501501
# set values by default
502502
if "default" in params:
503503
self.INP_DATA[arg] = params["default"]
@@ -514,7 +514,7 @@ def parse(self):
514514
if len(self.INP) > 0:
515515
# Check that first argument is a default argument
516516
# and another argument.
517-
if self.INP[0] not in (self.CMD_ARGS.keys() + self.CMD_FLAGS.keys()):
517+
if self.INP[0] not in (list(self.CMD_ARGS.keys()) + list(self.CMD_FLAGS.keys())):
518518
self.INP = [firstArg] + self.INP
519519
else:
520520
self.INP = [firstArg]
@@ -592,23 +592,23 @@ def parse(self):
592592
return False
593593

594594
# check whether there is a necessary argument request
595-
for arg, params in self.CMD_ARGS.items() + self.CMD_FLAGS.items():
595+
for arg, params in list(self.CMD_ARGS.items()) + list(self.CMD_FLAGS.items()):
596596
if "required" in params and arg not in self.INP:
597597
self.printErrorReqArgument(arg)
598598
return False
599599

600600
# trim -- and ->_
601601
self.INP_DATA = dict(
602602
[key.lstrip("-").replace("-", "_"), val]
603-
for key, val in self.INP_DATA.items()
603+
for key, val in list(self.INP_DATA.items())
604604
)
605605
return self.INP_DATA
606606

607607
def printAutocomplete(self):
608608
# checking later values
609609
LAST_VAL = self.INP[-1] if self.LVL > 1 else None
610610
PREV_LAST_VAL = self.INP[-2] if self.LVL > 2 else None
611-
ARGS_FLAGS_LIST = self.CMD_ARGS.keys() + self.CMD_FLAGS.keys()
611+
ARGS_FLAGS_LIST = list(self.CMD_ARGS.keys()) + list(self.CMD_FLAGS.keys())
612612

613613
# print root grid
614614
if self.CMD is None:
@@ -649,7 +649,7 @@ def printAutocomplete(self):
649649

650650
# processing of the arguments
651651
else:
652-
print "" # "Please_input_%s" % INP_ARG.replace('-', '')
652+
print("") # "Please_input_%s" % INP_ARG.replace('-', '')
653653

654654
def printGrid(self, list):
655655
out.printLine(" ".join(list))
@@ -678,7 +678,7 @@ def printErrorArgument(self, errorArg, errorVal=None):
678678

679679
def printHelp(self):
680680
if self.CMD is None or self.CMD not in self.COMMANDS:
681-
tab = len(max(self.COMMANDS.keys(), key=len))
681+
tab = len(max(list(self.COMMANDS.keys()), key=len))
682682
out.printLine("Available commands:")
683683
for cmd in sorted(self.COMMANDS):
684684
out.printLine(
@@ -687,7 +687,7 @@ def printHelp(self):
687687

688688
else:
689689

690-
tab = len(max(self.CMD_ARGS.keys() + self.CMD_FLAGS.keys(), key=len))
690+
tab = len(max(list(self.CMD_ARGS.keys()) + list(self.CMD_FLAGS.keys()), key=len))
691691

692692
out.printLine("Options for: %s" % self.CMD)
693693
out.printLine("Available arguments:")

geeknote/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
try:
9090
if not os.path.exists(APP_DIR):
9191
os.mkdir(APP_DIR)
92-
except Exception, e:
92+
except Exception as e:
9393
sys.stdout.write("Cannot create application directory : %s" % APP_DIR)
9494
exit(1)
9595

geeknote/editor.py

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
import hashlib
99
import html2text as html2text
1010
import markdown2 as markdown
11-
import tools
12-
import out
11+
from . import tools
12+
from . import out
1313
import re
14-
import config
15-
from storage import Storage
16-
from log import logging
14+
from . import config
15+
from .storage import Storage
16+
from .log import logging
1717
from xml.sax.saxutils import escape, unescape
1818

1919

@@ -35,7 +35,7 @@ def getHtmlEscapeTable():
3535

3636
@staticmethod
3737
def getHtmlUnescapeTable():
38-
return dict((v, k) for k, v in Editor.getHtmlEscapeTable().items())
38+
return dict((v, k) for k, v in list(Editor.getHtmlEscapeTable().items()))
3939

4040
@staticmethod
4141
def HTMLEscape(text):
@@ -55,7 +55,7 @@ def getImages(contentENML):
5555
Creates a list of image resources to save.
5656
Each has a hash and extension attribute.
5757
"""
58-
soup = BeautifulSoup(contentENML.decode("utf-8"))
58+
soup = BeautifulSoup(contentENML)
5959
imageList = []
6060
for section in soup.findAll("en-media"):
6161
if "type" in section.attrs and "hash" in section.attrs:
@@ -84,7 +84,7 @@ def ENMLtoText(
8484
imageOptions={"saveImages": False},
8585
imageFilename="",
8686
):
87-
soup = BeautifulSoup(contentENML.decode("utf-8"), "html.parser")
87+
soup = BeautifulSoup(contentENML, "html.parser")
8888

8989
if format == "pre":
9090
#
@@ -97,7 +97,7 @@ def ENMLtoText(
9797
if len(sections) >= 1:
9898
content = ""
9999
for c in sections[0].contents:
100-
content = u"".join((content, c))
100+
content = "".join((content, c))
101101
pass
102102
else:
103103
format = "default"
@@ -142,10 +142,10 @@ def ENMLtoText(
142142
for section in soup.find_all("en-media"):
143143
section.replace_with(str(section))
144144

145-
content = html2text.html2text(str(soup).decode("utf-8"), "")
145+
content = html2text.html2text(str(soup), "")
146146

147147
content = re.sub(r" *\n", os.linesep, content)
148-
content = content.replace(unichr(160), " ") # no-break space
148+
content = content.replace(chr(160), " ") # no-break space
149149
content = Editor.HTMLUnescape(content)
150150

151151
return content.encode("utf-8")
@@ -202,15 +202,14 @@ def textToENML(content, raise_ex=False, format="markdown", rawmd=False):
202202
if not isinstance(content, str):
203203
content = ""
204204
try:
205-
content = unicode(content, "utf-8")
206205
# add 2 space before new line in paragraph for creating br tags
207206
content = re.sub(r"([^\r\n])([\r\n])([^\r\n])", r"\1 \n\3", content)
208207
# content = re.sub(r'\r\n', '\n', content)
209208

210209
if format == "pre":
211210
# For the 'pre' format, simply wrap the content with a 'pre' tag.
212211
# Do not perform any further parsing/mutation.
213-
contentHTML = u"".join(("<pre>", content, "</pre>")).encode("utf-8")
212+
contentHTML = "".join(("<pre>", content, "</pre>")).encode("utf-8")
214213
elif format == "markdown":
215214
# Markdown format https://daringfireball.net/projects/markdown/basics
216215
extras = None
@@ -240,14 +239,9 @@ def textToENML(content, raise_ex=False, format="markdown", rawmd=False):
240239

241240
for tag in soup.findAll():
242241
if hasattr(tag, "attrs"):
243-
map(
244-
lambda x: tag.attrs.pop(x, None),
245-
[
246-
k
247-
for k in tag.attrs.keys()
248-
if k in ATTR_2_REMOVE or k.find("on") == 0
249-
],
250-
)
242+
for k in list(tag.attrs.keys()):
243+
if k in ATTR_2_REMOVE or k.find("on") == 0:
244+
tag.attrs.pop(k, None)
251245
contentHTML = str(soup)
252246
else:
253247
# Plain text format
@@ -256,9 +250,9 @@ def textToENML(content, raise_ex=False, format="markdown", rawmd=False):
256250
tmpstr = ""
257251
for l in contentHTML.split("\n"):
258252
if l == "":
259-
tmpstr = tmpstr + u"<div><br/></div>"
253+
tmpstr = tmpstr + "<div><br/></div>"
260254
else:
261-
tmpstr = tmpstr + u"<div>" + l + u"</div>"
255+
tmpstr = tmpstr + "<div>" + l + "</div>"
262256

263257
contentHTML = tmpstr.encode("utf-8")
264258
contentHTML = contentHTML.replace(

geeknote/gclient.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def validate(self):
7575
return
7676

7777
def __repr__(self):
78-
L = ["%s=%r" % (key, value) for key, value in self.__dict__.iteritems()]
78+
L = ["%s=%r" % (key, value) for key, value in self.__dict__.items()]
7979
return "%s(%s)" % (self.__class__.__name__, ", ".join(L))
8080

8181
def __eq__(self, other):
@@ -181,7 +181,7 @@ def validate(self):
181181
return
182182

183183
def __repr__(self):
184-
L = ["%s=%r" % (key, value) for key, value in self.__dict__.iteritems()]
184+
L = ["%s=%r" % (key, value) for key, value in self.__dict__.items()]
185185
return "%s(%s)" % (self.__class__.__name__, ", ".join(L))
186186

187187
def __eq__(self, other):

0 commit comments

Comments
 (0)