nodes: 0, module; 1, function_definition; 2, function_name:flair_template_sync; 3, parameters; 4, block; 5, identifier:self; 6, identifier:editable; 7, identifier:limit; 8, comment:# pylint: disable=R0912; 9, identifier:static; 10, identifier:sort; 11, identifier:use_css; 12, identifier:use_text; 13, expression_statement; 14, comment:# Parameter verification; 15, if_statement; 16, expression_statement; 17, if_statement; 18, comment:# Build current flair list along with static values; 19, expression_statement; 20, if_statement; 21, if_statement; 22, for_statement; 23, if_statement; 24, comment:# Sort flair list items according to the specified sort; 25, if_statement; 26, comment:# Clear current templates and store flair according to the sort; 27, if_statement; 28, expression_statement; 29, for_statement; 30, comment:"""Synchronize templates with flair that already exists on the site.
  
          :param editable: Indicates that all the options should be editable.
          :param limit: The minimum number of users that must share the flair
              before it is added as a template.
          :param static: A list of flair templates that will always be added.
          :param sort: The order to sort the flair templates.
          :param use_css: Include css in the templates.
          :param use_text: Include text in the templates.
  
          """; 31, boolean_operator; 32, block; 33, assignment; 34, comparison_operator:sort not in sorts; 35, block; 36, assignment; 37, identifier:static; 38, block; 39, attribute; 40, block; 41, identifier:flair; 42, call; 43, block; 44, attribute; 45, block; 46, comparison_operator:sort == 'alpha'; 47, block; 48, else_clause; 49, attribute; 50, block; 51, call; 52, pattern_list; 53, identifier:items; 54, block; 55, not_operator; 56, not_operator; 57, raise_statement; 58, identifier:sorts; 59, tuple; 60, identifier:sort; 61, identifier:sorts; 62, raise_statement; 63, identifier:counter; 64, dictionary; 65, for_statement; 66, identifier:self; 67, identifier:verbose; 68, expression_statement; 69, expression_statement; 70, attribute; 71, argument_list; 72, if_statement; 73, if_statement; 74, if_statement; 75, identifier:self; 76, identifier:verbose; 77, expression_statement; 78, identifier:sort; 79, string; 80, expression_statement; 81, block; 82, identifier:self; 83, identifier:verbose; 84, expression_statement; 85, attribute; 86, argument_list; 87, identifier:key; 88, identifier:count; 89, if_statement; 90, if_statement; 91, if_statement; 92, expression_statement; 93, identifier:use_text; 94, identifier:use_css; 95, call; 96, string; 97, string; 98, call; 99, identifier:key; 100, identifier:static; 101, block; 102, call; 103, call; 104, identifier:self; 105, identifier:current_flair; 106, attribute; 107, block; 108, boolean_operator; 109, block; 110, elif_clause; 111, else_clause; 112, comparison_operator:key in counter; 113, block; 114, else_clause; 115, call; 116, string_content:alpha; 117, assignment; 118, expression_statement; 119, call; 120, attribute; 121, identifier:clear; 122, boolean_operator; 123, block; 124, boolean_operator; 125, block; 126, elif_clause; 127, else_clause; 128, attribute; 129, block; 130, call; 131, identifier:Exception; 132, argument_list; 133, string_content:alpha; 134, string_content:size; 135, identifier:Exception; 136, argument_list; 137, if_statement; 138, expression_statement; 139, attribute; 140, argument_list; 141, attribute; 142, argument_list; 143, identifier:self; 144, identifier:verbose; 145, expression_statement; 146, expression_statement; 147, identifier:use_text; 148, identifier:use_css; 149, expression_statement; 150, identifier:use_text; 151, block; 152, block; 153, identifier:key; 154, identifier:counter; 155, expression_statement; 156, block; 157, identifier:print; 158, argument_list; 159, identifier:items; 160, call; 161, assignment; 162, identifier:print; 163, argument_list; 164, attribute; 165, identifier:templates; 166, not_operator; 167, comparison_operator:count < limit; 168, expression_statement; 169, continue_statement; 170, identifier:use_text; 171, identifier:use_css; 172, expression_statement; 173, identifier:use_text; 174, block; 175, block; 176, identifier:self; 177, identifier:verbose; 178, expression_statement; 179, attribute; 180, argument_list; 181, string; 182, call; 183, boolean_operator; 184, block; 185, assignment; 186, attribute; 187, identifier:write; 188, string; 189, attribute; 190, identifier:flush; 191, call; 192, call; 193, assignment; 194, expression_statement; 195, expression_statement; 196, augmented_assignment; 197, expression_statement; 198, identifier:sorted; 199, argument_list; 200, identifier:items; 201, call; 202, string; 203, attribute; 204, identifier:flair; 205, identifier:key; 206, identifier:count; 207, identifier:limit; 208, call; 209, assignment; 210, expression_statement; 211, expression_statement; 212, call; 213, attribute; 214, identifier:add; 215, identifier:text; 216, identifier:css; 217, identifier:editable; 218, string_content:At least one of use_text or use_css must be True; 219, attribute; 220, argument_list; 221, identifier:use_css; 222, identifier:use_text; 223, expression_statement; 224, if_statement; 225, expression_statement; 226, subscript; 227, identifier:limit; 228, identifier:sys; 229, identifier:stdout; 230, string_content; 231, identifier:sys; 232, identifier:stdout; 233, attribute; 234, argument_list; 235, attribute; 236, argument_list; 237, identifier:key; 238, tuple; 239, assignment; 240, assignment; 241, subscript; 242, integer:1; 243, assignment; 244, call; 245, identifier:sorted; 246, argument_list; 247, string_content:Clearing current flair templates; 248, identifier:self; 249, identifier:sub; 250, identifier:print; 251, argument_list; 252, pattern_list; 253, identifier:key; 254, assignment; 255, assignment; 256, identifier:print; 257, argument_list; 258, attribute; 259, identifier:templates; 260, string; 261, identifier:format; 262, call; 263, assignment; 264, comparison_operator:len(parts) != 2; 265, block; 266, assignment; 267, identifier:counter; 268, identifier:key; 269, escape_sequence:\n; 270, attribute; 271, identifier:write; 272, string; 273, attribute; 274, identifier:flush; 275, subscript; 276, subscript; 277, identifier:key; 278, subscript; 279, identifier:key; 280, subscript; 281, identifier:counter; 282, identifier:key; 283, subscript; 284, integer:1; 285, attribute; 286, argument_list; 287, call; 288, keyword_argument; 289, keyword_argument; 290, string; 291, identifier:text; 292, identifier:css; 293, pattern_list; 294, expression_list; 295, pattern_list; 296, expression_list; 297, call; 298, attribute; 299, identifier:flair; 300, string_content:Sort must be one of: {}; 301, attribute; 302, argument_list; 303, identifier:parts; 304, call; 305, call; 306, integer:2; 307, raise_statement; 308, identifier:key; 309, identifier:parts; 310, identifier:sys; 311, identifier:stdout; 312, string_content:.; 313, identifier:sys; 314, identifier:stdout; 315, identifier:flair; 316, string; 317, identifier:flair; 318, string; 319, identifier:flair; 320, string; 321, identifier:flair; 322, string; 323, identifier:counter; 324, identifier:key; 325, identifier:counter; 326, identifier:items; 327, attribute; 328, argument_list; 329, identifier:key; 330, lambda; 331, identifier:reverse; 332, True; 333, string_content:a; 334, identifier:text; 335, identifier:css; 336, identifier:key; 337, string; 338, identifier:text; 339, identifier:css; 340, string; 341, identifier:key; 342, attribute; 343, argument_list; 344, identifier:self; 345, identifier:sub; 346, string; 347, identifier:join; 348, identifier:sorts; 349, identifier:tuple; 350, generator_expression; 351, identifier:len; 352, argument_list; 353, call; 354, string_content:flair_text; 355, string_content:flair_css_class; 356, string_content:flair_text; 357, string_content:flair_css_class; 358, identifier:counter; 359, identifier:items; 360, lambda_parameters; 361, subscript; 362, string; 363, identifier:format; 364, identifier:text; 365, identifier:css; 366, string_content:,; 367, call; 368, for_in_clause; 369, identifier:parts; 370, identifier:Exception; 371, argument_list; 372, identifier:x; 373, identifier:x; 374, integer:1; 375, string_content:Adding template: text: {!r} css: {!r}; 376, attribute; 377, argument_list; 378, identifier:x; 379, call; 380, call; 381, identifier:x; 382, identifier:strip; 383, attribute; 384, argument_list; 385, attribute; 386, argument_list; 387, identifier:key; 388, identifier:split; 389, string; 390, concatenated_string; 391, identifier:format; 392, identifier:parts; 393, string_content:,; 394, string; 395, string; 396, string; 397, string_content:--static argument {!r} must have two; 398, string_content:parts (comma separated) when using; 399, string_content:both text and css.
code: def flair_template_sync(self, editable, limit,  # pylint: disable=R0912
                              static, sort, use_css, use_text):
          """Synchronize templates with flair that already exists on the site.
  
          :param editable: Indicates that all the options should be editable.
          :param limit: The minimum number of users that must share the flair
              before it is added as a template.
          :param static: A list of flair templates that will always be added.
          :param sort: The order to sort the flair templates.
          :param use_css: Include css in the templates.
          :param use_text: Include text in the templates.
  
          """
          # Parameter verification
          if not use_text and not use_css:
              raise Exception('At least one of use_text or use_css must be True')
          sorts = ('alpha', 'size')
          if sort not in sorts:
              raise Exception('Sort must be one of: {}'.format(', '.join(sorts)))
  
          # Build current flair list along with static values
          counter = {}
          if static:
              for key in static:
                  if use_css and use_text:
                      parts = tuple(x.strip() for x in key.split(','))
                      if len(parts) != 2:
                          raise Exception('--static argument {!r} must have two '
                                          'parts (comma separated) when using '
                                          'both text and css.'.format(parts))
                      key = parts
                  counter[key] = limit
          if self.verbose:
              sys.stdout.write('Retrieving current flair\n')
              sys.stdout.flush()
          for flair in self.current_flair():
              if self.verbose:
                  sys.stdout.write('.')
                  sys.stdout.flush()
              if use_text and use_css:
                  key = (flair['flair_text'], flair['flair_css_class'])
              elif use_text:
                  key = flair['flair_text']
              else:
                  key = flair['flair_css_class']
              if key in counter:
                  counter[key] += 1
              else:
                  counter[key] = 1
          if self.verbose:
              print()
  
          # Sort flair list items according to the specified sort
          if sort == 'alpha':
              items = sorted(counter.items())
          else:
              items = sorted(counter.items(), key=lambda x: x[1], reverse=True)
  
          # Clear current templates and store flair according to the sort
          if self.verbose:
              print('Clearing current flair templates')
          self.sub.flair.templates.clear()
          for key, count in items:
              if not key or count < limit:
                  print('a')
                  continue
              if use_text and use_css:
                  text, css = key
              elif use_text:
                  text, css = key, ''
              else:
                  text, css = '', key
              if self.verbose:
                  print('Adding template: text: {!r} css: {!r}'
                        .format(text, css))
              self.sub.flair.templates.add(text, css, editable)