Abstract stripURLParameters into the adapters for coming buffynfaithnet adapter.

This commit is contained in:
Jim Miller 2012-12-14 13:18:13 -06:00
parent 3346f0962c
commit 1346e9bc7a
3 changed files with 10 additions and 6 deletions

View file

@ -108,7 +108,6 @@ import adapter_jlaunlimitedcom
import adapter_qafficcom
import adapter_efpfanficnet
## This bit of complexity allows adapters to be added by just adding
## importing. It eliminates the long if/else clauses we used to need
## to pick out the adapter.
@ -172,10 +171,6 @@ def getClassFor(url):
## remove any trailing '#' locations.
fixedurl = re.sub(r"#.*$","",fixedurl)
## remove any trailing '&' parameters--?sid=999 will be left.
## that's all that any of the current adapters need or want.
fixedurl = re.sub(r"&.*$","",fixedurl)
parsedUrl = up.urlparse(fixedurl)
domain = parsedUrl.netloc.lower()
if( domain != parsedUrl.netloc ):
@ -192,6 +187,8 @@ def getClassFor(url):
cls = getClassFromList("www."+domain)
fixedurl = fixedurl.replace("http://","http://www.")
fixedurl = cls.stripURLParameters(fixedurl)
return (cls,fixedurl)
def getClassFromList(domain):

View file

@ -76,7 +76,7 @@ class SquidgeOrgPejaAdapter(BaseSiteAdapter):
# The site domain. Does have www here, if it uses it.
return 'www.squidge.org'
@classmethod # must be @staticmethod, don't remove it.
@classmethod # must be @classmethod, don't remove it.
def getConfigSection(cls):
# The config section name. Only override if != site domain.
return cls.getSiteDomain()+'/peja'

View file

@ -255,6 +255,13 @@ class BaseSiteAdapter(Configurable):
"Only needs to be overriden if != site domain."
return cls.getSiteDomain()
@classmethod
def stripURLParameters(cls,url):
"Only needs to be overriden if URL contains more than one parameter"
## remove any trailing '&' parameters--?sid=999 will be left.
## that's all that any of the current adapters need or want.
return re.sub(r"&.*$","",url)
## URL pattern validation is done *after* picking an adaptor based
## on domain instead of *as* the adaptor selector so we can offer
## the user example(s) for that particular site.