def test_gb4(self):
     """Non-ascii characters in author's name."""
     i = ('http://books.google.com/books?id='
          'i8nZjjo_9ikC&pg=PA229&dq=%22legal+translation+is%22&hl=en&sa='
          'X&ei=hEuYUr_mOsnKswb49oDQCA&ved=0CC4Q6AEwAA#v=onepage&q='
          '%22legal%20translation%20is%22&f=false')
     o = googlebooks_response(i)
     e1 = '{{sfn | Šarčević | 1997 | p=229}}'
     e2 = ('* {{cite book '
           '| last=Šarčević '
           '| first=S. '
           '| title=New Approach to Legal Translation '
           '| publisher=Springer Netherlands '
           '| year=1997 '
           '| isbn=978-90-411-0401-4 '
           '| url=http://books.google.com/books?id=i8nZjjo_9ikC&pg=PA229 '
           '| ref=harv '
           '| accessdate=')
     self.assertIn(e1, o.sfn)
     self.assertIn(e2, o.cite)
 def test_gb3(self):
     """Non-ascii characters in title (Some of them where removed later)"""
     i = ('http://books.google.com/books?id=icMEAAAAQBAJ&pg=PA588&dq=%22a+'
          'Delimiter+is%22&hl=en&sa=X&ei=oNKSUrKeDovItAbO_4CoBA&ved='
          '0CC4Q6AEwAA#v=onepage&q=%22a%20Delimiter%20is%22&f=false')
     o = googlebooks_response(i)
     e1 = '{{sfn | Farrell | 2009 | p=588}}'
     e2 = ('* {{cite book '
           '| last=Farrell '
           '| first=J. '
           '| title=Microsoft Visual C# 2008 Comprehensive: '
           'An Introduction to Object-Oriented Programming '
           '| publisher=Cengage Learning '
           '| year=2009 '
           '| isbn=978-1-111-78619-9 '
           '| url=http://books.google.com/books?id=icMEAAAAQBAJ&pg=PA588 '
           '| ref=harv '
           '| accessdate=')
     self.assertIn(e1, o.sfn)
     self.assertIn(e2, o.cite)
Exemple #3
0
 def test_gb4(self):
     """Non-ascii characters in author's name."""
     i = 'http://books.google.com/books?id=' \
         'i8nZjjo_9ikC&pg=PA229&dq=%22legal+translation+is%22&hl=en&sa=' \
         'X&ei=hEuYUr_mOsnKswb49oDQCA&ved=0CC4Q6AEwAA#v=onepage&q=' \
         '%22legal%20translation%20is%22&f=false'
     o = googlebooks_response(i)
     e1 = '<ref>{{پک | Šarčević | 1997 ' \
          '| ک=New Approach to Legal Translation |' \
          ' زبان=en | ص=229}}\u200f</ref>'
     e2 = '* {{یادکرد کتاب | نام خانوادگی=Šarčević |' \
          ' نام=S. |' \
          ' عنوان=New Approach to Legal Translation |' \
          ' ناشر=Springer Netherlands |' \
          ' سال=1997 |' \
          ' شابک=978-90-411-0401-4 |' \
          ' پیوند=http://books.google.com/books?id=i8nZjjo_9ikC&pg=PA229 |'\
          ' زبان=en |' \
          ' تاریخ بازبینی='
     self.assertIn(e1, o.sfn)
     self.assertIn(e2, o.cite)
 def test_gb5(self):
     """ref checking"""
     i = ('https://encrypted.google.com/books?id=6upvonUt0O8C&pg=PA378&'
          'dq=density+of+granite&hl=en&sa=X&ei=YBHIU-qCBIyX0QXusoDgAg&ved='
          '0CEIQ6AEwBjgK#v=onepage&q=density%20of%20granite&f=false')
     o = googlebooks_response(i)
     ctnt = (
         '* {{cite book '
         '| last=Serway '
         '| first=R.A. '
         '| last2=Jewett '
         '| first2=J.W. '
         '| title=Physics for Scientists and Engineers, Volume 1, '
         'Chapters 1-22 | publisher=Cengage Learning '
         '| series=Physics for Scientists and Engineers '
         '| year=2009 '
         '| isbn=978-1-4390-4838-2 '
         '| url=http://encrypted.google.com/books?id=6upvonUt0O8C&pg=PA378 '
         '| ref=harv '
         '| accessdate=')
     reft = (
         '<ref name="Serway Jewett 2009 p. 378">'
         '{{cite book '
         '| last=Serway '
         '| first=R.A. '
         '| last2=Jewett '
         '| first2=J.W. '
         '| title=Physics for Scientists and Engineers, Volume 1, '
         'Chapters 1-22 | publisher=Cengage Learning '
         '| series=Physics for Scientists and Engineers '
         '| year=2009 '
         '| isbn=978-1-4390-4838-2 '
         '| url=http://encrypted.google.com/books?id=6upvonUt0O8C&pg=PA378 '
         '| accessdate=')
     self.assertIn(ctnt, o.cite)
     self.assertIn(reft, o.ref)
     self.assertIn(' | page=378}}</ref>', o.ref)
Exemple #5
0
def get_response(user_input, date_format):
    if not user_input:
        # on first run user_input is ''
        return DEFAULT_RESPONSE
    en_user_input = unquote(uninum2en(user_input))
    # Checking the user input for dot is important because
    # the use of dotless domains is prohibited.
    # See: https://features.icann.org/dotless-domains
    user_input_contains_dot = '.' in en_user_input
    if user_input_contains_dot:
        # Try predefined URLs
        # Todo: The following code could be done in threads.
        if not user_input.startswith('http'):
            url = 'http://' + user_input
        else:
            url = user_input
        netloc = urlparse(url)[1]
        if '.google.com/books' in url:
            return googlebooks_response(url, date_format)
        response_getter = NETLOC_TO_RESPONSE.get(netloc)
        if response_getter:
            return response_getter(url, date_format)
        # DOIs contain dots
        m = DOI_SEARCH(unescape(en_user_input))
        if m:
            return doi_response(m.group(1), pure=True, date_format=date_format)
        return urls_response(url, date_format)
    else:
        # We can check user inputs containing dots for ISBNs, but probably is
        # error prone.
        m = ISBN13_SEARCH(en_user_input) or ISBN10_SEARCH(en_user_input)
        if m:
            try:
                return isbn_response(m.group(), True, date_format)
            except IsbnError:
                pass
        return UNDEFINED_INPUT_RESPONSE