Returns and records an alternative according to the following
        precedence:
          1. An existing alternative
          2. A server-chosen alternative
3161
def get_alternative(self, client, dt=None, prefetch=False):
        

        if self.is_archived() or self.is_paused():
            return self.control

        if self.is_client_excluded(client):
            return self.control

        chosen_alternative = self.existing_alternative(client)
        if not chosen_alternative:
            chosen_alternative, participate = self.choose_alternative(client)
            if participate and not prefetch:
                chosen_alternative.record_participation(client, dt=dt)

        return chosen_alternative
464210
def options(self, urls=None, **overrides):
        """"""
        if urls is not None:
            overrides['urls'] = urls
        return self.where(accept='OPTIONS', **overrides)
1317295
def attach_alternative(self, content, mimetype=None):
        """"""
        self.attach(content=content, mimetype=mimetype)
941436
def get_preferred(self, addr_1, addr_2):
        ''''''
        if addr_1 > addr_2:
            addr_1, addr_2 = addr_2, addr_1

        return self._cache.get((addr_1, addr_2))
1200781
def try_options
			return unless request.http_method == :OPTIONS

			allow = available_endpoint&.allow
			halt 404 unless allow
			response.headers['Allow'] = allow
		end
1104790
def resolve_alternates(load_path, logical_path)
      candidates, deps = super

      dirname = File.join(load_path, logical_path)

      if directory?(dirname)
        filename = File.join(dirname, 'package.json')

        if self.file?(filename)
          deps << build_file_digest_uri(filename)
          read_package_directives(dirname, filename) do |path|
            if file?(path)
              candidates << path
            end
          end
        end
      end

      return candidates, deps
    end
988012
def _request(self, process=None, wait=None):
        
        opts = []
        if process is not None:
            opts.append('process=%s' % process)
        if wait is not None:
            if wait:
                opts.append('wait=true')
            else:
                opts.append('wait=false')
        return 'field()record[%s]' % (','.join(opts))
1806
def _get_existing(driver, zone_name, server_name, validation):
    
    if zone_name is None:
        zones = sorted(
            (z for z
             in driver.list_zones()
             if server_name.rstrip(u'.')
                .endswith(u'.' + z.domain.rstrip(u'.'))),
            key=lambda z: len(z.domain),
            reverse=True)
        if len(zones) == 0:
            raise NotInZone(server_name=server_name, zone_name=None)
    else:
        zones = [
            z for z
            in driver.list_zones()
            if z.domain == zone_name]
        if len(zones) == 0:
            raise ZoneNotFound(zone_name=zone_name)
    zone = zones[0]
    subdomain = _split_zone(server_name, zone.domain)
    existing = [
        record for record
        in zone.list_records()
        if record.name == subdomain and
        record.type == 'TXT' and
        record.data == validation]
    return zone, existing, subdomain
216500
def clone(instance, substitutions, ignore=()):
    
    substitutions[instance.id] = new_object_id()

    def substitute(value):
        try:
            hash(value)
        except Exception:
            return value
        else:
            return substitutions.get(value, value)

    return instance.__class__(**{
        key:  substitute(value)
        for key, value in iter_items(instance, ignore)
    }).create()
538105
def save!(options={})
      if perform_validations(options)
        ret = super()
        process_response_errors
        raise_record_invalid if self.errors.any?
        ret
      else
        raise_record_invalid
      end
    end
1087051
def save(opts={})
    options = { :validate => true }.merge(opts)
    return false if !(new_record? || changed?)
    if options[:validate]
      return false if !valid?
    end
    begin
      save!(options)
    rescue
      return false
    end
    true
  end
132030
public ResolvedType alternateFor(ResolvedType type) {
    if (appliesTo(type)) {
      if (hasWildcards(original)) {
        return replaceWildcardsFrom(WildcardType.collectReplaceables(type, original), alternate);
      } else {
        return alternate;
      }
    }
    return type;
  }
403180
def main_target_alternative (self, target):
        
        assert isinstance(target, AbstractTarget)
        target.project ().add_alternative (target)
        return target
470408
def option(*args)
      clone.tap do |query|
        unless args.compact.empty?
          yield(query.options, query)
        end
      end
    end
816368
def __select_alternatives (self, property_set_, debug):
        
        # When selecting alternatives we have to consider defaults,
        # for example:
        #    lib l : l.cpp : <variant>debug ;
        #    lib l : l_opt.cpp : <variant>release ;
        # won't work unless we add default value <variant>debug.
        assert isinstance(property_set_, property_set.PropertySet)
        assert isinstance(debug, int)  # also matches bools

        property_set_ = property_set_.add_defaults ()

        # The algorithm: we keep the current best viable alternative.
        # When we've got new best viable alternative, we compare it
        # with the current one.
        best = None
        best_properties = None

        if len (self.alternatives_) == 0:
            return None

        if len (self.alternatives_) == 1:
            return self.alternatives_ [0]

        if debug:
            print "Property set for selection:", property_set_

        for v in self.alternatives_:
            properties = v.match (property_set_, debug)

            if properties is not None:
                if not best:
                    best = v
                    best_properties = properties

                else:
                    if b2.util.set.equal (properties, best_properties):
                        return None

                    elif b2.util.set.contains (properties, best_properties):
                        # Do nothing, this alternative is worse
                        pass

                    elif b2.util.set.contains (best_properties, properties):
                        best = v
                        best_properties = properties

                    else:
                        return None

        return best
1029692
private static int preferSignature(Object[] args,
                                       Class<?>[] sig1,
                                       boolean vararg1,
                                       Class<?>[] sig2,
                                       boolean vararg2 )
    {
        int totalPreference = 0;
        for (int j = 0; j < args.length; j++) {
            Class<?> type1 = vararg1 && j >= sig1.length ? sig1[sig1.length-1] : sig1[j];
            Class<?> type2 = vararg2 && j >= sig2.length ? sig2[sig2.length-1] : sig2[j];
            if (type1 == type2) {
                continue;
            }
            Object arg = args[j];

            // Determine which of type1, type2 is easier to convert from arg.

            int rank1 = NativeJavaObject.getConversionWeight(arg, type1);
            int rank2 = NativeJavaObject.getConversionWeight(arg, type2);

            int preference;
            if (rank1 < rank2) {
                preference = PREFERENCE_FIRST_ARG;
            } else if (rank1 > rank2) {
                preference = PREFERENCE_SECOND_ARG;
            } else {
                // Equal ranks
                if (rank1 == NativeJavaObject.CONVERSION_NONTRIVIAL) {
                    if (type1.isAssignableFrom(type2)) {
                        preference = PREFERENCE_SECOND_ARG;
                    } else if (type2.isAssignableFrom(type1)) {
                        preference = PREFERENCE_FIRST_ARG;
                    } else {
                        preference = PREFERENCE_AMBIGUOUS;
                    }
                } else {
                    preference = PREFERENCE_AMBIGUOUS;
                }
            }

            totalPreference |= preference;

            if (totalPreference == PREFERENCE_AMBIGUOUS) {
                break;
            }
        }
        return totalPreference;
    }
254925
protected void compareServerMode(Session other) throws ClientException {

        if (serverMode == SERVER_DEFAULT &&
            other.serverMode == SERVER_DEFAULT) {
            // this is OK
        } else {
            // active and passive side had already been set;
            // make sure that it has been done correctly:
            // either server can be active
            // providing that the other is passive

            // if this server mode has been defined,
            // but the other has not, we can't proceed
            if (this.serverMode == SERVER_DEFAULT ||
                other.serverMode == SERVER_DEFAULT) {
                throw new ClientException(ClientException.BAD_SERVER_MODE,
                        "Only one server has been defined as active or passive");
            }

            // both servers cannot have the same mode
            if (other.serverMode == this.serverMode) {
                String modeStr = (this.serverMode == SERVER_PASSIVE) ? "passive"
                        : "active";
                throw new ClientException(ClientException.BAD_SERVER_MODE,
                        "Both servers are " + modeStr);
            }
        }
    }