2 # -*- coding: ISO-8859-1 -*-
5 # Copyright (C) 2002 Jörg Lehmann <joergl@users.sourceforge.net>
6 # Copyright (C) 2002 André Wobst <wobsta@users.sourceforge.net>
8 # This file is part of PyX (http://pyx.sourceforge.net/).
10 # PyX is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 2 of the License, or
13 # (at your option) any later version.
15 # PyX is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with PyX; if not, write to the Free Software
22 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 "arg is string-like (cf. python cookbook 3.2)"
48 if type(arg
+ 0.0) is type(arg
):
55 """arg is sequence-like (e.g. has a len)
56 a string is *not* considered to be a sequence"""
57 if isstring(arg
): return 0
63 def ensuresequence(arg
):
64 """return arg or (arg,) depending on the result of issequence,
65 None is converted to ()"""
66 if isstring(arg
): return (arg
,)
67 if arg
is None: return ()
68 if issequence(arg
): return arg
73 """return list(arg) or [arg] depending on the result of isequence,
74 None is converted to []"""
75 if isstring(arg
): return [arg
]
76 if arg
is None: return []
77 if issequence(arg
): return list(arg
)
80 def getitemno(arg
, n
):
81 """get item number n if arg is a sequence (when the sequence
82 is not long enough, None is returned), otherweise arg is
91 def issequenceofsequences(arg
):
92 """check if arg has a sequence or None as it's first entry"""
93 return issequence(arg
) and len(arg
) and (issequence(arg
[0]) or arg
[0] is None)
96 def getsequenceno(arg
, n
):
97 """get sequence number n if arg is a sequence of sequences (when
98 the sequence is not long enough, None is returned), otherwise
100 if issequenceofsequences(arg
):