def make_complete_url(environ, localUri=None): """URL reconstruction according to PEP 333. @see https://www.python.org/dev/peps/pep-3333/#url-reconstruction """ url = environ["wsgi.url_scheme"] + "://" if environ.get("HTTP_HOST"): url += environ["HTTP_HOST"] else: url += environ["SERVER_NAME"] if environ["wsgi.url_scheme"] == "https": if environ["SERVER_PORT"] != "443": url += ":" + environ["SERVER_PORT"] else: if environ["SERVER_PORT"] != "80": url += ":" + environ["SERVER_PORT"] url += compat.quote(environ.get("SCRIPT_NAME", "")) if localUri is None: url += compat.quote(environ.get("PATH_INFO", "")) if environ.get("QUERY_STRING"): url += "?" + environ["QUERY_STRING"] else: url += localUri # TODO: quote? return url
def write_property( self, norm_url, name, property_value, dry_run=False, environ=None ): assert norm_url and norm_url.startswith("/") assert name assert property_value is not None assert name not in HIDDEN_KEYS, "MongoDB key is protected: '%s'" % name _logger.debug( "write_property(%s, %s, dry_run=%s):\n\t%s" % (norm_url, name, dry_run, property_value) ) if dry_run: return # TODO: can we check anything here? doc = self.collection.find_one({"_url": norm_url}) if not doc: doc = {"_url": norm_url, "_title": compat.quote(norm_url)} doc[encode_mongo_key(name)] = property_value self.collection.save(doc)
def writeProperty(self, normurl, propname, propertyvalue, dryRun=False, environ=None): assert normurl and normurl.startswith("/") assert propname assert propertyvalue is not None _logger.debug("writeProperty(%s, %s, dryRun=%s):\n\t%s" % (normurl, propname, dryRun, propertyvalue)) if dryRun: return # TODO: can we check anything here? doc = self._find(normurl) if doc: doc["properties"][propname] = propertyvalue else: doc = {"_id": uuid4().hex, # Documentation suggests to set the id "url": normurl, "title": compat.quote(normurl), "type": "properties", "properties": {propname: propertyvalue} } self.db.save(doc)
def writeProperty(self, normurl, propname, propertyvalue, dryRun=False, environ=None): assert normurl and normurl.startswith("/") assert propname assert propertyvalue is not None assert propname not in HIDDEN_KEYS, "MongoDB key is protected: '%s'" % propname _logger.debug("writeProperty(%s, %s, dryRun=%s):\n\t%s" % (normurl, propname, dryRun, propertyvalue)) if dryRun: return # TODO: can we check anything here? doc = self.collection.find_one({"_url": normurl}) if not doc: doc = { "_url": normurl, "_title": compat.quote(normurl), } doc[encodeMongoKey(propname)] = propertyvalue self.collection.save(doc)
def get_ref_url(self): refPath = "/by_key/%s/%s" % (self.data["key"], os.path.basename(self.file_path)) return compat.quote(self.provider.share_path + refPath)
def get_ref_url(self): refPath = "/by_key/%s/%s" % (self.data["key"], self.name) return compat.quote(self.provider.share_path + refPath)
def get_ref_url(self): refPath = "/by_key/%s" % self.data["key"] return compat.quote(self.provider.sharePath + refPath)
def unicode_to_url(s): # TODO: Py3: Is this the correct way? return compat.quote(s.encode("utf8"))