Ejemplo n.º 1
0
	def read(self):
		"""Read Presentation API resource."""
		data = self.data
		if type(data) in [dict, OrderedDict]:
			js = data
		else:
			try:
				js = json.loads(data)
			except:
				# could be badly encoded utf-8 with BOM
				data = data.decode('utf-8')
				if data[0] == u'\ufeff':
					data = data[1:].strip()
				try:
					js = json.loads(data)
				except:
					raise SerializationError("Data is not valid JSON", data)				

		# Try to see if we're valid JSON-LD before further testing

		version = self.getVersion(js)
		factory = self.buildFactory(version)
		self.factory = factory
		top = self.readObject(js)
		if jsonld:
			try:
				jsonld.expand(js)
			except Exception, e:
				raise
				raise SerializationError("Data is not valid JSON-LD: %r" % e, data)
Ejemplo n.º 2
0
	def read(self):
		"""Read Presentation API resource."""
		data = self.data
		if type(data) in [dict, OrderedDict]:
			js = data
		else:
			try:
				js = json.loads(data)
			except:
				# could be badly encoded utf-8 with BOM
				try:
					data = data.decode('utf-8')
				except:
					#Py3 does not have decode on str which is unicode already
					pass	
				if data[0] == u'\ufeff':
					data = data[1:].strip()
				try:
					js = json.loads(data)
				except:
					raise SerializationError("Data is not valid JSON", data)				

		# Try to see if we're valid JSON-LD before further testing

		version = self.getVersion(js)
		factory = self.buildFactory(version)
		self.factory = factory
		top = self.readObject(js)
		if jsonld:
			try:
				jsonld.expand(js)
			except Exception as e:
				raise
				raise SerializationError("Data is not valid JSON-LD: %r" % e, data)
		return top
Ejemplo n.º 3
0
	def set_hw_from_iiif(self):
		"""Set height and width from IIIF Image Information."""
		if not self._identifier:
			raise ConfigurationError("Image is not configured with IIIF support")

		requrl = self._factory.image_base + self._identifier + '/info.json';
		try:
			fh = urllib.urlopen(requrl)
			data = fh.read()
			fh.close()
		except:
			raise ConfigurationError("Could not get IIIF Info from %s" % requrl)

		try:
			js = json.loads(data)
			self.height = int(js['height'])
			self.width = int(js['width'])
		except:
			raise ConfigurationError("Response from IIIF server did not have mandatory height/width")
Ejemplo n.º 4
0
    def set_hw_from_iiif(self):
        """Set height and width from IIIF Image Information."""
        if not self._identifier:
            raise ConfigurationError(
                "Image is not configured with IIIF support")

        requrl = self._factory.image_base + self._identifier + '/info.json'
        try:
            fh = urllib.urlopen(requrl)
            data = fh.read()
            fh.close()
        except:
            raise ConfigurationError("Could not get IIIF Info from %s" %
                                     requrl)

        try:
            js = json.loads(data)
            self.height = int(js['height'])
            self.width = int(js['width'])
        except:
            raise ConfigurationError(
                "Response from IIIF server did not have mandatory height/width"
            )
Ejemplo n.º 5
0
	def set_hw_from_iiif(self):
		"""Set height and width from IIIF Image Information."""
		if not self._identifier:
			raise ConfigurationError("Image is not configured with IIIF support")

		requrl = self._factory.default_base_image_uri + "/" + self._identifier + '/info.json';
		try:
			if self._factory.image_auth_token:
				req = urllib2.Request(requrl, headers={'Authorization': self._factory.image_auth_token})
			else:
				req = urllib2.Request(requrl)
			fh = urllib2.urlopen(req)
			data = fh.read()
			fh.close()
		except:
			raise ConfigurationError("Could not get IIIF Info from %s" % requrl)

		try:
			js = json.loads(data)
			self.height = int(js['height'])
			self.width = int(js['width'])
		except:
			print data
			raise ConfigurationError("Response from IIIF server did not have mandatory height/width")