本文整理汇总了Python中yowsup.common.tools.StorageTools类的典型用法代码示例。如果您正苦于以下问题:Python StorageTools类的具体用法?Python StorageTools怎么用?Python StorageTools使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了StorageTools类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: save
def save(self, config, serialize_type=TYPE_JSON, dest=None):
outputdata = self.config_to_str(config, serialize_type)
if dest is None:
StorageTools.writePhoneConfig(config.phone, outputdata)
else:
with open(dest, 'wb') as outputfile:
outputfile.write(outputdata)
示例2: handleSuccess
def handleSuccess(self, node):
if node.data != None:
StorageTools.writeNonce(self.credentials[0], node.data)
successEvent = YowLayerEvent(self.__class__.EVENT_AUTHED, passive=self.getProp(self.__class__.PROP_PASSIVE))
self.broadcastEvent(successEvent)
nodeEntity = SuccessProtocolEntity.fromProtocolTreeNode(node)
self.toUpper(nodeEntity)
示例3: send
def send(self, parser = None):
if self.__id is not None:
request = WAExistsRequest(self.cc, self.p_in, self.__id)
result = request.send()
if result["status"] == "ok":
return result
self.__id = WATools.generateIdentity()
self.addParam("id", self.__id)
res = super(WACodeRequest, self).send(parser)
if res["status"] == "sent":
StorageTools.writeIdentity(self.cc + self.p_in, self.__id)
return res
示例4: initStore
def initStore(self):
self.store = LiteAxolotlStore(
StorageTools.constructPath(
self.getProp(
YowAuthenticationProtocolLayer.PROP_CREDENTIALS)[0],
self.__class__._DB
)
)
self.state = self.__class__._STATE_HASKEYS if self.store.getLocalRegistrationId() is not None \
else self.__class__._STATE_INIT
示例5: _sendAuth
def _sendAuth(self):
passive = self.getProp(self.__class__.PROP_PASSIVE, False)
nonce = StorageTools.getNonce(self.credentials[0])
if nonce == None:
self.entityToLower(AuthProtocolEntity(self.credentials[0], passive=passive))
else:
inputKey, outputKey, authBlob = self.generateAuthBlob(nonce)
#to prevent enr whole response
self.broadcastEvent(YowLayerEvent(YowCryptLayer.EVENT_KEYS_READY, keys = (inputKey, None)))
self.entityToLower(AuthProtocolEntity(self.credentials[0], passive=passive, nonce=authBlob))
self.broadcastEvent(YowLayerEvent(YowCryptLayer.EVENT_KEYS_READY, keys = (inputKey, outputKey)))
示例6: store
def store(self):
try:
if self._store is None:
self.store = LiteAxolotlStore(
StorageTools.constructPath(
self.getProp(
YowAuthenticationProtocolLayer.PROP_CREDENTIALS)[0],
self.__class__._DB
)
)
return self._store
except AttributeError:
return None
示例7: __init__
def __init__(self,cc, p_in, code):
super(WARegRequest,self).__init__()
idx = StorageTools.getIdentity(cc + p_in)
if idx is None:
raise ValueError("You have to request code first")
self.addParam("cc", cc)
self.addParam("in", p_in)
self.addParam("id", idx)
self.addParam("code", code)
self.url = "v.whatsapp.net/v2/register"
self.pvars = ["status", "login", "pw", "type", "expiration", "kind", "price", "cost", "currency", "price_expiration",
"reason","retry_after"]
self.setParser(JSONResponseParser())
示例8: __init__
def __init__(self,cc, p_in, mcc= "000", mnc = "000", sim_mcc = "000", sim_mnc = "000", method="sms"):
super(WACodeRequest,self).__init__()
idx = StorageTools.getIdentity(cc + p_in)
self.p_in = p_in
self.__id = idx
self.cc = cc
self.addParam("cc", cc)
self.addParam("in", p_in)
self.addParam("lc", "GB")
self.addParam("lg", "en")
self.addParam("sim_mcc", sim_mcc.zfill(3))
self.addParam("sim_mnc", sim_mnc.zfill(3))
self.addParam("mcc", sim_mcc.zfill(3))
self.addParam("mnc", sim_mnc.zfill(3))
self.addParam("method", method)
self.addParam("mistyped", "6")
self.addParam("network_radio_type", "1")
self.addParam("simnum", "1")
self.addParam("s", "")
self.addParam("copiedrc", "1")
self.addParam("hasinrc", "1")
self.addParam("rcmatch", "1")
self.addParam("pid", os.getpid())
self.addParam("rchash", hashlib.sha256(os.urandom(20)).hexdigest())
self.addParam("anhash", hashlib.md5(os.urandom(20)).hexdigest())
self.addParam("extexist", "1")
self.addParam("extstate", "1")
self.addParam("token", CURRENT_ENV.getToken(p_in))
self.url = "v.whatsapp.net/v2/code"
self.pvars = ["status","reason","length", "method", "retry_after", "code", "param"] +\
["login", "pw", "type", "expiration", "kind", "price", "cost", "currency", "price_expiration"]
self.setParser(JSONResponseParser())
示例9: __init__
def __init__(self,cc, p_in, mcc= "000", mnc = "000", sim_mcc = "000", sim_mnc = "000", method="sms"):
super(WACodeRequest,self).__init__()
idx = StorageTools.getIdentity(cc + p_in)
self.p_in = p_in
self.__id = idx
self.cc = cc
self.addParam("cc", cc)
self.addParam("in", p_in)
self.addParam("lc", "GB")
self.addParam("lg", "en")
self.addParam("sim_mcc", sim_mcc.zfill(3))
self.addParam("sim_mnc", sim_mnc.zfill(3))
self.addParam("method", method)
self.addParam("token", CURRENT_ENV.getToken(p_in))
self.url = "v.whatsapp.net/v2/code"
self.pvars = ["status","reason","length", "method", "retry_after", "code", "param"] +\
["login", "pw", "type", "expiration", "kind", "price", "cost", "currency", "price_expiration"]
self.setParser(JSONResponseParser())
示例10: load
def load(self, username):
"""
:param username:
:type username:
:return:
:rtype:
"""
config_dir = StorageTools.getStorageForPhone(username)
logger.debug("Detecting config for username=%s, dir=%s" % (username, config_dir))
exhausted = []
for ftype in self.MAP_EXT:
if len(ftype):
fname = (self.NAME_FILE_CONFIG + "." + ftype)
else:
fname = self.NAME_FILE_CONFIG
fpath = os.path.join(config_dir, fname)
logger.debug("Trying %s" % fpath)
if os.path.isfile(fpath):
return self.load_path(fpath)
exhausted.append(fpath)
logger.error("Could not find a config for username=%s, paths checked: %s" % (username, ":".join(exhausted)))
示例11: get_manager
def get_manager(self, username):
logger.debug("get_manager(username=%s)" % username)
dbpath = StorageTools.constructPath(username, self.DB)
store = LiteAxolotlStore(dbpath)
return AxolotlManager(store, username)
示例12: len
from yowsup_ext.layers.cleverbot.layer import YowCleverBotLayer
from yowsup_ext.layers.store import YowStorageLayer
import sys
import logging
logging.basicConfig(level = logging.DEBUG)
logger = logging.getLogger(__name__)
if __name__ == "__main__":
if len(sys.argv) < 3:
print("Usage: run.py username password")
sys.exit(1)
credentials = (sys.argv[1], sys.argv[2])
stackBuilder = YowStackBuilder()
phoneStorage = StorageTools.getStorageForPhone(credentials[0])
stackBuilder.setProp(YowStorageLayer.PROP_DB_PATH, StorageTools.constructPath(phoneStorage, "yowstore.db"))
stack = stackBuilder\
.pushDefaultLayers(True)\
.push(YowStorageLayer)\
.push(YowCleverBotLayer)\
.build()
stack.setCredentials(credentials)
logger.info("Starting")
stack.broadcastEvent(YowLayerEvent(YowNetworkLayer.EVENT_STATE_CONNECT))
try:
stack.loop(timeout = 0.5, discrete = 0.5)
except AuthError as e:
print("Auth Error, reason %s" % e)