Decorate as a rule for a key in top level JSON.
359028
def rule(self, key):
        """"""
        def register(f):
            self.rules[key] = f
            return f
        return register
814474
def make_key(self, key, version=None):
        """"""
        return '{}:{}:{}'.format(
            self.prefix,
            version or self.version,
            key,
        )
750362
def from_json(cls, key):
        
        obj = cls()
        try:
            jkey = json_decode(key)
        except Exception as e:  # pylint: disable=broad-except
            raise InvalidJWKValue(e)
        obj.import_key(**jkey)
        return obj
73315
function ret(flag, data) {
    var ret = {
        opts: flag,
        toggleAll: toggleAll
    }
    if (data) {
        ret.data = data;
    }
    ret = JSON.stringify(ret);
    return ret;
}
248616
def get(key, default=-1):
        """"""
        if isinstance(key, int):
            return ClassificationLevel(key)
        if key not in ClassificationLevel._member_map_:
            extend_enum(ClassificationLevel, key, default)
        return ClassificationLevel[key]
604624
function ( obj, key, value ) {
		key = string.toCamelCase( key );

		if ( value !== undefined ) {
			obj.style[key] = value;
			return obj;
		}
		else {
			return obj.style[key];
		}
	}
341150
function (doc, ruleTree) {
    // Special case for "sets"
    if (_.isArray(doc))
      return _.map(doc, function (subdoc) { return transform(subdoc, ruleTree); });

    var res = details.including ? {} : EJSON.clone(doc);
    _.each(ruleTree, function (rule, key) {
      if (!_.has(doc, key))
        return;
      if (_.isObject(rule)) {
        // For sub-objects/subsets we branch
        if (_.isObject(doc[key]))
          res[key] = transform(doc[key], rule);
        // Otherwise we don't even touch this subfield
      } else if (details.including)
        res[key] = EJSON.clone(doc[key]);
      else
        delete res[key];
    });

    return res;
  }
794644
def _coerce_json_to_amendment(self, json_repr):
        """"""
        if isinstance(json_repr, dict):
            amendment = json_repr
        else:
            try:
                amendment = anyjson.loads(json_repr)
            except:
                _LOG.warn('> invalid JSON (failed anyjson parsing)')
                return None
        return amendment
688766
public static <T> JsonObjectBase buildObjectSuccess(String key, T value) {

        JsonObject json = new JsonObject();
        json.addData(key, value);

        LOG.info(json.toString());

        return json;
    }
897077
def _from_json_object_hook(obj):
    

    for key, value in obj.items():
        # Check for datetime objects
        if isinstance(value, str):
            dt_result = datetime_regex.match(value)
            if dt_result:
                year, month, day, hour, minute, second = map(
                    lambda x: int(x), dt_result.groups())
                obj[key] = datetime.datetime(
                    year, month, day, hour, minute, second)
            else:
                dt_result = uuid_regex.match(value)
                if dt_result:
                    obj[key] = uuid.UUID(value)
    return obj
1080737
private static Optional<ICondition> asBetween( JsonObject json)
    {
    return
      Optional.of( json)
      .filter( j -> j.containsKey( BETWEEN_KEY))
      .map( j -> j.getJsonObject( BETWEEN_KEY))
      .map( b -> 
        new Between(
          b.containsKey( EXCLUSIVE_MIN_KEY)
          ? new AssertMore( b.getString( PROPERTY_KEY), b.getInt( EXCLUSIVE_MIN_KEY))
          : new AssertNotLess( b.getString( PROPERTY_KEY), b.getInt( MIN_KEY)),

          b.containsKey( EXCLUSIVE_MAX_KEY)
          ? new AssertLess( b.getString( PROPERTY_KEY), b.getInt( EXCLUSIVE_MAX_KEY))
          : new AssertNotMore( b.getString( PROPERTY_KEY), b.getInt( MAX_KEY))));
    }
1012493
def make_keys_safe(dct):
    """"""
    result = {}
    for key, val in dct.items():
        key = key.replace('-', '_')
        if key in keyword.kwlist:
            key = key + '_'
        result[key] = val
    return result
449418
def header(self, key, value, replace = True):
        ""
        if hasattr(key, 'encode'):
            key = key.encode('ascii')
        if hasattr(value, 'encode'):
            value = value.encode(self.encoding)
        if replace:
            self.sent_headers = [(k,v) for k,v in self.sent_headers if k.lower() != key.lower()]
        self.sent_headers.append((key, value))
1187955
def loadRule(rule_json_object):
    
    name = rule_json_object['name']
    rule_type = rule_json_object['rule_type']
    validation_regex = None
    required = False
    removehtml = False
    include_end_regex = False #Default to false for bakward compatibility
    strip_end_regex = None
    sub_rules = []
    begin_stripe_id = None
    end_stripe_id = None
    begin_shift = 0
    end_shift = 0

    if 'sub_rules' in rule_json_object:
        sub_rules = rule_json_object['sub_rules']
    
    if 'validation_regex' in rule_json_object:
        validation_regex = rule_json_object['validation_regex']
    
    if 'required' in rule_json_object:
        required = rule_json_object['required']
    
    if 'removehtml' in rule_json_object:
        removehtml = rule_json_object['removehtml']
        
    if 'include_end_regex' in rule_json_object:
        include_end_regex = rule_json_object['include_end_regex']
    
    if 'strip_end_regex' in rule_json_object:
        strip_end_regex = rule_json_object['strip_end_regex']

    if 'begin_stripe_id' in rule_json_object:
        begin_stripe_id = rule_json_object['begin_stripe_id']

    if 'end_stripe_id' in rule_json_object:
        end_stripe_id = rule_json_object['end_stripe_id']

    if 'begin_shift' in rule_json_object:
        begin_shift = rule_json_object['begin_shift']

    if 'end_shift' in rule_json_object:
        end_shift = rule_json_object['end_shift']

    rule = {}
    
    """ This is where we add our new type """
    if rule_type == ITEM_RULE or rule_type == 'RegexRule':
        begin_regex = rule_json_object['begin_regex']
        end_regex = rule_json_object['end_regex']
        rule = ItemRule(name, begin_regex, end_regex, include_end_regex, strip_end_regex, validation_regex, required,
                        removehtml, sub_rules, begin_stripe_id, end_stripe_id, begin_shift, end_shift)
    if rule_type == ITERATION_RULE or rule_type == 'RegexIterationRule':
        begin_regex = rule_json_object['begin_regex']
        end_regex = rule_json_object['end_regex']
        iter_begin_regex = rule_json_object['iter_begin_regex']
        iter_end_regex = rule_json_object['iter_end_regex']
        no_first_begin_iter_rule = False
        if 'no_first_begin_iter_rule' in rule_json_object:
            no_first_begin_iter_rule = rule_json_object['no_first_begin_iter_rule']
        no_last_end_iter_rule = False
        if 'no_last_end_iter_rule' in rule_json_object:
            no_last_end_iter_rule = rule_json_object['no_last_end_iter_rule']
        
        rule = IterationRule(name, begin_regex, end_regex, iter_begin_regex, iter_end_regex,
                                  include_end_regex, strip_end_regex, no_first_begin_iter_rule,
                                  no_last_end_iter_rule, validation_regex, required, removehtml,
                                  sub_rules, begin_shift=begin_shift, end_shift=end_shift)

    if 'id' in rule_json_object:
        rule.id = rule_json_object['id']
    
    return rule
275248
function wrap(obj, opts) {
  var result = {};
  for (var key in obj) {
    if(obj.hasOwnProperty(key)) {
      var wrapped = wrap1(obj[key], opts, key);
      if (typeof wrapped !== 'undefined')
        result[key] = wrapped;
    }
  }
  return result;
}
698248
private static Optional<ICondition> asAnyOf( JsonObject json)
    {
    return
      json.containsKey( ANY_OF_KEY)
      ? Optional.of( new AnyOf( toConditions( json.getJsonArray( ANY_OF_KEY))))
      : Optional.empty();
    }
922728
def set_json_item(key, value):
    
    data = get_json()
    data[key] = value

    request = get_request()
    request["BODY"] = json.dumps(data)