nodes: 0, module; 1, function_definition; 2, function_name:__parse_organizations; 3, parameters; 4, block; 5, identifier:self; 6, identifier:json; 7, expression_statement; 8, try_statement; 9, comment:"""Parse organizations using Sorting Hat format.
  
          The Sorting Hat organizations format is a JSON stream which
          its keys are the name of the organizations. Each organization
          object has a list of domains. For instance:
  
          {
              "organizations": {
                  "Bitergia": [
                      {
                          "domain": "api.bitergia.com",
                          "is_top": false
                      },
                      {
                          "domain": "bitergia.com",
                          "is_top": true
                      }
                  ],
                  "Example": []
              },
              "time": "2015-01-20 20:10:56.133378"
          }
  
          :param json: stream to parse
  
          :raises InvalidFormatError: raised when the format of the stream is
              not valid.
          """; 10, block; 11, except_clause; 12, for_statement; 13, as_pattern; 14, block; 15, identifier:organization; 16, subscript; 17, block; 18, identifier:KeyError; 19, as_pattern_target; 20, expression_statement; 21, raise_statement; 22, identifier:json; 23, string; 24, expression_statement; 25, expression_statement; 26, if_statement; 27, expression_statement; 28, for_statement; 29, identifier:e; 30, assignment; 31, call; 32, string_content:organizations; 33, assignment; 34, assignment; 35, not_operator; 36, block; 37, assignment; 38, identifier:domain; 39, identifier:domains; 40, block; 41, identifier:msg; 42, binary_operator:"invalid json format. Attribute %s not found" % e.args; 43, identifier:InvalidFormatError; 44, argument_list; 45, identifier:name; 46, call; 47, identifier:org; 48, call; 49, identifier:org; 50, expression_statement; 51, expression_statement; 52, identifier:domains; 53, subscript; 54, if_statement; 55, expression_statement; 56, expression_statement; 57, string:"invalid json format. Attribute %s not found"; 58, attribute; 59, keyword_argument; 60, attribute; 61, argument_list; 62, attribute; 63, argument_list; 64, assignment; 65, assignment; 66, subscript; 67, identifier:organization; 68, comparison_operator:type(domain['is_top']) != bool; 69, block; 70, assignment; 71, call; 72, identifier:e; 73, identifier:args; 74, identifier:cause; 75, identifier:msg; 76, identifier:self; 77, identifier:__encode; 78, identifier:organization; 79, attribute; 80, identifier:get; 81, identifier:name; 82, None; 83, identifier:org; 84, call; 85, subscript; 86, identifier:org; 87, identifier:json; 88, string; 89, call; 90, identifier:bool; 91, expression_statement; 92, raise_statement; 93, identifier:dom; 94, call; 95, attribute; 96, argument_list; 97, identifier:self; 98, identifier:_organizations; 99, identifier:Organization; 100, argument_list; 101, attribute; 102, identifier:name; 103, string_content:organizations; 104, identifier:type; 105, argument_list; 106, assignment; 107, call; 108, identifier:Domain; 109, argument_list; 110, attribute; 111, identifier:append; 112, identifier:dom; 113, keyword_argument; 114, identifier:self; 115, identifier:_organizations; 116, subscript; 117, identifier:msg; 118, string:"invalid json format. 'is_top' must have a bool value"; 119, identifier:InvalidFormatError; 120, argument_list; 121, keyword_argument; 122, keyword_argument; 123, identifier:org; 124, identifier:domains; 125, identifier:name; 126, identifier:name; 127, identifier:domain; 128, string; 129, keyword_argument; 130, identifier:domain; 131, subscript; 132, identifier:is_top_domain; 133, subscript; 134, string_content:is_top; 135, identifier:cause; 136, identifier:msg; 137, identifier:domain; 138, string; 139, identifier:domain; 140, string; 141, string_content:domain; 142, string_content:is_top
code: def __parse_organizations(self, json):
          """Parse organizations using Sorting Hat format.
  
          The Sorting Hat organizations format is a JSON stream which
          its keys are the name of the organizations. Each organization
          object has a list of domains. For instance:
  
          {
              "organizations": {
                  "Bitergia": [
                      {
                          "domain": "api.bitergia.com",
                          "is_top": false
                      },
                      {
                          "domain": "bitergia.com",
                          "is_top": true
                      }
                  ],
                  "Example": []
              },
              "time": "2015-01-20 20:10:56.133378"
          }
  
          :param json: stream to parse
  
          :raises InvalidFormatError: raised when the format of the stream is
              not valid.
          """
          try:
              for organization in json['organizations']:
                  name = self.__encode(organization)
  
                  org = self._organizations.get(name, None)
  
                  if not org:
                      org = Organization(name=name)
                      self._organizations[name] = org
  
                  domains = json['organizations'][organization]
  
                  for domain in domains:
                      if type(domain['is_top']) != bool:
                          msg = "invalid json format. 'is_top' must have a bool value"
                          raise InvalidFormatError(cause=msg)
  
                      dom = Domain(domain=domain['domain'],
                                   is_top_domain=domain['is_top'])
                      org.domains.append(dom)
          except KeyError as e:
              msg = "invalid json format. Attribute %s not found" % e.args
              raise InvalidFormatError(cause=msg)