blob: 18c68575775c290d7b9108ededd7253357df2a66 (
plain)
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# Copyright(c) 2004, Karl Trygve Kalleberg <karltk@gentoo.org>
# Copyright(c) 2004, Gentoo Foundation
#
# Licensed under the GNU General Public License, v2
#
# $Header: /var/cvsroot/gentoo-src/javatoolkit/src/javatoolkit/classpath.py,v 1.4 2004/11/08 20:06:06 karltk Exp $
class ClasspathIter:
"""An iterator for the Classpath class, below."""
def __init__(self, classpath):
self._classpath = classpath
self._index = 0
def next(self):
self._index += 1
if self._index >= len(self._classpath.classpath):
raise StopIteration
return self._classpath.classpath[self._index]
class Classpath:
"""A classpath object provides a collection interface to the elements of a : separated path list. """
def __init__(self, classpath_string = None):
if classpath_string != None:
cs = classpath_string.strip().strip("\"")
self.classpath = cs.split(":")
else:
self.classpath = []
def __iter__(self):
"""Returns iterator. Elements of the original classpath string are considered split by ':'."""
return ClasspathIter(self)
def __len__(self):
"""Returns length (number of elements) in this classpath."""
return len(self.classpath)
def __getitem__(self, i):
"""Returns i'th element."""
return self.classpath[i]
def __setitem__(self, i, val):
"""Sets i'th element."""
self.classpath[i] = val
def __str__(self):
"""Constructs a suitable string representation of the classpath."""
return ":".join(self.classpath)
def append(self, element):
"""Appends an path to the classpath."""
self.classpath.append(element)
# vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap:
|