mirror of
				https://github.com/python/cpython.git
				synced 2025-11-04 03:44:55 +00:00 
			
		
		
		
	- replaced a couple of asserts with proper exceptions
- use isinstance instead of flaky file-detection code
This commit is contained in:
		
							parent
							
								
									21d896cfa1
								
							
						
					
					
						commit
						94af32e244
					
				
					 1 changed files with 5 additions and 4 deletions
				
			
		| 
						 | 
					@ -142,7 +142,7 @@ class PlistWriter(DumbXMLWriter):
 | 
				
			||||||
        elif isinstance(value, (tuple, list)):
 | 
					        elif isinstance(value, (tuple, list)):
 | 
				
			||||||
            self.writeArray(value)
 | 
					            self.writeArray(value)
 | 
				
			||||||
        else:
 | 
					        else:
 | 
				
			||||||
            assert 0, "unsuported type: %s" % type(value)
 | 
					            raise TypeError("unsuported type: %s" % type(value))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def writeData(self, data):
 | 
					    def writeData(self, data):
 | 
				
			||||||
        self.beginElement("data")
 | 
					        self.beginElement("data")
 | 
				
			||||||
| 
						 | 
					@ -156,7 +156,8 @@ class PlistWriter(DumbXMLWriter):
 | 
				
			||||||
        items = d.items()
 | 
					        items = d.items()
 | 
				
			||||||
        items.sort()
 | 
					        items.sort()
 | 
				
			||||||
        for key, value in items:
 | 
					        for key, value in items:
 | 
				
			||||||
            assert isinstance(key, (str, unicode)), "keys must be strings"
 | 
					            if not isinstance(key, (str, unicode)):
 | 
				
			||||||
 | 
					                raise TypeError("keys must be strings")
 | 
				
			||||||
            self.simpleElement("key", key)
 | 
					            self.simpleElement("key", key)
 | 
				
			||||||
            self.writeValue(value)
 | 
					            self.writeValue(value)
 | 
				
			||||||
        self.endElement("dict")
 | 
					        self.endElement("dict")
 | 
				
			||||||
| 
						 | 
					@ -204,7 +205,7 @@ class Plist(Dict):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def fromFile(cls, pathOrFile):
 | 
					    def fromFile(cls, pathOrFile):
 | 
				
			||||||
        didOpen = 0
 | 
					        didOpen = 0
 | 
				
			||||||
        if not hasattr(pathOrFile, "write"):
 | 
					        if isinstance(pathOrFile, (str, unicode)):
 | 
				
			||||||
            pathOrFile = open(pathOrFile)
 | 
					            pathOrFile = open(pathOrFile)
 | 
				
			||||||
            didOpen = 1
 | 
					            didOpen = 1
 | 
				
			||||||
        p = PlistParser()
 | 
					        p = PlistParser()
 | 
				
			||||||
| 
						 | 
					@ -215,7 +216,7 @@ class Plist(Dict):
 | 
				
			||||||
    fromFile = classmethod(fromFile)
 | 
					    fromFile = classmethod(fromFile)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def write(self, pathOrFile):
 | 
					    def write(self, pathOrFile):
 | 
				
			||||||
        if not hasattr(pathOrFile, "write"):
 | 
					        if isinstance(pathOrFile, (str, unicode)):
 | 
				
			||||||
            pathOrFile = open(pathOrFile, "w")
 | 
					            pathOrFile = open(pathOrFile, "w")
 | 
				
			||||||
            didOpen = 1
 | 
					            didOpen = 1
 | 
				
			||||||
        else:
 | 
					        else:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue