~ubuntu-branches/debian/sid/calibre/sid

« back to all changes in this revision

Viewing changes to src/calibre/ebooks/metadata/__init__.py

  • Committer: Package Import Robot
  • Author(s): Martin Pitt
  • Date: 2014-02-27 07:48:06 UTC
  • mto: This revision was merged to the branch mainline in revision 74.
  • Revision ID: package-import@ubuntu.com-20140227074806-64wdebb3ptosxhhx
Tags: upstream-1.25.0+dfsg
ImportĀ upstreamĀ versionĀ 1.25.0+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
try:
17
17
    _author_pat = re.compile(tweaks['authors_split_regex'])
18
18
except:
19
 
    prints ('Author split regexp:', tweaks['authors_split_regex'],
 
19
    prints('Author split regexp:', tweaks['authors_split_regex'],
20
20
            'is invalid, using default')
21
21
    _author_pat = re.compile(r'(?i),?\s+(and|with)\s+')
22
22
 
150
150
)
151
151
 
152
152
 
153
 
 
154
153
def roman(num):
155
154
    if num <= 0 or num >= 4000 or int(num) != num:
156
155
        return str(num)
174
173
    return fmt%i
175
174
 
176
175
class Resource(object):
 
176
 
177
177
    '''
178
178
    Represents a resource (usually a file on the filesystem or a URL pointing
179
179
    to the web. Such resources are commonly referred to in OPF files.
217
217
                self.path = os.path.abspath(os.path.join(basedir, pc.replace('/', os.sep)))
218
218
                self.fragment = unquote(url[-1])
219
219
 
220
 
 
221
220
    def href(self, basedir=None):
222
221
        '''
223
222
        Return a URL pointing to this resource. If it is a file on the filesystem
240
239
            return ''+frag
241
240
        try:
242
241
            rpath = relpath(self.path, basedir)
243
 
        except OSError: # On windows path and basedir could be on different drives
 
242
        except OSError:  # On windows path and basedir could be on different drives
244
243
            rpath = self.path
245
244
        if isinstance(rpath, unicode):
246
245
            rpath = rpath.encode('utf-8')
308
307
            res.set_basedir(path)
309
308
 
310
309
 
311
 
 
312
310
def MetaInformation(title, authors=(_('Unknown'),)):
313
311
    ''' Convenient encapsulation of book metadata, needed for compatibility
314
312
        @param title: title or ``_('Unknown')`` or a MetaInformation object
368
366
        return '-'.join((i[:2], i[2:6], i[6:9], i[9]))
369
367
    return '-'.join((i[:3], i[3:5], i[5:9], i[9:12], i[12]))
370
368
 
 
369
def check_doi(doi):
 
370
    'Check if something that looks like a DOI is present anywhere in the string'
 
371
    if not doi:
 
372
        return None
 
373
    doi_check = re.search(r'10\.\d{4}/\S+', doi)
 
374
    if doi_check is not None:
 
375
        return doi_check.group()
 
376
    return None
 
377