Use optional CONTEXT_SOURCE_FILE setting to determine data source.
        Return the parsed data.

        Can be an http|https url or local file. Supports csv and excel files.
337224
def get_context(self, publish=False):
        
        context = self.project.DEFAULT_CONTEXT
        try:
            file = self.project.CONTEXT_SOURCE_FILE
            # CSV
            if re.search(r'(csv|CSV)$', file):
                context.update(self.get_context_from_csv())
            # Excel
            if re.search(r'(xlsx|XLSX|xls|XLS)$', file):
                context.update(self.get_context_from_xlsx())
        except AttributeError:
            context.update(self.get_context_from_gdoc())

        return context
88607
def get_data(context, resource, **kwargs):
    """"""

    url_suffix = ''
    if 'keys' in kwargs and kwargs['keys']:
        url_suffix = '/?keys=%s' % ','.join(kwargs.pop('keys'))

    uri = '%s/%s/%s/data%s' % (context.dci_cs_api, resource,
                               kwargs.pop('id'), url_suffix)

    r = context.session.get(uri, timeout=HTTP_TIMEOUT, params=kwargs)
    return r
565730
def _update_datasource(self, source, data):
        
        if not self.document:
            return

        data = self._postprocess_data(data)
        empty = all(len(v) == 0 for v in data.values())
        if (self.streaming and self.streaming[0].data is self.current_frame.data
            and self._stream_data and not empty):
            stream = self.streaming[0]
            if stream._triggering:
                data = {k: v[-stream._chunk_length:] for k, v in data.items()}
                source.stream(data, stream.length)
            return

        if cds_column_replace(source, data):
            source.data = data
        else:
            source.data.update(data)
1194425
def get_source(self, name):
        """"""
        path = self.get_filename(name)
        try:
            source_bytes = self.get_data(path)
        except OSError as exc:
            e = _ImportError('source not available through get_data()',
                             name=name)
            e.__cause__ = exc
            raise e
        return decode_source(source_bytes)
1261202
def source_file(self):
        
        if self._filename is None:
            self._filename = self._as_in_memory_geotiff()._filename
        return self._filename
902605
def get_context_data(self, **kwargs):
        
        context = super().get_context_data(**kwargs)
        context['top_level_forum'] = self.top_level_forum
        context['top_level_forum_url'] = self.get_top_level_forum_url()
        return context
1113541
def source(self, getline=linecache.getline):
        
        try:
            return getline(self.filename, self.lineno)
        except Exception as exc:
            return "??? NO SOURCE: {!r}".format(exc)
62335
def _load_data(self):
        
        if self.raw_data is None and self.data_format is not FormatType.PYTHON:
            if self.file_path is None:
                raise ArgumentInvalid('One of "raw_data" or "file_path" should be set!')
            if not os.path.isfile(self.file_path) or not os.access(self.file_path, os.R_OK):
                raise ArgumentInvalid('"file_path" should be a valid path to an exist file with read permission!')
            with open(self.file_path) as f:
                self.raw_data = f.read()
1221626
def get_context_from_xlsx(self):
        
        if re.search('^(http|https)://', self.project.CONTEXT_SOURCE_FILE):
            resp = requests.get(self.project.CONTEXT_SOURCE_FILE)
            content = resp.content
        else:
            try:
                with open(self.project.CONTEXT_SOURCE_FILE) as xlsxfile:
                    content = xlsxfile.read()
            except IOError:
                filepath = "%s/%s" % (
                    os.path.abspath(self.path),
                    self.project.CONTEXT_SOURCE_FILE)
                with open(filepath) as xlsxfile:
                    content = xlsxfile.read()

        data = process_xlsx(content)
        if 'values' in data:
            data = copy_global_values(data)

        return data
289158
def on_source_request(self, py_db, request):
        '''
        
        '''
        source_reference = request.arguments.sourceReference
        server_filename = None
        content = None

        if source_reference != 0:
            server_filename = pydevd_file_utils.get_server_filename_from_source_reference(source_reference)
            if server_filename:
                # Try direct file access first - it's much faster when available.
                try:
                    with open(server_filename, 'r') as stream:
                        content = stream.read()
                except:
                    pass

                if content is None:
                    # File might not exist at all, or we might not have a permission to read it,
                    # but it might also be inside a zipfile, or an IPython cell. In this case,
                    # linecache might still be able to retrieve the source.
                    lines = (linecache.getline(server_filename, i) for i in itertools.count(1))
                    lines = itertools.takewhile(bool, lines)  # empty lines are '\n', EOF is ''

                    # If we didn't get at least one line back, reset it to None so that it's
                    # reported as error below, and not as an empty file.
                    content = ''.join(lines) or None

        body = SourceResponseBody(content or '')
        response_args = {'body': body}

        if content is None:
            if source_reference == 0:
                message = 'Source unavailable'
            elif server_filename:
                message = 'Unable to retrieve source for %s' % (server_filename,)
            else:
                message = 'Invalid sourceReference %d' % (source_reference,)
            response_args.update({'success': False, 'message': message})

        response = pydevd_base_schema.build_response(request, kwargs=response_args)
        return NetCommand(CMD_RETURN, 0, response, is_json=True)
219912
def source(self, format='xml', accessible=False):
        
        if accessible:
            return self.http.get('/wda/accessibleSource').value
        return self.http.get('source?format='+format).value
106804
def localize_file_datasource(file_href, dirs):
    
    # support latest mapnik features of auto-detection
    # of image sizes and jpeg reading support...
    # http://trac.mapnik.org/ticket/508

    mapnik_requires_absolute_paths = (MAPNIK_VERSION < 601)

    file_href = urljoin(dirs.source.rstrip('/')+'/', file_href)
    scheme, n, path, p, q, f = urlparse(file_href)
    
    if scheme in ('http','https'):
        scheme, path = '', locally_cache_remote_file(file_href, dirs.cache)

    if scheme not in ('file', ''):
        raise Exception("Datasource file needs to be a working, fetchable resource, not %s" % file_href)

    if mapnik_requires_absolute_paths:
        return posixpath.realpath(path)
    
    else:
        return dirs.output_path(path)
929363
def _get_source(link):
    
    if link.startswith("http://") or link.startswith("https://"):
        down = httpkie.Downloader()
        return down.download(link)

    if os.path.exists(link):
        with open(link) as f:
            return f.read()

    raise UserWarning("html: '%s' is neither URL or data!" % link)
616152
def check_url_filetoupload(self):
        # type: () -> None
        
        if self.file_to_upload is None:
            if 'url' in self.data:
                if 'resource_type' not in self.data:
                    self.data['resource_type'] = 'api'
                if 'url_type' not in self.data:
                    self.data['url_type'] = 'api'
            else:
                raise HDXError('Either a url or a file to upload must be supplied!')
        else:
            if 'url' in self.data:
                if self.data['url'] != hdx.data.dataset.Dataset.temporary_url:
                    raise HDXError('Either a url or a file to upload must be supplied not both!')
            if 'resource_type' not in self.data:
                self.data['resource_type'] = 'file.upload'
            if 'url_type' not in self.data:
                self.data['url_type'] = 'upload'
            if 'tracking_summary' in self.data:
                del self.data['tracking_summary']
1195984
def get_uri(source):
    

    import gst

    src_info = source_info(source)

    if src_info['is_file']:  # Is this a file?
        return get_uri(src_info['uri'])

    elif gst.uri_is_valid(source):  # Is this a valid URI source for Gstreamer
        uri_protocol = gst.uri_get_protocol(source)
        if gst.uri_protocol_is_supported(gst.URI_SRC, uri_protocol):
            return source
        else:
            raise IOError('Invalid URI source for Gstreamer')
    else:
        raise IOError('Failed getting uri for path %s: no such file' % source)
1342070
def _get_learning_data_resource(self):
        
        for res in self.dsDoc['dataResources']:
            resPath = res['resPath']
            resType = res['resType']
            if resType == 'table':
                if 'learningData.csv' in resPath:
                    return res
                else:
                    raise RuntimeError('could not find learningData.csv')

        # if the for loop is over and learningDoc is not found, then return None
        raise RuntimeError('could not find learningData resource')
1103271
def load_csv_data(resource_name):
    # type: (str) -> List[str]
    
    data_bytes = pkgutil.get_data('clkhash', 'data/{}'.format(resource_name))
    if data_bytes is None:
        raise ValueError("No data resource found with name {}".format(resource_name))
    else:
        data = data_bytes.decode('utf8')
        reader = csv.reader(data.splitlines())
        next(reader, None)  # skip the headers
        return [row[0] for row in reader]