Helper for transpiling DEFAULT_VALUE trees.
352333
private Node defaultValueHook(Node getprop, Node defaultValue) {
    Node undefined = astFactory.createName("undefined", JSTypeNative.VOID_TYPE);
    undefined.makeNonIndexable();
    Node getpropClone = getprop.cloneTree().setJSType(getprop.getJSType());
    return astFactory.createHook(
        astFactory.createSheq(getprop, undefined), defaultValue, getpropClone);
  }
1355045
def compute_default(kwargs):
    """"""
    ranked_default = kwargs.get('default')
    typ = kwargs.get('type', str)

    default = ranked_default.value if ranked_default else None
    if default is None:
      return 'None'

    if typ == list:
      default_str = '[{}]'.format(','.join(["'{}'".format(s) for s in default]))
    elif typ == dict:
      if default:
        default_str = '{{ {} }}'.format(
          ','.join(["'{}':'{}'".format(k, v) for k, v in default.items()]))
      else:
        default_str = '{}'
    elif typ == str:
      default_str = "'{}'".format(default).replace('\n', ' ')
    else:
      default_str = str(default)
    return default_str
798733
def default(self):
        """"""
        if self.MUTABLE:
            return copy.deepcopy(self._default)
        else:
            return self._default
754848
def reverse_toctree(app, doctree, docname):
    """"""
    if docname == "changes":
        for node in doctree.traverse():
            if node.tagname == "toctree" and node.get("glob"):
                node["entries"].reverse()
                break
542486
def from_defaults(clz, defaults):
        
        if isinstance(defaults, (str, unicode)):
            defaults = json.loads(defaults)
        
        c = clz()
        for attribute in defaults.keys():
            if attribute in c:
                value = defaults[attribute]
                c[attribute].merge(value)
        # in case any values were not specified, attempt to merge them with 
        # the settings provided by clz.random()
        cr = clz.random()
        for attribute, value in cr:
            try:
                c[attribute].merge(value)
            except Contradiction:
                pass
        return c
1293501
def _strip_trailing_zeros(value):
        
        return list(
           reversed(
              list(itertools.dropwhile(lambda x: x == 0, reversed(value)))
           )
        )
302313
def _update_defaults(self, defaults, old_version, verbose=False):
        """"""
        old_defaults = self._load_old_defaults(old_version)
        for section, options in defaults:
            for option in options:
                new_value = options[ option ]
                try:
                    old_value = old_defaults.get(section, option)
                except (cp.NoSectionError, cp.NoOptionError):
                    old_value = None
                if old_value is None or \
                  to_text_string(new_value) != old_value:
                    self._set(section, option, new_value, verbose)
366048
def simple_defaults(self, defaults_dic):
        

        defaults=[]
        for d in defaults_dic.keys():
            dic={}
            dic["visualProperty"]=d
            dic["value"]=defaults_dic[d]
            defaults.append(dic)
        return defaults
40723
def key_value_to_tree(data):
    '''
    
    '''
    tree = {}
    for flatkey, value in six.iteritems(data):
        t = tree
        keys = flatkey.split(__opts__['pepa_delimiter'])
        for i, key in enumerate(keys, 1):
            if i == len(keys):
                t[key] = value
            else:
                t = t.setdefault(key, {})
    return tree
1160446
def preprocess_value(self, value, default=tuple()):
        
        # empty value
        if not value:
            return default

        # list with one empty item
        if isinstance(value, (list, tuple)):
            if len(value) == 1 and not value[0]:
                return default

        if not isinstance(value, (list, tuple)):
            value = value,

        return value
1039861
def from_values(cls, vals):
        ""
        if util.config.future_deprecations:
            param.main.param.warning("%s.from_values is deprecated, the %s "
                                     "constructor may now be used directly.")
        return cls(items=cls._process_items(vals))
302772
def namedtuple_with_defaults(typename, field_names, default_values=()):
    
    T = collections.namedtuple(typename, field_names)
    T.__new__.__defaults__ = (None, ) * len(T._fields)
    if isinstance(default_values, collections.Mapping):
        prototype = T(**default_values)
    else:
        prototype = T(*default_values)
    T.__new__.__defaults__ = tuple(prototype)
    return T
138257
def set_defaults(lvm_data):
    """"""
    for l in lvm_data:
        for k, v in lvm_data[l].items():
            if v == '':
                lvm_data[l][k] = None

    return lvm_data
262281
def convert_old_variant_handle(handle_dict):
    """"""
    old_variables = handle_dict.get("variables", {})
    variables = dict(repository_type="filesystem")

    for old_key, key in variant_key_conversions.iteritems():
        value = old_variables.get(old_key)
        #if value is not None:
        variables[key] = value

    path = handle_dict["path"]
    filename = os.path.basename(path)
    if os.path.splitext(filename)[0] == "package":
        key = "filesystem.variant"
    else:
        key = "filesystem.variant.combined"

    return dict(key=key, variables=variables)
696489
private function normalizeDefault()
    {
        if (!$this->hasDefaultValue()) {
            return;
        }

        if ($this->defaultValue[0] == '(' && $this->defaultValue[strlen($this->defaultValue) - 1] == ')') {
            //Cut braces
            $this->defaultValue = substr($this->defaultValue, 1, -1);
        }

        if (preg_match('/^[\'""].*?[\'"]$/', $this->defaultValue)) {
            $this->defaultValue = substr($this->defaultValue, 1, -1);
        }

        if (
            $this->getType() != 'string'
            && ($this->defaultValue[0] == '(' && $this->defaultValue[strlen($this->defaultValue) - 1] == ')')
        ) {
            //Cut another braces
            $this->defaultValue = substr($this->defaultValue, 1, -1);
        }
    }
1235325
def template_to_dict_alt(tree, title):
    
    box = []
    part = []

    for item in tree.iter():

        if item.tag == 'part':
            if part:
                box.append(part)
            part = []

        if item.tag == 'name' or item.tag == 'value':
            for attr in item.keys():
                part.append({attr: item.get(attr)})

            if item.text:
                part.append(item.text.strip())

            if item.tail:
                part.append(item.tail.strip())

    if part:
        box.append(part)

    return {title.strip(): box}
193058
def dump_tree(node, name=None, initial_indent='', indentation='    ',
              maxline=120, maxmerged=80,
              # Runtime optimization
              iter_node=iter_node, special=ast.AST,
              list=list, isinstance=isinstance, type=type, len=len):
    
    def dump(node, name=None, indent=''):
        level = indent + indentation
        name = name and name + '=' or ''
        values = list(iter_node(node))
        if isinstance(node, list):
            prefix, suffix = '%s[' % name, ']'
        elif values:
            prefix, suffix = '%s%s(' % (name, type(node).__name__), ')'
        elif isinstance(node, special):
            prefix, suffix = name + type(node).__name__, ''
        else:
            return '%s%s' % (name, repr(node))
        node = [dump(a, b, level) for a, b in values if b != 'ctx']
        oneline = '%s%s%s' % (prefix, ', '.join(node), suffix)
        if len(oneline) + len(indent) < maxline:
            return '%s' % oneline
        if node and len(prefix) + len(node[0]) < maxmerged:
            prefix = '%s%s,' % (prefix, node.pop(0))
        node = (',\n%s' % level).join(node).lstrip()
        return '%s\n%s%s%s' % (prefix, level, node, suffix)
    return dump(node, name, initial_indent)