• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

inspirehep / inspire-next / 12409

pending completion
12409

Pull #3436

travis-ci

web-flow
utils: make is_pdf_link accept long lines

The previous (i.e. third) iteration of `is_pdf_link` didn't work when
all the content was on a single line, as it was then reading too much
resulting in the connection being killed.
This is avoided by reading a fixed number of bytes, instead of a fixed
number of lines.

Signed-off-by: Micha Moskovic <michamos@gmail.com>
Pull Request #3436: utils: make is_pdf_link accept long lines

2 of 2 new or added lines in 1 file covered. (100.0%)

7216 of 9239 relevant lines covered (78.1%)

2.42 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.32
/inspirehep/utils/export.py
1
# -*- coding: utf-8 -*-
2
#
3
# This file is part of INSPIRE.
4
# Copyright (C) 2014-2017 CERN.
5
#
6
# INSPIRE is free software: you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation, either version 3 of the License, or
9
# (at your option) any later version.
10
#
11
# INSPIRE is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License
17
# along with INSPIRE. If not, see <http://www.gnu.org/licenses/>.
18
#
19
# In applying this license, CERN does not waive the privileges and immunities
20
# granted to it by virtue of its status as an Intergovernmental Organization
21
# or submit itself to any jurisdiction.
22

23
from __future__ import absolute_import, division, print_function
5✔
24

25
import time
5✔
26

27
from inspirehep.utils.record_getter import get_es_record
5✔
28

29

30
class MissingRequiredFieldError(LookupError):
5✔
31

32
    """Base class for exceptions in this module.
33
    The exception should be raised when the specific,
34
    required field doesn't exist in the record.
35
    """
36

37
    def __init__(self, field):
5✔
38
        self.field = field
×
39

40
    def __str__(self):
5✔
41
        return "Missing field: " + self.field
×
42

43

44
class Export(object):
5✔
45
    """Base class used for export formats."""
46

47
    def __init__(self, record, *args, **kwargs):
5✔
48
        self.record = record
2✔
49

50
    def _get_citation_key(self):
5✔
51
        """Returns citation keys."""
52
        result = []
2✔
53
        citation_key = ''
2✔
54
        if 'external_system_numbers' in self.record:
2✔
55
            for field in self.record['external_system_numbers']:
1✔
56
                if 'institute' in field and \
1✔
57
                    (field['institute'] == 'INSPIRETeX' or
58
                        field['institute'] == 'SPIRESTeX'):
59
                    result.append(field)
1✔
60
            for key in result:
1✔
61
                if key['institute'] in ('INSPIRETeX', 'SPIRESTeX'):
1✔
62
                    if 'value' in key:
1✔
63
                        citation_key = key['value']
1✔
64
        if isinstance(citation_key, list):
2✔
65
            return citation_key[0].replace(' ', '')
1✔
66
        else:
67
            return citation_key.replace(' ', '')
2✔
68

69
    def _get_doi(self):
5✔
70
        """Return doi"""
71
        if 'dois' in self.record:
2✔
72
            doi_list = []
2✔
73
            for doi in self.record['dois']:
2✔
74
                doi_list.append(doi['value'])
2✔
75
            return ', '.join(doi for doi in list(set(doi_list)))
2✔
76
        else:
77
            return ''
1✔
78

79
    @property
5✔
80
    def arxiv_field(self):
81
        """Return arXiv field if exists"""
82
        if 'arxiv_eprints' in self.record:
2✔
83
            for field in self.record['arxiv_eprints']:
1✔
84
                return field
1✔
85

86
    def _get_arxiv(self):
5✔
87
        """Return arXiv and arXiv category"""
88
        arxiv = ''
2✔
89
        if self.arxiv_field:
2✔
90
            if 'value' in self.arxiv_field:
1✔
91
                arxiv = self.arxiv_field['value']
1✔
92
                if self.arxiv_field.get('categories', []):
1✔
93
                    arxiv += ' ['
1✔
94
                    arxiv += ",".join(self.arxiv_field.get('categories', []))
1✔
95
                    arxiv += ']'
1✔
96
        return arxiv
2✔
97

98
    def _get_report_number(self):
5✔
99
        """Return report number separated by commas"""
100
        report_number = []
1✔
101
        if 'report_numbers' in self.record:
1✔
102
            for field in self.record['report_numbers']:
1✔
103
                if 'value' in field:
1✔
104
                    report_number.append(field['value'])
1✔
105
            return ', '.join(str(p) for p in report_number)
1✔
106
        else:
107
            return report_number
1✔
108

109
    def _get_slac_citation(self):
5✔
110
        """Return SLACcitation"""
111
        cite_line = ''
2✔
112
        cite_element = ''
2✔
113
        if self.arxiv_field:
2✔
114
            if 'value' in self.arxiv_field:
1✔
115
                cite_element = self.arxiv_field['value'].upper()
1✔
116
                cite_line = '%%CITATION = ' + \
1✔
117
                            cite_element + ';%%'
118
        elif self._get_pubnote():
2✔
119
            cite_element = self._get_pubnote()
1✔
120
            cite_line = '%%CITATION = ' + cite_element + ';%%'
1✔
121
        elif 'report_numbers' in self.record:
2✔
122
            for field in self.record.get('arxiv_eprints', []):
1✔
123
                if 'categories' in field:
×
124
                    cite_element = field['value'].upper()
×
125
                    cite_line = '%%CITATION = ' + cite_element + ';%%'
×
126
            if not cite_element and self.record['report_numbers']:
1✔
127
                cite_element = self.record[
1✔
128
                    'report_numbers'][0]['value'].upper()
129
                cite_line = '%%CITATION = ' + cite_element + ';%%'
1✔
130
        else:
131
            cite_element = str(self.record['control_number'])
2✔
132
            cite_line = '%%CITATION = ' + 'INSPIRE-' + \
2✔
133
                cite_element + ';%%'
134
        return cite_line
2✔
135

136
    def _get_citation_number(self):
5✔
137
        """Returns how many times record was cited. If 0, returns nothing"""
138
        today = time.strftime("%d %b %Y")
2✔
139
        record = get_es_record('lit', self.record['control_number'])
2✔
140
        citations = ''
2✔
141
        try:
2✔
142
            times_cited = record['citation_count']
2✔
143
            if times_cited != 0:
1✔
144
                if times_cited > 1:
1✔
145
                    citations = '%d citations counted in INSPIRE as of %s' \
1✔
146
                                % (times_cited, today)
147
                else:
148
                    citations = '%d citation counted in INSPIRE as of %s'\
1✔
149
                                % (times_cited, today)
150
        except KeyError:
2✔
151
            pass
2✔
152
        return citations
2✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2024 Coveralls, Inc