Author: bugman Date: Mon Apr 14 16:51:28 2008 New Revision: 5694 URL: http://svn.gna.org/viewcvs/relax?rev=5694&view=rev Log: Converted the Selection.wildcard_match() method into a module function. Modified: 1.3/generic_fns/selection.py Modified: 1.3/generic_fns/selection.py URL: http://svn.gna.org/viewcvs/relax/1.3/generic_fns/selection.py?rev=5694&r1=5693&r2=5694&view=diff ============================================================================== --- 1.3/generic_fns/selection.py (original) +++ 1.3/generic_fns/selection.py Mon Apr 14 16:51:28 2008 @@ -124,21 +124,21 @@ elif isinstance(obj, MoleculeContainer): if not self.molecules: return True - elif self.wildcard_match(obj.name, self.molecules): + elif wildcard_match(obj.name, self.molecules): return True # The object is a residue. elif isinstance(obj, ResidueContainer): if not self.residues: return True - elif self.wildcard_match(obj.name, self.residues) or obj.num in self.residues: + elif wildcard_match(obj.name, self.residues) or obj.num in self.residues: return True # The object is a spin. elif isinstance(obj, SpinContainer): if not self.spins: return True - elif self.wildcard_match(obj.name, self.spins) or obj.num in self.spins: + elif wildcard_match(obj.name, self.spins) or obj.num in self.spins: return True # No match. @@ -169,49 +169,6 @@ if self._union or self._intersect or self.molecules or self.residues or self.spins: raise RelaxError, "Cannot define multiple Boolean relationships between Selection objects" self._union = (select_obj0, select_obj1) - - - def wildcard_match(self, id, patterns): - """Determine if the id is in the list of patterns, allowing for regular expressions. - - This method converts from relax's RE syntax to that of the re python module. - - The changes include: - - 1. All '*' to '.*'. - - - @param id: The identification object. - @type id: None, str, or number - @param patterns: A list of patterns to match. The elements will be converted to strings, - so the list can consist of anything. - @type patterns: list - @return: True if there is a match, False otherwise. - @rtype: bool - """ - - # Catch None. - if id == None: - return False - - # If a number, convert to a string. - if type(id) == int or type(id) == float: - id = str(id) - - # Loop over the patterns. - for pattern in patterns: - # Force a conversion to str. - pattern = str(pattern) - - # First replace any '*' with '.*' (relax to re conversion). - pattern = replace(pattern, '*', '.*') - - # String matches. - if search(pattern, id): - return True - - # No matches. - return False @@ -1400,3 +1357,45 @@ # Return the three tokens. return mol_token, res_token, spin_token + +def wildcard_match(id, patterns): + """Determine if the id is in the list of patterns, allowing for regular expressions. + + This method converts from relax's RE syntax to that of the re python module. + + The changes include: + + 1. All '*' to '.*'. + + + @param id: The identification object. + @type id: None, str, or number + @param patterns: A list of patterns to match. The elements will be converted to strings, + so the list can consist of anything. + @type patterns: list + @return: True if there is a match, False otherwise. + @rtype: bool + """ + + # Catch None. + if id == None: + return False + + # If a number, convert to a string. + if type(id) == int or type(id) == float: + id = str(id) + + # Loop over the patterns. + for pattern in patterns: + # Force a conversion to str. + pattern = str(pattern) + + # First replace any '*' with '.*' (relax to re conversion). + pattern = replace(pattern, '*', '.*') + + # String matches. + if search(pattern, id): + return True + + # No matches. + return False