def validateStream(aFile, firstOccurrenceOnly=0, contentType=None, base=""): loggedEvents = [] if contentType: (mediaType, charset) = mediaTypes.checkValid(contentType, loggedEvents) else: (mediaType, charset) = (None, None) rawdata = aFile.read(MAXDATALENGTH) if aFile.read(1): raise ValidationFailure( logging.ValidatorLimit( {'limit': 'feed length > ' + str(MAXDATALENGTH) + ' bytes'})) encoding, rawdata = xmlEncoding.decode(mediaType, charset, rawdata, loggedEvents, fallback='utf-8') validator = _validate(rawdata, firstOccurrenceOnly, loggedEvents, base, encoding, mediaType=mediaType) if mediaType and validator.feedType: mediaTypes.checkAgainstFeedType(mediaType, validator.feedType, validator.loggedEvents) return { "feedType": validator.feedType, "loggedEvents": validator.loggedEvents }
def validateStream(aFile, firstOccurrenceOnly=0, contentType=None, base=""): loggedEvents = [] if contentType: (mediaType, charset) = mediaTypes.checkValid(contentType, loggedEvents) else: (mediaType, charset) = (None, None) rawdata = aFile.read(MAXDATALENGTH) if aFile.read(1): raise ValidationFailure(logging.ValidatorLimit({'limit': 'feed length > ' + str(MAXDATALENGTH) + ' bytes'})) encoding, rawdata = xmlEncoding.decode(mediaType, charset, rawdata, loggedEvents, fallback='utf-8') validator = _validate(rawdata, firstOccurrenceOnly, loggedEvents, base, encoding) if mediaType and validator.feedType: mediaTypes.checkAgainstFeedType(mediaType, validator.feedType, validator.loggedEvents) return {"feedType":validator.feedType, "loggedEvents":validator.loggedEvents}
import zlib try: rawdata = zlib.decompress(rawdata, -zlib.MAX_WBITS) except: import sys exctype, value = sys.exc_info()[:2] event=logging.IOError({"message": 'Server response declares Content-Encoding: deflate', "exception":value}) raise ValidationFailure(event) mediaType = None charset = None # Is the Content-Type correct? contentType = usock.headers.get('content-type', None) if contentType: (mediaType, charset) = mediaTypes.checkValid(contentType, loggedEvents) # Check for malformed HTTP headers for (h, v) in usock.headers.items(): if (h.find(' ') >= 0): loggedEvents.append(HttpProtocolError({'header': h})) selfURIs = [request.get_full_url()] baseURI = usock.geturl() if not baseURI in selfURIs: selfURIs.append(baseURI) # Get baseURI from content-location and/or redirect information if usock.headers.get('content-location', None): from urlparse import urljoin baseURI=urljoin(baseURI,usock.headers.get('content-location', "")) elif usock.headers.get('location', None):