nodes: 0, module; 1, function_definition; 2, function_name:to_file; 3, parameters; 4, block; 5, identifier:self; 6, identifier:f; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, expression_statement; 11, if_statement; 12, if_statement; 13, if_statement; 14, try_statement; 15, identifier:sorted; 16, True; 17, identifier:relativize; 18, True; 19, identifier:nl; 20, None; 21, comment:"""Write a zone to a file.
  
          @param f: file or string.  If I{f} is a string, it is treated
          as the name of a file to open.
          @param sorted: if True, the file will be written with the
          names sorted in DNSSEC order from least to greatest.  Otherwise
          the names will be written in whatever order they happen to have
          in the zone's dictionary.
          @param relativize: if True, domain names in the output will be
          relativized to the zone's origin (if possible).
          @type relativize: bool
          @param nl: The end of line string.  If not specified, the
          output will use the platform's native end-of-line marker (i.e.
          LF on POSIX, CRLF on Windows, CR on Macintosh).
          @type nl: string or None
          """; 22, comparison_operator:sys.hexversion >= 0x02030000; 23, comment:# allow Unicode filenames; 24, block; 25, else_clause; 26, comparison_operator:nl is None; 27, block; 28, else_clause; 29, call; 30, block; 31, else_clause; 32, block; 33, finally_clause; 34, attribute; 35, integer:0x02030000; 36, expression_statement; 37, block; 38, identifier:nl; 39, None; 40, expression_statement; 41, block; 42, identifier:isinstance; 43, argument_list; 44, expression_statement; 45, expression_statement; 46, block; 47, if_statement; 48, for_statement; 49, block; 50, identifier:sys; 51, identifier:hexversion; 52, assignment; 53, expression_statement; 54, assignment; 55, expression_statement; 56, identifier:f; 57, identifier:str_type; 58, assignment; 59, assignment; 60, expression_statement; 61, identifier:sorted; 62, block; 63, else_clause; 64, identifier:n; 65, identifier:names; 66, block; 67, if_statement; 68, identifier:str_type; 69, identifier:basestring; 70, assignment; 71, identifier:opts; 72, string; 73, assignment; 74, identifier:f; 75, call; 76, identifier:want_close; 77, True; 78, assignment; 79, expression_statement; 80, expression_statement; 81, block; 82, expression_statement; 83, if_statement; 84, identifier:want_close; 85, block; 86, identifier:str_type; 87, identifier:str; 88, string_content:w; 89, identifier:opts; 90, string; 91, identifier:file; 92, argument_list; 93, identifier:want_close; 94, False; 95, assignment; 96, call; 97, expression_statement; 98, assignment; 99, comparison_operator:nl is None; 100, block; 101, else_clause; 102, expression_statement; 103, string_content:wb; 104, identifier:f; 105, identifier:opts; 106, identifier:names; 107, call; 108, attribute; 109, argument_list; 110, assignment; 111, identifier:l; 112, call; 113, identifier:nl; 114, None; 115, print_statement; 116, block; 117, call; 118, attribute; 119, argument_list; 120, identifier:names; 121, identifier:sort; 122, identifier:names; 123, call; 124, attribute; 125, argument_list; 126, chevron; 127, identifier:l; 128, expression_statement; 129, expression_statement; 130, attribute; 131, argument_list; 132, identifier:self; 133, identifier:keys; 134, attribute; 135, argument_list; 136, subscript; 137, identifier:to_text; 138, identifier:n; 139, keyword_argument; 140, keyword_argument; 141, identifier:f; 142, call; 143, call; 144, identifier:f; 145, identifier:close; 146, identifier:self; 147, identifier:iterkeys; 148, identifier:self; 149, identifier:n; 150, identifier:origin; 151, attribute; 152, identifier:relativize; 153, identifier:relativize; 154, attribute; 155, argument_list; 156, attribute; 157, argument_list; 158, identifier:self; 159, identifier:origin; 160, identifier:f; 161, identifier:write; 162, identifier:l; 163, identifier:f; 164, identifier:write; 165, identifier:nl
code: def to_file(self, f, sorted=True, relativize=True, nl=None):
          """Write a zone to a file.
  
          @param f: file or string.  If I{f} is a string, it is treated
          as the name of a file to open.
          @param sorted: if True, the file will be written with the
          names sorted in DNSSEC order from least to greatest.  Otherwise
          the names will be written in whatever order they happen to have
          in the zone's dictionary.
          @param relativize: if True, domain names in the output will be
          relativized to the zone's origin (if possible).
          @type relativize: bool
          @param nl: The end of line string.  If not specified, the
          output will use the platform's native end-of-line marker (i.e.
          LF on POSIX, CRLF on Windows, CR on Macintosh).
          @type nl: string or None
          """
  
          if sys.hexversion >= 0x02030000:
              # allow Unicode filenames
              str_type = basestring
          else:
              str_type = str
          if nl is None:
              opts = 'w'
          else:
              opts = 'wb'
          if isinstance(f, str_type):
              f = file(f, opts)
              want_close = True
          else:
              want_close = False
          try:
              if sorted:
                  names = self.keys()
                  names.sort()
              else:
                  names = self.iterkeys()
              for n in names:
                  l = self[n].to_text(n, origin=self.origin,
                                      relativize=relativize)
                  if nl is None:
                      print >> f, l
                  else:
                      f.write(l)
                      f.write(nl)
          finally:
              if want_close:
                  f.close()