bugged
stringlengths
4
228k
fixed
stringlengths
0
96.3M
__index_level_0__
int64
0
481k
def startDocument(self): self._out.write('<?xml version="1.0" encoding="iso-8859-1"?>\n')
def startDocument(self): self._out.write('<?xml version="1.0" encoding="iso-8859-1"?>\n')
8,200
def startPrefixMapping(self, prefix, uri): pass
def startPrefixMapping(self, prefix, uri): pass
8,201
def endPrefixMapping(self, prefix): pass
def endPrefixMapping(self, prefix): pass
8,202
def startElement(self, name, attrs): if type(name) is type(()): uri, localname, prefix = name name = "%s:%s"%(prefix,localname) self._out.write('<' + name) for (name, value) in attrs.items(): self._out.write(' %s="%s"' % (name, escape(value))) self._out.write('>')
def startElement(self, name, attrs): self._out.write('<' + name) for (name, value) in attrs.items(): self._out.write(' %s="%s"' % (name, escape(value))) self._out.write('>')
8,203
def startElement(self, name, attrs): if type(name) is type(()): uri, localname, prefix = name name = "%s:%s"%(prefix,localname) self._out.write('<' + name) for (name, value) in attrs.items(): self._out.write(' %s="%s"' % (name, escape(value))) self._out.write('>')
def startElement(self, name, attrs): if type(name) is type(()): uri, localname, prefix = name name = "%s:%s"%(prefix,localname) self._out.write('<' + name) for (name, value) in attrs.items(): self._out.write(' %s="%s"' % (name, escape(value))) self._out.write('>')
8,204
def endElement(self, name): # FIXME: not namespace friendly yet self._out.write('</%s>' % name)
defendElement(self,name):#FIXME:notnamespacefriendlyyetself._out.write('</%s>'%name)
8,205
def endElement(self, name, qname): self._cont_handler.endElement(name, qname)
def endElement(self, name, qname): self._cont_handler.endElement(name, qname)
8,206
def rewrite_descriptor(doc, descriptor): # # Do these things: # 1. Add an "index='no'" attribute to the element if the tagName # ends in 'ni', removing the 'ni' from the name. # 2. Create a <signature> from the name attribute # 2a.Create an <args> if it appears to be available. # 3. Create additional <signature>s from <*line{,ni}> elements, # if found. # 4. If a <versionadded> is found, move it to an attribute on the # descriptor. # 5. Move remaining child nodes to a <description> element. # 6. Put it back together. # # 1. descname = descriptor.tagName index = descriptor.getAttribute("name") != "no" desctype = descname[:-4] # remove 'desc' linename = desctype + "line" if not index: linename = linename + "ni" # 2. signature = doc.createElement("signature") name = doc.createElement("name") signature.appendChild(doc.createTextNode("\n ")) signature.appendChild(name) name.appendChild(doc.createTextNode(descriptor.getAttribute("name"))) descriptor.removeAttribute("name") # 2a. if descriptor.hasAttribute("var"): if descname != "opcodedesc": raise RuntimeError, \ "got 'var' attribute on descriptor other than opcodedesc" variable = descriptor.getAttribute("var") if variable: args = doc.createElement("args") args.appendChild(doc.createTextNode(variable)) signature.appendChild(doc.createTextNode("\n ")) signature.appendChild(args) descriptor.removeAttribute("var") newchildren = [signature] children = descriptor.childNodes pos = skip_leading_nodes(children) if pos < len(children): child = children[pos] if child.nodeName == "args": # move <args> to <signature>, or remove if empty: child.parentNode.removeChild(child) if len(child.childNodes): signature.appendChild(doc.createTextNode("\n ")) signature.appendChild(child) signature.appendChild(doc.createTextNode("\n ")) # 3, 4. pos = skip_leading_nodes(children, pos) while pos < len(children) \ and children[pos].nodeName in (linename, "versionadded"): if children[pos].tagName == linename: # this is really a supplemental signature, create <signature> oldchild = children[pos].cloneNode(1) try: sig = methodline_to_signature(doc, children[pos]) except KeyError: print oldchild.toxml() raise newchildren.append(sig) else: # <versionadded added=...> descriptor.setAttribute( "added", children[pos].getAttribute("version")) pos = skip_leading_nodes(children, pos + 1) # 5. description = doc.createElement("description") description.appendChild(doc.createTextNode("\n")) newchildren.append(description) move_children(descriptor, description, pos) last = description.childNodes[-1] if last.nodeType == TEXT: last.data = string.rstrip(last.data) + "\n " # 6. # should have nothing but whitespace and signature lines in <descriptor>; # discard them while descriptor.childNodes: descriptor.removeChild(descriptor.childNodes[0]) for node in newchildren: descriptor.appendChild(doc.createTextNode("\n ")) descriptor.appendChild(node) descriptor.appendChild(doc.createTextNode("\n"))
def rewrite_descriptor(doc, descriptor): # # Do these things: # 1. Add an "index='no'" attribute to the element if the tagName # ends in 'ni', removing the 'ni' from the name. # 2. Create a <signature> from the name attribute # 2a.Create an <args> if it appears to be available. # 3. Create additional <signature>s from <*line{,ni}> elements, # if found. # 4. If a <versionadded> is found, move it to an attribute on the # descriptor. # 5. Move remaining child nodes to a <description> element. # 6. Put it back together. # # 1. descname = descriptor.tagName index = descriptor.getAttribute("name") != "no" desctype = descname[:-4] # remove 'desc' linename = desctype + "line" if not index: linename = linename + "ni" # 2. signature = doc.createElement("signature") name = doc.createElement("name") signature.appendChild(doc.createTextNode("\n ")) signature.appendChild(name) name.appendChild(doc.createTextNode(descriptor.getAttribute("name"))) descriptor.removeAttribute("name") # 2a. if descriptor.hasAttribute("var"): if descname != "opcodedesc": raise RuntimeError, \ "got 'var' attribute on descriptor other than opcodedesc" variable = descriptor.getAttribute("var") if variable: args = doc.createElement("args") args.appendChild(doc.createTextNode(variable)) signature.appendChild(doc.createTextNode("\n ")) signature.appendChild(args) descriptor.removeAttribute("var") newchildren = [signature] children = descriptor.childNodes pos = skip_leading_nodes(children) if pos < len(children): child = children[pos] if child.nodeName == "args": # move <args> to <signature>, or remove if empty: child.parentNode.removeChild(child) if len(child.childNodes): signature.appendChild(doc.createTextNode("\n ")) signature.appendChild(child) signature.appendChild(doc.createTextNode("\n ")) # 3, 4. pos = skip_leading_nodes(children, pos) while pos < len(children) \ and children[pos].nodeName in (linename, "versionadded"): if children[pos].tagName == linename: # this is really a supplemental signature, create <signature> oldchild = children[pos].cloneNode(1) try: sig = methodline_to_signature(doc, children[pos]) except KeyError: print oldchild.toxml() raise newchildren.append(sig) else: # <versionadded added=...> descriptor.setAttribute( "added", children[pos].getAttribute("version")) pos = skip_leading_nodes(children, pos + 1) # 5. description = doc.createElement("description") description.appendChild(doc.createTextNode("\n")) newchildren.append(description) move_children(descriptor, description, pos) last = description.childNodes[-1] if last.nodeType == TEXT: last.data = last.data.rstrip() + "\n " # 6. # should have nothing but whitespace and signature lines in <descriptor>; # discard them while descriptor.childNodes: descriptor.removeChild(descriptor.childNodes[0]) for node in newchildren: descriptor.appendChild(doc.createTextNode("\n ")) descriptor.appendChild(node) descriptor.appendChild(doc.createTextNode("\n"))
8,207
def handle_appendix(doc, fragment): # must be called after simplfy() if document is multi-rooted to begin with docelem = get_documentElement(fragment) toplevel = docelem.tagName == "manual" and "chapter" or "section" appendices = 0 nodes = [] for node in docelem.childNodes: if appendices: nodes.append(node) elif node.nodeType == ELEMENT: appnodes = node.getElementsByTagName("appendix") if appnodes: appendices = 1 parent = appnodes[0].parentNode parent.removeChild(appnodes[0]) parent.normalize() if nodes: map(docelem.removeChild, nodes) docelem.appendChild(doc.createTextNode("\n\n\n")) back = doc.createElement("back-matter") docelem.appendChild(back) back.appendChild(doc.createTextNode("\n")) while nodes and nodes[0].nodeType == TEXT \ and not string.strip(nodes[0].data): del nodes[0] map(back.appendChild, nodes) docelem.appendChild(doc.createTextNode("\n"))
def handle_appendix(doc, fragment): # must be called after simplfy() if document is multi-rooted to begin with docelem = get_documentElement(fragment) toplevel = docelem.tagName == "manual" and "chapter" or "section" appendices = 0 nodes = [] for node in docelem.childNodes: if appendices: nodes.append(node) elif node.nodeType == ELEMENT: appnodes = node.getElementsByTagName("appendix") if appnodes: appendices = 1 parent = appnodes[0].parentNode parent.removeChild(appnodes[0]) parent.normalize() if nodes: map(docelem.removeChild, nodes) docelem.appendChild(doc.createTextNode("\n\n\n")) back = doc.createElement("back-matter") docelem.appendChild(back) back.appendChild(doc.createTextNode("\n")) while nodes and nodes[0].nodeType == TEXT \ and not nodes[0].data.strip(): del nodes[0] map(back.appendChild, nodes) docelem.appendChild(doc.createTextNode("\n"))
8,208
def handle_labels(doc, fragment): for label in find_all_elements(fragment, "label"): id = label.getAttribute("id") if not id: continue parent = label.parentNode parentTagName = parent.tagName if parentTagName == "title": parent.parentNode.setAttribute("id", id) else: parent.setAttribute("id", id) # now, remove <label id="..."/> from parent: parent.removeChild(label) if parentTagName == "title": parent.normalize() children = parent.childNodes if children[-1].nodeType == TEXT: children[-1].data = string.rstrip(children[-1].data)
def handle_labels(doc, fragment): for label in find_all_elements(fragment, "label"): id = label.getAttribute("id") if not id: continue parent = label.parentNode parentTagName = parent.tagName if parentTagName == "title": parent.parentNode.setAttribute("id", id) else: parent.setAttribute("id", id) # now, remove <label id="..."/> from parent: parent.removeChild(label) if parentTagName == "title": parent.normalize() children = parent.childNodes if children[-1].nodeType == TEXT: children[-1].data = string.rstrip(children[-1].data)
8,209
def fixup_trailing_whitespace(doc, wsmap): queue = [doc] while queue: node = queue[0] del queue[0] if wsmap.has_key(node.nodeName): ws = wsmap[node.tagName] children = node.childNodes children.reverse() if children[0].nodeType == TEXT: data = string.rstrip(children[0].data) + ws children[0].data = data children.reverse() # hack to get the title in place: if node.tagName == "title" \ and node.parentNode.firstChild.nodeType == ELEMENT: node.parentNode.insertBefore(doc.createText("\n "), node.parentNode.firstChild) for child in node.childNodes: if child.nodeType == ELEMENT: queue.append(child)
def fixup_trailing_whitespace(doc, wsmap): queue = [doc] while queue: node = queue[0] del queue[0] if wsmap.has_key(node.nodeName): ws = wsmap[node.tagName] children = node.childNodes children.reverse() if children[0].nodeType == TEXT: data = string.rstrip(children[0].data) + ws children[0].data = data children.reverse() # hack to get the title in place: if node.tagName == "title" \ and node.parentNode.firstChild.nodeType == ELEMENT: node.parentNode.insertBefore(doc.createText("\n "), node.parentNode.firstChild) for child in node.childNodes: if child.nodeType == ELEMENT: queue.append(child)
8,210
def create_module_info(doc, section): # Heavy. node = extract_first_element(section, "modulesynopsis") if node is None: return set_tagName(node, "synopsis") lastchild = node.childNodes[-1] if lastchild.nodeType == TEXT \ and lastchild.data[-1:] == ".": lastchild.data = lastchild.data[:-1] modauthor = extract_first_element(section, "moduleauthor") if modauthor: set_tagName(modauthor, "author") modauthor.appendChild(doc.createTextNode( modauthor.getAttribute("name"))) modauthor.removeAttribute("name") platform = extract_first_element(section, "platform") if section.tagName == "section": modinfo_pos = 2 modinfo = doc.createElement("moduleinfo") moddecl = extract_first_element(section, "declaremodule") name = None if moddecl: modinfo.appendChild(doc.createTextNode("\n ")) name = moddecl.attributes["name"].value namenode = doc.createElement("name") namenode.appendChild(doc.createTextNode(name)) modinfo.appendChild(namenode) type = moddecl.attributes.get("type") if type: type = type.value modinfo.appendChild(doc.createTextNode("\n ")) typenode = doc.createElement("type") typenode.appendChild(doc.createTextNode(type)) modinfo.appendChild(typenode) versionadded = extract_first_element(section, "versionadded") if versionadded: modinfo.setAttribute("added", versionadded.getAttribute("version")) title = get_first_element(section, "title") if title: children = title.childNodes if len(children) >= 2 \ and children[0].nodeName == "module" \ and children[0].childNodes[0].data == name: # this is it; morph the <title> into <short-synopsis> first_data = children[1] if first_data.data[:4] == " ---": first_data.data = string.lstrip(first_data.data[4:]) set_tagName(title, "short-synopsis") if children[-1].nodeType == TEXT \ and children[-1].data[-1:] == ".": children[-1].data = children[-1].data[:-1] section.removeChild(title) section.removeChild(section.childNodes[0]) title.removeChild(children[0]) modinfo_pos = 0 else: ewrite("module name in title doesn't match" " <declaremodule/>; no <short-synopsis/>\n") else: ewrite("Unexpected condition: <section/> without <title/>\n") modinfo.appendChild(doc.createTextNode("\n ")) modinfo.appendChild(node) if title and not contents_match(title, node): # The short synopsis is actually different, # and needs to be stored: modinfo.appendChild(doc.createTextNode("\n ")) modinfo.appendChild(title) if modauthor: modinfo.appendChild(doc.createTextNode("\n ")) modinfo.appendChild(modauthor) if platform: modinfo.appendChild(doc.createTextNode("\n ")) modinfo.appendChild(platform) modinfo.appendChild(doc.createTextNode("\n ")) section.insertBefore(modinfo, section.childNodes[modinfo_pos]) section.insertBefore(doc.createTextNode("\n "), modinfo) # # The rest of this removes extra newlines from where we cut out # a lot of elements. A lot of code for minimal value, but keeps # keeps the generated *ML from being too funny looking. # section.normalize() children = section.childNodes for i in range(len(children)): node = children[i] if node.nodeName == "moduleinfo": nextnode = children[i+1] if nextnode.nodeType == TEXT: data = nextnode.data if len(string.lstrip(data)) < (len(data) - 4): nextnode.data = "\n\n\n" + string.lstrip(data)
def create_module_info(doc, section): # Heavy. node = extract_first_element(section, "modulesynopsis") if node is None: return set_tagName(node, "synopsis") lastchild = node.childNodes[-1] if lastchild.nodeType == TEXT \ and lastchild.data[-1:] == ".": lastchild.data = lastchild.data[:-1] modauthor = extract_first_element(section, "moduleauthor") if modauthor: set_tagName(modauthor, "author") modauthor.appendChild(doc.createTextNode( modauthor.getAttribute("name"))) modauthor.removeAttribute("name") platform = extract_first_element(section, "platform") if section.tagName == "section": modinfo_pos = 2 modinfo = doc.createElement("moduleinfo") moddecl = extract_first_element(section, "declaremodule") name = None if moddecl: modinfo.appendChild(doc.createTextNode("\n ")) name = moddecl.attributes["name"].value namenode = doc.createElement("name") namenode.appendChild(doc.createTextNode(name)) modinfo.appendChild(namenode) type = moddecl.attributes.get("type") if type: type = type.value modinfo.appendChild(doc.createTextNode("\n ")) typenode = doc.createElement("type") typenode.appendChild(doc.createTextNode(type)) modinfo.appendChild(typenode) versionadded = extract_first_element(section, "versionadded") if versionadded: modinfo.setAttribute("added", versionadded.getAttribute("version")) title = get_first_element(section, "title") if title: children = title.childNodes if len(children) >= 2 \ and children[0].nodeName == "module" \ and children[0].childNodes[0].data == name: # this is it; morph the <title> into <short-synopsis> first_data = children[1] if first_data.data[:4] == " ---": first_data.data = first_data.data[4:].lstrip() set_tagName(title, "short-synopsis") if children[-1].nodeType == TEXT \ and children[-1].data[-1:] == ".": children[-1].data = children[-1].data[:-1] section.removeChild(title) section.removeChild(section.childNodes[0]) title.removeChild(children[0]) modinfo_pos = 0 else: ewrite("module name in title doesn't match" " <declaremodule/>; no <short-synopsis/>\n") else: ewrite("Unexpected condition: <section/> without <title/>\n") modinfo.appendChild(doc.createTextNode("\n ")) modinfo.appendChild(node) if title and not contents_match(title, node): # The short synopsis is actually different, # and needs to be stored: modinfo.appendChild(doc.createTextNode("\n ")) modinfo.appendChild(title) if modauthor: modinfo.appendChild(doc.createTextNode("\n ")) modinfo.appendChild(modauthor) if platform: modinfo.appendChild(doc.createTextNode("\n ")) modinfo.appendChild(platform) modinfo.appendChild(doc.createTextNode("\n ")) section.insertBefore(modinfo, section.childNodes[modinfo_pos]) section.insertBefore(doc.createTextNode("\n "), modinfo) # # The rest of this removes extra newlines from where we cut out # a lot of elements. A lot of code for minimal value, but keeps # keeps the generated *ML from being too funny looking. # section.normalize() children = section.childNodes for i in range(len(children)): node = children[i] if node.nodeName == "moduleinfo": nextnode = children[i+1] if nextnode.nodeType == TEXT: data = nextnode.data if len(string.lstrip(data)) < (len(data) - 4): nextnode.data = "\n\n\n" + string.lstrip(data)
8,211
def create_module_info(doc, section): # Heavy. node = extract_first_element(section, "modulesynopsis") if node is None: return set_tagName(node, "synopsis") lastchild = node.childNodes[-1] if lastchild.nodeType == TEXT \ and lastchild.data[-1:] == ".": lastchild.data = lastchild.data[:-1] modauthor = extract_first_element(section, "moduleauthor") if modauthor: set_tagName(modauthor, "author") modauthor.appendChild(doc.createTextNode( modauthor.getAttribute("name"))) modauthor.removeAttribute("name") platform = extract_first_element(section, "platform") if section.tagName == "section": modinfo_pos = 2 modinfo = doc.createElement("moduleinfo") moddecl = extract_first_element(section, "declaremodule") name = None if moddecl: modinfo.appendChild(doc.createTextNode("\n ")) name = moddecl.attributes["name"].value namenode = doc.createElement("name") namenode.appendChild(doc.createTextNode(name)) modinfo.appendChild(namenode) type = moddecl.attributes.get("type") if type: type = type.value modinfo.appendChild(doc.createTextNode("\n ")) typenode = doc.createElement("type") typenode.appendChild(doc.createTextNode(type)) modinfo.appendChild(typenode) versionadded = extract_first_element(section, "versionadded") if versionadded: modinfo.setAttribute("added", versionadded.getAttribute("version")) title = get_first_element(section, "title") if title: children = title.childNodes if len(children) >= 2 \ and children[0].nodeName == "module" \ and children[0].childNodes[0].data == name: # this is it; morph the <title> into <short-synopsis> first_data = children[1] if first_data.data[:4] == " ---": first_data.data = string.lstrip(first_data.data[4:]) set_tagName(title, "short-synopsis") if children[-1].nodeType == TEXT \ and children[-1].data[-1:] == ".": children[-1].data = children[-1].data[:-1] section.removeChild(title) section.removeChild(section.childNodes[0]) title.removeChild(children[0]) modinfo_pos = 0 else: ewrite("module name in title doesn't match" " <declaremodule/>; no <short-synopsis/>\n") else: ewrite("Unexpected condition: <section/> without <title/>\n") modinfo.appendChild(doc.createTextNode("\n ")) modinfo.appendChild(node) if title and not contents_match(title, node): # The short synopsis is actually different, # and needs to be stored: modinfo.appendChild(doc.createTextNode("\n ")) modinfo.appendChild(title) if modauthor: modinfo.appendChild(doc.createTextNode("\n ")) modinfo.appendChild(modauthor) if platform: modinfo.appendChild(doc.createTextNode("\n ")) modinfo.appendChild(platform) modinfo.appendChild(doc.createTextNode("\n ")) section.insertBefore(modinfo, section.childNodes[modinfo_pos]) section.insertBefore(doc.createTextNode("\n "), modinfo) # # The rest of this removes extra newlines from where we cut out # a lot of elements. A lot of code for minimal value, but keeps # keeps the generated *ML from being too funny looking. # section.normalize() children = section.childNodes for i in range(len(children)): node = children[i] if node.nodeName == "moduleinfo": nextnode = children[i+1] if nextnode.nodeType == TEXT: data = nextnode.data if len(string.lstrip(data)) < (len(data) - 4): nextnode.data = "\n\n\n" + string.lstrip(data)
def create_module_info(doc, section): # Heavy. node = extract_first_element(section, "modulesynopsis") if node is None: return set_tagName(node, "synopsis") lastchild = node.childNodes[-1] if lastchild.nodeType == TEXT \ and lastchild.data[-1:] == ".": lastchild.data = lastchild.data[:-1] modauthor = extract_first_element(section, "moduleauthor") if modauthor: set_tagName(modauthor, "author") modauthor.appendChild(doc.createTextNode( modauthor.getAttribute("name"))) modauthor.removeAttribute("name") platform = extract_first_element(section, "platform") if section.tagName == "section": modinfo_pos = 2 modinfo = doc.createElement("moduleinfo") moddecl = extract_first_element(section, "declaremodule") name = None if moddecl: modinfo.appendChild(doc.createTextNode("\n ")) name = moddecl.attributes["name"].value namenode = doc.createElement("name") namenode.appendChild(doc.createTextNode(name)) modinfo.appendChild(namenode) type = moddecl.attributes.get("type") if type: type = type.value modinfo.appendChild(doc.createTextNode("\n ")) typenode = doc.createElement("type") typenode.appendChild(doc.createTextNode(type)) modinfo.appendChild(typenode) versionadded = extract_first_element(section, "versionadded") if versionadded: modinfo.setAttribute("added", versionadded.getAttribute("version")) title = get_first_element(section, "title") if title: children = title.childNodes if len(children) >= 2 \ and children[0].nodeName == "module" \ and children[0].childNodes[0].data == name: # this is it; morph the <title> into <short-synopsis> first_data = children[1] if first_data.data[:4] == " ---": first_data.data = string.lstrip(first_data.data[4:]) set_tagName(title, "short-synopsis") if children[-1].nodeType == TEXT \ and children[-1].data[-1:] == ".": children[-1].data = children[-1].data[:-1] section.removeChild(title) section.removeChild(section.childNodes[0]) title.removeChild(children[0]) modinfo_pos = 0 else: ewrite("module name in title doesn't match" " <declaremodule/>; no <short-synopsis/>\n") else: ewrite("Unexpected condition: <section/> without <title/>\n") modinfo.appendChild(doc.createTextNode("\n ")) modinfo.appendChild(node) if title and not contents_match(title, node): # The short synopsis is actually different, # and needs to be stored: modinfo.appendChild(doc.createTextNode("\n ")) modinfo.appendChild(title) if modauthor: modinfo.appendChild(doc.createTextNode("\n ")) modinfo.appendChild(modauthor) if platform: modinfo.appendChild(doc.createTextNode("\n ")) modinfo.appendChild(platform) modinfo.appendChild(doc.createTextNode("\n ")) section.insertBefore(modinfo, section.childNodes[modinfo_pos]) section.insertBefore(doc.createTextNode("\n "), modinfo) # # The rest of this removes extra newlines from where we cut out # a lot of elements. A lot of code for minimal value, but keeps # keeps the generated *ML from being too funny looking. # section.normalize() children = section.childNodes for i in range(len(children)): node = children[i] if node.nodeName == "moduleinfo": nextnode = children[i+1] if nextnode.nodeType == TEXT: data = nextnode.data s = data.lstrip() if len(s) < (len(data) - 4): nextnode.data = "\n\n\n" + s
8,212
def fixup_table(doc, table): # create the table head thead = doc.createElement("thead") row = doc.createElement("row") move_elements_by_name(doc, table, row, "entry") thead.appendChild(doc.createTextNode("\n ")) thead.appendChild(row) thead.appendChild(doc.createTextNode("\n ")) # create the table body tbody = doc.createElement("tbody") prev_row = None last_was_hline = 0 children = table.childNodes for child in children: if child.nodeType == ELEMENT: tagName = child.tagName if tagName == "hline" and prev_row is not None: prev_row.setAttribute("rowsep", "1") elif tagName == "row": prev_row = child # save the rows: tbody.appendChild(doc.createTextNode("\n ")) move_elements_by_name(doc, table, tbody, "row", sep="\n ") # and toss the rest: while children: child = children[0] nodeType = child.nodeType if nodeType == TEXT: if string.strip(child.data): raise ConversionError("unexpected free data in <%s>: %r" % (table.tagName, child.data)) table.removeChild(child) continue if nodeType == ELEMENT: if child.tagName != "hline": raise ConversionError( "unexpected <%s> in table" % child.tagName) table.removeChild(child) continue raise ConversionError( "unexpected %s node in table" % child.__class__.__name__) # nothing left in the <table>; add the <thead> and <tbody> tgroup = doc.createElement("tgroup") tgroup.appendChild(doc.createTextNode("\n ")) tgroup.appendChild(thead) tgroup.appendChild(doc.createTextNode("\n ")) tgroup.appendChild(tbody) tgroup.appendChild(doc.createTextNode("\n ")) table.appendChild(tgroup) # now make the <entry>s look nice: for row in table.getElementsByTagName("row"): fixup_row(doc, row)
def fixup_table(doc, table): # create the table head thead = doc.createElement("thead") row = doc.createElement("row") move_elements_by_name(doc, table, row, "entry") thead.appendChild(doc.createTextNode("\n ")) thead.appendChild(row) thead.appendChild(doc.createTextNode("\n ")) # create the table body tbody = doc.createElement("tbody") prev_row = None last_was_hline = 0 children = table.childNodes for child in children: if child.nodeType == ELEMENT: tagName = child.tagName if tagName == "hline" and prev_row is not None: prev_row.setAttribute("rowsep", "1") elif tagName == "row": prev_row = child # save the rows: tbody.appendChild(doc.createTextNode("\n ")) move_elements_by_name(doc, table, tbody, "row", sep="\n ") # and toss the rest: while children: child = children[0] nodeType = child.nodeType if nodeType == TEXT: if child.data.strip(): raise ConversionError("unexpected free data in <%s>: %r" % (table.tagName, child.data)) table.removeChild(child) continue if nodeType == ELEMENT: if child.tagName != "hline": raise ConversionError( "unexpected <%s> in table" % child.tagName) table.removeChild(child) continue raise ConversionError( "unexpected %s node in table" % child.__class__.__name__) # nothing left in the <table>; add the <thead> and <tbody> tgroup = doc.createElement("tgroup") tgroup.appendChild(doc.createTextNode("\n ")) tgroup.appendChild(thead) tgroup.appendChild(doc.createTextNode("\n ")) tgroup.appendChild(tbody) tgroup.appendChild(doc.createTextNode("\n ")) table.appendChild(tgroup) # now make the <entry>s look nice: for row in table.getElementsByTagName("row"): fixup_row(doc, row)
8,213
def build_para(doc, parent, start, i): children = parent.childNodes after = start + 1 have_last = 0 BREAK_ELEMENTS = PARA_LEVEL_ELEMENTS + RECURSE_INTO_PARA_CONTAINERS # Collect all children until \n\n+ is found in a text node or a # member of BREAK_ELEMENTS is found. for j in range(start, i): after = j + 1 child = children[j] nodeType = child.nodeType if nodeType == ELEMENT: if child.tagName in BREAK_ELEMENTS: after = j break elif nodeType == TEXT: pos = string.find(child.data, "\n\n") if pos == 0: after = j break if pos >= 1: child.splitText(pos) break else: have_last = 1 if (start + 1) > after: raise ConversionError( "build_para() could not identify content to turn into a paragraph") if children[after - 1].nodeType == TEXT: # we may need to split off trailing white space: child = children[after - 1] data = child.data if string.rstrip(data) != data: have_last = 0 child.splitText(len(string.rstrip(data))) para = doc.createElement(PARA_ELEMENT) prev = None indexes = range(start, after) indexes.reverse() for j in indexes: node = parent.childNodes[j] parent.removeChild(node) para.insertBefore(node, prev) prev = node if have_last: parent.appendChild(para) parent.appendChild(doc.createTextNode("\n\n")) return len(parent.childNodes) else: nextnode = parent.childNodes[start] if nextnode.nodeType == TEXT: if nextnode.data and nextnode.data[0] != "\n": nextnode.data = "\n" + nextnode.data else: newnode = doc.createTextNode("\n") parent.insertBefore(newnode, nextnode) nextnode = newnode start = start + 1 parent.insertBefore(para, nextnode) return start + 1
def build_para(doc, parent, start, i): children = parent.childNodes after = start + 1 have_last = 0 BREAK_ELEMENTS = PARA_LEVEL_ELEMENTS + RECURSE_INTO_PARA_CONTAINERS # Collect all children until \n\n+ is found in a text node or a # member of BREAK_ELEMENTS is found. for j in range(start, i): after = j + 1 child = children[j] nodeType = child.nodeType if nodeType == ELEMENT: if child.tagName in BREAK_ELEMENTS: after = j break elif nodeType == TEXT: pos = child.data.find("\n\n") if pos == 0: after = j break if pos >= 1: child.splitText(pos) break else: have_last = 1 if (start + 1) > after: raise ConversionError( "build_para() could not identify content to turn into a paragraph") if children[after - 1].nodeType == TEXT: # we may need to split off trailing white space: child = children[after - 1] data = child.data if string.rstrip(data) != data: have_last = 0 child.splitText(len(string.rstrip(data))) para = doc.createElement(PARA_ELEMENT) prev = None indexes = range(start, after) indexes.reverse() for j in indexes: node = parent.childNodes[j] parent.removeChild(node) para.insertBefore(node, prev) prev = node if have_last: parent.appendChild(para) parent.appendChild(doc.createTextNode("\n\n")) return len(parent.childNodes) else: nextnode = parent.childNodes[start] if nextnode.nodeType == TEXT: if nextnode.data and nextnode.data[0] != "\n": nextnode.data = "\n" + nextnode.data else: newnode = doc.createTextNode("\n") parent.insertBefore(newnode, nextnode) nextnode = newnode start = start + 1 parent.insertBefore(para, nextnode) return start + 1
8,214
def build_para(doc, parent, start, i): children = parent.childNodes after = start + 1 have_last = 0 BREAK_ELEMENTS = PARA_LEVEL_ELEMENTS + RECURSE_INTO_PARA_CONTAINERS # Collect all children until \n\n+ is found in a text node or a # member of BREAK_ELEMENTS is found. for j in range(start, i): after = j + 1 child = children[j] nodeType = child.nodeType if nodeType == ELEMENT: if child.tagName in BREAK_ELEMENTS: after = j break elif nodeType == TEXT: pos = string.find(child.data, "\n\n") if pos == 0: after = j break if pos >= 1: child.splitText(pos) break else: have_last = 1 if (start + 1) > after: raise ConversionError( "build_para() could not identify content to turn into a paragraph") if children[after - 1].nodeType == TEXT: # we may need to split off trailing white space: child = children[after - 1] data = child.data if string.rstrip(data) != data: have_last = 0 child.splitText(len(string.rstrip(data))) para = doc.createElement(PARA_ELEMENT) prev = None indexes = range(start, after) indexes.reverse() for j in indexes: node = parent.childNodes[j] parent.removeChild(node) para.insertBefore(node, prev) prev = node if have_last: parent.appendChild(para) parent.appendChild(doc.createTextNode("\n\n")) return len(parent.childNodes) else: nextnode = parent.childNodes[start] if nextnode.nodeType == TEXT: if nextnode.data and nextnode.data[0] != "\n": nextnode.data = "\n" + nextnode.data else: newnode = doc.createTextNode("\n") parent.insertBefore(newnode, nextnode) nextnode = newnode start = start + 1 parent.insertBefore(para, nextnode) return start + 1
def build_para(doc, parent, start, i): children = parent.childNodes after = start + 1 have_last = 0 BREAK_ELEMENTS = PARA_LEVEL_ELEMENTS + RECURSE_INTO_PARA_CONTAINERS # Collect all children until \n\n+ is found in a text node or a # member of BREAK_ELEMENTS is found. for j in range(start, i): after = j + 1 child = children[j] nodeType = child.nodeType if nodeType == ELEMENT: if child.tagName in BREAK_ELEMENTS: after = j break elif nodeType == TEXT: pos = string.find(child.data, "\n\n") if pos == 0: after = j break if pos >= 1: child.splitText(pos) break else: have_last = 1 if (start + 1) > after: raise ConversionError( "build_para() could not identify content to turn into a paragraph") if children[after - 1].nodeType == TEXT: # we may need to split off trailing white space: child = children[after - 1] data = child.data if data.rstrip() != data: have_last = 0 child.splitText(len(string.rstrip(data))) para = doc.createElement(PARA_ELEMENT) prev = None indexes = range(start, after) indexes.reverse() for j in indexes: node = parent.childNodes[j] parent.removeChild(node) para.insertBefore(node, prev) prev = node if have_last: parent.appendChild(para) parent.appendChild(doc.createTextNode("\n\n")) return len(parent.childNodes) else: nextnode = parent.childNodes[start] if nextnode.nodeType == TEXT: if nextnode.data and nextnode.data[0] != "\n": nextnode.data = "\n" + nextnode.data else: newnode = doc.createTextNode("\n") parent.insertBefore(newnode, nextnode) nextnode = newnode start = start + 1 parent.insertBefore(para, nextnode) return start + 1
8,215
def build_para(doc, parent, start, i): children = parent.childNodes after = start + 1 have_last = 0 BREAK_ELEMENTS = PARA_LEVEL_ELEMENTS + RECURSE_INTO_PARA_CONTAINERS # Collect all children until \n\n+ is found in a text node or a # member of BREAK_ELEMENTS is found. for j in range(start, i): after = j + 1 child = children[j] nodeType = child.nodeType if nodeType == ELEMENT: if child.tagName in BREAK_ELEMENTS: after = j break elif nodeType == TEXT: pos = string.find(child.data, "\n\n") if pos == 0: after = j break if pos >= 1: child.splitText(pos) break else: have_last = 1 if (start + 1) > after: raise ConversionError( "build_para() could not identify content to turn into a paragraph") if children[after - 1].nodeType == TEXT: # we may need to split off trailing white space: child = children[after - 1] data = child.data if string.rstrip(data) != data: have_last = 0 child.splitText(len(string.rstrip(data))) para = doc.createElement(PARA_ELEMENT) prev = None indexes = range(start, after) indexes.reverse() for j in indexes: node = parent.childNodes[j] parent.removeChild(node) para.insertBefore(node, prev) prev = node if have_last: parent.appendChild(para) parent.appendChild(doc.createTextNode("\n\n")) return len(parent.childNodes) else: nextnode = parent.childNodes[start] if nextnode.nodeType == TEXT: if nextnode.data and nextnode.data[0] != "\n": nextnode.data = "\n" + nextnode.data else: newnode = doc.createTextNode("\n") parent.insertBefore(newnode, nextnode) nextnode = newnode start = start + 1 parent.insertBefore(para, nextnode) return start + 1
def build_para(doc, parent, start, i): children = parent.childNodes after = start + 1 have_last = 0 BREAK_ELEMENTS = PARA_LEVEL_ELEMENTS + RECURSE_INTO_PARA_CONTAINERS # Collect all children until \n\n+ is found in a text node or a # member of BREAK_ELEMENTS is found. for j in range(start, i): after = j + 1 child = children[j] nodeType = child.nodeType if nodeType == ELEMENT: if child.tagName in BREAK_ELEMENTS: after = j break elif nodeType == TEXT: pos = string.find(child.data, "\n\n") if pos == 0: after = j break if pos >= 1: child.splitText(pos) break else: have_last = 1 if (start + 1) > after: raise ConversionError( "build_para() could not identify content to turn into a paragraph") if children[after - 1].nodeType == TEXT: # we may need to split off trailing white space: child = children[after - 1] data = child.data if string.rstrip(data) != data: have_last = 0 child.splitText(len(data.rstrip())) para = doc.createElement(PARA_ELEMENT) prev = None indexes = range(start, after) indexes.reverse() for j in indexes: node = parent.childNodes[j] parent.removeChild(node) para.insertBefore(node, prev) prev = node if have_last: parent.appendChild(para) parent.appendChild(doc.createTextNode("\n\n")) return len(parent.childNodes) else: nextnode = parent.childNodes[start] if nextnode.nodeType == TEXT: if nextnode.data and nextnode.data[0] != "\n": nextnode.data = "\n" + nextnode.data else: newnode = doc.createTextNode("\n") parent.insertBefore(newnode, nextnode) nextnode = newnode start = start + 1 parent.insertBefore(para, nextnode) return start + 1
8,216
def skip_leading_nodes(children, start=0): """Return index into children of a node at which paragraph building should begin or a recursive call to fixup_paras_helper() should be made (for subsections, etc.). When the return value >= len(children), we've built all the paras we can from this list of children. """ i = len(children) while i > start: # skip over leading comments and whitespace: child = children[start] nodeType = child.nodeType if nodeType == TEXT: data = child.data shortened = string.lstrip(data) if shortened: if data != shortened: # break into two nodes: whitespace and non-whitespace child.splitText(len(data) - len(shortened)) return start + 1 return start # all whitespace, just skip elif nodeType == ELEMENT: tagName = child.tagName if tagName in RECURSE_INTO_PARA_CONTAINERS: return start if tagName not in PARA_LEVEL_ELEMENTS + PARA_LEVEL_PRECEEDERS: return start start = start + 1 return start
def skip_leading_nodes(children, start=0): """Return index into children of a node at which paragraph building should begin or a recursive call to fixup_paras_helper() should be made (for subsections, etc.). When the return value >= len(children), we've built all the paras we can from this list of children. """ i = len(children) while i > start: # skip over leading comments and whitespace: child = children[start] nodeType = child.nodeType if nodeType == TEXT: data = child.data shortened = data.lstrip() if shortened: if data != shortened: # break into two nodes: whitespace and non-whitespace child.splitText(len(data) - len(shortened)) return start + 1 return start # all whitespace, just skip elif nodeType == ELEMENT: tagName = child.tagName if tagName in RECURSE_INTO_PARA_CONTAINERS: return start if tagName not in PARA_LEVEL_ELEMENTS + PARA_LEVEL_PRECEEDERS: return start start = start + 1 return start
8,217
def fixup_verbatims(doc): for verbatim in find_all_elements(doc, "verbatim"): child = verbatim.childNodes[0] if child.nodeType == TEXT \ and string.lstrip(child.data)[:3] == ">>>": set_tagName(verbatim, "interactive-session")
def fixup_verbatims(doc): for verbatim in find_all_elements(doc, "verbatim"): child = verbatim.childNodes[0] if child.nodeType == TEXT \ and child.data.lstrip().startswith(">>>"): set_tagName(verbatim, "interactive-session")
8,218
def convert(ifp, ofp): events = esistools.parse(ifp) toktype, doc = events.getEvent() fragment = doc.createDocumentFragment() events.expandNode(fragment) normalize(fragment) simplify(doc, fragment) handle_labels(doc, fragment) handle_appendix(doc, fragment) fixup_trailing_whitespace(doc, { "abstract": "\n", "title": "", "chapter": "\n\n", "section": "\n\n", "subsection": "\n\n", "subsubsection": "\n\n", "paragraph": "\n\n", "subparagraph": "\n\n", }) cleanup_root_text(doc) cleanup_trailing_parens(fragment, ["function", "method", "cfunction"]) cleanup_synopses(doc, fragment) fixup_descriptors(doc, fragment) fixup_verbatims(fragment) normalize(fragment) fixup_paras(doc, fragment) fixup_sectionauthors(doc, fragment) fixup_table_structures(doc, fragment) fixup_rfc_references(doc, fragment) fixup_signatures(doc, fragment) fixup_ulink(doc, fragment) add_node_ids(fragment) fixup_refmodindexes(fragment) fixup_bifuncindexes(fragment) # Take care of ugly hacks in the LaTeX markup to avoid LaTeX and # LaTeX2HTML screwing with GNU-style long options (the '--' problem). join_adjacent_elements(fragment, "option") # d = {} for gi in events.parser.get_empties(): d[gi] = gi if d.has_key("author"): del d["author"] if d.has_key("rfc"): del d["rfc"] knownempty = d.has_key # try: write_esis(fragment, ofp, knownempty) except IOError, (err, msg): # Ignore EPIPE; it just means that whoever we're writing to stopped # reading. The rest of the output would be ignored. All other errors # should still be reported, if err != errno.EPIPE: raise
def convert(ifp, ofp): events = esistools.parse(ifp) toktype, doc = events.getEvent() fragment = doc.createDocumentFragment() events.expandNode(fragment) normalize(fragment) simplify(doc, fragment) handle_labels(doc, fragment) handle_appendix(doc, fragment) fixup_trailing_whitespace(doc, fragment, { "abstract": ("\n", "\n"), "title": ("", "\n"), "chapter": ("\n", "\n\n\n"), "section": ("\n", "\n\n\n"), "subsection": ("\n", "\n\n"), "subsubsection": ("\n", "\n\n"), "paragraph": ("\n", "\n\n"), "subparagraph": ("\n", "\n\n"), "enumeration": ("\n", "\n\n"), }) cleanup_root_text(doc) cleanup_trailing_parens(fragment, ["function", "method", "cfunction"]) cleanup_synopses(doc, fragment) fixup_descriptors(doc, fragment) fixup_verbatims(fragment) normalize(fragment) fixup_paras(doc, fragment) fixup_sectionauthors(doc, fragment) fixup_table_structures(doc, fragment) fixup_rfc_references(doc, fragment) fixup_signatures(doc, fragment) fixup_ulink(doc, fragment) add_node_ids(fragment) fixup_refmodindexes(fragment) fixup_bifuncindexes(fragment) # Take care of ugly hacks in the LaTeX markup to avoid LaTeX and # LaTeX2HTML screwing with GNU-style long options (the '--' problem). join_adjacent_elements(fragment, "option") # d = {} for gi in events.parser.get_empties(): d[gi] = gi if d.has_key("author"): del d["author"] if d.has_key("rfc"): del d["rfc"] knownempty = d.has_key # try: write_esis(fragment, ofp, knownempty) except IOError, (err, msg): # Ignore EPIPE; it just means that whoever we're writing to stopped # reading. The rest of the output would be ignored. All other errors # should still be reported, if err != errno.EPIPE: raise
8,219
def testHostnameRes(self): # Testing hostname resolution mechanisms hostname = socket.gethostname() try: ip = socket.gethostbyname(hostname) except socket.error: # Probably name lookup wasn't set up right; skip this test return self.assert_(ip.find('.') >= 0, "Error resolving host to ip.") try: hname, aliases, ipaddrs = socket.gethostbyaddr(ip) except socket.error: # Probably a similar problem as above; skip this test return all_host_names = [hostname, hname] + aliases fqhn = socket.getfqdn() if not fqhn in all_host_names: self.fail("Error testing host resolution mechanisms. (fqdn: %s, all: %s)" % (fqdn, repr(all_host_names)))
def testHostnameRes(self): # Testing hostname resolution mechanisms hostname = socket.gethostname() try: ip = socket.gethostbyname(hostname) except socket.error: # Probably name lookup wasn't set up right; skip this test return self.assert_(ip.find('.') >= 0, "Error resolving host to ip.") try: hname, aliases, ipaddrs = socket.gethostbyaddr(ip) except socket.error: # Probably a similar problem as above; skip this test return all_host_names = [hostname, hname] + aliases fqhn = socket.getfqdn() if not fqhn in all_host_names: self.fail("Error testing host resolution mechanisms. (fqdn: %s, all: %s)" % (fqdn, repr(all_host_names)))
8,220
def mkcorealias(src, altsrc): import string import macostools version = string.split(sys.version)[0] dst = getextensiondirfile(src+ ' ' + version) if not os.path.exists(os.path.join(sys.exec_prefix, src)): if not os.path.exists(os.path.join(sys.exec_prefix, altsrc)): if verbose: print '*', src, 'not found' return 0 src = altsrc try: os.unlink(dst) except os.error: pass macostools.mkalias(os.path.join(sys.exec_prefix, src), dst) if verbose: print ' ', dst, '->', src return 1
def mkcorealias(src, altsrc): import string import macostools version = string.split(sys.version)[0] dst = getextensiondirfile(src+ ' ' + version) if not os.path.exists(os.path.join(sys.exec_prefix, src)): if not os.path.exists(os.path.join(sys.exec_prefix, altsrc)): if verbose: print '*', src, 'not found' return 0 src = altsrc try: os.unlink(dst) except os.error: pass do_copy = 0 if macfs.FSSpec(sys.exec_prefix).as_tuple()[0] != -1: try: import Dlg rv = Dlg.CautionAlert(ALERT_NONBOOT, None) if rv == ALERT_NONBOOT_COPY: do_copy = 1 except ImportError: pass if do_copy: macostools.copy(os.path.join(sys.exec_prefix, src), dst) else: macostools.mkalias(os.path.join(sys.exec_prefix, src), dst) if verbose: print ' ', dst, '->', src return 1
8,221
def tightloop_example(): items = range(0, 3) try: i = 0 while 1: print items[i]; i+=1 except IndexError: pass
def tightloop_example(): items = range(0, 3) try: i = 0 while 1: b = items[i]; i+=1 except IndexError: pass
8,222
def check(self, result, expect): self.assertEquals(result, expect, 'Expected:\n%s\nbut got:\n%s' % ( self.show(result), self.show(expect)))
def check(self, result, expect): self.assertEquals(result, expect, 'Expected:\n%s\nbut got:\n%s' % ( self.show(result), self.show(expect)))
8,223
typedef struct
typedef struct
8,224
def expect(got_this, expect_this): if test_support.verbose: print '%r =?= %r ...' % (got_this, expect_this), if got_this != expect_this: if test_support.verbose: print 'no' raise test_support.TestFailed, 'got %r, but expected %r' %\ (got_this, expect_this) else: if test_support.verbose: print 'yes'
def expect(got_this, expect_this): if test_support.verbose: print '%r =?= %r ...' % (got_this, expect_this), if got_this != expect_this: if test_support.verbose: print 'no' raise test_support.TestFailed, 'got %r, but expected %r' %\ (got_this, expect_this) else: if test_support.verbose: print 'yes'
8,225
def expect(got_this, expect_this): if test_support.verbose: print '%r =?= %r ...' % (got_this, expect_this), if got_this != expect_this: if test_support.verbose: print 'no' raise test_support.TestFailed, 'got %r, but expected %r' %\ (got_this, expect_this) else: if test_support.verbose: print 'yes'
def expect(got_this, expect_this): if test_support.verbose: print '%r =?= %r ...' % (got_this, expect_this), if got_this != expect_this: if test_support.verbose: print 'no' raise test_support.TestFailed, 'got %r, but expected %r' %\ (got_this, expect_this) else: if test_support.verbose: print 'yes'
8,226
def expect(got_this, expect_this): if test_support.verbose: print '%r =?= %r ...' % (got_this, expect_this), if got_this != expect_this: if test_support.verbose: print 'no' raise test_support.TestFailed, 'got %r, but expected %r' %\ (got_this, expect_this) else: if test_support.verbose: print 'yes'
def expect(got_this, expect_this): if test_support.verbose: print '%r =?= %r ...' % (got_this, expect_this), if got_this != expect_this: if test_support.verbose: print 'no' raise test_support.TestFailed, 'got %r, but expected %r' %\ (got_this, expect_this) else: if test_support.verbose: print 'yes'
8,227
def expect(got_this, expect_this): if test_support.verbose: print '%r =?= %r ...' % (got_this, expect_this), if got_this != expect_this: if test_support.verbose: print 'no' raise test_support.TestFailed, 'got %r, but expected %r' %\ (got_this, expect_this) else: if test_support.verbose: print 'yes'
def expect(got_this, expect_this): if test_support.verbose: print '%r =?= %r ...' % (got_this, expect_this), if got_this != expect_this: if test_support.verbose: print 'no' raise test_support.TestFailed, 'got %r, but expected %r' %\ (got_this, expect_this) else: if test_support.verbose: print 'yes'
8,228
def expect(got_this, expect_this): if test_support.verbose: print '%r =?= %r ...' % (got_this, expect_this), if got_this != expect_this: if test_support.verbose: print 'no' raise test_support.TestFailed, 'got %r, but expected %r' %\ (got_this, expect_this) else: if test_support.verbose: print 'yes'
def expect(got_this, expect_this): if test_support.verbose: print '%r =?= %r ...' % (got_this, expect_this), if got_this != expect_this: if test_support.verbose: print 'no' raise test_support.TestFailed, 'got %r, but expected %r' %\ (got_this, expect_this) else: if test_support.verbose: print 'yes'
8,229
def expect(got_this, expect_this): if test_support.verbose: print '%r =?= %r ...' % (got_this, expect_this), if got_this != expect_this: if test_support.verbose: print 'no' raise test_support.TestFailed, 'got %r, but expected %r' %\ (got_this, expect_this) else: if test_support.verbose: print 'yes'
def expect(got_this, expect_this): if test_support.verbose: print '%r =?= %r ...' % (got_this, expect_this), if got_this != expect_this: if test_support.verbose: print 'no' raise test_support.TestFailed, 'got %r, but expected %r' %\ (got_this, expect_this) else: if test_support.verbose: print 'yes'
8,230
def expect(got_this, expect_this): if test_support.verbose: print '%r =?= %r ...' % (got_this, expect_this), if got_this != expect_this: if test_support.verbose: print 'no' raise test_support.TestFailed, 'got %r, but expected %r' %\ (got_this, expect_this) else: if test_support.verbose: print 'yes'
def expect(got_this, expect_this): if test_support.verbose: print '%r =?= %r ...' % (got_this, expect_this), if got_this != expect_this: if test_support.verbose: print 'no' raise test_support.TestFailed, 'got %r, but expected %r' %\ (got_this, expect_this) else: if test_support.verbose: print 'yes'
8,231
def test_qp(self): # A test for SF bug 534347 (segfaults without the proper fix) try: binascii.a2b_qp("", **{1:1}) except TypeError: pass else: self.fail("binascii.a2b_qp(**{1:1}) didn't raise TypeError") self.assertEqual(binascii.a2b_qp("= "), "") self.assertEqual(binascii.a2b_qp("=="), "=") self.assertEqual(binascii.a2b_qp("=AX"), "=AX") self.assertRaises(TypeError, binascii.b2a_qp, foo="bar") self.assertEqual(binascii.a2b_qp("=00\r\n=00"), "\x00\r\n\x00") self.assertEqual( binascii.b2a_qp("\xff\r\n\xff\n\xff"), "=FF\r\n=FF\r\n=FF" ) self.assertEqual( binascii.b2a_qp("0"*75+"\xff\r\n\xff\r\n\xff"), "0"*75+"=\r\n=FF\r\n=FF\r\n=FF" )
def test_qp(self): # A test for SF bug 534347 (segfaults without the proper fix) try: binascii.a2b_qp("", **{1:1}) except TypeError: pass else: self.fail("binascii.a2b_qp(**{1:1}) didn't raise TypeError") self.assertEqual(binascii.a2b_qp("= "), "= ") self.assertEqual(binascii.a2b_qp("=="), "=") self.assertEqual(binascii.a2b_qp("=AX"), "=AX") self.assertRaises(TypeError, binascii.b2a_qp, foo="bar") self.assertEqual(binascii.a2b_qp("=00\r\n=00"), "\x00\r\n\x00") self.assertEqual( binascii.b2a_qp("\xff\r\n\xff\n\xff"), "=FF\r\n=FF\r\n=FF" ) self.assertEqual( binascii.b2a_qp("0"*75+"\xff\r\n\xff\r\n\xff"), "0"*75+"=\r\n=FF\r\n=FF\r\n=FF" )
8,232
def make_entry(self, label, var): l = Label(self.top, text=label) l.grid(row=self.row, col=0, sticky="nw") e = Entry(self.top, textvariable=var, exportselection=0) e.grid(row=self.row, col=1, sticky="nwe") self.row = self.row + 1 return e
def make_entry(self, label, var): l = Label(self.top, text=label) l.grid(row=self.row, column=0, sticky="nw") e = Entry(self.top, textvariable=var, exportselection=0) e.grid(row=self.row, col=1, sticky="nwe") self.row = self.row + 1 return e
8,233
def make_entry(self, label, var): l = Label(self.top, text=label) l.grid(row=self.row, col=0, sticky="nw") e = Entry(self.top, textvariable=var, exportselection=0) e.grid(row=self.row, col=1, sticky="nwe") self.row = self.row + 1 return e
def make_entry(self, label, var): l = Label(self.top, text=label) l.grid(row=self.row, col=0, sticky="nw") e = Entry(self.top, textvariable=var, exportselection=0) e.grid(row=self.row, column=1, sticky="nwe") self.row = self.row + 1 return e
8,234
def make_frame(self,labeltext=None): if labeltext: l = Label(self.top, text=labeltext) l.grid(row=self.row, col=0, sticky="nw") f = Frame(self.top) f.grid(row=self.row, col=1, columnspan=1, sticky="nwe") self.row = self.row + 1 return f
def make_frame(self,labeltext=None): if labeltext: l = Label(self.top, text=labeltext) l.grid(row=self.row, column=0, sticky="nw") f = Frame(self.top) f.grid(row=self.row, col=1, columnspan=1, sticky="nwe") self.row = self.row + 1 return f
8,235
def make_frame(self,labeltext=None): if labeltext: l = Label(self.top, text=labeltext) l.grid(row=self.row, col=0, sticky="nw") f = Frame(self.top) f.grid(row=self.row, col=1, columnspan=1, sticky="nwe") self.row = self.row + 1 return f
def make_frame(self,labeltext=None): if labeltext: l = Label(self.top, text=labeltext) l.grid(row=self.row, col=0, sticky="nw") f = Frame(self.top) f.grid(row=self.row, column=1, columnspan=1, sticky="nwe") self.row = self.row + 1 return f
8,236
def create_command_buttons(self): # # place button frame on the right f = self.buttonframe = Frame(self.top) f.grid(row=0,col=2,padx=2,pady=2,ipadx=2,ipady=2)
def create_command_buttons(self): # # place button frame on the right f = self.buttonframe = Frame(self.top) f.grid(row=0,col=2,padx=2,pady=2,ipadx=2,ipady=2)
8,237
def login(self, user = '', passwd = '', acct = ''): '''Login, default anonymous.''' if not user: user = 'anonymous' if not passwd: passwd = '' if not acct: acct = '' if user == 'anonymous' and passwd in ('', '-'): # get fully qualified domain name of local host thishost = socket.getfqdn() try: if os.environ.has_key('LOGNAME'): realuser = os.environ['LOGNAME'] elif os.environ.has_key('USER'): realuser = os.environ['USER'] else: realuser = 'anonymous' except AttributeError: # Not all systems have os.environ.... realuser = 'anonymous' passwd = passwd + realuser + '@' + thishost resp = self.sendcmd('USER ' + user) if resp[0] == '3': resp = self.sendcmd('PASS ' + passwd) if resp[0] == '3': resp = self.sendcmd('ACCT ' + acct) if resp[0] != '2': raise error_reply, resp return resp
def login(self, user = '', passwd = '', acct = ''): '''Login, default anonymous.''' if not user: user = 'anonymous' if not passwd: passwd = '' if not acct: acct = '' if user == 'anonymous' and passwd in ('', '-'): # get fully qualified domain name of local host thishost = socket.getfqdn() try: if os.environ.has_key('LOGNAME'): realuser = os.environ['LOGNAME'] elif os.environ.has_key('USER'): realuser = os.environ['USER'] else: realuser = 'anonymous' except AttributeError: # Not all systems have os.environ.... realuser = 'anonymous' passwd = passwd + realuser + '@' + thishost resp = self.sendcmd('USER ' + user) if resp[0] == '3': resp = self.sendcmd('PASS ' + passwd) if resp[0] == '3': resp = self.sendcmd('ACCT ' + acct) if resp[0] != '2': raise error_reply, resp return resp
8,238
def run (self):
def run (self):
8,239
def run (self):
def run (self):
8,240
def run (self):
def run (self):
8,241
def run (self):
def run (self):
8,242
def run (self):
def run (self):
8,243
def run (self):
def run (self):
8,244
def _make_spec_file(self): """Generate the text of an RPM spec file and return it as a list of strings (one per line). """ # definitions and headers spec_file = [ '%define name ' + self.distribution.get_name(), '%define version ' + self.distribution.get_version(), '%define release ' + self.release, '', 'Summary: ' + self.distribution.get_description(), ]
def _make_spec_file(self): """Generate the text of an RPM spec file and return it as a list of strings (one per line). """ # definitions and headers spec_file = [ '%define name ' + self.distribution.get_name(), '%define version ' + self.distribution.get_version(), '%define release ' + self.release, '', 'Summary: ' + self.distribution.get_description(), ]
8,245
def _make_spec_file(self): """Generate the text of an RPM spec file and return it as a list of strings (one per line). """ # definitions and headers spec_file = [ '%define name ' + self.distribution.get_name(), '%define version ' + self.distribution.get_version(), '%define release ' + self.release, '', 'Summary: ' + self.distribution.get_description(), ]
def _make_spec_file(self): """Generate the text of an RPM spec file and return it as a list of strings (one per line). """ # definitions and headers spec_file = [ '%define name ' + self.distribution.get_name(), '%define version ' + self.distribution.get_version(), '%define release ' + self.release, '', 'Summary: ' + self.distribution.get_description(), ]
8,246
def detect_modules(self): # Ensure that /usr/local is always used if '/usr/local/lib' not in self.compiler.library_dirs: self.compiler.library_dirs.insert(0, '/usr/local/lib') if '/usr/local/include' not in self.compiler.include_dirs: self.compiler.include_dirs.insert(0, '/usr/local/include' )
def detect_modules(self): # Ensure that /usr/local is always used if '/usr/local/lib' not in self.compiler.library_dirs: self.compiler.library_dirs.insert(0, '/usr/local/lib') if '/usr/local/include' not in self.compiler.include_dirs: self.compiler.include_dirs.insert(0, '/usr/local/include' )
8,247
def spawnv(mode, file, args): """spawnv(mode, file, args) -> integer
def spawnv(mode, file, args): """spawnv(mode, file, args) -> integer
8,248
def test_title(self): self.checkmethod('title', u' hello ', u' Hello ') self.checkmethod('title', u'Hello ', u'Hello ') self.checkmethod('title', u'hello ', u'Hello ') self.checkmethod('title', u"fOrMaT thIs aS titLe String", u'Format This As Title String') self.checkmethod('title', u"fOrMaT,thIs-aS*titLe;String", u'Format,This-As*Title;String') self.checkmethod('title', u"getInt", u'Getint')
def test_title(self): self.checkmethod('title', u' hello ', u' Hello ') self.checkmethod('title', u'Hello ', u'Hello ') self.checkmethod('title', u'hello ', u'Hello ') self.checkmethod('title', u"fOrMaT thIs aS titLe String", u'Format This As Title String') self.checkmethod('title', u"fOrMaT,thIs-aS*titLe;String", u'Format,This-As*Title;String') self.checkmethod('title', u"getInt", u'Getint')
8,249
def writelines(self, list): self.write(''.join(list))
def writelines(self, list): self.write(''.join(list))
8,250
def set_reuse_addr(self): # try to re-use a server port if possible try: # Windows SO_REUSEADDR is very broken (from a unixy perspective) if sys.platform == 'win32': reuse_constant = socket.SO_EXCLUSIVEADDRUSE else: reuse_constant = socket.SO_REUSEADDR
def set_reuse_addr(self): # try to re-use a server port if possible try: # Windows SO_REUSEADDR is very broken (from a unixy perspective) if sys.platform == 'win32': reuse_constant = socket.SO_EXCLUSIVEADDRUSE else: reuse_constant = socket.SO_REUSEADDR
8,251
def set_reuse_addr(self): # try to re-use a server port if possible try: # Windows SO_REUSEADDR is very broken (from a unixy perspective) if sys.platform == 'win32': reuse_constant = socket.SO_EXCLUSIVEADDRUSE else: reuse_constant = socket.SO_REUSEADDR
def set_reuse_addr(self): # try to re-use a server port if possible try: # Windows SO_REUSEADDR is very broken (from a unixy perspective) if sys.platform == 'win32': reuse_constant = socket.SO_EXCLUSIVEADDRUSE else: reuse_constant = socket.SO_REUSEADDR
8,252
def set_reuse_addr(self): # try to re-use a server port if possible try: # Windows SO_REUSEADDR is very broken (from a unixy perspective) if sys.platform == 'win32': reuse_constant = socket.SO_EXCLUSIVEADDRUSE else: reuse_constant = socket.SO_REUSEADDR
def set_reuse_addr(self): # try to re-use a server port if possible try: # Windows SO_REUSEADDR is very broken (from a unixy perspective) if sys.platform == 'win32': reuse_constant = socket.SO_EXCLUSIVEADDRUSE else: reuse_constant = socket.SO_REUSEADDR
8,253
def poll (timeout=0.0, map=None): global DEBUG if map is None: map = socket_map if map: r = []; w = []; e = [] for fd, obj in map.items(): if obj.readable(): r.append (fd) if obj.writable(): w.append (fd) r,w,e = select.select (r,w,e, timeout) if DEBUG: print r,w,e for fd in r: try: obj = map[fd] except KeyError: continue try: obj.handle_read_event() except ExitNow: raise ExitNow except: obj.handle_error() for fd in w: try: obj = map[fd] except KeyError: continue try: obj.handle_write_event() except ExitNow: raise ExitNow except: obj.handle_error()
def poll (timeout=0.0, map=None): if map is None: map = socket_map if map: r = []; w = []; e = [] for fd, obj in map.items(): if obj.readable(): r.append (fd) if obj.writable(): w.append (fd) r,w,e = select.select (r,w,e, timeout) if DEBUG: print r,w,e for fd in r: try: obj = map[fd] except KeyError: continue try: obj.handle_read_event() except ExitNow: raise ExitNow except: obj.handle_error() for fd in w: try: obj = map[fd] except KeyError: continue try: obj.handle_write_event() except ExitNow: raise ExitNow except: obj.handle_error()
8,254
def poll (timeout=0.0, map=None): global DEBUG if map is None: map = socket_map if map: r = []; w = []; e = [] for fd, obj in map.items(): if obj.readable(): r.append (fd) if obj.writable(): w.append (fd) r,w,e = select.select (r,w,e, timeout) if DEBUG: print r,w,e for fd in r: try: obj = map[fd] except KeyError: continue try: obj.handle_read_event() except ExitNow: raise ExitNow except: obj.handle_error() for fd in w: try: obj = map[fd] except KeyError: continue try: obj.handle_write_event() except ExitNow: raise ExitNow except: obj.handle_error()
def poll (timeout=0.0, map=None): global DEBUG if map is None: map = socket_map if map: r = []; w = []; e = [] for fd, obj in map.items(): if obj.readable(): r.append (fd) if obj.writable(): w.append (fd) try: r,w,e = select.select (r,w,e, timeout) except select.error, err: if err[0] != EINTR: raise if DEBUG: print r,w,e for fd in r: try: obj = map[fd] except KeyError: continue try: obj.handle_read_event() except ExitNow: raise ExitNow except: obj.handle_error() for fd in w: try: obj = map[fd] except KeyError: continue try: obj.handle_write_event() except ExitNow: raise ExitNow except: obj.handle_error()
8,255
def poll3 (timeout=0.0, map=None): # Use the poll() support added to the select module in Python 2.0 if map is None: map=socket_map if timeout is not None: # timeout is in milliseconds timeout = int(timeout*1000) pollster = select.poll() if map: for fd, obj in map.items(): flags = 0 if obj.readable(): flags = select.POLLIN if obj.writable(): flags = flags | select.POLLOUT if flags: pollster.register(fd, flags) r = pollster.poll (timeout) for fd, flags in r: try: obj = map[fd] except KeyError: continue try: if (flags & select.POLLIN): obj.handle_read_event() if (flags & select.POLLOUT): obj.handle_write_event() except ExitNow: raise ExitNow except: obj.handle_error()
def poll3 (timeout=0.0, map=None): # Use the poll() support added to the select module in Python 2.0 if map is None: map=socket_map if timeout is not None: # timeout is in milliseconds timeout = int(timeout*1000) pollster = select.poll() if map: for fd, obj in map.items(): flags = 0 if obj.readable(): flags = select.POLLIN if obj.writable(): flags = flags | select.POLLOUT if flags: pollster.register(fd, flags) try: r = pollster.poll (timeout) except select.error, err: if err[0] != EINTR: raise r = [] for fd, flags in r: try: obj = map[fd] except KeyError: continue try: if (flags & select.POLLIN): obj.handle_read_event() if (flags & select.POLLOUT): obj.handle_write_event() except ExitNow: raise ExitNow except: obj.handle_error()
8,256
def set_socket (self, sock, map=None): self.__dict__['socket'] = sock self._fileno = sock.fileno() self.add_channel (map)
def set_socket (self, sock, map=None): self.socket = sock self._fileno = sock.fileno() self.add_channel (map)
8,257
for undef in ext.undef_macros: macros.append((undef,))
for undef in ext.undef_macros: macros.append((undef,))
8,258
for undef in ext.undef_macros: macros.append((undef,))
forundefinext.undef_macros:macros.append((undef,))
8,259
def path(path): return test_support.findfile(path)
def path(path): return test_support.findfile(path)
8,260
def activate(self, onoff): self._activated = onoff if self._visible: self._list.LActivate(onoff) state = [kThemeStateActive, kThemeStateInactive][not onoff] App.DrawThemeListBoxFrame(Qd.InsetRect(self._bounds, 1, 1), state) if self._selected: self.drawselframe(onoff)
def activate(self, onoff): self._activated = onoff if self._visible: self._list.LActivate(onoff) if self._selected: self.drawselframe(onoff)
8,261
def __init__(self, master, name, destroy_physically=1, check_intermediate=1): if check_intermediate: path = master._subwidget_name(name) try: path = path[len(master._w)+1:] plist = path.split('.') except: plist = []
def __init__(self, master, name, destroy_physically=1, check_intermediate=1): if check_intermediate: path = master._subwidget_name(name) try: path = path[len(master._w)+1:] plist = path.split('.') except: plist = []
8,262
def read_lines(self): """Internal: read lines until EOF or outerboundary.""" self.file = self.make_file('') if self.outerboundary: self.read_lines_to_outerboundary() else: self.read_lines_to_eof()
def read_lines(self): """Internal: read lines until EOF or outerboundary.""" self.file = self.__file = StringIO() if self.outerboundary: self.read_lines_to_outerboundary() else: self.read_lines_to_eof()
8,263
def read_lines_to_eof(self): """Internal: read lines until EOF.""" while 1: line = self.fp.readline() if not line: self.done = -1 break self.file.write(line)
def read_lines_to_eof(self): """Internal: read lines until EOF.""" while 1: line = self.fp.readline() if not line: self.done = -1 break self.file.write(line)
8,264
def read_lines_to_outerboundary(self): """Internal: read lines until outerboundary.""" next = "--" + self.outerboundary last = next + "--" delim = "" while 1: line = self.fp.readline() if not line: self.done = -1 break if line[:2] == "--": strippedline = line.strip() if strippedline == next: break if strippedline == last: self.done = 1 break odelim = delim if line[-2:] == "\r\n": delim = "\r\n" line = line[:-2] elif line[-1] == "\n": delim = "\n" line = line[:-1] else: delim = "" self.file.write(odelim + line)
def read_lines_to_outerboundary(self): """Internal: read lines until outerboundary.""" next = "--" + self.outerboundary last = next + "--" delim = "" while 1: line = self.fp.readline() if not line: self.done = -1 break if line[:2] == "--": strippedline = line.strip() if strippedline == next: break if strippedline == last: self.done = 1 break odelim = delim if line[-2:] == "\r\n": delim = "\r\n" line = line[:-2] elif line[-1] == "\n": delim = "\n" line = line[:-1] else: delim = "" self.file.write(odelim + line)
8,265
def copy(self): """Return a shallow copy of a set.""" result = self.__class__([]) result._data.update(self._data) return result
def copy(self): """Return a shallow copy of a set.""" result = self.__class__() result._data.update(self._data) return result
8,266
def __deepcopy__(self, memo): """Return a deep copy of a set; used by copy module.""" # This pre-creates the result and inserts it in the memo # early, in case the deep copy recurses into another reference # to this same set. A set can't be an element of itself, but # it can certainly contain an object that has a reference to # itself. from copy import deepcopy result = self.__class__([]) memo[id(self)] = result data = result._data value = True for elt in self: data[deepcopy(elt, memo)] = value return result
def __deepcopy__(self, memo): """Return a deep copy of a set; used by copy module.""" # This pre-creates the result and inserts it in the memo # early, in case the deep copy recurses into another reference # to this same set. A set can't be an element of itself, but # it can certainly contain an object that has a reference to # itself. from copy import deepcopy result = self.__class__() memo[id(self)] = result data = result._data value = True for elt in self: data[deepcopy(elt, memo)] = value return result
8,267
def __and__(self, other): """Return the intersection of two sets as a new set.
def __and__(self, other): """Return the intersection of two sets as a new set.
8,268
def __xor__(self, other): """Return the symmetric difference of two sets as a new set.
def __xor__(self, other): """Return the symmetric difference of two sets as a new set.
8,269
def __sub__(self, other): """Return the difference of two sets as a new Set.
def __sub__(self, other): """Return the difference of two sets as a new Set.
8,270
def _as_temporarily_immutable(self): # Return self wrapped in a temporarily immutable set return _TemporarilyImmutableSet(self)
def _as_temporarily_immutable(self): # Return self wrapped in a temporarily immutable set return _TemporarilyImmutableSet(self)
8,271
def __hash__(self): if self._hashcode is None: self._hashcode = self._set._compute_hash() return self._hashcode
def __hash__(self): if self._hashcode is None: self._hashcode = self._set._compute_hash() return self._hashcode
8,272
def repr_dictionary(self, x, level): n = len(x) if n == 0: return '{}' if level <= 0: return '{...}' s = '' keys = x.keys() keys.sort() for i in range(min(n, self.maxdict)): if s: s = s + ', ' key = keys[i] s = s + self.repr1(key, level-1) s = s + ': ' + self.repr1(x[key], level-1) if n > self.maxlist: s = s + ', ...' return '{' + s + '}'
def repr_dictionary(self, x, level): n = len(x) if n == 0: return '{}' if level <= 0: return '{...}' s = '' keys = x.keys() keys.sort() for i in range(min(n, self.maxdict)): if s: s = s + ', ' key = keys[i] s = s + self.repr1(key, level-1) s = s + ': ' + self.repr1(x[key], level-1) if n > self.maxdict: s = s + ', ...' return '{' + s + '}'
8,273
def items(self, section, raw=False, vars=None): """Return a list of tuples with (name, value) for each option in the section.
def items(self, section, raw=False, vars=None): """Return a list of tuples with (name, value) for each option in the section.
8,274
def items(self, section, raw=False, vars=None): """Return a list of tuples with (name, value) for each option in the section.
def items(self, section, raw=False, vars=None): """Return a list of tuples with (name, value) for each option in the section.
8,275
def main(): testtype('c', 'c') for type in (['b', 'h', 'i', 'l', 'f', 'd']): testtype(type, 1) unlink(TESTFN)
defmain():testtype('c','c')fortypein(['b','h','i','l','f','d']):testtype(type,1)unlink(TESTFN)
8,276
def main(): testtype('c', 'c') for type in (['b', 'h', 'i', 'l', 'f', 'd']): testtype(type, 1) unlink(TESTFN)
deftesttype('u', u'\u263a') main():testtype('u', u'\u263a') testtype('u', u'\u263a') testtype('c',testtype('u', u'\u263a') 'c')testtype('u', u'\u263a') testtype('u', u'\u263a') fortesttype('u', u'\u263a') typetesttype('u', u'\u263a') intesttype('u', u'\u263a') (['b',testtype('u', u'\u263a') 'h',testtype('u', u'\u263a') 'i',testtype('u', u'\u263a') 'l',testtype('u', u'\u263a') 'f',testtype('u', u'\u263a') 'd']):testtype('u', u'\u263a') testtype(type,testtype('u', u'\u263a') 1)testtype('u', u'\u263a') testtype('u', u'\u263a') unlink(TESTFN)testtype('u', u'\u263a') testtype('u', u'\u263a')
8,277
def main(): testtype('c', 'c') for type in (['b', 'h', 'i', 'l', 'f', 'd']): testtype(type, 1) unlink(TESTFN)
deftestunicode() testsubclassing() main():testunicode() testsubclassing() testunicode() testsubclassing() testtype('c',testunicode() testsubclassing() 'c')testunicode() testsubclassing() testunicode() testsubclassing() fortestunicode() testsubclassing() typetestunicode() testsubclassing() intestunicode() testsubclassing() (['b',testunicode() testsubclassing() 'h',testunicode() testsubclassing() 'i',testunicode() testsubclassing() 'l',testunicode() testsubclassing() 'f',testunicode() testsubclassing() 'd']):testunicode() testsubclassing() testtype(type,testunicode() testsubclassing() 1)testunicode() testsubclassing() testunicode() testsubclassing() unlink(TESTFN)testunicode() testsubclassing() testunicode() testsubclassing()
8,278
def flush(self): self.fileobj.flush()
def flush(self): self.fileobj.flush()
8,279
def _execvpe(file, args, env=None): if env is not None: func = execve argrest = (args, env) else: func = execv argrest = (args,) env = environ global _notfound head, tail = path.split(file) if head: apply(func, (file,) + argrest) return if env.has_key('PATH'): envpath = env['PATH'] else: envpath = defpath import string PATH = string.splitfields(envpath, pathsep) if not _notfound: import tempfile # Exec a file that is guaranteed not to exist try: execv(tempfile.mktemp(), ()) except error, _notfound: pass exc, arg = error, _notfound for dir in PATH: fullname = path.join(dir, file) try: apply(func, (fullname,) + argrest) except error, (errno, msg): if errno != arg[0]: exc, arg = error, (errno, msg) raise exc, arg
def _execvpe(file, args, env=None): if env is not None: func = execve argrest = (args, env) else: func = execv argrest = (args,) env = environ global _notfound head, tail = path.split(file) if head: apply(func, (file,) + argrest) return if env.has_key('PATH'): envpath = env['PATH'] else: envpath = defpath PATH = envpath.split(pathsep) if not _notfound: import tempfile # Exec a file that is guaranteed not to exist try: execv(tempfile.mktemp(), ()) except error, _notfound: pass exc, arg = error, _notfound for dir in PATH: fullname = path.join(dir, file) try: apply(func, (fullname,) + argrest) except error, (errno, msg): if errno != arg[0]: exc, arg = error, (errno, msg) raise exc, arg
8,280
def _execvpe(file, args, env=None): if env is not None: func = execve argrest = (args, env) else: func = execv argrest = (args,) env = environ global _notfound head, tail = path.split(file) if head: apply(func, (file,) + argrest) return if env.has_key('PATH'): envpath = env['PATH'] else: envpath = defpath import string PATH = string.splitfields(envpath, pathsep) if not _notfound: import tempfile # Exec a file that is guaranteed not to exist try: execv(tempfile.mktemp(), ()) except error, _notfound: pass exc, arg = error, _notfound for dir in PATH: fullname = path.join(dir, file) try: apply(func, (fullname,) + argrest) except error, (errno, msg): if errno != arg[0]: exc, arg = error, (errno, msg) raise exc, arg
def _execvpe(file, args, env=None): if env is not None: func = execve argrest = (args, env) else: func = execv argrest = (args,) env = environ global _notfound head, tail = path.split(file) if head: apply(func, (file,) + argrest) return if env.has_key('PATH'): envpath = env['PATH'] else: envpath = defpath PATH = string.splitfields(envpath, pathsep) if not _notfound: import tempfile # Exec a file that is guaranteed not to exist try: execv(tempfile.mktemp(), ()) except error, _notfound: pass exc, arg = error, _notfound for dir in PATH: fullname = path.join(dir, file) try: apply(func, (fullname,) + argrest) except error, (errno, msg): if errno != arg[0]: exc, arg = error, (errno, msg) raise exc, arg
8,281
def __init__(self, environ): UserDict.UserDict.__init__(self) data = self.data upper = string.upper for k, v in environ.items(): data[upper(k)] = v
def __init__(self, environ): UserDict.UserDict.__init__(self) data = self.data for k, v in environ.items(): data[upper(k)] = v
8,282
def __init__(self, environ): UserDict.UserDict.__init__(self) data = self.data upper = string.upper for k, v in environ.items(): data[upper(k)] = v
def __init__(self, environ): UserDict.UserDict.__init__(self) data = self.data upper = string.upper for k, v in environ.items(): data[upper(k)] = v
8,283
def __setitem__(self, key, item): putenv(key, item) key = string.upper(key) self.data[key] = item
def __setitem__(self, key, item): putenv(key, item) key = string.upper(key) self.data[key] = item
8,284
def __getitem__(self, key): return self.data[string.upper(key)]
def __getitem__(self, key): return self.data[string.upper(key)]
8,285
def has_key(self, key): return self.data.has_key(string.upper(key))
def has_key(self, key): return self.data.has_key(string.upper(key))
8,286
def select_item(self): """Return the item which has the selection.""" self.tk.call(self._w, 'select', 'item')
def select_item(self): """Return the item which has the selection.""" self.tk.call(self._w, 'select', 'item')
8,287
def wm_state(self): """Return the state of this widget as one of normal, icon, iconic (see wm_iconwindow) and withdrawn.""" return self.tk.call('wm', 'state', self._w)
def wm_state(self): """Return the state of this widget as one of normal, icon, iconic (see wm_iconwindow) and withdrawn.""" return self.tk.call('wm', 'state', self._w)
8,288
def test_basic(self): f = StringIO.StringIO('\xed\x95\x9c\n\xea\xb8\x80') ef = codecs.EncodedFile(f, 'utf-16-le', 'utf-8') self.assertEquals(ef.read(), '\xff\xfe\\\xd5\n\x00\x00\xae')
def test_basic(self): f = StringIO.StringIO('\xed\x95\x9c\n\xea\xb8\x80') ef = codecs.EncodedFile(f, 'utf-16-le', 'utf-8') self.assertEquals(ef.read(), '\xff\xfe\\\xd5\n\x00\x00\xae')
8,289
def main(): bad = 0 if not sys.argv[1:]: # No arguments err('usage: classfix file-or-directory ...\n') sys.exit(2) for arg in sys.argv[1:]: if path.isdir(arg): if recursedown(arg): bad = 1 elif path.islink(arg): err(arg + ': will not process symbolic links\n') bad = 1 else: if fix(arg): bad = 1 sys.exit(bad)
def main(): bad = 0 if not sys.argv[1:]: # No arguments err('usage: ' + argv[0] + ' file-or-directory ...\n') sys.exit(2) for arg in sys.argv[1:]: if path.isdir(arg): if recursedown(arg): bad = 1 elif path.islink(arg): err(arg + ': will not process symbolic links\n') bad = 1 else: if fix(arg): bad = 1 sys.exit(bad)
8,290
def main(): bad = 0 if not sys.argv[1:]: # No arguments err('usage: classfix file-or-directory ...\n') sys.exit(2) for arg in sys.argv[1:]: if path.isdir(arg): if recursedown(arg): bad = 1 elif path.islink(arg): err(arg + ': will not process symbolic links\n') bad = 1 else: if fix(arg): bad = 1 sys.exit(bad)
def main(): bad = 0 if not sys.argv[1:]: # No arguments err('usage: classfix file-or-directory ...\n') sys.exit(2) for arg in sys.argv[1:]: if path.isdir(arg): if recursedown(arg): bad = 1 elif path.islink(arg): err(arg + ': will not process symbolic links\n') bad = 1 else: if fix(arg): bad = 1 sys.exit(bad)
8,291
def recursedown(dirname): dbg('recursedown(' + `dirname` + ')\n') bad = 0 try: names = posix.listdir(dirname) except posix.error, msg: err(dirname + ': cannot list directory: ' + `msg` + '\n') return 1 for name in names: if name in ('.', '..'): continue fullname = path.join(dirname, name) if path.islink(fullname): pass elif path.isdir(fullname): if recursedown(fullname): bad = 1 elif ispython(name): if fix(fullname): bad = 1 return bad
def recursedown(dirname): dbg('recursedown(' + `dirname` + ')\n') bad = 0 try: names = posix.listdir(dirname) except posix.error, msg: err(dirname + ': cannot list directory: ' + `msg` + '\n') return 1 for name in names: if name in ('.', '..'): continue fullname = path.join(dirname, name) if path.islink(fullname): pass elif path.isdir(fullname): subdirs.append(fullname) elif ispython(name): if fix(fullname): bad = 1 return bad
8,292
def recursedown(dirname): dbg('recursedown(' + `dirname` + ')\n') bad = 0 try: names = posix.listdir(dirname) except posix.error, msg: err(dirname + ': cannot list directory: ' + `msg` + '\n') return 1 for name in names: if name in ('.', '..'): continue fullname = path.join(dirname, name) if path.islink(fullname): pass elif path.isdir(fullname): if recursedown(fullname): bad = 1 elif ispython(name): if fix(fullname): bad = 1 return bad
def recursedown(dirname): dbg('recursedown(' + `dirname` + ')\n') bad = 0 try: names = posix.listdir(dirname) except posix.error, msg: err(dirname + ': cannot list directory: ' + `msg` + '\n') return 1 for name in names: if name in ('.', '..'): continue fullname = path.join(dirname, name) if path.islink(fullname): pass elif path.isdir(fullname): if recursedown(fullname): bad = 1 elif ispython(name): if fix(fullname): bad = 1 return bad
8,293
def fix(filename):
defdbg('fix(' + `filename` + ')\n') fix(filename):
8,294
def fix(filename):
def fix(filename):
8,295
def fix(filename):
def fix(filename):
8,296
def fix(filename):
def fix(filename):
8,297
def detect_modules(self): # Ensure that /usr/local is always used add_dir_to_list(self.compiler.library_dirs, '/usr/local/lib') add_dir_to_list(self.compiler.include_dirs, '/usr/local/include')
def detect_modules(self): # Ensure that /usr/local is always used add_dir_to_list(self.compiler.library_dirs, '/usr/local/lib') add_dir_to_list(self.compiler.include_dirs, '/usr/local/include')
8,298
def detect_modules(self): # Ensure that /usr/local is always used add_dir_to_list(self.compiler.library_dirs, '/usr/local/lib') add_dir_to_list(self.compiler.include_dirs, '/usr/local/include')
def detect_modules(self): # Ensure that /usr/local is always used add_dir_to_list(self.compiler.library_dirs, '/usr/local/lib') add_dir_to_list(self.compiler.include_dirs, '/usr/local/include')
8,299