nodes: 0, module; 1, function_definition; 2, function_name:__sort_registry; 3, parameters; 4, comment:# type: (ServiceReference) -> None; 5, block; 6, identifier:self; 7, identifier:svc_ref; 8, expression_statement; 9, with_statement; 10, comment:"""
          Sorts the registry, after the update of the sort key of given service
          reference
  
          :param svc_ref: A service reference with a modified sort key
          """; 11, with_clause; 12, block; 13, with_item; 14, if_statement; 15, comment:# Remove current references; 16, for_statement; 17, comment:# ... use the new sort key; 18, expression_statement; 19, for_statement; 20, attribute; 21, comparison_operator:svc_ref not in self.__svc_registry; 22, block; 23, identifier:spec; 24, call; 25, comment:# Use bisect to remove the reference (faster); 26, block; 27, call; 28, identifier:spec; 29, call; 30, comment:# ... and insert it again; 31, block; 32, identifier:self; 33, identifier:__svc_lock; 34, identifier:svc_ref; 35, attribute; 36, raise_statement; 37, attribute; 38, argument_list; 39, expression_statement; 40, expression_statement; 41, delete_statement; 42, attribute; 43, argument_list; 44, attribute; 45, argument_list; 46, expression_statement; 47, expression_statement; 48, identifier:self; 49, identifier:__svc_registry; 50, call; 51, identifier:svc_ref; 52, identifier:get_property; 53, identifier:OBJECTCLASS; 54, assignment; 55, assignment; 56, subscript; 57, identifier:svc_ref; 58, identifier:update_sort_key; 59, identifier:svc_ref; 60, identifier:get_property; 61, identifier:OBJECTCLASS; 62, assignment; 63, call; 64, identifier:BundleException; 65, argument_list; 66, identifier:spec_refs; 67, subscript; 68, identifier:idx; 69, call; 70, identifier:spec_refs; 71, identifier:idx; 72, identifier:spec_refs; 73, subscript; 74, attribute; 75, argument_list; 76, call; 77, attribute; 78, identifier:spec; 79, attribute; 80, argument_list; 81, attribute; 82, identifier:spec; 83, identifier:bisect; 84, identifier:insort_left; 85, identifier:spec_refs; 86, identifier:svc_ref; 87, attribute; 88, argument_list; 89, identifier:self; 90, identifier:__svc_specs; 91, identifier:bisect; 92, identifier:bisect_left; 93, identifier:spec_refs; 94, identifier:svc_ref; 95, identifier:self; 96, identifier:__svc_specs; 97, string:"Unknown service: {0}"; 98, identifier:format; 99, identifier:svc_ref
code: def __sort_registry(self, svc_ref):
          # type: (ServiceReference) -> None
          """
          Sorts the registry, after the update of the sort key of given service
          reference
  
          :param svc_ref: A service reference with a modified sort key
          """
          with self.__svc_lock:
              if svc_ref not in self.__svc_registry:
                  raise BundleException("Unknown service: {0}".format(svc_ref))
  
              # Remove current references
              for spec in svc_ref.get_property(OBJECTCLASS):
                  # Use bisect to remove the reference (faster)
                  spec_refs = self.__svc_specs[spec]
                  idx = bisect.bisect_left(spec_refs, svc_ref)
                  del spec_refs[idx]
  
              # ... use the new sort key
              svc_ref.update_sort_key()
  
              for spec in svc_ref.get_property(OBJECTCLASS):
                  # ... and insert it again
                  spec_refs = self.__svc_specs[spec]
                  bisect.insort_left(spec_refs, svc_ref)