def encode_job(self, job): random_bytes = Array.CreateInstance(Byte, 2) Random().NextBytes(random_bytes) data = Encoding.UTF8.GetBytes(JavaScriptSerializer().Serialize(job)) with MemoryStream(data.Length) as initialStream: initialStream.Write(data, 0, data.Length) initialStream.Seek(0, SeekOrigin.Begin) with MemoryStream() as resultStream: with GZipStream(resultStream, CompressionMode.Compress) as zipStream: buffer = Array.CreateInstance(Byte, 4096) bytesRead = initialStream.Read(buffer, 0, buffer.Length) zipStream.Write(buffer, 0, bytesRead) while bytesRead != 0: bytesRead = initialStream.Read(buffer, 0, buffer.Length) zipStream.Write(buffer, 0, bytesRead) result = resultStream.ToArray() result[:2] = random_bytes return { Convert.ToBase64String(Guid.NewGuid().ToByteArray()).Substring( 0, 8): Convert.ToBase64String(Guid.NewGuid().ToByteArray()), "data": Convert.ToBase64String(result) }
def setEntryBySrcEntry(): ''' 由源单明细表体写入明细表体 ''' srcEntry = this.View.Model.DataObject["RECEIVEBILLSRCENTRY"] entry = this.View.Model.DataObject["RECEIVEBILLENTRY"] rowNum = this.View.Model.GetEntryRowCount("FRECEIVEBILLENTRY") if rowNum > 0: if (str(entry[rowNum - 1]["RECTOTALAMOUNTFOR"]) == "0" and str(entry[rowNum - 1]["RECAMOUNTFOR_E"]) == "0" and str(entry[rowNum - 1]["SETTLERECAMOUNTFOR"]) == "0"): this.View.Model.DeleteEntryRow("FRECEIVEBILLENTRY", rowNum - 1) for idx, row in enumerate(srcEntry): srcBillType = str(row["SRCBILLTYPEID"]) if srcBillType == "ora_CZ_ReceiptSplit": guid = str(Guid.NewGuid()) amount = str(row["REALRECAMOUNT"]) #本次收款金额 this.View.Model.CreateNewEntryRow("FRECEIVEBILLENTRY") i = this.View.Model.GetEntryRowCount("FRECEIVEBILLENTRY") - 1 this.View.Model.SetValue("FRECTOTALAMOUNTFOR", amount, i) #应收金额 this.View.Model.SetValue("FRECAMOUNTFOR_E", amount, i) #收款金额 this.View.Model.SetValue("FSETTLERECAMOUNTFOR", amount, i) #折后金额 this.View.Model.SetValue("F_ora_ReGuid", guid, i) #明细表体 this.View.Model.SetValue("F_ora_RseGuid", guid, idx) #源单明细表体 this.View.UpdateView("FRECEIVEBILLENTRY")
def test_struct_constructor(): """Test struct constructor args""" from System import Guid from Python.Test import StructConstructorTest guid = Guid.NewGuid() ob = StructConstructorTest(guid) assert ob.value == guid
def testStructConstructor(self): """Test struct constructor args""" from System import Guid from Python.Test import StructConstructorTest guid = Guid.NewGuid() ob = StructConstructorTest(guid) self.assertTrue(ob.value == guid)
def testMethodCallStructConversion(self): """Test struct conversion in method call.""" from System import Guid object = MethodTest() guid = Guid.NewGuid() temp = guid.ToString() r = object.TestStructConversion(guid) self.assertTrue(r.ToString() == temp)
def test_method_call_struct_conversion(): """Test struct conversion in method call.""" from System import Guid ob = MethodTest() guid = Guid.NewGuid() temp = guid.ToString() r = ob.TestStructConversion(guid) assert r.ToString() == temp
def randtest(doc): #生成1w个测试点 with dbtrans(doc) as tr: btr = tr.opencurrspace() from System import Guid, Random r = Random(Guid.NewGuid().GetHashCode()) for i in range(10000): tr.addentity( btr, acdb.DBPoint(acge.Point3d(r.Next(0, 1000), r.Next(0, 1000), 0)))
def __init__(self, name, ptype, group="pypevitmep", guid=None, description="", modifiable=True, visible=True, new=True): # type: (str, ParameterType or str, str, Guid or None, str, bool, bool, bool) -> None self.name = name self.description = description self.group = group true_tuple = (True, "", None, "True", "Yes", "Oui", 1) if modifiable in true_tuple: self.modifiable = True else: self.modifiable = False if visible in true_tuple: self.visible = True else: self.visible = False # Check if a Guid is given. If not a new one is created if not guid: self.guid = Guid.NewGuid() else: self.guid = guid # Check if given parameter type is valid. If not user is prompted to choose one. if isinstance(ptype, ParameterType): self.type = ptype else: try: self.type = getattr(ParameterType, ptype) except AttributeError: selected_type = rpw.ui.forms.SelectFromList( "Select ParameterType", ParameterType.GetNames(ParameterType), "Parameter {} ParameterType: {} is not valid. Please select a parameter type".format(name, ptype), sort=False) self.type = getattr(ParameterType, selected_type) self.initial_values = {} if new is True: self.new = new else: self.new = False self.initial_values_update() self.changed = False
def createCodes(self): try: guid = Guid.NewGuid().ToString('N') # global unique ID # get configuration from web.config codeSource = WebConfigurationManager.AppSettings['CodeGenQueue'] lengthCaptchaStrng = int(WebConfigurationManager.AppSettings['captchaStrngLngth']) # create captcha code captcha = '' for a in range(lengthCaptchaStrng): apd = random.choice(codeSource) captcha += apd # save to session cache self.usrDt.addNewItem('GUID', guid) self.usrDt.addNewItem('CAPTCHA', captcha) return guid except Exception,e: self.log.w2lgError(traceback.format_exc())
from System import Guid g = Guid.NewGuid() print("Hello! Your Python-made GUID is: {}".format(g)) def new_guid(): return Guid.NewGuid()
def guid(gid = None): from System import Guid return gid and Guid(gid) or Guid.NewGuid()
def test_negative(): AssertError(ValueError, clr.LoadTypeLibrary, "DlrComLibrary.DlrComServer") AssertError(ValueError, clr.LoadTypeLibrary, 42) AssertError(EnvironmentError, clr.LoadTypeLibrary, Guid.NewGuid())
try: assert DEBUG clr.AddReference(IronPythonDLL) except NameError: DEBUG = True print "Set DEBUG: {}".format(DEBUG) try: import traceback except ImportError: print "[!] Error importing traceback module, full tracebacks will not be displayed" clr.AddReference("IronPython") try: assert GUID except NameError: GUID = Guid.NewGuid().ToString() print "Created GUID: {}".format(GUID) try: assert URL except NameError: URL = Uri(Uri("https://172.16.164.1:5000/"), GUID) print "Set URL: {}\n".format(URL) clr.AddReference("System.Management") clr.AddReference("System.Web.Extensions") clr.AddReference("Microsoft.VisualBasic") clr.AddReference("Boo.Lang.Interpreter") from System.Text import Encoding from System.Management import ManagementObject from System.Diagnostics import Process
def new_uuid(): """Create a new UUID (using dotnet Guid.NewGuid)""" # RE: https://github.com/eirannejad/pyRevit/issues/413 # return uuid.uuid1() return str(Guid.NewGuid())
def gen_random_string(self, length=8): return Guid.NewGuid().ToString("n").Substring(0, length)
PINVOKE_METHOD_ATTRIBUTES = (Refl.MethodAttributes.Public | Refl.MethodAttributes.Static | Refl.MethodAttributes.HideBySig | Refl.MethodAttributes.PinvokeImpl) PUBLIC_STATIC_BINDING_FLAGS = Refl.BindingFlags.Static | Refl.BindingFlags.Public WIN_API_CALLING_CONVENTION = Interop.CallingConvention.StdCall assemblyBuilder = (Emit.AssemblyBuilder.DefineDynamicAssembly( Refl.AssemblyName(WIN32_PINVOKE_DYNAMIC_ASSEMBLY_NAME), Emit.AssemblyBuilderAccess.Run)) MODULE_BUILDER = assemblyBuilder.DefineDynamicModule("WIN_API_MODULE_" + Guid.NewGuid().ToString()) def GetWinApiFunctionImpl(functionName, moduleName, charSet, returnType, *parameterTypes): tbuilder = MODULE_BUILDER.DefineType("WIN_API_TYPE" + "_" + moduleName + "_" + functionName) mbuilder = tbuilder.DefinePInvokeMethod( functionName, moduleName, PINVOKE_METHOD_ATTRIBUTES, Refl.CallingConventions.Standard, clr.GetClrType(returnType), [clr.GetClrType(t) for t in parameterTypes].ToArray[System.Type](), WIN_API_CALLING_CONVENTION, charSet) mbuilder.SetImplementationFlags(mbuilder.MethodImplementationFlags | Refl.MethodImplAttributes.PreserveSig) winApiType = tbuilder.CreateType() methodInfo = winApiType.GetMethod(functionName,
Refl.MethodAttributes.HideBySig | Refl.MethodAttributes.PinvokeImpl ) PUBLIC_STATIC_BINDING_FLAGS = Refl.BindingFlags.Static | Refl.BindingFlags.Public WIN_API_CALLING_CONVENTION = Interop.CallingConvention.StdCall assemblyBuilder = ( Emit.AssemblyBuilder.DefineDynamicAssembly( Refl.AssemblyName(WIN32_PINVOKE_DYNAMIC_ASSEMBLY_NAME), Emit.AssemblyBuilderAccess.Run ) ) MODULE_BUILDER = assemblyBuilder.DefineDynamicModule("WIN_API_MODULE_" + Guid.NewGuid().ToString()) def GetWinApiFunctionImpl( functionName, moduleName, charSet, returnType, *parameterTypes ): tbuilder = MODULE_BUILDER.DefineType("WIN_API_TYPE" + "_" + moduleName + "_" + functionName) mbuilder = tbuilder.DefinePInvokeMethod( functionName, moduleName, PINVOKE_METHOD_ATTRIBUTES, Refl.CallingConventions.Standard, clr.GetClrType(returnType),
def __init__(self, name, ptype, group=None, guid=None, description="", modifiable=True, visible=True, new=True): # type: (str, ParameterType or str, str, Guid or None, str, bool, bool, bool) -> None self.name = name self.description = description if group: self.group = group else: self.group = "pyrevitmep" true_tuple = (True, "", None, "True", "Yes", "Oui", 1, "1") if modifiable in true_tuple: self.modifiable = True else: self.modifiable = False if visible in true_tuple: self.visible = True else: self.visible = False # Check if a Guid is given. If not a new one is created if not guid: self.guid = Guid.NewGuid() elif not isinstance(guid, Guid): try: self.guid = Guid(guid) except SystemError: self.guid = Guid.NewGuid() else: self.guid = guid # Check if given parameter type is valid. If not user is prompted to choose one. if isinstance(ptype, ParameterType): self.type = ptype else: try: self.type = getattr(ParameterType, ptype) except AttributeError: self.type = ptype while not isinstance(self.type, ParameterType): self.type = SelectFromList.show( PType.enum_generator(), "Parameter {} ParameterType: {} not valid. Please select a parameter type" .format(name, ptype)) self.initial_values = {} if new is True: self.new = new else: self.new = False self.initial_values_update() self.changed = False
def __init__(self, _center, _radius): self.center = _center self.radius = _radius self.guid = guid.NewGuid()
def new_guid(): return Guid.NewGuid()
def new_uuid(): # RE: https://github.com/eirannejad/pyRevit/issues/413 # return uuid.uuid1() return str(Guid.NewGuid())
def __init__(self, center, radius): self.__center = center self.__radius = radius self.__guid = guid.NewGuid()