def user_groups(self, ldap_user, group_search):
groups = []<EOL>try:<EOL><INDENT>user_uid = ldap_user.attrs['<STR_LIT>'][<NUM_LIT:0>]<EOL>if '<STR_LIT>' in ldap_user.attrs:<EOL><INDENT>user_gid = ldap_user.attrs['<STR_LIT>'][<NUM_LIT:0>]<EOL>filterstr = u'<STR_LIT>' % (<EOL>self.ldap.filter.escape_filter_chars(user_gid),<EOL>self.ldap.filter.escape_filter_chars(user_uid)<EOL>)<EOL><DEDENT>else:<EOL><INDENT>filterstr = u'<STR_LIT>' % (<EOL>self.ldap.filter.escape_filter_chars(user_uid),<EOL>)<EOL><DEDENT>search = group_search.search_with_additional_term_string(filterstr)<EOL>groups = search.execute(ldap_user.connection)<EOL><DEDENT>except (KeyError, IndexError):<EOL><INDENT>pass<EOL><DEDENT>return groups<EOL>
Searches for any group that is either the user's primary or contains the
user as a member.