本文整理匯總了Python中md5.new方法的典型用法代碼示例。如果您正苦於以下問題:Python md5.new方法的具體用法?Python md5.new怎麽用?Python md5.new使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類md5
的用法示例。
在下文中一共展示了md5.new方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: initKimmo
# 需要導入模塊: import md5 [as 別名]
# 或者: from md5 import new [as 別名]
def initKimmo(self, *args):
"""
Initialize the Kimmo engine from the lexicon. This will get called no matter generate
or recognize. (i.e. loading all rules, lexicon, and alternations
"""
# only initialize Kimmo if the contents of the *rules* have changed
tmprmd5 = md5.new(self.rules.get(1.0, Tkinter.END))
tmplmd5 = md5.new(self.lexicon.get(1.0, Tkinter.END))
if (not self.kimmoinstance) or (self.rulemd5 != tmprmd5) or (self.lexmd5 != tmplmd5):
self.guiError("Creating new Kimmo instance")
self.kimmoinstance = KimmoControl(self.lexicon.get(1.0, Tkinter.END),self.rules.get(1.0, Tkinter.END),'','',self.debug)
self.guiError("")
self.rulemd5 = tmprmd5
self.lexmd5 = tmplmd5
if not self.kimmoinstance.ok:
self.guiError("Creation of Kimmo Instance Failed")
return
if not self.kimmoinstance.m.initial_state() :
self.guiError("Morphology Setup Failed")
elif self.kimmoinstance.errors:
self.guiError(self.kimmoinstance.errors)
self.kimmoinstance.errors = ''
# self.validate()
示例2: __generate
# 需要導入模塊: import md5 [as 別名]
# 或者: from md5 import new [as 別名]
def __generate(self):
"""Generate a new value for this ObjectId.
"""
oid = EMPTY
# 4 bytes current time
oid += struct.pack(">i", int(time.time()))
# 3 bytes machine
oid += ObjectId._machine_bytes
# 2 bytes pid
oid += struct.pack(">H", os.getpid() % 0xFFFF)
# 3 bytes inc
ObjectId._inc_lock.acquire()
oid += struct.pack(">i", ObjectId._inc)[1:4]
ObjectId._inc = (ObjectId._inc + 1) % 0xFFFFFF
ObjectId._inc_lock.release()
self.__id = oid
示例3: request
# 需要導入模塊: import md5 [as 別名]
# 或者: from md5 import new [as 別名]
def request(self, method, request_uri, headers, content):
"""Modify the request headers"""
keys = _get_end2end_headers(headers)
keylist = "".join(["%s " % k for k in keys])
headers_val = "".join([headers[k] for k in keys])
created = time.strftime('%Y-%m-%dT%H:%M:%SZ',time.gmtime())
cnonce = _cnonce()
request_digest = "%s:%s:%s:%s:%s" % (method, request_uri, cnonce, self.challenge['snonce'], headers_val)
request_digest = hmac.new(self.key, request_digest, self.hashmod).hexdigest().lower()
headers['authorization'] = 'HMACDigest username="%s", realm="%s", snonce="%s", cnonce="%s", uri="%s", created="%s", response="%s", headers="%s"' % (
self.credentials[0],
self.challenge['realm'],
self.challenge['snonce'],
cnonce,
request_uri,
created,
request_digest,
keylist)
示例4: save_wav
# 需要導入模塊: import md5 [as 別名]
# 或者: from md5 import new [as 別名]
def save_wav(self, chunk_id, model, body, frame_rate):
checksum = md5.new(body).hexdigest()
directory = "%s/%s" % (model, checksum[:2])
self.create_directories_if_needed(self.path + "/" + directory)
path = '%s/%s/%s.wav' % (self.path, directory, checksum)
url = '/static/data/%s/%s.wav' % (directory, checksum)
wav = wave.open(path, 'w')
wav.setnchannels(1)
wav.setsampwidth(2)
wav.setframerate(frame_rate)
wav.writeframes(body)
wav.close()
return (path, url)
示例5: md5_init
# 需要導入模塊: import md5 [as 別名]
# 或者: from md5 import new [as 別名]
def md5_init(data=None):
"""
Returns md5. This function is implemented in order to encapsulate hash
objects in a way that is compatible with python 2.4 and python 2.6
without warnings.
Note that even though python 2.6 hashlib supports hash types other than
md5 and sha1, we are artificially limiting the input values in order to
make the function to behave exactly the same among both python
implementations.
:param data: Optional input string that will be used to update the hash.
"""
try:
md5_value = hashlib.new("md5")
except NameError:
md5_value = md5.new()
if data:
md5_value.update(data)
return md5_value
示例6: _md5eval
# 需要導入模塊: import md5 [as 別名]
# 或者: from md5 import new [as 別名]
def _md5eval(data):
"""
Returns a md5 hash evaluator. This function is implemented in order to
encapsulate objects in a way that is compatible with python 2.4 and
python 2.6 without warnings.
:param data: Optional input string that will be used to update the object.
"""
try:
hsh = hashlib.new('md5')
except NameError:
hsh = md5.new()
if data:
hsh.update(data)
return hsh
示例7: image_crop_save
# 需要導入模塊: import md5 [as 別名]
# 或者: from md5 import new [as 別名]
def image_crop_save(image, new_image, box=None):
"""
Crop an image and save it to a new image.
:param image: Full path of the original image
:param new_image: Full path of the cropped image
:param box: A 4-tuple defining the left, upper, right, and lower pixel coordinate.
:return: True if crop and save image succeed
"""
img = Image.open(image)
if not box:
x, y = img.size
box = (x/4, y/4, x*3/4, y*3/4)
try:
img.crop(box).save(new_image)
except (KeyError, SystemError) as e:
logging.error("Fail to crop image: %s", e)
return False
return True
示例8: _get_bdstoken
# 需要導入模塊: import md5 [as 別名]
# 或者: from md5 import new [as 別名]
def _get_bdstoken(self):
if hasattr(self, 'bdstoken'):
return self.bdstoken
resp = self._request('GET', 'http://pan.baidu.com/disk/home',
'_get_bdstoken')
html_string = resp.content
mod = re.search(r'"bdstoken":"(.+?)"', html_string)
if mod:
self.bdstoken = mod.group(1)
return self.bdstoken
else:
print s % (1, 91, ' ! Can\'t get bdstoken')
sys.exit(1)
# self.bdstoken = md5.new(str(time.time())).hexdigest()
#def _sift(self, fileslist, name=None, size=None, time=None, head=None, tail=None, include=None, exclude=None):
示例9: GetEmail
# 需要導入模塊: import md5 [as 別名]
# 或者: from md5 import new [as 別名]
def GetEmail(prompt):
"""Prompts the user for their email address and returns it.
The last used email address is saved to a file and offered up as a suggestion
to the user. If the user presses enter without typing in anything the last
used email address is used. If the user enters a new address, it is saved
for next time we prompt.
"""
last_email_file_name = os.path.expanduser("~/.last_codereview_email_address")
last_email = ""
if os.path.exists(last_email_file_name):
try:
last_email_file = open(last_email_file_name, "r")
last_email = last_email_file.readline().strip("\n")
last_email_file.close()
prompt += " [%s]" % last_email
except IOError, e:
pass
示例10: create_incident_progression
# 需要導入模塊: import md5 [as 別名]
# 或者: from md5 import new [as 別名]
def create_incident_progression(anchor,requests,referers,date):
hash_name = md5.new(str(anchor)).hexdigest()
file_name = "incident-progression-{0}.json".format(hash_name)
app_path = Configuration.spot()
hdfs_path = "{0}/proxy/oa/storyboard/{1}/{2}/{3}"\
.format(app_path,date.year,date.month,date.day)
data = {'fulluri':anchor, 'requests':requests,'referer_for':referers.keys()}
if HDFSClient.put_file_json(data,hdfs_path,file_name,overwrite_file=True) :
response = "Incident progression successfuly created"
else:
return False
示例11: incident_progression
# 需要導入模塊: import md5 [as 別名]
# 或者: from md5 import new [as 別名]
def incident_progression(date,uri):
app_path = Configuration.spot()
hdfs_path = "{0}/proxy/oa/storyboard/{1}/{2}/{3}".format(app_path,\
date.year,date.month,date.day)
hash_name = md5.new(str(uri)).hexdigest()
file_name = "incident-progression-{0}.json".format(hash_name)
if HDFSClient.file_exists(hdfs_path,file_name):
return json.loads(HDFSClient.get_file("{0}/{1}"\
.format(hdfs_path,file_name)))
else:
return {}
示例12: _get_filename
# 需要導入模塊: import md5 [as 別名]
# 或者: from md5 import new [as 別名]
def _get_filename(self, key):
hash = md5(key.encode("utf8")).hexdigest()
return os.path.join(self._path, hash)
示例13: _generate_addons_file
# 需要導入模塊: import md5 [as 別名]
# 或者: from md5 import new [as 別名]
def _generate_addons_file( self ):
# addon list
addons = sorted(os.listdir( "." ))
# final addons text
addons_xml = u"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<addons>\n"
# loop thru and add each addons addon.xml file
for addon in addons:
try:
# skip any file or .svn folder
if ( not os.path.isdir( addon ) or addon == ".svn" ): continue
# create path
_path = os.path.join( addon, "addon.xml" )
# split lines for stripping
xml_lines = open( _path, "r" ).read().splitlines()
# new addon
addon_xml = ""
# loop thru cleaning each line
for line in xml_lines:
# skip encoding format line
if ( line.find( "<?xml" ) >= 0 ): continue
# add line
addon_xml += unicode( line.rstrip() + "\n", "utf-8" )
# we succeeded so add to our final addons.xml text
addons_xml += addon_xml.rstrip() + "\n\n"
except Exception, e:
# missing or poorly formatted addon.xml
print "Excluding %s for %s" % ( _path, e, )
# clean and add closing tag
示例14: _generate_md5_file
# 需要導入模塊: import md5 [as 別名]
# 或者: from md5 import new [as 別名]
def _generate_md5_file( self ):
try:
# create a new md5 object
m = md5.new()
except Exception, e:
print "An error occurred creating md5 object\n%s" % (e, )
示例15: http_error_302
# 需要導入模塊: import md5 [as 別名]
# 或者: from md5 import new [as 別名]
def http_error_302(self, req, fp, code, msg, headers):
if headers.has_key('location'):
newurl = headers['location']
elif headers.has_key('uri'):
newurl = headers['uri']
else:
return
newurl = urlparse.urljoin(req.get_full_url(), newurl)
# XXX Probably want to forget about the state of the current
# request, although that might interact poorly with other
# handlers that also use handler-specific request attributes
new = Request(newurl, req.get_data())
new.error_302_dict = {}
if hasattr(req, 'error_302_dict'):
if len(req.error_302_dict)>10 or \
req.error_302_dict.has_key(newurl):
raise HTTPError(req.get_full_url(), code,
self.inf_msg + msg, headers, fp)
new.error_302_dict.update(req.error_302_dict)
new.error_302_dict[newurl] = newurl
# Don't close the fp until we are sure that we won't use it
# with HTTPError.
fp.read()
fp.close()
return self.parent.open(new)