File: gp.py

package info (click to toggle)
python-gnuplot 1.8-8
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 1,272 kB
  • sloc: python: 2,042; makefile: 6
file content (50 lines) | stat: -rw-r--r-- 1,789 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# $Id: gp.py 292 2006-03-03 09:49:04Z mhagger $

# Copyright (C) 1998-2003 Michael Haggerty <mhagger@alum.mit.edu>
#
# This file is licensed under the GNU Lesser General Public License
# (LGPL).  See LICENSE.txt for details.

"""gp -- a platform-independent interface to a gnuplot process.

This file imports a low-level, platform-independent interface to the
gnuplot program.  Which interface is imported depends on the platform.
There are variations of this file for Unix, the Macintosh, and for
Windows called gp_unix.py, gp_mac.py, and gp_win32.py, respectively.
Note that the end-user should use the more capable interface from
__init__.py (i.e., 'import Gnuplot') rather than the low-level
interface imported by this file.

See gp_unix.py for most documentation about the facilities of the
gp_*.py modules.

"""

import sys, string

# Low-level communication with gnuplot is platform-dependent.  Import
# the appropriate implementation of GnuplotProcess based on the
# platform:
if sys.platform == 'mac':
    from Gnuplot.gp_mac import GnuplotOpts, GnuplotProcess, test_persist
elif sys.platform == 'win32':
    from Gnuplot.gp_win32 import GnuplotOpts, GnuplotProcess, test_persist
elif sys.platform == 'darwin':
    from Gnuplot.gp_macosx import GnuplotOpts, GnuplotProcess, test_persist
elif sys.platform[:4] == 'java':
    from Gnuplot.gp_java import GnuplotOpts, GnuplotProcess, test_persist
elif sys.platform == 'cygwin':
    from Gnuplot.gp_cygwin import GnuplotOpts, GnuplotProcess, test_persist
else:
    from Gnuplot.gp_unix import GnuplotOpts, GnuplotProcess, test_persist


def double_quote_string(s):
    """Return string s quoted and surrounded by double-quotes for gnuplot."""

    for c in ['\\', '\"']:
        s = s.replace(c, '\\' + c)

    return '"%s"' % (s,)