summaryrefslogtreecommitdiff
path: root/mammoth/docx/files.py
blob: d919de93edbe49c5549b9a5de445d90088a4ab5d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import os
import contextlib
try:
    from urllib2 import urlopen
except ImportError:
    from urllib.request import urlopen
try:
    from urllib.parse import urlparse
except ImportError:
    from urlparse import urlparse


class Files(object):
    def __init__(self, base):
        self._base = base
    
    def open(self, uri):
        if _is_absolute(uri):
            return contextlib.closing(urlopen(uri))
        else:
            return open(os.path.join(self._base, uri), "rb")


def _is_absolute(url):
    return urlparse(url).scheme != ""