• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python encoding.to_unicode_from_fs函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中spyderlib.utils.encoding.to_unicode_from_fs函数的典型用法代码示例。如果您正苦于以下问题:Python to_unicode_from_fs函数的具体用法?Python to_unicode_from_fs怎么用?Python to_unicode_from_fs使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了to_unicode_from_fs函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: add_history

    def add_history(self, filename):
        """
        Add new history tab
        Slot for add_history signal emitted by shell instance
        """
        filename = encoding.to_unicode_from_fs(filename)
        if filename in self.filenames:
            return
        editor = codeeditor.CodeEditor(self)
        if osp.splitext(filename)[1] == '.py':
            language = 'py'
            icon = ima.icon('python')
        else:
            language = 'bat'
            icon = ima.icon('cmdprompt')
        editor.setup_editor(linenumbers=False, language=language,
                            scrollflagarea=False)
        editor.focus_changed.connect(lambda: self.focus_changed.emit())
        editor.setReadOnly(True)
        color_scheme = get_color_scheme(self.get_option('color_scheme_name'))
        editor.set_font( self.get_plugin_font(), color_scheme )
        editor.toggle_wrap_mode( self.get_option('wrap') )

        text, _ = encoding.read(filename)
        editor.set_text(text)
        editor.set_cursor_position('eof')
        
        self.editors.append(editor)
        self.filenames.append(filename)
        self.icons.append(icon)
        index = self.tabwidget.addTab(editor, osp.basename(filename))
        self.find_widget.set_editor(editor)
        self.tabwidget.setTabToolTip(index, filename)
        self.tabwidget.setTabIcon(index, icon)
        self.tabwidget.setCurrentIndex(index)
开发者ID:ImadBouirmane,项目名称:spyder,代码行数:35,代码来源:history.py


示例2: add_history

    def add_history(self, filename):
        """
        Add new history tab
        Slot for SIGNAL('add_history(QString)') emitted by shell instance
        """
        filename = encoding.to_unicode_from_fs(filename)
        if filename in self.filenames:
            return
        editor = codeeditor.CodeEditor(self)
        if osp.splitext(filename)[1] == ".py":
            language = "py"
            icon = get_icon("python.png")
        else:
            language = "bat"
            icon = get_icon("cmdprompt.png")
        editor.setup_editor(linenumbers=False, language=language, scrollflagarea=False)
        self.connect(editor, SIGNAL("focus_changed()"), lambda: self.emit(SIGNAL("focus_changed()")))
        editor.setReadOnly(True)
        color_scheme = get_color_scheme(self.get_option("color_scheme_name"))
        editor.set_font(self.get_plugin_font(), color_scheme)
        editor.toggle_wrap_mode(self.get_option("wrap"))

        text, _ = encoding.read(filename)
        editor.set_text(text)
        editor.set_cursor_position("eof")

        self.editors.append(editor)
        self.filenames.append(filename)
        self.icons.append(icon)
        index = self.tabwidget.addTab(editor, osp.basename(filename))
        self.find_widget.set_editor(editor)
        self.tabwidget.setTabToolTip(index, filename)
        self.tabwidget.setTabIcon(index, icon)
        self.tabwidget.setCurrentIndex(index)
开发者ID:ymarfoq,项目名称:outilACVDesagregation,代码行数:34,代码来源:history.py


示例3: get_home_dir

def get_home_dir():
    """
    Return user home directory
    """
    try:
        # expanduser() returns a raw byte string which needs to be
        # decoded with the codec that the OS is using to represent file paths.
        path = encoding.to_unicode_from_fs(osp.expanduser('~'))
    except:
        path = ''
    for env_var in ('HOME', 'USERPROFILE', 'TMP'):
        if osp.isdir(path):
            break
        # os.environ.get() returns a raw byte string which needs to be
        # decoded with the codec that the OS is using to represent environment
        # variables.
        path = encoding.to_unicode_from_fs(os.environ.get(env_var, ''))
    if path:
        return path
    else:
        raise RuntimeError('Please define environment variable $HOME')
开发者ID:ChunHungLiu,项目名称:spyder,代码行数:21,代码来源:base.py


示例4: patched

 def patched():
     """
     Return user home directory
     """
     import os.path as osp
     from spyderlib.utils import encoding
     for env_var in ('APPDATA', 'USERPROFILE', 'HOME', 'TMP'):
         # os.environ.get() returns a raw byte string which needs to be
         # decoded with the codec that the OS is using to represent environment
         # variables.
         path = encoding.to_unicode_from_fs(os.environ.get(env_var, ''))
         if osp.isdir(path):
             break
     if path:
         return path
     try:
         # expanduser() returns a raw byte string which needs to be
         # decoded with the codec that the OS is using to represent file paths.
         path = encoding.to_unicode_from_fs(osp.expanduser('~'))
         return path
     except:
         raise RuntimeError('Please define environment variable $HOME')
开发者ID:burlab,项目名称:emzed,代码行数:22,代码来源:spyder_app_patches.py


示例5: get_pylint_version

def get_pylint_version():
    """Return pylint version"""
    global PYLINT_PATH
    if PYLINT_PATH is None:
        return
    process = subprocess.Popen(['pylint', '--version'],
                               stdout=subprocess.PIPE, stderr=subprocess.PIPE,
                               cwd=osp.dirname(PYLINT_PATH),
                               shell=True if os.name == 'nt' else False)
    lines = to_unicode_from_fs(process.stdout.read()).splitlines()
    if lines:
        match = re.match('(pylint|pylint-script.py) ([0-9\.]*)', lines[0])
        if match is not None:
            return match.groups()[1]
开发者ID:dhirschfeld,项目名称:spyderlib,代码行数:14,代码来源:pylintgui.py


示例6: get_pylint_version

def get_pylint_version():
    """Return pylint version"""
    if PYLINT_PATH is None:
        return
    cwd = osp.dirname(PYLINT_PATH)
    args = ['--version']
    if os.name == 'nt':
        cmd = ' '.join([PYLINT] + args)
        process = programs.run_shell_command(cmd, cwd=cwd)
    else:
        process = programs.run_program(PYLINT, args, cwd=cwd)
    lines = to_unicode_from_fs(process.stdout.read()).splitlines()
    if lines:
        regex = '({0}*|pylint-script.py) ([0-9\.]*)'.format(PYLINT)
        match = re.match(regex, lines[0])
        if match is not None:
            return match.groups()[1]
开发者ID:dzosz,项目名称:spyder,代码行数:17,代码来源:pylintgui.py


示例7: get_pylint_version

def get_pylint_version():
    """Return pylint version"""
    global PYLINT_PATH
    if PYLINT_PATH is None:
        return
    process = subprocess.Popen(
        [PYLINT, "--version"],
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE,
        cwd=osp.dirname(PYLINT_PATH),
        shell=True if os.name == "nt" else False,
    )
    lines = to_unicode_from_fs(process.stdout.read()).splitlines()
    if lines:
        regex = "({0}*|pylint-script.py) ([0-9\.]*)".format(PYLINT)
        match = re.match(regex, lines[0])
        if match is not None:
            return match.groups()[1]
开发者ID:ftsiadimos,项目名称:spyder,代码行数:18,代码来源:pylintgui.py


示例8: _convert

 def _convert(fname):
     fname = os.path.abspath(encoding.to_unicode_from_fs(fname))
     if os.name == 'nt' and len(fname) >= 2 and fname[1] == ':':
         fname = fname[0].upper()+fname[1:]
     return fname
开发者ID:kirichoi,项目名称:spyderplugins,代码行数:5,代码来源:p_import_combine_phrasedml.py


示例9: is_program_installed

import os
import os.path as osp
import re
import subprocess
import sys
import tempfile

# Local imports
from spyderlib.utils import encoding
from spyderlib.py3compat import PY2, is_text_string


if os.name == 'nt':
    TEMPDIR = tempfile.gettempdir() + osp.sep + 'spyder'
else:
    username = encoding.to_unicode_from_fs(os.environ.get('USER'))
    TEMPDIR = tempfile.gettempdir() + osp.sep + 'spyder-' + username


def is_program_installed(basename):
    """Return program absolute path if installed in PATH
    Otherwise, return None"""
    for path in os.environ["PATH"].split(os.pathsep):
        abspath = osp.join(path, basename)
        if osp.isfile(abspath):
            return abspath


def find_program(basename):
    """Find program in PATH and return absolute path
    Try adding .exe or .bat to basename on Windows platforms
开发者ID:ImadBouirmane,项目名称:spyder,代码行数:31,代码来源:programs.py


示例10: sphinxify

def sphinxify(docstring, context, buildername='html'):
    """
    Runs Sphinx on a docstring and outputs the processed documentation.

    Parameters
    ----------
    docstring : str
        a ReST-formatted docstring

    context : dict
        Variables to be passed to the layout template to control how its
        rendered (through the Sphinx variable *html_context*).

    buildername:  str
        It can be either `html` or `text`.

    Returns
    -------
    An Sphinx-processed string, in either HTML or plain text format, depending
    on the value of `buildername`
    """

    srcdir = mkdtemp()
    srcdir = encoding.to_unicode_from_fs(srcdir)

    base_name = osp.join(srcdir, 'docstring')
    rst_name = base_name + '.rst'

    if buildername == 'html':
        suffix = '.html'
    else:
        suffix = '.txt'
    output_name = base_name + suffix

    # This is needed so users can type \\ on latex eqnarray envs inside raw
    # docstrings
    if context['right_sphinx_version'] and context['math_on']:
        docstring = docstring.replace('\\\\', '\\\\\\\\')
    
    # Add a class to several characters on the argspec. This way we can
    # highlight them using css, in a similar way to what IPython does.
    # NOTE: Before doing this, we escape common html chars so that they
    # don't interfere with the rest of html present in the page
    argspec = escape(context['argspec'])
    for char in ['=', ',', '(', ')', '*', '**']:
        argspec = argspec.replace(char,
                         '<span class="argspec-highlight">' + char + '</span>')
    context['argspec'] = argspec

    doc_file = codecs.open(rst_name, 'w', encoding='utf-8')
    doc_file.write(docstring)
    doc_file.close()
    
    temp_confdir = False
    if temp_confdir:
        # TODO: This may be inefficient. Find a faster way to do it.
        confdir = mkdtemp()
        confdir = encoding.to_unicode_from_fs(confdir)
        generate_configuration(confdir)
    else:
        confdir = osp.join(get_module_source_path('spyderlib.utils.inspector'))

    confoverrides = {'html_context': context}

    doctreedir = osp.join(srcdir, 'doctrees')

    sphinx_app = Sphinx(srcdir, confdir, srcdir, doctreedir, buildername,
                        confoverrides, status=None, warning=None,
                        freshenv=True, warningiserror=False, tags=None)
    try:
        sphinx_app.build(None, [rst_name])
    except SystemMessage:
        output = _("It was not possible to generate rich text help for this "
                    "object.</br>"
                    "Please see it in plain text.")
        return warning(output)

    # TODO: Investigate if this is necessary/important for us
    if osp.exists(output_name):
        output = codecs.open(output_name, 'r', encoding='utf-8').read()
        output = output.replace('<pre>', '<pre class="literal-block">')
    else:
        output = _("It was not possible to generate rich text help for this "
                    "object.</br>"
                    "Please see it in plain text.")
        return warning(output)

    if temp_confdir:
        shutil.rmtree(confdir, ignore_errors=True)
    shutil.rmtree(srcdir, ignore_errors=True)

    return output
开发者ID:ImadBouirmane,项目名称:spyder,代码行数:92,代码来源:sphinxify.py



注:本文中的spyderlib.utils.encoding.to_unicode_from_fs函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python icon_manager.icon函数代码示例发布时间:2022-05-27
下一篇:
Python debug.log_last_error函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap