nodes: 0, module; 1, function_definition; 2, function_name:_wrap; 3, parameters; 4, type; 5, block; 6, identifier:self; 7, typed_parameter; 8, identifier:str; 9, expression_statement; 10, expression_statement; 11, if_statement; 12, return_statement; 13, identifier:line; 14, type; 15, comment:"""
              Returns an import wrapped to the specified line-length, if possible.
          """; 16, assignment; 17, boolean_operator; 18, block; 19, elif_clause; 20, identifier:line; 21, identifier:str; 22, identifier:wrap_mode; 23, subscript; 24, comparison_operator:len(line) > self.config['line_length']; 25, comparison_operator:wrap_mode != WrapModes.NOQA; 26, expression_statement; 27, expression_statement; 28, if_statement; 29, for_statement; 30, boolean_operator; 31, block; 32, attribute; 33, string; 34, call; 35, subscript; 36, identifier:wrap_mode; 37, attribute; 38, assignment; 39, assignment; 40, comparison_operator:'#' in line; 41, block; 42, identifier:splitter; 43, tuple; 44, block; 45, comparison_operator:len(line) > self.config['line_length']; 46, comparison_operator:wrap_mode == settings.WrapModes.NOQA; 47, if_statement; 48, identifier:self; 49, identifier:config; 50, string_content:multi_line_output; 51, identifier:len; 52, argument_list; 53, attribute; 54, string; 55, identifier:WrapModes; 56, identifier:NOQA; 57, identifier:line_without_comment; 58, identifier:line; 59, identifier:comment; 60, None; 61, string; 62, identifier:line; 63, expression_statement; 64, string:"import "; 65, string:"."; 66, string:"as "; 67, expression_statement; 68, if_statement; 69, call; 70, subscript; 71, identifier:wrap_mode; 72, attribute; 73, comparison_operator:"# NOQA" not in line; 74, block; 75, identifier:line; 76, identifier:self; 77, identifier:config; 78, string_content:line_length; 79, string_content:#; 80, assignment; 81, assignment; 82, boolean_operator; 83, block; 84, identifier:len; 85, argument_list; 86, attribute; 87, string; 88, attribute; 89, identifier:NOQA; 90, string:"# NOQA"; 91, identifier:line; 92, return_statement; 93, pattern_list; 94, call; 95, identifier:exp; 96, binary_operator:r"\b" + re.escape(splitter) + r"\b"; 97, call; 98, not_operator; 99, expression_statement; 100, if_statement; 101, expression_statement; 102, while_statement; 103, if_statement; 104, expression_statement; 105, if_statement; 106, return_statement; 107, identifier:line; 108, identifier:self; 109, identifier:config; 110, string_content:line_length; 111, identifier:settings; 112, identifier:WrapModes; 113, call; 114, identifier:line_without_comment; 115, identifier:comment; 116, attribute; 117, argument_list; 118, binary_operator:r"\b" + re.escape(splitter); 119, string:r"\b"; 120, attribute; 121, argument_list; 122, call; 123, assignment; 124, identifier:comment; 125, block; 126, assignment; 127, boolean_operator; 128, block; 129, not_operator; 130, block; 131, assignment; 132, subscript; 133, block; 134, call; 135, attribute; 136, argument_list; 137, identifier:line; 138, identifier:split; 139, string; 140, integer:1; 141, string:r"\b"; 142, call; 143, identifier:re; 144, identifier:search; 145, identifier:exp; 146, identifier:line_without_comment; 147, attribute; 148, argument_list; 149, identifier:line_parts; 150, call; 151, expression_statement; 152, identifier:next_line; 153, list; 154, comparison_operator:(len(line) + 2) > (self.config['wrap_length'] or self.config['line_length']); 155, identifier:line_parts; 156, expression_statement; 157, expression_statement; 158, identifier:line; 159, expression_statement; 160, identifier:cont_line; 161, call; 162, attribute; 163, string; 164, expression_statement; 165, expression_statement; 166, if_statement; 167, return_statement; 168, attribute; 169, argument_list; 170, string:"{0}{1} NOQA"; 171, identifier:format; 172, identifier:line; 173, subscript; 174, string_content:#; 175, attribute; 176, argument_list; 177, call; 178, identifier:startswith; 179, identifier:splitter; 180, attribute; 181, argument_list; 182, assignment; 183, parenthesized_expression; 184, parenthesized_expression; 185, call; 186, assignment; 187, assignment; 188, attribute; 189, argument_list; 190, identifier:self; 191, identifier:config; 192, string_content:use_parentheses; 193, assignment; 194, assignment; 195, boolean_operator; 196, block; 197, call; 198, string:"{0}{1}\\{2}{3}"; 199, identifier:format; 200, identifier:line; 201, identifier:splitter; 202, attribute; 203, identifier:cont_line; 204, attribute; 205, string; 206, identifier:re; 207, identifier:escape; 208, identifier:splitter; 209, attribute; 210, argument_list; 211, identifier:re; 212, identifier:split; 213, identifier:exp; 214, identifier:line_without_comment; 215, subscript; 216, call; 217, binary_operator:len(line) + 2; 218, boolean_operator; 219, attribute; 220, argument_list; 221, identifier:line; 222, call; 223, identifier:line; 224, call; 225, identifier:self; 226, identifier:_wrap; 227, binary_operator:self.config['indent'] + splitter.join(next_line).lstrip(); 228, identifier:output; 229, call; 230, identifier:lines; 231, call; 232, comparison_operator:self.config['comment_prefix'] in lines[-1]; 233, call; 234, expression_statement; 235, expression_statement; 236, attribute; 237, argument_list; 238, identifier:self; 239, identifier:line_separator; 240, identifier:self; 241, identifier:config; 242, string_content:comment_prefix; 243, identifier:line_without_comment; 244, identifier:strip; 245, identifier:line_parts; 246, unary_operator; 247, attribute; 248, argument_list; 249, call; 250, integer:2; 251, subscript; 252, subscript; 253, identifier:next_line; 254, identifier:append; 255, call; 256, attribute; 257, argument_list; 258, attribute; 259, argument_list; 260, subscript; 261, call; 262, attribute; 263, argument_list; 264, attribute; 265, argument_list; 266, subscript; 267, subscript; 268, attribute; 269, argument_list; 270, assignment; 271, assignment; 272, attribute; 273, identifier:join; 274, identifier:lines; 275, integer:1; 276, string; 277, identifier:format; 278, subscript; 279, identifier:comment; 280, identifier:len; 281, argument_list; 282, attribute; 283, string; 284, attribute; 285, string; 286, attribute; 287, argument_list; 288, identifier:splitter; 289, identifier:join; 290, identifier:line_parts; 291, identifier:next_line; 292, identifier:pop; 293, attribute; 294, string; 295, attribute; 296, argument_list; 297, string:"{0}{1}({2}{3}{4}{5})"; 298, identifier:format; 299, identifier:line; 300, identifier:splitter; 301, attribute; 302, identifier:cont_line; 303, conditional_expression:"," if self.config['include_trailing_comma'] else ""; 304, conditional_expression:self.line_separator if wrap_mode in {WrapModes.VERTICAL_HANGING_INDENT,
                                                                   WrapModes.VERTICAL_GRID_GROUPED}
                              else ""; 305, identifier:output; 306, identifier:split; 307, attribute; 308, attribute; 309, string; 310, identifier:lines; 311, unary_operator; 312, subscript; 313, identifier:endswith; 314, string; 315, pattern_list; 316, call; 317, subscript; 318, binary_operator:line + ')' + self.config['comment_prefix'] + comment[:-1]; 319, identifier:self; 320, identifier:line_separator; 321, string_content:{0}#{1}; 322, identifier:line_parts; 323, unary_operator; 324, identifier:line; 325, identifier:self; 326, identifier:config; 327, string_content:wrap_length; 328, identifier:self; 329, identifier:config; 330, string_content:line_length; 331, identifier:line_parts; 332, identifier:pop; 333, identifier:self; 334, identifier:config; 335, string_content:indent; 336, call; 337, identifier:lstrip; 338, identifier:self; 339, identifier:line_separator; 340, string:","; 341, subscript; 342, string:""; 343, attribute; 344, comparison_operator:wrap_mode in {WrapModes.VERTICAL_HANGING_INDENT,
                                                                   WrapModes.VERTICAL_GRID_GROUPED}; 345, string:""; 346, identifier:self; 347, identifier:line_separator; 348, identifier:self; 349, identifier:config; 350, string_content:comment_prefix; 351, integer:1; 352, identifier:lines; 353, unary_operator; 354, string_content:); 355, identifier:line; 356, identifier:comment; 357, attribute; 358, argument_list; 359, identifier:lines; 360, unary_operator; 361, binary_operator:line + ')' + self.config['comment_prefix']; 362, subscript; 363, integer:1; 364, attribute; 365, argument_list; 366, attribute; 367, string; 368, identifier:self; 369, identifier:line_separator; 370, identifier:wrap_mode; 371, set; 372, integer:1; 373, subscript; 374, identifier:split; 375, subscript; 376, integer:1; 377, integer:1; 378, binary_operator:line + ')'; 379, subscript; 380, identifier:comment; 381, slice; 382, identifier:splitter; 383, identifier:join; 384, identifier:next_line; 385, identifier:self; 386, identifier:config; 387, string_content:include_trailing_comma; 388, attribute; 389, attribute; 390, identifier:lines; 391, unary_operator; 392, attribute; 393, string; 394, identifier:line; 395, string; 396, attribute; 397, string; 398, unary_operator; 399, identifier:WrapModes; 400, identifier:VERTICAL_HANGING_INDENT; 401, identifier:WrapModes; 402, identifier:VERTICAL_GRID_GROUPED; 403, integer:1; 404, identifier:self; 405, identifier:config; 406, string_content:comment_prefix; 407, string_content:); 408, identifier:self; 409, identifier:config; 410, string_content:comment_prefix; 411, integer:1
code: def _wrap(self, line: str) -> str:
          """
              Returns an import wrapped to the specified line-length, if possible.
          """
          wrap_mode = self.config['multi_line_output']
          if len(line) > self.config['line_length'] and wrap_mode != WrapModes.NOQA:
              line_without_comment = line
              comment = None
              if '#' in line:
                  line_without_comment, comment = line.split('#', 1)
              for splitter in ("import ", ".", "as "):
                  exp = r"\b" + re.escape(splitter) + r"\b"
                  if re.search(exp, line_without_comment) and not line_without_comment.strip().startswith(splitter):
                      line_parts = re.split(exp, line_without_comment)
                      if comment:
                          line_parts[-1] = '{0}#{1}'.format(line_parts[-1], comment)
                      next_line = []
                      while (len(line) + 2) > (self.config['wrap_length'] or self.config['line_length']) and line_parts:
                          next_line.append(line_parts.pop())
                          line = splitter.join(line_parts)
                      if not line:
                          line = next_line.pop()
  
                      cont_line = self._wrap(self.config['indent'] + splitter.join(next_line).lstrip())
                      if self.config['use_parentheses']:
                          output = "{0}{1}({2}{3}{4}{5})".format(
                              line, splitter, self.line_separator, cont_line,
                              "," if self.config['include_trailing_comma'] else "",
                              self.line_separator if wrap_mode in {WrapModes.VERTICAL_HANGING_INDENT,
                                                                   WrapModes.VERTICAL_GRID_GROUPED}
                              else "")
                          lines = output.split(self.line_separator)
                          if self.config['comment_prefix'] in lines[-1] and lines[-1].endswith(')'):
                              line, comment = lines[-1].split(self.config['comment_prefix'], 1)
                              lines[-1] = line + ')' + self.config['comment_prefix'] + comment[:-1]
                          return self.line_separator.join(lines)
                      return "{0}{1}\\{2}{3}".format(line, splitter, self.line_separator, cont_line)
          elif len(line) > self.config['line_length'] and wrap_mode == settings.WrapModes.NOQA:
              if "# NOQA" not in line:
                  return "{0}{1} NOQA".format(line, self.config['comment_prefix'])
  
          return line