def _fetch(self, method, url=None, post_data=None, parse_data=True, key=None, parameters=None, listener=None, full_return=False):
headers = self.get_headers()<EOL>headers["<STR_LIT:Content-Type>"] = "<STR_LIT:application/json>"<EOL>handlers = []<EOL>debuglevel = int(self._settings["<STR_LIT>"])<EOL>handlers.append(urllib2.HTTPHandler(debuglevel=debuglevel))<EOL>if hasattr(httplib, "<STR_LIT>"):<EOL><INDENT>handlers.append(urllib2.HTTPSHandler(debuglevel=debuglevel))<EOL><DEDENT>handlers.append(urllib2.HTTPCookieProcessor(cookielib.CookieJar()))<EOL>password_url = self._get_password_url()<EOL>if password_url and "<STR_LIT>" not in headers:<EOL><INDENT>pwd_manager = urllib2.HTTPPasswordMgrWithDefaultRealm()<EOL>pwd_manager.add_password(None, password_url, self._settings["<STR_LIT:user>"], self._settings["<STR_LIT:password>"])<EOL>handlers.append(HTTPBasicAuthHandler(pwd_manager))<EOL><DEDENT>opener = urllib2.build_opener(*handlers)<EOL>if post_data is not None:<EOL><INDENT>post_data = json.dumps(post_data)<EOL><DEDENT>uri = self._url(url, parameters)<EOL>request = RESTRequest(uri, method=method, headers=headers)<EOL>if post_data is not None:<EOL><INDENT>request.add_data(post_data)<EOL><DEDENT>response = None<EOL>try:<EOL><INDENT>response = opener.open(request)<EOL>body = response.read()<EOL>if password_url and password_url not in self._settings["<STR_LIT>"] and request.has_header("<STR_LIT>"):<EOL><INDENT>self._settings["<STR_LIT>"][password_url] = request.get_header("<STR_LIT>")<EOL><DEDENT><DEDENT>except urllib2.HTTPError as e:<EOL><INDENT>if e.code == <NUM_LIT>:<EOL><INDENT>raise AuthenticationError("<STR_LIT>" % uri)<EOL><DEDENT>elif e.code == <NUM_LIT>:<EOL><INDENT>raise ConnectionError("<STR_LIT>" % uri)<EOL><DEDENT>else:<EOL><INDENT>raise<EOL><DEDENT><DEDENT>except urllib2.URLError as e:<EOL><INDENT>raise ConnectionError("<STR_LIT>" % (uri, e))<EOL><DEDENT>finally:<EOL><INDENT>if response:<EOL><INDENT>response.close()<EOL><DEDENT>opener.close()<EOL><DEDENT>data = None<EOL>if parse_data:<EOL><INDENT>if not key:<EOL><INDENT>key = string.split(url, "<STR_LIT:/>")[<NUM_LIT:0>]<EOL><DEDENT>data = self.parse(body, key)<EOL><DEDENT>if full_return:<EOL><INDENT>info = response.info() if response else None<EOL>status = int(string.split(info["<STR_LIT:status>"])[<NUM_LIT:0>]) if (info and "<STR_LIT:status>" in info) else None<EOL>return {<EOL>"<STR_LIT:success>": (status >= <NUM_LIT:200> and status < <NUM_LIT>), <EOL>"<STR_LIT:data>": data, <EOL>"<STR_LIT:info>": info, <EOL>"<STR_LIT:body>": body<EOL>}<EOL><DEDENT>return data<EOL>
Issue a request.

        Args:
            method (str): Request method (GET/POST/PUT/DELETE/etc.) If not specified, it will be POST if post_data is not None

        Kwargs:
            url (str): Destination URL
            post_data (str): A string of what to POST
            parse_data (bool): If true, parse response data
            key (string): If parse_data==True, look for this key when parsing data
            parameters (dict): Additional GET parameters to append to the URL
            listener (func): callback called when uploading a file
            full_return (bool): If set to True, get a full response (with success, data, info, body)

        Returns:
            dict. Response. If full_return==True, a dict with keys: success, data, info, body, otherwise the parsed data

        Raises:
            AuthenticationError, ConnectionError, urllib2.HTTPError, ValueError