Maintain unique name within parent_id scope.
 If name is not unique add numeric postfix.
6842
def maintain_name
        postfix = nil
        total_count = 0

        while self.class.where(parent_id: parent_id, name: "#{name}#{postfix}").where("id != ?", id.to_i).exists? do
          total_count += 1
          postfix = "(#{total_count})"
        end

        if postfix
          self.name = "#{name}#{postfix}"
        end
      end
40722
def _relative_name(self, record_name):
        """"""
        # Handle None and empty strings as None
        if not record_name:
            return None
        subdomain = super(Provider, self)._relative_name(record_name)
        return subdomain if subdomain else None
983950
def construct_stable_id(
    parent_context,
    polymorphic_type,
    relative_char_offset_start,
    relative_char_offset_end,
):
    
    doc_id, _, parent_doc_char_start, _ = split_stable_id(parent_context.stable_id)
    start = parent_doc_char_start + relative_char_offset_start
    end = parent_doc_char_start + relative_char_offset_end
    return f"{doc_id}::{polymorphic_type}:{start}:{end}"
539790
def fill_parentidid2obj_r0(self, id2obj, child_obj):
        """"""
        for parent_obj in child_obj.parents:
            if parent_obj.item_id not in id2obj:
                id2obj[parent_obj.item_id] = parent_obj
                self.fill_parentidid2obj_r0(id2obj, parent_obj)
534599
def push_unique(field)
      push(field) unless @fields.detect { |f| f.name? field.name }
      self
    end
1027773
def get_unique_name(name='', collection=()):
    '''
    
    '''
    if name not in collection:
        return name
    i = 1
    while True:
        i += 1
        name2 = '%s_%s' % (name, i)
        if name2 not in collection:
            return name2
742559
def unique_name(self, name):
        
        result = name

        if self.parent is not None:
            index = self.index
            bname = re.sub(r'-[0-9]+$', '', name)
            names = []
            for idx, actor in enumerate(self.parent.actors):
                if idx != index:
                    names.append(actor.name)
            result = bname
            count = 0
            while result in names:
                count += 1
                result = bname + "-" + str(count)

        return result
796061
def set_parent(self, key_name, new_parent):
        """"""
        self.unbake()
        kf = self.dct[key_name]
        kf['parent'] = new_parent
        self.bake()
49040
def v_unique_name_defintions(ctx, stmt):
    """"""
    defs = [('typedef', 'TYPE_ALREADY_DEFINED', stmt.i_typedefs),
            ('grouping', 'GROUPING_ALREADY_DEFINED', stmt.i_groupings)]
    def f(s):
        for (keyword, errcode, dict) in defs:
            if s.keyword == keyword and s.arg in dict:
                err_add(ctx.errors, dict[s.arg].pos,
                        errcode, (s.arg, s.pos))

    for i in stmt.search('include'):
        submodulename = i.arg
        subm = ctx.get_module(submodulename)
        if subm is not None:
            for s in subm.substmts:
                for ss in s.substmts:
                    iterate_stmt(ss, f)
349345
def FindUniqueId(dic):
  """"""
  name = str(len(dic))
  while name in dic:
    # Use bigger numbers so it is obvious when an id is picked randomly.
    name = str(random.randint(1000000, 999999999))
  return name
1368162
def add_unique_postfix(fn):
    """'"""
    if not os.path.exists(fn):
        return fn

    path, name = os.path.split(fn)
    name, ext = os.path.splitext(name)

    make_fn = lambda i: os.path.join(path, '%s(%d)%s' % (name, i, ext))

    for i in xrange(2, sys.maxint):
        uni_fn = make_fn(i)
        if not os.path.exists(uni_fn):
            return uni_fn
1143040
def add(parent, idx, value):
  """"""
  if isinstance(parent, dict):
    if idx in parent:
      raise JSONPatchError("Item already exists")
    parent[idx] = value
  elif isinstance(parent, list):
    if idx == "" or idx == "~":
      parent.append(value)
    else:
      parent.insert(int(idx), value)
  else:
    raise JSONPathError("Invalid path for operation")
364137
def add_to(self, parent, name=None, index=None):
        """"""
        parent.add_child(self, name=name, index=index)
        return self
1284785
def _set_id(self, Id, is_added, index):
        """"""
        if is_added:
            self.selected_ids.add(Id)
        else:
            self.selected_ids.remove(Id)
        self.dataChanged.emit(index, index)
1012284
def __set_name(self, value):
        '''
        
        '''
        if not value or not len(value):
            raise ValueError("Invalid name.")

        self.__name = value
1344314
def insert_child(self, child_pid, index=-1):
        """"""
        if child_pid.status != PIDStatus.REGISTERED:
            raise PIDRelationConsistencyError(
                "Version PIDs should have status 'REGISTERED'. Use "
                "insert_draft_child to insert 'RESERVED' draft PID.")
        with db.session.begin_nested():
            # if there is a draft and "child" is inserted as the last version,
            # it should be inserted before the draft.
            draft = self.draft_child
            if draft and index == -1:
                index = self.index(draft)
            super(PIDNodeVersioning, self).insert_child(child_pid, index=index)
            self.update_redirect()
978875
def unique_def_name(self, stmt, inrpc=False):
        
        module = stmt.main_module()
        name = ""
        while True:
            pref = stmt.arg if stmt.arg else stmt.keyword
            name = "__" + pref + name
            if stmt.keyword == "grouping": name = "_" + name
            if stmt.parent.parent is None: break
            stmt = stmt.parent
        defs = (self.global_defs
                if stmt.keyword in ("grouping", "typedef")
                else self.local_defs)
        if inrpc: name += "__rpc"
        return (module.arg + name, defs)