本文整理汇总了Python中storage.Storage.getUserprop方法的典型用法代码示例。如果您正苦于以下问题:Python Storage.getUserprop方法的具体用法?Python Storage.getUserprop怎么用?Python Storage.getUserprop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类storage.Storage
的用法示例。
在下文中一共展示了Storage.getUserprop方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: edit
# 需要导入模块: from storage import Storage [as 别名]
# 或者: from storage.Storage import getUserprop [as 别名]
def edit(self):
"""
Call the system editor, that types as a default in the system.
Editing goes in markdown format, and then the markdown
converts into HTML, before uploading to Evernote.
"""
# Try to find default editor in the system.
storage = Storage()
editor = storage.getUserprop('editor')
if not editor:
editor = os.environ.get("editor")
if not editor:
editor = os.environ.get("EDITOR")
if not editor:
# If default editor is not finded, then use nano as a default.
if sys.platform == 'win32':
editor = config.DEF_WIN_EDITOR
else:
editor = config.DEF_UNIX_EDITOR
# Make a system call to open file for editing.
logging.debug("launch system editor: %s %s" % (editor, self.tempfile))
out.preloader.stop()
os.system(editor + " " + self.tempfile)
out.preloader.launch()
newContent = open(self.tempfile, 'r').read()
return newContent
示例2: textToENML
# 需要导入模块: from storage import Storage [as 别名]
# 或者: from storage.Storage import getUserprop [as 别名]
def textToENML(content, raise_ex=False, format='markdown'):
"""
Create an ENML format of note.
"""
if not isinstance(content, str):
content = ""
try:
content = unicode(content, "utf-8")
# add 2 space before new line in paragraph for creating br tags
content = re.sub(r'([^\r\n])([\r\n])([^\r\n])', r'\1 \n\3', content)
if format=='markdown':
storage = Storage()
extras = storage.getUserprop('markdown2_extras')
#contentHTML = markdown.markdown(content).encode("utf-8")
contentHTML = markdown.markdown(
content, extras=extras).encode("utf-8")
# Non-Pretty HTML output
contentHTML = str(BeautifulSoup(contentHTML, 'html.parser'))
else:
contentHTML = Editor.HTMLEscape(content)
return Editor.wrapENML(contentHTML)
except:
if raise_ex:
raise Exception("Error while parsing text to html."
" Content must be an UTF-8 encode.")
logging.error("Error while parsing text to html. "
"Content must be an UTF-8 encode.")
out.failureMessage("Error while parsing text to html. "
"Content must be an UTF-8 encode.")
return tools.exitErr()
示例3: edit
# 需要导入模块: from storage import Storage [as 别名]
# 或者: from storage.Storage import getUserprop [as 别名]
def edit(content=None):
"""
Call the system editor, that types as a default in the system.
Editing goes in markdown format, and then the markdown converts into HTML, before uploading to Evernote.
"""
if content is None:
content = ""
if not isinstance(content, str):
raise Exception("Note content must be an instanse of string, '%s' given." % type(content))
storage = Storage()
userSuffix = storage.getUserprop('suffix')
if not userSuffix:
userSuffix = '.md'
(tmpFileHandler, tmpFileName) = tempfile.mkstemp(suffix=userSuffix)
os.write(tmpFileHandler, ENMLtoText(content))
os.close(tmpFileHandler)
# Try to find default editor in the system.
editor = storage.getUserprop('editor')
if not editor:
# If default editor is not finded, then use nano as a default.
if sys.platform == 'win32':
editor = config.DEF_WIN_EDITOR
else:
editor = config.DEF_UNIX_EDITOR
if not editor:
editor = os.environ.get("editor")
if not editor:
editor = os.environ.get("EDITOR")
# Make a system call to open file for editing.
logging.debug("launch system editor: %s %s" % (editor, tmpFileName))
out.preloader.stop()
os.system(editor + " " + tmpFileName)
out.preloader.launch()
newContent = open(tmpFileName, 'r').read()
return newContent
示例4: textToENML
# 需要导入模块: from storage import Storage [as 别名]
# 或者: from storage.Storage import getUserprop [as 别名]
def textToENML(content, raise_ex=False, format='markdown'):
"""
Create an ENML format of note.
"""
if not isinstance(content, str):
content = ""
try:
content = unicode(content, "utf-8")
# add 2 space before new line in paragraph for creating br tags
content = re.sub(r'([^\r\n])([\r\n])([^\r\n])', r'\1 \n\3', content)
if format=='markdown':
storage = Storage()
extras = storage.getUserprop('markdown2_extras')
#contentHTML = markdown.markdown(content).encode("utf-8")
contentHTML = markdown.markdown(
content, extras=extras).encode("utf-8")
soup = BeautifulSoup(contentHTML, 'html.parser')
Editor.checklistInSoupToENML(soup)
# Non-Pretty HTML output
contentHTML = str(soup)
#
# For the 'pre' format, simply wrap the content with a 'pre' tag. Do
# perform any parsing/mutation.
#
elif format=='pre':
contentHTML = u''.join(('<pre>', content, '</pre>')).encode("utf-8")
else:
contentHTML = Editor.HTMLEscape(content)
contentHTML = contentHTML.replace('[x]','<en-todo checked="true"></en-todo>')
contentHTML = contentHTML.replace('[ ]','<en-todo></en-todo>')
return Editor.wrapENML(contentHTML)
except:
import traceback
traceback.print_exc()
if raise_ex:
raise Exception("Error while parsing text to html."
" Content must be an UTF-8 encode.")
logging.error("Error while parsing text to html. "
"Content must be an UTF-8 encode.")
out.failureMessage("Error while parsing text to html. "
"Content must be an UTF-8 encode.")
return tools.exitErr()
示例5: textToENML
# 需要导入模块: from storage import Storage [as 别名]
# 或者: from storage.Storage import getUserprop [as 别名]
def textToENML(content, raise_ex=False, format='markdown', rawmd=False):
"""
Transform formatted text to ENML
"""
if not isinstance(content, str):
content = ""
try:
content = unicode(content, "utf-8")
# add 2 space before new line in paragraph for creating br tags
content = re.sub(r'([^\r\n])([\r\n])([^\r\n])', r'\1 \n\3', content)
# content = re.sub(r'\r\n', '\n', content)
if format == 'pre':
# For the 'pre' format, simply wrap the content with a 'pre' tag.
# Do not perform any further parsing/mutation.
contentHTML = u''.join(('<pre>', content, '</pre>')).encode("utf-8")
elif format == 'markdown':
# Markdown format https://daringfireball.net/projects/markdown/basics
extras = None
if not rawmd:
storage = Storage()
extras = storage.getUserprop('markdown2_extras')
content = Editor.HTMLEscapeTag(content)
contentHTML = markdown.markdown(content, extras=extras)
soup = BeautifulSoup(contentHTML, 'html.parser')
Editor.checklistInSoupToENML(soup)
contentHTML = str(soup)
elif format == 'html':
# Html to ENML http://dev.evernote.com/doc/articles/enml.php
soup = BeautifulSoup(content, 'html.parser')
ATTR_2_REMOVE = ["id",
"class",
# "on*",
"accesskey",
"data",
"dynsrc",
"tabindex"]
for tag in soup.findAll():
if hasattr(tag, 'attrs'):
map(lambda x: tag.attrs.pop(x, None),
[k for k in tag.attrs.keys()
if k in ATTR_2_REMOVE
or k.find('on') == 0])
contentHTML = str(soup)
else:
# Plain text format
contentHTML = Editor.HTMLEscape(content)
tmpstr = ''
for l in contentHTML.split('\n'):
if l == '':
tmpstr = tmpstr + u'<div><br/></div>'
else:
tmpstr = tmpstr + u'<div>' + l + u'</div>'
contentHTML = tmpstr.encode("utf-8")
contentHTML = contentHTML.replace('[x]', '<en-todo checked="true"></en-todo>')
contentHTML = contentHTML.replace('[ ]', '<en-todo></en-todo>')
return Editor.wrapENML(contentHTML)
except:
import traceback
traceback.print_exc()
if raise_ex:
raise Exception("Error while parsing text to html.")
logging.error("Error while parsing text to html.")
out.failureMessage("Error while parsing text to html.")
return tools.exitErr()