<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def get_uri_prefix_map(self):
 """Constructs and returns a map from namespace URI to prefix, representing all namespaces in this set. The prefix chosen for each namespace is its preferred prefix if it's not None. If the preferred prefix is None, one is chosen from the set of registered prefixes. In the latter situation, if no prefixes are registered, an exception is raised. """

        mapping = {}
        
        for ni in six.itervalues(self.__ns_uri_map):
            if ni.preferred_prefix:
                mapping[ni.uri] = ni.preferred_prefix
            elif len(ni.prefixes) > 0:
                mapping[ni.uri] = next(iter(ni.prefixes))
            else:
                # The reason I don't let any namespace map to None here is that
                # I don't think generateDS supports it.  It requires prefixes
                # for all namespaces.
                raise NoPrefixesError(ni.uri)

        return mapping