Commit 06ffd3a0 authored by mitshel's avatar mitshel
Browse files

PATH_INFO environ processing is made in sopdserve.py

parent fde0f0ce
Loading
Loading
Loading
Loading
+44 −30
Original line number Diff line number Diff line
@@ -82,6 +82,12 @@ class opdsClient():
        self.template1=sopdstempl.opdsTemplate(self.modulePath)
        self.opdsWrapper=sopdswrap.baseWrapper(self.cfg, self.template1)

        self.template2=sopdstempl.webTemplate(self.modulePath)
        self.webWrapper=sopdswrap.baseWrapper(self.cfg, self.template2)

        self.Wrapper=self.opdsWrapper


    def resetParams(self):
        self.id_value='0'
        self.type_value=0
@@ -94,12 +100,15 @@ class opdsClient():
        self.nl=''
        self.searchTerm=''
        self.user=None
        self.method=0
#        self.response_status='200 Ok'
#        self.response_headers=[]
#        self.response_body=[]
        self.opdsWrapper.resetParams()
        self.webWrapper.resetParams()

    def parseParams(self,qs):
    def parseParams(self,qs,method=0):
        self.method=method
        if 'id' in qs:
           self.id_value=qs.get("id")[0]
        else:
@@ -143,101 +152,106 @@ class opdsClient():
           if ser.isdigit():
              self.ser_value=int(ser)

        if self.method==1:
           self.Wrapper=self.webWrapper
        else:
           self.Wrapper=self.opdsWrapper

    def setUser(self,user):
        self.user=user

    def add_response_body(self, string='', encoding='utf8'):
        self.opdsWrapper.add_response_body(string,encoding)
        self.Wrapper.add_response_body(string,encoding)

    def add_response_binary(self, data):
        self.opdsWrapper.add_response_binary(data)
        self.Wrapper.add_response_binary(data)

    def add_response_header(self,list):
        self.opdsWrapper.add_response_header(list)
        self.Wrapper.add_response_header(list)

    def set_response_status(self,status):
        self.opdsWrapper.set_response_status(status)
        self.Wrapper.set_response_status(status)

    def write_response_headers(self, encoding='utf8'):
        self.opdsWrapper.write_response_headers(encoding)
        self.Wrapper.write_response_headers(encoding)

    def write_response(self):
        self.opdsWrapper.write_response()
        self.Wrapper.write_response()

    def get_response_status(self):
        return self.opdsWrapper.response_status
        return self.Wrapper.response_status

    def get_response_headers(self):
        return self.opdsWrapper.response_headers
        return self.Wrapper.response_headers

    def get_response_body(self):
        return self.opdsWrapper.response_body
        return self.Wrapper.response_body

    def header(self, h_id=None, h_title=None, h_subtitle=None,charset='utf-8'):
        if h_id==None: h_id=self.cfg.SITE_ID
        if h_title==None: h_title=self.cfg.SITE_TITLE
        if h_subtitle==None: h_subtitle='Simple OPDS Catalog by www.sopds.ru. Version '+sopdscfg.VERSION
        self.opdsWrapper.header(h_id,h_title,h_subtitle,time.strftime("%Y-%m-%dT%H:%M:%SZ"))
        self.Wrapper.header(h_id,h_title,h_subtitle,time.strftime("%Y-%m-%dT%H:%M:%SZ"))

    def footer(self):
        self.opdsWrapper.footer()
        self.Wrapper.footer()

    def main_menu(self):
        dbinfo=self.opdsdb.getdbinfo(self.cfg.DUBLICATES_SHOW,self.cfg.BOOK_SHELF,self.user)
        self.opdsWrapper.main_menu(self.user,dbinfo)
        self.Wrapper.main_menu(self.user,dbinfo)

    def new_menu(self):
        newinfo=self.opdsdb.getnewinfo(self.cfg.DUBLICATES_SHOW,self.cfg.NEW_PERIOD)
        self.opdsWrapper.new_menu(newinfo)
        self.Wrapper.new_menu(newinfo)

    def authors_submenu(self,author_id):
        self.opdsWrapper.authors_submenu(author_id)
        self.Wrapper.authors_submenu(author_id)

    def entry_start(self):
        self.opdsWrapper.entry_start()
        self.Wrapper.entry_start()

    def entry_head(self,e_title,e_date,e_id):
        self.opdsWrapper.entry_head(e_title,e_date,e_id)
        self.Wrapper.entry_head(e_title,e_date,e_id)

    def entry_link_subsection(self,link_id):
         self.opdsWrapper.entry_link_subsection(link_id,self.nl)
         self.Wrapper.entry_link_subsection(link_id,self.nl)

    def entry_link_book(self,link_id,format):
         self.opdsWrapper.entry_link_book(link_id,format)
         self.Wrapper.entry_link_book(link_id,format)

    def entry_authors(self,book_id,link_show=False):
        return self.opdsWrapper.entry_authors(self.opdsdb.getauthors(book_id))
        return self.Wrapper.entry_authors(self.opdsdb.getauthors(book_id))

    def entry_doubles(self,book_id):
        self.opdsWrapper.entry_doubles(book_id,self.opdsdb.getdoublecount(book_id))
        self.Wrapper.entry_doubles(book_id,self.opdsdb.getdoublecount(book_id))

    def entry_genres(self,book_id):
        return self.opdsWrapper.entry_genres(self.opdsdb.getgenres(book_id))
        return self.Wrapper.entry_genres(self.opdsdb.getgenres(book_id))

    def entry_series(self,book_id):
        return self.opdsWrapper.entry_series(self.opdsdb.getseries(book_id))
        return self.Wrapper.entry_series(self.opdsdb.getseries(book_id))

    def entry_covers(self,cover,cover_type,book_id):
        if self.cfg.COVER_SHOW!=0:
           self.opdsWrapper.entry_covers(book_id)
           self.Wrapper.entry_covers(book_id)

    def entry_content(self,e_content):
        self.opdsWrapper.entry_content(e_content)
        self.Wrapper.entry_content(e_content)

    def entry_content2(self,annotation='',title='',authors='',genres='',filename='',filesize=0,docdate='',series=''):
         self.opdsWrapper.entry_content2(annotation,title,authors,genres,filename,filesize,docdate,series)
         self.Wrapper.entry_content2(annotation,title,authors,genres,filename,filesize,docdate,series)

    def entry_finish(self):
        self.opdsWrapper.entry_finish()
        self.Wrapper.entry_finish()

    def page_control(self, page, link_id):
        if page>0:
           self.opdsWrapper.page_control_prev(page,link_id)
           self.Wrapper.page_control_prev(page,link_id)
        if self.opdsdb.next_page:
           self.opdsWrapper.page_control_next(page,link_id)
           self.Wrapper.page_control_next(page,link_id)

    def alphabet_menu(self,iid_value):
        self.opdsWrapper.alphabet_menu(iid_value,self.nl) 
        self.Wrapper.alphabet_menu(iid_value,self.nl) 

    def response_main(self):
        self.header()
+6 −1
Original line number Diff line number Diff line
@@ -35,10 +35,15 @@ def app(environ, start_response):

   if (user!=None) or not cfg.AUTH:
      qs   = None
      method = 0 
      if 'QUERY_STRING' in environ:
         qs = parse.parse_qs(environ['QUERY_STRING'])
      if 'PATH_INFO' in environ:
         if '/web' in environ['PATH_INFO']:
            method = 1

      sopds.resetParams()
      sopds.parseParams(qs)
      sopds.parseParams(qs,method)
      sopds.setUser(user)
      sopds.make_response()
   else:
+41 −60
Original line number Diff line number Diff line
@@ -137,53 +137,43 @@ class webTemplate(opdsTemplate):
    def __init__(self, modulepath, charset='utf-8'):
       self.charset=charset
       self.modulepath=modulepath
       self.response_header=('Content-Type','text/xml; charset='+self.charset)
       self.response_header=('Content-Type','text/html; charset='+self.charset)
       self.document_style='''
                           <style>
                               body {font-family: Tahoma, Geneva, sans-serif; font-size: 8pt; color: #000; max-width: 840px; margin: 0; padding: 0; }
                               h1 {font-size: 140%%; margin-bottom: 30px; }
                               h2 {font-size: 120%%; }
                               h2 a { color: #000; }
                               a {color: #0F3253;}
                               input, button {vertical-align: middle;border-radius: 2pt;}
                               input {border: 1pt solid #676767;}
                               button {border: 1pt solid #676767; background-color: #EEE; }
                               .page { padding: 0 40px 20px 40px; }
                               .footer {padding-top: 15pt; border-top: 2pt dotted #AAA; margin-top: 20pt; }
                               .navigation_entry {margin-left: 20pt; }
                               .navigation_entry h2 {display: inline-block;margin: 2pt 20pt 6pt -15pt; }
                            </style>
                            '''
       self.document_header=('<html>'
                               '<head>'
                               '<title>%%(title)s/>%%(subtitle)s</title>'
                               '<meta charset=%(charset)s>'
                               '<title>%%(title)s</title>'
                               '%(style)s'
                               '</head>'
                               '<body>'
                               )
       self.document_footer='</body>'
       self.document_mainmenu_std=('<
                               ('<link href="%(modulepath)s?id=09" rel="search" type="application/opensearchdescription+xml" />'
                               '<link href="%(modulepath)s?searchTerm={searchTerms}" rel="search" type="application/atom+xml" />'
                               '<entry>'
                               '<title>По каталогам</title>'
                               '<content type="text">Каталогов: %%(cat_num)s, книг: %%(book_num)s.</content>'
                               '<link type="application/atom+xml;profile=opds-catalog;kind=navigation" href="%(modulepath)s?id=01"/>'
                               '<id>id:01</id></entry>'
                               '<entry>'
                               '<title>По авторам</title>'
                               '<content type="text">Авторов: %%(author_num)s.</content>'
                               '<link type="application/atom+xml;profile=opds-catalog;kind=navigation" href="%(modulepath)s?id=%%(alphabet_id)s02"/>'
                               '<id>id:02</id></entry>'
                               '<entry>'
                               '<title>По наименованию</title>'
                               '<content type="text">Книг: %%(book_num)s.</content>'
                               '<link type="application/atom+xml;profile=opds-catalog;kind=navigation" href="%(modulepath)s?id=%%(alphabet_id)s03"/>'
                               '<id>id:03</id></entry>'
                               '<entry>'
                               '<title>По Жанрам</title>'
                               '<content type="text">Жанров: %%(genre_num)s.</content>'
                               '<link type="application/atom+xml;profile=opds-catalog;kind=navigation" href="%(modulepath)s?id=04"/>'
                               '<id>id:04</id></entry>'
                               '<entry>'
                               '<title>По Сериям</title>'
                               '<content type="text">Серий: %%(series_num)s.</content>'
                               '<link type="application/atom+xml;profile=opds-catalog;kind=navigation" href="%(modulepath)s?id=%%(alphabet_id)s06"/>'
                               '<id>id:06</id></entry>'
                               '<div class=page>'
                               '<h1>%%(subtitle)s</h1>'
                               )%{'charset':self.charset,'style':self.document_style}
       self.document_footer='</div></body>'
       self.document_mainmenu_std=('<div class=navigation_entry><h2><a href="%(modulepath)s?id=01">По каталогам</a></h2><i>Каталогов: %%(cat_num)s, книг: %%(book_num)s.</i></div>'
                               '<div class=navigation_entry><h2><a href="%(modulepath)s?id=%%(alphabet_id)s02">По авторам</a></h2><i>Авторов: %%(author_num)s.</i></div>'
                               '<div class=navigation_entry><h2><a href="%(modulepath)s?id=%%(alphabet_id)s03">По наименованию</a></h2><i>Книг: %%(book_num)s.</i></div>'
                               '<div class=navigation_entry><h2><a href="%(modulepath)s?id=04">По жанрам</a></h2><i>Жанров: %%(genre_num)s.</i></div>'
                               '<div class=navigation_entry><h2><a href="%(modulepath)s?id=%%(alphabet_id)s06">По сериям</a></h2><i>Серий: %%(series_num)s.</i></div>'
                               )%{'modulepath':self.modulepath}
       self.document_mainmenu_new=('<entry>'
                               '<title>Новинки за %%(new_period)s суток</title>'
                               '<link type="application/atom+xml;profile=opds-catalog;kind=navigation" href="%(modulepath)s?id=05"/>'
                               '<id>id:05</id></entry>'
       self.document_mainmenu_new=('<div class=navigation_entry><h2><a href="%(modulepath)s?id=05">Новинки за %%(new_period)s суток.</a></h2><i></i></div>'
                               )%{'modulepath':self.modulepath}
       self.document_mainmenu_shelf=('<entry>'
                               '<title>Книжная полка для %%(user)s</title>'
                               '<content type="text">Книг: %%(shelf_book_num)s.</content>'
                               '<link type="application/atom+xml;profile=opds-catalog;kind=navigation" href="%(modulepath)s?id=08"/>'
                               '<id>id:08</id></entry>'
       self.document_mainmenu_shelf=('<div class=navigation_entry><h2><a href="%(modulepath)s?id=08">Книжная полка для %%(user)s.</a></h2><i></i></div>'
                               )%{'modulepath':self.modulepath}
       self.document_newmenu=('<entry>'
                               '<title>Все новинки за %%(new_period)s суток</title>'
@@ -203,21 +193,12 @@ class webTemplate(opdsTemplate):
                               '<link type="application/atom+xml;profile=opds-catalog;kind=navigation" href="%(modulepath)s?id=%%(alphabet_id)s06&amp;news=1"/>'
                               '<id>id:06:news</id></entry>'
                               )%{'modulepath':self.modulepath}
       self.document_authors_submenu=('<entry>'
                               '<title>Книги по сериям</title>'
                               '<link type="application/atom+xml;profile=opds-catalog;kind=navigation" href="%(modulepath)s?id=31%%(author_id)s"/>'
                               '<id>id:31:authors</id></entry>'
                               '<entry>'
                               '<title>Книги вне серий</title>'
                               '<link type="application/atom+xml;profile=opds-catalog;kind=navigation" href="%(modulepath)s?id=34%%(author_id)s"/>'
                               '<id>id:32:authors</id></entry>'
                               '<entry>'
                               '<title>Книги по алфавиту</title>'
                               '<link type="application/atom+xml;profile=opds-catalog;kind=navigation" href="%(modulepath)s?id=33%%(author_id)s"/>'
                               '<id>id:33:authors</id></entry>'
       self.document_authors_submenu=('<div class=navigation_entry><h2><a href="%(modulepath)s?id=31%%(author_id)s">Книги по сериям</a></h2><i></i></div>'
                               '<div class=navigation_entry><h2><a href="%(modulepath)s?id=34%%(author_id)s">Книги вне серий</a></h2><i></i></div>'
                               '<div class=navigation_entry><h2><a href="%(modulepath)s?id=33%%(author_id)s">Книги по алфавиту</a></h2><i></i></div>'
                               )%{'modulepath':self.modulepath}
       self.document_entry_start='<entry>'
       self.document_entry_finish='</entry>'
       self.document_entry_start='<div class=navigation_entry>'
       self.document_entry_finish='</div>'
       self.document_entry_head=('<title>%(e_title)s</title>'
                               '<updated>%(e_date)s</updated>'
                               '<id>id:%(e_id)s</id>')
@@ -253,11 +234,11 @@ class webTemplate(opdsTemplate):
       self.document_entry_content2_annotation='&lt;p class=book&gt; %(annotation)s&lt;/p&gt;'
       self.document_entry_content2_finish='</content>'

       self.document_alphabet_menu=('<entry><title>А..Я (РУС)</title><id>alpha:1</id><link type="application/atom+xml;profile=opds-catalog;kind=navigation" href="%(modulepath)s?id=%%(iid)s&amp;alpha=1%%(nl)s"/></entry>'
                                    '<entry><title>0..9 (Цифры)</title><id>alpha:2</id><link type="application/atom+xml;profile=opds-catalog;kind=navigation" href="%(modulepath)s?id=%%(iid)s&amp;alpha=2%%(nl)s"/></entry>'
                                    '<entry><title>A..Z (ENG)</title><id>alpha:3</id><link type="application/atom+xml;profile=opds-catalog;kind=navigation" href="%(modulepath)s?id=%%(iid)s&amp;alpha=3%%(nl)s"/></entry>'
                                    '<entry><title>Другие Символы</title><id>alpha:4</id><link type="application/atom+xml;profile=opds-catalog;kind=navigation" href="%(modulepath)s?id=%%(iid)s&amp;alpha=4%%(nl)s"/></entry>'
                                    '<entry><title>Показать все</title><id>alpha:5</id><link type="application/atom+xml;profile=opds-catalog;kind=navigation" href="%(modulepath)s?id=%%(iid)s&amp;alpha=5%%(nl)s"/></entry>'
       self.document_alphabet_menu=('<div class=navigation_entry><h2><a href="%(modulepath)s?id=%%(iid)s&amp;alpha=1%%(nl)s">А..Я (РУС)</a></h2><i></i></div>'
                                    '<div class=navigation_entry><h2><a href="%(modulepath)s?id=%%(iid)s&amp;alpha=2%%(nl)s">0..9 (Цифры)</a></h2><i></i></div>'
                                    '<div class=navigation_entry><h2><a href="%(modulepath)s?id=%%(iid)s&amp;alpha=3%%(nl)s">A..Z (ENG)</a></h2><i></i></div>'
                                    '<div class=navigation_entry><h2><a href="%(modulepath)s?id=%%(iid)s&amp;alpha=4%%(nl)s">Другие символы</a></h2><i></i></div>'
                                    '<div class=navigation_entry><h2><a href="%(modulepath)s?id=%%(iid)s&amp;alpha=5%%(nl)s">Показать все</a></h2><i></i></div>'
                                    )%{'modulepath':self.modulepath}

       self.document_page_control_prev=('<link type="application/atom+xml;profile=opds-catalog;kind=acquisition" rel="prev" title="Previous Page" href="%(modulepath)s?id=%%(link_id)s&amp;page=%%(page)s" />'