desc
stringlengths 3
26.7k
| decl
stringlengths 11
7.89k
| bodies
stringlengths 8
553k
|
---|---|---|
'Add a key and cert that will be used
any time a request requires authentication.'
| def add_certificate(self, key, cert, domain):
| self.certificates.add(key, cert, domain)
|
'Remove all the names and passwords
that are used for authentication'
| def clear_credentials(self):
| self.credentials.clear()
self.authorizations = []
|
'Do the actual request using the connection object
and also follow one level of redirects if necessary'
| def _request(self, conn, host, absolute_uri, request_uri, method, body, headers, redirections, cachekey):
| auths = [(auth.depth(request_uri), auth) for auth in self.authorizations if auth.inscope(host, request_uri)]
auth = ((auths and sorted(auths)[0][1]) or None)
if auth:
auth.request(method, request_uri, headers, body)
(response, content) = self._conn_request(conn, request_uri, method, body, headers)
if auth:
if auth.response(response, body):
auth.request(method, request_uri, headers, body)
(response, content) = self._conn_request(conn, request_uri, method, body, headers)
response._stale_digest = 1
if (response.status == 401):
for authorization in self._auth_from_challenge(host, request_uri, headers, response, content):
authorization.request(method, request_uri, headers, body)
(response, content) = self._conn_request(conn, request_uri, method, body, headers)
if (response.status != 401):
self.authorizations.append(authorization)
authorization.response(response, body)
break
if (self.follow_all_redirects or (method in ['GET', 'HEAD']) or (response.status == 303)):
if (self.follow_redirects and (response.status in [300, 301, 302, 303, 307])):
if redirections:
if ((not response.has_key('location')) and (response.status != 300)):
raise RedirectMissingLocation(_('Redirected but the response is missing a Location: header.'), response, content)
if response.has_key('location'):
location = response['location']
(scheme, authority, path, query, fragment) = parse_uri(location)
if (authority == None):
response['location'] = urlparse.urljoin(absolute_uri, location)
if ((response.status == 301) and (method in ['GET', 'HEAD'])):
response['-x-permanent-redirect-url'] = response['location']
if (not response.has_key('content-location')):
response['content-location'] = absolute_uri
_updateCache(headers, response, content, self.cache, cachekey)
if headers.has_key('if-none-match'):
del headers['if-none-match']
if headers.has_key('if-modified-since'):
del headers['if-modified-since']
if response.has_key('location'):
location = response['location']
old_response = copy.deepcopy(response)
if (not old_response.has_key('content-location')):
old_response['content-location'] = absolute_uri
redirect_method = ((((response.status == 303) and (method not in ['GET', 'HEAD'])) and 'GET') or method)
(response, content) = self.request(location, redirect_method, body=body, headers=headers, redirections=(redirections - 1))
response.previous = old_response
else:
raise RedirectLimit(_('Redirected more times than rediection_limit allows.'), response, content)
elif ((response.status in [200, 203]) and (method == 'GET')):
if (not response.has_key('content-location')):
response['content-location'] = absolute_uri
_updateCache(headers, response, content, self.cache, cachekey)
return (response, content)
|
'Performs a single HTTP request.
The \'uri\' is the URI of the HTTP resource and can begin
with either \'http\' or \'https\'. The value of \'uri\' must be an absolute URI.
The \'method\' is the HTTP method to perform, such as GET, POST, DELETE, etc.
There is no restriction on the methods allowed.
The \'body\' is the entity body to be sent with the request. It is a string
object.
Any extra headers that are to be sent with the request should be provided in the
\'headers\' dictionary.
The maximum number of redirect to follow before raising an
exception is \'redirections. The default is 5.
The return value is a tuple of (response, content), the first
being and instance of the \'Response\' class, the second being
a string that contains the response entity body.'
| def request(self, uri, method='GET', body=None, headers=None, redirections=DEFAULT_MAX_REDIRECTS, connection_type=None):
| try:
if (headers is None):
headers = {}
else:
headers = self._normalize_headers(headers)
if (not headers.has_key('user-agent')):
headers['user-agent'] = ('Python-httplib2/%s' % __version__)
uri = iri2uri(uri)
(scheme, authority, request_uri, defrag_uri) = urlnorm(uri)
domain_port = authority.split(':')[0:2]
if ((len(domain_port) == 2) and (domain_port[1] == '443') and (scheme == 'http')):
scheme = 'https'
authority = domain_port[0]
conn_key = ((scheme + ':') + authority)
if (conn_key in self.connections):
conn = self.connections[conn_key]
else:
if (not connection_type):
connection_type = (((scheme == 'https') and HTTPSConnectionWithTimeout) or HTTPConnectionWithTimeout)
certs = list(self.certificates.iter(authority))
if ((scheme == 'https') and certs):
conn = self.connections[conn_key] = connection_type(authority, key_file=certs[0][0], cert_file=certs[0][1], timeout=self.timeout, proxy_info=self.proxy_info)
else:
conn = self.connections[conn_key] = connection_type(authority, timeout=self.timeout, proxy_info=self.proxy_info)
conn.set_debuglevel(debuglevel)
if ((method in ['GET', 'HEAD']) and ('range' not in headers) and ('accept-encoding' not in headers)):
headers['accept-encoding'] = 'gzip, deflate'
info = email.Message.Message()
cached_value = None
if self.cache:
cachekey = defrag_uri
cached_value = self.cache.get(cachekey)
if cached_value:
try:
(info, content) = cached_value.split('\r\n\r\n', 1)
feedparser = email.FeedParser.FeedParser()
feedparser.feed(info)
info = feedparser.close()
feedparser._parse = None
except IndexError as ValueError:
self.cache.delete(cachekey)
cachekey = None
cached_value = None
else:
cachekey = None
if ((method in self.optimistic_concurrency_methods) and self.cache and info.has_key('etag') and (not self.ignore_etag) and ('if-match' not in headers)):
headers['if-match'] = info['etag']
if ((method not in ['GET', 'HEAD']) and self.cache and cachekey):
self.cache.delete(cachekey)
if ((method in ['GET', 'HEAD']) and ('vary' in info)):
vary = info['vary']
vary_headers = vary.lower().replace(' ', '').split(',')
for header in vary_headers:
key = ('-varied-%s' % header)
value = info[key]
if (headers.get(header, '') != value):
cached_value = None
break
if (cached_value and (method in ['GET', 'HEAD']) and self.cache and ('range' not in headers)):
if info.has_key('-x-permanent-redirect-url'):
(response, new_content) = self.request(info['-x-permanent-redirect-url'], 'GET', headers=headers, redirections=(redirections - 1))
response.previous = Response(info)
response.previous.fromcache = True
else:
entry_disposition = _entry_disposition(info, headers)
if (entry_disposition == 'FRESH'):
if (not cached_value):
info['status'] = '504'
content = ''
response = Response(info)
if cached_value:
response.fromcache = True
return (response, content)
if (entry_disposition == 'STALE'):
if (info.has_key('etag') and (not self.ignore_etag) and (not ('if-none-match' in headers))):
headers['if-none-match'] = info['etag']
if (info.has_key('last-modified') and (not ('last-modified' in headers))):
headers['if-modified-since'] = info['last-modified']
elif (entry_disposition == 'TRANSPARENT'):
pass
(response, new_content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey)
if ((response.status == 304) and (method == 'GET')):
for key in _get_end2end_headers(response):
info[key] = response[key]
merged_response = Response(info)
if hasattr(response, '_stale_digest'):
merged_response._stale_digest = response._stale_digest
_updateCache(headers, merged_response, content, self.cache, cachekey)
response = merged_response
response.status = 200
response.fromcache = True
elif (response.status == 200):
content = new_content
else:
self.cache.delete(cachekey)
content = new_content
else:
cc = _parse_cache_control(headers)
if cc.has_key('only-if-cached'):
info['status'] = '504'
response = Response(info)
content = ''
else:
(response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey)
except Exception as e:
if self.force_exception_to_status_code:
if isinstance(e, HttpLib2ErrorWithResponse):
response = e.response
content = e.content
response.status = 500
response.reason = str(e)
elif (isinstance(e, socket.timeout) or (isinstance(e, socket.error) and ('timed out' in str(e)))):
content = 'Request Timeout'
response = Response({'content-type': 'text/plain', 'status': '408', 'content-length': len(content)})
response.reason = 'Request Timeout'
else:
content = str(e)
response = Response({'content-type': 'text/plain', 'status': '400', 'content-length': len(content)})
response.reason = 'Bad Request'
else:
raise
return (response, content)
|
'__recvall(count) -> data
Receive EXACTLY the number of bytes requested from the socket.
Blocks until the required number of bytes have been received.'
| def __recvall(self, count):
| data = self.recv(count)
while (len(data) < count):
d = self.recv((count - len(data)))
if (not d):
raise GeneralProxyError((0, 'connection closed unexpectedly'))
data = (data + d)
return data
|
'setproxy(proxytype, addr[, port[, rdns[, username[, password]]]])
Sets the proxy to be used.
proxytype - The type of the proxy to be used. Three types
are supported: PROXY_TYPE_SOCKS4 (including socks4a),
PROXY_TYPE_SOCKS5 and PROXY_TYPE_HTTP
addr - The address of the server (IP or DNS).
port - The port of the server. Defaults to 1080 for SOCKS
servers and 8080 for HTTP proxy servers.
rdns - Should DNS queries be preformed on the remote side
(rather than the local side). The default is True.
Note: This has no effect with SOCKS4 servers.
username - Username to authenticate with to the server.
The default is no authentication.
password - Password to authenticate with to the server.
Only relevant when username is also provided.'
| def setproxy(self, proxytype=None, addr=None, port=None, rdns=True, username=None, password=None):
| self.__proxy = (proxytype, addr, port, rdns, username, password)
|
'__negotiatesocks5(self,destaddr,destport)
Negotiates a connection through a SOCKS5 server.'
| def __negotiatesocks5(self, destaddr, destport):
| if ((self.__proxy[4] != None) and (self.__proxy[5] != None)):
self.sendall(struct.pack('BBBB', 5, 2, 0, 2))
else:
self.sendall(struct.pack('BBB', 5, 1, 0))
chosenauth = self.__recvall(2)
if (chosenauth[0:1] != chr(5).encode()):
self.close()
raise GeneralProxyError((1, _generalerrors[1]))
if (chosenauth[1:2] == chr(0).encode()):
pass
elif (chosenauth[1:2] == chr(2).encode()):
self.sendall(((((chr(1).encode() + chr(len(self.__proxy[4]))) + self.__proxy[4]) + chr(len(self.__proxy[5]))) + self.__proxy[5]))
authstat = self.__recvall(2)
if (authstat[0:1] != chr(1).encode()):
self.close()
raise GeneralProxyError((1, _generalerrors[1]))
if (authstat[1:2] != chr(0).encode()):
self.close()
raise Socks5AuthError((3, _socks5autherrors[3]))
else:
self.close()
if (chosenauth[1] == chr(255).encode()):
raise Socks5AuthError((2, _socks5autherrors[2]))
else:
raise GeneralProxyError((1, _generalerrors[1]))
req = struct.pack('BBB', 5, 1, 0)
try:
ipaddr = socket.inet_aton(destaddr)
req = ((req + chr(1).encode()) + ipaddr)
except socket.error:
if self.__proxy[3]:
ipaddr = None
req = (((req + chr(3).encode()) + chr(len(destaddr)).encode()) + destaddr)
else:
ipaddr = socket.inet_aton(socket.gethostbyname(destaddr))
req = ((req + chr(1).encode()) + ipaddr)
req = (req + struct.pack('>H', destport))
self.sendall(req)
resp = self.__recvall(4)
if (resp[0:1] != chr(5).encode()):
self.close()
raise GeneralProxyError((1, _generalerrors[1]))
elif (resp[1:2] != chr(0).encode()):
self.close()
if (ord(resp[1:2]) <= 8):
raise Socks5Error((ord(resp[1:2]), _socks5errors[ord(resp[1:2])]))
else:
raise Socks5Error((9, _socks5errors[9]))
elif (resp[3:4] == chr(1).encode()):
boundaddr = self.__recvall(4)
elif (resp[3:4] == chr(3).encode()):
resp = (resp + self.recv(1))
boundaddr = self.__recvall(ord(resp[4:5]))
else:
self.close()
raise GeneralProxyError((1, _generalerrors[1]))
boundport = struct.unpack('>H', self.__recvall(2))[0]
self.__proxysockname = (boundaddr, boundport)
if (ipaddr != None):
self.__proxypeername = (socket.inet_ntoa(ipaddr), destport)
else:
self.__proxypeername = (destaddr, destport)
|
'getsockname() -> address info
Returns the bound IP address and port number at the proxy.'
| def getproxysockname(self):
| return self.__proxysockname
|
'getproxypeername() -> address info
Returns the IP and port number of the proxy.'
| def getproxypeername(self):
| return _orgsocket.getpeername(self)
|
'getpeername() -> address info
Returns the IP address and port number of the destination
machine (note: getproxypeername returns the proxy)'
| def getpeername(self):
| return self.__proxypeername
|
'__negotiatesocks4(self,destaddr,destport)
Negotiates a connection through a SOCKS4 server.'
| def __negotiatesocks4(self, destaddr, destport):
| rmtrslv = False
try:
ipaddr = socket.inet_aton(destaddr)
except socket.error:
if self.__proxy[3]:
ipaddr = struct.pack('BBBB', 0, 0, 0, 1)
rmtrslv = True
else:
ipaddr = socket.inet_aton(socket.gethostbyname(destaddr))
req = (struct.pack('>BBH', 4, 1, destport) + ipaddr)
if (self.__proxy[4] != None):
req = (req + self.__proxy[4])
req = (req + chr(0).encode())
if rmtrslv:
req = ((req + destaddr) + chr(0).encode())
self.sendall(req)
resp = self.__recvall(8)
if (resp[0:1] != chr(0).encode()):
self.close()
raise GeneralProxyError((1, _generalerrors[1]))
if (resp[1:2] != chr(90).encode()):
self.close()
if (ord(resp[1:2]) in (91, 92, 93)):
self.close()
raise Socks4Error((ord(resp[1:2]), _socks4errors[(ord(resp[1:2]) - 90)]))
else:
raise Socks4Error((94, _socks4errors[4]))
self.__proxysockname = (socket.inet_ntoa(resp[4:]), struct.unpack('>H', resp[2:4])[0])
if (rmtrslv != None):
self.__proxypeername = (socket.inet_ntoa(ipaddr), destport)
else:
self.__proxypeername = (destaddr, destport)
|
'__negotiatehttp(self,destaddr,destport)
Negotiates a connection through an HTTP server.'
| def __negotiatehttp(self, destaddr, destport):
| if (not self.__proxy[3]):
addr = socket.gethostbyname(destaddr)
else:
addr = destaddr
self.sendall(((((((('CONNECT ' + addr) + ':') + str(destport)) + ' HTTP/1.1\r\n') + 'Host: ') + destaddr) + '\r\n\r\n').encode())
resp = self.recv(1)
while (resp.find('\r\n\r\n'.encode()) == (-1)):
resp = (resp + self.recv(1))
statusline = resp.splitlines()[0].split(' '.encode(), 2)
if (statusline[0] not in ('HTTP/1.0'.encode(), 'HTTP/1.1'.encode())):
self.close()
raise GeneralProxyError((1, _generalerrors[1]))
try:
statuscode = int(statusline[1])
except ValueError:
self.close()
raise GeneralProxyError((1, _generalerrors[1]))
if (statuscode != 200):
self.close()
raise HTTPError((statuscode, statusline[2]))
self.__proxysockname = ('0.0.0.0', 0)
self.__proxypeername = (addr, destport)
|
'connect(self, despair)
Connects to the specified destination through a proxy.
destpar - A tuple of the IP/DNS address and the port number.
(identical to socket\'s connect).
To select the proxy server use setproxy().'
| def connect(self, destpair):
| if ((not (type(destpair) in (list, tuple))) or (len(destpair) < 2) or (type(destpair[0]) != type('')) or (type(destpair[1]) != int)):
raise GeneralProxyError((5, _generalerrors[5]))
if (self.__proxy[0] == PROXY_TYPE_SOCKS5):
if (self.__proxy[2] != None):
portnum = self.__proxy[2]
else:
portnum = 1080
_orgsocket.connect(self, (self.__proxy[1], portnum))
self.__negotiatesocks5(destpair[0], destpair[1])
elif (self.__proxy[0] == PROXY_TYPE_SOCKS4):
if (self.__proxy[2] != None):
portnum = self.__proxy[2]
else:
portnum = 1080
_orgsocket.connect(self, (self.__proxy[1], portnum))
self.__negotiatesocks4(destpair[0], destpair[1])
elif (self.__proxy[0] == PROXY_TYPE_HTTP):
if (self.__proxy[2] != None):
portnum = self.__proxy[2]
else:
portnum = 8080
_orgsocket.connect(self, (self.__proxy[1], portnum))
self.__negotiatehttp(destpair[0], destpair[1])
elif (self.__proxy[0] == None):
_orgsocket.connect(self, (destpair[0], destpair[1]))
else:
raise GeneralProxyError((4, _generalerrors[4]))
|
'Returns the first argument used to construct this error.'
| @property
def message(self):
| return self.args[0]
|
'An object to hold a Twitter status message.
This class is normally instantiated by the twitter.Api class and
returned in a sequence.
Note: Dates are posted in the form "Sat Jan 27 04:17:38 +0000 2007"
Args:
created_at:
The time this status message was posted. [Optional]
favorited:
Whether this is a favorite of the authenticated user. [Optional]
favorite_count:
Number of times this status message has been favorited. [Optional]
id:
The unique id of this status message. [Optional]
text:
The text of this status message. [Optional]
location:
the geolocation string associated with this message. [Optional]
relative_created_at:
A human readable string representing the posting time. [Optional]
user:
A twitter.User instance representing the person posting the
message. [Optional]
now:
The current time, if the client chooses to set it.
Defaults to the wall clock time. [Optional]
urls:
user_mentions:
hashtags:
geo:
place:
coordinates:
contributors:
retweeted:
retweeted_status:
current_user_retweet:
retweet_count:
possibly_sensitive:
scopes:
withheld_copyright:
withheld_in_countries:
withheld_scope:'
| def __init__(self, created_at=None, favorited=None, favorite_count=None, id=None, text=None, location=None, user=None, in_reply_to_screen_name=None, in_reply_to_user_id=None, in_reply_to_status_id=None, truncated=None, source=None, now=None, urls=None, user_mentions=None, hashtags=None, media=None, geo=None, place=None, coordinates=None, contributors=None, retweeted=None, retweeted_status=None, current_user_retweet=None, retweet_count=None, possibly_sensitive=None, scopes=None, withheld_copyright=None, withheld_in_countries=None, withheld_scope=None):
| self.created_at = created_at
self.favorited = favorited
self.favorite_count = favorite_count
self.id = id
self.text = text
self.location = location
self.user = user
self.now = now
self.in_reply_to_screen_name = in_reply_to_screen_name
self.in_reply_to_user_id = in_reply_to_user_id
self.in_reply_to_status_id = in_reply_to_status_id
self.truncated = truncated
self.retweeted = retweeted
self.source = source
self.urls = urls
self.user_mentions = user_mentions
self.hashtags = hashtags
self.media = media
self.geo = geo
self.place = place
self.coordinates = coordinates
self.contributors = contributors
self.retweeted_status = retweeted_status
self.current_user_retweet = current_user_retweet
self.retweet_count = retweet_count
self.possibly_sensitive = possibly_sensitive
self.scopes = scopes
self.withheld_copyright = withheld_copyright
self.withheld_in_countries = withheld_in_countries
self.withheld_scope = withheld_scope
|
'Get the time this status message was posted.
Returns:
The time this status message was posted'
| def GetCreatedAt(self):
| return self._created_at
|
'Set the time this status message was posted.
Args:
created_at:
The time this status message was created'
| def SetCreatedAt(self, created_at):
| self._created_at = created_at
|
'Get the time this status message was posted, in seconds since the epoch.
Returns:
The time this status message was posted, in seconds since the epoch.'
| def GetCreatedAtInSeconds(self):
| return calendar.timegm(rfc822.parsedate(self.created_at))
|
'Get the favorited setting of this status message.
Returns:
True if this status message is favorited; False otherwise'
| def GetFavorited(self):
| return self._favorited
|
'Set the favorited state of this status message.
Args:
favorited:
boolean True/False favorited state of this status message'
| def SetFavorited(self, favorited):
| self._favorited = favorited
|
'Get the favorite count of this status message.
Returns:
number of times this status message has been favorited'
| def GetFavoriteCount(self):
| return self._favorite_count
|
'Set the favorited state of this status message.
Args:
favorite_count:
int number of favorites for this status message'
| def SetFavoriteCount(self, favorite_count):
| self._favorite_count = favorite_count
|
'Get the unique id of this status message.
Returns:
The unique id of this status message'
| def GetId(self):
| return self._id
|
'Set the unique id of this status message.
Args:
id:
The unique id of this status message'
| def SetId(self, id):
| self._id = id
|
'Get the text of this status message.
Returns:
The text of this status message.'
| def GetText(self):
| return self._text
|
'Set the text of this status message.
Args:
text:
The text of this status message'
| def SetText(self, text):
| self._text = text
|
'Get the geolocation associated with this status message
Returns:
The geolocation string of this status message.'
| def GetLocation(self):
| return self._location
|
'Set the geolocation associated with this status message
Args:
location:
The geolocation string of this status message'
| def SetLocation(self, location):
| self._location = location
|
'Get a human readable string representing the posting time
Returns:
A human readable string representing the posting time'
| def GetRelativeCreatedAt(self):
| fudge = 1.25
delta = (long(self.now) - long(self.created_at_in_seconds))
if (delta < (1 * fudge)):
return 'about a second ago'
elif (delta < (60 * (1 / fudge))):
return ('about %d seconds ago' % delta)
elif (delta < (60 * fudge)):
return 'about a minute ago'
elif (delta < ((60 * 60) * (1 / fudge))):
return ('about %d minutes ago' % (delta / 60))
elif ((delta < ((60 * 60) * fudge)) or ((delta / (60 * 60)) == 1)):
return 'about an hour ago'
elif (delta < (((60 * 60) * 24) * (1 / fudge))):
return ('about %d hours ago' % (delta / (60 * 60)))
elif ((delta < (((60 * 60) * 24) * fudge)) or ((delta / ((60 * 60) * 24)) == 1)):
return 'about a day ago'
else:
return ('about %d days ago' % (delta / ((60 * 60) * 24)))
|
'Get a twitter.User representing the entity posting this status message.
Returns:
A twitter.User representing the entity posting this status message'
| def GetUser(self):
| return self._user
|
'Set a twitter.User representing the entity posting this status message.
Args:
user:
A twitter.User representing the entity posting this status message'
| def SetUser(self, user):
| self._user = user
|
'Get the wallclock time for this status message.
Used to calculate relative_created_at. Defaults to the time
the object was instantiated.
Returns:
Whatever the status instance believes the current time to be,
in seconds since the epoch.'
| def GetNow(self):
| if (self._now is None):
self._now = time.time()
return self._now
|
'Set the wallclock time for this status message.
Used to calculate relative_created_at. Defaults to the time
the object was instantiated.
Args:
now:
The wallclock time for this instance.'
| def SetNow(self, now):
| self._now = now
|
'A string representation of this twitter.Status instance.
The return value is the same as the JSON string representation.
Returns:
A string representation of this twitter.Status instance.'
| def __str__(self):
| return self.AsJsonString()
|
'A JSON string representation of this twitter.Status instance.
Returns:
A JSON string representation of this twitter.Status instance'
| def AsJsonString(self):
| return simplejson.dumps(self.AsDict(), sort_keys=True)
|
'A dict representation of this twitter.Status instance.
The return value uses the same key names as the JSON representation.
Return:
A dict representing this twitter.Status instance'
| def AsDict(self):
| data = {}
if self.created_at:
data['created_at'] = self.created_at
if self.favorited:
data['favorited'] = self.favorited
if self.favorite_count:
data['favorite_count'] = self.favorite_count
if self.id:
data['id'] = self.id
if self.text:
data['text'] = self.text
if self.location:
data['location'] = self.location
if self.user:
data['user'] = self.user.AsDict()
if self.in_reply_to_screen_name:
data['in_reply_to_screen_name'] = self.in_reply_to_screen_name
if self.in_reply_to_user_id:
data['in_reply_to_user_id'] = self.in_reply_to_user_id
if self.in_reply_to_status_id:
data['in_reply_to_status_id'] = self.in_reply_to_status_id
if (self.truncated is not None):
data['truncated'] = self.truncated
if (self.retweeted is not None):
data['retweeted'] = self.retweeted
if (self.favorited is not None):
data['favorited'] = self.favorited
if self.source:
data['source'] = self.source
if self.geo:
data['geo'] = self.geo
if self.place:
data['place'] = self.place
if self.coordinates:
data['coordinates'] = self.coordinates
if self.contributors:
data['contributors'] = self.contributors
if self.hashtags:
data['hashtags'] = [h.text for h in self.hashtags]
if self.retweeted_status:
data['retweeted_status'] = self.retweeted_status.AsDict()
if self.retweet_count:
data['retweet_count'] = self.retweet_count
if self.urls:
data['urls'] = dict([(url.url, url.expanded_url) for url in self.urls])
if self.user_mentions:
data['user_mentions'] = [um.AsDict() for um in self.user_mentions]
if self.current_user_retweet:
data['current_user_retweet'] = self.current_user_retweet
if self.possibly_sensitive:
data['possibly_sensitive'] = self.possibly_sensitive
if self.scopes:
data['scopes'] = self.scopes
if self.withheld_copyright:
data['withheld_copyright'] = self.withheld_copyright
if self.withheld_in_countries:
data['withheld_in_countries'] = self.withheld_in_countries
if self.withheld_scope:
data['withheld_scope'] = self.withheld_scope
return data
|
'Create a new instance based on a JSON dict.
Args:
data: A JSON dict, as converted from the JSON in the twitter API
Returns:
A twitter.Status instance'
| @staticmethod
def NewFromJsonDict(data):
| if ('user' in data):
user = User.NewFromJsonDict(data['user'])
else:
user = None
if ('retweeted_status' in data):
retweeted_status = Status.NewFromJsonDict(data['retweeted_status'])
else:
retweeted_status = None
if ('current_user_retweet' in data):
current_user_retweet = data['current_user_retweet']['id']
else:
current_user_retweet = None
urls = None
user_mentions = None
hashtags = None
media = None
if ('entities' in data):
if ('urls' in data['entities']):
urls = [Url.NewFromJsonDict(u) for u in data['entities']['urls']]
if ('user_mentions' in data['entities']):
user_mentions = [User.NewFromJsonDict(u) for u in data['entities']['user_mentions']]
if ('hashtags' in data['entities']):
hashtags = [Hashtag.NewFromJsonDict(h) for h in data['entities']['hashtags']]
if ('media' in data['entities']):
media = data['entities']['media']
else:
media = []
return Status(created_at=data.get('created_at', None), favorited=data.get('favorited', None), favorite_count=data.get('favorite_count', None), id=data.get('id', None), text=data.get('text', None), location=data.get('location', None), in_reply_to_screen_name=data.get('in_reply_to_screen_name', None), in_reply_to_user_id=data.get('in_reply_to_user_id', None), in_reply_to_status_id=data.get('in_reply_to_status_id', None), truncated=data.get('truncated', None), retweeted=data.get('retweeted', None), source=data.get('source', None), user=user, urls=urls, user_mentions=user_mentions, hashtags=hashtags, media=media, geo=data.get('geo', None), place=data.get('place', None), coordinates=data.get('coordinates', None), contributors=data.get('contributors', None), retweeted_status=retweeted_status, current_user_retweet=current_user_retweet, retweet_count=data.get('retweet_count', None), possibly_sensitive=data.get('possibly_sensitive', None), scopes=data.get('scopes', None), withheld_copyright=data.get('withheld_copyright', None), withheld_in_countries=data.get('withheld_in_countries', None), withheld_scope=data.get('withheld_scope', None))
|
'Get the unique id of this user.
Returns:
The unique id of this user'
| def GetId(self):
| return self._id
|
'Set the unique id of this user.
Args:
id: The unique id of this user.'
| def SetId(self, id):
| self._id = id
|
'Get the real name of this user.
Returns:
The real name of this user'
| def GetName(self):
| return self._name
|
'Set the real name of this user.
Args:
name: The real name of this user'
| def SetName(self, name):
| self._name = name
|
'Get the short twitter name of this user.
Returns:
The short twitter name of this user'
| def GetScreenName(self):
| return self._screen_name
|
'Set the short twitter name of this user.
Args:
screen_name: the short twitter name of this user'
| def SetScreenName(self, screen_name):
| self._screen_name = screen_name
|
'Get the geographic location of this user.
Returns:
The geographic location of this user'
| def GetLocation(self):
| return self._location
|
'Set the geographic location of this user.
Args:
location: The geographic location of this user'
| def SetLocation(self, location):
| self._location = location
|
'Get the short text description of this user.
Returns:
The short text description of this user'
| def GetDescription(self):
| return self._description
|
'Set the short text description of this user.
Args:
description: The short text description of this user'
| def SetDescription(self, description):
| self._description = description
|
'Get the homepage url of this user.
Returns:
The homepage url of this user'
| def GetUrl(self):
| return self._url
|
'Set the homepage url of this user.
Args:
url: The homepage url of this user'
| def SetUrl(self, url):
| self._url = url
|
'Get the url of the thumbnail of this user.
Returns:
The url of the thumbnail of this user'
| def GetProfileImageUrl(self):
| return self._profile_image_url
|
'Set the url of the thumbnail of this user.
Args:
profile_image_url: The url of the thumbnail of this user'
| def SetProfileImageUrl(self, profile_image_url):
| self._profile_image_url = profile_image_url
|
'Boolean for whether to tile the profile background image.
Returns:
True if the background is to be tiled, False if not, None if unset.'
| def GetProfileBackgroundTile(self):
| return self._profile_background_tile
|
'Set the boolean flag for whether to tile the profile background image.
Args:
profile_background_tile: Boolean flag for whether to tile or not.'
| def SetProfileBackgroundTile(self, profile_background_tile):
| self._profile_background_tile = profile_background_tile
|
'Returns the current time zone string for the user.
Returns:
The descriptive time zone string for the user.'
| def GetTimeZone(self):
| return self._time_zone
|
'Sets the user\'s time zone string.
Args:
time_zone:
The descriptive time zone to assign for the user.'
| def SetTimeZone(self, time_zone):
| self._time_zone = time_zone
|
'Get the latest twitter.Status of this user.
Returns:
The latest twitter.Status of this user'
| def GetStatus(self):
| return self._status
|
'Set the latest twitter.Status of this user.
Args:
status:
The latest twitter.Status of this user'
| def SetStatus(self, status):
| self._status = status
|
'Get the friend count for this user.
Returns:
The number of users this user has befriended.'
| def GetFriendsCount(self):
| return self._friends_count
|
'Set the friend count for this user.
Args:
count:
The number of users this user has befriended.'
| def SetFriendsCount(self, count):
| self._friends_count = count
|
'Get the listed count for this user.
Returns:
The number of lists this user belongs to.'
| def GetListedCount(self):
| return self._listed_count
|
'Set the listed count for this user.
Args:
count:
The number of lists this user belongs to.'
| def SetListedCount(self, count):
| self._listed_count = count
|
'Get the follower count for this user.
Returns:
The number of users following this user.'
| def GetFollowersCount(self):
| return self._followers_count
|
'Set the follower count for this user.
Args:
count:
The number of users following this user.'
| def SetFollowersCount(self, count):
| self._followers_count = count
|
'Get the number of status updates for this user.
Returns:
The number of status updates for this user.'
| def GetStatusesCount(self):
| return self._statuses_count
|
'Set the status update count for this user.
Args:
count:
The number of updates for this user.'
| def SetStatusesCount(self, count):
| self._statuses_count = count
|
'Get the number of favourites for this user.
Returns:
The number of favourites for this user.'
| def GetFavouritesCount(self):
| return self._favourites_count
|
'Set the favourite count for this user.
Args:
count:
The number of favourites for this user.'
| def SetFavouritesCount(self, count):
| self._favourites_count = count
|
'Get the setting of geo_enabled for this user.
Returns:
True/False if Geo tagging is enabled'
| def GetGeoEnabled(self):
| return self._geo_enabled
|
'Set the latest twitter.geo_enabled of this user.
Args:
geo_enabled:
True/False if Geo tagging is to be enabled'
| def SetGeoEnabled(self, geo_enabled):
| self._geo_enabled = geo_enabled
|
'Get the setting of verified for this user.
Returns:
True/False if user is a verified account'
| def GetVerified(self):
| return self._verified
|
'Set twitter.verified for this user.
Args:
verified:
True/False if user is a verified account'
| def SetVerified(self, verified):
| self._verified = verified
|
'Get the setting of lang for this user.
Returns:
language code of the user'
| def GetLang(self):
| return self._lang
|
'Set twitter.lang for this user.
Args:
lang:
language code for the user'
| def SetLang(self, lang):
| self._lang = lang
|
'Get the setting of notifications for this user.
Returns:
True/False for the notifications setting of the user'
| def GetNotifications(self):
| return self._notifications
|
'Set twitter.notifications for this user.
Args:
notifications:
True/False notifications setting for the user'
| def SetNotifications(self, notifications):
| self._notifications = notifications
|
'Get the setting of contributors_enabled for this user.
Returns:
True/False contributors_enabled of the user'
| def GetContributorsEnabled(self):
| return self._contributors_enabled
|
'Set twitter.contributors_enabled for this user.
Args:
contributors_enabled:
True/False contributors_enabled setting for the user'
| def SetContributorsEnabled(self, contributors_enabled):
| self._contributors_enabled = contributors_enabled
|
'Get the setting of created_at for this user.
Returns:
created_at value of the user'
| def GetCreatedAt(self):
| return self._created_at
|
'Set twitter.created_at for this user.
Args:
created_at:
created_at value for the user'
| def SetCreatedAt(self, created_at):
| self._created_at = created_at
|
'A string representation of this twitter.User instance.
The return value is the same as the JSON string representation.
Returns:
A string representation of this twitter.User instance.'
| def __str__(self):
| return self.AsJsonString()
|
'A JSON string representation of this twitter.User instance.
Returns:
A JSON string representation of this twitter.User instance'
| def AsJsonString(self):
| return simplejson.dumps(self.AsDict(), sort_keys=True)
|
'A dict representation of this twitter.User instance.
The return value uses the same key names as the JSON representation.
Return:
A dict representing this twitter.User instance'
| def AsDict(self):
| data = {}
if self.id:
data['id'] = self.id
if self.name:
data['name'] = self.name
if self.screen_name:
data['screen_name'] = self.screen_name
if self.location:
data['location'] = self.location
if self.description:
data['description'] = self.description
if self.profile_image_url:
data['profile_image_url'] = self.profile_image_url
if (self.profile_background_tile is not None):
data['profile_background_tile'] = self.profile_background_tile
if self.profile_background_image_url:
data['profile_sidebar_fill_color'] = self.profile_background_image_url
if self.profile_background_color:
data['profile_background_color'] = self.profile_background_color
if self.profile_link_color:
data['profile_link_color'] = self.profile_link_color
if self.profile_text_color:
data['profile_text_color'] = self.profile_text_color
if (self.protected is not None):
data['protected'] = self.protected
if self.utc_offset:
data['utc_offset'] = self.utc_offset
if self.time_zone:
data['time_zone'] = self.time_zone
if self.url:
data['url'] = self.url
if self.status:
data['status'] = self.status.AsDict()
if self.friends_count:
data['friends_count'] = self.friends_count
if self.followers_count:
data['followers_count'] = self.followers_count
if self.statuses_count:
data['statuses_count'] = self.statuses_count
if self.favourites_count:
data['favourites_count'] = self.favourites_count
if self.geo_enabled:
data['geo_enabled'] = self.geo_enabled
if self.verified:
data['verified'] = self.verified
if self.lang:
data['lang'] = self.lang
if self.notifications:
data['notifications'] = self.notifications
if self.contributors_enabled:
data['contributors_enabled'] = self.contributors_enabled
if self.created_at:
data['created_at'] = self.created_at
if self.listed_count:
data['listed_count'] = self.listed_count
return data
|
'Create a new instance based on a JSON dict.
Args:
data:
A JSON dict, as converted from the JSON in the twitter API
Returns:
A twitter.User instance'
| @staticmethod
def NewFromJsonDict(data):
| if ('status' in data):
status = Status.NewFromJsonDict(data['status'])
else:
status = None
return User(id=data.get('id', None), name=data.get('name', None), screen_name=data.get('screen_name', None), location=data.get('location', None), description=data.get('description', None), statuses_count=data.get('statuses_count', None), followers_count=data.get('followers_count', None), favourites_count=data.get('favourites_count', None), friends_count=data.get('friends_count', None), profile_image_url=data.get('profile_image_url_https', data.get('profile_image_url', None)), profile_background_tile=data.get('profile_background_tile', None), profile_background_image_url=data.get('profile_background_image_url', None), profile_sidebar_fill_color=data.get('profile_sidebar_fill_color', None), profile_background_color=data.get('profile_background_color', None), profile_link_color=data.get('profile_link_color', None), profile_text_color=data.get('profile_text_color', None), protected=data.get('protected', None), utc_offset=data.get('utc_offset', None), time_zone=data.get('time_zone', None), url=data.get('url', None), status=status, geo_enabled=data.get('geo_enabled', None), verified=data.get('verified', None), lang=data.get('lang', None), notifications=data.get('notifications', None), contributors_enabled=data.get('contributors_enabled', None), created_at=data.get('created_at', None), listed_count=data.get('listed_count', None))
|
'Get the unique id of this list.
Returns:
The unique id of this list'
| def GetId(self):
| return self._id
|
'Set the unique id of this list.
Args:
id:
The unique id of this list.'
| def SetId(self, id):
| self._id = id
|
'Get the real name of this list.
Returns:
The real name of this list'
| def GetName(self):
| return self._name
|
'Set the real name of this list.
Args:
name:
The real name of this list'
| def SetName(self, name):
| self._name = name
|
'Get the slug of this list.
Returns:
The slug of this list'
| def GetSlug(self):
| return self._slug
|
'Set the slug of this list.
Args:
slug:
The slug of this list.'
| def SetSlug(self, slug):
| self._slug = slug
|
'Get the description of this list.
Returns:
The description of this list'
| def GetDescription(self):
| return self._description
|
'Set the description of this list.
Args:
description:
The description of this list.'
| def SetDescription(self, description):
| self._description = description
|
'Get the full_name of this list.
Returns:
The full_name of this list'
| def GetFull_name(self):
| return self._full_name
|
'Set the full_name of this list.
Args:
full_name:
The full_name of this list.'
| def SetFull_name(self, full_name):
| self._full_name = full_name
|
'Get the mode of this list.
Returns:
The mode of this list'
| def GetMode(self):
| return self._mode
|
'Set the mode of this list.
Args:
mode:
The mode of this list.'
| def SetMode(self, mode):
| self._mode = mode
|
'Get the uri of this list.
Returns:
The uri of this list'
| def GetUri(self):
| return self._uri
|
'Set the uri of this list.
Args:
uri:
The uri of this list.'
| def SetUri(self, uri):
| self._uri = uri
|
'Get the member_count of this list.
Returns:
The member_count of this list'
| def GetMember_count(self):
| return self._member_count
|
'Set the member_count of this list.
Args:
member_count:
The member_count of this list.'
| def SetMember_count(self, member_count):
| self._member_count = member_count
|
'Get the subscriber_count of this list.
Returns:
The subscriber_count of this list'
| def GetSubscriber_count(self):
| return self._subscriber_count
|
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.