Exemplo n.º 1
0
def url_doi_isbn_to_sfn_cit_ref(user_input, date_format) -> tuple:
    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
    if '.' in en_user_input:
        # 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
        # TLD stands for top-level domain
        tldless_netloc = urlparse(url)[1].rpartition('.')[0]
        resolver = TLDLESS_NETLOC_RESOLVER(
            tldless_netloc[4:] if tldless_netloc.
            startswith('www.') else tldless_netloc)
        if resolver:
            return resolver(url, date_format)
        # DOIs contain dots
        m = DOI_SEARCH(unescape(en_user_input))
        if m:
            return doi_sfn_cit_ref(m[1], True, date_format)
        return urls_sfn_cit_ref(url, date_format)
    else:
        # We can check user inputs containing dots for ISBNs, but probably is
        # error prone.
        m = ISBN_10OR13_SEARCH(en_user_input)
        if m:
            try:
                return isbn_sfn_cit_ref(m[0], True, date_format)
            except IsbnError:
                pass
        return UNDEFINED_INPUT_SFN_CIT_REF
Exemplo n.º 2
0
Arquivo: app.py Projeto: 5j9/yadkard
def url_doi_isbn_to_sfn_cit_ref(user_input, date_format) -> tuple:
    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
    if '.' in en_user_input:
        # 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
        # TLD stands for top-level domain
        tldless_netloc = urlparse(url)[1].rpartition('.')[0]
        resolver = TLDLESS_NETLOC_RESOLVER(
            tldless_netloc[4:] if tldless_netloc.startswith('www.')
            else tldless_netloc)
        if resolver:
            return resolver(url, date_format)
        # DOIs contain dots
        m = DOI_SEARCH(unescape(en_user_input))
        if m:
            return doi_sfn_cit_ref(m[1], True, date_format)
        return urls_sfn_cit_ref(url, date_format)
    else:
        # We can check user inputs containing dots for ISBNs, but probably is
        # error prone.
        m = ISBN_10OR13_SEARCH(en_user_input)
        if m:
            try:
                return isbn_sfn_cit_ref(m[0], True, date_format)
            except IsbnError:
                pass
        return UNDEFINED_INPUT_SFN_CIT_REF
Exemplo n.º 3
0
 def test_is4(self):
     """unpure isbn10"""
     self.assertEqual(
         '* {{یادکرد کتاب | نام خانوادگی=حافظ |'
         ' نام=شمس‌الدین‌محمد | دیگران=رضا نظرزاده (به‌اهتمام) |'
         ' عنوان=دیوان کامل حافظ همراه با فالنامه |'
         ' ناشر=دیوان | مکان=قم - قم |'
         ' سال=۱۳۸۵ | ماه=۰۹ | شابک=964-92962-6-3 | زبان=fa}}',
         isbn_sfn_cit_ref('choghondar 964-92962-6-3 شلغم')[1])
Exemplo n.º 4
0
 def test_is4(self):
     """unpure isbn10 not found in ottobib"""
     self.assertEqual((
         '* {{cite book | last=حافظ | first=شمس‌الدین‌محمد '
         '| others=رضا نظرزاده (به‌اهتمام) '
         '| title=دیوان کامل حافظ همراه با فالنامه | publisher=دیوان '
         '| publication-place=قم - قم | year=1385 | isbn=964-92962-6-3 '
         '| language=fa | ref=harv}}'
     ), isbn_sfn_cit_ref('choghondar 964-92962-6-3 شلغم')[1])
Exemplo n.º 5
0
 def test_is3(self):
     """exists in both"""
     self.assertEqual((
         '* {{cite book | last=Sipihrī | first=Suhrāb '
         '| title=Rāz-i gul-i surkh '
         '| publisher=Muʼassasah-ʼi Intishārāt-i Nigāh '
         '| publication-place=Tihrān | year=1379 | isbn=964-6736-34-3 '
         '| oclc=53446327 | ref=harv}}'
     ), isbn_sfn_cit_ref('964-6736-34-3 ')[1])
Exemplo n.º 6
0
 def test_is4(self):
     """unpure isbn10"""
     self.assertEqual(
         '* {{یادکرد کتاب | نام خانوادگی=حافظ |'
         ' نام=شمس‌الدین‌محمد | دیگران=رضا نظرزاده (به‌اهتمام) |'
         ' عنوان=دیوان کامل حافظ همراه با فالنامه |'
         ' ناشر=دیوان | مکان=قم - قم |'
         ' سال=۱۳۸۵ | ماه=۰۹ | شابک=964-92962-6-3 | زبان=fa}}',
         isbn_sfn_cit_ref('choghondar 964-92962-6-3 شلغم')[1]
     )
Exemplo n.º 7
0
 def test_is2(self):
     """not found in ottobib"""
     self.assertEqual(
         '* {{یادکرد کتاب | دیگران=بدیل‌بن‌علی خاقانی'
         ' (شاعر)، جهانگیر منصور (به‌اهتمام) '
         'و محمدحسن فروزانفر (مقدمه) |'
         ' عنوان=دیوان خاقانی شروانی |'
         ' ناشر=موسسه انتشارات نگاه | مکان=تهران - تهران |'
         ' سال=۱۳۹۶ | ماه=۰۵ | شابک=978-964-6736-71-9 | زبان=fa}}',
         isbn_sfn_cit_ref('978-964-6736-71-9', pure=True)[1])
Exemplo n.º 8
0
 def test_is3(self):
     """exists in both"""
     self.assertEqual(
         '* {{یادکرد کتاب |'
         ' دیگران=سهراب سپهری (شاعر) و سحر معصومی (به‌اهتمام) |'
         ' عنوان=راز گل سرخ: نقد و گزیده شعرهای سهراب سپهری |'
         ' ناشر=موسسه انتشارات نگاه | مکان=تهران - تهران |'
         ' سال=۱۳۸۱ | ماه=۰۶ | شابک=964-6736-34-3 | oclc=53446327 '
         '| زبان=fa}}',
         isbn_sfn_cit_ref('964-6736-34-3 ')[1],
     )
Exemplo n.º 9
0
 def test_is2(self):
     """not found in ottobib"""
     self.assertEqual(
         '* {{یادکرد کتاب | دیگران=بدیل‌بن‌علی خاقانی'
         ' (شاعر)، جهانگیر منصور (به‌اهتمام) '
         'و محمدحسن فروزانفر (مقدمه) |'
         ' عنوان=دیوان خاقانی شروانی |'
         ' ناشر=موسسه انتشارات نگاه | مکان=تهران - تهران |'
         ' سال=۱۳۹۶ | ماه=۰۵ | شابک=978-964-6736-71-9 | زبان=fa}}',
         isbn_sfn_cit_ref('978-964-6736-71-9', pure=True)[1]
     )
Exemplo n.º 10
0
 def test_is1(self):
     """not found in ketabir"""
     self.assertIn(
         '* {{یادکرد کتاب | نام خانوادگی=Adkins | نام=Roy |'
         ' عنوان=The war for all the oceans : '
         'from Nelson at the Nile to Napoleon at Waterloo |'
         ' ناشر=Abacus | مکان=London | سال=2007 |'
         ' شابک=978-0-349-11916-8 '
         '| oclc=137313052 '
         '| زبان=en}}',
         isbn_sfn_cit_ref('9780349119168', pure=True)[1])
Exemplo n.º 11
0
 def test_is3(self):
     """exists in both"""
     self.assertEqual(
         '* {{یادکرد کتاب |'
         ' دیگران=سهراب سپهری (شاعر) و سحر معصومی (به‌اهتمام) |'
         ' عنوان=راز گل سرخ: نقد و گزیده شعرهای سهراب سپهری |'
         ' ناشر=موسسه انتشارات نگاه | مکان=تهران - تهران |'
         ' سال=۱۳۸۱ | ماه=۰۶ | شابک=964-6736-34-3 | oclc=53446327 '
         '| زبان=fa}}',
         isbn_sfn_cit_ref('964-6736-34-3 ')[1],
     )
Exemplo n.º 12
0
 def test_is1(self):
     """not found in ketabir"""
     self.assertIn(
         '* {{یادکرد کتاب | نام خانوادگی=Adkins | نام=Roy |'
         ' عنوان=The war for all the oceans : '
         'from Nelson at the Nile to Napoleon at Waterloo |'
         ' ناشر=Abacus | مکان=London | سال=2007 |'
         ' شابک=978-0-349-11916-8 '
         '| oclc=137313052 '
         '| زبان=en}}',
         isbn_sfn_cit_ref('9780349119168', pure=True)[1])
Exemplo n.º 13
0
 def test_is2(self):
     """not found in ottobib"""
     self.assertEqual(
         '* {{cite book | others=بدیل‌بن‌علی خاقانی (شاعر)'
         ', جهانگیر منصور (به‌اهتمام), and محمدحسن فروزانفر (مقدمه) '
         '| title=دیوان خاقانی شروانی | publisher=موسسه انتشارات نگاه '
         '| publication-place=تهران - تهران | year=1396 '
         '| isbn=978-964-6736-71-9 | language=fa | ref={{sfnref '
         '| موسسه انتشارات نگاه |'
         ' 1396}}}}',
         isbn_sfn_cit_ref('978-964-6736-71-9', pure=True)[1]
     )
Exemplo n.º 14
0
 def test_is1(self):
     """not found in ketabir"""
     self.assertIn((
         '* {{cite book '
         '| last=Adkins '
         '| first=Roy '
         '| title=The war for all the oceans : '
         'from Nelson at the Nile to Napoleon at Waterloo '
         '| publisher=Abacus '
         '| publication-place=London '
         '| year=2007 '
         '| isbn=978-0-349-11916-8 '
         '| oclc=137313052 '
         '| ref=harv}}'
     ), isbn_sfn_cit_ref('9780349119168', pure=True)[1])