コード例 #1
0
ファイル: start.py プロジェクト: spillz/spyder
def send_args_to_spyder(args):
    """
    Simple socket client used to send the args passed to the Spyder 
    executable to an already running instance.

    Args can be Python scripts or files with these extensions: .spydata, .mat,
    .npy, or .h5, which can be imported by the Variable Explorer.
    """
    port = CONF.get('main', 'open_files_port')

    # Wait ~50 secs for the server to be up
    # Taken from http://stackoverflow.com/a/4766598/438386
    for _x in range(200):
        try:
            for arg in args:
                client = socket.socket(socket.AF_INET, socket.SOCK_STREAM,
                                       socket.IPPROTO_TCP)
                client.connect(("127.0.0.1", port))
                if is_unicode(arg):
                    arg = arg.encode('utf-8')
                client.send(osp.abspath(arg))
                client.close()
        except socket.error:
            time.sleep(0.25)
            continue
        break
コード例 #2
0
ファイル: start.py プロジェクト: burrbull/spyder
def send_args_to_spyder(args):
    """
    Simple socket client used to send the args passed to the Spyder 
    executable to an already running instance.

    Args can be Python scripts or files with these extensions: .spydata, .mat,
    .npy, or .h5, which can be imported by the Variable Explorer.
    """
    port = CONF.get('main', 'open_files_port')

    # Wait ~50 secs for the server to be up
    # Taken from https://stackoverflow.com/a/4766598/438386
    for _x in range(200):
        try:
            for arg in args:
                client = socket.socket(socket.AF_INET, socket.SOCK_STREAM,
                                       socket.IPPROTO_TCP)
                client.connect(("127.0.0.1", port))
                if is_unicode(arg):
                    arg = arg.encode('utf-8')
                client.send(osp.abspath(arg))
                client.close()
        except socket.error:
            time.sleep(0.25)
            continue
        break
コード例 #3
0
ファイル: start.py プロジェクト: timgates42/spyder
def send_args_to_spyder(args):
    """
    Simple socket client used to send the args passed to the Spyder
    executable to an already running instance.

    Args can be Python scripts or files with these extensions: .spydata, .mat,
    .npy, or .h5, which can be imported by the Variable Explorer.
    """
    from spyder.config.manager import CONF
    port = CONF.get('main', 'open_files_port')
    print_warning = True

    # Wait ~50 secs for the server to be up
    # Taken from https://stackoverflow.com/a/4766598/438386
    for __ in range(200):
        try:
            for arg in args:
                client = socket.socket(socket.AF_INET, socket.SOCK_STREAM,
                                       socket.IPPROTO_TCP)
                client.connect(("127.0.0.1", port))
                if is_unicode(arg):
                    arg = arg.encode('utf-8')
                client.send(osp.abspath(arg))
                client.close()
        except socket.error:
            # Print informative warning to let users know what Spyder is doing
            if print_warning:
                print("Waiting for the server to open files and directories "
                      "to be up (perhaps it failed to be started).")
                print_warning = False

            # Wait 250 ms before trying again
            time.sleep(0.25)
            continue
        break
コード例 #4
0
ファイル: base.py プロジェクト: xiaopengyou0000/spyder
 def translate_gettext(x):
     if not PY3 and is_unicode(x):
         x = x.encode("utf-8")
     y = lgettext(x)
     if is_text_string(y) and PY3:
         return y
     else:
         return to_text_string(y, "utf-8")
コード例 #5
0
def save_figure_tofile(fig, fmt, fname):
    """Save fig to fname in the format specified by fmt."""
    root, ext = osp.splitext(fname)
    if ext == '.png' and fmt == 'image/svg+xml':
        qimg = svg_to_image(fig)
        qimg.save(fname)
    else:
        if fmt == 'image/svg+xml' and is_unicode(fig):
            fig = fig.encode('utf-8')

        with open(fname, 'wb') as f:
            f.write(fig)
コード例 #6
0
ファイル: figurebrowser.py プロジェクト: impact27/spyder
def save_figure_tofile(fig, fmt, fname):
    """Save fig to fname in the format specified by fmt."""
    root, ext = osp.splitext(fname)
    if ext == '.png' and fmt == 'image/svg+xml':
        qimg = svg_to_image(fig)
        qimg.save(fname)
    else:
        if fmt == 'image/svg+xml' and is_unicode(fig):
            fig = fig.encode('utf-8')

        with open(fname, 'wb') as f:
            f.write(fig)
コード例 #7
0
ファイル: encoding.py プロジェクト: zalois/spyder
def to_fs_from_unicode(unic):
    """
    Return a byte string version of unic encoded using the file
    system encoding.
    """
    if is_unicode(unic):
        try:
            string = unic.encode(FS_ENCODING)
        except (UnicodeError, TypeError):
            pass
        else:
            return string
    return unic
コード例 #8
0
ファイル: encoding.py プロジェクト: zalois/spyder
def to_unicode(string):
    """Convert a string to unicode"""
    if not is_unicode(string):
        for codec in CODECS:
            try:
                unic = to_text_string(string, codec)
            except UnicodeError:
                pass
            except TypeError:
                break
            else:
                return unic
    return string
コード例 #9
0
ファイル: encoding.py プロジェクト: impact27/spyder
def to_fs_from_unicode(unic):
    """
    Return a byte string version of unic encoded using the file 
    system encoding.
    """
    if is_unicode(unic):
        try:
            string = unic.encode(FS_ENCODING)
        except (UnicodeError, TypeError):
            pass
        else:
            return string
    return unic
コード例 #10
0
ファイル: encoding.py プロジェクト: impact27/spyder
def to_unicode(string):
    """Convert a string to unicode"""
    if not is_unicode(string):
        for codec in CODECS:
            try:
                unic = to_text_string(string, codec)
            except UnicodeError:
                pass
            except TypeError:
                break
            else:
                return unic
    return string
コード例 #11
0
ファイル: base.py プロジェクト: xiaopengyou0000/spyder
 def translate_dumb(x):
     if not is_unicode(x):
         return to_text_string(x, "utf-8")
     return x
コード例 #12
0
ファイル: base.py プロジェクト: 23101997/spyder
 def translate_dumb(x):
     """Dumb function to not use translations."""
     if not is_unicode(x):
         return to_text_string(x, "utf-8")
     return x
コード例 #13
0
ファイル: base.py プロジェクト: impact27/spyder
 def translate_dumb(x):
     """Dumb function to not use translations."""
     if not is_unicode(x):
         return to_text_string(x, "utf-8")
     return x